TrackerSettings.cpp 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605
  1. /*
  2. * TrackerSettings.cpp
  3. * -------------------
  4. * Purpose: Code for managing, loading and saving all applcation settings.
  5. * Notes : (currently none)
  6. * Authors: Olivier Lapicque
  7. * OpenMPT Devs
  8. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  9. */
  10. #include "stdafx.h"
  11. #include "Mptrack.h"
  12. #include "Moddoc.h"
  13. #include "Mainfrm.h"
  14. #include "mpt/environment/environment.hpp"
  15. #include "mpt/uuid/uuid.hpp"
  16. #include "openmpt/sounddevice/SoundDevice.hpp"
  17. #include "openmpt/sounddevice/SoundDeviceManager.hpp"
  18. #include "../common/version.h"
  19. #include "UpdateCheck.h"
  20. #include "Mpdlgs.h"
  21. #include "../common/mptStringBuffer.h"
  22. #include "TrackerSettings.h"
  23. #include "../common/misc_util.h"
  24. #include "PatternClipboard.h"
  25. #include "../common/ComponentManager.h"
  26. #include "ExceptionHandler.h"
  27. #include "../soundlib/mod_specifications.h"
  28. #include "../soundlib/Tables.h"
  29. #include "../common/mptFileIO.h"
  30. #include "../soundlib/tuningcollection.h"
  31. #include "TuningDialog.h"
  32. #include <algorithm>
  33. OPENMPT_NAMESPACE_BEGIN
  34. #define OLD_SOUNDSETUP_REVERSESTEREO 0x20
  35. #define OLD_SOUNDSETUP_SECONDARY 0x40
  36. #define OLD_SOUNDSETUP_NOBOOSTTHREADPRIORITY 0x80
  37. #ifndef NO_EQ
  38. constexpr EQPreset FlatEQPreset = {"Flat", {16, 16, 16, 16, 16, 16}, {125, 300, 600, 1250, 4000, 8000}};
  39. #endif // !NO_EQ
  40. TrackerSettings &TrackerSettings::Instance()
  41. {
  42. return theApp.GetTrackerSettings();
  43. }
  44. static Version GetPreviousSettingsVersion(const mpt::ustring &iniVersion)
  45. {
  46. if(!iniVersion.empty())
  47. {
  48. return Version::Parse(iniVersion);
  49. } else
  50. {
  51. // No version stored.
  52. // This is the first run, thus set the previous version to our current
  53. // version which will avoid running all settings upgrade code.
  54. return Version::Current();
  55. }
  56. }
  57. mpt::ustring SettingsModTypeToString(MODTYPE modtype)
  58. {
  59. return mpt::ToUnicode(mpt::Charset::UTF8, CSoundFile::GetModSpecifications(modtype).fileExtension);
  60. }
  61. MODTYPE SettingsStringToModType(const mpt::ustring &str)
  62. {
  63. return CModSpecifications::ExtensionToType(mpt::ToCharset(mpt::Charset::UTF8, str));
  64. }
  65. static uint32 GetDefaultPatternSetup()
  66. {
  67. return PATTERN_PLAYNEWNOTE | PATTERN_EFFECTHILIGHT
  68. | PATTERN_CENTERROW | PATTERN_DRAGNDROPEDIT
  69. | PATTERN_FLATBUTTONS | PATTERN_NOEXTRALOUD | PATTERN_2NDHIGHLIGHT
  70. | PATTERN_STDHIGHLIGHT | PATTERN_SHOWPREVIOUS | PATTERN_CONTSCROLL
  71. | PATTERN_SYNCMUTE | PATTERN_AUTODELAY | PATTERN_NOTEFADE
  72. | PATTERN_SHOWDEFAULTVOLUME | PATTERN_LIVEUPDATETREE | PATTERN_SYNCSAMPLEPOS;
  73. }
  74. void SampleUndoBufferSize::CalculateSize()
  75. {
  76. if(sizePercent < 0)
  77. sizePercent = 0;
  78. MEMORYSTATUSEX memStatus;
  79. memStatus.dwLength = sizeof(MEMORYSTATUSEX);
  80. GlobalMemoryStatusEx(&memStatus);
  81. // The setting is a percentage of the memory that's actually *available* to OpenMPT, which is a max of 4GB in 32-bit mode.
  82. sizeByte = mpt::saturate_cast<size_t>(std::min(memStatus.ullTotalPhys, DWORDLONG(SIZE_T_MAX)) * sizePercent / 100);
  83. // Pretend there's at least one MiB of memory (haha)
  84. if(sizePercent != 0 && sizeByte < 1 * 1024 * 1024)
  85. {
  86. sizeByte = 1 * 1024 * 1024;
  87. }
  88. }
  89. DebugSettings::DebugSettings(SettingsContainer &conf)
  90. : conf(conf)
  91. // Debug
  92. #if !defined(MPT_LOG_IS_DISABLED)
  93. , DebugLogLevel(conf, U_("Debug"), U_("LogLevel"), static_cast<int>(mpt::log::GlobalLogLevel))
  94. , DebugLogFacilitySolo(conf, U_("Debug"), U_("LogFacilitySolo"), std::string())
  95. , DebugLogFacilityBlocked(conf, U_("Debug"), U_("LogFacilityBlocked"), std::string())
  96. , DebugLogFileEnable(conf, U_("Debug"), U_("LogFileEnable"), mpt::log::FileEnabled)
  97. , DebugLogDebuggerEnable(conf, U_("Debug"), U_("LogDebuggerEnable"), mpt::log::DebuggerEnabled)
  98. , DebugLogConsoleEnable(conf, U_("Debug"), U_("LogConsoleEnable"), mpt::log::ConsoleEnabled)
  99. #endif
  100. , DebugTraceEnable(conf, U_("Debug"), U_("TraceEnable"), false)
  101. , DebugTraceSize(conf, U_("Debug"), U_("TraceSize"), 1000000)
  102. , DebugTraceAlwaysDump(conf, U_("Debug"), U_("TraceAlwaysDump"), false)
  103. , DebugStopSoundDeviceOnCrash(conf, U_("Debug"), U_("StopSoundDeviceOnCrash"), true)
  104. , DebugStopSoundDeviceBeforeDump(conf, U_("Debug"), U_("StopSoundDeviceBeforeDump"), false)
  105. , DebugDelegateToWindowsHandler(conf, U_("Debug"), U_("DelegateToWindowsHandler"), false)
  106. {
  107. // Duplicate state for debug stuff in order to avoid calling into settings framework from crash context.
  108. ExceptionHandler::stopSoundDeviceOnCrash = DebugStopSoundDeviceOnCrash;
  109. ExceptionHandler::stopSoundDeviceBeforeDump = DebugStopSoundDeviceBeforeDump;
  110. ExceptionHandler::delegateToWindowsHandler = DebugDelegateToWindowsHandler;
  111. // enable debug features (as early as possible after reading the settings)
  112. #if !defined(MPT_LOG_IS_DISABLED)
  113. #if !defined(MPT_LOG_GLOBAL_LEVEL_STATIC)
  114. mpt::log::GlobalLogLevel = DebugLogLevel;
  115. #endif
  116. mpt::log::SetFacilities(DebugLogFacilitySolo, DebugLogFacilityBlocked);
  117. mpt::log::FileEnabled = DebugLogFileEnable;
  118. mpt::log::DebuggerEnabled = DebugLogDebuggerEnable;
  119. mpt::log::ConsoleEnabled = DebugLogConsoleEnable;
  120. #endif
  121. if(DebugTraceEnable)
  122. {
  123. mpt::log::Trace::Enable(DebugTraceSize);
  124. }
  125. }
  126. DebugSettings::~DebugSettings()
  127. {
  128. if(DebugTraceAlwaysDump)
  129. {
  130. DebugTraceDump();
  131. }
  132. }
  133. TrackerSettings::TrackerSettings(SettingsContainer &conf)
  134. : conf(conf)
  135. // Version
  136. , IniVersion(conf, U_("Version"), U_("Version"), mpt::ustring())
  137. , FirstRun(IniVersion.Get() == mpt::ustring())
  138. , PreviousSettingsVersion(GetPreviousSettingsVersion(IniVersion))
  139. , VersionInstallGUID(conf, U_("Version"), U_("InstallGUID"), mpt::UUID())
  140. // Display
  141. , m_ShowSplashScreen(conf, U_("Display"), U_("ShowSplashScreen"), true)
  142. , gbMdiMaximize(conf, U_("Display"), U_("MDIMaximize"), true)
  143. , highResUI(conf, U_("Display"), U_("HighResUI"), false)
  144. , glTreeSplitRatio(conf, U_("Display"), U_("MDITreeRatio"), 128)
  145. , glTreeWindowWidth(conf, U_("Display"), U_("MDITreeWidth"), 160)
  146. , glGeneralWindowHeight(conf, U_("Display"), U_("MDIGeneralHeight"), 222)
  147. , glPatternWindowHeight(conf, U_("Display"), U_("MDIPatternHeight"), 152)
  148. , glSampleWindowHeight(conf, U_("Display"), U_("MDISampleHeight"), 190)
  149. , glInstrumentWindowHeight(conf, U_("Display"), U_("MDIInstrumentHeight"), 300)
  150. , glCommentsWindowHeight(conf, U_("Display"), U_("MDICommentsHeight"), 288)
  151. , glGraphWindowHeight(conf, U_("Display"), U_("MDIGraphHeight"), 288)
  152. , gnPlugWindowX(conf, U_("Display"), U_("PlugSelectWindowX"), 243)
  153. , gnPlugWindowY(conf, U_("Display"), U_("PlugSelectWindowY"), 273)
  154. , gnPlugWindowWidth(conf, U_("Display"), U_("PlugSelectWindowWidth"), 450)
  155. , gnPlugWindowHeight(conf, U_("Display"), U_("PlugSelectWindowHeight"), 540)
  156. , gnPlugWindowLast(conf, U_("Display"), U_("PlugSelectWindowLast"), 0)
  157. , gnMsgBoxVisiblityFlags(conf, U_("Display"), U_("MsgBoxVisibilityFlags"), uint32_max)
  158. , GUIUpdateInterval(conf, U_("Display"), U_("GUIUpdateInterval"), 0)
  159. , FSUpdateInterval(conf, U_("Display"), U_("FSUpdateInterval"), 500)
  160. , VuMeterUpdateInterval(conf, U_("Display"), U_("VuMeterUpdateInterval"), 15)
  161. , VuMeterDecaySpeedDecibelPerSecond(conf, U_("Display"), U_("VuMeterDecaySpeedDecibelPerSecond"), 88.0f)
  162. , accidentalFlats(conf, U_("Display"), U_("AccidentalFlats"), false)
  163. , rememberSongWindows(conf, U_("Display"), U_("RememberSongWindows"), true)
  164. , showDirsInSampleBrowser(conf, U_("Display"), U_("ShowDirsInSampleBrowser"), false)
  165. , commentsFont(conf, U_("Display"), U_("Comments Font"), FontSetting(U_("Courier New"), 120))
  166. , defaultRainbowChannelColors(conf, U_("Display"), U_("DefaultChannelColors"), DefaultChannelColors::Random)
  167. // Misc
  168. , defaultModType(conf, U_("Misc"), U_("DefaultModType"), MOD_TYPE_IT)
  169. , defaultNewFileAction(conf, U_("Misc"), U_("DefaultNewFileAction"), nfDefaultFormat)
  170. , DefaultPlugVolumeHandling(conf, U_("Misc"), U_("DefaultPlugVolumeHandling"), PLUGIN_VOLUMEHANDLING_IGNORE)
  171. , autoApplySmoothFT2Ramping(conf, U_("Misc"), U_("SmoothFT2Ramping"), false)
  172. , MiscITCompressionStereo(conf, U_("Misc"), U_("ITCompressionStereo"), 4)
  173. , MiscITCompressionMono(conf, U_("Misc"), U_("ITCompressionMono"), 4)
  174. , MiscSaveChannelMuteStatus(conf, U_("Misc"), U_("SaveChannelMuteStatus"), true)
  175. , MiscAllowMultipleCommandsPerKey(conf, U_("Misc"), U_("AllowMultipleCommandsPerKey"), false)
  176. , MiscDistinguishModifiers(conf, U_("Misc"), U_("DistinguishModifiers"), false)
  177. , MiscProcessPriorityClass(conf, U_("Misc"), U_("ProcessPriorityClass"), ProcessPriorityClassNORMAL)
  178. , MiscFlushFileBuffersOnSave(conf, U_("Misc"), U_("FlushFileBuffersOnSave"), true)
  179. , MiscCacheCompleteFileBeforeLoading(conf, U_("Misc"), U_("CacheCompleteFileBeforeLoading"), false)
  180. , MiscUseSingleInstance(conf, U_("Misc"), U_("UseSingleInstance"), false)
  181. // Sound Settings
  182. , m_SoundShowRecordingSettings(false)
  183. , m_SoundShowDeprecatedDevices(conf, U_("Sound Settings"), U_("ShowDeprecatedDevices"), false)
  184. , m_SoundDeprecatedDeviceWarningShown(conf, U_("Sound Settings"), U_("DeprecatedDeviceWarningShown"), false)
  185. , m_SoundSampleRates(conf, U_("Sound Settings"), U_("SampleRates"), GetDefaultSampleRates())
  186. , m_SoundSettingsOpenDeviceAtStartup(conf, U_("Sound Settings"), U_("OpenDeviceAtStartup"), false)
  187. , m_SoundSettingsStopMode(conf, U_("Sound Settings"), U_("StopMode"), SoundDeviceStopModeClosed)
  188. , m_SoundDeviceSettingsUseOldDefaults(false)
  189. , m_SoundDeviceID_DEPRECATED(SoundDevice::Legacy::ID())
  190. , m_SoundDeviceIdentifier(conf, U_("Sound Settings"), U_("Device"), SoundDevice::Identifier())
  191. , MixerMaxChannels(conf, U_("Sound Settings"), U_("MixChannels"), MixerSettings().m_nMaxMixChannels)
  192. , MixerDSPMask(conf, U_("Sound Settings"), U_("Quality"), MixerSettings().DSPMask)
  193. , MixerFlags(conf, U_("Sound Settings"), U_("SoundSetup"), MixerSettings().MixerFlags)
  194. , MixerSamplerate(conf, U_("Sound Settings"), U_("Mixing_Rate"), MixerSettings().gdwMixingFreq)
  195. , MixerOutputChannels(conf, U_("Sound Settings"), U_("ChannelMode"), MixerSettings().gnChannels)
  196. , MixerPreAmp(conf, U_("Sound Settings"), U_("PreAmp"), MixerSettings().m_nPreAmp)
  197. , MixerStereoSeparation(conf, U_("Sound Settings"), U_("StereoSeparation"), MixerSettings().m_nStereoSeparation)
  198. , MixerVolumeRampUpMicroseconds(conf, U_("Sound Settings"), U_("VolumeRampUpMicroseconds"), MixerSettings().GetVolumeRampUpMicroseconds())
  199. , MixerVolumeRampDownMicroseconds(conf, U_("Sound Settings"), U_("VolumeRampDownMicroseconds"), MixerSettings().GetVolumeRampDownMicroseconds())
  200. , MixerNumInputChannels(conf, U_("Sound Settings"), U_("NumInputChannels"), static_cast<uint32>(MixerSettings().NumInputChannels))
  201. , ResamplerMode(conf, U_("Sound Settings"), U_("SrcMode"), CResamplerSettings().SrcMode)
  202. , ResamplerSubMode(conf, U_("Sound Settings"), U_("XMMSModplugResamplerWFIRType"), CResamplerSettings().gbWFIRType)
  203. , ResamplerCutoffPercent(conf, U_("Sound Settings"), U_("ResamplerWFIRCutoff"), mpt::saturate_round<int32>(CResamplerSettings().gdWFIRCutoff * 100.0))
  204. , ResamplerEmulateAmiga(conf, U_("Sound Settings"), U_("ResamplerEmulateAmiga"), Resampling::AmigaFilter::A1200)
  205. , SoundBoostedThreadPriority(conf, U_("Sound Settings"), U_("BoostedThreadPriority"), SoundDevice::AppInfo().BoostedThreadPriorityXP)
  206. , SoundBoostedThreadMMCSSClass(conf, U_("Sound Settings"), U_("BoostedThreadMMCSSClass"), SoundDevice::AppInfo().BoostedThreadMMCSSClassVista)
  207. , SoundBoostedThreadRealtimePosix(conf, U_("Sound Settings"), U_("BoostedThreadRealtimeLinux"), SoundDevice::AppInfo().BoostedThreadRealtimePosix)
  208. , SoundBoostedThreadNicenessPosix(conf, U_("Sound Settings"), U_("BoostedThreadNicenessPosix"), SoundDevice::AppInfo().BoostedThreadNicenessPosix)
  209. , SoundBoostedThreadRtprioPosix(conf, U_("Sound Settings"), U_("BoostedThreadRtprioLinux"), SoundDevice::AppInfo().BoostedThreadRtprioPosix)
  210. , SoundMaskDriverCrashes(conf, U_("Sound Settings"), U_("MaskDriverCrashes"), SoundDevice::AppInfo().MaskDriverCrashes)
  211. , SoundAllowDeferredProcessing(conf, U_("Sound Settings"), U_("AllowDeferredProcessing"), SoundDevice::AppInfo().AllowDeferredProcessing)
  212. // MIDI Settings
  213. , m_nMidiDevice(conf, U_("MIDI Settings"), U_("MidiDevice"), 0)
  214. , midiDeviceName(conf, U_("MIDI Settings"), U_("MidiDeviceName"), _T(""))
  215. , m_dwMidiSetup(conf, U_("MIDI Settings"), U_("MidiSetup"), MIDISETUP_RECORDVELOCITY | MIDISETUP_RECORDNOTEOFF | MIDISETUP_TRANSPOSEKEYBOARD | MIDISETUP_MIDITOPLUG)
  216. , aftertouchBehaviour(conf, U_("MIDI Settings"), U_("AftertouchBehaviour"), atDoNotRecord)
  217. , midiVelocityAmp(conf, U_("MIDI Settings"), U_("MidiVelocityAmp"), 100)
  218. , midiIgnoreCCs(conf, U_("MIDI Settings"), U_("IgnoredCCs"), std::bitset<128>())
  219. , midiImportPatternLen(conf, U_("MIDI Settings"), U_("MidiImportPatLen"), 128)
  220. , midiImportQuantize(conf, U_("MIDI Settings"), U_("MidiImportQuantize"), 32)
  221. , midiImportTicks(conf, U_("MIDI Settings"), U_("MidiImportTicks"), 6)
  222. // Pattern Editor
  223. , gbLoopSong(conf, U_("Pattern Editor"), U_("LoopSong"), true)
  224. , gnPatternSpacing(conf, U_("Pattern Editor"), U_("Spacing"), 0)
  225. , gbPatternVUMeters(conf, U_("Pattern Editor"), U_("VU-Meters"), true)
  226. , gbPatternPluginNames(conf, U_("Pattern Editor"), U_("Plugin-Names"), true)
  227. , gbPatternRecord(conf, U_("Pattern Editor"), U_("Record"), true)
  228. , patternNoEditPopup(conf, U_("Pattern Editor"), U_("NoEditPopup"), false)
  229. , patternStepCommands(conf, U_("Pattern Editor"), U_("EditStepAppliesToCommands"), false)
  230. , m_dwPatternSetup(conf, U_("Pattern Editor"), U_("PatternSetup"), GetDefaultPatternSetup())
  231. , m_nRowHighlightMeasures(conf, U_("Pattern Editor"), U_("RowSpacing"), 16)
  232. , m_nRowHighlightBeats(conf, U_("Pattern Editor"), U_("RowSpacing2"), 4)
  233. , recordQuantizeRows(conf, U_("Pattern Editor"), U_("RecordQuantize"), 0)
  234. , gnAutoChordWaitTime(conf, U_("Pattern Editor"), U_("AutoChordWaitTime"), 60)
  235. , orderlistMargins(conf, U_("Pattern Editor"), U_("DefaultSequenceMargins"), 0)
  236. , rowDisplayOffset(conf, U_("Pattern Editor"), U_("RowDisplayOffset"), 0)
  237. , patternFont(conf, U_("Pattern Editor"), U_("Font"), FontSetting(PATTERNFONT_SMALL, 0))
  238. , patternFontDot(conf, U_("Pattern Editor"), U_("FontDot"), U_("."))
  239. , effectVisWidth(conf, U_("Pattern Editor"), U_("EffectVisWidth"), -1)
  240. , effectVisHeight(conf, U_("Pattern Editor"), U_("EffectVisHeight"), -1)
  241. , effectVisX(conf, U_("Pattern Editor"), U_("EffectVisX"), int32_min)
  242. , effectVisY(conf, U_("Pattern Editor"), U_("EffectVisY"), int32_min)
  243. , patternAccessibilityFormat(conf, U_("Pattern Editor"), U_("AccessibilityFormat"), _T("Row %row%, Channel %channel%, %column_type%: %column_description%"))
  244. , patternAlwaysDrawWholePatternOnScrollSlow(conf, U_("Pattern Editor"), U_("AlwaysDrawWholePatternOnScrollSlow"), false)
  245. , orderListOldDropBehaviour(conf, U_("Pattern Editor"), U_("OrderListOldDropBehaviour"), false)
  246. // Sample Editor
  247. , m_SampleUndoBufferSize(conf, U_("Sample Editor"), U_("UndoBufferSize"), SampleUndoBufferSize())
  248. , sampleEditorKeyBehaviour(conf, U_("Sample Editor"), U_("KeyBehaviour"), seNoteOffOnNewKey)
  249. , m_defaultSampleFormat(conf, U_("Sample Editor"), U_("DefaultFormat"), dfFLAC)
  250. , sampleEditorTimelineFormat(conf, U_("Sample Editor"), U_("TimelineFormat"), TimelineFormat::Seconds)
  251. , sampleEditorDefaultResampler(conf, U_("Sample Editor"), U_("DefaultResampler"), SRCMODE_DEFAULT)
  252. , m_nFinetuneStep(conf, U_("Sample Editor"), U_("FinetuneStep"), 10)
  253. , m_FLACCompressionLevel(conf, U_("Sample Editor"), U_("FLACCompressionLevel"), 5)
  254. , compressITI(conf, U_("Sample Editor"), U_("CompressITI"), true)
  255. , m_MayNormalizeSamplesOnLoad(conf, U_("Sample Editor"), U_("MayNormalizeSamplesOnLoad"), true)
  256. , previewInFileDialogs(conf, U_("Sample Editor"), U_("PreviewInFileDialogs"), false)
  257. , cursorPositionInHex(conf, U_("Sample Editor"), U_("CursorPositionInHex"), false)
  258. // Export
  259. , ExportDefaultToSoundcardSamplerate(conf, U_("Export"), U_("DefaultToSoundcardSamplerate"), true)
  260. , ExportStreamEncoderSettings(conf, U_("Export"))
  261. // Components
  262. , ComponentsLoadOnStartup(conf, U_("Components"), U_("LoadOnStartup"), ComponentManagerSettingsDefault().LoadOnStartup())
  263. , ComponentsKeepLoaded(conf, U_("Components"), U_("KeepLoaded"), ComponentManagerSettingsDefault().KeepLoaded())
  264. // AutoSave
  265. , CreateBackupFiles(conf, U_("AutoSave"), U_("CreateBackupFiles"), true)
  266. , AutosaveEnabled(conf, U_("AutoSave"), U_("Enabled"), true)
  267. , AutosaveIntervalMinutes(conf, U_("AutoSave"), U_("IntervalMinutes"), 10)
  268. , AutosaveHistoryDepth(conf, U_("AutoSave"), U_("BackupHistory"), 3)
  269. , AutosaveUseOriginalPath(conf, U_("AutoSave"), U_("UseOriginalPath"), true)
  270. , AutosavePath(conf, U_("AutoSave"), U_("Path"), mpt::GetTempDirectory())
  271. // Paths
  272. , PathSongs(conf, U_("Paths"), U_("Songs_Directory"), mpt::PathString())
  273. , PathSamples(conf, U_("Paths"), U_("Samples_Directory"), mpt::PathString())
  274. , PathInstruments(conf, U_("Paths"), U_("Instruments_Directory"), mpt::PathString())
  275. , PathPlugins(conf, U_("Paths"), U_("Plugins_Directory"), mpt::PathString())
  276. , PathPluginPresets(conf, U_("Paths"), U_("Plugin_Presets_Directory"), mpt::PathString())
  277. , PathExport(conf, U_("Paths"), U_("Export_Directory"), mpt::PathString())
  278. , PathTunings(theApp.GetConfigPath() + P_("tunings\\"))
  279. , PathUserTemplates(theApp.GetConfigPath() + P_("TemplateModules\\"))
  280. // Default template
  281. , defaultTemplateFile(conf, U_("Paths"), U_("DefaultTemplate"), mpt::PathString())
  282. , defaultArtist(conf, U_("Misc"), U_("DefaultArtist"), mpt::getenv(U_("USERNAME")).value_or(U_("")))
  283. // MRU List
  284. , mruListLength(conf, U_("Misc"), U_("MRUListLength"), 10)
  285. // Plugins
  286. , bridgeAllPlugins(conf, U_("VST Plugins"), U_("BridgeAllPlugins"), false)
  287. , enableAutoSuspend(conf, U_("VST Plugins"), U_("EnableAutoSuspend"), false)
  288. , midiMappingInPluginEditor(conf, U_("VST Plugins"), U_("EnableMidiMappingInEditor"), true)
  289. , pluginProjectPath(conf, U_("VST Plugins"), U_("ProjectPath"), mpt::ustring())
  290. , vstHostProductString(conf, U_("VST Plugins"), U_("HostProductString"), "OpenMPT")
  291. , vstHostVendorString(conf, U_("VST Plugins"), U_("HostVendorString"), "OpenMPT project")
  292. , vstHostVendorVersion(conf, U_("VST Plugins"), U_("HostVendorVersion"), Version::Current().GetRawVersion())
  293. // Broken Plugins Workarounds
  294. , BrokenPluginsWorkaroundVSTMaskAllCrashes(conf, U_("Broken Plugins Workarounds"), U_("VSTMaskAllCrashes"), true) // TODO: really should be false
  295. , BrokenPluginsWorkaroundVSTNeverUnloadAnyPlugin(conf, U_("Broken Plugins Workarounds"), U_("VSTNeverUnloadAnyPlugin"), false)
  296. #if defined(MPT_ENABLE_UPDATE)
  297. // Update
  298. , UpdateEnabled(conf, U_("Update"), U_("Enabled"), true)
  299. , UpdateInstallAutomatically(conf, U_("Update"), U_("InstallAutomatically"), false)
  300. , UpdateLastUpdateCheck(conf, U_("Update"), U_("LastUpdateCheck"), mpt::Date::Unix(time_t()))
  301. , UpdateUpdateCheckPeriod_DEPRECATED(conf, U_("Update"), U_("UpdateCheckPeriod"), 7)
  302. , UpdateIntervalDays(conf, U_("Update"), U_("UpdateCheckIntervalDays"), 7)
  303. , UpdateChannel(conf, U_("Update"), U_("Channel"), UpdateChannelRelease)
  304. , UpdateUpdateURL_DEPRECATED(conf, U_("Update"), U_("UpdateURL"), U_("https://update.openmpt.org/check/$VERSION/$GUID"))
  305. , UpdateAPIURL(conf, U_("Update"), U_("APIURL"), CUpdateCheck::GetDefaultAPIURL())
  306. , UpdateStatisticsConsentAsked(conf, U_("Update"), U_("StatistisConsentAsked"), false)
  307. , UpdateStatistics(conf, U_("Update"), U_("Statistis"), false)
  308. , UpdateSendGUID_DEPRECATED(conf, U_("Update"), U_("SendGUID"), false)
  309. , UpdateShowUpdateHint(conf, U_("Update"), U_("ShowUpdateHint"), true)
  310. , UpdateIgnoreVersion(conf, U_("Update"), U_("IgnoreVersion"), _T(""))
  311. , UpdateSkipSignatureVerificationUNSECURE(conf, U_("Update"), U_("SkipSignatureVerification"), false)
  312. , UpdateSigningKeysRootAnchors(conf, U_("Update"), U_("SigningKeysRootAnchors"), CUpdateCheck::GetDefaultUpdateSigningKeysRootAnchors())
  313. #endif // MPT_ENABLE_UPDATE
  314. // Wine suppport
  315. , WineSupportEnabled(conf, U_("WineSupport"), U_("Enabled"), false)
  316. , WineSupportAlwaysRecompile(conf, U_("WineSupport"), U_("AlwaysRecompile"), false)
  317. , WineSupportAskCompile(conf, U_("WineSupport"), U_("AskCompile"), false)
  318. , WineSupportCompileVerbosity(conf, U_("WineSupport"), U_("CompileVerbosity"), 2) // 0=silent 1=silentmake 2=progresswindow 3=standard 4=verbosemake 5=veryverbosemake 6=msgboxes
  319. , WineSupportForeignOpenMPT(conf, U_("WineSupport"), U_("ForeignOpenMPT"), false)
  320. , WineSupportAllowUnknownHost(conf, U_("WineSupport"), U_("AllowUnknownHost"), false)
  321. , WineSupportEnablePulseAudio(conf, U_("WineSupport"), U_("EnablePulseAudio"), 1)
  322. , WineSupportEnablePortAudio(conf, U_("WineSupport"), U_("EnablePortAudio"), 1)
  323. , WineSupportEnableRtAudio(conf, U_("WineSupport"), U_("EnableRtAudio"), 1)
  324. {
  325. // Effects
  326. #ifndef NO_DSP
  327. m_MegaBassSettings.m_nXBassDepth = conf.Read<int32>(U_("Effects"), U_("XBassDepth"), m_MegaBassSettings.m_nXBassDepth);
  328. m_MegaBassSettings.m_nXBassRange = conf.Read<int32>(U_("Effects"), U_("XBassRange"), m_MegaBassSettings.m_nXBassRange);
  329. #endif
  330. #ifndef NO_REVERB
  331. m_ReverbSettings.m_nReverbDepth = conf.Read<int32>(U_("Effects"), U_("ReverbDepth"), m_ReverbSettings.m_nReverbDepth);
  332. m_ReverbSettings.m_nReverbType = conf.Read<int32>(U_("Effects"), U_("ReverbType"), m_ReverbSettings.m_nReverbType);
  333. #endif
  334. #ifndef NO_DSP
  335. m_SurroundSettings.m_nProLogicDepth = conf.Read<int32>(U_("Effects"), U_("ProLogicDepth"), m_SurroundSettings.m_nProLogicDepth);
  336. m_SurroundSettings.m_nProLogicDelay = conf.Read<int32>(U_("Effects"), U_("ProLogicDelay"), m_SurroundSettings.m_nProLogicDelay);
  337. #endif
  338. #ifndef NO_EQ
  339. m_EqSettings = conf.Read<EQPreset>(U_("Effects"), U_("EQ_Settings"), FlatEQPreset);
  340. const EQPreset userPresets[] =
  341. {
  342. FlatEQPreset,
  343. { "User 1", {16,16,16,16,16,16}, { 150, 350, 700, 1500, 4500, 8000 } },
  344. { "User 2", {16,16,16,16,16,16}, { 200, 400, 800, 1750, 5000, 9000 } },
  345. { "User 3", {16,16,16,16,16,16}, { 250, 450, 900, 2000, 5000, 10000 } }
  346. };
  347. m_EqUserPresets[0] = conf.Read<EQPreset>(U_("Effects"), U_("EQ_User1"), userPresets[0]);
  348. m_EqUserPresets[1] = conf.Read<EQPreset>(U_("Effects"), U_("EQ_User2"), userPresets[1]);
  349. m_EqUserPresets[2] = conf.Read<EQPreset>(U_("Effects"), U_("EQ_User3"), userPresets[2]);
  350. m_EqUserPresets[3] = conf.Read<EQPreset>(U_("Effects"), U_("EQ_User4"), userPresets[3]);
  351. #endif
  352. #ifndef NO_DSP
  353. m_BitCrushSettings.m_Bits = conf.Read<int32>(U_("Effects"), U_("BitCrushBits"), m_BitCrushSettings.m_Bits);
  354. #endif
  355. // Display (Colors)
  356. GetDefaultColourScheme(rgbCustomColors);
  357. for(int ncol = 0; ncol < MAX_MODCOLORS; ncol++)
  358. {
  359. const mpt::ustring colorName = MPT_UFORMAT("Color{}")(mpt::ufmt::dec0<2>(ncol));
  360. rgbCustomColors[ncol] = conf.Read<uint32>(U_("Display"), colorName, rgbCustomColors[ncol]);
  361. }
  362. // Paths
  363. m_szKbdFile = conf.Read<mpt::PathString>(U_("Paths"), U_("Key_Config_File"), mpt::PathString());
  364. conf.Forget(U_("Paths"), U_("Key_Config_File"));
  365. // init old and messy stuff:
  366. // Default chords
  367. MemsetZero(Chords);
  368. for(UINT ichord = 0; ichord < 3 * 12; ichord++)
  369. {
  370. Chords[ichord].key = (uint8)ichord;
  371. Chords[ichord].notes[0] = MPTChord::noNote;
  372. Chords[ichord].notes[1] = MPTChord::noNote;
  373. Chords[ichord].notes[2] = MPTChord::noNote;
  374. if(ichord < 12)
  375. {
  376. // Major Chords
  377. Chords[ichord].notes[0] = (int8)(ichord + 4);
  378. Chords[ichord].notes[1] = (int8)(ichord + 7);
  379. Chords[ichord].notes[2] = (int8)(ichord + 10);
  380. } else if(ichord < 24)
  381. {
  382. // Minor Chords
  383. Chords[ichord].notes[0] = (int8)(ichord - 9);
  384. Chords[ichord].notes[1] = (int8)(ichord - 5);
  385. Chords[ichord].notes[2] = (int8)(ichord - 2);
  386. }
  387. }
  388. // load old and messy stuff:
  389. PatternClipboard::SetClipboardSize(conf.Read<int32>(U_("Pattern Editor"), U_("NumClipboards"), mpt::saturate_cast<int32>(PatternClipboard::GetClipboardSize())));
  390. // Chords
  391. LoadChords(Chords);
  392. // Zxx Macros
  393. MIDIMacroConfig macros;
  394. theApp.GetDefaultMidiMacro(macros);
  395. for(int i = 0; i < kSFxMacros; i++)
  396. {
  397. macros.SFx[i] = conf.Read<std::string>(U_("Zxx Macros"), MPT_UFORMAT("SF{}")(mpt::ufmt::HEX(i)), macros.SFx[i]);
  398. }
  399. for(int i = 0; i < kZxxMacros; i++)
  400. {
  401. macros.Zxx[i] = conf.Read<std::string>(U_("Zxx Macros"), MPT_UFORMAT("Z{}")(mpt::ufmt::HEX0<2>(i | 0x80)), macros.Zxx[i]);
  402. }
  403. // MRU list
  404. Limit(mruListLength, 0u, 32u);
  405. mruFiles.reserve(mruListLength);
  406. for(uint32 i = 0; i < mruListLength; i++)
  407. {
  408. mpt::ustring key = MPT_UFORMAT("File{}")(i);
  409. mpt::PathString path = theApp.PathInstallRelativeToAbsolute(conf.Read<mpt::PathString>(U_("Recent File List"), key, mpt::PathString()));
  410. if(!path.empty())
  411. {
  412. mruFiles.push_back(path);
  413. }
  414. }
  415. // Fixups:
  416. // -------
  417. const Version storedVersion = PreviousSettingsVersion;
  418. // Version
  419. if(!VersionInstallGUID.Get().IsValid())
  420. {
  421. // No UUID found - generate one.
  422. VersionInstallGUID = mpt::UUID::Generate(mpt::global_prng());
  423. }
  424. // Plugins
  425. if(storedVersion < MPT_V("1.19.03.01") && vstHostProductString.Get() == "OpenMPT")
  426. {
  427. vstHostVendorVersion = Version::Current().GetRawVersion();
  428. }
  429. if(storedVersion < MPT_V("1.30.00.24"))
  430. {
  431. BrokenPluginsWorkaroundVSTNeverUnloadAnyPlugin = !conf.Read<bool>(U_("VST Plugins"), U_("FullyUnloadPlugins"), true);
  432. conf.Remove(U_("VST Plugins"), U_("FullyUnloadPlugins"));
  433. }
  434. // Sound Settings
  435. if(storedVersion < MPT_V("1.22.07.30"))
  436. {
  437. if(conf.Read<bool>(U_("Sound Settings"), U_("KeepDeviceOpen"), false))
  438. {
  439. m_SoundSettingsStopMode = SoundDeviceStopModePlaying;
  440. } else
  441. {
  442. m_SoundSettingsStopMode = SoundDeviceStopModeStopped;
  443. }
  444. }
  445. if(storedVersion < MPT_V("1.22.07.04"))
  446. {
  447. std::vector<uint32> sampleRates = m_SoundSampleRates;
  448. if(std::count(sampleRates.begin(), sampleRates.end(), MixerSamplerate) == 0)
  449. {
  450. sampleRates.push_back(MixerSamplerate);
  451. std::sort(sampleRates.begin(), sampleRates.end());
  452. std::reverse(sampleRates.begin(), sampleRates.end());
  453. m_SoundSampleRates = sampleRates;
  454. }
  455. }
  456. if(storedVersion < MPT_V("1.22.07.04"))
  457. {
  458. m_SoundDeviceID_DEPRECATED = conf.Read<SoundDevice::Legacy::ID>(U_("Sound Settings"), U_("WaveDevice"), SoundDevice::Legacy::ID());
  459. Setting<uint32> m_BufferLength_DEPRECATED(conf, U_("Sound Settings"), U_("BufferLength"), 50);
  460. Setting<uint32> m_LatencyMS(conf, U_("Sound Settings"), U_("Latency"), mpt::saturate_round<int32>(SoundDevice::Settings().Latency * 1000.0));
  461. Setting<uint32> m_UpdateIntervalMS(conf, U_("Sound Settings"), U_("UpdateInterval"), mpt::saturate_round<int32>(SoundDevice::Settings().UpdateInterval * 1000.0));
  462. Setting<SampleFormat> m_SampleFormat(conf, U_("Sound Settings"), U_("BitsPerSample"), SoundDevice::Settings().sampleFormat);
  463. Setting<bool> m_SoundDeviceExclusiveMode(conf, U_("Sound Settings"), U_("ExclusiveMode"), SoundDevice::Settings().ExclusiveMode);
  464. Setting<bool> m_SoundDeviceBoostThreadPriority(conf, U_("Sound Settings"), U_("BoostThreadPriority"), SoundDevice::Settings().BoostThreadPriority);
  465. Setting<bool> m_SoundDeviceUseHardwareTiming(conf, U_("Sound Settings"), U_("UseHardwareTiming"), SoundDevice::Settings().UseHardwareTiming);
  466. Setting<SoundDevice::ChannelMapping> m_SoundDeviceChannelMapping(conf, U_("Sound Settings"), U_("ChannelMapping"), SoundDevice::Settings().Channels);
  467. if(storedVersion < MPT_V("1.21.01.26"))
  468. {
  469. if(m_BufferLength_DEPRECATED != 0)
  470. {
  471. if(m_BufferLength_DEPRECATED < 1) m_BufferLength_DEPRECATED = 1; // 1ms
  472. if(m_BufferLength_DEPRECATED > 1000) m_BufferLength_DEPRECATED = 1000; // 1sec
  473. if((m_SoundDeviceID_DEPRECATED & SoundDevice::Legacy::MaskType) == SoundDevice::Legacy::TypeASIO)
  474. {
  475. m_LatencyMS = m_BufferLength_DEPRECATED * 1;
  476. m_UpdateIntervalMS = m_BufferLength_DEPRECATED / 8;
  477. } else
  478. {
  479. m_LatencyMS = m_BufferLength_DEPRECATED * 3;
  480. m_UpdateIntervalMS = m_BufferLength_DEPRECATED / 8;
  481. }
  482. if(!m_UpdateIntervalMS) m_UpdateIntervalMS = static_cast<uint32>(SoundDevice::Settings().UpdateInterval * 1000.0);
  483. }
  484. conf.Remove(m_BufferLength_DEPRECATED.GetPath());
  485. }
  486. if(storedVersion < MPT_V("1.22.01.03"))
  487. {
  488. m_SoundDeviceExclusiveMode = ((MixerFlags & OLD_SOUNDSETUP_SECONDARY) == 0);
  489. }
  490. if(storedVersion < MPT_V("1.22.01.03"))
  491. {
  492. m_SoundDeviceBoostThreadPriority = ((MixerFlags & OLD_SOUNDSETUP_NOBOOSTTHREADPRIORITY) == 0);
  493. }
  494. if(storedVersion < MPT_V("1.22.07.03"))
  495. {
  496. m_SoundDeviceChannelMapping = SoundDevice::ChannelMapping::BaseChannel(MixerOutputChannels, conf.Read<int>(U_("Sound Settings"), U_("ASIOBaseChannel"), 0));
  497. }
  498. m_SoundDeviceSettingsDefaults.Latency = m_LatencyMS / 1000.0;
  499. m_SoundDeviceSettingsDefaults.UpdateInterval = m_UpdateIntervalMS / 1000.0;
  500. m_SoundDeviceSettingsDefaults.Samplerate = MixerSamplerate;
  501. if(m_SoundDeviceSettingsDefaults.Channels.GetNumHostChannels() != MixerOutputChannels)
  502. {
  503. // reset invalid channel mapping to default
  504. m_SoundDeviceSettingsDefaults.Channels = SoundDevice::ChannelMapping(MixerOutputChannels);
  505. }
  506. m_SoundDeviceSettingsDefaults.InputChannels = 0;
  507. m_SoundDeviceSettingsDefaults.sampleFormat = m_SampleFormat;
  508. m_SoundDeviceSettingsDefaults.ExclusiveMode = m_SoundDeviceExclusiveMode;
  509. m_SoundDeviceSettingsDefaults.BoostThreadPriority = m_SoundDeviceBoostThreadPriority;
  510. m_SoundDeviceSettingsDefaults.UseHardwareTiming = m_SoundDeviceUseHardwareTiming;
  511. m_SoundDeviceSettingsDefaults.InputSourceID = 0;
  512. m_SoundDeviceSettingsUseOldDefaults = true;
  513. }
  514. if(storedVersion < MPT_V("1.28.00.41"))
  515. {
  516. // reset this setting to the default when updating,
  517. // because we do not provide a GUI any more,
  518. // and in general, it should not get changed anyway
  519. ResamplerCutoffPercent = mpt::saturate_round<int32>(CResamplerSettings().gdWFIRCutoff * 100.0);
  520. }
  521. if(MixerSamplerate == 0)
  522. {
  523. MixerSamplerate = MixerSettings().gdwMixingFreq;
  524. }
  525. if(storedVersion < MPT_V("1.21.01.26"))
  526. {
  527. MixerFlags &= ~OLD_SOUNDSETUP_REVERSESTEREO;
  528. }
  529. if(storedVersion < MPT_V("1.22.01.03"))
  530. {
  531. MixerFlags &= ~OLD_SOUNDSETUP_SECONDARY;
  532. }
  533. if(storedVersion < MPT_V("1.22.01.03"))
  534. {
  535. MixerFlags &= ~OLD_SOUNDSETUP_NOBOOSTTHREADPRIORITY;
  536. }
  537. if(storedVersion < MPT_V("1.20.00.22"))
  538. {
  539. MixerSettings settings = GetMixerSettings();
  540. settings.SetVolumeRampUpSamples(conf.Read<int32>(U_("Sound Settings"), U_("VolumeRampSamples"), 42));
  541. settings.SetVolumeRampDownSamples(conf.Read<int32>(U_("Sound Settings"), U_("VolumeRampSamples"), 42));
  542. SetMixerSettings(settings);
  543. conf.Remove(U_("Sound Settings"), U_("VolumeRampSamples"));
  544. } else if(storedVersion < MPT_V("1.22.07.18"))
  545. {
  546. MixerSettings settings = GetMixerSettings();
  547. settings.SetVolumeRampUpSamples(conf.Read<int32>(U_("Sound Settings"), U_("VolumeRampUpSamples"), MixerSettings().GetVolumeRampUpSamples()));
  548. settings.SetVolumeRampDownSamples(conf.Read<int32>(U_("Sound Settings"), U_("VolumeRampDownSamples"), MixerSettings().GetVolumeRampDownSamples()));
  549. SetMixerSettings(settings);
  550. }
  551. Limit(ResamplerCutoffPercent, 0, 100);
  552. if(storedVersion < MPT_V("1.29.00.11"))
  553. {
  554. MixerMaxChannels = MixerSettings().m_nMaxMixChannels; // reset to default on update because we removed the setting in the GUI
  555. }
  556. if(storedVersion < MPT_V("1.29.00.20"))
  557. {
  558. MixerDSPMask = MixerDSPMask & ~SNDDSP_BITCRUSH;
  559. }
  560. // Misc
  561. if(defaultModType == MOD_TYPE_NONE)
  562. {
  563. defaultModType = MOD_TYPE_IT;
  564. }
  565. // MIDI Settings
  566. if((m_dwMidiSetup & 0x40) != 0 && storedVersion < MPT_V("1.20.00.86"))
  567. {
  568. // This flag used to be "amplify MIDI Note Velocity" - with a fixed amplification factor of 2.
  569. midiVelocityAmp = 200;
  570. m_dwMidiSetup &= ~0x40;
  571. }
  572. // Pattern Editor
  573. if(storedVersion < MPT_V("1.17.02.50"))
  574. {
  575. m_dwPatternSetup |= PATTERN_NOTEFADE;
  576. }
  577. if(storedVersion < MPT_V("1.17.03.01"))
  578. {
  579. m_dwPatternSetup |= PATTERN_RESETCHANNELS;
  580. }
  581. if(storedVersion < MPT_V("1.19.00.07"))
  582. {
  583. m_dwPatternSetup &= ~0x800; // this was previously deprecated and is now used for something else
  584. }
  585. if(storedVersion < MPT_V("1.20.00.04"))
  586. {
  587. m_dwPatternSetup &= ~0x200000; // ditto
  588. }
  589. if(storedVersion < MPT_V("1.20.00.07"))
  590. {
  591. m_dwPatternSetup &= ~0x400000; // ditto
  592. }
  593. if(storedVersion < MPT_V("1.20.00.39"))
  594. {
  595. m_dwPatternSetup &= ~0x10000000; // ditto
  596. }
  597. if(storedVersion < MPT_V("1.24.01.04"))
  598. {
  599. commentsFont = FontSetting(U_("Courier New"), (m_dwPatternSetup & 0x02) ? 120 : 90);
  600. patternFont = FontSetting((m_dwPatternSetup & 0x08) ? PATTERNFONT_SMALL : PATTERNFONT_LARGE, 0);
  601. m_dwPatternSetup &= ~(0x08 | 0x02);
  602. }
  603. if(storedVersion < MPT_V("1.25.00.08") && glGeneralWindowHeight < 222)
  604. {
  605. glGeneralWindowHeight += 44;
  606. }
  607. if(storedVersion < MPT_V("1.25.00.16") && (m_dwPatternSetup & 0x100000))
  608. {
  609. // Move MIDI recording to MIDI setup
  610. m_dwPatternSetup &= ~0x100000;
  611. m_dwMidiSetup |= MIDISETUP_ENABLE_RECORD_DEFAULT;
  612. }
  613. if(storedVersion < MPT_V("1.27.00.51"))
  614. {
  615. // Moving option out of pattern config
  616. CreateBackupFiles = (m_dwPatternSetup & 0x200) != 0;
  617. m_dwPatternSetup &= ~0x200;
  618. }
  619. // Export
  620. if(storedVersion < MPT_V("1.30.00.38"))
  621. {
  622. {
  623. conf.Write<Encoder::Mode>(U_("Export"), U_("FLAC_Mode"), Encoder::ModeLossless);
  624. const int oldformat = conf.Read<int>(U_("Export"), U_("FLAC_Format"), 1);
  625. Encoder::Format newformat = { Encoder::Format::Encoding::Integer, 24, mpt::get_endian() };
  626. if (oldformat >= 0)
  627. {
  628. switch (oldformat % 3)
  629. {
  630. case 0:
  631. newformat = { Encoder::Format::Encoding::Integer, 24, mpt::get_endian() };
  632. break;
  633. case 1:
  634. newformat = { Encoder::Format::Encoding::Integer, 16, mpt::get_endian() };
  635. break;
  636. case 2:
  637. newformat = { Encoder::Format::Encoding::Integer, 8, mpt::get_endian() };
  638. break;
  639. }
  640. }
  641. conf.Write<Encoder::Format>(U_("Export"), U_("FLAC_Format2"), newformat);
  642. conf.Forget(U_("Export"), U_("FLAC_Format"));
  643. }
  644. {
  645. conf.Write<Encoder::Mode>(U_("Export"), U_("Wave_Mode"), Encoder::ModeLossless);
  646. const int oldformat = conf.Read<int>(U_("Export"), U_("Wave_Format"), 1);
  647. Encoder::Format newformat = { Encoder::Format::Encoding::Float, 32, mpt::endian::little };
  648. if (oldformat >= 0)
  649. {
  650. switch (oldformat % 6)
  651. {
  652. case 0:
  653. newformat = { Encoder::Format::Encoding::Float, 64, mpt::endian::little };
  654. break;
  655. case 1:
  656. newformat = { Encoder::Format::Encoding::Float, 32, mpt::endian::little };
  657. break;
  658. case 2:
  659. newformat = { Encoder::Format::Encoding::Integer, 32, mpt::endian::little };
  660. break;
  661. case 3:
  662. newformat = { Encoder::Format::Encoding::Integer, 24, mpt::endian::little };
  663. break;
  664. case 4:
  665. newformat = { Encoder::Format::Encoding::Integer, 16, mpt::endian::little };
  666. break;
  667. case 5:
  668. newformat = { Encoder::Format::Encoding::Unsigned, 8, mpt::endian::little };
  669. break;
  670. }
  671. }
  672. conf.Write<Encoder::Format>(U_("Export"), U_("Wave_Format2"), newformat);
  673. conf.Forget(U_("Export"), U_("Wave_Format"));
  674. }
  675. {
  676. conf.Write<Encoder::Mode>(U_("Export"), U_("AU_Mode"), Encoder::ModeLossless);
  677. const int oldformat = conf.Read<int>(U_("Export"), U_("AU_Format"), 1);
  678. Encoder::Format newformat = { Encoder::Format::Encoding::Float, 32, mpt::endian::big };
  679. if(oldformat >= 0)
  680. {
  681. switch(oldformat % 6)
  682. {
  683. case 0:
  684. newformat = { Encoder::Format::Encoding::Float, 64, mpt::endian::big };
  685. break;
  686. case 1:
  687. newformat = { Encoder::Format::Encoding::Float, 32, mpt::endian::big };
  688. break;
  689. case 2:
  690. newformat = { Encoder::Format::Encoding::Integer, 32, mpt::endian::big };
  691. break;
  692. case 3:
  693. newformat = { Encoder::Format::Encoding::Integer, 24, mpt::endian::big };
  694. break;
  695. case 4:
  696. newformat = { Encoder::Format::Encoding::Integer, 16, mpt::endian::big };
  697. break;
  698. case 5:
  699. newformat = { Encoder::Format::Encoding::Integer, 8, mpt::endian::big };
  700. break;
  701. }
  702. }
  703. conf.Write<Encoder::Format>(U_("Export"), U_("AU_Format2"), newformat);
  704. conf.Forget(U_("Export"), U_("AU_Format"));
  705. }
  706. {
  707. conf.Write<Encoder::Mode>(U_("Export"), U_("RAW_Mode"), Encoder::ModeLossless);
  708. const int oldformat = conf.Read<int>(U_("Export"), U_("RAW_Format"), 1);
  709. Encoder::Format newformat = { Encoder::Format::Encoding::Float, 32, mpt::get_endian() };
  710. if(oldformat >= 0)
  711. {
  712. switch(oldformat % 7)
  713. {
  714. case 0:
  715. newformat = { Encoder::Format::Encoding::Float, 64, mpt::get_endian() };
  716. break;
  717. case 1:
  718. newformat = { Encoder::Format::Encoding::Float, 32, mpt::get_endian() };
  719. break;
  720. case 2:
  721. newformat = { Encoder::Format::Encoding::Integer, 32, mpt::get_endian() };
  722. break;
  723. case 3:
  724. newformat = { Encoder::Format::Encoding::Integer, 24, mpt::get_endian() };
  725. break;
  726. case 4:
  727. newformat = { Encoder::Format::Encoding::Integer, 16, mpt::get_endian() };
  728. break;
  729. case 5:
  730. newformat = { Encoder::Format::Encoding::Integer, 8, mpt::get_endian() };
  731. break;
  732. case 6:
  733. newformat = { Encoder::Format::Encoding::Unsigned, 8, mpt::get_endian() };
  734. break;
  735. }
  736. }
  737. conf.Write<Encoder::Format>(U_("Export"), U_("RAW_Format2"), newformat);
  738. conf.Forget(U_("Export"), U_("RAW_Format"));
  739. }
  740. }
  741. #if defined(MPT_ENABLE_UPDATE)
  742. // Update
  743. if(storedVersion < MPT_V("1.28.00.39"))
  744. {
  745. if(UpdateUpdateCheckPeriod_DEPRECATED <= 0)
  746. {
  747. UpdateEnabled = true;
  748. UpdateIntervalDays = -1;
  749. } else
  750. {
  751. UpdateEnabled = true;
  752. UpdateIntervalDays = UpdateUpdateCheckPeriod_DEPRECATED.Get();
  753. }
  754. const auto url = UpdateUpdateURL_DEPRECATED.Get();
  755. if(url.empty() ||
  756. url == UL_("http://update.openmpt.org/check/$VERSION/$GUID") ||
  757. url == UL_("https://update.openmpt.org/check/$VERSION/$GUID"))
  758. {
  759. UpdateChannel = UpdateChannelRelease;
  760. } else if(url == UL_("http://update.openmpt.org/check/testing/$VERSION/$GUID") ||
  761. url == UL_("https://update.openmpt.org/check/testing/$VERSION/$GUID"))
  762. {
  763. UpdateChannel = UpdateChannelDevelopment;
  764. } else
  765. {
  766. UpdateChannel = UpdateChannelDevelopment;
  767. }
  768. UpdateStatistics = UpdateSendGUID_DEPRECATED.Get();
  769. conf.Forget(UpdateUpdateCheckPeriod_DEPRECATED.GetPath());
  770. conf.Forget(UpdateUpdateURL_DEPRECATED.GetPath());
  771. conf.Forget(UpdateSendGUID_DEPRECATED.GetPath());
  772. }
  773. #endif // MPT_ENABLE_UPDATE
  774. if(storedVersion < MPT_V("1.29.00.39"))
  775. {
  776. // ASIO device IDs are now normalized to upper-case in the device enumeration code.
  777. // Previous device IDs could be mixed-case (as retrieved from the registry), which would make direct ID comparison fail now.
  778. auto device = m_SoundDeviceIdentifier.Get();
  779. if(device.substr(0, 5) == UL_("ASIO_"))
  780. {
  781. device = mpt::ToUpperCase(device);
  782. m_SoundDeviceIdentifier = device;
  783. }
  784. }
  785. // Effects
  786. #ifndef NO_EQ
  787. FixupEQ(m_EqSettings);
  788. FixupEQ(m_EqUserPresets[0]);
  789. FixupEQ(m_EqUserPresets[1]);
  790. FixupEQ(m_EqUserPresets[2]);
  791. FixupEQ(m_EqUserPresets[3]);
  792. #endif // !NO_EQ
  793. // Zxx Macros
  794. if((MPT_V("1.17.00.00") <= storedVersion) && (storedVersion < MPT_V("1.20.00.00")))
  795. {
  796. // Fix old nasty broken (non-standard) MIDI configs in INI file.
  797. macros.UpgradeMacros();
  798. }
  799. theApp.SetDefaultMidiMacro(macros);
  800. // Paths
  801. m_szKbdFile = theApp.PathInstallRelativeToAbsolute(m_szKbdFile);
  802. // Sample undo buffer size (used to be a hidden, absolute setting in MiB)
  803. int64 oldUndoSize = m_SampleUndoBufferSize.Get().GetSizeInPercent();
  804. if(storedVersion < MPT_V("1.22.07.25") && oldUndoSize != SampleUndoBufferSize::defaultSize && oldUndoSize != 0)
  805. {
  806. m_SampleUndoBufferSize = SampleUndoBufferSize(static_cast<int32>(100 * (oldUndoSize << 20) / SampleUndoBufferSize(100).GetSizeInBytes()));
  807. }
  808. // More controls in the plugin selection dialog
  809. if(storedVersion < MPT_V("1.26.00.26"))
  810. {
  811. gnPlugWindowHeight += 40;
  812. }
  813. // Sanitize resampling mode for sample editor
  814. if(!Resampling::IsKnownMode(sampleEditorDefaultResampler) && sampleEditorDefaultResampler != SRCMODE_DEFAULT)
  815. {
  816. sampleEditorDefaultResampler = SRCMODE_DEFAULT;
  817. }
  818. // Migrate Tuning data
  819. MigrateTunings(storedVersion);
  820. // Sanitize MIDI import data
  821. if(midiImportPatternLen < 1 || midiImportPatternLen > MAX_PATTERN_ROWS)
  822. midiImportPatternLen = 128;
  823. if(midiImportQuantize < 4 || midiImportQuantize > 256)
  824. midiImportQuantize = 32;
  825. if(midiImportTicks < 2 || midiImportTicks > 16)
  826. midiImportTicks = 16;
  827. // Last fixup: update config version
  828. IniVersion = mpt::ufmt::val(Version::Current());
  829. // Write updated settings
  830. conf.Flush();
  831. }
  832. TrackerSettings::~TrackerSettings()
  833. {
  834. return;
  835. }
  836. namespace SoundDevice
  837. {
  838. namespace Legacy
  839. {
  840. SoundDevice::Info FindDeviceInfo(SoundDevice::Manager &manager, SoundDevice::Legacy::ID id)
  841. {
  842. if(manager.GetDeviceInfos().empty())
  843. {
  844. return SoundDevice::Info();
  845. }
  846. SoundDevice::Type type = SoundDevice::Type();
  847. switch((id & SoundDevice::Legacy::MaskType) >> SoundDevice::Legacy::ShiftType)
  848. {
  849. case SoundDevice::Legacy::TypeWAVEOUT:
  850. type = SoundDevice::TypeWAVEOUT;
  851. break;
  852. case SoundDevice::Legacy::TypeDSOUND:
  853. type = SoundDevice::TypeDSOUND;
  854. break;
  855. case SoundDevice::Legacy::TypeASIO:
  856. type = SoundDevice::TypeASIO;
  857. break;
  858. case SoundDevice::Legacy::TypePORTAUDIO_WASAPI:
  859. type = SoundDevice::TypePORTAUDIO_WASAPI;
  860. break;
  861. case SoundDevice::Legacy::TypePORTAUDIO_WDMKS:
  862. type = SoundDevice::TypePORTAUDIO_WDMKS;
  863. break;
  864. case SoundDevice::Legacy::TypePORTAUDIO_WMME:
  865. type = SoundDevice::TypePORTAUDIO_WMME;
  866. break;
  867. case SoundDevice::Legacy::TypePORTAUDIO_DS:
  868. type = SoundDevice::TypePORTAUDIO_DS;
  869. break;
  870. }
  871. if(type.empty())
  872. { // fallback to first device
  873. return *manager.begin();
  874. }
  875. std::size_t index = static_cast<uint8>((id & SoundDevice::Legacy::MaskIndex) >> SoundDevice::Legacy::ShiftIndex);
  876. std::size_t seenDevicesOfDesiredType = 0;
  877. for(const auto &info : manager)
  878. {
  879. if(info.type == type)
  880. {
  881. if(seenDevicesOfDesiredType == index)
  882. {
  883. if(!info.IsValid())
  884. { // fallback to first device
  885. return *manager.begin();
  886. }
  887. return info;
  888. }
  889. seenDevicesOfDesiredType++;
  890. }
  891. }
  892. // default to first device
  893. return *manager.begin();
  894. }
  895. } // namespace Legacy
  896. } // namespace SoundDevice
  897. void TrackerSettings::MigrateOldSoundDeviceSettings(SoundDevice::Manager &manager)
  898. {
  899. if(m_SoundDeviceSettingsUseOldDefaults)
  900. {
  901. // get the old default device
  902. SetSoundDeviceIdentifier(SoundDevice::Legacy::FindDeviceInfo(manager, m_SoundDeviceID_DEPRECATED).GetIdentifier());
  903. // apply old global sound device settings to each found device
  904. for(const auto &it : manager)
  905. {
  906. SetSoundDeviceSettings(it.GetIdentifier(), GetSoundDeviceSettingsDefaults());
  907. }
  908. }
  909. }
  910. void TrackerSettings::MigrateTunings(const Version storedVersion)
  911. {
  912. if(!PathTunings.GetDefaultDir().IsDirectory())
  913. {
  914. CreateDirectory(PathTunings.GetDefaultDir().AsNative().c_str(), 0);
  915. }
  916. if(!(PathTunings.GetDefaultDir() + P_("Built-in\\")).IsDirectory())
  917. {
  918. CreateDirectory((PathTunings.GetDefaultDir() + P_("Built-in\\")).AsNative().c_str(), 0);
  919. }
  920. if(!(PathTunings.GetDefaultDir() + P_("Locale\\")).IsDirectory())
  921. {
  922. CreateDirectory((PathTunings.GetDefaultDir() + P_("Local\\")).AsNative().c_str(), 0);
  923. }
  924. {
  925. mpt::PathString fn = PathTunings.GetDefaultDir() + P_("Built-in\\12TET.tun");
  926. if(!fn.FileOrDirectoryExists())
  927. {
  928. std::unique_ptr<CTuning> pT = CSoundFile::CreateTuning12TET(U_("12TET"));
  929. mpt::SafeOutputFile sf(fn, std::ios::binary, mpt::FlushMode::Full);
  930. pT->Serialize(sf);
  931. }
  932. }
  933. {
  934. mpt::PathString fn = PathTunings.GetDefaultDir() + P_("Built-in\\12TET [[fs15 1.17.02.49]].tun");
  935. if(!fn.FileOrDirectoryExists())
  936. {
  937. std::unique_ptr<CTuning> pT = CSoundFile::CreateTuning12TET(U_("12TET [[fs15 1.17.02.49]]"));
  938. mpt::SafeOutputFile sf(fn, std::ios::binary, mpt::FlushMode::Full);
  939. pT->Serialize(sf);
  940. }
  941. }
  942. oldLocalTunings = LoadLocalTunings();
  943. if(storedVersion < MPT_V("1.27.00.56"))
  944. {
  945. UnpackTuningCollection(*oldLocalTunings, PathTunings.GetDefaultDir() + P_("Local\\"));
  946. }
  947. }
  948. std::unique_ptr<CTuningCollection> TrackerSettings::LoadLocalTunings()
  949. {
  950. std::unique_ptr<CTuningCollection> s_pTuningsSharedLocal = std::make_unique<CTuningCollection>();
  951. mpt::ifstream f(
  952. PathTunings.GetDefaultDir()
  953. + P_("local_tunings")
  954. + mpt::PathString::FromUTF8(CTuningCollection::s_FileExtension)
  955. , std::ios::binary);
  956. if(f.good())
  957. {
  958. mpt::ustring dummyName;
  959. s_pTuningsSharedLocal->Deserialize(f, dummyName, TuningCharsetFallback);
  960. }
  961. return s_pTuningsSharedLocal;
  962. }
  963. struct StoredSoundDeviceSettings
  964. {
  965. private:
  966. SettingsContainer &conf;
  967. const SoundDevice::Info deviceInfo;
  968. private:
  969. Setting<uint32> LatencyUS;
  970. Setting<uint32> UpdateIntervalUS;
  971. Setting<uint32> Samplerate;
  972. Setting<uint8> ChannelsOld; // compatibility with older versions
  973. Setting<SoundDevice::ChannelMapping> ChannelMapping;
  974. Setting<uint8> InputChannels;
  975. Setting<SampleFormat> sampleFormat;
  976. Setting<bool> ExclusiveMode;
  977. Setting<bool> BoostThreadPriority;
  978. Setting<bool> KeepDeviceRunning;
  979. Setting<bool> UseHardwareTiming;
  980. Setting<int32> DitherType;
  981. Setting<uint32> InputSourceID;
  982. public:
  983. StoredSoundDeviceSettings(SettingsContainer &conf, const SoundDevice::Info & deviceInfo, const SoundDevice::Settings & defaults)
  984. : conf(conf)
  985. , deviceInfo(deviceInfo)
  986. , LatencyUS(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("Latency"), mpt::saturate_round<int32>(defaults.Latency * 1000000.0))
  987. , UpdateIntervalUS(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("UpdateInterval"), mpt::saturate_round<int32>(defaults.UpdateInterval * 1000000.0))
  988. , Samplerate(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("SampleRate"), defaults.Samplerate)
  989. , ChannelsOld(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("Channels"), mpt::saturate_cast<uint8>((int)defaults.Channels))
  990. , ChannelMapping(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("ChannelMapping"), defaults.Channels)
  991. , InputChannels(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("InputChannels"), defaults.InputChannels)
  992. , sampleFormat(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("SampleFormat"), defaults.sampleFormat)
  993. , ExclusiveMode(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("ExclusiveMode"), defaults.ExclusiveMode)
  994. , BoostThreadPriority(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("BoostThreadPriority"), defaults.BoostThreadPriority)
  995. , KeepDeviceRunning(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("KeepDeviceRunning"), defaults.KeepDeviceRunning)
  996. , UseHardwareTiming(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("UseHardwareTiming"), defaults.UseHardwareTiming)
  997. , DitherType(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("DitherType"), static_cast<int32>(defaults.DitherType))
  998. , InputSourceID(conf, U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("InputSourceID"), defaults.InputSourceID)
  999. {
  1000. if(ChannelMapping.Get().GetNumHostChannels() != ChannelsOld)
  1001. {
  1002. // If the stored channel count and the count of channels used in the channel mapping do not match,
  1003. // construct a default mapping from the channel count.
  1004. ChannelMapping = SoundDevice::ChannelMapping(ChannelsOld);
  1005. }
  1006. // store informational data (not read back, just to allow the user to mock with the raw ini file)
  1007. conf.Write(U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("Type"), deviceInfo.type);
  1008. conf.Write(U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("InternalID"), deviceInfo.internalID);
  1009. conf.Write(U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("API"), deviceInfo.apiName);
  1010. conf.Write(U_("Sound Settings"), deviceInfo.GetIdentifier() + U_("_") + U_("Name"), deviceInfo.name);
  1011. }
  1012. StoredSoundDeviceSettings & operator = (const SoundDevice::Settings &settings)
  1013. {
  1014. LatencyUS = mpt::saturate_round<int32>(settings.Latency * 1000000.0);
  1015. UpdateIntervalUS = mpt::saturate_round<int32>(settings.UpdateInterval * 1000000.0);
  1016. Samplerate = settings.Samplerate;
  1017. ChannelsOld = mpt::saturate_cast<uint8>((int)settings.Channels);
  1018. ChannelMapping = settings.Channels;
  1019. InputChannels = settings.InputChannels;
  1020. sampleFormat = settings.sampleFormat;
  1021. ExclusiveMode = settings.ExclusiveMode;
  1022. BoostThreadPriority = settings.BoostThreadPriority;
  1023. KeepDeviceRunning = settings.KeepDeviceRunning;
  1024. UseHardwareTiming = settings.UseHardwareTiming;
  1025. DitherType = static_cast<int32>(settings.DitherType);
  1026. InputSourceID = settings.InputSourceID;
  1027. return *this;
  1028. }
  1029. operator SoundDevice::Settings () const
  1030. {
  1031. SoundDevice::Settings settings;
  1032. settings.Latency = LatencyUS / 1000000.0;
  1033. settings.UpdateInterval = UpdateIntervalUS / 1000000.0;
  1034. settings.Samplerate = Samplerate;
  1035. settings.Channels = ChannelMapping;
  1036. settings.InputChannels = InputChannels;
  1037. settings.sampleFormat = sampleFormat;
  1038. settings.ExclusiveMode = ExclusiveMode;
  1039. settings.BoostThreadPriority = BoostThreadPriority;
  1040. settings.KeepDeviceRunning = KeepDeviceRunning;
  1041. settings.UseHardwareTiming = UseHardwareTiming;
  1042. settings.DitherType = DitherType;
  1043. settings.InputSourceID = InputSourceID;
  1044. return settings;
  1045. }
  1046. };
  1047. SoundDevice::Settings TrackerSettings::GetSoundDeviceSettingsDefaults() const
  1048. {
  1049. return m_SoundDeviceSettingsDefaults;
  1050. }
  1051. SoundDevice::Identifier TrackerSettings::GetSoundDeviceIdentifier() const
  1052. {
  1053. return m_SoundDeviceIdentifier;
  1054. }
  1055. void TrackerSettings::SetSoundDeviceIdentifier(const SoundDevice::Identifier &identifier)
  1056. {
  1057. m_SoundDeviceIdentifier = identifier;
  1058. }
  1059. SoundDevice::Settings TrackerSettings::GetSoundDeviceSettings(const SoundDevice::Identifier &device) const
  1060. {
  1061. const SoundDevice::Info deviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(device);
  1062. if(!deviceInfo.IsValid())
  1063. {
  1064. return SoundDevice::Settings();
  1065. }
  1066. const SoundDevice::Caps deviceCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(device, CMainFrame::GetMainFrame()->gpSoundDevice);
  1067. SoundDevice::Settings settings = StoredSoundDeviceSettings(conf, deviceInfo, deviceCaps.DefaultSettings);
  1068. return settings;
  1069. }
  1070. void TrackerSettings::SetSoundDeviceSettings(const SoundDevice::Identifier &device, const SoundDevice::Settings &settings)
  1071. {
  1072. const SoundDevice::Info deviceInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(device);
  1073. if(!deviceInfo.IsValid())
  1074. {
  1075. return;
  1076. }
  1077. const SoundDevice::Caps deviceCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(device, CMainFrame::GetMainFrame()->gpSoundDevice);
  1078. StoredSoundDeviceSettings(conf, deviceInfo, deviceCaps.DefaultSettings) = settings;
  1079. }
  1080. MixerSettings TrackerSettings::GetMixerSettings() const
  1081. {
  1082. MixerSettings settings;
  1083. settings.m_nMaxMixChannels = MixerMaxChannels;
  1084. settings.DSPMask = MixerDSPMask;
  1085. settings.MixerFlags = MixerFlags;
  1086. settings.gdwMixingFreq = MixerSamplerate;
  1087. settings.gnChannels = MixerOutputChannels;
  1088. settings.m_nPreAmp = MixerPreAmp;
  1089. settings.m_nStereoSeparation = MixerStereoSeparation;
  1090. settings.VolumeRampUpMicroseconds = MixerVolumeRampUpMicroseconds;
  1091. settings.VolumeRampDownMicroseconds = MixerVolumeRampDownMicroseconds;
  1092. settings.NumInputChannels = MixerNumInputChannels;
  1093. return settings;
  1094. }
  1095. void TrackerSettings::SetMixerSettings(const MixerSettings &settings)
  1096. {
  1097. MixerMaxChannels = settings.m_nMaxMixChannels;
  1098. MixerDSPMask = settings.DSPMask;
  1099. MixerFlags = settings.MixerFlags;
  1100. MixerSamplerate = settings.gdwMixingFreq;
  1101. MixerOutputChannels = settings.gnChannels;
  1102. MixerPreAmp = settings.m_nPreAmp;
  1103. MixerStereoSeparation = settings.m_nStereoSeparation;
  1104. MixerVolumeRampUpMicroseconds = settings.VolumeRampUpMicroseconds;
  1105. MixerVolumeRampDownMicroseconds = settings.VolumeRampDownMicroseconds;
  1106. MixerNumInputChannels = static_cast<uint32>(settings.NumInputChannels);
  1107. }
  1108. CResamplerSettings TrackerSettings::GetResamplerSettings() const
  1109. {
  1110. CResamplerSettings settings;
  1111. settings.SrcMode = ResamplerMode;
  1112. settings.gbWFIRType = ResamplerSubMode;
  1113. settings.gdWFIRCutoff = ResamplerCutoffPercent * 0.01;
  1114. settings.emulateAmiga = ResamplerEmulateAmiga;
  1115. return settings;
  1116. }
  1117. void TrackerSettings::SetResamplerSettings(const CResamplerSettings &settings)
  1118. {
  1119. ResamplerMode = settings.SrcMode;
  1120. ResamplerSubMode = settings.gbWFIRType;
  1121. ResamplerCutoffPercent = mpt::saturate_round<int32>(settings.gdWFIRCutoff * 100.0);
  1122. ResamplerEmulateAmiga = settings.emulateAmiga;
  1123. }
  1124. void TrackerSettings::GetDefaultColourScheme(std::array<COLORREF, MAX_MODCOLORS> &colours)
  1125. {
  1126. colours[MODCOLOR_BACKNORMAL] = RGB(0xFF, 0xFF, 0xFF);
  1127. colours[MODCOLOR_TEXTNORMAL] = RGB(0x00, 0x00, 0x00);
  1128. colours[MODCOLOR_BACKCURROW] = RGB(0xC0, 0xC0, 0xC0);
  1129. colours[MODCOLOR_TEXTCURROW] = RGB(0x00, 0x00, 0x00);
  1130. colours[MODCOLOR_BACKSELECTED] = RGB(0x00, 0x00, 0x00);
  1131. colours[MODCOLOR_TEXTSELECTED] = RGB(0xFF, 0xFF, 0xFF);
  1132. colours[MODCOLOR_SAMPLE] = RGB(0xFF, 0x00, 0x00);
  1133. colours[MODCOLOR_BACKPLAYCURSOR] = RGB(0xFF, 0xFF, 0x80);
  1134. colours[MODCOLOR_TEXTPLAYCURSOR] = RGB(0x00, 0x00, 0x00);
  1135. colours[MODCOLOR_BACKHILIGHT] = RGB(0xE0, 0xE8, 0xE0);
  1136. // Effect Colors
  1137. colours[MODCOLOR_NOTE] = RGB(0x00, 0x00, 0x80);
  1138. colours[MODCOLOR_INSTRUMENT] = RGB(0x00, 0x80, 0x80);
  1139. colours[MODCOLOR_VOLUME] = RGB(0x00, 0x80, 0x00);
  1140. colours[MODCOLOR_PANNING] = RGB(0x00, 0x80, 0x80);
  1141. colours[MODCOLOR_PITCH] = RGB(0x80, 0x80, 0x00);
  1142. colours[MODCOLOR_GLOBALS] = RGB(0x80, 0x00, 0x00);
  1143. // VU-Meters
  1144. colours[MODCOLOR_VUMETER_LO] = RGB(0x00, 0xC8, 0x00);
  1145. colours[MODCOLOR_VUMETER_MED] = RGB(0xFF, 0xC8, 0x00);
  1146. colours[MODCOLOR_VUMETER_HI] = RGB(0xE1, 0x00, 0x00);
  1147. colours[MODCOLOR_VUMETER_LO_VST] = RGB(0x18, 0x96, 0xE1);
  1148. colours[MODCOLOR_VUMETER_MED_VST] = RGB(0xFF, 0xC8, 0x00);
  1149. colours[MODCOLOR_VUMETER_HI_VST] = RGB(0xE1, 0x00, 0x00);
  1150. // Channel separators
  1151. colours[MODCOLOR_SEPSHADOW] = GetSysColor(COLOR_BTNSHADOW);
  1152. colours[MODCOLOR_SEPFACE] = GetSysColor(COLOR_BTNFACE);
  1153. colours[MODCOLOR_SEPHILITE] = GetSysColor(COLOR_BTNHIGHLIGHT);
  1154. // Pattern blend colour
  1155. colours[MODCOLOR_BLENDCOLOR] = GetSysColor(COLOR_BTNFACE);
  1156. // Dodgy commands
  1157. colours[MODCOLOR_DODGY_COMMANDS] = RGB(0xC0, 0x00, 0x00);
  1158. // Sample / instrument editor
  1159. colours[MODCOLOR_BACKSAMPLE] = RGB(0x00, 0x00, 0x00);
  1160. colours[MODCOLOR_SAMPLESELECTED] = RGB(0xFF, 0xFF, 0xFF);
  1161. colours[MODCOLOR_BACKENV] = RGB(0x00, 0x00, 0x00);
  1162. colours[MODCOLOR_ENVELOPES] = RGB(0x00, 0x00, 0xFF);
  1163. colours[MODCOLOR_ENVELOPE_RELEASE] = RGB(0xFF, 0xFF, 0x00);
  1164. colours[MODCOLOR_SAMPLE_LOOPMARKER] = RGB(0x30, 0xCC, 0x30);
  1165. colours[MODCOLOR_SAMPLE_SUSTAINMARKER] = RGB(50, 0xCC, 0xCC);
  1166. colours[MODCOLOR_SAMPLE_CUEPOINT] = RGB(0xFF, 0xCC, 0x30);
  1167. }
  1168. #ifndef NO_EQ
  1169. void TrackerSettings::FixupEQ(EQPreset &eqSettings)
  1170. {
  1171. for(UINT i = 0; i < MAX_EQ_BANDS; i++)
  1172. {
  1173. if(eqSettings.Gains[i] > 32)
  1174. eqSettings.Gains[i] = 16;
  1175. if((eqSettings.Freqs[i] < 100) || (eqSettings.Freqs[i] > 10000))
  1176. eqSettings.Freqs[i] = FlatEQPreset.Freqs[i];
  1177. }
  1178. mpt::String::SetNullTerminator(eqSettings.szName);
  1179. }
  1180. #endif // !NO_EQ
  1181. void TrackerSettings::SaveSettings()
  1182. {
  1183. WINDOWPLACEMENT wpl;
  1184. wpl.length = sizeof(WINDOWPLACEMENT);
  1185. CMainFrame::GetMainFrame()->GetWindowPlacement(&wpl);
  1186. conf.Write<WINDOWPLACEMENT>(U_("Display"), U_("WindowPlacement"), wpl);
  1187. conf.Write<int32>(U_("Pattern Editor"), U_("NumClipboards"), mpt::saturate_cast<int32>(PatternClipboard::GetClipboardSize()));
  1188. // Effects
  1189. #ifndef NO_DSP
  1190. conf.Write<int32>(U_("Effects"), U_("XBassDepth"), m_MegaBassSettings.m_nXBassDepth);
  1191. conf.Write<int32>(U_("Effects"), U_("XBassRange"), m_MegaBassSettings.m_nXBassRange);
  1192. #endif
  1193. #ifndef NO_REVERB
  1194. conf.Write<int32>(U_("Effects"), U_("ReverbDepth"), m_ReverbSettings.m_nReverbDepth);
  1195. conf.Write<int32>(U_("Effects"), U_("ReverbType"), m_ReverbSettings.m_nReverbType);
  1196. #endif
  1197. #ifndef NO_DSP
  1198. conf.Write<int32>(U_("Effects"), U_("ProLogicDepth"), m_SurroundSettings.m_nProLogicDepth);
  1199. conf.Write<int32>(U_("Effects"), U_("ProLogicDelay"), m_SurroundSettings.m_nProLogicDelay);
  1200. #endif
  1201. #ifndef NO_EQ
  1202. conf.Write<EQPreset>(U_("Effects"), U_("EQ_Settings"), m_EqSettings);
  1203. conf.Write<EQPreset>(U_("Effects"), U_("EQ_User1"), m_EqUserPresets[0]);
  1204. conf.Write<EQPreset>(U_("Effects"), U_("EQ_User2"), m_EqUserPresets[1]);
  1205. conf.Write<EQPreset>(U_("Effects"), U_("EQ_User3"), m_EqUserPresets[2]);
  1206. conf.Write<EQPreset>(U_("Effects"), U_("EQ_User4"), m_EqUserPresets[3]);
  1207. #endif
  1208. #ifndef NO_DSP
  1209. conf.Write<int32>(U_("Effects"), U_("BitCrushBits"), m_BitCrushSettings.m_Bits);
  1210. #endif
  1211. // Display (Colors)
  1212. for(int ncol = 0; ncol < MAX_MODCOLORS; ncol++)
  1213. {
  1214. conf.Write<uint32>(U_("Display"), MPT_UFORMAT("Color{}")(mpt::ufmt::dec0<2>(ncol)), rgbCustomColors[ncol]);
  1215. }
  1216. // Paths
  1217. // Obsolete, since we always write to Keybindings.mkb now.
  1218. // Older versions of OpenMPT 1.18+ will look for this file if this entry is missing, so removing this entry after having read it is kind of backwards compatible.
  1219. conf.Remove(U_("Paths"), U_("Key_Config_File"));
  1220. // Chords
  1221. SaveChords(Chords);
  1222. // Save default macro configuration
  1223. MIDIMacroConfig macros;
  1224. theApp.GetDefaultMidiMacro(macros);
  1225. for(int isfx = 0; isfx < kSFxMacros; isfx++)
  1226. {
  1227. conf.Write<std::string>(U_("Zxx Macros"), MPT_UFORMAT("SF{}")(mpt::ufmt::HEX(isfx)), macros.SFx[isfx]);
  1228. }
  1229. for(int izxx = 0; izxx < kZxxMacros; izxx++)
  1230. {
  1231. conf.Write<std::string>(U_("Zxx Macros"), MPT_UFORMAT("Z{}")(mpt::ufmt::HEX0<2>(izxx | 0x80)), macros.Zxx[izxx]);
  1232. }
  1233. // MRU list
  1234. for(uint32 i = 0; i < (ID_MRU_LIST_LAST - ID_MRU_LIST_FIRST + 1); i++)
  1235. {
  1236. mpt::ustring key = MPT_UFORMAT("File{}")(i);
  1237. if(i < mruFiles.size())
  1238. {
  1239. mpt::PathString path = mruFiles[i];
  1240. if(theApp.IsPortableMode())
  1241. {
  1242. path = theApp.PathAbsoluteToInstallRelative(path);
  1243. }
  1244. conf.Write<mpt::PathString>(U_("Recent File List"), key, path);
  1245. } else
  1246. {
  1247. conf.Remove(U_("Recent File List"), key);
  1248. }
  1249. }
  1250. }
  1251. bool TrackerSettings::IsComponentBlocked(const std::string &key)
  1252. {
  1253. return Setting<bool>(conf, U_("Components"), U_("Block") + mpt::ToUnicode(mpt::Charset::ASCII, key), ComponentManagerSettingsDefault().IsBlocked(key));
  1254. }
  1255. std::vector<uint32> TrackerSettings::GetSampleRates() const
  1256. {
  1257. return m_SoundSampleRates;
  1258. }
  1259. std::vector<uint32> TrackerSettings::GetDefaultSampleRates()
  1260. {
  1261. return std::vector<uint32>{
  1262. 192000,
  1263. 176400,
  1264. 96000,
  1265. 88200,
  1266. 48000,
  1267. 44100,
  1268. 32000,
  1269. 24000,
  1270. 22050,
  1271. 16000,
  1272. 11025,
  1273. 8000
  1274. };
  1275. }
  1276. ////////////////////////////////////////////////////////////////////////////////
  1277. // Chords
  1278. void TrackerSettings::LoadChords(MPTChords &chords)
  1279. {
  1280. for(std::size_t i = 0; i < std::size(chords); i++)
  1281. {
  1282. uint32 chord;
  1283. mpt::ustring noteName = MPT_UFORMAT("{}{}")(mpt::ustring(NoteNamesSharp[i % 12]), i / 12);
  1284. if((chord = conf.Read<int32>(U_("Chords"), noteName, -1)) != uint32(-1))
  1285. {
  1286. if((chord & 0xFFFFFFC0) || chords[i].notes[0] == MPTChord::noNote)
  1287. {
  1288. chords[i].key = (uint8)(chord & 0x3F);
  1289. int shift = 6;
  1290. for(auto &note : chords[i].notes)
  1291. {
  1292. // Extract 6 bits and sign-extend to 8 bits
  1293. const int signBit = ((chord >> (shift + 5)) & 1);
  1294. note = static_cast<MPTChord::NoteType>(((chord >> shift) & 0x3F) | (0xC0 * signBit));
  1295. shift += 6;
  1296. if(note == 0)
  1297. note = MPTChord::noNote;
  1298. else if(note > 0)
  1299. note--;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. }
  1305. void TrackerSettings::SaveChords(MPTChords &chords)
  1306. {
  1307. for(std::size_t i = 0; i < std::size(chords); i++)
  1308. {
  1309. auto notes = chords[i].notes;
  1310. for(auto &note : notes)
  1311. {
  1312. if(note == MPTChord::noNote)
  1313. note = 0;
  1314. else if(note >= 0)
  1315. note++;
  1316. note &= 0x3F;
  1317. }
  1318. int32 s = (chords[i].key) | (notes[0] << 6) | (notes[1] << 12) | (notes[2] << 18);
  1319. mpt::ustring noteName = MPT_UFORMAT("{}{}")(mpt::ustring(NoteNamesSharp[i % 12]), i / 12);
  1320. conf.Write<int32>(U_("Chords"), noteName, s);
  1321. }
  1322. }
  1323. void TrackerSettings::SetMIDIDevice(UINT id)
  1324. {
  1325. m_nMidiDevice = id;
  1326. MIDIINCAPS mic;
  1327. mic.szPname[0] = 0;
  1328. if(midiInGetDevCaps(id, &mic, sizeof(mic)) == MMSYSERR_NOERROR)
  1329. {
  1330. midiDeviceName = mic.szPname;
  1331. }
  1332. }
  1333. UINT TrackerSettings::GetCurrentMIDIDevice()
  1334. {
  1335. if(midiDeviceName.Get().IsEmpty())
  1336. return m_nMidiDevice;
  1337. CString deviceName = midiDeviceName;
  1338. deviceName.TrimRight();
  1339. MIDIINCAPS mic;
  1340. UINT candidate = m_nMidiDevice, numDevs = midiInGetNumDevs();
  1341. for(UINT i = 0; i < numDevs; i++)
  1342. {
  1343. mic.szPname[0] = 0;
  1344. if(midiInGetDevCaps(i, &mic, sizeof(mic)) != MMSYSERR_NOERROR)
  1345. continue;
  1346. // Some device names have trailing spaces (e.g. "USB MIDI Interface "), but those may get lost in our settings framework.
  1347. mpt::String::SetNullTerminator(mic.szPname);
  1348. size_t strLen = _tcslen(mic.szPname);
  1349. while(strLen-- > 0)
  1350. {
  1351. if(mic.szPname[strLen] == _T(' '))
  1352. mic.szPname[strLen] = 0;
  1353. else
  1354. break;
  1355. }
  1356. if(CString(mic.szPname) == deviceName)
  1357. {
  1358. candidate = i;
  1359. numDevs = m_nMidiDevice + 1;
  1360. // If the same device name exists twice, try to match both device number and name
  1361. if(candidate == m_nMidiDevice)
  1362. return candidate;
  1363. }
  1364. }
  1365. // If the device changed its ID, update it now.
  1366. m_nMidiDevice = candidate;
  1367. return candidate;
  1368. }
  1369. mpt::ustring IgnoredCCsToString(const std::bitset<128> &midiIgnoreCCs)
  1370. {
  1371. mpt::ustring cc;
  1372. bool first = true;
  1373. for(int i = 0; i < 128; i++)
  1374. {
  1375. if(midiIgnoreCCs[i])
  1376. {
  1377. if(!first)
  1378. {
  1379. cc += U_(",");
  1380. }
  1381. cc += mpt::ufmt::val(i);
  1382. first = false;
  1383. }
  1384. }
  1385. return cc;
  1386. }
  1387. std::bitset<128> StringToIgnoredCCs(const mpt::ustring &in)
  1388. {
  1389. CString cc = mpt::ToCString(in);
  1390. std::bitset<128> midiIgnoreCCs;
  1391. midiIgnoreCCs.reset();
  1392. int curPos = 0;
  1393. CString ccToken = cc.Tokenize(_T(", "), curPos);
  1394. while(ccToken != _T(""))
  1395. {
  1396. int ccNumber = ConvertStrTo<int>(ccToken);
  1397. if(ccNumber >= 0 && ccNumber <= 127)
  1398. midiIgnoreCCs.set(ccNumber);
  1399. ccToken = cc.Tokenize(_T(", "), curPos);
  1400. }
  1401. return midiIgnoreCCs;
  1402. }
  1403. DefaultAndWorkingDirectory::DefaultAndWorkingDirectory()
  1404. {
  1405. return;
  1406. }
  1407. DefaultAndWorkingDirectory::DefaultAndWorkingDirectory(const mpt::PathString &def)
  1408. : m_Default(def)
  1409. , m_Working(def)
  1410. {
  1411. return;
  1412. }
  1413. DefaultAndWorkingDirectory::~DefaultAndWorkingDirectory()
  1414. {
  1415. return;
  1416. }
  1417. void DefaultAndWorkingDirectory::SetDefaultDir(const mpt::PathString &filenameFrom, bool stripFilename)
  1418. {
  1419. if(InternalSet(m_Default, filenameFrom, stripFilename) && !m_Default.empty())
  1420. {
  1421. // When updating default directory, also update the working directory.
  1422. InternalSet(m_Working, filenameFrom, stripFilename);
  1423. }
  1424. }
  1425. void DefaultAndWorkingDirectory::SetWorkingDir(const mpt::PathString &filenameFrom, bool stripFilename)
  1426. {
  1427. InternalSet(m_Working, filenameFrom, stripFilename);
  1428. }
  1429. mpt::PathString DefaultAndWorkingDirectory::GetDefaultDir() const
  1430. {
  1431. return m_Default;
  1432. }
  1433. mpt::PathString DefaultAndWorkingDirectory::GetWorkingDir() const
  1434. {
  1435. return m_Working;
  1436. }
  1437. // Retrieve / set default directory from given string and store it our setup variables
  1438. // If stripFilename is true, the filenameFrom parameter is assumed to be a full path including a filename.
  1439. // Return true if the value changed.
  1440. bool DefaultAndWorkingDirectory::InternalSet(mpt::PathString &dest, const mpt::PathString &filenameFrom, bool stripFilename)
  1441. {
  1442. mpt::PathString newPath = (stripFilename ? filenameFrom.GetPath() : filenameFrom);
  1443. newPath.EnsureTrailingSlash();
  1444. mpt::PathString oldPath = dest;
  1445. dest = newPath;
  1446. return newPath != oldPath;
  1447. }
  1448. ConfigurableDirectory::ConfigurableDirectory(SettingsContainer &conf, const AnyStringLocale &section, const AnyStringLocale &key, const mpt::PathString &def)
  1449. : conf(conf)
  1450. , m_Setting(conf, section, key, def)
  1451. {
  1452. SetDefaultDir(theApp.PathInstallRelativeToAbsolute(m_Setting), false);
  1453. }
  1454. ConfigurableDirectory::~ConfigurableDirectory()
  1455. {
  1456. m_Setting = theApp.IsPortableMode() ? theApp.PathAbsoluteToInstallRelative(m_Default) : m_Default;
  1457. }
  1458. OPENMPT_NAMESPACE_END