Pitching options

This commit is contained in:
Lasercar 2025-03-04 21:07:45 +10:00
parent 98140f5f5f
commit b2a2e58548
3 changed files with 86 additions and 3 deletions
source/funkin

View file

@ -141,6 +141,8 @@ class Save
theme: ChartEditorTheme.Light,
playtestStartTime: false,
downscroll: false,
hitsoundPitchNoteDirection: false,
randomPitch: true,
metronomeVolume: 1.0,
hitsoundVolumePlayer: 1.0,
hitsoundVolumeOpponent: 1.0,
@ -327,6 +329,41 @@ class Save
return data.optionsChartEditor.theme;
}
public var chartEditorHitsoundPitchNoteDirection(get, set):Bool;
function get_chartEditorHitsoundPitchNoteDirection():Bool
{
if (data.optionsChartEditor.hitsoundPitchNoteDirection == null) data.optionsChartEditor.hitsoundPitchNoteDirection = false;
return data.optionsChartEditor.hitsoundPitchNoteDirection;
}
function set_chartEditorHitsoundPitchNoteDirection(value:Bool):Bool
{
// Set and apply.
data.optionsChartEditor.hitsoundPitchNoteDirection = value;
flush();
return data.optionsChartEditor.hitsoundPitchNoteDirection;
}
public var chartEditorRandomPitch(get, set):Bool;
function get_chartEditorRandomPitch():Bool
{
if (data.optionsChartEditor.randomPitch == null) data.optionsChartEditor.randomPitch = true;
return data.optionsChartEditor.randomPitch;
}
function set_chartEditorRandomPitch(value:Bool):Bool
{
// Set and apply.
data.optionsChartEditor.randomPitch = value;
flush();
return data.optionsChartEditor.randomPitch;
}
public var chartEditorMetronomeVolume(get, set):Float;
function get_chartEditorMetronomeVolume():Float
@ -1527,6 +1564,18 @@ typedef SaveDataChartEditorOptions =
*/
var ?downscroll:Bool;
/**
* Pitch the hitsound by note direction in the Chart editor.
* @default `false`
*/
var ?hitsoundPitchNoteDirection:Bool;
/**
* Random pitch for sounds in the Chart Editor.
* @default `true`
*/
var ?randomPitch:Bool;
/**
* Metronome volume in the Chart Editor.
* @default `1.0`

View file

@ -1859,6 +1859,16 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
*/
var menubarItemVolumeMetronome:Slider;
/**
* The `Audio -> Pitch hitsound by note direction` menu checkbox.
*/
var menubarItemHitsoundPitchNoteDirection:MenuCheckBox;
/**
* The `Audio -> "Random pitch for SFX` menu checkbox.
*/
var menubarItemRandomPitch:MenuCheckBox;
/**
* The `Audio -> Play Theme Music` menu checkbox.
*/
@ -2325,6 +2335,10 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
// audioInstTrack.pitch = save.chartEditorPlaybackSpeed;
// audioVocalTrackGroup.volume = save.chartEditorVoicesVolume;
// audioVocalTrackGroup.pitch = save.chartEditorPlaybackSpeed;
/*
menubarItemHitsoundPitchNoteDirection.selected = save.chartEditorHitsoundPitchNoteDirection;
menubarItemRandomPitch.selected = save.chartEditorRandomPitch;
*/
}
public function writePreferences(hasBackup:Bool):Void
@ -2353,6 +2367,10 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
// save.chartEditorInstVolume = audioInstTrack.volume;
// save.chartEditorVoicesVolume = audioVocalTrackGroup.volume;
// save.chartEditorPlaybackSpeed = audioInstTrack.pitch;
/*
save.chartEditorHitsoundPitchNoteDirection = menubarItemHitsoundPitchNoteDirection.selected;
save.chartEditorRandomPitch = menubarItemRandomPitch.selected;
*/
}
public function populateOpenRecentMenu():Void
@ -6281,13 +6299,29 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
// Calling event.cancelEvent() skips all the other logic! Neat!
if (event.eventCanceled) continue;
var pitch:Float = 1.0;
// Pitch the hitsound based on the note's direction, if the option is enabled
if (Save.instance.chartEditorHitsoundPitchNoteDirection /* menubarItemHitsoundPitchNoteDirection.selected */)
{
switch (noteData.getDirection())
{
case 0:
pitch = 0.75;
case 1:
pitch = 0.65;
case 2:
pitch = 1;
case 3:
pitch = 0.85;
}
}
// Hitsounds.
switch (noteData.getStrumlineIndex())
{
case 0: // Player
if (hitsoundVolumePlayer > 0) this.playSound(Paths.sound('chartingSounds/hitNotePlayer'), hitsoundVolumePlayer, 1.0, 0.1);
if (hitsoundVolumePlayer > 0) this.playSound(Paths.sound('chartingSounds/hitNotePlayer'), hitsoundVolumePlayer, pitch, 0.1);
case 1: // Opponent
if (hitsoundVolumeOpponent > 0) this.playSound(Paths.sound('chartingSounds/hitNoteOpponent'), hitsoundVolumeOpponent, 1.0, 0.1);
if (hitsoundVolumeOpponent > 0) this.playSound(Paths.sound('chartingSounds/hitNoteOpponent'), hitsoundVolumeOpponent, pitch, 0.1);
}
}
}

View file

@ -298,7 +298,7 @@ class ChartEditorAudioHandler
public static function playSound(_state:ChartEditorState, path:String, volume:Float = 1.0, pitch:Float = 1.0, pitchRandom:Float = 0):Void
{
if (volume == 0) return;
if (pitchRandom != 0)
if (funkin.save.Save.instance.chartEditorRandomPitch /* _state.menubarItemRandomPitch.selected */ && pitchRandom != 0)
{
pitch = FlxG.random.float(pitch - pitchRandom / 2, pitch + pitchRandom / 2);
}