Fix for vocals not loading properly and not getting cleared properly.

This commit is contained in:
EliteMasterEric 2023-12-19 01:26:26 -05:00
parent 328bb7b938
commit 3e65e7ecc5
3 changed files with 38 additions and 26 deletions

View file

@ -2548,8 +2548,25 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
menubarItemPlayPause.onClick = _ -> toggleAudioPlayback(); menubarItemPlayPause.onClick = _ -> toggleAudioPlayback();
menubarItemLoadInstrumental.onClick = _ -> this.openUploadInstDialog(true); menubarItemLoadInstrumental.onClick = _ -> {
menubarItemLoadVocals.onClick = _ -> this.openUploadVocalsDialog(true); var dialog = this.openUploadInstDialog(true);
// Ensure instrumental and vocals are reloaded properly.
dialog.onDialogClosed = function(_) {
this.isHaxeUIDialogOpen = false;
this.switchToCurrentInstrumental();
this.postLoadInstrumental();
}
};
menubarItemLoadVocals.onClick = _ -> {
var dialog = this.openUploadVocalsDialog(true);
// Ensure instrumental and vocals are reloaded properly.
dialog.onDialogClosed = function(_) {
this.isHaxeUIDialogOpen = false;
this.switchToCurrentInstrumental();
this.postLoadInstrumental();
}
};
menubarItemVolumeMetronome.onChange = event -> { menubarItemVolumeMetronome.onChange = event -> {
var volume:Float = event.value.toFloat() / 100.0; var volume:Float = event.value.toFloat() / 100.0;
@ -4047,7 +4064,7 @@ class ChartEditorState extends UIState // UIState derives from MusicBeatState
} }
else else
{ {
// If we clicked and released outside the grid, do nothing. // If we clicked and released outside the grid (or on HaxeUI), do nothing.
} }
} }

View file

