Skip to content

Commit

Permalink
Add 'Bulk assign samples' option in Hitsound Studio.
Browse files Browse the repository at this point in the history
  • Loading branch information
OliBomby committed Dec 19, 2023
1 parent f45774f commit 9ac12ca
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 6 deletions.
7 changes: 4 additions & 3 deletions Mapping_Tools/Classes/SystemTools/IOHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,16 @@ public static string SampleFileDialog() {
return openFileDialog.FileName;
}

public static string AudioFileDialog() {
public static string[] AudioFileDialog(bool multiselect = false) {
OpenFileDialog openFileDialog = new OpenFileDialog {
Filter = "Audio files (*.wav;*.ogg)|*.wav;*.ogg",
FilterIndex = 1,
RestoreDirectory = true,
CheckFileExists = true
CheckFileExists = true,
Multiselect = multiselect
};
openFileDialog.ShowDialog();
return openFileDialog.FileName;
return openFileDialog.FileNames;
}

public static string[] BeatmapFileDialog(bool multiselect = false, bool restore = false) {
Expand Down
51 changes: 48 additions & 3 deletions Mapping_Tools/Views/HitsoundStudio/HitsoundStudioView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,13 +1152,25 @@ public void SetSaveData(HitsoundStudioVm saveData)
#region IHaveExtraMenuItems members

public MenuItem[] GetMenuItems() {
var menu = new MenuItem {
var loadSampleSchemaMenu = new MenuItem {
Header = "_Load sample schema", Icon = new PackIcon {Kind = PackIconKind.FileMusic},
ToolTip = "Load sample schema from a project file."
};
menu.Click += LoadSampleSchemaFromFile;
loadSampleSchemaMenu.Click += LoadSampleSchemaFromFile;

var bulkAssignSamplesMenu = new MenuItem {
Header = "_Bulk assign samples", Icon = new PackIcon {Kind = PackIconKind.MusicBoxMultiple},
ToolTip = "Bulk assign samples to selected hitsound layers. " +
"The file name is expected to be in the following shape: [bank]_[patch]_[key]_[length]_[velocity].[extension]. " +
"Leave a value empty to imply any value. " +
"Example: 0_39__127.wav"
};
bulkAssignSamplesMenu.Click += BulkAssignSamples;

return new[] {menu};
return new[] {
loadSampleSchemaMenu,
bulkAssignSamplesMenu,
};
}

private void LoadSampleSchemaFromFile(object sender, RoutedEventArgs e) {
Expand All @@ -1173,6 +1185,39 @@ private void LoadSampleSchemaFromFile(object sender, RoutedEventArgs e) {
}
}

private void BulkAssignSamples(object sender, RoutedEventArgs e) {
try {
var result = IOHelper.AudioFileDialog(true);

foreach (string path in result) {
// The file name is expected to be in the following shape:
// [bank]_[patch]_[key]_[length]_[velocity].[extension]
// Example: 0_39_256_100.wav
var fileName = Path.GetFileNameWithoutExtension(path);
var split = fileName.Split('_');
int? bank = split.Length > 0 && int.TryParse(split[0], out var bankParsed) ? bankParsed : null;
int? patch = split.Length > 1 && int.TryParse(split[1], out var patchParsed) ? patchParsed : null;
int? key = split.Length > 2 && int.TryParse(split[2], out var keyParsed) ? keyParsed : null;
int? length = split.Length > 3 && int.TryParse(split[3], out var lengthParsed) ? lengthParsed : null;
int? velocity = split.Length > 4 && int.TryParse(split[4], out var velocityParsed) ? velocityParsed : null;

foreach (var layer in selectedLayers) {
if (bank.HasValue && bank.Value != layer.ImportArgs.Bank) continue;
if (patch.HasValue && patch.Value != layer.ImportArgs.Patch) continue;
if (key.HasValue && key.Value != layer.ImportArgs.Key) continue;
if (length.HasValue && length.Value != (int)Math.Round(layer.ImportArgs.Length)) continue;
if (velocity.HasValue && velocity.Value != layer.ImportArgs.Velocity) continue;

layer.SampleArgs.Path = path;
}
}


} catch (Exception ex) {
ex.Show();
}
}

#endregion
}
}

0 comments on commit 9ac12ca

Please sign in to comment.