Skip to content

Commit e8f0601

Browse files
committed
Multichannel: Made external controller classes multi-channel aware
1 parent 05739df commit e8f0601

12 files changed

Lines changed: 53 additions & 42 deletions

modules/tracktion_engine/control_surfaces/tracktion_ControlSurface.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,18 +142,17 @@ class ControlSurface : public Selectable
142142

143143
// if the device has per-channel level meters, this should update one of them.
144144
// the channel number is the physical channel on the device, regardless of bank selection
145-
// if the channel is mono then l == r
146-
// level is 0 to 1.0
147-
virtual void channelLevelChanged ([[maybe_unused]] int channel, [[maybe_unused]] float l, [[maybe_unused]] float r) {}
145+
// levels are 0 to 1.0, one per channel
146+
virtual void channelLevelChanged ([[maybe_unused]] int channel, [[maybe_unused]] std::span<const float> levels) {}
148147

149148
// when a track is selected or deselected
150149
virtual void trackSelectionChanged ([[maybe_unused]] int channel, [[maybe_unused]] bool isSelected) {}
151150

152151
virtual void trackRecordEnabled ([[maybe_unused]] int channel, [[maybe_unused]] bool isEnabled) {}
153152

154153
// if the device has a master level readout, this should update it.
155-
virtual void masterLevelsChanged ([[maybe_unused]] float leftLevel,
156-
[[maybe_unused]] float rightLevel) {}
154+
// levels are 0 to 1.0, one per channel
155+
virtual void masterLevelsChanged ([[maybe_unused]] std::span<const float> levels) {}
157156

158157
// tells the device that the playback position has changed, so if it has a timecode
159158
// display, it should update it.

modules/tracktion_engine/control_surfaces/tracktion_CustomControlSurface.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ void CustomControlSurface::faderBankChanged (int newStartChannelNumber, const ju
821821
}
822822
}
823823

824-
void CustomControlSurface::channelLevelChanged (int, float, float) {}
824+
void CustomControlSurface::channelLevelChanged (int, std::span<const float>) {}
825825

826826
void CustomControlSurface::trackSelectionChanged (int faderIndex, bool isSelected)
827827
{
@@ -833,7 +833,7 @@ void CustomControlSurface::trackRecordEnabled (int faderIndex, bool recordEnable
833833
sendCommandToControllerForActionID (armTrackId + faderIndex, recordEnabled);
834834
}
835835

836-
void CustomControlSurface::masterLevelsChanged (float, float) {}
836+
void CustomControlSurface::masterLevelsChanged (std::span<const float>) {}
837837

838838
void CustomControlSurface::timecodeChanged (int barsOrHours, int beatsOrMinutes,
839839
int ticksOrSeconds, int millisecs, bool isBarsBeats, bool isFrames)

modules/tracktion_engine/control_surfaces/tracktion_CustomControlSurface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,10 @@ class CustomControlSurface : public ControlSurface,
220220
void automationReadModeChanged (bool isReading) override;
221221
void automationWriteModeChanged (bool isWriting) override;
222222
void faderBankChanged (int newStartChannelNumber, const juce::StringArray& trackNames) override;
223-
void channelLevelChanged (int channel, float l, float r) override;
223+
void channelLevelChanged (int channel, std::span<const float> levels) override;
224224
void trackSelectionChanged (int channel, bool isSelected) override;
225225
void trackRecordEnabled (int channel, bool isEnabled) override;
226-
void masterLevelsChanged (float leftLevel, float rightLevel) override;
226+
void masterLevelsChanged (std::span<const float> levels) override;
227227
void timecodeChanged (int barsOrHours, int beatsOrMinutes, int ticksOrSeconds, int millisecs, bool isBarsBeats, bool isFrames) override;
228228
void clickOnOffChanged (bool isClickOn) override;
229229
void snapOnOffChanged (bool isSnapOn) override;

modules/tracktion_engine/control_surfaces/tracktion_ExternalController.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -549,18 +549,18 @@ void ExternalController::clickChanged (bool isOn)
549549
getControlSurface().clickOnOffChanged (isOn);
550550
}
551551

552-
void ExternalController::channelLevelChanged (int channelNum, float l, float r)
552+
void ExternalController::channelLevelChanged (int channelNum, std::span<const float> levels)
553553
{
554554
int i = getFaderIndexInActiveRegion (channelNum);
555555

556556
if (i >= 0)
557-
getControlSurface().channelLevelChanged (i, l, r);
557+
getControlSurface().channelLevelChanged (i, levels);
558558
}
559559

560-
void ExternalController::masterLevelsChanged (float leftLevel, float rightLevel)
560+
void ExternalController::masterLevelsChanged (std::span<const float> levels)
561561
{
562562
if (controlSurface != nullptr)
563-
getControlSurface().masterLevelsChanged (leftLevel, rightLevel);
563+
getControlSurface().masterLevelsChanged (levels);
564564
}
565565

