@@ -44,35 +44,90 @@ EffectRackController::EffectRackController(DeviceServiceS deviceService, EditorS
4444
4545int EffectRackController::effectCount () const
4646{
47- return static_cast <int >(m_deviceService->effectRack ().effectCount ());
47+ if (const auto rack = currentRack ()) {
48+ return static_cast <int >(rack->get ().effectCount ());
49+ }
50+ return 0 ;
4851}
4952
5053int EffectRackController::revision () const
5154{
5255 return m_revision;
5356}
5457
58+ QString EffectRackController::targetDeviceName () const
59+ {
60+ return m_targetDeviceName;
61+ }
62+
63+ void EffectRackController::setTargetDeviceName (const QString & name)
64+ {
65+ if (m_targetDeviceName != name) {
66+ m_targetDeviceName = name;
67+ emit targetDeviceNameChanged ();
68+ m_revision++;
69+ emit revisionChanged ();
70+ emit effectCountChanged ();
71+ }
72+ }
73+
74+ bool EffectRackController::isInsertRack () const
75+ {
76+ return m_isInsertRack;
77+ }
78+
79+ void EffectRackController::setIsInsertRack (bool isInsert)
80+ {
81+ if (m_isInsertRack != isInsert) {
82+ m_isInsertRack = isInsert;
83+ emit isInsertRackChanged ();
84+ m_revision++;
85+ emit revisionChanged ();
86+ emit effectCountChanged ();
87+ }
88+ }
89+
90+ std::optional<std::reference_wrapper<EffectRack>> EffectRackController::currentRack () const
91+ {
92+ if (m_targetDeviceName.isEmpty ()) {
93+ if (m_isInsertRack) {
94+ return std::ref (m_deviceService->insertEffectRack ());
95+ } else {
96+ return std::ref (m_deviceService->sendEffectRack ());
97+ }
98+ } else {
99+ if (const auto device = m_deviceService->device (m_targetDeviceName.toStdString ())) {
100+ return std::ref (device->insertEffectRack ());
101+ }
102+ }
103+ return std::nullopt ;
104+ }
105+
55106float EffectRackController::parameterValue (int effectIndex, const QString & paramName) const
56107{
57- if (const auto effect = m_deviceService->effectRack ().effect (static_cast <size_t >(effectIndex))) {
58- if (const auto parameter = effect->parameter (paramName.toStdString ()); parameter) {
59- return parameter->get ().value ();
108+ if (const auto rack = currentRack ()) {
109+ if (const auto effect = rack->get ().effect (static_cast <size_t >(effectIndex))) {
110+ if (const auto parameter = effect->parameter (paramName.toStdString ()); parameter) {
111+ return parameter->get ().value ();
112+ }
60113 }
61114 }
62115 return 0 .0f ;
63116}
64117
65118void EffectRackController::setParameterValue (int effectIndex, const QString & paramName, float value)
66119{
67- if (const auto effect = m_deviceService->effectRack ().effect (static_cast <size_t >(effectIndex))) {
68- if (const auto parameter = effect->parameter (paramName.toStdString ()); parameter) {
69- if (parameter->get ().update (value)) {
70- effect->sync ();
120+ if (const auto rack = currentRack ()) {
121+ if (const auto effect = rack->get ().effect (static_cast <size_t >(effectIndex))) {
122+ if (const auto parameter = effect->parameter (paramName.toStdString ()); parameter) {
123+ if (parameter->get ().update (value)) {
124+ effect->sync ();
71125
72- m_editorService->setIsModified (true );
73- m_revision++;
74- emit revisionChanged ();
75- emit parameterChanged (effectIndex, paramName);
126+ m_editorService->setIsModified (true );
127+ m_revision++;
128+ emit revisionChanged ();
129+ emit parameterChanged (effectIndex, paramName);
130+ }
76131 }
77132 }
78133 }
@@ -97,19 +152,23 @@ void EffectRackController::setEffect(int slotIndex, const QString & typeId)
97152 }
98153
99154 if (effect) {
100- m_deviceService->effectRack ().setEffect (static_cast <size_t >(slotIndex), std::move (effect));
101- m_editorService->setIsModified (true );
102- m_revision++;
103- emit revisionChanged ();
155+ if (const auto rack = currentRack ()) {
156+ rack->get ().setEffect (static_cast <size_t >(slotIndex), std::move (effect));
157+ m_editorService->setIsModified (true );
158+ m_revision++;
159+ emit revisionChanged ();
160+ }
104161 }
105162}
106163
107164void EffectRackController::clearEffect (int slotIndex)
108165{
109- m_deviceService->effectRack ().setEffect (static_cast <size_t >(slotIndex), nullptr );
110- m_editorService->setIsModified (true );
111- m_revision++;
112- emit revisionChanged ();
166+ if (const auto rack = currentRack ()) {
167+ rack->get ().setEffect (static_cast <size_t >(slotIndex), nullptr );
168+ m_editorService->setIsModified (true );
169+ m_revision++;
170+ emit revisionChanged ();
171+ }
113172}
114173QVariantList EffectRackController::availableEffects () const
115174{
@@ -123,31 +182,30 @@ QVariantList EffectRackController::availableEffects() const
123182 };
124183
125184 addEffect (" Reverb" , ReverbEffect::typeIdString ());
126- addEffect (" Delay" , DelayEffect::typeIdString ());
127- addEffect (" High Pass Filter" , HighPassFilterEffect::typeIdString ());
128- addEffect (" Low Pass Filter" , LowPassFilterEffect::typeIdString ());
129- addEffect (" Panning" , PanningEffect::typeIdString ());
130- addEffect (" Volume" , VolumeEffect::typeIdString ());
131185
132186 return list;
133187}
134188
135189QStringList EffectRackController::parameterNames (int effectIndex) const
136190{
137- if (const auto effect = m_deviceService->effectRack ().effect (static_cast <size_t >(effectIndex))) {
138- QStringList names;
139- for (const auto & name : effect->parameterNames ()) {
140- names.append (QString::fromStdString (name));
191+ if (const auto rack = currentRack ()) {
192+ if (const auto effect = rack->get ().effect (static_cast <size_t >(effectIndex))) {
193+ QStringList names;
194+ for (const auto & name : effect->parameterNames ()) {
195+ names.append (QString::fromStdString (name));
196+ }
197+ return names;
141198 }
142- return names;
143199 }
144200 return {};
145201}
146202
147203QString EffectRackController::effectType (int effectIndex) const
148204{
149- if (const auto effect = m_deviceService->effectRack ().effect (static_cast <size_t >(effectIndex))) {
150- return QString::fromStdString (effect->type ());
205+ if (const auto rack = currentRack ()) {
206+ if (const auto effect = rack->get ().effect (static_cast <size_t >(effectIndex))) {
207+ return QString::fromStdString (effect->type ());
208+ }
151209 }
152210 return " " ;
153211}
@@ -193,15 +251,17 @@ QStringList EffectRackController::reverbPresets() const
193251
194252void EffectRackController::applyReverbPreset (int effectIndex, int presetIndex)
195253{
196- if (const auto effect = m_deviceService->effectRack ().effect (static_cast <size_t >(effectIndex))) {
197- if (const auto reverb = std::dynamic_pointer_cast<ReverbEffect>(effect)) {
198- const auto presetNames = ReverbEffect::presetNames ();
199- if (presetIndex >= 0 && presetIndex < static_cast <int >(presetNames.size ())) {
200- reverb->applyPreset (ReverbEffect::stringToPreset (presetNames[presetIndex]));
201- m_editorService->setIsModified (true );
202- m_revision++;
203- emit revisionChanged ();
204- emit parameterChanged (effectIndex, " " ); // Notify all parameters changed
254+ if (const auto rack = currentRack ()) {
255+ if (const auto effect = rack->get ().effect (static_cast <size_t >(effectIndex))) {
256+ if (const auto reverb = std::dynamic_pointer_cast<ReverbEffect>(effect)) {
257+ const auto presetNames = ReverbEffect::presetNames ();
258+ if (presetIndex >= 0 && presetIndex < static_cast <int >(presetNames.size ())) {
259+ reverb->applyPreset (ReverbEffect::stringToPreset (presetNames[presetIndex]));
260+ m_editorService->setIsModified (true );
261+ m_revision++;
262+ emit revisionChanged ();
263+ emit parameterChanged (effectIndex, " " ); // Notify all parameters changed
264+ }
205265 }
206266 }
207267 }
0 commit comments