public static void Save() { var ini = new IniFile(); // General ini.SetInt("General", "Version", SettingsVersion); ini.SetBool("General", "CheckUpdates", CheckUpdates); ini.SetBool("General", "TrackPadControls", TrackPadControls); ini.SetBool("General", "ShowTutorial", ShowTutorial); ini.SetBool("General", "ClearUndoRedoOnSave", ClearUndoRedoOnSave); ini.SetBool("General", "OpenLastProjectOnStart", OpenLastProjectOnStart); ini.SetString("General", "LastProjectFile", OpenLastProjectOnStart ? LastProjectFile : ""); ini.SetBool("General", "AutoSaveCopy", AutoSaveCopy); // UI ini.SetInt("UI", "DpiScaling", DpiScaling); ini.SetInt("UI", "TimeFormat", TimeFormat); ini.SetInt("UI", "FollowMode", FollowMode); ini.SetInt("UI", "FollowSync", FollowSync); ini.SetBool("UI", "ShowNoteLabels", ShowNoteLabels); ini.SetInt("UI", "ScrollBars", ScrollBars); ini.SetBool("UI", "ShowOscilloscope", ShowOscilloscope); ini.SetBool("UI", "ForceCompactSequencer", ForceCompactSequencer); ini.SetBool("UI", "ShowPianoRollViewRange", ShowPianoRollViewRange); ini.SetInt("UI", "TrackPadMoveSensitity", TrackPadMoveSensitity); ini.SetInt("UI", "TrackPadZoomSensitity", TrackPadZoomSensitity); ini.SetBool("UI", "ReverseTrackPad", ReverseTrackPad); ini.SetBool("UI", "ShowImplicitStopNotes", ShowImplicitStopNotes); // Audio ini.SetInt("Audio", "NumBufferedFrames", NumBufferedAudioFrames); ini.SetInt("Audio", "InstrumentStopTime", InstrumentStopTime); ini.SetBool("Audio", "SquareSmoothVibrato", SquareSmoothVibrato); ini.SetBool("Audio", "NoDragSoungWhenPlaying", NoDragSoungWhenPlaying); ini.SetInt("Audio", "MetronomeVolume", MetronomeVolume); ini.SetInt("Audio", "SeparateChannelsExportTndMode", SeparateChannelsExportTndMode); // Mixer ini.SetFloat("Mixer", "GlobalVolume", GlobalVolume); for (int i = 0; i < ExpansionType.Count; i++) { var section = "Mixer" + ExpansionType.ShortNames[i]; ini.SetFloat(section, "Volume", ExpansionMixerSettings[i].volume); ini.SetFloat(section, "Treble", ExpansionMixerSettings[i].treble); } // MIDI ini.SetString("MIDI", "Device", MidiDevice); // Folders ini.SetString("Folders", "LastFileFolder", LastFileFolder); ini.SetString("Folders", "LastInstrumentFolder", LastInstrumentFolder); ini.SetString("Folders", "LastSampleFolder", LastSampleFolder); ini.SetString("Folders", "LastExportFolder", LastExportFolder); // FFmpeg ini.SetString("FFmpeg", "ExecutablePath", FFmpegExecutablePath); // QWERTY // Stop note. { if (QwertyKeys[0, 0] >= 0) { ini.SetInt("QWERTY", "StopNote", QwertyKeys[0, 0]); } if (QwertyKeys[0, 1] >= 0) { ini.SetInt("QWERTY", "StopNoteAlt", QwertyKeys[0, 1]); } } // Regular notes. for (int idx = 1; idx < QwertyKeys.GetLength(0); idx++) { var octave = (idx - 1) / 12; var note = (idx - 1) % 12; var keyName0 = $"Octave{octave}Note{note}"; var keyName1 = $"Octave{octave}Note{note}Alt"; if (QwertyKeys[idx, 0] >= 0) { ini.SetInt("QWERTY", keyName0, QwertyKeys[idx, 0]); } if (QwertyKeys[idx, 1] >= 0) { ini.SetInt("QWERTY", keyName1, QwertyKeys[idx, 1]); } } // Mobile ini.SetBool("Mobile", "AllowVibration", AllowVibration); ini.SetBool("Mobile", "DoubleClickDelete", DoubleClickDelete); Directory.CreateDirectory(GetConfigFilePath()); ini.Save(GetConfigFileName()); }
public static void Load() { var ini = new IniFile(); ini.Load(GetConfigFileName()); Version = ini.GetInt("General", "Version", 0); // General CheckUpdates = ini.GetBool(Version < 2 ? "UI" : "General", "CheckUpdates", true); // At version 2 (FamiStudio 3.0.0, changed section) TrackPadControls = ini.GetBool(Version < 2 ? "UI" : "General", "TrackPadControls", false); // At version 2 (FamiStudio 3.0.0, changed section) ShowTutorial = ini.GetBool(Version < 2 ? "UI" : "General", "ShowTutorial", true); // At version 2 (FamiStudio 3.0.0, changed section) ClearUndoRedoOnSave = ini.GetBool("General", "ClearUndoRedoOnSave", true); OpenLastProjectOnStart = ini.GetBool("General", "OpenLastProjectOnStart", true); AutoSaveCopy = ini.GetBool("General", "AutoSaveCopy", true); LastProjectFile = OpenLastProjectOnStart ? ini.GetString("General", "LastProjectFile", "") : ""; // UI DpiScaling = ini.GetInt("UI", "DpiScaling", 0); TimeFormat = ini.GetInt("UI", "TimeFormat", 0); FollowMode = ini.GetInt("UI", "FollowMode", FollowModeContinuous); FollowSync = ini.GetInt("UI", "FollowSync", FollowSyncBoth); ShowNoteLabels = ini.GetBool("UI", "ShowNoteLabels", true); ScrollBars = Version < 3 ? (ini.GetBool("UI", "ShowScrollBars", false) ? ScrollBarsThin : ScrollBarsNone) : ini.GetInt("UI", "ScrollBars", ScrollBarsNone); ShowOscilloscope = ini.GetBool("UI", "ShowOscilloscope", true); ForceCompactSequencer = ini.GetBool("UI", "ForceCompactSequencer", false); ShowPianoRollViewRange = ini.GetBool("UI", "ShowPianoRollViewRange", true); ReverseTrackPad = ini.GetBool("UI", "ReverseTrackPad", false); TrackPadMoveSensitity = ini.GetInt("UI", "TrackPadMoveSensitity", 1); TrackPadZoomSensitity = ini.GetInt("UI", "TrackPadZoomSensitity", 8); ShowImplicitStopNotes = ini.GetBool("UI", "ShowImplicitStopNotes", true); // Audio NumBufferedAudioFrames = ini.GetInt("Audio", "NumBufferedFrames", DefaultNumBufferedAudioFrames); InstrumentStopTime = ini.GetInt("Audio", "InstrumentStopTime", 2); SquareSmoothVibrato = ini.GetBool("Audio", "SquareSmoothVibrato", true); NoDragSoungWhenPlaying = ini.GetBool("Audio", "NoDragSoungWhenPlaying", false); MetronomeVolume = ini.GetInt("Audio", "MetronomeVolume", 50); SeparateChannelsExportTndMode = ini.GetInt("Audio", "SeparateChannelsExportTndMode", NesApu.TND_MODE_SINGLE); // MIDI MidiDevice = ini.GetString("MIDI", "Device", ""); // Folders LastFileFolder = ini.GetString("Folders", "LastFileFolder", ""); LastInstrumentFolder = ini.GetString("Folders", "LastInstrumentFolder", ""); LastSampleFolder = ini.GetString("Folders", "LastSampleFolder", ""); LastExportFolder = ini.GetString("Folders", "LastExportFolder", ""); // FFmpeg FFmpegExecutablePath = ini.GetString("FFmpeg", "ExecutablePath", ""); // Mixer. GlobalVolume = ini.GetFloat("Mixer", "GlobalVolume", -3.0f); Array.Copy(DefaultExpansionMixerSettings, ExpansionMixerSettings, ExpansionMixerSettings.Length); for (int i = 0; i < ExpansionType.Count; i++) { var section = "Mixer" + ExpansionType.ShortNames[i]; ExpansionMixerSettings[i].volume = ini.GetFloat(section, "Volume", DefaultExpansionMixerSettings[i].volume); ExpansionMixerSettings[i].treble = ini.GetFloat(section, "Treble", DefaultExpansionMixerSettings[i].treble); } // QWERTY Array.Copy(DefaultQwertyKeys, QwertyKeys, DefaultQwertyKeys.Length); // Stop note. { if (ini.HasKey("QWERTY", "StopNote")) { QwertyKeys[0, 0] = ini.GetInt("QWERTY", "StopNote", QwertyKeys[0, 0]); } if (ini.HasKey("QWERTY", "StopNoteAlt")) { QwertyKeys[0, 1] = ini.GetInt("QWERTY", "StopNoteAlt", QwertyKeys[0, 1]); } } // Regular notes. for (int idx = 1; idx < QwertyKeys.GetLength(0); idx++) { var octave = (idx - 1) / 12; var note = (idx - 1) % 12; var keyName0 = $"Octave{octave}Note{note}"; var keyName1 = $"Octave{octave}Note{note}Alt"; if (ini.HasKey("QWERTY", keyName0)) { QwertyKeys[idx, 0] = ini.GetInt("QWERTY", keyName0, QwertyKeys[idx, 0]); } if (ini.HasKey("QWERTY", keyName1)) { QwertyKeys[idx, 1] = ini.GetInt("QWERTY", keyName1, QwertyKeys[idx, 1]); } } UpdateKeyCodeMaps(); if (Array.IndexOf(global::FamiStudio.DpiScaling.GetAvailableScalings(), DpiScaling) < 0) { DpiScaling = 0; } InstrumentStopTime = Utils.Clamp(InstrumentStopTime, 0, 10); if (MidiDevice == null) { MidiDevice = ""; } if (!Directory.Exists(LastInstrumentFolder)) { LastInstrumentFolder = ""; } if (!Directory.Exists(LastSampleFolder)) { LastSampleFolder = ""; } if (!Directory.Exists(LastExportFolder)) { LastExportFolder = ""; } // Try to point to the demo songs initially. if (string.IsNullOrEmpty(LastFileFolder) || !Directory.Exists(LastFileFolder)) { var appPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var demoSongsPath = Path.Combine(appPath, "Demo Songs"); LastFileFolder = Directory.Exists(demoSongsPath) ? demoSongsPath : ""; } // Clamp to something reasonable. NumBufferedAudioFrames = Utils.Clamp(NumBufferedAudioFrames, 2, 16); // Linux or Mac is more likely to have standard path for ffmpeg. if (PlatformUtils.IsLinux || PlatformUtils.IsMacOS) { if (string.IsNullOrEmpty(FFmpegExecutablePath) || !File.Exists(FFmpegExecutablePath)) { if (File.Exists("/usr/bin/ffmpeg")) { FFmpegExecutablePath = "/usr/bin/ffmpeg"; } else if (File.Exists("/usr/local/bin/ffmpeg")) { FFmpegExecutablePath = "/usr/local/bin/ffmpeg"; } else { FFmpegExecutablePath = "ffmpeg"; // Hope for the best! } } } // Mobile section AllowVibration = ini.GetBool("Mobile", "AllowVibration", true); DoubleClickDelete = ini.GetBool("Mobile", "DoubleClickDelete", false); // At 3.2.0, we added a new Discord screen to the tutorial. if (Version < 4) { ShowTutorial = true; } // No deprecation at the moment. Version = SettingsVersion; }