Skip to content

Commit

Permalink
Separated file GOSettingsMidiDeviceList GrandOrgue#885
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Samarin committed Dec 31, 2021
1 parent 17e5944 commit ca9ff60
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 166 deletions.
1 change: 1 addition & 0 deletions src/grandorgue/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ GOPanelView.cpp
settings/GOMidiDeviceConfig.cpp
settings/GOMidiDeviceConfigList.cpp
settings/GOPortFactory.cpp
settings/GOSettingsMidiDeviceList.cpp
settings/GOSettingsPorts.cpp
settings/SettingsArchives.cpp
settings/SettingsAudioGroup.cpp
Expand Down
125 changes: 125 additions & 0 deletions src/grandorgue/settings/GOSettingsMidiDeviceList.cpp
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);
}
}
66 changes: 66 additions & 0 deletions src/grandorgue/settings/GOSettingsMidiDeviceList.h
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 */

130 changes: 8 additions & 122 deletions src/grandorgue/settings/SettingsMidiDevices.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "SettingsMidiDevices.h"

#include <wx/button.h>
#include <wx/checklst.h>
#include <wx/choice.h>
#include <wx/choicdlg.h>
#include <wx/numdlg.h>
Expand All @@ -25,125 +24,6 @@ BEGIN_EVENT_TABLE(SettingsMidiDevices, wxPanel)
EVT_BUTTON(ID_INOUTDEVICE, SettingsMidiDevices::OnInOutDeviceClick)
END_EVENT_TABLE()

SettingsMidiDevices::MidiDeviceListSettings::MidiDeviceListSettings(
const ptr_vector<GOMidiPort>& ports,
GOMidiDeviceConfigList& configListPersist,
wxWindow* parent,
wxWindowID id
):
m_Ports(ports), m_ConfList(configListPersist)
{
m_LbDevices = new wxCheckListBox(
parent, id, wxDefaultPosition, wxSize(100, 100)
);
m_LbDevices->Bind(
wxEVT_CHECKLISTBOX,
&SettingsMidiDevices::MidiDeviceListSettings::OnChecked,
this
);
}

void SettingsMidiDevices::MidiDeviceListSettings::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);
}

void SettingsMidiDevices::MidiDeviceListSettings::Init()
{
ClearDevices();
m_ConfListTmp.Clear();
}

void SettingsMidiDevices::MidiDeviceListSettings::RefreshDevices(
const GOPortsConfig& portsConfig,
const bool isToAutoEnable,
const MidiDeviceListSettings* 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
);

const int i = m_LbDevices->Append(physicalName, pConfTmp);

if (pConfTmp->m_IsEnabled)
m_LbDevices->Check(i);
}
}

unsigned SettingsMidiDevices::MidiDeviceListSettings::GetDeviceCount() const
{
return m_LbDevices->GetCount();
}

GOMidiDeviceConfig& SettingsMidiDevices::MidiDeviceListSettings::GetDeviceConf(
unsigned i
) const
{
return * (GOMidiDeviceConfig*) m_LbDevices->GetClientData(i);
}

GOMidiDeviceConfig&
SettingsMidiDevices::MidiDeviceListSettings::GetSelectedDeviceConf()
const
{
return GetDeviceConf(m_LbDevices->GetSelection());
}

void SettingsMidiDevices::MidiDeviceListSettings::OnChecked(wxCommandEvent& event)
{
unsigned i = (unsigned) event.GetInt();

GetDeviceConf(i).m_IsEnabled = m_LbDevices->IsChecked(i);
}

void SettingsMidiDevices::MidiDeviceListSettings::Save(
const MidiDeviceListSettings* pOutDevList
)
{
for (int l = m_LbDevices->GetCount(), i = 0; i < l; i++)
{
GOMidiDeviceConfig* pDevConfTmp
= (GOMidiDeviceConfig*) m_LbDevices->GetClientData(i);
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);
}
}

SettingsMidiDevices::SettingsMidiDevices(
GOSettings& settings, GOMidi& midi, wxWindow* parent
):
Expand All @@ -152,10 +32,16 @@ SettingsMidiDevices::SettingsMidiDevices(
m_Settings(settings),
m_Midi(midi),
m_InDevices(
m_Midi.GetInDevices(), m_Settings.m_MidiIn, this, ID_INDEVICES
m_Midi.GetInDevices(),
m_Settings.m_MidiIn,
this,
ID_INDEVICES
),
m_OutDevices(
m_Midi.GetOutDevices(), m_Settings.m_MidiOut, this, ID_OUTDEVICES
m_Midi.GetOutDevices(),
m_Settings.m_MidiOut,
this,
ID_OUTDEVICES
)
{
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
Expand Down
Loading

0 comments on commit ca9ff60

Please sign in to comment.