Skip to content

Commit

Permalink
[音乐盒] 添加处理超范围音符的选项
Browse files Browse the repository at this point in the history
  • Loading branch information
happyme531 committed Aug 1, 2024
1 parent 92afb45 commit eb9ff84
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 4 deletions.
4 changes: 4 additions & 0 deletions 楚留香音乐盒/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1770,6 +1770,8 @@ function loadMusicFile(fileName, loadType) {
let humanifyNoteAbsTimeStdDev = readGlobalConfig("humanifyNoteAbsTimeStdDev", 0)
let majorPitchOffset = configuration.readFileConfigForTarget("majorPitchOffset", rawFileName, gameProfile, 0);
let minorPitchOffset = configuration.readFileConfigForTarget("minorPitchOffset", rawFileName, gameProfile, 0);
let wrapHigherOctave = configuration.readFileConfigForTarget("wrapHigherOctave", rawFileName, gameProfile, 1);
let wrapLowerOctave = configuration.readFileConfigForTarget("wrapLowerOctave", rawFileName, gameProfile, 0);
let semiToneRoundingMode = readFileConfig("semiToneRoundingMode", rawFileName, 0);
let limitClickSpeedHz = readFileConfig("limitClickSpeedHz", rawFileName, 0);
let speedMultiplier = readFileConfig("speedMultiplier", rawFileName, 1);
Expand Down Expand Up @@ -1831,6 +1833,8 @@ function loadMusicFile(fileName, loadType) {
pipeline.push(new passes.LegalizeTargetNoteRangePass({
semiToneRoundingMode: semiToneRoundingMode,
currentGameProfile: gameProfile,
wrapHigherOctave: wrapHigherOctave,
wrapLowerOctave: wrapLowerOctave
}));
//单个按键频率限制
pipeline.push(new passes.SingleKeyFrequencyLimitPass({
Expand Down
33 changes: 29 additions & 4 deletions 楚留香音乐盒/src/passes.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,8 @@ var SemiToneRoundingMode = {
* @brief 处理目标游戏中无法演奏的音符
* @typedef {Object} LegalizeTargetNoteRangePassConfig
* @property {SemiToneRoundingMode} semiToneRoundingMode - 半音处理方式
* @property {number} [wrapHigherOctave] - 将超出最高音n个八度内的音符移动到范围内, 默认为0
* @property {number} [wrapLowerOctave] - 将超出最低音n个八度内的音符移动到范围内, 默认为0
* @property {GameProfile} currentGameProfile - 当前游戏配置
* @param {LegalizeTargetNoteRangePassConfig} config
*/
Expand All @@ -216,12 +218,16 @@ function LegalizeTargetNoteRangePass(config) {
this.description = "处理目标游戏中无法演奏的音符";

let semiToneRoundingMode = SemiToneRoundingMode.floor;
let wrapHigherOctave = 0;
let wrapLowerOctave = 0;
let currentGameProfile = null;

let underFlowedNoteCnt = 0;
let overFlowedNoteCnt = 0;
let roundedNoteCnt = 0;
let middleFailedNoteCnt = 0;
let wrappedHigherNoteCnt = 0;
let wrappedLowerNoteCnt = 0;
let lastIsFloor = false;


Expand All @@ -234,6 +240,13 @@ function LegalizeTargetNoteRangePass(config) {
semiToneRoundingMode = config.semiToneRoundingMode;
currentGameProfile = config.currentGameProfile;

if (config.wrapHigherOctave != null) {
wrapHigherOctave = config.wrapHigherOctave;
}
if (config.wrapLowerOctave != null) {
wrapLowerOctave = config.wrapLowerOctave;
}

/**
* 运行此pass
* @param {noteUtils.Note[]} noteData - 音乐数据
Expand All @@ -250,12 +263,24 @@ function LegalizeTargetNoteRangePass(config) {
let midiPitch = note[0];
//超出范围的音符
if (midiPitch < noteRange[0]) {
underFlowedNoteCnt++;
continue;
if(midiPitch >= noteRange[0] - wrapLowerOctave * 12){
midiPitch += 12 * Math.ceil((noteRange[0] - midiPitch) / 12);
note[0] = midiPitch;
wrappedLowerNoteCnt++;
}else{
underFlowedNoteCnt++;
continue;
}
}
if (midiPitch > noteRange[1]) {
overFlowedNoteCnt++;
continue;
if(midiPitch <= noteRange[1] + wrapHigherOctave * 12){
midiPitch -= 12 * Math.ceil((midiPitch - noteRange[1]) / 12);
note[0] = midiPitch;
wrappedHigherNoteCnt++;
} else {
overFlowedNoteCnt++;
continue;
}
}
let key = currentGameProfile.getKeyByPitch(midiPitch);
if (key != -1) { //有对应的按键, 不需要处理
Expand Down
22 changes: 22 additions & 0 deletions 楚留香音乐盒/src/ui/config_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -777,6 +777,14 @@ function ConfigurationUi(rawFileName, gameProfile, flags, callback) {
</horizontal>
<seekbar id="minorPitchOffsetSeekbar" w="*" max="11" layout_gravity="center" />
</vertical>
<horizontal id="wrapHigherOctaveContainer">
<text text="移动高八度音符到音域内: " />
<checkbox id="wrapHigherOctaveCheckbox" />
</horizontal>
<horizontal id="wrapLowerOctaveContainer">
<text text="移动低八度音符到音域内: " />
<checkbox id="wrapLowerOctaveCheckbox" />
</horizontal>
<horizontal id="trackSelectionContainer">
<text text="音轨选择:" />
<button id="selectTracksButton" text="选择..." padding="0dp" />
Expand All @@ -790,6 +798,8 @@ function ConfigurationUi(rawFileName, gameProfile, flags, callback) {
view_range.semiToneRoundingModeSettingContainer.setVisibility(View.GONE);
view_range.trackDisableThresholdSettingContainer.setVisibility(View.GONE);
view_range.minorPitchOffsetSettingContainer.setVisibility(View.GONE);
view_range.wrapHigherOctaveContainer.setVisibility(View.GONE);
view_range.wrapLowerOctaveContainer.setVisibility(View.GONE);
}
//如果游戏有所有半音, 隐藏移调设置
if (this.flags.includes(ConfigurationFlags.GAME_HAS_ALL_SEMITONES)) {
Expand Down Expand Up @@ -836,6 +846,10 @@ function ConfigurationUi(rawFileName, gameProfile, flags, callback) {
if (analyzedMinorPitchOffset != undefined) {
view_range.analyzedMinorPitchOffsetValueText.setText(` (推荐: ${analyzedMinorPitchOffset.toFixed(0)})`);
}
let wrapHigherOctave = configuration.readFileConfigForTarget("wrapHigherOctave", rawFileName, gameProfile, 1);
view_range.wrapHigherOctaveCheckbox.setChecked(wrapHigherOctave > 0); //居然不会自动转换成bool
let wrapLowerOctave = configuration.readFileConfigForTarget("wrapLowerOctave", rawFileName, gameProfile, 0);
view_range.wrapLowerOctaveCheckbox.setChecked(wrapLowerOctave > 0);

view_range.semiToneRoundingModeSetting.setOnCheckedChangeListener(function (group, checkedId) {
anythingChanged = true;
Expand Down Expand Up @@ -904,6 +918,14 @@ function ConfigurationUi(rawFileName, gameProfile, flags, callback) {
"trackDisableThreshold": trackDisableThreshold
});
});
view_range.wrapHigherOctaveCheckbox.setOnCheckedChangeListener(function (button, checked) {
anythingChanged = true;
configuration.setFileConfigForTarget("wrapHigherOctave", checked, rawFileName, gameProfile);
});
view_range.wrapLowerOctaveCheckbox.setOnCheckedChangeListener(function (button, checked) {
anythingChanged = true;
configuration.setFileConfigForTarget("wrapLowerOctave", checked, rawFileName, gameProfile);
});
view_range.selectTracksButton.click(function () {
anythingChanged = true;
runCallback(ConfigurationCallbacks.selectTracks, {
Expand Down

0 comments on commit eb9ff84

Please sign in to comment.