Skip to content

Commit b0d090c

Browse files
authored
Added an internal OR switch to every drawstop (#2012)
1 parent 8e250a1 commit b0d090c

File tree

6 files changed

+46
-23
lines changed

6 files changed

+46
-23
lines changed

src/grandorgue/combinations/model/GOCombination.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ bool GOCombination::Push(
455455
m_ElementStates[i] != BOOL3_DEFAULT
456456
&& (!extraSet || extraSet->find(i) == extraSet->end())) {
457457
r_ElementDefinitions[i].control->SetCombinationState(
458-
to_bool(m_ElementStates[i]));
458+
to_bool(m_ElementStates[i]), m_CombinationStateName);
459459
used |= to_bool(m_ElementStates[i]);
460460
}
461461
}

src/grandorgue/combinations/model/GOCombination.h

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class GOCombination : public GOSaveableObject, public GOSaveableToYaml {
5858
protected:
5959
const std::vector<GOCombinationDefinition::Element> &r_ElementDefinitions;
6060
bool m_Protected;
61+
wxString m_CombinationStateName;
6162

6263
void EnsureElementStatesAllocated();
6364

@@ -135,6 +136,13 @@ class GOCombination : public GOSaveableObject, public GOSaveableToYaml {
135136
GOOrganModel &organModel, const GOCombinationDefinition &cmbDef);
136137
virtual ~GOCombination();
137138

139+
const wxString &GetCombinationStateName() const {
140+
return m_CombinationStateName;
141+
}
142+
void SetCombinationStateName(const wxString &combinationStateName) {
143+
m_CombinationStateName = combinationStateName;
144+
}
145+
138146
bool IsEmpty() const;
139147
GOBool3 GetElementState(unsigned no) const { return m_ElementStates[no]; }
140148
void GetExtraSetState(ExtraElementsSet &extraSet);

src/grandorgue/combinations/model/GOCombinationElement.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@
88
#ifndef GOCOMBINATIONELEMENT_H
99
#define GOCOMBINATIONELEMENT_H
1010

11+
class wxString;
12+
1113
class GOCombinationElement {
1214
public:
1315
virtual bool GetCombinationState() const = 0;
14-
virtual void SetCombinationState(bool on) = 0;
16+
virtual void SetCombinationState(bool on, const wxString &stateName) = 0;
1517
virtual bool IsControlledByUser() const = 0;
1618
};
1719

src/grandorgue/dialogs/GOStopsDialog.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ void GOStopsDialog::OnElementChanging(wxCommandEvent &event) {
139139
= static_cast<GOCombinationElement *>(pCheck->GetClientData());
140140

141141
if (pE)
142-
pE->SetCombinationState(event.IsChecked());
142+
pE->SetCombinationState(event.IsChecked(), wxEmptyString);
143143
}
144144

145145
void GOStopsDialog::ControlChanged(GOControl *pControl) {

src/grandorgue/model/GODrawStop.cpp

+25-18
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,6 @@ void GODrawstop::Save(GOConfigWriter &cfg) {
132132
GOButtonControl::Save(cfg);
133133
}
134134

135-
void GODrawstop::SetButtonState(bool on) {
136-
if (IsEngaged() == on)
137-
return;
138-
Display(on);
139-
SetDrawStopState(on);
140-
}
141-
142135
void GODrawstop::Reset() {
143136
if (IsReadOnly())
144137
return;
@@ -147,21 +140,35 @@ void GODrawstop::Reset() {
147140
SetButtonState(m_GCState > 0 ? true : false);
148141
}
149142

150-
void GODrawstop::SetDrawStopState(bool on) {
151-
if (IsActive() == on)
152-
return;
153-
if (IsReadOnly()) {
154-
Display(on);
143+
void GODrawstop::SetInternalState(bool on, const wxString &stateName) {
144+
bool &internalState = m_InternalStates[stateName];
145+
146+
if (internalState != on) {
147+
internalState = on;
148+
149+
bool resState = false;
150+
151+
for (const auto &intState : m_InternalStates)
152+
resState = resState || intState.second;
153+
if (m_ActiveState != resState) {
154+
Display(resState);
155+
// must be before calling m_ControlledDrawstops[i]->Update();
156+
m_ActiveState = resState;
157+
OnDrawstopStateChanged(resState);
158+
for (auto *pDrawstop : m_ControlledDrawstops)
159+
pDrawstop->Update(); // reads m_ActiveState
160+
}
155161
}
156-
m_ActiveState = on;
157-
OnDrawstopStateChanged(on);
158-
for (unsigned i = 0; i < m_ControlledDrawstops.size(); i++)
159-
m_ControlledDrawstops[i]->Update();
160162
}
161163

162-
void GODrawstop::SetCombinationState(bool on) {
164+
void GODrawstop::SetButtonState(bool on) {
165+
if (IsEngaged() != on)
166+
SetDrawStopState(on);
167+
}
168+
169+
void GODrawstop::SetCombinationState(bool on, const wxString &stateName) {
163170
if (!IsReadOnly())
164-
SetButtonState(on);
171+
SetInternalState(on, stateName);
165172
}
166173

167174
void GODrawstop::StartPlayback() {

src/grandorgue/model/GODrawStop.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#ifndef GODRAWSTOP_H
99
#define GODRAWSTOP_H
1010

11+
#include <unordered_map>
12+
13+
#include <wx/hashmap.h>
1114
#include <wx/string.h>
1215

1316
#include "combinations/model/GOCombinationElement.h"
@@ -29,13 +32,16 @@ class GODrawstop : public GOButtonControl, virtual public GOCombinationElement {
2932
static const struct IniFileEnumEntry m_function_types[];
3033
GOFunctionType m_Type;
3134
int m_GCState;
35+
std::unordered_map<wxString, bool, wxStringHash, wxStringEqual>
36+
m_InternalStates;
3237
bool m_ActiveState;
3338
std::vector<GODrawstop *> m_ControlledDrawstops;
3439
std::vector<GODrawstop *> m_ControllingDrawstops;
3540

3641
bool IsControlledByUser() const override { return !IsReadOnly(); }
3742

38-
void SetDrawStopState(bool on);
43+
void SetInternalState(bool on, const wxString &stateName);
44+
void SetDrawStopState(bool on) { SetInternalState(on, wxEmptyString); }
3945

4046
protected:
4147
/*
@@ -71,7 +77,7 @@ class GODrawstop : public GOButtonControl, virtual public GOCombinationElement {
7177
virtual void SetButtonState(bool on) override;
7278
virtual void Update();
7379
void Reset();
74-
void SetCombinationState(bool on) override;
80+
void SetCombinationState(bool on, const wxString &stateName) override;
7581
};
7682

7783
#endif

0 commit comments

Comments
 (0)