566566
void ExternalController::timecodeChanged (int barsOrHours,
@@ -1244,7 +1244,7 @@ void ExternalController::updateDeviceState()
12441244

12451245
updateSoloAndMute (chan, t->getMuteAndSoloLightState(), true);
12461246

1247-
channelLevelChanged (chan, 0.0f, 0.0f);
1247+
channelLevelChanged (chan, {});
12481248

12491249
if (auto sm = ecm.getSelectionManager())
12501250
trackSelected (chan, sm->isSelected (t));
@@ -1254,7 +1254,7 @@ void ExternalController::updateDeviceState()
12541254
moveFader (chan, decibelsToVolumeFaderPosition (0.0f));
12551255
movePanPot (chan, 0.0f);
12561256
updateSoloAndMute (chan, {}, false);
1257-
channelLevelChanged (chan, 0.0f, 0.0f);
1257+
channelLevelChanged (chan, {});
12581258
trackSelected (chan, false);
12591259
}
12601260
}
@@ -1318,7 +1318,7 @@ void ExternalController::updateDeviceState()
13181318
cs.punchOnOffChanged (edit->recordingPunchInOut);
13191319
cs.slaveOnOffChanged (edit->isTimecodeSyncEnabled());
13201320

1321-
masterLevelsChanged (0.0f, 0.0f);
1321+
masterLevelsChanged ({});
13221322

13231323
updateTrackRecordLights();
13241324
cs.auxBankChanged (auxBank);

modules/tracktion_engine/control_surfaces/tracktion_ExternalController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ class ExternalController : private juce::AsyncUpdater,
8484
void snapChanged (bool isOn);
8585
void loopChanged (bool isOn);
8686
void clickChanged (bool isOn);
87-
void channelLevelChanged (int channel, float l, float r);
88-
void masterLevelsChanged (float leftLevel, float rightLevel);
87+
void channelLevelChanged (int channel, std::span<const float> levels);
88+
void masterLevelsChanged (std::span<const float> levels);
8989
void timecodeChanged (int barsOrHours, int beatsOrMinutes, int ticksOrSeconds, int millisecs, bool isBarsBeats, bool isFrames);
9090
void trackSelected (int channel, bool isSelected);
9191
void selectOtherObject (SelectableClass::Relationship, bool moveFromCurrentPlugin);

modules/tracktion_engine/control_surfaces/tracktion_ExternalControllerManager.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,13 @@ ExternalControllerManager::ExternalControllerManager (Engine& e) : engine (e)
233233
masterLevelState->measurer->addClient (masterLevelState->client);
234234
}
235235

236-
auto dBL = masterLevelState->client.getAndClearAudioLevel (0).dB;
237-
auto dBR = masterLevelState->client.getNumChannelsUsed() > 1
238-
? masterLevelState->client.getAndClearAudioLevel (1).dB : dBL;
236+
auto numChans = masterLevelState->client.getNumChannelsUsed();
237+
float gains[32];
239238

240-
masterLevelsChanged (dbToGain (dBL), dbToGain (dBR));
239+
for (int i = 0; i < numChans; ++i)
240+
gains[i] = dbToGain (masterLevelState->client.getAndClearAudioLevel (i).dB);
241+
242+
masterLevelsChanged ({ gains, (size_t) numChans });
241243
});
242244
}
243245

@@ -741,7 +743,7 @@ void ExternalControllerManager::automationModeChanged (bool isReading, bool isWr
741743
FOR_EACH_ACTIVE_DEVICE (automationModeChanged (isReading, isWriting));
742744
}
743745

744-
void ExternalControllerManager::channelLevelChanged (int channel, float l, float r)
746+
void ExternalControllerManager::channelLevelChanged (int channel, std::span<const float> levels)
745747
{
746748
CRASH_TRACER
747749
// This is an optimisation that avoids calling mapTrackNumToChannelNum if there are no enabled/active devices
@@ -758,13 +760,13 @@ void ExternalControllerManager::channelLevelChanged (int channel, float l, float
758760
return *channelNum;
759761
};
760762

761-
FOR_EACH_ACTIVE_DEVICE (channelLevelChanged (getChannelNum(), l, r));
763+
FOR_EACH_ACTIVE_DEVICE (channelLevelChanged (getChannelNum(), levels));
762764
}
763765

764-
void ExternalControllerManager::masterLevelsChanged (float leftLevel, float rightLevel)
766+
void ExternalControllerManager::masterLevelsChanged (std::span<const float> levels)
765767
{
766768
CRASH_TRACER
767-
FOR_EACH_ACTIVE_DEVICE (masterLevelsChanged (leftLevel, rightLevel));
769+
FOR_EACH_ACTIVE_DEVICE (masterLevelsChanged (levels));
768770
}
769771