@ -28,11 +28,11 @@ class ChartEditorAudioHandler
* @param instId The instrumental this vocal track will be for. * @param instId The instrumental this vocal track will be for.
* @return Success or failure. * @return Success or failure.
*/ */
public static function loadVocalsFromPath(state:ChartEditorState, path:Path, charId:String, instId:String = ''):Bool public static function loadVocalsFromPath(state:ChartEditorState, path:Path, charId:String, instId:String = '', wipeFirst:Bool = false):Bool
{ {
#if sys #if sys
var fileBytes:Bytes = sys.io.File.getBytes(path.toString()); var fileBytes:Bytes = sys.io.File.getBytes(path.toString());
return loadVocalsFromBytes(state, fileBytes, charId, instId); return loadVocalsFromBytes(state, fileBytes, charId, instId, wipeFirst);
#else #else
trace("[WARN] This platform can't load audio from a file path, you'll need to fetch the bytes some other way."); trace("[WARN] This platform can't load audio from a file path, you'll need to fetch the bytes some other way.");
return false; return false;
@ -47,12 +47,12 @@ class ChartEditorAudioHandler
* @param instId The instrumental this vocal track will be for. * @param instId The instrumental this vocal track will be for.
* @return Success or failure. * @return Success or failure.
*/ */
public static function loadVocalsFromAsset(state:ChartEditorState, path:String, charId:String, instId:String = ''):Bool public static function loadVocalsFromAsset(state:ChartEditorState, path:String, charId:String, instId:String = '', wipeFirst:Bool = false):Bool
{ {
var trackData:Null<Bytes> = Assets.getBytes(path); var trackData:Null<Bytes> = Assets.getBytes(path);
if (trackData != null) if (trackData != null)
{ {
return loadVocalsFromBytes(state, trackData, charId, instId); return loadVocalsFromBytes(state, trackData, charId, instId, wipeFirst);
} }
return false; return false;
} }
@ -63,10 +63,12 @@ class ChartEditorAudioHandler
* @param bytes The audio byte data. * @param bytes The audio byte data.
* @param charId The character this vocal track will be for. * @param charId The character this vocal track will be for.
* @param instId The instrumental this vocal track will be for. * @param instId The instrumental this vocal track will be for.
* @param wipeFirst Whether to wipe the existing vocal data before loading.
*/ */
public static function loadVocalsFromBytes(state:ChartEditorState, bytes:Bytes, charId:String, instId:String = ''):Bool public static function loadVocalsFromBytes(state:ChartEditorState, bytes:Bytes, charId:String, instId:String = '', wipeFirst:Bool = false):Bool
{ {
var trackId:String = '${charId}${instId == '' ? '' : '-${instId}'}'; var trackId:String = '${charId}${instId == '' ? '' : '-${instId}'}';
if (wipeFirst) wipeVocalData(state);
state.audioVocalTrackData.set(trackId, bytes); state.audioVocalTrackData.set(trackId, bytes);
return true; return true;
} }
@ -78,11 +80,11 @@ class ChartEditorAudioHandler
* @param instId The instrumental this vocal track will be for. * @param instId The instrumental this vocal track will be for.
* @return Success or failure. * @return Success or failure.
*/ */
public static function loadInstFromPath(state:ChartEditorState, path:Path, instId:String = ''):Bool public static function loadInstFromPath(state:ChartEditorState, path:Path, instId:String = '', wipeFirst:Bool = false):Bool
{ {
#if sys #if sys
var fileBytes:Bytes = sys.io.File.getBytes(path.toString()); var fileBytes:Bytes = sys.io.File.getBytes(path.toString());
return loadInstFromBytes(state, fileBytes, instId); return loadInstFromBytes(state, fileBytes, instId, wipeFirst);
#else #else
trace("[WARN] This platform can't load audio from a file path, you'll need to fetch the bytes some other way."); trace("[WARN] This platform can't load audio from a file path, you'll need to fetch the bytes some other way.");
return false; return false;
@ -96,12 +98,12 @@ class ChartEditorAudioHandler
* @param instId The instrumental this vocal track will be for. * @param instId The instrumental this vocal track will be for.
* @return Success or failure. * @return Success or failure.
*/ */
public static function loadInstFromAsset(state:ChartEditorState, path:String, instId:String = ''):Bool public static function loadInstFromAsset(state:ChartEditorState, path:String, instId:String = '', wipeFirst:Bool = false):Bool
{ {
var trackData:Null<Bytes> = Assets.getBytes(path); var trackData:Null<Bytes> = Assets.getBytes(path);
if (trackData != null) if (trackData != null)
{ {
return loadInstFromBytes(state, trackData, instId); return loadInstFromBytes(state, trackData, instId, wipeFirst);
} }
return false; return false;
} }
@ -113,9 +115,10 @@ class ChartEditorAudioHandler
* @param charId The character this vocal track will be for. * @param charId The character this vocal track will be for.
* @param instId The instrumental this vocal track will be for. * @param instId The instrumental this vocal track will be for.
*/ */
public static function loadInstFromBytes(state:ChartEditorState, bytes:Bytes, instId:String = ''):Bool public static function loadInstFromBytes(state:ChartEditorState, bytes:Bytes, instId:String = '', wipeFirst:Bool = false):Bool
{ {
if (instId == '') instId = 'default'; if (instId == '') instId = 'default';
if (wipeFirst) wipeInstrumentalData(state);
state.audioInstTrackData.set(instId, bytes); state.audioInstTrackData.set(instId, bytes);
return true; return true;
} }
@ -127,9 +130,9 @@ class ChartEditorAudioHandler
stopExistingVocals(state); stopExistingVocals(state);
result = playVocals(state, BF, playerId, instId); result = playVocals(state, BF, playerId, instId);
if (!result) return false; // if (!result) return false;
result = playVocals(state, DAD, opponentId, instId); result = playVocals(state, DAD, opponentId, instId);
if (!result) return false; // if (!result) return false;
return true; return true;
} }

View file

@ -758,14 +758,9 @@ class ChartEditorDialogHandler
trace('Selected file: $pathStr'); trace('Selected file: $pathStr');
var path:Path = new Path(pathStr); var path:Path = new Path(pathStr);
if (!hasClearedVocals) if (state.loadVocalsFromPath(path, charKey, instId, !hasClearedVocals))
{ {
hasClearedVocals = true; hasClearedVocals = true;
state.stopExistingVocals();
}
if (state.loadVocalsFromPath(path, charKey, instId))
{
// Tell the user the load was successful. // Tell the user the load was successful.
state.success('Loaded Vocals', 'Loaded vocals for $charName (${path.file}.${path.ext}), variation ${state.selectedVariation}'); state.success('Loaded Vocals', 'Loaded vocals for $charName (${path.file}.${path.ext}), variation ${state.selectedVariation}');
#if FILE_DROP_SUPPORTED #if FILE_DROP_SUPPORTED
@ -799,13 +794,10 @@ class ChartEditorDialogHandler
if (selectedFile != null && selectedFile.bytes != null) if (selectedFile != null && selectedFile.bytes != null)
{ {
trace('Selected file: ' + selectedFile.name); trace('Selected file: ' + selectedFile.name);
if (!hasClearedVocals)
if (state.loadVocalsFromBytes(selectedFile.bytes, charKey, instId, !hasClearedVocals))
{ {
hasClearedVocals = true; hasClearedVocals = true;
state.stopExistingVocals();
}
if (state.loadVocalsFromBytes(selectedFile.bytes, charKey, instId))
{
// Tell the user the load was successful. // Tell the user the load was successful.
state.success('Loaded Vocals', 'Loaded vocals for $charName (${selectedFile.name}), variation ${state.selectedVariation}'); state.success('Loaded Vocals', 'Loaded vocals for $charName (${selectedFile.name}), variation ${state.selectedVariation}');