Skip to content

Commit 2e9abc8

Browse files
committed
SoundFonts paths saving implementation
1 parent 6d728ad commit 2e9abc8

3 files changed

Lines changed: 19 additions & 6 deletions

File tree

Openthesia/ProgramData.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ private class SettingsJson
1818
public string InputDevice;
1919
public string OutputDevice;
2020
public List<string> MidiPaths = new();
21+
public List<string> SoundFontsPaths = new();
2122
public bool KeyboardInput;
2223
public bool AnimatedBackground;
2324
public bool NeonFx;
@@ -86,6 +87,7 @@ public static void LoadSettings()
8687
}
8788

8889
Settings.SetMidiPaths(storedSettings.MidiPaths);
90+
Settings.SetSoundFontsPaths(storedSettings.SoundFontsPaths);
8991
Settings.SetKeyboardInput(storedSettings.KeyboardInput);
9092
Settings.SetAnimatedBackground(storedSettings.AnimatedBackground);
9193
Settings.SetNeonFx(storedSettings.NeonFx);
@@ -125,6 +127,7 @@ public static void SaveSettings()
125127
InputDevice = Settings.IDevice?.Name,
126128
OutputDevice = Settings.ODevice?.Name,
127129
MidiPaths = Settings.MidiPaths,
130+
SoundFontsPaths = Settings.SoundFontsPaths,
128131
KeyboardInput = Settings.KeyboardInput,
129132
AnimatedBackground = Settings.AnimatedBackground,
130133
NeonFx = Settings.NeonFx,

Openthesia/ScreenCanvas.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ public static void RenderScreen(bool playMode = false)
10231023
_comboSoundFont = true;
10241024
foreach (var folderPath in Settings.SoundFontsPaths)
10251025
{
1026-
foreach (var soundFontPath in Directory.GetFiles(folderPath))
1026+
foreach (var soundFontPath in Directory.GetFiles(folderPath).Where(f => Path.GetExtension(f) == ".sf2"))
10271027
{
10281028
if (ImGui.Selectable(Path.GetFileNameWithoutExtension(soundFontPath)))
10291029
{

Openthesia/Settings.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public class Settings
2222

2323
public static List<string> MidiPaths { get { return _midiPaths; } }
2424

25-
2625
private static List<string> _soundFontsPaths = new()
2726
{
2827
Path.Combine(Path.GetDirectoryName(Environment.ProcessPath), "SoundFonts"),
@@ -70,9 +69,20 @@ public enum Themes
7069

7170
public static void SetMidiPaths(List<string> paths)
7271
{
72+
if (paths.Count == 0)
73+
return;
74+
7375
_midiPaths = paths;
7476
}
7577

78+
public static void SetSoundFontsPaths(List<string> paths)
79+
{
80+
if (paths.Count == 0)
81+
return;
82+
83+
_soundFontsPaths = paths;
84+
}
85+
7686
public static void SetKeyboardInput(bool onoff)
7787
{
7888
_keyboardInput = onoff;
@@ -346,11 +356,11 @@ public static void Render()
346356
ImGui.EndTable();
347357

348358
ImGui.SetCursorPosX(ImGui.GetContentRegionAvail().X - 100 * FontController.DSF);
349-
if (ImGui.Button(FontAwesome6.FolderPlus, new Vector2(100, 50) * FontController.DSF))
359+
if (ImGui.Button($"{FontAwesome6.FolderPlus}##addMidiPath", new Vector2(100, 50) * FontController.DSF))
350360
{
351361
var dlg = new FolderPicker();
352362
dlg.InputPath = "C:\\";
353-
if (dlg.ShowDialog(Program._window.SdlWindowHandle) == true)
363+
if (dlg.ShowDialog(Program._window.Handle) == true)
354364
{
355365
if (_midiPaths.Contains(dlg.ResultPath))
356366
{
@@ -435,11 +445,11 @@ public static void Render()
435445
ImGui.EndTable();
436446

437447
ImGui.SetCursorPosX(ImGui.GetContentRegionAvail().X - 100 * FontController.DSF);
438-
if (ImGui.Button($"{FontAwesome6.Folder}", new Vector2(100, 50) * FontController.DSF))
448+
if (ImGui.Button($"{FontAwesome6.FolderPlus}##addSoundPath", new Vector2(100, 50) * FontController.DSF))
439449
{
440450
var dlg = new FolderPicker();
441451
dlg.InputPath = "C:\\";
442-
if (dlg.ShowDialog(Program._window.SdlWindowHandle) == true)
452+
if (dlg.ShowDialog(Program._window.Handle) == true)
443453
{
444454
if (_soundFontsPaths.Contains(dlg.ResultPath))
445455
{

0 commit comments

Comments
 (0)