Skip to content

Commit

Permalink
Fixed disengaging manually enabled stops when a crescendo was in the …
Browse files Browse the repository at this point in the history
…Override=Off mode GrandOrgue#1935
  • Loading branch information
oleg68 committed Oct 14, 2024
1 parent d04c076 commit 83870e2
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 100 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fixed disengaging manually enabled stops when a crescendo was in the Override=Off mode https://github.com/GrandOrgue/grandorgue/issues/1935
- Fixed non bringing a dialog windows on top when it had been already open https://github.com/GrandOrgue/grandorgue/issues/1961
- Fixed combination button lighting when a crescendo was in the Override=Off mode https://github.com/GrandOrgue/grandorgue/issues/1935
# 3.15.1 (2024-09-03)
Expand Down
89 changes: 42 additions & 47 deletions src/grandorgue/combinations/GOSetter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,18 @@ GOSetter::GOSetter(GOOrganController *organController)
GOSetter::~GOSetter() {}

static const wxString WX_OVERRIDE_MODE = wxT("OverrideMode");
static const wxString WX_EMPTY_STRING = wxEmptyString;

static wxString crescendo_cmb_state_name(
bool isOverride, uint8_t crescendoIdx) {
return isOverride ? WX_EMPTY_STRING
: wxString::Format("crescendo-%c", 'A' + crescendoIdx);
}

wxString GOSetter::GetCrescendoCmbStateName(uint8_t crescendoIdx) const {
return crescendo_cmb_state_name(
m_CrescendoOverrideMode[crescendoIdx], crescendoIdx);
}