770772
void ExternalControllerManager::timecodeChanged (int barsOrHours, int beatsOrMinutes, int ticksOrSeconds,

modules/tracktion_engine/control_surfaces/tracktion_ExternalControllerManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ class ExternalControllerManager : public juce::ChangeBroadcaster,
111111
void playStateChanged (bool isPlaying);
112112
void recordStateChanged (bool isRecording);
113113
void automationModeChanged (bool isReading, bool isWriting);
114-
void channelLevelChanged (int channel, float l, float r);
115-
void masterLevelsChanged (float leftLevel, float rightLevel);
114+
void channelLevelChanged (int channel, std::span<const float> levels);
115+
void masterLevelsChanged (std::span<const float> levels);
116116
void timecodeChanged (int barsOrHours, int beatsOrMinutes, int ticksOrSeconds,
117117
int millisecs, bool isBarsBeats, bool isFrames);
118118
void editPositionChanged (Edit*, TimePosition newCursorPosition);

modules/tracktion_engine/control_surfaces/types/tracktion_MackieC4.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -974,17 +974,21 @@ void MackieC4::clearAux (int channel, int)
974974
}
975975
}
976976

977-
void MackieC4::channelLevelChanged (int channel, float l, float r)
977+
void MackieC4::channelLevelChanged (int channel, std::span<const float> levels)
978978
{
979979
if (mode == MixerMode)
980980
{
981981
CRASH_TRACER
982982

983+
float peak = 0.0f;
984+
for (auto v : levels)
985+
peak = std::max (peak, v);
986+
983987
char midi[256];
984988
int midiLen = 0;
985989

986990
if (c4->C4LCDSetMeterLevelTxString (midi, &midiLen, channel * 2 + 1,
987-
juce::jlimit (0, 12, (juce::roundToInt (12.0f * std::max (l, r))))))
991+
juce::jlimit (0, 12, (juce::roundToInt (12.0f * peak)))))
988992
sendMidiCommandToController (0, midi, midiLen);
989993
}
990994
}
@@ -1003,7 +1007,7 @@ void MackieC4::loopOnOffChanged (bool) { updateButtonLights(); }
10031007
void MackieC4::slaveOnOffChanged (bool) { updateButtonLights(); }
10041008
void MackieC4::punchOnOffChanged (bool) { updateButtonLights(); }
10051009

1006-
void MackieC4::masterLevelsChanged (float, float) {}
1010+
void MackieC4::masterLevelsChanged (std::span<const float>) {}
10071011
void MackieC4::timecodeChanged (int, int, int, int, bool, bool) {}
10081012
void MackieC4::trackRecordEnabled (int, bool) {}
10091013

modules/tracktion_engine/control_surfaces/types/tracktion_MackieC4.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class MackieC4 : public ControlSurface,
3434
void faderBankChanged (int newStartChannelNumber, const juce::StringArray& trackNames) override;
3535
void moveAux (int channelNum, int auxNum, const char* bus, float newPos) override;
3636
void clearAux (int channel, int auxNum) override;
37-
void channelLevelChanged (int channel, float l, float r) override;
37+
void channelLevelChanged (int channel, std::span<const float> levels) override;
3838
void updateSoloAndMute (int channelNum, Track::MuteAndSoloLightState, bool isBright) override;
3939
void soloCountChanged (bool) override;
4040
void trackSelectionChanged (int channel, bool isSelected) override;
@@ -47,7 +47,7 @@ class MackieC4 : public ControlSurface,
4747
void loopOnOffChanged (bool isLoopOn) override;
4848
void slaveOnOffChanged (bool isSlaving) override;
4949
void punchOnOffChanged (bool isPunching) override;
50-
void masterLevelsChanged (float leftLevel, float rightLevel) override;
50+
void masterLevelsChanged (std::span<const float> levels) override;
5151
void timecodeChanged (int barsOrHours, int beatsOrMinutes, int ticksOrSeconds, int millisecs, bool isBarsBeats, bool isFrames) override;
5252
void trackRecordEnabled (int channel, bool isEnabled) override;
5353
bool canChangeSelectedPlugin() override;

modules/tracktion_engine/control_surfaces/types/tracktion_MackieMCU.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,14 +1284,18 @@ void MackieMCU::faderBankChanged (int newStartChannelNumber, const juce::StringA
12841284
}
12851285
}
12861286

1287-
void MackieMCU::channelLevelChanged (int channelNum_, float l , float r)
1287+
void MackieMCU::channelLevelChanged (int channelNum_, std::span<const float> levels)
12881288
{
12891289
int channel = channelNum_ % 8;
12901290
int dev = channelNum_ / 8;
12911291

12921292
if (assignmentMode == PanMode)
12931293
{
1294-
auto newValue = (uint8_t) juce::jlimit (0, 13, juce::roundToInt (13.0f * std::max (l, r)));
1294+
float peak = 0.0f;
1295+
for (auto v : levels)
1296+
peak = std::max (peak, v);
1297+
1298+
auto newValue = (uint8_t) juce::jlimit (0, 13, juce::roundToInt (13.0f * peak));
12951299

12961300
if (lastChannelLevels[channelNum_] != newValue)
12971301
{
@@ -1306,7 +1310,7 @@ void MackieMCU::channelLevelChanged (int channelNum_, float l , float r)
13061310
}
13071311
}
13081312

1309-
void MackieMCU::masterLevelsChanged (float, float)
1313+
void MackieMCU::masterLevelsChanged (std::span<const float>)
13101314
{
13111315
}
13121316

0 commit comments

Comments
 (0)