Skip to content

Commit

Permalink
Intermediate commit
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 committed Feb 8, 2025
1 parent 6a2d905 commit b038d5a
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,27 @@

#include "GOOrganSettingsButtonsProxy.h"

#include <wx/intl.h>

#include "GOEvent.h"

GOOrganSettingsButtonsProxy::GOOrganSettingsButtonsProxy(
Listener &listener, wxWindow *pWindow)
: r_listener(listener), p_window(pWindow) {}

void GOOrganSettingsButtonsProxy::NotifyModified(bool newValue) {
SetModified(newValue);
NotifyButtonStatesChanged();
}
}

bool GOOrganSettingsButtonsProxy::CheckForUnapplied() {
bool res = IsModified();

if (res)
GOMessageBox(
_("Please apply or discard changes first"),
_("Error"),
wxOK | wxICON_ERROR,
p_window);
return res;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#ifndef GOORGANSETTINGSBUTTONSPROXY_H
#define GOORGANSETTINGSBUTTONSPROXY_H

class wxWindow;

class GOOrganSettingsButtonsProxy {
public:
class Listener {
Expand All @@ -17,6 +19,7 @@ class GOOrganSettingsButtonsProxy {

private:
Listener &r_listener;
wxWindow *p_window;

protected:
bool m_IsDistributeAudioEnabled = true;
Expand All @@ -26,13 +29,19 @@ class GOOrganSettingsButtonsProxy {
bool m_IsModified = false;

public:
GOOrganSettingsButtonsProxy(Listener &listener) : r_listener(listener) {}
GOOrganSettingsButtonsProxy(Listener &listener, wxWindow *pWindow);

protected:
void NotifyButtonStatesChanged() { r_listener.ButtonStatesChanged(); }
bool IsModified() const { return m_IsModified; }
void SetModified(bool newValue) { m_IsModified = newValue; }
void NotifyModified(bool newValue = true);
/**
* Checks if all changes have been applied. If some unapplied changes are
* present, then display an error message.
* Returns if there are unapplied changes
*/
bool CheckForUnapplied();

public:
bool IsDistributeAudioEnabled() const { return m_IsDistributeAudioEnabled; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,55 @@
#include "GOOrganSettingsEnclosuresTab.h"

#include <wx/gbsizer.h>
#include <wx/listbox.h>
#include <wx/stattext.h>
#include <wx/treectrl.h>

#include <model/GOEnclosure.h>
#include <model/GOOrganModel.h>
#include <model/GOWindchest.h>

static const wxSize EDIT_SIZE = wxSize(60, -1);

enum {
ID_EVENT_TREE = 200,
ID_EVENT_MIN_AMP_LEVEL,
};

BEGIN_EVENT_TABLE(GOOrganSettingsEnclosuresTab, wxPanel)
EVT_TREE_SEL_CHANGING(
ID_EVENT_TREE, GOOrganSettingsEnclosuresTab::OnTreeChanging)
EVT_TREE_SEL_CHANGED(ID_EVENT_TREE, GOOrganSettingsEnclosuresTab::OnTreeChanged)
END_EVENT_TABLE()

class GOOrganSettingsEnclosuresTab::ItemData : public wxTreeItemData {
public:
enum ItemType {
ORGAN,
WINDCHEST,
ENCLOSURE,
} m_type;

union {
GOOrganModel *p_organ;
GOWindchest *p_windchest;
GOEnclosure *p_enclosure;
};

ItemData(GOOrganModel &organModel) : m_type(ORGAN), p_organ(&organModel) {}
ItemData(GOWindchest &windchest)
: m_type(WINDCHEST), p_windchest(&windchest) {}
ItemData(GOEnclosure &enclosure)
: m_type(ENCLOSURE), p_enclosure(&enclosure) {}
};

GOOrganSettingsEnclosuresTab::GOOrganSettingsEnclosuresTab(
GOOrganModel &organModel,
wxWindow *parent,
GOOrganSettingsButtonsProxy::Listener &listener)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS),
GOOrganSettingsButtonsProxy(listener) {
GOOrganSettingsButtonsProxy(listener, this),
r_OrganModel(organModel) {
wxGridBagSizer *const mainSizer = new wxGridBagSizer(5, 5);

m_tree = new wxTreeCtrl(
Expand All @@ -32,13 +66,93 @@ GOOrganSettingsEnclosuresTab::GOOrganSettingsEnclosuresTab(
wxDefaultSize,
wxTR_HAS_BUTTONS | wxTR_MULTIPLE);
mainSizer->Add(
m_tree,
wxGBPosition(0, 0),
wxGBSpan(4, 1),
wxEXPAND | wxTOP | wxLEFT | wxBOTTOM,
m_tree, wxGBPosition(0, 0), wxGBSpan(3, 1), wxEXPAND | wxALL, 5);

mainSizer->Add(
new wxStaticText(this, wxID_ANY, _("Affected windchests:")),
wxGBPosition(0, 1),
wxDefaultSpan,
wxALIGN_RIGHT | wxTOP | wxLEFT | wxBOTTOM,
5);
m_WindchestList = new wxListBox(
this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0, nullptr, wxLB_SINGLE);
mainSizer->Add(
m_WindchestList,
wxGBPosition(0, 2),
wxGBSpan(2, 2),
wxEXPAND | wxTOP | wxRIGHT | wxBOTTOM,
5);
mainSizer->Add(
new wxStaticText(this, wxID_ANY, _("Minimal amplitude level:")),
wxGBPosition(2, 1),
wxDefaultSpan,
wxALIGN_RIGHT | wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM,
5);
m_MinAmpLevelEdit = new wxTextCtrl(
this, ID_EVENT_MIN_AMP_LEVEL, wxEmptyString, wxDefaultPosition, EDIT_SIZE);
mainSizer->Add(
m_MinAmpLevelEdit,
wxGBPosition(2, 2),
wxDefaultSpan,
wxEXPAND | wxRIGHT | wxBOTTOM,
5);
mainSizer->AddGrowableCol(0, 1);
mainSizer->AddGrowableRow(3, 1);

mainSizer->AddGrowableCol(0, 1);
mainSizer->AddGrowableCol(3, 1);
mainSizer->AddGrowableRow(1, 1);
SetSizerAndFit(mainSizer);
}

bool GOOrganSettingsEnclosuresTab::TransferDataToWindow() {
auto rootItem = m_tree->AddRoot(
r_OrganModel.GetRootPipeConfigNode().GetName(),
-1,
-1,
new ItemData(r_OrganModel));

for (GOWindchest *pW : r_OrganModel.GetWindchests()) {
auto windchestItem
= m_tree->AppendItem(rootItem, pW->GetName(), -1, -1, new ItemData(*pW));

for (GOEnclosure *pE : pW->GetEnclosures()) {
m_tree->AppendItem(
windchestItem, pE->GetName(), -1, -1, new ItemData(*pE));
m_WindchestsByEnclosures[pE].push_back(pW->GetName());
}
}
m_tree->Expand(rootItem);
m_tree->SelectItem(rootItem, true);
return true;
}

void GOOrganSettingsEnclosuresTab::OnTreeChanging(wxTreeEvent &e) {
if (CheckForUnapplied())
e.Veto();
}

void GOOrganSettingsEnclosuresTab::OnTreeChanged(wxTreeEvent &e) {
wxArrayTreeItemIds entries;
GOEnclosure *pSelectedEnclosure = nullptr;

m_tree->GetSelections(entries);
// set pSelectedEnclosure if only one enclosure is selected
if (entries.size() == 1) {
ItemData *pData = (ItemData *)m_tree->GetItemData(entries[0]);

if (pData->m_type == ItemData::ENCLOSURE)
pSelectedEnclosure = pData->p_enclosure;
}

// display data of the selected enclosure
m_WindchestList->Clear();
if (pSelectedEnclosure) {
if (auto iWindchests = m_WindchestsByEnclosures.find(pSelectedEnclosure);
iWindchests != m_WindchestsByEnclosures.end())
m_WindchestList->Append(iWindchests->second);
m_MinAmpLevelEdit->ChangeValue(
wxString::Format("%u", pSelectedEnclosure->GetAmpMinimumLevel()));
m_MinAmpLevelEdit->DiscardEdits();
} else {
m_MinAmpLevelEdit->Clear();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,56 @@
#ifndef GOORGANSETTINGSENCLOSURESTAB_H
#define GOORGANSETTINGSENCLOSURESTAB_H

#include <unordered_map>
#include <vector>

#include <wx/event.h>
#include <wx/panel.h>

#include "GOOrganSettingsButtonsProxy.h"

class wxListBox;
class wxTextCtrl;
class wxTreeCtrl;
class wxTreeEvent;

class GOEnclosure;
class GOOrganModel;
class GOWindchest;

class GOOrganSettingsEnclosuresTab : public wxPanel,
public GOOrganSettingsButtonsProxy {
private:
class ItemData;

GOOrganModel &r_OrganModel;

wxTreeCtrl *m_tree;
wxListBox *m_WindchestList;
wxTextCtrl *m_MinAmpLevelEdit;

std::unordered_map<GOEnclosure *, std::vector<wxString>>
m_WindchestsByEnclosures;

public:
GOOrganSettingsEnclosuresTab(
GOOrganModel &organModel,
wxWindow *parent,
GOOrganSettingsButtonsProxy::Listener &listener);

private:
bool TransferDataToWindow() override;

void OnTreeChanging(wxTreeEvent &e);
void OnTreeChanged(wxTreeEvent &e);

public:
void ResetToDefault();
void DiscardChanges();
void ApplyChanges();

bool Validate() override { return !CheckForUnapplied(); }

DECLARE_EVENT_TABLE()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ GOOrganSettingsPipesTab::GOOrganSettingsPipesTab(
wxWindow *parent,
GOOrganSettingsButtonsProxy::Listener &listener)
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS),
GOOrganSettingsButtonsProxy(listener),
GOOrganSettingsButtonsProxy(listener, this),
r_config(organModel.GetConfig()),
r_RootNode(organModel.GetRootPipeConfigNode()),
p_LastTreeItemData(nullptr),
Expand Down Expand Up @@ -423,18 +423,6 @@ bool GOOrganSettingsPipesTab::TransferDataToWindow() {
return true;
}

bool GOOrganSettingsPipesTab::CheckForUnapplied() {
bool res = IsModified();

if (res)
GOMessageBox(
_("Please apply or discard changes first"),
_("Error"),
wxOK | wxICON_ERROR,
this);
return res;
}

void GOOrganSettingsPipesTab::SetEmpty(wxChoice *choice) {
int index = choice->FindString(wxEmptyString);
if (index == wxNOT_FOUND)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,6 @@ class GOOrganSettingsPipesTab : public wxPanel,
wxTreeItemId FillTree(wxTreeItemId parent, GOPipeConfigNode &config);
bool TransferDataToWindow() override;

/**
* Checks if all changes have been applied. If some unapplied changes are
* present, then display an error message.
* Returns if there are unapplied changes
*/
bool CheckForUnapplied();

void SetEmpty(wxChoice *choice);
void RemoveEmpty(wxChoice *choice);

Expand Down
3 changes: 2 additions & 1 deletion src/grandorgue/model/GOOrganModel.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2024 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -147,6 +147,7 @@ class GOOrganModel : private GOCombinationButtonSet,
void UpdateTremulant(GOTremulant *tremulant);
void UpdateVolume();

const ptr_vector<GOWindchest> &GetWindchests() const { return m_windchests; }
unsigned GetWindchestCount() const { return m_windchests.size(); }
// Returns the windchest number starting with 1
unsigned AddWindchest(GOWindchest *windchest);
Expand Down
5 changes: 4 additions & 1 deletion src/grandorgue/model/GOWindchest.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Copyright 2006 Milan Digital Audio LLC
* Copyright 2009-2023 GrandOrgue contributors (see AUTHORS)
* Copyright 2009-2025 GrandOrgue contributors (see AUTHORS)
* License GPL-2.0 or later
* (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
*/
Expand Down Expand Up @@ -50,6 +50,9 @@ class GOWindchest : private GOSoundStateHandler {
void AddRank(GORank *rank);
void AddPipe(GOPipeWindchestCallback *pipe);
void AddEnclosure(GOEnclosure *enclosure);
const std::vector<GOEnclosure *> &GetEnclosures() const {
return m_enclosure;
}
const wxString &GetName();
GOPipeConfigNode &GetPipeConfig();
};
Expand Down

0 comments on commit b038d5a

Please sign in to comment.