Mpdlgs.cpp 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991
  1. /*
  2. * MPDlgs.cpp
  3. * ----------
  4. * Purpose: Implementation of various player setup dialogs.
  5. * Notes : (currently none)
  6. * Authors: OpenMPT Devs
  7. * The OpenMPT source code is released under the BSD license. Read LICENSE for more details.
  8. */
  9. #include "stdafx.h"
  10. #include "Mptrack.h"
  11. #include "Sndfile.h"
  12. #include "Mainfrm.h"
  13. #include "ImageLists.h"
  14. #include "Moddoc.h"
  15. #include "Mpdlgs.h"
  16. #include "dlg_misc.h"
  17. #include "../common/mptStringBuffer.h"
  18. #include "openmpt/sounddevice/SoundDevice.hpp"
  19. #include "openmpt/sounddevice/SoundDeviceManager.hpp"
  20. #include "../common/Dither.h"
  21. OPENMPT_NAMESPACE_BEGIN
  22. const TCHAR *gszChnCfgNames[3] =
  23. {
  24. _T("Mono"),
  25. _T("Stereo"),
  26. _T("Quad")
  27. };
  28. static double ParseTime(CString str)
  29. {
  30. return ConvertStrTo<double>(mpt::ToCharset(mpt::Charset::ASCII, str)) / 1000.0;
  31. }
  32. static CString PrintTime(double seconds)
  33. {
  34. int32 microseconds = mpt::saturate_round<int32>(seconds * 1000000.0);
  35. int precision = 0;
  36. if(microseconds < 1000)
  37. {
  38. precision = 3;
  39. } else if(microseconds < 10000)
  40. {
  41. precision = 2;
  42. } else if(microseconds < 100000)
  43. {
  44. precision = 1;
  45. } else
  46. {
  47. precision = 0;
  48. }
  49. return MPT_CFORMAT("{} ms")(mpt::cfmt::fix(seconds * 1000.0, precision));
  50. }
  51. BEGIN_MESSAGE_MAP(COptionsSoundcard, CPropertyPage)
  52. ON_WM_HSCROLL()
  53. ON_COMMAND(IDC_CHECK4, &COptionsSoundcard::OnExclusiveModeChanged)
  54. ON_COMMAND(IDC_CHECK5, &COptionsSoundcard::OnSettingsChanged)
  55. ON_COMMAND(IDC_CHECK7, &COptionsSoundcard::OnSettingsChanged)
  56. ON_COMMAND(IDC_CHECK9, &COptionsSoundcard::OnSettingsChanged)
  57. ON_COMMAND(IDC_CHECK_SOUNDCARD_SHOWALL, &COptionsSoundcard::OnSoundCardShowAll)
  58. ON_CBN_SELCHANGE(IDC_COMBO1, &COptionsSoundcard::OnDeviceChanged)
  59. ON_CBN_SELCHANGE(IDC_COMBO2, &COptionsSoundcard::OnSettingsChanged)
  60. ON_CBN_SELCHANGE(IDC_COMBO_UPDATEINTERVAL, &COptionsSoundcard::OnSettingsChanged)
  61. ON_CBN_SELCHANGE(IDC_COMBO3, &COptionsSoundcard::OnSettingsChanged)
  62. ON_CBN_SELCHANGE(IDC_COMBO4, &COptionsSoundcard::OnSettingsChanged)
  63. ON_CBN_SELCHANGE(IDC_COMBO5, &COptionsSoundcard::OnChannelsChanged)
  64. ON_CBN_SELCHANGE(IDC_COMBO6, &COptionsSoundcard::OnSampleFormatChanged)
  65. ON_CBN_SELCHANGE(IDC_COMBO10, &COptionsSoundcard::OnSettingsChanged)
  66. ON_CBN_EDITCHANGE(IDC_COMBO2, &COptionsSoundcard::OnSettingsChanged)
  67. ON_CBN_EDITCHANGE(IDC_COMBO_UPDATEINTERVAL, &COptionsSoundcard::OnSettingsChanged)
  68. ON_CBN_SELCHANGE(IDC_COMBO11, &COptionsSoundcard::OnSettingsChanged)
  69. ON_COMMAND(IDC_BUTTON1, &COptionsSoundcard::OnSoundCardRescan)
  70. ON_COMMAND(IDC_BUTTON2, &COptionsSoundcard::OnSoundCardDriverPanel)
  71. ON_CBN_SELCHANGE(IDC_COMBO_CHANNEL_FRONTLEFT, &COptionsSoundcard::OnChannel1Changed)
  72. ON_CBN_SELCHANGE(IDC_COMBO_CHANNEL_FRONTRIGHT, &COptionsSoundcard::OnChannel2Changed)
  73. ON_CBN_SELCHANGE(IDC_COMBO_CHANNEL_REARLEFT, &COptionsSoundcard::OnChannel3Changed)
  74. ON_CBN_SELCHANGE(IDC_COMBO_CHANNEL_REARRIGHT, &COptionsSoundcard::OnChannel4Changed)
  75. ON_CBN_SELCHANGE(IDC_COMBO_RECORDING_CHANNELS, &COptionsSoundcard::OnRecordingChanged)
  76. ON_CBN_SELCHANGE(IDC_COMBO_RECORDING_SOURCE, &COptionsSoundcard::OnSettingsChanged)
  77. END_MESSAGE_MAP()
  78. void COptionsSoundcard::OnSampleFormatChanged()
  79. {
  80. OnSettingsChanged();
  81. UpdateDither();
  82. }
  83. void COptionsSoundcard::OnRecordingChanged()
  84. {
  85. DWORD_PTR inputChannels = m_CbnRecordingChannels.GetItemData(m_CbnRecordingChannels.GetCurSel());
  86. m_CbnRecordingSource.EnableWindow((m_CurrentDeviceCaps.HasNamedInputSources && inputChannels > 0) ? TRUE : FALSE);
  87. OnSettingsChanged();
  88. }
  89. void COptionsSoundcard::DoDataExchange(CDataExchange* pDX)
  90. {
  91. CPropertyPage::DoDataExchange(pDX);
  92. //{{AFX_DATA_MAP(COptionsSoundcard)
  93. DDX_Control(pDX, IDC_COMBO1, m_CbnDevice);
  94. DDX_Control(pDX, IDC_COMBO2, m_CbnLatencyMS);
  95. DDX_Control(pDX, IDC_COMBO_UPDATEINTERVAL, m_CbnUpdateIntervalMS);
  96. DDX_Control(pDX, IDC_COMBO3, m_CbnMixingFreq);
  97. DDX_Control(pDX, IDC_COMBO5, m_CbnChannels);
  98. DDX_Control(pDX, IDC_COMBO6, m_CbnSampleFormat);
  99. DDX_Control(pDX, IDC_COMBO10, m_CbnDither);
  100. DDX_Control(pDX, IDC_BUTTON2, m_BtnDriverPanel);
  101. DDX_Control(pDX, IDC_COMBO6, m_CbnSampleFormat);
  102. DDX_Control(pDX, IDC_COMBO11, m_CbnStoppedMode);
  103. DDX_Control(pDX, IDC_COMBO_CHANNEL_FRONTLEFT , m_CbnChannelMapping[0]);
  104. DDX_Control(pDX, IDC_COMBO_CHANNEL_FRONTRIGHT, m_CbnChannelMapping[1]);
  105. DDX_Control(pDX, IDC_COMBO_CHANNEL_REARLEFT , m_CbnChannelMapping[2]);
  106. DDX_Control(pDX, IDC_COMBO_CHANNEL_REARRIGHT , m_CbnChannelMapping[3]);
  107. DDX_Control(pDX, IDC_COMBO_RECORDING_CHANNELS, m_CbnRecordingChannels);
  108. DDX_Control(pDX, IDC_COMBO_RECORDING_SOURCE, m_CbnRecordingSource);
  109. DDX_Control(pDX, IDC_EDIT_STATISTICS, m_EditStatistics);
  110. //}}AFX_DATA_MAP
  111. }
  112. COptionsSoundcard::COptionsSoundcard(SoundDevice::Identifier deviceIdentifier)
  113. : CPropertyPage(IDD_OPTIONS_SOUNDCARD)
  114. , m_InitialDeviceIdentifier(deviceIdentifier)
  115. {
  116. return;
  117. }
  118. void COptionsSoundcard::SetInitialDevice()
  119. {
  120. SetDevice(m_InitialDeviceIdentifier, true);
  121. }
  122. void COptionsSoundcard::SetDevice(SoundDevice::Identifier dev, bool forceReload)
  123. {
  124. SoundDevice::Identifier olddev = m_CurrentDeviceInfo.GetIdentifier();
  125. SoundDevice::Info newInfo;
  126. SoundDevice::Caps newCaps;
  127. SoundDevice::DynamicCaps newDynamicCaps;
  128. SoundDevice::Settings newSettings;
  129. newInfo = theApp.GetSoundDevicesManager()->FindDeviceInfo(dev);
  130. newCaps = theApp.GetSoundDevicesManager()->GetDeviceCaps(dev, CMainFrame::GetMainFrame()->gpSoundDevice);
  131. newDynamicCaps = theApp.GetSoundDevicesManager()->GetDeviceDynamicCaps(dev, TrackerSettings::Instance().GetSampleRates(), CMainFrame::GetMainFrame(), CMainFrame::GetMainFrame()->gpSoundDevice, true);
  132. bool deviceChanged = (dev != olddev);
  133. if(deviceChanged || forceReload)
  134. {
  135. newSettings = TrackerSettings::Instance().GetSoundDeviceSettings(dev);
  136. } else
  137. {
  138. newSettings = m_Settings;
  139. }
  140. m_CurrentDeviceInfo = newInfo;
  141. m_CurrentDeviceCaps = newCaps;
  142. m_CurrentDeviceDynamicCaps = newDynamicCaps;
  143. m_Settings = newSettings;
  144. }
  145. void COptionsSoundcard::OnSoundCardShowAll()
  146. {
  147. TrackerSettings::Instance().m_SoundShowDeprecatedDevices = (IsDlgButtonChecked(IDC_CHECK_SOUNDCARD_SHOWALL) == BST_CHECKED);
  148. SetDevice(m_CurrentDeviceInfo.GetIdentifier(), true);
  149. UpdateEverything();
  150. }
  151. void COptionsSoundcard::OnSoundCardRescan()
  152. {
  153. {
  154. // Close sound device because IDs might change when re-enumerating which could cause all kinds of havoc.
  155. CMainFrame::GetMainFrame()->audioCloseDevice();
  156. delete CMainFrame::GetMainFrame()->gpSoundDevice;
  157. CMainFrame::GetMainFrame()->gpSoundDevice = nullptr;
  158. }
  159. theApp.GetSoundDevicesManager()->ReEnumerate();
  160. SetDevice(m_CurrentDeviceInfo.GetIdentifier(), true);
  161. UpdateEverything();
  162. }
  163. BOOL COptionsSoundcard::OnInitDialog()
  164. {
  165. CPropertyPage::OnInitDialog();
  166. SetInitialDevice();
  167. UpdateEverything();
  168. return TRUE;
  169. }
  170. void COptionsSoundcard::UpdateLatency()
  171. {
  172. {
  173. GetDlgItem(IDC_STATIC_LATENCY)->EnableWindow(TRUE);
  174. m_CbnLatencyMS.EnableWindow(TRUE);
  175. }
  176. // latency
  177. {
  178. static constexpr double latencies [] = {
  179. 0.001,
  180. 0.002,
  181. 0.003,
  182. 0.004,
  183. 0.005,
  184. 0.010,
  185. 0.015,
  186. 0.020,
  187. 0.025,
  188. 0.030,
  189. 0.040,
  190. 0.050,
  191. 0.075,
  192. 0.100,
  193. 0.150,
  194. 0.200,
  195. 0.250
  196. };
  197. m_CbnLatencyMS.ResetContent();
  198. m_CbnLatencyMS.SetWindowText(PrintTime(m_Settings.Latency));
  199. for(auto lat : latencies)
  200. {
  201. if(m_CurrentDeviceCaps.LatencyMin <= lat && lat <= m_CurrentDeviceCaps.LatencyMax)
  202. {
  203. m_CbnLatencyMS.AddString(PrintTime(lat));
  204. }
  205. }
  206. }
  207. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  208. {
  209. GetDlgItem(IDC_STATIC_LATENCY)->EnableWindow(FALSE);
  210. m_CbnLatencyMS.EnableWindow(FALSE);
  211. }
  212. }
  213. void COptionsSoundcard::UpdateUpdateInterval()
  214. {
  215. {
  216. m_CbnUpdateIntervalMS.EnableWindow(TRUE);
  217. }
  218. // update interval
  219. {
  220. static constexpr double updateIntervals [] = {
  221. 0.001,
  222. 0.002,
  223. 0.005,
  224. 0.010,
  225. 0.015,
  226. 0.020,
  227. 0.025,
  228. 0.050
  229. };
  230. m_CbnUpdateIntervalMS.ResetContent();
  231. m_CbnUpdateIntervalMS.SetWindowText(PrintTime(m_Settings.UpdateInterval));
  232. for(auto upd : updateIntervals)
  233. {
  234. if(m_CurrentDeviceCaps.UpdateIntervalMin <= upd && upd <= m_CurrentDeviceCaps.UpdateIntervalMax)
  235. {
  236. m_CbnUpdateIntervalMS.AddString(PrintTime(upd));
  237. }
  238. }
  239. }
  240. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()) || !m_CurrentDeviceCaps.CanUpdateInterval)
  241. {
  242. m_CbnUpdateIntervalMS.EnableWindow(FALSE);
  243. }
  244. }
  245. void COptionsSoundcard::UpdateGeneral()
  246. {
  247. // General
  248. {
  249. if(m_CurrentDeviceCaps.CanKeepDeviceRunning)
  250. {
  251. m_CbnStoppedMode.ResetContent();
  252. m_CbnStoppedMode.AddString(_T("Close driver"));
  253. m_CbnStoppedMode.AddString(_T("Pause driver"));
  254. m_CbnStoppedMode.AddString(_T("Play silence"));
  255. m_CbnStoppedMode.SetCurSel(TrackerSettings::Instance().m_SoundSettingsStopMode);
  256. } else
  257. {
  258. m_CbnStoppedMode.ResetContent();
  259. m_CbnStoppedMode.AddString(_T("Close driver"));
  260. m_CbnStoppedMode.AddString(_T("Close driver"));
  261. m_CbnStoppedMode.AddString(_T("Close driver"));
  262. m_CbnStoppedMode.SetCurSel(TrackerSettings::Instance().m_SoundSettingsStopMode);
  263. }
  264. CheckDlgButton(IDC_CHECK7, TrackerSettings::Instance().m_SoundSettingsOpenDeviceAtStartup ? BST_CHECKED : BST_UNCHECKED);
  265. }
  266. bool isUnavailble = theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier());
  267. m_CbnStoppedMode.EnableWindow(isUnavailble ? FALSE : (m_CurrentDeviceCaps.CanKeepDeviceRunning ? TRUE : FALSE));
  268. CPropertySheet *sheet = dynamic_cast<CPropertySheet *>(GetParent());
  269. if(sheet) sheet->GetDlgItem(IDOK)->EnableWindow(isUnavailble ? FALSE : TRUE);
  270. }
  271. void COptionsSoundcard::UpdateEverything()
  272. {
  273. // Sound Device
  274. {
  275. if(m_CurrentDeviceInfo.IsDeprecated())
  276. {
  277. TrackerSettings::Instance().m_SoundShowDeprecatedDevices = true;
  278. }
  279. CheckDlgButton(IDC_CHECK_SOUNDCARD_SHOWALL, TrackerSettings::Instance().m_SoundShowDeprecatedDevices ? BST_CHECKED : BST_UNCHECKED);
  280. m_CbnDevice.ResetContent();
  281. m_CbnDevice.SetImageList(&CMainFrame::GetMainFrame()->m_MiscIcons);
  282. UINT iItem = 0;
  283. for(const auto &it : *theApp.GetSoundDevicesManager())
  284. {
  285. if(!TrackerSettings::Instance().m_SoundShowDeprecatedDevices)
  286. {
  287. if(it.IsDeprecated())
  288. {
  289. continue;
  290. }
  291. }
  292. {
  293. COMBOBOXEXITEM cbi;
  294. MemsetZero(cbi);
  295. cbi.iItem = iItem;
  296. cbi.cchTextMax = 0;
  297. cbi.mask = CBEIF_LPARAM | CBEIF_TEXT;
  298. cbi.lParam = theApp.GetSoundDevicesManager()->GetGlobalID(it.GetIdentifier());
  299. mpt::ustring TypeWineNative = U_("Wine-Native");
  300. if(it.type == SoundDevice::TypeWAVEOUT || it.type == SoundDevice::TypePORTAUDIO_WMME)
  301. {
  302. cbi.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY;
  303. cbi.iImage = IMAGE_WAVEOUT;
  304. } else if(it.type == SoundDevice::TypeDSOUND || it.type == SoundDevice::TypePORTAUDIO_DS || it.type == U_("RtAudio-ds"))
  305. {
  306. cbi.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY;
  307. cbi.iImage = IMAGE_DIRECTX;
  308. } else if(it.type == SoundDevice::TypeASIO || it.type == U_("RtAudio-asio"))
  309. {
  310. cbi.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY;
  311. cbi.iImage = IMAGE_ASIO;
  312. } else if(it.type == SoundDevice::TypePORTAUDIO_WASAPI || it.type == U_("RtAudio-wasapi"))
  313. {
  314. cbi.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY;
  315. cbi.iImage = IMAGE_SAMPLEMUTE; // // No real image available for now,
  316. } else if(it.type == SoundDevice::TypePORTAUDIO_WDMKS)
  317. {
  318. cbi.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY;
  319. cbi.iImage = IMAGE_CHIP; // No real image available for now,
  320. } else if(it.type.find(TypeWineNative + U_("-")) == 0)
  321. {
  322. if(theApp.GetWineVersion() && (theApp.GetWineVersion()->HostClass() == mpt::osinfo::osclass::Linux))
  323. {
  324. cbi.mask |= CBEIF_IMAGE | CBEIF_SELECTEDIMAGE | CBEIF_OVERLAY;
  325. cbi.iImage = IMAGE_TUX;
  326. } else
  327. {
  328. cbi.iImage = 0;
  329. }
  330. } else
  331. {
  332. cbi.iImage = 0;
  333. }
  334. cbi.iSelectedImage = cbi.iImage;
  335. cbi.iOverlay = cbi.iImage;
  336. CString tmp = mpt::ToCString(it.GetDisplayName());
  337. cbi.pszText = const_cast<TCHAR *>(tmp.GetString());
  338. cbi.iIndent = 0;
  339. int pos = m_CbnDevice.InsertItem(&cbi);
  340. if(static_cast<SoundDevice::Manager::GlobalID>(cbi.lParam) == theApp.GetSoundDevicesManager()->GetGlobalID(m_CurrentDeviceInfo.GetIdentifier()))
  341. {
  342. m_CbnDevice.SetCurSel(pos);
  343. }
  344. iItem++;
  345. }
  346. }
  347. }
  348. UpdateDevice();
  349. }
  350. void COptionsSoundcard::UpdateDevice()
  351. {
  352. GetDlgItem(IDC_CHECK_SOUNDCARD_SHOWALL)->EnableWindow(m_CurrentDeviceInfo.IsDeprecated() ? FALSE : TRUE);
  353. UpdateGeneral();
  354. UpdateControls();
  355. UpdateLatency();
  356. UpdateUpdateInterval();
  357. UpdateSampleRates();
  358. UpdateChannels();
  359. UpdateSampleFormat();
  360. UpdateDither();
  361. UpdateChannelMapping();
  362. UpdateRecording();
  363. }
  364. void COptionsSoundcard::UpdateChannels()
  365. {
  366. {
  367. m_CbnChannels.EnableWindow(TRUE);
  368. }
  369. m_CbnChannels.ResetContent();
  370. int maxChannels = 0;
  371. if(m_CurrentDeviceDynamicCaps.channelNames.size() > 0)
  372. {
  373. maxChannels = static_cast<int>(std::min(std::size_t(4), m_CurrentDeviceDynamicCaps.channelNames.size()));
  374. } else
  375. {
  376. maxChannels = 4;
  377. }
  378. int sel = 0;
  379. for(int channels = maxChannels; channels >= 1; channels /= 2)
  380. {
  381. int ndx = m_CbnChannels.AddString(gszChnCfgNames[(channels+2)/2-1]);
  382. m_CbnChannels.SetItemData(ndx, channels);
  383. if(channels == m_Settings.Channels)
  384. {
  385. sel = ndx;
  386. }
  387. }
  388. m_CbnChannels.SetCurSel(sel);
  389. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  390. {
  391. m_CbnChannels.EnableWindow(FALSE);
  392. }
  393. }
  394. void COptionsSoundcard::UpdateRecording()
  395. {
  396. GetDlgItem(IDC_STATIC_RECORDING)->ShowWindow(TrackerSettings::Instance().m_SoundShowRecordingSettings ? SW_SHOW : SW_HIDE);
  397. m_CbnRecordingChannels.ShowWindow(TrackerSettings::Instance().m_SoundShowRecordingSettings ? SW_SHOW : SW_HIDE);
  398. m_CbnRecordingSource.ShowWindow(TrackerSettings::Instance().m_SoundShowRecordingSettings ? SW_SHOW : SW_HIDE);
  399. m_CbnRecordingChannels.ResetContent();
  400. m_CbnRecordingSource.ResetContent();
  401. if(m_CurrentDeviceCaps.CanInput && ((m_CurrentDeviceCaps.HasNamedInputSources && m_CurrentDeviceDynamicCaps.inputSourceNames.size() > 0) || !m_CurrentDeviceCaps.HasNamedInputSources))
  402. {
  403. GetDlgItem(IDC_STATIC_RECORDING)->EnableWindow(TRUE);
  404. m_CbnRecordingChannels.EnableWindow(TRUE);
  405. int sel = 0;
  406. {
  407. int ndx = m_CbnRecordingChannels.AddString(_T("off"));
  408. m_CbnRecordingChannels.SetItemData(ndx, 0);
  409. if(0 == m_Settings.InputChannels)
  410. {
  411. sel = ndx;
  412. }
  413. }
  414. for(int channels = 4; channels >= 1; channels /= 2)
  415. {
  416. int ndx = m_CbnRecordingChannels.AddString(gszChnCfgNames[(channels+2)/2-1]);
  417. m_CbnRecordingChannels.SetItemData(ndx, channels);
  418. if(channels == m_Settings.InputChannels)
  419. {
  420. sel = ndx;
  421. }
  422. }
  423. m_CbnRecordingChannels.SetCurSel(sel);
  424. if(m_CurrentDeviceCaps.HasNamedInputSources)
  425. {
  426. m_CbnRecordingSource.EnableWindow((m_Settings.InputChannels > 0) ? TRUE : FALSE);
  427. sel = -1;
  428. for(size_t ch = 0; ch < m_CurrentDeviceDynamicCaps.inputSourceNames.size(); ch++)
  429. {
  430. const int pos = (int)::SendMessageW(m_CbnRecordingSource.m_hWnd, CB_ADDSTRING, 0, (LPARAM)m_CurrentDeviceDynamicCaps.inputSourceNames[ch].second.c_str());
  431. m_CbnRecordingSource.SetItemData(pos, (DWORD_PTR)m_CurrentDeviceDynamicCaps.inputSourceNames[ch].first);
  432. if(m_CurrentDeviceDynamicCaps.inputSourceNames[ch].first == m_Settings.InputSourceID)
  433. {
  434. sel = pos;
  435. }
  436. }
  437. if(sel == -1 ) sel = 0;
  438. m_CbnRecordingSource.SetCurSel(sel);
  439. } else
  440. {
  441. m_CbnRecordingSource.EnableWindow(FALSE);
  442. }
  443. } else
  444. {
  445. GetDlgItem(IDC_STATIC_RECORDING)->EnableWindow(FALSE);
  446. m_CbnRecordingChannels.EnableWindow(FALSE);
  447. int ndx = m_CbnRecordingChannels.AddString(_T("off"));
  448. m_CbnRecordingChannels.SetItemData(ndx, 0);
  449. m_CbnRecordingChannels.SetCurSel(ndx);
  450. m_CbnRecordingSource.EnableWindow(FALSE);
  451. }
  452. }
  453. void COptionsSoundcard::UpdateSampleFormat()
  454. {
  455. {
  456. m_CbnSampleFormat.EnableWindow(TRUE);
  457. }
  458. UINT n = 0;
  459. m_CbnSampleFormat.ResetContent();
  460. std::vector<SampleFormat> sampleformats;
  461. if(IsDlgButtonChecked(IDC_CHECK4))
  462. {
  463. sampleformats = m_CurrentDeviceDynamicCaps.supportedExclusiveModeSampleFormats;
  464. } else
  465. {
  466. sampleformats = m_CurrentDeviceDynamicCaps.supportedSampleFormats;
  467. }
  468. m_CbnSampleFormat.EnableWindow(m_CurrentDeviceCaps.CanSampleFormat && (sampleformats.size() != 1) ? TRUE : FALSE);
  469. const std::vector<SampleFormat> allSampleFormats = AllSampleFormats<std::vector<SampleFormat>>();
  470. for(const auto sampleFormat : allSampleFormats)
  471. {
  472. if(!sampleformats.empty() && !mpt::contains(sampleformats, sampleFormat))
  473. {
  474. continue;
  475. }
  476. CString name;
  477. if(sampleFormat.IsFloat())
  478. {
  479. name = MPT_CFORMAT("Float {} bit")(sampleFormat.GetBitsPerSample());
  480. } else if(sampleFormat.IsUnsigned())
  481. {
  482. name = MPT_CFORMAT("{} Bit uint")(sampleFormat.GetBitsPerSample());
  483. } else
  484. {
  485. name = MPT_CFORMAT("{} Bit")(sampleFormat.GetBitsPerSample());
  486. }
  487. UINT ndx = m_CbnSampleFormat.AddString(name);
  488. m_CbnSampleFormat.SetItemData(ndx, mpt::to_underlying<SampleFormat::Enum>(sampleFormat));
  489. if(sampleFormat == m_Settings.sampleFormat)
  490. {
  491. n = ndx;
  492. }
  493. }
  494. m_CbnSampleFormat.SetCurSel(n);
  495. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  496. {
  497. m_CbnSampleFormat.EnableWindow(FALSE);
  498. }
  499. }
  500. void COptionsSoundcard::UpdateDither()
  501. {
  502. {
  503. m_CbnDither.EnableWindow(TRUE);
  504. }
  505. m_CbnDither.ResetContent();
  506. SampleFormat sampleFormat = SampleFormat::FromInt(static_cast<int>(m_CbnSampleFormat.GetItemData(m_CbnSampleFormat.GetCurSel())));
  507. if(sampleFormat.IsInt() && sampleFormat.GetBitsPerSample() < 32)
  508. {
  509. m_CbnDither.EnableWindow(TRUE);
  510. for(std::size_t i = 0; i < DithersOpenMPT::GetNumDithers(); ++i)
  511. {
  512. m_CbnDither.AddString(mpt::ToCString(DithersOpenMPT::GetModeName(i) + U_(" dither")));
  513. }
  514. } else if(m_CurrentDeviceCaps.HasInternalDither)
  515. {
  516. m_CbnDither.EnableWindow(TRUE);
  517. m_CbnDither.AddString(mpt::ToCString(DithersOpenMPT::GetModeName(DithersOpenMPT::GetNoDither()) + U_(" dither")));
  518. m_CbnDither.AddString(mpt::ToCString(DithersOpenMPT::GetModeName(DithersOpenMPT::GetDefaultDither()) + U_(" dither")));
  519. } else
  520. {
  521. m_CbnDither.EnableWindow(FALSE);
  522. for(std::size_t i = 0; i < DithersOpenMPT::GetNumDithers(); ++i)
  523. {
  524. m_CbnDither.AddString(mpt::ToCString(DithersOpenMPT::GetModeName(DithersOpenMPT::GetNoDither()) + U_(" dither")));
  525. }
  526. }
  527. if(m_Settings.DitherType < 0 || m_Settings.DitherType >= m_CbnDither.GetCount())
  528. {
  529. m_CbnDither.SetCurSel(1);
  530. } else
  531. {
  532. m_CbnDither.SetCurSel(m_Settings.DitherType);
  533. }
  534. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  535. {
  536. m_CbnDither.EnableWindow(FALSE);
  537. }
  538. }
  539. void COptionsSoundcard::UpdateChannelMapping()
  540. {
  541. {
  542. GetDlgItem(IDC_STATIC_CHANNELMAPPING)->EnableWindow(TRUE);
  543. GetDlgItem(IDC_STATIC_CHANNEL_FRONT)->EnableWindow(TRUE);
  544. GetDlgItem(IDC_STATIC_CHANNEL_REAR)->EnableWindow(TRUE);
  545. for(int mch = 0; mch < NUM_CHANNELCOMBOBOXES; mch++)
  546. {
  547. CComboBox *combo = &m_CbnChannelMapping[mch];
  548. combo->EnableWindow(TRUE);
  549. }
  550. }
  551. int usedChannels = static_cast<int>(m_CbnChannels.GetItemData(m_CbnChannels.GetCurSel()));
  552. if(m_Settings.Channels.GetNumHostChannels() != static_cast<uint32>(usedChannels))
  553. {
  554. // If the channel mapping is not valid for the selected number of channels, reset it to default identity mapping.
  555. m_Settings.Channels = SoundDevice::ChannelMapping(usedChannels);
  556. }
  557. GetDlgItem(IDC_STATIC_CHANNELMAPPING)->EnableWindow(m_CurrentDeviceCaps.CanChannelMapping ? TRUE : FALSE);
  558. if(m_CurrentDeviceCaps.CanChannelMapping && usedChannels > 2)
  559. {
  560. GetDlgItem(IDC_STATIC_CHANNEL_FRONT)->EnableWindow(TRUE);
  561. GetDlgItem(IDC_STATIC_CHANNEL_REAR)->EnableWindow(TRUE);
  562. } else
  563. {
  564. GetDlgItem(IDC_STATIC_CHANNEL_FRONT)->EnableWindow(FALSE);
  565. GetDlgItem(IDC_STATIC_CHANNEL_REAR)->EnableWindow(FALSE);
  566. }
  567. for(int mch = 0; mch < NUM_CHANNELCOMBOBOXES; mch++) // Host channels
  568. {
  569. CComboBox *combo = &m_CbnChannelMapping[mch];
  570. combo->EnableWindow((m_CurrentDeviceCaps.CanChannelMapping && mch < usedChannels) ? TRUE : FALSE);
  571. combo->ResetContent();
  572. if(m_CurrentDeviceCaps.CanChannelMapping)
  573. {
  574. combo->SetItemData(combo->AddString(_T("Unassigned")), (DWORD_PTR)-1);
  575. combo->SetCurSel(0);
  576. if(mch < usedChannels)
  577. {
  578. for(size_t dch = 0; dch < m_CurrentDeviceDynamicCaps.channelNames.size(); dch++) // Device channels
  579. {
  580. const int pos = (int)::SendMessageW(combo->m_hWnd, CB_ADDSTRING, 0, (LPARAM)m_CurrentDeviceDynamicCaps.channelNames[dch].c_str());
  581. combo->SetItemData(pos, (DWORD_PTR)dch);
  582. if(static_cast<int32>(dch) == m_Settings.Channels.ToDevice(mch))
  583. {
  584. combo->SetCurSel(pos);
  585. }
  586. }
  587. }
  588. }
  589. }
  590. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  591. {
  592. GetDlgItem(IDC_STATIC_CHANNELMAPPING)->EnableWindow(FALSE);
  593. GetDlgItem(IDC_STATIC_CHANNEL_FRONT)->EnableWindow(FALSE);
  594. GetDlgItem(IDC_STATIC_CHANNEL_REAR)->EnableWindow(FALSE);
  595. for(int mch = 0; mch < NUM_CHANNELCOMBOBOXES; mch++)
  596. {
  597. CComboBox *combo = &m_CbnChannelMapping[mch];
  598. combo->EnableWindow(FALSE);
  599. }
  600. }
  601. }
  602. void COptionsSoundcard::OnDeviceChanged()
  603. {
  604. int n = m_CbnDevice.GetCurSel();
  605. if(n >= 0)
  606. {
  607. SetDevice(theApp.GetSoundDevicesManager()->FindDeviceInfo(static_cast<SoundDevice::Manager::GlobalID>(m_CbnDevice.GetItemData(n))).GetIdentifier());
  608. UpdateDevice();
  609. OnSettingsChanged();
  610. }
  611. }
  612. void COptionsSoundcard::OnExclusiveModeChanged()
  613. {
  614. UpdateSampleRates();
  615. UpdateSampleFormat();
  616. UpdateDither();
  617. OnSettingsChanged();
  618. }
  619. void COptionsSoundcard::OnChannelsChanged()
  620. {
  621. UpdateChannelMapping();
  622. OnSettingsChanged();
  623. }
  624. void COptionsSoundcard::OnSoundCardDriverPanel()
  625. {
  626. theApp.GetSoundDevicesManager()->OpenDriverSettings(
  627. theApp.GetSoundDevicesManager()->FindDeviceInfo(static_cast<SoundDevice::Manager::GlobalID>(m_CbnDevice.GetItemData(m_CbnDevice.GetCurSel()))).GetIdentifier(),
  628. CMainFrame::GetMainFrame(),
  629. CMainFrame::GetMainFrame()->gpSoundDevice
  630. );
  631. }
  632. void COptionsSoundcard::OnChannelChanged(int channel)
  633. {
  634. CComboBox *combo = &m_CbnChannelMapping[channel];
  635. const LONG_PTR newChn = combo->GetItemData(combo->GetCurSel());
  636. if(newChn == -1)
  637. {
  638. return;
  639. }
  640. // Ensure that no channel is used twice
  641. for(int mch = 0; mch < NUM_CHANNELCOMBOBOXES; mch++) // Host channels
  642. {
  643. if(mch != channel)
  644. {
  645. combo = &m_CbnChannelMapping[mch];
  646. if((int)combo->GetItemData(combo->GetCurSel()) == newChn)
  647. {
  648. // find an unused channel
  649. bool found = false;
  650. int deviceChannel = 0;
  651. for(; deviceChannel < static_cast<int>(m_CurrentDeviceDynamicCaps.channelNames.size()); ++deviceChannel)
  652. {
  653. bool used = false;
  654. for(int hostChannel = 0; hostChannel < NUM_CHANNELCOMBOBOXES; ++hostChannel)
  655. {
  656. if(static_cast<int>(m_CbnChannelMapping[hostChannel].GetItemData(m_CbnChannelMapping[hostChannel].GetCurSel())) == deviceChannel)
  657. {
  658. used = true;
  659. break;
  660. }
  661. }
  662. if(!used)
  663. {
  664. found = true;
  665. break;
  666. }
  667. }
  668. if(found)
  669. {
  670. combo->SetCurSel(deviceChannel+1);
  671. } else
  672. {
  673. combo->SetCurSel(0);
  674. }
  675. break;
  676. }
  677. }
  678. }
  679. OnSettingsChanged();
  680. }
  681. // Fill the dropdown box with a list of valid sample rates, depending on the selected sound device.
  682. void COptionsSoundcard::UpdateSampleRates()
  683. {
  684. {
  685. GetDlgItem(IDC_STATIC_FORMAT)->EnableWindow(TRUE);
  686. m_CbnMixingFreq.EnableWindow(TRUE);
  687. }
  688. m_CbnMixingFreq.ResetContent();
  689. std::vector<uint32> samplerates;
  690. if(IsDlgButtonChecked(IDC_CHECK4))
  691. {
  692. samplerates = m_CurrentDeviceDynamicCaps.supportedExclusiveSampleRates;
  693. } else
  694. {
  695. samplerates = m_CurrentDeviceDynamicCaps.supportedSampleRates;
  696. }
  697. if(samplerates.empty())
  698. {
  699. // We have no valid list of supported playback rates! Assume all rates supported by OpenMPT are possible...
  700. samplerates = TrackerSettings::Instance().GetSampleRates();
  701. }
  702. int n = 0;
  703. for(size_t i = 0; i < samplerates.size(); i++)
  704. {
  705. int pos = m_CbnMixingFreq.AddString(MPT_CFORMAT("{} Hz")(samplerates[i]));
  706. m_CbnMixingFreq.SetItemData(pos, samplerates[i]);
  707. if(m_Settings.Samplerate == samplerates[i])
  708. {
  709. n = pos;
  710. }
  711. }
  712. m_CbnMixingFreq.SetCurSel(n);
  713. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  714. {
  715. GetDlgItem(IDC_STATIC_FORMAT)->EnableWindow(FALSE);
  716. m_CbnMixingFreq.EnableWindow(FALSE);
  717. }
  718. }
  719. void COptionsSoundcard::UpdateControls()
  720. {
  721. {
  722. m_BtnDriverPanel.EnableWindow(TRUE);
  723. GetDlgItem(IDC_CHECK4)->EnableWindow(TRUE);
  724. GetDlgItem(IDC_CHECK5)->EnableWindow(TRUE);
  725. GetDlgItem(IDC_CHECK9)->EnableWindow(TRUE);
  726. GetDlgItem(IDC_STATIC_UPDATEINTERVAL)->EnableWindow(TRUE);
  727. GetDlgItem(IDC_COMBO_UPDATEINTERVAL)->EnableWindow(TRUE);
  728. }
  729. if(!m_CurrentDeviceCaps.CanKeepDeviceRunning)
  730. {
  731. m_Settings.KeepDeviceRunning = false;
  732. }
  733. m_BtnDriverPanel.EnableWindow(m_CurrentDeviceCaps.CanDriverPanel ? TRUE : FALSE);
  734. GetDlgItem(IDC_CHECK4)->EnableWindow(m_CurrentDeviceCaps.CanExclusiveMode ? TRUE : FALSE);
  735. GetDlgItem(IDC_CHECK5)->EnableWindow(m_CurrentDeviceCaps.CanBoostThreadPriority ? TRUE : FALSE);
  736. GetDlgItem(IDC_CHECK9)->EnableWindow(m_CurrentDeviceCaps.CanUseHardwareTiming ? TRUE : FALSE);
  737. GetDlgItem(IDC_STATIC_UPDATEINTERVAL)->EnableWindow(m_CurrentDeviceCaps.CanUpdateInterval ? TRUE : FALSE);
  738. GetDlgItem(IDC_COMBO_UPDATEINTERVAL)->EnableWindow(m_CurrentDeviceCaps.CanUpdateInterval ? TRUE : FALSE);
  739. GetDlgItem(IDC_CHECK4)->SetWindowText(mpt::ToCString(m_CurrentDeviceCaps.ExclusiveModeDescription));
  740. CheckDlgButton(IDC_CHECK4, m_CurrentDeviceCaps.CanExclusiveMode && m_Settings.ExclusiveMode ? BST_CHECKED : BST_UNCHECKED);
  741. CheckDlgButton(IDC_CHECK5, m_CurrentDeviceCaps.CanBoostThreadPriority && m_Settings.BoostThreadPriority ? BST_CHECKED : BST_UNCHECKED);
  742. CheckDlgButton(IDC_CHECK9, m_CurrentDeviceCaps.CanUseHardwareTiming && m_Settings.UseHardwareTiming ? BST_CHECKED : BST_UNCHECKED);
  743. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  744. {
  745. m_BtnDriverPanel.EnableWindow(FALSE);
  746. GetDlgItem(IDC_CHECK4)->EnableWindow(FALSE);
  747. GetDlgItem(IDC_CHECK5)->EnableWindow(FALSE);
  748. GetDlgItem(IDC_CHECK9)->EnableWindow(FALSE);
  749. GetDlgItem(IDC_STATIC_UPDATEINTERVAL)->EnableWindow(FALSE);
  750. GetDlgItem(IDC_COMBO_UPDATEINTERVAL)->EnableWindow(FALSE);
  751. }
  752. }
  753. BOOL COptionsSoundcard::OnSetActive()
  754. {
  755. CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_SOUNDCARD;
  756. return CPropertyPage::OnSetActive();
  757. }
  758. void COptionsSoundcard::OnOK()
  759. {
  760. if(!theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  761. {
  762. // General
  763. {
  764. TrackerSettings::Instance().m_SoundSettingsOpenDeviceAtStartup = IsDlgButtonChecked(IDC_CHECK7) != BST_UNCHECKED;
  765. }
  766. m_Settings.ExclusiveMode = IsDlgButtonChecked(IDC_CHECK4) != BST_UNCHECKED;
  767. m_Settings.BoostThreadPriority = IsDlgButtonChecked(IDC_CHECK5) != BST_UNCHECKED;
  768. m_Settings.UseHardwareTiming = IsDlgButtonChecked(IDC_CHECK9) != BST_UNCHECKED;
  769. // Mixing Freq
  770. {
  771. m_Settings.Samplerate = static_cast<uint32>(m_CbnMixingFreq.GetItemData(m_CbnMixingFreq.GetCurSel()));
  772. }
  773. // Channels
  774. {
  775. DWORD_PTR n = m_CbnChannels.GetItemData(m_CbnChannels.GetCurSel());
  776. m_Settings.Channels = static_cast<int>(n);
  777. if((m_Settings.Channels != 1) && (m_Settings.Channels != 4))
  778. {
  779. m_Settings.Channels = 2;
  780. }
  781. }
  782. // SampleFormat
  783. {
  784. DWORD_PTR n = m_CbnSampleFormat.GetItemData(m_CbnSampleFormat.GetCurSel());
  785. m_Settings.sampleFormat = SampleFormat::FromInt(static_cast<int>(n));
  786. }
  787. // Dither
  788. {
  789. m_Settings.DitherType = m_CbnDither.GetCurSel();
  790. }
  791. // Latency
  792. {
  793. CString s;
  794. m_CbnLatencyMS.GetWindowText(s);
  795. m_Settings.Latency = ParseTime(s);
  796. //Check given value.
  797. if(m_Settings.Latency == 0.0) m_Settings.Latency = m_CurrentDeviceCaps.DefaultSettings.Latency;
  798. m_Settings.Latency = Clamp(m_Settings.Latency, m_CurrentDeviceCaps.LatencyMin, m_CurrentDeviceCaps.LatencyMax);
  799. m_CbnLatencyMS.SetWindowText(PrintTime(m_Settings.Latency));
  800. }
  801. // Update Interval
  802. {
  803. CString s;
  804. m_CbnUpdateIntervalMS.GetWindowText(s);
  805. m_Settings.UpdateInterval = ParseTime(s);
  806. //Check given value.
  807. if(m_Settings.UpdateInterval == 0.0) m_Settings.UpdateInterval = m_CurrentDeviceCaps.DefaultSettings.UpdateInterval;
  808. m_Settings.UpdateInterval = Clamp(m_Settings.UpdateInterval, m_CurrentDeviceCaps.UpdateIntervalMin, m_CurrentDeviceCaps.UpdateIntervalMax);
  809. m_CbnUpdateIntervalMS.SetWindowText(PrintTime(m_Settings.UpdateInterval));
  810. }
  811. // Channel Mapping
  812. {
  813. if(m_CurrentDeviceCaps.CanChannelMapping)
  814. {
  815. int numChannels = std::min(static_cast<int>(m_Settings.Channels), static_cast<int>(NUM_CHANNELCOMBOBOXES));
  816. std::vector<int32> channels(numChannels);
  817. for(int mch = 0; mch < numChannels; mch++) // Host channels
  818. {
  819. CComboBox *combo = &m_CbnChannelMapping[mch];
  820. channels[mch] = static_cast<int32>(combo->GetItemData(combo->GetCurSel()));
  821. }
  822. m_Settings.Channels = channels;
  823. }
  824. }
  825. // Recording
  826. {
  827. if(TrackerSettings::Instance().m_SoundShowRecordingSettings && m_CurrentDeviceCaps.CanInput && ((m_CurrentDeviceCaps.HasNamedInputSources && m_CurrentDeviceDynamicCaps.inputSourceNames.size() > 0) || !m_CurrentDeviceCaps.HasNamedInputSources))
  828. {
  829. DWORD_PTR n = m_CbnRecordingChannels.GetItemData(m_CbnRecordingChannels.GetCurSel());
  830. m_Settings.InputChannels = static_cast<uint8>(n);
  831. if((m_Settings.InputChannels != 1) && (m_Settings.InputChannels != 2) && (m_Settings.InputChannels != 4))
  832. {
  833. m_Settings.InputChannels = 0;
  834. }
  835. if(m_CurrentDeviceCaps.HasNamedInputSources)
  836. {
  837. DWORD_PTR sourceID = m_CbnRecordingSource.GetItemData(m_CbnRecordingSource.GetCurSel());
  838. m_Settings.InputSourceID = static_cast<uint32>(sourceID);
  839. } else
  840. {
  841. m_Settings.InputSourceID = 0;
  842. }
  843. } else
  844. {
  845. m_Settings.InputChannels = 0;
  846. m_Settings.InputSourceID = 0;
  847. }
  848. }
  849. CMainFrame::GetMainFrame()->SetupSoundCard(m_Settings, m_CurrentDeviceInfo.GetIdentifier(), (SoundDeviceStopMode)m_CbnStoppedMode.GetCurSel());
  850. SetDevice(m_CurrentDeviceInfo.GetIdentifier(), true); // Poll changed ASIO sample format and channel names
  851. UpdateDevice();
  852. UpdateStatistics();
  853. } else
  854. {
  855. Reporting::Error("Sound card currently not available.");
  856. }
  857. CPropertyPage::OnOK();
  858. }
  859. void COptionsSoundcard::UpdateStatistics()
  860. {
  861. if (!m_EditStatistics) return;
  862. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  863. if(pMainFrm->gpSoundDevice && pMainFrm->IsPlaying())
  864. {
  865. const SoundDevice::BufferAttributes bufferAttributes = pMainFrm->gpSoundDevice->GetEffectiveBufferAttributes();
  866. const SoundDevice::Statistics stats = pMainFrm->gpSoundDevice->GetStatistics();
  867. #if 0
  868. const SoundDevice::TimeInfo timeInfo = pMainFrm->gpSoundDevice->GetTimeInfo();
  869. const SoundDevice::StreamPosition streamPosition = pMainFrm->gpSoundDevice->GetStreamPosition();
  870. #endif
  871. const uint32 samplerate = pMainFrm->gpSoundDevice->GetSettings().Samplerate;
  872. mpt::ustring s;
  873. if(bufferAttributes.NumBuffers > 2)
  874. {
  875. s += MPT_UFORMAT("Buffer: {}% ({}/{})\r\n")((bufferAttributes.Latency > 0.0) ? mpt::saturate_round<int64>(stats.InstantaneousLatency / bufferAttributes.Latency * 100.0) : 0, (stats.LastUpdateInterval > 0.0) ? mpt::saturate_round<int64>(bufferAttributes.Latency / stats.LastUpdateInterval) : 0, bufferAttributes.NumBuffers);
  876. } else
  877. {
  878. s += MPT_UFORMAT("Buffer: {}%\r\n")((bufferAttributes.Latency > 0.0) ? mpt::saturate_round<int64>(stats.InstantaneousLatency / bufferAttributes.Latency * 100.0) : 0);
  879. }
  880. s += MPT_UFORMAT("Latency: {} ms (current: {} ms, {} frames)\r\n")(mpt::ufmt::fix(bufferAttributes.Latency * 1000.0, 1), mpt::ufmt::fix(stats.InstantaneousLatency * 1000.0, 1), mpt::saturate_round<int64>(stats.InstantaneousLatency * samplerate));
  881. s += MPT_UFORMAT("Period: {} ms (current: {} ms, {} frames)\r\n")(mpt::ufmt::fix(bufferAttributes.UpdateInterval * 1000.0, 1), mpt::ufmt::fix(stats.LastUpdateInterval * 1000.0, 1), mpt::saturate_round<int64>(stats.LastUpdateInterval * samplerate));
  882. #if 0
  883. s += MPT_UFORMAT("TimeInfo: latency = {} ms / speed = {} / latency = {} ms\r\n")(
  884. mpt::ufmt::fix(timeInfo.Latency * 1000.0, 1),
  885. mpt::ufmt::flt(timeInfo.Speed, 4),
  886. mpt::ufmt::fix((timeInfo.RenderStreamPositionBefore.Seconds - streamPosition.Seconds) * 1000.0, 1));
  887. #endif
  888. s += stats.text;
  889. m_EditStatistics.SetWindowText(mpt::ToCString(s));
  890. } else
  891. {
  892. if(theApp.GetSoundDevicesManager()->IsDeviceUnavailable(m_CurrentDeviceInfo.GetIdentifier()))
  893. {
  894. m_EditStatistics.SetWindowText(_T("Device currently unavailable."));
  895. } else
  896. {
  897. m_EditStatistics.SetWindowText(_T(""));
  898. }
  899. }
  900. }
  901. //////////////////
  902. // COptionsMixer
  903. BEGIN_MESSAGE_MAP(COptionsMixer, CPropertyPage)
  904. ON_WM_HSCROLL()
  905. ON_WM_VSCROLL()
  906. ON_CBN_SELCHANGE(IDC_COMBO_FILTER, &COptionsMixer::OnSettingsChanged)
  907. ON_CBN_SELCHANGE(IDC_COMBO_AMIGA_TYPE, &COptionsMixer::OnSettingsChanged)
  908. ON_EN_UPDATE(IDC_RAMPING_IN, &COptionsMixer::OnRampingChanged)
  909. ON_EN_UPDATE(IDC_RAMPING_OUT, &COptionsMixer::OnRampingChanged)
  910. ON_COMMAND(IDC_CHECK_SOFTPAN, &COptionsMixer::OnSettingsChanged)
  911. ON_COMMAND(IDC_CHECK1, &COptionsMixer::OnAmigaChanged)
  912. ON_COMMAND(IDC_BUTTON1, &COptionsMixer::OnDefaultRampSettings)
  913. END_MESSAGE_MAP()
  914. void COptionsMixer::DoDataExchange(CDataExchange* pDX)
  915. {
  916. CPropertyPage::DoDataExchange(pDX);
  917. //{{AFX_DATA_MAP(COptionsSoundcard)
  918. DDX_Control(pDX, IDC_COMBO_FILTER, m_CbnResampling);
  919. DDX_Control(pDX, IDC_COMBO_AMIGA_TYPE, m_CbnAmigaType);
  920. DDX_Control(pDX, IDC_RAMPING_IN, m_CEditRampUp);
  921. DDX_Control(pDX, IDC_RAMPING_OUT, m_CEditRampDown);
  922. DDX_Control(pDX, IDC_EDIT_VOLRAMP_SAMPLES_UP, m_CInfoRampUp);
  923. DDX_Control(pDX, IDC_EDIT_VOLRAMP_SAMPLES_DOWN, m_CInfoRampDown);
  924. DDX_Control(pDX, IDC_SLIDER_STEREOSEP, m_SliderStereoSep);
  925. // check box soft pan
  926. DDX_Control(pDX, IDC_SLIDER_PREAMP, m_SliderPreAmp);
  927. //}}AFX_DATA_MAP
  928. }
  929. BOOL COptionsMixer::OnInitDialog()
  930. {
  931. CPropertyPage::OnInitDialog();
  932. // Resampling type
  933. {
  934. const auto resamplingModes = Resampling::AllModes();
  935. for(auto mode : resamplingModes)
  936. {
  937. int index = m_CbnResampling.AddString(CTrackApp::GetResamplingModeName(mode, 2, true));
  938. m_CbnResampling.SetItemData(index, mode);
  939. if(TrackerSettings::Instance().ResamplerMode == mode)
  940. {
  941. m_CbnResampling.SetCurSel(index);
  942. }
  943. }
  944. }
  945. // Amiga Resampler
  946. const bool enableAmigaResampler = TrackerSettings::Instance().ResamplerEmulateAmiga != Resampling::AmigaFilter::Off;
  947. CheckDlgButton(IDC_CHECK1, enableAmigaResampler ? BST_CHECKED : BST_UNCHECKED);
  948. m_CbnAmigaType.EnableWindow(enableAmigaResampler ? TRUE : FALSE);
  949. static constexpr std::pair<const TCHAR *, Resampling::AmigaFilter> Filters[] =
  950. {
  951. {_T("A500 Filter"), Resampling::AmigaFilter::A500},
  952. {_T("A1200 Filter"), Resampling::AmigaFilter::A1200},
  953. {_T("Unfiltered"), Resampling::AmigaFilter::Unfiltered},
  954. };
  955. int sel = 0;
  956. for(const auto & [name, filter] : Filters)
  957. {
  958. const int item = m_CbnAmigaType.AddString(name);
  959. m_CbnAmigaType.SetItemData(item, static_cast<DWORD_PTR>(filter));
  960. if(filter == TrackerSettings::Instance().ResamplerEmulateAmiga)
  961. sel = item;
  962. }
  963. m_CbnAmigaType.SetCurSel(sel);
  964. // volume ramping
  965. {
  966. m_CEditRampUp.SetWindowText(mpt::ToCString(mpt::ufmt::val(TrackerSettings::Instance().GetMixerSettings().GetVolumeRampUpMicroseconds())));
  967. m_CEditRampDown.SetWindowText(mpt::ToCString(mpt::ufmt::val(TrackerSettings::Instance().GetMixerSettings().GetVolumeRampDownMicroseconds())));
  968. static_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN2))->SetRange32(0, int32_max);
  969. static_cast<CSpinButtonCtrl *>(GetDlgItem(IDC_SPIN3))->SetRange32(0, int32_max);
  970. UpdateRamping();
  971. }
  972. // Stereo Separation
  973. {
  974. m_SliderStereoSep.SetRange(0, 32);
  975. m_SliderStereoSep.SetPos(16);
  976. for (int n = 0; n <= 32; n++)
  977. {
  978. if ((int)TrackerSettings::Instance().MixerStereoSeparation <= 8 * n)
  979. {
  980. m_SliderStereoSep.SetPos(n);
  981. break;
  982. }
  983. }
  984. UpdateStereoSep();
  985. }
  986. // soft pan
  987. {
  988. CheckDlgButton(IDC_CHECK_SOFTPAN, (TrackerSettings::Instance().MixerFlags & SNDMIX_SOFTPANNING) ? BST_CHECKED : BST_UNCHECKED);
  989. }
  990. // Pre-Amplification
  991. {
  992. m_SliderPreAmp.SetTicFreq(5);
  993. m_SliderPreAmp.SetRange(0, 40);
  994. int n = (TrackerSettings::Instance().MixerPreAmp - 64) / 8;
  995. if ((n < 0) || (n > 40)) n = 16;
  996. m_SliderPreAmp.SetPos(n);
  997. }
  998. m_initialized = true;
  999. return TRUE;
  1000. }
  1001. BOOL COptionsMixer::OnSetActive()
  1002. {
  1003. CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_MIXER;
  1004. return CPropertyPage::OnSetActive();
  1005. }
  1006. void COptionsMixer::OnAmigaChanged()
  1007. {
  1008. const bool enableAmigaResampler = IsDlgButtonChecked(IDC_CHECK1) != BST_UNCHECKED;
  1009. m_CbnAmigaType.EnableWindow(enableAmigaResampler ? TRUE : FALSE);
  1010. OnSettingsChanged();
  1011. }
  1012. void COptionsMixer::OnRampingChanged()
  1013. {
  1014. if(!m_initialized)
  1015. return;
  1016. UpdateRamping();
  1017. OnSettingsChanged();
  1018. }
  1019. void COptionsMixer::OnDefaultRampSettings()
  1020. {
  1021. m_CEditRampUp.SetWindowText(mpt::ToCString(mpt::ufmt::val(MixerSettings().GetVolumeRampUpMicroseconds())));
  1022. m_CEditRampDown.SetWindowText(mpt::ToCString(mpt::ufmt::val(MixerSettings().GetVolumeRampDownMicroseconds())));
  1023. OnRampingChanged();
  1024. }
  1025. void COptionsMixer::OnHScroll(UINT n, UINT pos, CScrollBar *p)
  1026. {
  1027. CPropertyPage::OnHScroll(n, pos, p);
  1028. if(p == (CScrollBar *)&m_SliderStereoSep)
  1029. {
  1030. UpdateStereoSep();
  1031. OnSettingsChanged();
  1032. }
  1033. }
  1034. void COptionsMixer::UpdateRamping()
  1035. {
  1036. MixerSettings settings = TrackerSettings::Instance().GetMixerSettings();
  1037. CString s;
  1038. m_CEditRampUp.GetWindowText(s);
  1039. settings.SetVolumeRampUpMicroseconds(ConvertStrTo<int32>(s));
  1040. m_CEditRampDown.GetWindowText(s);
  1041. settings.SetVolumeRampDownMicroseconds(ConvertStrTo<int32>(s));
  1042. s.Format(_T("%i samples at %i Hz"), (int)settings.GetVolumeRampUpSamples(), (int)settings.gdwMixingFreq);
  1043. m_CInfoRampUp.SetWindowText(s);
  1044. s.Format(_T("%i samples at %i Hz"), (int)settings.GetVolumeRampDownSamples(), (int)settings.gdwMixingFreq);
  1045. m_CInfoRampDown.SetWindowText(s);
  1046. }
  1047. void COptionsMixer::UpdateStereoSep()
  1048. {
  1049. CString s;
  1050. s.Format(_T("%d%%"), ((8 * m_SliderStereoSep.GetPos()) * 100) / 128);
  1051. SetDlgItemText(IDC_TEXT_STEREOSEP, s);
  1052. }
  1053. void COptionsMixer::OnOK()
  1054. {
  1055. // resampler mode
  1056. {
  1057. TrackerSettings::Instance().ResamplerMode = static_cast<ResamplingMode>(m_CbnResampling.GetItemData(m_CbnResampling.GetCurSel()));
  1058. }
  1059. // Amiga Resampler
  1060. if(IsDlgButtonChecked(IDC_CHECK1) == BST_UNCHECKED)
  1061. TrackerSettings::Instance().ResamplerEmulateAmiga = Resampling::AmigaFilter::Off;
  1062. else
  1063. TrackerSettings::Instance().ResamplerEmulateAmiga = static_cast<Resampling::AmigaFilter>(m_CbnAmigaType.GetItemData(m_CbnAmigaType.GetCurSel()));
  1064. // volume ramping
  1065. {
  1066. MixerSettings settings = TrackerSettings::Instance().GetMixerSettings();
  1067. CString s;
  1068. m_CEditRampUp.GetWindowText(s);
  1069. settings.SetVolumeRampUpMicroseconds(ConvertStrTo<int>(s));
  1070. m_CEditRampDown.GetWindowText(s);
  1071. settings.SetVolumeRampDownMicroseconds(ConvertStrTo<int>(s));
  1072. TrackerSettings::Instance().SetMixerSettings(settings);
  1073. }
  1074. // stereo sep
  1075. {
  1076. TrackerSettings::Instance().MixerStereoSeparation = 8 * m_SliderStereoSep.GetPos();
  1077. }
  1078. // soft pan
  1079. {
  1080. if(IsDlgButtonChecked(IDC_CHECK_SOFTPAN))
  1081. {
  1082. TrackerSettings::Instance().MixerFlags = TrackerSettings::Instance().MixerFlags | SNDMIX_SOFTPANNING;
  1083. } else
  1084. {
  1085. TrackerSettings::Instance().MixerFlags = TrackerSettings::Instance().MixerFlags & ~SNDMIX_SOFTPANNING;
  1086. }
  1087. }
  1088. // pre amp
  1089. {
  1090. int n = m_SliderPreAmp.GetPos();
  1091. if ((n >= 0) && (n <= 40)) // approximately +/- 10dB
  1092. {
  1093. TrackerSettings::Instance().MixerPreAmp = 64 + (n * 8);
  1094. }
  1095. }
  1096. CMainFrame::GetMainFrame()->SetupPlayer();
  1097. CMainFrame::GetMainFrame()->PostMessage(WM_MOD_INVALIDATEPATTERNS, HINT_MPTOPTIONS);
  1098. CPropertyPage::OnOK();
  1099. }
  1100. ////////////////////////////////////////////////////////////////////////////////
  1101. //
  1102. // CEQSavePresetDlg
  1103. //
  1104. #ifndef NO_EQ
  1105. class CEQSavePresetDlg: public CDialog
  1106. {
  1107. protected:
  1108. EQPreset &m_EQ;
  1109. public:
  1110. CEQSavePresetDlg(EQPreset &eq, CWnd *parent = nullptr) : CDialog(IDD_SAVEPRESET, parent), m_EQ(eq) { }
  1111. BOOL OnInitDialog();
  1112. void OnOK();
  1113. };
  1114. BOOL CEQSavePresetDlg::OnInitDialog()
  1115. {
  1116. CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  1117. if (pCombo)
  1118. {
  1119. int ndx = 0;
  1120. for (UINT i=0; i<4; i++)
  1121. {
  1122. int n = pCombo->AddString(mpt::ToCString(mpt::Charset::Locale, TrackerSettings::Instance().m_EqUserPresets[i].szName));
  1123. pCombo->SetItemData( n, i);
  1124. if (!lstrcmpiA(TrackerSettings::Instance().m_EqUserPresets[i].szName, m_EQ.szName)) ndx = n;
  1125. }
  1126. pCombo->SetCurSel(ndx);
  1127. }
  1128. SetDlgItemText(IDC_EDIT1, mpt::ToCString(mpt::Charset::Locale, m_EQ.szName));
  1129. return TRUE;
  1130. }
  1131. void CEQSavePresetDlg::OnOK()
  1132. {
  1133. CComboBox *pCombo = (CComboBox *)GetDlgItem(IDC_COMBO1);
  1134. if (pCombo)
  1135. {
  1136. int n = pCombo->GetCurSel();
  1137. if ((n < 0) || (n >= 4)) n = 0;
  1138. CString s;
  1139. GetDlgItemText(IDC_EDIT1, s);
  1140. mpt::String::WriteAutoBuf(m_EQ.szName) = mpt::ToCharset(mpt::Charset::Locale, s);
  1141. TrackerSettings::Instance().m_EqUserPresets[n] = m_EQ;
  1142. }
  1143. CDialog::OnOK();
  1144. }
  1145. void CEQSlider::Init(UINT nID, UINT n, CWnd *parent)
  1146. {
  1147. m_nSliderNo = n;
  1148. m_pParent = parent;
  1149. SubclassDlgItem(nID, parent);
  1150. }
  1151. BOOL CEQSlider::PreTranslateMessage(MSG *pMsg)
  1152. {
  1153. if ((pMsg) && (pMsg->message == WM_RBUTTONDOWN) && (m_pParent))
  1154. {
  1155. m_x = LOWORD(pMsg->lParam);
  1156. m_y = HIWORD(pMsg->lParam);
  1157. m_pParent->PostMessage(WM_COMMAND, ID_EQSLIDER_BASE+m_nSliderNo, 0);
  1158. }
  1159. return CSliderCtrl::PreTranslateMessage(pMsg);
  1160. }
  1161. #endif // !NO_EQ
  1162. //////////////////////////////////////////////////////////
  1163. // COptionsPlayer - DSP / EQ settings
  1164. #ifndef NO_EQ
  1165. #define EQ_MAX_FREQS 5
  1166. const UINT gEqBandFreqs[MAX_EQ_BANDS][EQ_MAX_FREQS] =
  1167. {
  1168. { 100, 125, 150, 200, 250 },
  1169. { 300, 350, 400, 450, 500 },
  1170. { 600, 700, 800, 900, 1000 },
  1171. { 1250, 1500, 1750, 2000, 2500 },
  1172. { 3000, 3500, 4000, 4500, 5000 },
  1173. { 6000, 7000, 8000, 9000, 10000 },
  1174. };
  1175. #endif // !NO_EQ
  1176. BEGIN_MESSAGE_MAP(COptionsPlayer, CPropertyPage)
  1177. #ifndef NO_EQ
  1178. // EQ
  1179. ON_WM_VSCROLL()
  1180. ON_COMMAND(IDC_CHECK3, &COptionsPlayer::OnSettingsChanged)
  1181. ON_COMMAND(IDC_BUTTON1, &COptionsPlayer::OnEqUser1)
  1182. ON_COMMAND(IDC_BUTTON2, &COptionsPlayer::OnEqUser2)
  1183. ON_COMMAND(IDC_BUTTON3, &COptionsPlayer::OnEqUser3)
  1184. ON_COMMAND(IDC_BUTTON4, &COptionsPlayer::OnEqUser4)
  1185. ON_COMMAND(IDC_BUTTON5, &COptionsPlayer::OnSavePreset)
  1186. ON_COMMAND_RANGE(ID_EQSLIDER_BASE, ID_EQSLIDER_BASE + MAX_EQ_BANDS, &COptionsPlayer::OnSliderMenu)
  1187. ON_COMMAND_RANGE(ID_EQMENU_BASE, ID_EQMENU_BASE + EQ_MAX_FREQS, &COptionsPlayer::OnSliderFreq)
  1188. #endif // !NO_EQ
  1189. // DSP
  1190. ON_WM_HSCROLL()
  1191. ON_CBN_SELCHANGE(IDC_COMBO2, &COptionsPlayer::OnSettingsChanged)
  1192. ON_COMMAND(IDC_CHECK1, &COptionsPlayer::OnSettingsChanged)
  1193. ON_COMMAND(IDC_CHECK2, &COptionsPlayer::OnSettingsChanged)
  1194. ON_COMMAND(IDC_CHECK4, &COptionsPlayer::OnSettingsChanged)
  1195. ON_COMMAND(IDC_CHECK5, &COptionsPlayer::OnSettingsChanged)
  1196. ON_COMMAND(IDC_CHECK6, &COptionsPlayer::OnSettingsChanged)
  1197. ON_COMMAND(IDC_CHECK7, &COptionsPlayer::OnSettingsChanged)
  1198. END_MESSAGE_MAP()
  1199. void COptionsPlayer::DoDataExchange(CDataExchange* pDX)
  1200. {
  1201. CPropertyPage::DoDataExchange(pDX);
  1202. //{{AFX_DATA_MAP(COptionsPlayer)
  1203. DDX_Control(pDX, IDC_COMBO2, m_CbnReverbPreset);
  1204. DDX_Control(pDX, IDC_SLIDER1, m_SbXBassDepth);
  1205. DDX_Control(pDX, IDC_SLIDER2, m_SbXBassRange);
  1206. DDX_Control(pDX, IDC_SLIDER3, m_SbReverbDepth);
  1207. DDX_Control(pDX, IDC_SLIDER5, m_SbSurroundDepth);
  1208. DDX_Control(pDX, IDC_SLIDER6, m_SbSurroundDelay);
  1209. DDX_Control(pDX, IDC_SLIDER4, m_SbBitCrushBits);
  1210. //}}AFX_DATA_MAP
  1211. }
  1212. BOOL COptionsPlayer::OnInitDialog()
  1213. {
  1214. CPropertyPage::OnInitDialog();
  1215. uint32 dwQuality = TrackerSettings::Instance().MixerDSPMask;
  1216. #ifndef NO_EQ
  1217. for (UINT i = 0; i < MAX_EQ_BANDS; i++)
  1218. {
  1219. m_Sliders[i].Init(IDC_SLIDER7 + i, i, this);
  1220. m_Sliders[i].SetRange(0, 32);
  1221. m_Sliders[i].SetTicFreq(4);
  1222. }
  1223. UpdateDialog();
  1224. if (dwQuality & SNDDSP_EQ) CheckDlgButton(IDC_CHECK3, BST_CHECKED);
  1225. #else
  1226. GetDlgItem(IDC_CHECK3)->EnableWindow(FALSE);
  1227. #endif
  1228. // Effects
  1229. #ifndef NO_DSP
  1230. if (dwQuality & SNDDSP_MEGABASS) CheckDlgButton(IDC_CHECK1, BST_CHECKED);
  1231. #else
  1232. GetDlgItem(IDC_CHECK1)->EnableWindow(FALSE);
  1233. #endif
  1234. #ifndef NO_AGC
  1235. if (dwQuality & SNDDSP_AGC) CheckDlgButton(IDC_CHECK2, BST_CHECKED);
  1236. #else
  1237. GetDlgItem(IDC_CHECK2)->EnableWindow(FALSE);
  1238. #endif
  1239. #ifndef NO_DSP
  1240. if (dwQuality & SNDDSP_SURROUND) CheckDlgButton(IDC_CHECK4, BST_CHECKED);
  1241. #else
  1242. GetDlgItem(IDC_CHECK4)->EnableWindow(FALSE);
  1243. #endif
  1244. #ifndef NO_DSP
  1245. if (dwQuality & SNDDSP_BITCRUSH) CheckDlgButton(IDC_CHECK5, BST_CHECKED);
  1246. #else
  1247. GetDlgItem(IDC_CHECK5)->EnableWindow(FALSE);
  1248. #endif
  1249. #ifndef NO_DSP
  1250. m_SbBitCrushBits.SetRange(1, 24);
  1251. m_SbBitCrushBits.SetPos(TrackerSettings::Instance().m_BitCrushSettings.m_Bits);
  1252. #else
  1253. m_SbBitCurshBits.EnableWindow(FALSE);
  1254. #endif
  1255. #ifndef NO_DSP
  1256. // Bass Expansion
  1257. m_SbXBassDepth.SetRange(0,4);
  1258. m_SbXBassDepth.SetPos(8-TrackerSettings::Instance().m_MegaBassSettings.m_nXBassDepth);
  1259. m_SbXBassRange.SetRange(0,4);
  1260. m_SbXBassRange.SetPos(4 - (TrackerSettings::Instance().m_MegaBassSettings.m_nXBassRange - 1) / 5);
  1261. #else
  1262. m_SbXBassDepth.EnableWindow(FALSE);
  1263. m_SbXBassRange.EnableWindow(FALSE);
  1264. #endif
  1265. #ifndef NO_REVERB
  1266. // Reverb
  1267. m_SbReverbDepth.SetRange(1, 16);
  1268. m_SbReverbDepth.SetPos(TrackerSettings::Instance().m_ReverbSettings.m_nReverbDepth);
  1269. UINT nSel = 0;
  1270. for (UINT iRvb=0; iRvb<NUM_REVERBTYPES; iRvb++)
  1271. {
  1272. CString pszName = mpt::ToCString(GetReverbPresetName(iRvb));
  1273. if(!pszName.IsEmpty())
  1274. {
  1275. UINT n = m_CbnReverbPreset.AddString(pszName);
  1276. m_CbnReverbPreset.SetItemData(n, iRvb);
  1277. if (iRvb == TrackerSettings::Instance().m_ReverbSettings.m_nReverbType) nSel = n;
  1278. }
  1279. }
  1280. m_CbnReverbPreset.SetCurSel(nSel);
  1281. if (dwQuality & SNDDSP_REVERB) CheckDlgButton(IDC_CHECK6, BST_CHECKED);
  1282. #else
  1283. GetDlgItem(IDC_CHECK6)->EnableWindow(FALSE);
  1284. m_SbReverbDepth.EnableWindow(FALSE);
  1285. m_CbnReverbPreset.EnableWindow(FALSE);
  1286. #endif
  1287. #ifndef NO_DSP
  1288. // Surround
  1289. {
  1290. UINT n = TrackerSettings::Instance().m_SurroundSettings.m_nProLogicDepth;
  1291. if (n < 1) n = 1;
  1292. if (n > 16) n = 16;
  1293. m_SbSurroundDepth.SetRange(1, 16);
  1294. m_SbSurroundDepth.SetPos(n);
  1295. m_SbSurroundDelay.SetRange(0, 8);
  1296. m_SbSurroundDelay.SetPos((TrackerSettings::Instance().m_SurroundSettings.m_nProLogicDelay-5)/5);
  1297. }
  1298. #else
  1299. m_SbSurroundDepth.EnableWindow(FALSE);
  1300. m_SbSurroundDelay.EnableWindow(FALSE);
  1301. #endif
  1302. return TRUE;
  1303. }
  1304. BOOL COptionsPlayer::OnSetActive()
  1305. {
  1306. CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_PLAYER;
  1307. SetDlgItemText(IDC_EQ_WARNING,
  1308. _T("Note: This EQ is applied to any and all of the modules ")
  1309. _T("that you load in OpenMPT; its settings are stored globally, ")
  1310. _T("rather than in each file. This means that you should avoid ")
  1311. _T("using it as part of your production process, and instead only ")
  1312. _T("use it to correct deficiencies in your audio hardware."));
  1313. return CPropertyPage::OnSetActive();
  1314. }
  1315. void COptionsPlayer::OnHScroll(UINT nSBCode, UINT, CScrollBar *psb)
  1316. {
  1317. if (nSBCode == SB_ENDSCROLL) return;
  1318. if ((psb) && (psb->m_hWnd == m_SbReverbDepth.m_hWnd))
  1319. {
  1320. #ifndef NO_REVERB
  1321. UINT n = m_SbReverbDepth.GetPos();
  1322. if ((n) && (n <= 16)) TrackerSettings::Instance().m_ReverbSettings.m_nReverbDepth = n;
  1323. //if ((n) && (n <= 16)) CSoundFile::m_Reverb.m_Settings.m_nReverbDepth = n;
  1324. CMainFrame::GetMainFrame()->SetupPlayer();
  1325. #endif
  1326. } else
  1327. {
  1328. OnSettingsChanged();
  1329. }
  1330. }
  1331. void COptionsPlayer::OnOK()
  1332. {
  1333. DWORD dwQuality = 0;
  1334. DWORD dwQualityMask = 0;
  1335. #ifndef NO_DSP
  1336. dwQualityMask |= SNDDSP_MEGABASS;
  1337. if (IsDlgButtonChecked(IDC_CHECK1)) dwQuality |= SNDDSP_MEGABASS;
  1338. #endif
  1339. #ifndef NO_AGC
  1340. dwQualityMask |= SNDDSP_AGC;
  1341. if (IsDlgButtonChecked(IDC_CHECK2)) dwQuality |= SNDDSP_AGC;
  1342. #endif
  1343. #ifndef NO_EQ
  1344. dwQualityMask |= SNDDSP_EQ;
  1345. if (IsDlgButtonChecked(IDC_CHECK3)) dwQuality |= SNDDSP_EQ;
  1346. #endif
  1347. #ifndef NO_DSP
  1348. dwQualityMask |= SNDDSP_SURROUND;
  1349. if (IsDlgButtonChecked(IDC_CHECK4)) dwQuality |= SNDDSP_SURROUND;
  1350. #endif
  1351. #ifndef NO_REVERB
  1352. dwQualityMask |= SNDDSP_REVERB;
  1353. if (IsDlgButtonChecked(IDC_CHECK6)) dwQuality |= SNDDSP_REVERB;
  1354. #endif
  1355. #ifndef NO_DSP
  1356. dwQualityMask |= SNDDSP_BITCRUSH;
  1357. if (IsDlgButtonChecked(IDC_CHECK5)) dwQuality |= SNDDSP_BITCRUSH;
  1358. #endif
  1359. #ifndef NO_DSP
  1360. {
  1361. TrackerSettings::Instance().m_BitCrushSettings.m_Bits = m_SbBitCrushBits.GetPos();
  1362. }
  1363. #endif
  1364. #ifndef NO_DSP
  1365. // Bass Expansion
  1366. {
  1367. UINT nXBassDepth = 8-m_SbXBassDepth.GetPos();
  1368. if (nXBassDepth < 4) nXBassDepth = 4;
  1369. if (nXBassDepth > 8) nXBassDepth = 8;
  1370. UINT nXBassRange = (4-m_SbXBassRange.GetPos()) * 5 + 1;
  1371. if (nXBassRange < 5) nXBassRange = 5;
  1372. if (nXBassRange > 21) nXBassRange = 21;
  1373. TrackerSettings::Instance().m_MegaBassSettings.m_nXBassDepth = nXBassDepth;
  1374. TrackerSettings::Instance().m_MegaBassSettings.m_nXBassRange = nXBassRange;
  1375. }
  1376. #endif
  1377. #ifndef NO_REVERB
  1378. // Reverb
  1379. {
  1380. // Reverb depth is dynamically changed
  1381. uint32 nReverbType = static_cast<uint32>(m_CbnReverbPreset.GetItemData(m_CbnReverbPreset.GetCurSel()));
  1382. if (nReverbType < NUM_REVERBTYPES) TrackerSettings::Instance().m_ReverbSettings.m_nReverbType = nReverbType;
  1383. }
  1384. #endif
  1385. #ifndef NO_DSP
  1386. // Surround
  1387. {
  1388. UINT nProLogicDepth = m_SbSurroundDepth.GetPos();
  1389. UINT nProLogicDelay = 5 + (m_SbSurroundDelay.GetPos() * 5);
  1390. TrackerSettings::Instance().m_SurroundSettings.m_nProLogicDepth = nProLogicDepth;
  1391. TrackerSettings::Instance().m_SurroundSettings.m_nProLogicDelay = nProLogicDelay;
  1392. }
  1393. #endif
  1394. TrackerSettings::Instance().MixerDSPMask = dwQuality;
  1395. CMainFrame::GetMainFrame()->SetupPlayer();
  1396. CPropertyPage::OnOK();
  1397. }
  1398. #ifndef NO_EQ
  1399. void COptionsPlayer::UpdateEQ(bool bReset)
  1400. {
  1401. CriticalSection cs;
  1402. if(CMainFrame::GetMainFrame()->GetSoundFilePlaying())
  1403. CMainFrame::GetMainFrame()->GetSoundFilePlaying()->SetEQGains(m_EQPreset.Gains, m_EQPreset.Freqs, bReset);
  1404. }
  1405. void COptionsPlayer::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar *pScrollBar)
  1406. {
  1407. CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
  1408. for (UINT i=0; i<MAX_EQ_BANDS; i++)
  1409. {
  1410. int n = 32 - m_Sliders[i].GetPos();
  1411. if ((n >= 0) && (n <= 32)) m_EQPreset.Gains[i] = n;
  1412. }
  1413. UpdateEQ(FALSE);
  1414. }
  1415. void COptionsPlayer::LoadEQPreset(const EQPreset &preset)
  1416. {
  1417. m_EQPreset = preset;
  1418. UpdateEQ(TRUE);
  1419. UpdateDialog();
  1420. }
  1421. void COptionsPlayer::OnSavePreset()
  1422. {
  1423. CEQSavePresetDlg dlg(m_EQPreset, this);
  1424. if (dlg.DoModal() == IDOK)
  1425. {
  1426. UpdateDialog();
  1427. }
  1428. }
  1429. static CString f2s(UINT f)
  1430. {
  1431. if (f < 1000)
  1432. {
  1433. return MPT_CFORMAT("{}Hz")(f);
  1434. } else
  1435. {
  1436. UINT fHi = f / 1000u;
  1437. UINT fLo = f % 1000u;
  1438. if(fLo)
  1439. {
  1440. return MPT_CFORMAT("{}.{}kHz")(fHi, mpt::cfmt::dec0<1>(fLo/100));
  1441. } else
  1442. {
  1443. return MPT_CFORMAT("{}kHz")(fHi);
  1444. }
  1445. }
  1446. }
  1447. void COptionsPlayer::UpdateDialog()
  1448. {
  1449. for (UINT i=0; i<MAX_EQ_BANDS; i++)
  1450. {
  1451. int n = 32 - m_EQPreset.Gains[i];
  1452. if (n < 0) n = 0;
  1453. if (n > 32) n = 32;
  1454. if (n != (m_Sliders[i].GetPos() & 0xFFFF)) m_Sliders[i].SetPos(n);
  1455. SetDlgItemText(IDC_TEXT1 + i, f2s(m_EQPreset.Freqs[i]));
  1456. }
  1457. for(unsigned int i = 0; i < std::size(TrackerSettings::Instance().m_EqUserPresets); i++)
  1458. {
  1459. SetDlgItemText(IDC_BUTTON1 + i, mpt::ToCString(mpt::Charset::Locale, TrackerSettings::Instance().m_EqUserPresets[i].szName));
  1460. }
  1461. }
  1462. void COptionsPlayer::OnSliderMenu(UINT nID)
  1463. {
  1464. UINT n = nID - ID_EQSLIDER_BASE;
  1465. if (n < MAX_EQ_BANDS)
  1466. {
  1467. HMENU hMenu = ::CreatePopupMenu();
  1468. m_nSliderMenu = n;
  1469. if (!hMenu) return;
  1470. const UINT *pFreqs = gEqBandFreqs[m_nSliderMenu];
  1471. for (UINT i = 0; i < EQ_MAX_FREQS; i++)
  1472. {
  1473. DWORD d = MF_STRING;
  1474. if (m_EQPreset.Freqs[m_nSliderMenu] == pFreqs[i]) d |= MF_CHECKED;
  1475. ::AppendMenu(hMenu, d, ID_EQMENU_BASE+i, f2s(pFreqs[i]));
  1476. }
  1477. CPoint pt(m_Sliders[m_nSliderMenu].m_x, m_Sliders[m_nSliderMenu].m_y);
  1478. m_Sliders[m_nSliderMenu].ClientToScreen(&pt);
  1479. ::TrackPopupMenu(hMenu, TPM_LEFTALIGN|TPM_RIGHTBUTTON, pt.x, pt.y, 0, m_hWnd, NULL);
  1480. ::DestroyMenu(hMenu);
  1481. }
  1482. }
  1483. void COptionsPlayer::OnSliderFreq(UINT nID)
  1484. {
  1485. UINT n = nID - ID_EQMENU_BASE;
  1486. if ((m_nSliderMenu < MAX_EQ_BANDS) && (n < EQ_MAX_FREQS))
  1487. {
  1488. UINT f = gEqBandFreqs[m_nSliderMenu][n];
  1489. if (f != m_EQPreset.Freqs[m_nSliderMenu])
  1490. {
  1491. m_EQPreset.Freqs[m_nSliderMenu] = f;
  1492. UpdateEQ(TRUE);
  1493. UpdateDialog();
  1494. }
  1495. }
  1496. }
  1497. #endif // !NO_EQ
  1498. /////////////////////////////////////////////////////////////
  1499. // CMidiSetupDlg
  1500. BEGIN_MESSAGE_MAP(CMidiSetupDlg, CPropertyPage)
  1501. ON_CBN_SELCHANGE(IDC_COMBO1, &CMidiSetupDlg::OnSettingsChanged)
  1502. ON_CBN_SELCHANGE(IDC_COMBO2, &CMidiSetupDlg::OnSettingsChanged)
  1503. ON_CBN_SELCHANGE(IDC_COMBO3, &CMidiSetupDlg::OnSettingsChanged)
  1504. ON_COMMAND(IDC_BUTTON1, &CMidiSetupDlg::OnRenameDevice)
  1505. ON_COMMAND(IDC_CHECK1, &CMidiSetupDlg::OnSettingsChanged)
  1506. ON_COMMAND(IDC_CHECK2, &CMidiSetupDlg::OnSettingsChanged)
  1507. ON_COMMAND(IDC_CHECK3, &CMidiSetupDlg::OnSettingsChanged)
  1508. ON_COMMAND(IDC_CHECK4, &CMidiSetupDlg::OnSettingsChanged)
  1509. ON_COMMAND(IDC_CHECK5, &CMidiSetupDlg::OnSettingsChanged)
  1510. ON_COMMAND(IDC_MIDI_TO_PLUGIN, &CMidiSetupDlg::OnSettingsChanged)
  1511. ON_COMMAND(IDC_MIDI_MACRO_CONTROL, &CMidiSetupDlg::OnSettingsChanged)
  1512. ON_COMMAND(IDC_MIDIVOL_TO_NOTEVOL, &CMidiSetupDlg::OnSettingsChanged)
  1513. ON_COMMAND(IDC_MIDIPLAYCONTROL, &CMidiSetupDlg::OnSettingsChanged)
  1514. ON_COMMAND(IDC_MIDIPLAYPATTERNONMIDIIN, &CMidiSetupDlg::OnSettingsChanged)
  1515. ON_EN_CHANGE(IDC_EDIT1, &CMidiSetupDlg::OnSettingsChanged)
  1516. ON_EN_CHANGE(IDC_EDIT2, &CMidiSetupDlg::OnSettingsChanged)
  1517. ON_EN_CHANGE(IDC_EDIT3, &CMidiSetupDlg::OnSettingsChanged)
  1518. ON_EN_CHANGE(IDC_EDIT4, &CMidiSetupDlg::OnSettingsChanged)
  1519. END_MESSAGE_MAP()
  1520. void CMidiSetupDlg::DoDataExchange(CDataExchange* pDX)
  1521. {
  1522. CPropertyPage::DoDataExchange(pDX);
  1523. //{{AFX_DATA_MAP(COptionsSoundcard)
  1524. DDX_Control(pDX, IDC_SPIN1, m_SpinSpd);
  1525. DDX_Control(pDX, IDC_SPIN2, m_SpinPat);
  1526. DDX_Control(pDX, IDC_SPIN3, m_SpinAmp);
  1527. DDX_Control(pDX, IDC_COMBO1, m_InputDevice);
  1528. DDX_Control(pDX, IDC_COMBO2, m_ATBehaviour);
  1529. DDX_Control(pDX, IDC_COMBO3, m_Quantize);
  1530. //}}AFX_DATA_MAP
  1531. }
  1532. BOOL CMidiSetupDlg::OnInitDialog()
  1533. {
  1534. CPropertyPage::OnInitDialog();
  1535. // Flags
  1536. if (m_dwMidiSetup & MIDISETUP_RECORDVELOCITY) CheckDlgButton(IDC_CHECK1, BST_CHECKED);
  1537. if (m_dwMidiSetup & MIDISETUP_RECORDNOTEOFF) CheckDlgButton(IDC_CHECK2, BST_CHECKED);
  1538. if (m_dwMidiSetup & MIDISETUP_ENABLE_RECORD_DEFAULT) CheckDlgButton(IDC_CHECK3, BST_CHECKED);
  1539. if (m_dwMidiSetup & MIDISETUP_TRANSPOSEKEYBOARD) CheckDlgButton(IDC_CHECK4, BST_CHECKED);
  1540. if (m_dwMidiSetup & MIDISETUP_MIDITOPLUG) CheckDlgButton(IDC_MIDI_TO_PLUGIN, BST_CHECKED);
  1541. if (m_dwMidiSetup & MIDISETUP_MIDIMACROCONTROL) CheckDlgButton(IDC_MIDI_MACRO_CONTROL, BST_CHECKED);
  1542. if (m_dwMidiSetup & MIDISETUP_MIDIVOL_TO_NOTEVOL) CheckDlgButton(IDC_MIDIVOL_TO_NOTEVOL, BST_CHECKED);
  1543. if (m_dwMidiSetup & MIDISETUP_RESPONDTOPLAYCONTROLMSGS) CheckDlgButton(IDC_MIDIPLAYCONTROL, BST_CHECKED);
  1544. if (m_dwMidiSetup & MIDISETUP_PLAYPATTERNONMIDIIN) CheckDlgButton(IDC_MIDIPLAYPATTERNONMIDIIN, BST_CHECKED);
  1545. if (m_dwMidiSetup & MIDISETUP_MIDIMACROPITCHBEND) CheckDlgButton(IDC_CHECK5, BST_CHECKED);
  1546. // Midi In Device
  1547. RefreshDeviceList(m_nMidiDevice);
  1548. // Aftertouch behaviour
  1549. m_ATBehaviour.ResetContent();
  1550. static constexpr std::pair<const TCHAR *, RecordAftertouchOptions> aftertouchOptions[] =
  1551. {
  1552. { _T("Do not record Aftertouch"), atDoNotRecord },
  1553. { _T("Record as Volume Commands"), atRecordAsVolume },
  1554. { _T("Record as MIDI Macros"), atRecordAsMacro },
  1555. };
  1556. for(const auto & [str, value] : aftertouchOptions)
  1557. {
  1558. int item = m_ATBehaviour.AddString(str);
  1559. m_ATBehaviour.SetItemData(item, value);
  1560. if(value == TrackerSettings::Instance().aftertouchBehaviour)
  1561. {
  1562. m_ATBehaviour.SetCurSel(item);
  1563. }
  1564. }
  1565. // Note Velocity amp
  1566. SetDlgItemInt(IDC_EDIT3, TrackerSettings::Instance().midiVelocityAmp);
  1567. m_SpinAmp.SetRange(1, 10000);
  1568. SetDlgItemText(IDC_EDIT4, mpt::ToCString(IgnoredCCsToString(TrackerSettings::Instance().midiIgnoreCCs)));
  1569. // Midi Import settings
  1570. SetDlgItemInt(IDC_EDIT1, TrackerSettings::Instance().midiImportTicks);
  1571. SetDlgItemInt(IDC_EDIT2, TrackerSettings::Instance().midiImportPatternLen);
  1572. // Note quantization
  1573. m_Quantize.ResetContent();
  1574. static constexpr std::pair<const TCHAR *, uint32> quantizeOptions[] =
  1575. {
  1576. { _T("1/4th Notes"), 4 }, { _T("1/6th Notes"), 6 },
  1577. { _T("1/8th Notes"), 8 }, { _T("1/12th Notes"), 12 },
  1578. { _T("1/16th Notes"), 16 }, { _T("1/24th Notes"), 24 },
  1579. { _T("1/32nd Notes"), 32 }, { _T("1/48th Notes"), 48 },
  1580. { _T("1/64th Notes"), 64 }, { _T("1/96th Notes"), 96 },
  1581. };
  1582. for(const auto & [str, value]: quantizeOptions)
  1583. {
  1584. int item = m_Quantize.AddString(str);
  1585. m_Quantize.SetItemData(item, value);
  1586. if(value == TrackerSettings::Instance().midiImportQuantize)
  1587. {
  1588. m_Quantize.SetCurSel(item);
  1589. }
  1590. }
  1591. m_SpinSpd.SetRange(2, 16);
  1592. m_SpinPat.SetRange(1, MAX_PATTERN_ROWS);
  1593. return TRUE;
  1594. }
  1595. void CMidiSetupDlg::RefreshDeviceList(UINT currentDevice)
  1596. {
  1597. m_InputDevice.SetRedraw(FALSE);
  1598. m_InputDevice.ResetContent();
  1599. UINT ndevs = midiInGetNumDevs();
  1600. for(UINT i = 0; i < ndevs; i++)
  1601. {
  1602. MIDIINCAPS mic;
  1603. mic.szPname[0] = 0;
  1604. if(midiInGetDevCaps(i, &mic, sizeof(mic)) == MMSYSERR_NOERROR)
  1605. {
  1606. int item = m_InputDevice.AddString(theApp.GetFriendlyMIDIPortName(mpt::ToCString(mpt::String::ReadWinBuf(mic.szPname)), true));
  1607. m_InputDevice.SetItemData(item, i);
  1608. if(i == currentDevice)
  1609. {
  1610. m_InputDevice.SetCurSel(item);
  1611. }
  1612. }
  1613. }
  1614. m_InputDevice.SetRedraw(TRUE);
  1615. m_InputDevice.Invalidate(FALSE);
  1616. }
  1617. void CMidiSetupDlg::OnRenameDevice()
  1618. {
  1619. int n = m_InputDevice.GetCurSel();
  1620. if(n >= 0)
  1621. {
  1622. UINT device = static_cast<UINT>(m_InputDevice.GetItemData(n));
  1623. MIDIINCAPS mic;
  1624. mic.szPname[0] = 0;
  1625. midiInGetDevCaps(device, &mic, sizeof(mic));
  1626. CString name = mic.szPname;
  1627. CString friendlyName = theApp.GetSettings().Read(U_("MIDI Input Ports"), mpt::ToUnicode(name), name);
  1628. CInputDlg dlg(this, _T("New name for ") + name + _T(":"), friendlyName);
  1629. if(dlg.DoModal() == IDOK)
  1630. {
  1631. if(dlg.resultAsString.IsEmpty() || dlg.resultAsString == name)
  1632. theApp.GetSettings().Remove(U_("MIDI Input Ports"), mpt::ToUnicode(name));
  1633. else
  1634. theApp.GetSettings().Write(U_("MIDI Input Ports"), mpt::ToUnicode(name), dlg.resultAsString);
  1635. RefreshDeviceList(device);
  1636. }
  1637. }
  1638. }
  1639. void CMidiSetupDlg::OnOK()
  1640. {
  1641. CMainFrame *pMainFrm = CMainFrame::GetMainFrame();
  1642. m_dwMidiSetup = 0;
  1643. m_nMidiDevice = MIDI_MAPPER;
  1644. if (IsDlgButtonChecked(IDC_CHECK1)) m_dwMidiSetup |= MIDISETUP_RECORDVELOCITY;
  1645. if (IsDlgButtonChecked(IDC_CHECK2)) m_dwMidiSetup |= MIDISETUP_RECORDNOTEOFF;
  1646. if (IsDlgButtonChecked(IDC_CHECK3)) m_dwMidiSetup |= MIDISETUP_ENABLE_RECORD_DEFAULT;
  1647. if (IsDlgButtonChecked(IDC_CHECK4)) m_dwMidiSetup |= MIDISETUP_TRANSPOSEKEYBOARD;
  1648. if (IsDlgButtonChecked(IDC_MIDI_TO_PLUGIN)) m_dwMidiSetup |= MIDISETUP_MIDITOPLUG;
  1649. if (IsDlgButtonChecked(IDC_MIDI_MACRO_CONTROL)) m_dwMidiSetup |= MIDISETUP_MIDIMACROCONTROL;
  1650. if (IsDlgButtonChecked(IDC_MIDIVOL_TO_NOTEVOL)) m_dwMidiSetup |= MIDISETUP_MIDIVOL_TO_NOTEVOL;
  1651. if (IsDlgButtonChecked(IDC_MIDIPLAYCONTROL)) m_dwMidiSetup |= MIDISETUP_RESPONDTOPLAYCONTROLMSGS;
  1652. if (IsDlgButtonChecked(IDC_MIDIPLAYPATTERNONMIDIIN)) m_dwMidiSetup |= MIDISETUP_PLAYPATTERNONMIDIIN;
  1653. if (IsDlgButtonChecked(IDC_CHECK5)) m_dwMidiSetup |= MIDISETUP_MIDIMACROPITCHBEND;
  1654. int n = m_InputDevice.GetCurSel();
  1655. if (n >= 0) m_nMidiDevice = static_cast<UINT>(m_InputDevice.GetItemData(n));
  1656. TrackerSettings::Instance().aftertouchBehaviour = static_cast<RecordAftertouchOptions>(m_ATBehaviour.GetItemData(m_ATBehaviour.GetCurSel()));
  1657. TrackerSettings::Instance().midiVelocityAmp = static_cast<uint16>(Clamp(GetDlgItemInt(IDC_EDIT3), 1u, 10000u));
  1658. CString cc;
  1659. GetDlgItemText(IDC_EDIT4, cc);
  1660. TrackerSettings::Instance().midiIgnoreCCs = StringToIgnoredCCs(mpt::ToUnicode(cc));
  1661. TrackerSettings::Instance().midiImportTicks = static_cast<uint8>(Clamp(GetDlgItemInt(IDC_EDIT1), uint8(2), uint8(16)));
  1662. TrackerSettings::Instance().midiImportPatternLen = Clamp(GetDlgItemInt(IDC_EDIT2), ROWINDEX(1), MAX_PATTERN_ROWS);
  1663. if(m_Quantize.GetCurSel() != -1)
  1664. {
  1665. TrackerSettings::Instance().midiImportQuantize = static_cast<uint32>(m_Quantize.GetItemData(m_Quantize.GetCurSel()));
  1666. }
  1667. if (pMainFrm) pMainFrm->SetupMidi(m_dwMidiSetup, m_nMidiDevice);
  1668. CPropertyPage::OnOK();
  1669. }
  1670. BOOL CMidiSetupDlg::OnSetActive()
  1671. {
  1672. CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_MIDI;
  1673. return CPropertyPage::OnSetActive();
  1674. }
  1675. // Wine
  1676. BEGIN_MESSAGE_MAP(COptionsWine, CPropertyPage)
  1677. ON_COMMAND(IDC_CHECK_WINE_ENABLE, &COptionsWine::OnSettingsChanged)
  1678. ON_CBN_SELCHANGE(IDC_COMBO_WINE_PULSEAUDIO, &COptionsWine::OnSettingsChanged)
  1679. ON_CBN_SELCHANGE(IDC_COMBO_WINE_PORTAUDIO, &COptionsWine::OnSettingsChanged)
  1680. ON_CBN_SELCHANGE(IDC_COMBO_WINE_RTAUDIO, &COptionsWine::OnSettingsChanged)
  1681. END_MESSAGE_MAP()
  1682. COptionsWine::COptionsWine()
  1683. : CPropertyPage(IDD_OPTIONS_WINE)
  1684. {
  1685. return;
  1686. }
  1687. void COptionsWine::DoDataExchange(CDataExchange* pDX)
  1688. {
  1689. CPropertyPage::DoDataExchange(pDX);
  1690. //{{AFX_DATA_MAP(COptionsWine)
  1691. DDX_Control(pDX, IDC_COMBO_WINE_PULSEAUDIO, m_CbnPulseAudio);
  1692. DDX_Control(pDX, IDC_COMBO_WINE_PORTAUDIO, m_CbnPortAudio);
  1693. DDX_Control(pDX, IDC_COMBO_WINE_RTAUDIO, m_CbnRtAudio);
  1694. //}}AFX_DATA_MAP
  1695. }
  1696. BOOL COptionsWine::OnInitDialog()
  1697. {
  1698. CPropertyPage::OnInitDialog();
  1699. GetDlgItem(IDC_CHECK_WINE_ENABLE)->EnableWindow(mpt::OS::Windows::IsWine() ? TRUE : FALSE);
  1700. CheckDlgButton(IDC_CHECK_WINE_ENABLE, TrackerSettings::Instance().WineSupportEnabled ? BST_CHECKED : BST_UNCHECKED);
  1701. int index;
  1702. index = m_CbnPulseAudio.AddString(_T("Auto" )); m_CbnPulseAudio.SetItemData(index, 1);
  1703. index = m_CbnPulseAudio.AddString(_T("Enabled" )); m_CbnPulseAudio.SetItemData(index, 2);
  1704. index = m_CbnPulseAudio.AddString(_T("Disabled")); m_CbnPulseAudio.SetItemData(index, 0);
  1705. m_CbnPulseAudio.SetCurSel(0);
  1706. for(index = 0; index < 3; ++index)
  1707. {
  1708. if(m_CbnPulseAudio.GetItemData(index) == static_cast<uint32>(TrackerSettings::Instance().WineSupportEnablePulseAudio))
  1709. {
  1710. m_CbnPulseAudio.SetCurSel(index);
  1711. }
  1712. }
  1713. index = m_CbnPortAudio.AddString(_T("Auto" )); m_CbnPortAudio.SetItemData(index, 1);
  1714. index = m_CbnPortAudio.AddString(_T("Enabled" )); m_CbnPortAudio.SetItemData(index, 2);
  1715. index = m_CbnPortAudio.AddString(_T("Disabled")); m_CbnPortAudio.SetItemData(index, 0);
  1716. for(index = 0; index < 3; ++index)
  1717. {
  1718. if(m_CbnPortAudio.GetItemData(index) == static_cast<uint32>(TrackerSettings::Instance().WineSupportEnablePortAudio))
  1719. {
  1720. m_CbnPortAudio.SetCurSel(index);
  1721. }
  1722. }
  1723. index = m_CbnRtAudio.AddString(_T("Auto" )); m_CbnRtAudio.SetItemData(index, 1);
  1724. index = m_CbnRtAudio.AddString(_T("Enabled" )); m_CbnRtAudio.SetItemData(index, 2);
  1725. index = m_CbnRtAudio.AddString(_T("Disabled")); m_CbnRtAudio.SetItemData(index, 0);
  1726. for(index = 0; index < 3; ++index)
  1727. {
  1728. if(m_CbnRtAudio.GetItemData(index) == static_cast<uint32>(TrackerSettings::Instance().WineSupportEnableRtAudio))
  1729. {
  1730. m_CbnRtAudio.SetCurSel(index);
  1731. }
  1732. }
  1733. return TRUE;
  1734. }
  1735. void COptionsWine::OnSettingsChanged()
  1736. {
  1737. SetModified(TRUE);
  1738. }
  1739. void COptionsWine::OnOK()
  1740. {
  1741. TrackerSettings::Instance().WineSupportEnabled = IsDlgButtonChecked(IDC_CHECK_WINE_ENABLE) ? true : false;
  1742. TrackerSettings::Instance().WineSupportEnablePulseAudio = static_cast<int32>(m_CbnPulseAudio.GetItemData(m_CbnPulseAudio.GetCurSel()));
  1743. TrackerSettings::Instance().WineSupportEnablePortAudio = static_cast<int32>(m_CbnPortAudio.GetItemData(m_CbnPortAudio.GetCurSel()));
  1744. TrackerSettings::Instance().WineSupportEnableRtAudio = static_cast<int32>(m_CbnRtAudio.GetItemData(m_CbnRtAudio.GetCurSel()));
  1745. CPropertyPage::OnOK();
  1746. }
  1747. BOOL COptionsWine::OnSetActive()
  1748. {
  1749. CMainFrame::m_nLastOptionsPage = OPTIONS_PAGE_WINE;
  1750. return CPropertyPage::OnSetActive();
  1751. }
  1752. OPENMPT_NAMESPACE_END