Skip to content

Commit

Permalink
Added refreshing key states when changing Couple Through
Browse files Browse the repository at this point in the history
  • Loading branch information
oleg68 committed Feb 29, 2024
1 parent 194d105 commit b25656e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 14 deletions.
4 changes: 3 additions & 1 deletion src/grandorgue/GOVirtualCouplerController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ void GOVirtualCouplerController::ButtonStateChanged(
const CouplerSetKey &couplerSetKey = e.first;
ManualCouplerSet &manualCouplers = m_CouplerPtrs[couplerSetKey];

for (auto pCoupler : manualCouplers)
for (auto pCoupler : manualCouplers) {
pCoupler->SetRecursive(newState);
pCoupler->RefreshState();
}
}
}
17 changes: 15 additions & 2 deletions src/grandorgue/model/GOCoupler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void GOCoupler::SetOut(int noteNumber, unsigned velocity) {
newstate--;
GOManual *dest = r_OrganModel.GetManual(m_DestinationManual);
m_OutVelocity[note] = newstate;
dest->SetKey(note, m_OutVelocity[note], this, m_CouplerIndexInDest);
dest->SetKey(note, m_OutVelocity[note], m_CouplerIndexInDest);
}

unsigned GOCoupler::GetInternalState(int noteNumber) {
Expand Down Expand Up @@ -363,11 +363,24 @@ void GOCoupler::ChangeState(bool on) {
newstate--;
if (m_OutVelocity[i] != newstate) {
m_OutVelocity[i] = newstate;
dest->SetKey(i, m_OutVelocity[i], this, m_CouplerIndexInDest);
dest->SetKey(i, m_OutVelocity[i], m_CouplerIndexInDest);
}
}
}

void GOCoupler::RefreshState() {
bool on = IsActive();

if (m_UnisonOff)
r_OrganModel.GetManual(m_SourceManual)->SetUnisonOff(on);
else {
GOManual *dest = r_OrganModel.GetManual(m_DestinationManual);

for (unsigned l = m_OutVelocity.size(), i = 0; i < l; i++)
dest->PropagateKeyToCouplers(i);
}
}

bool GOCoupler::IsIntermanual() {
return m_SourceManual != m_DestinationManual;
}
Expand Down
3 changes: 3 additions & 0 deletions src/grandorgue/model/GOCoupler.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ class GOCoupler : public GODrawstop {
int dest_manual,
GOCouplerType coupler_type);
void Load(GOConfigReader &cfg, wxString group);

void RefreshState();

void SetKey(
unsigned note,
const std::vector<unsigned> &velocities,
Expand Down
21 changes: 13 additions & 8 deletions src/grandorgue/model/GOManual.cpp
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-2024 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 @@ -271,9 +271,17 @@ void GOManual::SetOutput(unsigned note, unsigned velocity) {
m_division.SetKey(midi_note, velocity);
}

void GOManual::SetKey(
unsigned note, unsigned velocity, GOCoupler *prev, unsigned couplerID) {
if (note < 0 || note >= m_Velocity.size())
void GOManual::PropagateKeyToCouplers(unsigned note) {
if (note < m_Velocity.size()) {
auto &noteVelocities = m_Velocities[note];

for (auto pCoupler : m_couplers)
pCoupler->SetKey(note, noteVelocities, m_InputCouplers);
}
}

void GOManual::SetKey(unsigned note, unsigned velocity, unsigned couplerID) {
if (note >= m_Velocity.size())
return;

if (m_Velocities[note][couplerID] == velocity)
Expand All @@ -289,9 +297,7 @@ void GOManual::SetKey(
m_RemoteVelocity[note] = m_Velocities[note][i];
}

for (unsigned i = 0; i < m_couplers.size(); i++)
m_couplers[i]->SetKey(note, m_Velocities[note], m_InputCouplers);

PropagateKeyToCouplers(note);
SetOutput(note, m_UnisonOff > 0 ? m_RemoteVelocity[note] : m_Velocity[note]);

if (
Expand All @@ -315,7 +321,6 @@ void GOManual::Set(unsigned note, unsigned velocity) {
note - m_first_accessible_key_midi_note_nb
+ m_first_accessible_logical_key_nb - 1,
velocity,
NULL,
0);
}

Expand Down
7 changes: 4 additions & 3 deletions src/grandorgue/model/GOManual.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-2024 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 @@ -116,8 +116,9 @@ class GOManual : private GOEventHandler,
void Load(GOConfigReader &cfg, const wxString &group, int manualNumber);
void LoadDivisionals(GOConfigReader &cfg);
unsigned RegisterCoupler(GOCoupler *coupler);
void SetKey(
unsigned note, unsigned velocity, GOCoupler *prev, unsigned couplerID);
// send the key state to all outgoing couplers
void PropagateKeyToCouplers(unsigned note);
void SetKey(unsigned note, unsigned velocity, unsigned couplerID);
void Set(unsigned note, unsigned velocity);
void SetUnisonOff(bool on);
void Update();
Expand Down

0 comments on commit b25656e

Please sign in to comment.