浏览代码

feat:小节评分打击乐只返回节奏分,记录设备类型

Joburgess 4 年之前
父节点
当前提交
24d113ff54

+ 24 - 1
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/SoundCompareHelper.java

@@ -4,6 +4,7 @@ import be.tarsos.dsp.AudioEvent;
 import be.tarsos.dsp.SilenceDetector;
 import be.tarsos.dsp.pitch.PitchDetectionHandler;
 import be.tarsos.dsp.pitch.PitchDetectionResult;
+import com.ym.mec.biz.dal.enums.DeviceTypeEnum;
 import com.ym.mec.biz.service.impl.SoundCompareHandler;
 import io.swagger.annotations.ApiModelProperty;
 import org.springframework.util.CollectionUtils;
@@ -21,9 +22,15 @@ import java.util.Map;
  */
 public class SoundCompareHelper implements PitchDetectionHandler {
 
+    @ApiModelProperty(value = "设备类型")
+    private DeviceTypeEnum deviceType;
+
     @ApiModelProperty(value = "伴奏编号")
     private Integer musicScoreId;
 
+    @ApiModelProperty(value = "声部编号")
+    private Integer subjectId;
+
     @ApiModelProperty(value = "小节开始时间")
     private double measureStartTime = 0;
 
@@ -77,6 +84,22 @@ public class SoundCompareHelper implements PitchDetectionHandler {
         this.musicalNotePitchMap = musicalNotePitchMap;
     }
 
+    public Integer getSubjectId() {
+        return subjectId;
+    }
+
+    public void setSubjectId(Integer subjectId) {
+        this.subjectId = subjectId;
+    }
+
+    public DeviceTypeEnum getDeviceType() {
+        return deviceType;
+    }
+
+    public void setDeviceType(DeviceTypeEnum deviceType) {
+        this.deviceType = deviceType;
+    }
+
     public int getOffsetTime() {
         return offsetTime;
     }
@@ -169,7 +192,7 @@ public class SoundCompareHelper implements PitchDetectionHandler {
     public void handlePitch(PitchDetectionResult pitchDetectionResult, AudioEvent audioEvent) {
         int timeStamp = (int) (measureStartTime + audioEvent.getTimeStamp()*1000);
         float pitch = pitchDetectionResult.getPitch();
-        if(pitch>0 && offsetTime == -1){
+        if(offsetTime == -1 && !DeviceTypeEnum.IOS.equals(deviceType) && pitch>0){
             int preTimeStamp = CollectionUtils.isEmpty(recordMeasurePithInfo)?0:recordMeasurePithInfo.get(recordMeasurePithInfo.size()-1).getTimeStamp();
             offsetTime = timeStamp - (timeStamp - preTimeStamp)/2;
             for (Map.Entry<Integer, MusicPitchDetailDto> musicPitchDetailDtoEntry : measureEndTime.entrySet()) {

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/SysMusicCompareRecord.java

@@ -1,5 +1,6 @@
 package com.ym.mec.biz.dal.entity;
 
+import com.ym.mec.biz.dal.enums.DeviceTypeEnum;
 import org.apache.commons.lang3.builder.ToStringBuilder;
 
 import java.math.BigDecimal;
@@ -39,6 +40,8 @@ public class SysMusicCompareRecord {
 	/** 创建时间 */
 	private java.util.Date createTime;
 
+	private DeviceTypeEnum deviceType;
+
 	private String clientId;
 	
 	public void setId(Long id){
@@ -121,6 +124,14 @@ public class SysMusicCompareRecord {
 		this.recordFilePath = recordFilePath;
 	}
 
+	public DeviceTypeEnum getDeviceType() {
+		return deviceType;
+	}
+
+	public void setDeviceType(DeviceTypeEnum deviceType) {
+		this.deviceType = deviceType;
+	}
+
 	public void setCreateTime(java.util.Date createTime){
 		this.createTime = createTime;
 	}

+ 35 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/enums/DeviceTypeEnum.java

@@ -0,0 +1,35 @@
+package com.ym.mec.biz.dal.enums;
+
+import com.ym.mec.common.enums.BaseEnum;
+
+public enum DeviceTypeEnum implements BaseEnum<String, DeviceTypeEnum> {
+	IOS("IOS", "苹果"),
+	ANDROID("ANDROID", "安卓"),
+	WEB("WEB", "浏览器");
+
+	private String code;
+
+	private String msg;
+
+	DeviceTypeEnum(String code, String msg) {
+		this.code = code;
+		this.msg = msg;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getMsg() {
+		return msg;
+	}
+
+	public void setMsg(String msg) {
+		this.msg = msg;
+	}
+
+	@Override
+	public String getCode() {
+		return this.code;
+	}
+}

+ 19 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SoundCompareHandler.java

@@ -7,10 +7,12 @@ import be.tarsos.dsp.util.PitchConverter;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.biz.dal.config.SoundCompareConfig;
+import com.ym.mec.biz.dal.dao.SysMusicScoreAccompanimentDao;
 import com.ym.mec.biz.dal.dto.MusicPitchDetailDto;
 import com.ym.mec.biz.dal.dto.SoundCompareHelper;
 import com.ym.mec.biz.dal.dto.WavHeader;
 import com.ym.mec.biz.dal.dto.WebSocketInfo;
+import com.ym.mec.biz.dal.enums.DeviceTypeEnum;
 import com.ym.mec.biz.handler.WebSocketHandler;
 import com.ym.mec.biz.service.SoundSocketService;
 import com.ym.mec.biz.service.SysMusicCompareRecordService;
@@ -21,7 +23,6 @@ import org.apache.commons.io.FileUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Value;
 import org.springframework.security.oauth2.provider.OAuth2Authentication;
 import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
@@ -64,6 +65,8 @@ public class SoundCompareHandler implements WebSocketEventHandler {
 
     @Autowired
     private SysMusicCompareRecordService sysMusicCompareRecordService;
+    @Autowired
+    private SysMusicScoreAccompanimentDao sysMusicScoreAccompanimentDao;
 
     public SoundCompareHandler() {
         WebSocketHandler.regist("SOUND_COMPARE", this);
@@ -95,6 +98,13 @@ public class SoundCompareHandler implements WebSocketEventHandler {
                 userSoundInfoMap.get(phone).setMusicXmlInfos(musicXmlInfos);
                 musicXmlInfos = musicXmlInfos.stream().filter(m->!m.getDontEvaluating()).collect(Collectors.toList());
                 userSoundInfoMap.get(phone).setMusicScoreId(bodyObject.getInteger("id"));
+                if(bodyObject.containsKey("platform")){
+                    userSoundInfoMap.get(phone).setDeviceType(DeviceTypeEnum.valueOf(bodyObject.getString("platform")));
+                }
+                List<Integer> subjectIds = sysMusicScoreAccompanimentDao.findSubjectByMusicScoreId(userSoundInfoMap.get(phone).getMusicScoreId(), null);
+                if(!CollectionUtils.isEmpty(subjectIds)){
+                    userSoundInfoMap.get(phone).setSubjectId(subjectIds.get(0));
+                }
                 userSoundInfoMap.get(phone).setMeasureXmlInfoMap(musicXmlInfos.stream().collect(Collectors.groupingBy(MusicPitchDetailDto::getMeasureIndex)));
                 musicXmlInfos.forEach(e->userSoundInfoMap.get(phone).getMusicalNotePitchMap().put(e.getMusicalNotesIndex(), e.getFrequency()));
                 for (Map.Entry<Integer, List<MusicPitchDetailDto>> userMeasureXmlInfoEntry : userSoundInfoMap.get(phone).getMeasureXmlInfoMap().entrySet()) {
@@ -144,10 +154,10 @@ public class SoundCompareHandler implements WebSocketEventHandler {
                 createHeader(phone);
                 break;
             case SoundSocketService.PROXY_MESSAGE:
-//                if(bodyObject.containsKey(SoundSocketService.OFFSET_TIME)){
-//                    int offsetTime = bodyObject.getIntValue(SoundSocketService.OFFSET_TIME);
-//                    calOffsetTime(phone, offsetTime);
-//                }
+                if(DeviceTypeEnum.IOS.equals(userSoundInfoMap.get(phone).getDeviceType())&&bodyObject.containsKey(SoundSocketService.OFFSET_TIME)){
+                    int offsetTime = bodyObject.getIntValue(SoundSocketService.OFFSET_TIME);
+                    calOffsetTime(phone, offsetTime);
+                }
                 break;
             default:
                 break;
@@ -478,7 +488,10 @@ public class SoundCompareHandler implements WebSocketEventHandler {
         header.put("commond", command);
         webSocketInfo.setHeader(header);
         Map<String, Object> result = new HashMap<>(5);
-        BigDecimal score = intonation.add(cadence).add(integrity).divide(new BigDecimal(3), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0, BigDecimal.ROUND_UP);
+        BigDecimal score = cadence;
+        if(Objects.isNull(userSoundInfoMap.get(phone).getSubjectId())||userSoundInfoMap.get(phone).getSubjectId()!=23){
+            score = intonation.add(cadence).add(integrity).divide(new BigDecimal(3), CommonConstants.DECIMAL_PLACE, BigDecimal.ROUND_DOWN).setScale(0, BigDecimal.ROUND_UP);
+        }
         result.put("score", score);
         result.put("intonation", intonation);
         result.put("cadence", cadence);

+ 1 - 0
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysMusicCompareRecordServiceImpl.java

@@ -47,6 +47,7 @@ public class SysMusicCompareRecordServiceImpl extends BaseServiceImpl<Long, SysM
 			sysMusicCompareRecord.setIntegrity((BigDecimal) finalScore.get("integrity"));
 		}
 		sysMusicCompareRecord.setRecordFilePath(soundCompareInfo.getRecordFilePath());
+		sysMusicCompareRecord.setDeviceType(soundCompareInfo.getDeviceType());
 		sysMusicCompareRecord.setClientId(soundCompareInfo.getClientId());
 		sysMusicCompareRecordDao.insert(sysMusicCompareRecord);
 	}

+ 4 - 2
mec-biz/src/main/resources/config/mybatis/SysMusicCompareRecordMapper.xml

@@ -16,6 +16,7 @@
 		<result column="cadence_" property="cadence" />
 		<result column="integrity_" property="integrity" />
 		<result column="record_file_path_" property="recordFilePath" />
+		<result column="device_type_" property="deviceType" typeHandler="com.ym.mec.common.dal.CustomEnumTypeHandler" />
 		<result column="client_id_" property="clientId" />
 		<result column="create_time_" property="createTime" />
 	</resultMap>
@@ -38,8 +39,9 @@
 		</selectKey>
 		-->
 		INSERT INTO sys_music_compare_record (id_,user_id_,sys_music_score_id_,score_data_,score_,intonation_,cadence_,integrity_,
-		                                      record_file_path_,client_id_,create_time_)
-		VALUES(#{id},#{userId},#{sysMusicScoreId},#{scoreData},#{score},#{intonation},#{cadence},#{integrity},#{recordFilePath},#{clientId},NOW())
+		                                      record_file_path_,device_type_,client_id_,create_time_)
+		VALUES(#{id},#{userId},#{sysMusicScoreId},#{scoreData},#{score},#{intonation},#{cadence},#{integrity},
+		       #{recordFilePath},#{deviceType,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{clientId},NOW())
 	</insert>
 
 	<!-- 根据主键查询一条记录 -->