Skip to content

Commit afb0f52

Browse files
committed
Selected track Solo, Mute, Muted by Solo lights fully implemented
1 parent 401d031 commit afb0f52

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

src/niMidi.cpp

+28-4
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const unsigned char CMD_CHANGE_SEL_TRACK_PAN = 0x65;
8282
const unsigned char CMD_TOGGLE_SEL_TRACK_MUTE = 0x66;
8383
const unsigned char CMD_TOGGLE_SEL_TRACK_SOLO = 0x67;
8484
const unsigned char CMD_SEL_TRACK_AVAILABLE = 0x68;
85-
const unsigned char CMD_SEL_TRACK_MUTED_BY_SOLO = 0x69; // ToDo: Consider to implement this too (i.e. if g_anySolo and selected track != solo)
85+
const unsigned char CMD_SEL_TRACK_MUTED_BY_SOLO = 0x69;
8686

8787
const unsigned char TRTYPE_UNSPEC = 1;
8888
const unsigned char TRTYPE_MASTER = 6;
@@ -232,16 +232,17 @@ class NiMidiSurface: public BaseSurface {
232232
// SetSurfaceSelected() is less economical because it will be called multiple times (also for unselecting tracks).
233233
// However, SetSurfaceSelected() is the more robust choice because of: https://forum.cockos.com/showpost.php?p=2138446&postcount=15
234234

235-
// Note: SetSurfaceSelected is also called on project tab change
235+
// Note: SetSurfaceSelected is also called on project tab change or when record arming. However, <selected> will only be true if a track selection has changed.
236236
this->_metronomeUpdate(); //check if metronome status has changed when switching project tabs
237+
// Track selection has changed:
237238
if (selected) {
238239
int id = CSurf_TrackToID(track, false);
239240
int numInBank = id % BANK_NUM_TRACKS;
240241
int oldBankStart = this->_bankStart;
241242
this->_bankStart = id - numInBank;
242243
if (this->_bankStart != oldBankStart) {
243244
// Update everything
244-
this->_allMixerUpdate();
245+
this->_allMixerUpdate(); // Note: this will also update the g_muteStateBank and g_soloStateBank caches
245246
}
246247
else {
247248
// Update track names
@@ -255,6 +256,12 @@ class NiMidiSurface: public BaseSurface {
255256
this->_sendSysex(CMD_SEL_TRACK_AVAILABLE, 1, 0);
256257
this->_sendSysex(CMD_TOGGLE_SEL_TRACK_MUTE, g_muteStateBank[numInBank] ? 1 : 0, 0);
257258
this->_sendSysex(CMD_TOGGLE_SEL_TRACK_SOLO, g_soloStateBank[numInBank], 0);
259+
if (g_anySolo) {
260+
this->_sendSysex(CMD_SEL_TRACK_MUTED_BY_SOLO, (g_soloStateBank[numInBank] == 0) ? 1 : 0, 0);
261+
}
262+
else {
263+
this->_sendSysex(CMD_SEL_TRACK_MUTED_BY_SOLO, 0, 0);
264+
}
258265
}
259266
else {
260267
// Master track not available for Mute and Solo
@@ -302,15 +309,32 @@ class NiMidiSurface: public BaseSurface {
302309
virtual void SetSurfaceSolo(MediaTrack* track, bool solo) override {
303310
// Note: Solo in Reaper can have different meanings (Solo In Place, Solo In Front and much more -> Reaper Preferences)
304311
int id = CSurf_TrackToID(track, false);
305-
// Ignore solo on master, id = 0 is only used as an "any track is soloed" indicator
312+
313+
// Ignore solo on master, id = 0 is only used as an "any track is soloed" change indicator
306314
if (id == 0) {
307315
// If g_anySolo state has changed update the tracks' muted by solo states within the current bank
308316
if (g_anySolo != solo) {
309317
g_anySolo = solo;
310318
this->_allMixerUpdate(); // Everything needs to be updated, not good enough to just update muted_by_solo states
311319
}
320+
// If any track is soloed the currently selected track will be muted by solo unless it is also soloed
321+
if (g_trackInFocus > 0) {
322+
if (g_anySolo) {
323+
MediaTrack* track = CSurf_TrackFromID(g_trackInFocus, false);
324+
if (!track) {
325+
return;
326+
}
327+
int soloState = *(int*)GetSetMediaTrackInfo(track, "I_SOLO", nullptr);
328+
this->_sendSysex(CMD_SEL_TRACK_MUTED_BY_SOLO, (soloState == 0) ? 1 : 0, 0);
329+
}
330+
else {
331+
this->_sendSysex(CMD_SEL_TRACK_MUTED_BY_SOLO, 0, 0);
332+
}
333+
}
312334
return;
313335
}
336+
337+
// Solo state has changed on individual tracks:
314338
if (id == g_trackInFocus) {
315339
this->_sendSysex(CMD_TOGGLE_SEL_TRACK_SOLO, solo ? 1 : 0, 0);
316340
}

0 commit comments

Comments
 (0)