From 9ac12ca44367915fa92a8d8f54b686039dee16af Mon Sep 17 00:00:00 2001 From: OliBomby Date: Tue, 19 Dec 2023 19:48:45 +0100 Subject: [PATCH] Add 'Bulk assign samples' option in Hitsound Studio. --- Mapping_Tools/Classes/SystemTools/IOHelper.cs | 7 +-- .../HitsoundStudio/HitsoundStudioView.xaml.cs | 51 +++++++++++++++++-- 2 files changed, 52 insertions(+), 6 deletions(-) diff --git a/Mapping_Tools/Classes/SystemTools/IOHelper.cs b/Mapping_Tools/Classes/SystemTools/IOHelper.cs index 2f581bcc..56ebe908 100644 --- a/Mapping_Tools/Classes/SystemTools/IOHelper.cs +++ b/Mapping_Tools/Classes/SystemTools/IOHelper.cs @@ -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) { diff --git a/Mapping_Tools/Views/HitsoundStudio/HitsoundStudioView.xaml.cs b/Mapping_Tools/Views/HitsoundStudio/HitsoundStudioView.xaml.cs index e0f17e25..acca32b9 100644 --- a/Mapping_Tools/Views/HitsoundStudio/HitsoundStudioView.xaml.cs +++ b/Mapping_Tools/Views/HitsoundStudio/HitsoundStudioView.xaml.cs @@ -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) { @@ -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 } } \ No newline at end of file