forked from GrandOrgue/grandorgue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separated file GOSettingsMidiDeviceList GrandOrgue#885
- Loading branch information
Oleg Samarin
committed
Dec 31, 2021
1 parent
17e5944
commit ca9ff60
Showing
5 changed files
with
203 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* Copyright 2006 Milan Digital Audio LLC | ||
* Copyright 2009-2021 GrandOrgue contributors (see AUTHORS) | ||
* License GPL-2.0 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html). | ||
*/ | ||
|
||
#include "GOSettingsMidiDeviceList.h" | ||
|
||
GOSettingsMidiDeviceList::GOSettingsMidiDeviceList( | ||
const ptr_vector<GOMidiPort>& ports, | ||
GOMidiDeviceConfigList& configListPersist, | ||
wxWindow* parent, | ||
wxWindowID id | ||
): | ||
m_parent(parent), m_Ports(ports), m_ConfList(configListPersist) | ||
{ | ||
m_LbDevices = new wxCheckListBox( | ||
parent, id, wxDefaultPosition, wxSize(100, 100) | ||
); | ||
m_LbDevices->Bind( | ||
wxEVT_CHECKLISTBOX, | ||
&GOSettingsMidiDeviceList::OnChecked, | ||
this | ||
); | ||
Init(); | ||
} | ||
|
||
void GOSettingsMidiDeviceList::ClearDevices() | ||
{ | ||
// We cann't use lbDevices->Clear() because it disables the event handler | ||
for (int i = m_LbDevices->GetCount() - 1; i >= 0; i--) | ||
m_LbDevices->Delete(i); | ||
m_ListedConfs.clear(); | ||
} | ||
|
||
void GOSettingsMidiDeviceList::Init() | ||
{ | ||
ClearDevices(); | ||
m_ConfListTmp.Clear(); | ||
} | ||
|
||
void GOSettingsMidiDeviceList::RefreshDevices( | ||
const GOPortsConfig& portsConfig, | ||
const bool isToAutoEnable, | ||
const GOSettingsMidiDeviceList* pOutDevList | ||
) | ||
{ | ||
ClearDevices(); | ||
for (GOMidiPort* port : m_Ports) | ||
if ( | ||
port->IsToUse() | ||
&& portsConfig.IsEnabled(port->GetPortName(), port->GetApiName()) | ||
) | ||
{ | ||
const wxString physicalName = port->GetName(); | ||
GOMidiDeviceConfig* const pConf | ||
= m_ConfList.FindByPhysicalName(physicalName); | ||
GOMidiDeviceConfig* pConfTmp | ||
= m_ConfListTmp.FindByPhysicalName(physicalName); | ||
|
||
if (! pConfTmp) | ||
pConfTmp = pConf | ||
? m_ConfListTmp.Append( | ||
*pConf, pOutDevList ? &pOutDevList->m_ConfListTmp : NULL | ||
) | ||
: m_ConfListTmp.Append( | ||
port->GetDefaultLogicalName(), | ||
port->GetDefaultRegEx(), | ||
isToAutoEnable, | ||
physicalName | ||
); | ||
|
||
m_ListedConfs.push_back(pConfTmp); | ||
|
||
const int i = m_LbDevices->Append(physicalName); | ||
|
||
if (pConfTmp->m_IsEnabled) | ||
m_LbDevices->Check(i); | ||
} | ||
} | ||
|
||
unsigned GOSettingsMidiDeviceList::GetDeviceCount() const | ||
{ | ||
return m_LbDevices->GetCount(); | ||
} | ||
|
||
GOMidiDeviceConfig& | ||
GOSettingsMidiDeviceList::GetSelectedDeviceConf() | ||
const | ||
{ | ||
return GetDeviceConf(m_LbDevices->GetSelection()); | ||
} | ||
|
||
void GOSettingsMidiDeviceList::OnSelected(wxCommandEvent& event) | ||
{ | ||
} | ||
|
||
void GOSettingsMidiDeviceList::OnChecked(wxCommandEvent& event) | ||
{ | ||
unsigned i = (unsigned) event.GetInt(); | ||
|
||
GetDeviceConf(i).m_IsEnabled = m_LbDevices->IsChecked(i); | ||
} | ||
|
||
void GOSettingsMidiDeviceList::Save( | ||
const GOSettingsMidiDeviceList* pOutDevList | ||
) | ||
{ | ||
for (GOMidiDeviceConfig* pDevConfTmp : m_ListedConfs) | ||
{ | ||
GOMidiDeviceConfig* pDevConf = m_ConfList.FindByPhysicalName( | ||
pDevConfTmp->m_PhysicalName | ||
); | ||
const GOMidiDeviceConfigList* pOutConfList | ||
= pOutDevList ? & pOutDevList->m_ConfList : NULL; | ||
|
||
if (pDevConf) | ||
{ | ||
pDevConf->Assign(*pDevConfTmp); | ||
if (pOutConfList) | ||
pOutConfList->MapOutputDevice(*pDevConfTmp, *pDevConf); | ||
} else | ||
m_ConfList.Append(*pDevConfTmp, pOutConfList); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2006 Milan Digital Audio LLC | ||
* Copyright 2009-2021 GrandOrgue contributors (see AUTHORS) | ||
* License GPL-2.0 or later (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html). | ||
*/ | ||
|
||
#ifndef GOSETTINGSMIDIDEVICELIST_H | ||
#define GOSETTINGSMIDIDEVICELIST_H | ||
|
||
#include <wx/button.h> | ||
#include <wx/checklst.h> | ||
#include <wx/window.h> | ||
|
||
#include "ptrvector.h" | ||
|
||
#include "midi/ports/GOMidiPort.h" | ||
|
||
#include "GOMidiDeviceConfigList.h" | ||
#include "GOPortsConfig.h" | ||
|
||
class GOSettingsMidiDeviceList | ||
{ | ||
private: | ||
wxWindow* m_parent; | ||
const ptr_vector<GOMidiPort>& m_Ports; | ||
GOMidiDeviceConfigList& m_ConfList; | ||
GOMidiDeviceConfig::List m_ListedConfs; | ||
wxCheckListBox* m_LbDevices; | ||
|
||
// temporary storage for configs when edited | ||
GOMidiDeviceConfigList m_ConfListTmp; | ||
|
||
void ClearDevices(); | ||
|
||
void OnChecked(wxCommandEvent& event); | ||
|
||
public: | ||
GOSettingsMidiDeviceList( | ||
const ptr_vector<GOMidiPort>& ports, | ||
GOMidiDeviceConfigList& configListPersist, | ||
wxWindow* parent, | ||
wxWindowID id | ||
); | ||
|
||
wxCheckListBox* GetListbox() const { return m_LbDevices; } | ||
|
||
void Init(); | ||
|
||
void RefreshDevices( | ||
const GOPortsConfig& portsConfig, | ||
const bool isToAutoEnable, | ||
const GOSettingsMidiDeviceList* pOutDevList = NULL | ||
); | ||
|
||
unsigned GetDeviceCount() const; | ||
GOMidiDeviceConfig& GetDeviceConf(unsigned i) const { return *m_ListedConfs[i]; } | ||
GOMidiDeviceConfig& GetSelectedDeviceConf() const; | ||
|
||
void OnSelected(wxCommandEvent& event); | ||
|
||
void Save(const GOSettingsMidiDeviceList* pOutDevList = NULL); | ||
}; | ||
|
||
|
||
#endif /* GOSETTINGSMIDIDEVICELIST_H */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.