void GOSetter::Load(GOConfigReader &cfg) {
m_OrganController->RegisterSaveableObject(this);
Expand Down Expand Up @@ -382,14 +394,20 @@ void GOSetter::Load(GOConfigReader &cfg) {
m_CrescendoOverrideMode[i] = cfg.ReadBoolean(
CMBSetting, buffer, WX_OVERRIDE_MODE, false, defaultAddMode);
}
for (unsigned i = 0; i < N_CRESCENDOS * CRESCENDO_STEPS; i++) {
m_crescendo.push_back(new GOGeneralCombination(*m_OrganController, true));
m_CrescendoExtraSets.emplace_back();
buffer.Printf(
wxT("SetterCrescendo%d_%03d"),
(i / CRESCENDO_STEPS) + 1,
(i % CRESCENDO_STEPS) + 1);
m_crescendo[i]->Load(cfg, buffer);
for (uint8_t crescendoIdx = 0; crescendoIdx < N_CRESCENDOS; crescendoIdx++) {
wxString cmbStateName = GetCrescendoCmbStateName(crescendoIdx);

for (unsigned i = 0; i < CRESCENDO_STEPS; i++) {
GOGeneralCombination *pCmb
= new GOGeneralCombination(*m_OrganController, true);

m_crescendo.push_back(pCmb);
pCmb->Load(
cfg,
wxString::Format(
wxT("SetterCrescendo%d_%03d"), crescendoIdx + 1, i + 1));
pCmb->SetCombinationStateName(cmbStateName);
}
}

m_buttons[ID_SETTER_PREV]->Init(cfg, wxT("SetterPrev"), _("Previous"));
Expand Down Expand Up @@ -678,8 +696,6 @@ void GOSetter::FromYaml(const YAML::Node &yamlNode) {
}

void GOSetter::ButtonStateChanged(int id, bool newState) {
GOCombination::ExtraElementsSet elementSet;

switch (id) {

case ID_SETTER_REFRESH_FILES:
Expand Down Expand Up @@ -868,10 +884,16 @@ void GOSetter::ButtonStateChanged(int id, bool newState) {
nullptr);
break;

case ID_SETTER_CRESCENDO_OVERRIDE:
case ID_SETTER_CRESCENDO_OVERRIDE: {
wxString cmbStateName = crescendo_cmb_state_name(newState, m_crescendobank);

m_CrescendoOverrideMode[m_crescendobank] = newState;
for (unsigned i = 0; i < CRESCENDO_STEPS; i++)
m_crescendo[N_CRESCENDOS * m_crescendobank + i]->SetCombinationStateName(
cmbStateName);
m_buttons[ID_SETTER_CRESCENDO_OVERRIDE]->Display(newState);

break;
}
case ID_SETTER_PITCH_M1:
m_OrganController->GetRootPipeConfigNode().ModifyManualTuning(-1);
m_OrganController->GetRootPipeConfigNode().ModifyAutoTuningCorrection(-1);
Expand Down Expand Up @@ -1022,13 +1044,10 @@ void GOSetter::UpdateAllSetsButtonsLight(

void GOSetter::PushGeneral(
GOGeneralCombination &cmb, GOButtonControl *pButtonToLight) {
GOCombination::ExtraElementsSet elementSet;
const GOCombination::ExtraElementsSet *pExtraSet
= GetCrescendoAddSet(elementSet);

NotifyCmbPushed(cmb.Push(m_state, pExtraSet));
if (pButtonToLight || !pExtraSet) { // Otherwise the crescendo in add mode:
// not to switch off combination buttons
NotifyCmbPushed(cmb.Push(m_state));
if (pButtonToLight || IsCurrentCrescendoOverride()) {
// Otherwise the crescendo in add mode: not to switch off combination
// buttons
UpdateAllSetsButtonsLight(pButtonToLight, -1);
}
}
Expand All @@ -1039,12 +1058,8 @@ void GOSetter::PushDivisional(
unsigned cmbManual,
GOButtonControl *pButtonToLight) {
if (cmbManual == startManual || !m_state.m_IsActive) {
GOCombination::ExtraElementsSet elementSet;
const GOCombination::ExtraElementsSet *pExtraSet
= GetCrescendoAddSet(elementSet);

NotifyCmbPushed(cmb.Push(m_state, pExtraSet));
if (pButtonToLight || !pExtraSet)
NotifyCmbPushed(cmb.Push(m_state));
if (pButtonToLight || IsCurrentCrescendoOverride())
UpdateAllSetsButtonsLight(pButtonToLight, cmbManual);
}
}
Expand Down Expand Up @@ -1074,18 +1089,6 @@ void GOSetter::SetCrescendoType(unsigned no) {
m_CrescendoOverrideMode[m_crescendobank]);
}

const GOCombination::ExtraElementsSet *GOSetter::GetCrescendoAddSet(
GOCombination::ExtraElementsSet &elementSet) {
const GOCombination::ExtraElementsSet *pResElementSet = nullptr;

if (!m_CrescendoOverrideMode[m_crescendobank]) {
m_crescendo[m_crescendopos + m_crescendobank * CRESCENDO_STEPS]
->GetEnabledElements(elementSet);
pResElementSet = &elementSet;
}
return pResElementSet;
}

void GOSetter::UpdatePosition(int pos) {
if (pos != (int)m_pos)
SetPosition(pos);
Expand Down Expand Up @@ -1131,24 +1134,16 @@ void GOSetter::Crescendo(int newpos, bool force) {
const unsigned oldIdx = m_crescendopos + m_crescendobank * CRESCENDO_STEPS;
const unsigned newIdx = oldIdx + 1;

if (crescendoAddMode)
m_crescendo[oldIdx]->GetExtraSetState(m_CrescendoExtraSets[oldIdx]);
else
m_CrescendoExtraSets[oldIdx].clear();
++m_crescendopos;
changed = changed
|| m_crescendo[newIdx]->Push(
m_state, crescendoAddMode ? &m_CrescendoExtraSets[oldIdx] : nullptr);
changed = changed || m_crescendo[newIdx]->Push(m_state);
}

while (pos < m_crescendopos) {
--m_crescendopos;

const unsigned newIdx = m_crescendopos + m_crescendobank * CRESCENDO_STEPS;

changed = changed
|| m_crescendo[newIdx]->Push(
m_state, crescendoAddMode ? &m_CrescendoExtraSets[newIdx] : nullptr);
changed = changed || m_crescendo[newIdx]->Push(m_state);
}
// switch combination buttons off in the crescendo override mode
if (changed && !crescendoAddMode)
Expand Down
13 changes: 4 additions & 9 deletions src/grandorgue/combinations/GOSetter.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class GOSetter : private GOSoundStateHandler,
ptr_vector<GOGeneralCombination> m_framegeneral;
ptr_vector<GOGeneralCombination> m_general;
ptr_vector<GOGeneralCombination> m_crescendo;
std::vector<GOCombination::ExtraElementsSet> m_CrescendoExtraSets;
bool m_CrescendoOverrideMode[N_CRESCENDOS];
GOLabelControl m_CurrFileDisplay;
GOLabelControl m_PosDisplay;
Expand All @@ -81,6 +80,10 @@ class GOSetter : private GOSoundStateHandler,

void SetSetterType(GOSetterState::SetterType type);
void SetCrescendoType(unsigned no);
bool IsCurrentCrescendoOverride() const {
return m_CrescendoOverrideMode[m_crescendobank];
}
wxString GetCrescendoCmbStateName(uint8_t crescendoIdx) const;
void Crescendo(int pos, bool force = false);

static const struct ButtonDefinitionEntry m_element_types[];
Expand Down Expand Up @@ -205,14 +208,6 @@ class GOSetter : private GOSoundStateHandler,
unsigned cmbManual,
GOButtonControl *pButtonToLight) override;

/*
* If current crescendo is in override mode then returns nullptr
* If current crescendo is in add mode then fills elementSet and returns a
* pointer to it
*/
const GOCombination::ExtraElementsSet *GetCrescendoAddSet(
GOCombination::ExtraElementsSet &elementSet);

void Next();
void Prev();
void Push();
Expand Down
36 changes: 6 additions & 30 deletions src/grandorgue/combinations/model/GOCombination.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,28 +213,6 @@ void GOCombination::SetStatesFromYaml(
}
}

void GOCombination::GetExtraSetState(
GOCombination::ExtraElementsSet &extraSet) {
extraSet.clear();
// May be called from init a crescendo before init combinations
EnsureElementStatesAllocated();
for (unsigned i = 0; i < r_ElementDefinitions.size(); i++) {
if (
m_ElementStates[i] == BOOL3_FALSE
&& r_ElementDefinitions[i].control->GetCombinationState())
extraSet.insert(i);
}
}

void GOCombination::GetEnabledElements(
GOCombination::ExtraElementsSet &enabledElements) {
enabledElements.clear();
for (unsigned i = 0; i < r_ElementDefinitions.size(); i++) {
if (to_bool(m_ElementStates[i]))
enabledElements.insert(i);
}
}

void GOCombination::EnsureElementStatesAllocated() {
unsigned defSize = r_ElementDefinitions.size();

Expand Down Expand Up @@ -438,9 +416,7 @@ bool GOCombination::FillWithCurrent(
return used;
}

bool GOCombination::Push(
const GOSetterState &setterState,
const GOCombination::ExtraElementsSet *extraSet) {
bool GOCombination::Push(const GOSetterState &setterState) {
bool used = false;

if (setterState.m_IsActive) {
Expand All @@ -451,12 +427,12 @@ bool GOCombination::Push(
} else {
EnsureElementStatesAllocated();
for (unsigned i = 0; i < r_ElementDefinitions.size(); i++) {
if (
m_ElementStates[i] != BOOL3_DEFAULT
&& (!extraSet || extraSet->find(i) == extraSet->end())) {
if (m_ElementStates[i] != BOOL3_DEFAULT) {
bool elementState = to_bool(m_ElementStates[i]);

r_ElementDefinitions[i].control->SetCombinationState(
to_bool(m_ElementStates[i]), m_CombinationStateName);
used |= to_bool(m_ElementStates[i]);
elementState, m_CombinationStateName);
used = used || elementState;
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions src/grandorgue/combinations/model/GOCombination.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
class GOOrganModel;

class GOCombination : public GOSaveableObject, public GOSaveableToYaml {
public:
using ExtraElementsSet = std::unordered_set<unsigned>;

protected:
GOOrganModel &r_OrganModel;

Expand Down Expand Up @@ -145,8 +142,6 @@ class GOCombination : public GOSaveableObject, public GOSaveableToYaml {

bool IsEmpty() const;
GOBool3 GetElementState(unsigned no) const { return m_ElementStates[no]; }
void GetExtraSetState(ExtraElementsSet &extraSet);
void GetEnabledElements(GOCombination::ExtraElementsSet &enabledElements);

void Copy(const GOCombination *combination);
void Clear();
Expand Down Expand Up @@ -182,9 +177,7 @@ class GOCombination : public GOSaveableObject, public GOSaveableToYaml {

void FromYaml(const YAML::Node &yamlNode) override;

bool Push(
const GOSetterState &setterState,
const ExtraElementsSet *extraSet = nullptr);
bool Push(const GOSetterState &setterState);
};

#endif
5 changes: 0 additions & 5 deletions src/grandorgue/model/GODrawStop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,6 @@ void GODrawstop::SetInternalState(bool on, const wxString &stateName) {
}
}

void GODrawstop::SetButtonState(bool on) {
if (IsEngaged() != on)
SetDrawStopState(on);
}

void GODrawstop::SetCombinationState(bool on, const wxString &stateName) {
if (!IsReadOnly())
SetInternalState(on, stateName);
Expand Down
2 changes: 1 addition & 1 deletion src/grandorgue/model/GODrawStop.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class GODrawstop : public GOButtonControl, virtual public GOCombinationElement {
void Init(GOConfigReader &cfg, wxString group, wxString name);
void Load(GOConfigReader &cfg, wxString group);
void RegisterControlled(GODrawstop *sw);
virtual void SetButtonState(bool on) override;
virtual void SetButtonState(bool on) override { SetDrawStopState(on); }
virtual void Update();
void Reset();
void SetCombinationState(bool on, const wxString &stateName) override;
Expand Down

0 comments on commit 83870e2

Please sign in to comment.