-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from SleepyLGod/fix-midi-generator-cli
Fix midi generator cli
- Loading branch information
Showing
24 changed files
with
665 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.idea | ||
transcription.onnx | ||
out.mid | ||
target | ||
target | ||
/pianotranscriptioncli/src/main/resources/output/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...anotranscriptioncli/src/main/java/com/pianotranscriptioncli/TranscriptionApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.pianotranscriptioncli; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class TranscriptionApplication { | ||
public static void main(String[] args) { | ||
// 注:这里传入的字段码对象,必需是声明了@SpringBootApplication的类 | ||
//启动SpringBoot程序 | ||
SpringApplication.run(TranscriptionApplication.class, args); | ||
} | ||
} |
135 changes: 135 additions & 0 deletions
135
...ianotranscriptioncli/src/main/java/com/pianotranscriptioncli/common/api/CommonResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
package com.pianotranscriptioncli.common.api; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* 通用返回对象 | ||
* | ||
*/ | ||
@Getter | ||
@Setter | ||
public class CommonResult { | ||
private long code; | ||
private String message; | ||
private Object data; | ||
|
||
protected CommonResult() { | ||
} | ||
|
||
protected CommonResult(long code, String message, Object data) { | ||
this.code = code; | ||
this.message = message; | ||
this.data = data; | ||
} | ||
|
||
/** | ||
* 成功返回结果 | ||
* | ||
*/ | ||
public static CommonResult success() { | ||
return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), null); | ||
} | ||
|
||
/** | ||
* 成功返回结果 | ||
* | ||
* @param data 获取的数据 | ||
*/ | ||
public static CommonResult success(Object data) { | ||
return new CommonResult(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data); | ||
} | ||
|
||
/** | ||
* 成功返回结果 | ||
* | ||
* @param data 获取的数据 | ||
* @param message 提示信息 | ||
*/ | ||
public static CommonResult success(Object data, String message) { | ||
return new CommonResult(ResultCode.SUCCESS.getCode(), message, data); | ||
} | ||
|
||
/** | ||
* 失败返回结果 | ||
* | ||
* @param errorCode 错误码 | ||
*/ | ||
public static CommonResult failed(ErrorCode errorCode) { | ||
return new CommonResult(errorCode.getCode(), errorCode.getMessage(), null); | ||
} | ||
|
||
/** | ||
* 失败返回结果 | ||
* | ||
* @param errorCode 错误码 | ||
* @param message 错误信息 | ||
*/ | ||
public static CommonResult failed(ErrorCode errorCode, String message) { | ||
return new CommonResult(errorCode.getCode(), message, null); | ||
} | ||
|
||
/** | ||
* 失败返回结果 | ||
* | ||
* @param message 提示信息 | ||
*/ | ||
public static CommonResult failed(String message) { | ||
return new CommonResult(ResultCode.FAILED.getCode(), message, null); | ||
} | ||
|
||
/** | ||
* 失败返回结果 | ||
*/ | ||
public static CommonResult failed() { | ||
return failed(ResultCode.FAILED); | ||
} | ||
|
||
/** | ||
* 参数验证失败返回结果 | ||
*/ | ||
public static CommonResult validateFailed() { | ||
return failed(ResultCode.VALIDATE_FAILED); | ||
} | ||
|
||
/** | ||
* 参数验证失败返回结果 | ||
* | ||
* @param message 提示信息 | ||
*/ | ||
public static CommonResult validateFailed(String message) { | ||
return new CommonResult(ResultCode.VALIDATE_FAILED.getCode(), message, null); | ||
} | ||
|
||
/** | ||
* 未登录返回结果 | ||
*/ | ||
public static CommonResult unauthorized(Object data) { | ||
return new CommonResult(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data); | ||
} | ||
|
||
/** | ||
* 未授权返回结果 | ||
*/ | ||
public static CommonResult forbidden(Object data) { | ||
return new CommonResult(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data); | ||
} | ||
|
||
/** | ||
* 通过map携带简单键值对数据的无限链式调用,但切记不要在data已经不是map类型后调用 | ||
*/ | ||
public CommonResult with(String k, Object v) { | ||
Map<String, Object> map; | ||
if (data == null) { | ||
map = new HashMap<>(); | ||
} else { | ||
map = (Map<String, Object>) this.data; | ||
} | ||
map.put(k, v); | ||
this.data = map; | ||
return this; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...n/pianotranscriptioncli/src/main/java/com/pianotranscriptioncli/common/api/ErrorCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.pianotranscriptioncli.common.api; | ||
|
||
/** | ||
* 封装API的错误码 | ||
* | ||
*/ | ||
public interface ErrorCode { | ||
long getCode(); | ||
|
||
String getMessage(); | ||
} |
28 changes: 28 additions & 0 deletions
28
.../pianotranscriptioncli/src/main/java/com/pianotranscriptioncli/common/api/ResultCode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.pianotranscriptioncli.common.api; | ||
|
||
public enum ResultCode implements ErrorCode { | ||
|
||
SUCCESS(1, "操作成功"), | ||
FAILED(-1, "操作失败"), | ||
VALIDATE_FAILED(101, "参数检验失败"), | ||
UNAUTHORIZED(102, "暂未登录或token已经过期"), | ||
FORBIDDEN(103, "没有相关权限"); | ||
|
||
private final long code; | ||
private final String message; | ||
|
||
ResultCode(long code, String message) { | ||
this.code = code; | ||
this.message = message; | ||
} | ||
|
||
@Override | ||
public long getCode() { | ||
return code; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return message; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
...anotranscriptioncli/src/main/java/com/pianotranscriptioncli/common/exception/Asserts.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.pianotranscriptioncli.common.exception; | ||
|
||
import com.pianotranscriptioncli.common.api.ErrorCode; | ||
|
||
public class Asserts extends org.springframework.util.Assert { | ||
public static void fail(String message) { | ||
throw new BaseException(message); | ||
} | ||
|
||
public static void fail(ErrorCode errorCode) { | ||
throw new BaseException(errorCode); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...nscriptioncli/src/main/java/com/pianotranscriptioncli/common/exception/BaseException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.pianotranscriptioncli.common.exception; | ||
|
||
import com.pianotranscriptioncli.common.api.ErrorCode; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
/** | ||
* | ||
* 自定义API异常 | ||
*/ | ||
@Getter | ||
@Setter | ||
public class BaseException extends RuntimeException{ | ||
private ErrorCode errorCode; | ||
|
||
public BaseException() { | ||
super(); | ||
} | ||
|
||
public BaseException(ErrorCode errorCode) { | ||
super(errorCode.getMessage()); | ||
this.errorCode = errorCode; | ||
} | ||
|
||
public BaseException(String message) { | ||
super(message); | ||
} | ||
|
||
public BaseException(Throwable cause) { | ||
super(cause); | ||
} | ||
|
||
public BaseException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
...iptioncli/src/main/java/com/pianotranscriptioncli/controller/TranscriptionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.pianotranscriptioncli.controller; | ||
|
||
import com.pianotranscriptioncli.common.api.CommonResult; | ||
import com.pianotranscriptioncli.dto.Mp3ImportDTO; | ||
import com.pianotranscriptioncli.dto.Mp3ImportWithFileDTO; | ||
import com.pianotranscriptioncli.service.TranscriptionService; | ||
import com.pianotranscriptioncli.service.impl.TranscriptionServiceImpl; | ||
import com.pianotranscriptioncli.vo.Mp3ImportVO; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.io.File; | ||
import java.io.IOException; | ||
|
||
@RestController | ||
@RequestMapping("/transcription") | ||
public class TranscriptionController { | ||
|
||
@Autowired | ||
TranscriptionService transcriptionService; | ||
|
||
@PostMapping(value = "/fuck") | ||
public String Mp3TOMidiUpload() throws Exception { | ||
return "hello"; | ||
} | ||
|
||
@PostMapping(value = "/mp3ToMidi", consumes = {"application/json"}) | ||
@ResponseBody | ||
public Mp3ImportVO Mp3ToMidi(@RequestBody Mp3ImportDTO mp3ImportDTO) throws Exception { | ||
try { | ||
CommonResult commonResult = transcriptionService.Mp3TOMidiUpload(mp3ImportDTO); | ||
if (commonResult.getCode() == 1) { | ||
return new Mp3ImportVO(true, commonResult.getData().toString(), null); | ||
} else { | ||
return new Mp3ImportVO(false, null, commonResult.getMessage()); | ||
} | ||
} catch (NullPointerException e) { | ||
return new Mp3ImportVO(false, null, "请检查是否传入了正确的参数"); | ||
} | ||
} | ||
|
||
|
||
@ResponseBody | ||
@PostMapping(value = "/mp3ToMidiWithFile", consumes = {"multipart/form-data"}) | ||
public Mp3ImportVO Mp3ToMidiWithFile(@RequestParam("file")MultipartFile file, | ||
@RequestParam("outPath")String outPath, | ||
@RequestParam("songName")String songName) throws Exception { | ||
Mp3ImportWithFileDTO mp3ImportWithFileDTO = new Mp3ImportWithFileDTO(file, outPath, songName); | ||
try { | ||
CommonResult commonResult = transcriptionService.Mp3TOMidiUploadWithFile(mp3ImportWithFileDTO); | ||
if (commonResult.getCode() == 1) { | ||
return new Mp3ImportVO(true, commonResult.getData().toString(), null); | ||
} else { | ||
return new Mp3ImportVO(false, null, commonResult.getMessage()); | ||
} | ||
} catch (NullPointerException e) { | ||
return new Mp3ImportVO(false, null, "请检查是否传入了正确的参数"); | ||
} | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...ption/pianotranscriptioncli/src/main/java/com/pianotranscriptioncli/dto/Mp3ImportDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.pianotranscriptioncli.dto; | ||
|
||
import lombok.Data; | ||
import lombok.NonNull; | ||
|
||
@Data | ||
public class Mp3ImportDTO { | ||
@NonNull | ||
private boolean isAbsolute; | ||
@NonNull | ||
private String resourcePath; | ||
@NonNull | ||
private String songName; | ||
} |
27 changes: 27 additions & 0 deletions
27
...anotranscriptioncli/src/main/java/com/pianotranscriptioncli/dto/Mp3ImportWithFileDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.pianotranscriptioncli.dto; | ||
|
||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
import lombok.Setter; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Data | ||
public class Mp3ImportWithFileDTO { | ||
@NonNull | ||
private MultipartFile file; | ||
@NonNull | ||
private String outPath; | ||
@NonNull | ||
private String songName; | ||
@NonNull | ||
private String inputPath = "D:\\gitrepositories\\omg-score\\OmgPianoTranscription\\pianotranscriptioncli\\src\\main\\resources\\"; | ||
|
||
public Mp3ImportWithFileDTO(MultipartFile file, String outPath, String songName) { | ||
this.file = file; | ||
this.outPath = outPath; | ||
this.songName = songName; | ||
} | ||
|
||
} | ||
|
Oops, something went wrong.