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 27, 2021
1 parent e3cd037 commit 6197a28
Show file tree
Hide file tree
Showing 6 changed files with 319 additions and 276 deletions.
12 changes: 12 additions & 0 deletions ide-projects/NetBeans12/nbproject/configurations.xml
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,8 @@
<in>GOPortFactory.cpp</in>
<in>GOPortsConfig.cpp</in>
<in>GOSettings.cpp</in>
<in>GOSettingsMidiDeviceList.cpp</in>
<in>GOSettingsMidiDeviceList.h</in>
<in>GOSettingsPorts.cpp</in>
<in>SettingsArchives.cpp</in>
<in>SettingsAudioGroup.cpp</in>
Expand Down Expand Up @@ -7618,6 +7620,16 @@
<ccTool flags="5">
</ccTool>
</item>
<item path="../../src/grandorgue/settings/GOSettingsMidiDeviceList.cpp"
ex="false"
tool="1"
flavor2="0">
</item>
<item path="../../src/grandorgue/settings/GOSettingsMidiDeviceList.h"
ex="false"
tool="3"
flavor2="0">
</item>
<item path="../../src/grandorgue/settings/GOSettingsPorts.cpp"
ex="false"
tool="1"
Expand Down
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
235 changes: 235 additions & 0 deletions src/grandorgue/settings/GOSettingsMidiDeviceList.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,235 @@
/*
* 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"

#include <wx/dialog.h>
#include <wx/sizer.h>
#include <wx/stattext.h>
#include <wx/textctrl.h>

class DeviceMatchingDialog: public wxDialog
{
private:
wxTextCtrl* m_PhysicalName;
wxTextCtrl* m_LogicalName;
wxTextCtrl* m_regex;

public:
DeviceMatchingDialog(wxWindow* parent);

void FillWith(const GOMidiDeviceConfig& devConf);
void SaveTo(GOMidiDeviceConfig& devConf);
};

DeviceMatchingDialog::DeviceMatchingDialog(wxWindow* parent):
wxDialog(
parent,
wxID_ANY,
_("MIDI device matching properties"),
wxDefaultPosition,
wxSize(400, -1),
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxDIALOG_NO_PARENT
)
{
wxBoxSizer* const topSizer = new wxBoxSizer(wxVERTICAL);

wxFlexGridSizer* const mainSizer = new wxFlexGridSizer(2);

mainSizer->AddGrowableCol (1, 1);
mainSizer->Add(
new wxStaticText(this, wxID_ANY, _("Physical device name:")),
0,
wxALIGN_RIGHT | wxALL | wxALIGN_CENTER_VERTICAL,
5
);
m_PhysicalName = new wxTextCtrl(this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(400, -1));
m_PhysicalName->SetEditable(false);
mainSizer->Add(m_PhysicalName, 1, wxEXPAND | wxALL, 5);
mainSizer->Add(
new wxStaticText(this, wxID_ANY, _("Logical device name:")),
0,
wxALIGN_RIGHT | wxALL | wxALIGN_CENTER_VERTICAL,
5
);
m_LogicalName = new wxTextCtrl(this, wxID_ANY);
mainSizer->Add(m_LogicalName, 1, wxEXPAND | wxALL, 5);
mainSizer->Add(
new wxStaticText(this, wxID_ANY, _("Physical name regex pattern:")),
0,
wxALIGN_RIGHT | wxALL | wxALIGN_CENTER_VERTICAL,
5
);
m_regex = new wxTextCtrl(this, wxID_ANY);
mainSizer->Add(m_regex, 1, wxEXPAND | wxALL, 5);
topSizer->Add(mainSizer, 0, wxALL | wxEXPAND, 5);

topSizer->Add(
CreateSeparatedButtonSizer(wxOK | wxCANCEL | wxHELP),
0,
wxALIGN_RIGHT | wxALL | wxEXPAND,
5
);
SetSizer(topSizer);
Fit();
}

void DeviceMatchingDialog::FillWith(const GOMidiDeviceConfig& devConf)
{
m_PhysicalName->ChangeValue(devConf.m_PhysicalName);
m_LogicalName->ChangeValue(devConf.m_LogicalName);
m_regex->ChangeValue(devConf.m_RegEx);
}

void DeviceMatchingDialog::SaveTo(GOMidiDeviceConfig& devConf)
{
devConf.m_LogicalName = m_LogicalName->GetValue();
devConf.SetRegEx(m_regex->GetValue());
}

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
);
m_BMatching = new wxButton(parent, wxID_ANY, _("Matching..."));
m_BMatching->Bind(
wxEVT_BUTTON,
&GOSettingsMidiDeviceList::OnMatchingClick,
this
);
Init();
}

void GOSettingsMidiDeviceList::ClearDevices()
{
m_BMatching->Disable();
// 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 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
);

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

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

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

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

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

void GOSettingsMidiDeviceList::OnSelected(wxCommandEvent& event)
{
m_BMatching->Enable();
}

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

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

void GOSettingsMidiDeviceList::OnMatchingClick(
wxCommandEvent& event
)
{
GOMidiDeviceConfig& devConf = GetSelectedDeviceConf();
DeviceMatchingDialog dlg(m_parent);

dlg.FillWith(devConf);
if (dlg.ShowModal() == wxID_OK)
dlg.SaveTo(devConf);
}

void GOSettingsMidiDeviceList::Save(
const GOSettingsMidiDeviceList* 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);
}
}
68 changes: 68 additions & 0 deletions src/grandorgue/settings/GOSettingsMidiDeviceList.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/*
* 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;
wxCheckListBox* m_LbDevices;
wxButton* m_BMatching;

// temporary storage for configs when edited
GOMidiDeviceConfigList m_ConfListTmp;

void ClearDevices();

void OnChecked(wxCommandEvent& event);
void OnMatchingClick(wxCommandEvent& event);

public:
GOSettingsMidiDeviceList(
const ptr_vector<GOMidiPort>& ports,
GOMidiDeviceConfigList& configListPersist,
wxWindow* parent,
wxWindowID id
);

wxCheckListBox* GetListbox() const { return m_LbDevices; }
wxButton* GetMatchingButton() const { return m_BMatching; }

void Init();

void RefreshDevices(
const GOPortsConfig& portsConfig,
const bool isToAutoEnable,
const GOSettingsMidiDeviceList* pOutDevList = NULL
);

unsigned GetDeviceCount() const;
GOMidiDeviceConfig& GetDeviceConf(unsigned i) const;
GOMidiDeviceConfig& GetSelectedDeviceConf() const;

void OnSelected(wxCommandEvent& event);

void Save(const GOSettingsMidiDeviceList* pOutDevList = NULL);
};


#endif /* GOSETTINGSMIDIDEVICELIST_H */

Loading

0 comments on commit 6197a28

Please sign in to comment.