|
1 | 1 | /*
|
2 | 2 | * Copyright 2006 Milan Digital Audio LLC
|
3 |
| - * Copyright 2009-2023 GrandOrgue contributors (see AUTHORS) |
| 3 | + * Copyright 2009-2024 GrandOrgue contributors (see AUTHORS) |
4 | 4 | * License GPL-2.0 or later
|
5 | 5 | * (https://www.gnu.org/licenses/old-licenses/gpl-2.0.html).
|
6 | 6 | */
|
|
9 | 9 |
|
10 | 10 | #include <wx/intl.h>
|
11 | 11 |
|
| 12 | +#include "config/GOConfigWriter.h" |
| 13 | +#include "control/GOCallbackButtonControl.h" |
12 | 14 | #include "model/GOCoupler.h"
|
13 | 15 | #include "model/GOManual.h"
|
14 | 16 | #include "model/GOOrganModel.h"
|
@@ -56,8 +58,8 @@ void GOVirtualCouplerController::Init(
|
56 | 58 | for (unsigned int dstManualN = organModel.GetFirstManualIndex();
|
57 | 59 | dstManualN < organModel.GetODFManualCount();
|
58 | 60 | dstManualN++) {
|
59 |
| - ManualCouplerSet &manualCouplers |
60 |
| - = m_CouplerPtrs[make_key(srcManualN, dstManualN)]; |
| 61 | + CouplerSetKey couplerSetKey = make_key(srcManualN, dstManualN); |
| 62 | + ManualCouplerSet &manualCouplers = m_CouplerPtrs[couplerSetKey]; |
61 | 63 |
|
62 | 64 | load_coupler(
|
63 | 65 | organModel,
|
@@ -123,13 +125,67 @@ void GOVirtualCouplerController::Init(
|
123 | 125 | wxT("SetterManual%03dCoupler%03dMEL"),
|
124 | 126 | wxT("S%dM%dCM"),
|
125 | 127 | _("MEL"));
|
| 128 | + |
| 129 | + GOCallbackButtonControl *pCoupleThrough |
| 130 | + = new GOCallbackButtonControl(organModel, this, false, false); |
| 131 | + |
| 132 | + pCoupleThrough->Init( |
| 133 | + cfg, |
| 134 | + wxString::Format( |
| 135 | + wxT("SetterManual%03dCoupler%03dThrough"), srcManualN, dstManualN), |
| 136 | + _("Couple Through")); |
| 137 | + m_CoupleThroughPtrs[couplerSetKey] = pCoupleThrough; |
126 | 138 | }
|
127 | 139 | }
|
128 | 140 | }
|
129 | 141 |
|
| 142 | +static wxString WX_COOPLE_THROUGH = wxT("CoupleThrough"); |
| 143 | + |
| 144 | +void GOVirtualCouplerController::Load( |
| 145 | + GOOrganModel &organModel, GOConfigReader &cfg) { |
| 146 | + Init(organModel, cfg); |
| 147 | + for (auto e : m_CoupleThroughPtrs) { |
| 148 | + GOCallbackButtonControl *pCoupleThrough = e.second; |
| 149 | + bool isCoupleThrough = cfg.ReadBoolean( |
| 150 | + CMBSetting, pCoupleThrough->GetGroup(), WX_COOPLE_THROUGH, false, false); |
| 151 | + |
| 152 | + pCoupleThrough->Set(isCoupleThrough); |
| 153 | + } |
| 154 | +} |
| 155 | + |
| 156 | +void GOVirtualCouplerController::Save(GOConfigWriter &cfg) { |
| 157 | + for (auto e : m_CoupleThroughPtrs) { |
| 158 | + GOCallbackButtonControl *pCoupleThrough = e.second; |
| 159 | + |
| 160 | + cfg.WriteBoolean( |
| 161 | + pCoupleThrough->GetGroup(), |
| 162 | + WX_COOPLE_THROUGH, |
| 163 | + pCoupleThrough->IsEngaged()); |
| 164 | + } |
| 165 | +} |
| 166 | + |
130 | 167 | GOCoupler *GOVirtualCouplerController::GetCoupler(
|
131 | 168 | unsigned fromManual, unsigned toManual, CouplerType type) const {
|
132 | 169 | const auto iter = m_CouplerPtrs.find(make_key(fromManual, toManual));
|
133 | 170 |
|
134 | 171 | return iter != m_CouplerPtrs.end() ? iter->second[type] : nullptr;
|
135 | 172 | }
|
| 173 | + |
| 174 | +GOButtonControl *GOVirtualCouplerController::GetCouplerThrough( |
| 175 | + unsigned fromManual, unsigned toManual) const { |
| 176 | + const auto iter = m_CoupleThroughPtrs.find(make_key(fromManual, toManual)); |
| 177 | + |
| 178 | + return iter != m_CoupleThroughPtrs.end() ? iter->second : nullptr; |
| 179 | +} |
| 180 | + |
| 181 | +void GOVirtualCouplerController::ButtonStateChanged( |
| 182 | + GOButtonControl *button, bool newState) { |
| 183 | + for (auto e : m_CoupleThroughPtrs) |
| 184 | + if (e.second == button) { |
| 185 | + const CouplerSetKey &couplerSetKey = e.first; |
| 186 | + ManualCouplerSet &manualCouplers = m_CouplerPtrs[couplerSetKey]; |
| 187 | + |
| 188 | + for (auto pCoupler : manualCouplers) |
| 189 | + pCoupler->SetRecursive(newState); |
| 190 | + } |
| 191 | +} |
0 commit comments