Skip to content

Commit 401d031

Browse files
committed
Selected track solo_mute lights and undo_redo
1 parent feaeabf commit 401d031

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

src/niMidi.cpp

+27-12
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,8 @@ const unsigned char CMD_CHANGE_SEL_TRACK_VOLUME = 0x64;
8181
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;
84-
const unsigned char CMD_SEL_TRACK_AVAILABLE = 0x68; // ToDo: ?
85-
const unsigned char CMD_SEL_TRACK_MUTED_BY_SOLO = 0x69; // ToDo: ?
84+
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)
8686

8787
const unsigned char TRTYPE_UNSPEC = 1;
8888
const unsigned char TRTYPE_MASTER = 6;
@@ -97,6 +97,7 @@ const bool HIDE_MUTED_BY_SOLO = false;
9797
static int g_trackInFocus = 0;
9898
static bool g_anySolo = false;
9999
static int g_soloStateBank[BANK_NUM_TRACKS] = { 0 };
100+
static bool g_muteStateBank[BANK_NUM_TRACKS] = { false };
100101

101102
signed char convertSignedMidiValue(unsigned char value) {
102103
// Convert a signed 7 bit MIDI value to a signed char.
@@ -154,6 +155,8 @@ class NiMidiSurface: public BaseSurface {
154155
NiMidiSurface(int inDev, int outDev)
155156
: BaseSurface(inDev, outDev) {
156157
this->_sendCc(CMD_HELLO, 0);
158+
this->_sendCc(CMD_UNDO, 1);
159+
this->_sendCc(CMD_REDO, 1);
157160
}
158161

159162
virtual ~NiMidiSurface() {
@@ -200,7 +203,7 @@ class NiMidiSurface: public BaseSurface {
200203
}
201204
}
202205

203-
// ToDo: add more button lights: AUTO, tbd: undo/redo, clear, quantize, tempo
206+
// ToDo: add more button lights: AUTO, clear, quantize, 4D encoder navigation (blue LEDs)
204207

205208
virtual void SetTrackListChange() override {
206209
// If tracklist changes update Mixer View and ensure sanity of track and bank focus
@@ -246,10 +249,19 @@ class NiMidiSurface: public BaseSurface {
246249
}
247250
// Let Keyboard know about changed track selection
248251
this->_sendSysex(CMD_TRACK_SELECTED, 1, numInBank);
249-
// Set KK Instance Focus
250252
g_trackInFocus = id;
251-
this->_sendSysex(CMD_SET_KK_INSTANCE, 0, 0,
252-
getKkInstanceName(track));
253+
if (g_trackInFocus != 0) {
254+
// Mark selected track as available and update Mute and Solo Button lights
255+
this->_sendSysex(CMD_SEL_TRACK_AVAILABLE, 1, 0);
256+
this->_sendSysex(CMD_TOGGLE_SEL_TRACK_MUTE, g_muteStateBank[numInBank] ? 1 : 0, 0);
257+
this->_sendSysex(CMD_TOGGLE_SEL_TRACK_SOLO, g_soloStateBank[numInBank], 0);
258+
}
259+
else {
260+
// Master track not available for Mute and Solo
261+
this->_sendSysex(CMD_SEL_TRACK_AVAILABLE, 0, 0);
262+
}
263+
// Set KK Instance Focus
264+
this->_sendSysex(CMD_SET_KK_INSTANCE, 0, 0, getKkInstanceName(track));
253265
}
254266
}
255267

@@ -278,10 +290,11 @@ class NiMidiSurface: public BaseSurface {
278290
virtual void SetSurfaceMute(MediaTrack* track, bool mute) override {
279291
int id = CSurf_TrackToID(track, false);
280292
if (id == g_trackInFocus) {
281-
this->_sendCc(CMD_TOGGLE_SEL_TRACK_MUTE, mute ? 1 : 0); // ToDo: does not work yet - why? Is an extra track_available required? Or instance? Or SysEx?
293+
this->_sendSysex(CMD_TOGGLE_SEL_TRACK_MUTE, mute ? 1 : 0, 0);
282294
}
283295
if ((id >= this->_bankStart) && (id <= this->_bankEnd)) {
284296
int numInBank = id % BANK_NUM_TRACKS;
297+
g_muteStateBank[numInBank] = mute;
285298
this->_sendSysex(CMD_TRACK_MUTED, mute ? 1 : 0, numInBank);
286299
}
287300
}
@@ -299,7 +312,7 @@ class NiMidiSurface: public BaseSurface {
299312
return;
300313
}
301314
if (id == g_trackInFocus) {
302-
this->_sendCc(CMD_TOGGLE_SEL_TRACK_SOLO, solo ? 1 : 0); // ToDo: Button light does not work yet - why? Is an extra track_available required? Or instance? Or SysEx?
315+
this->_sendSysex(CMD_TOGGLE_SEL_TRACK_SOLO, solo ? 1 : 0, 0);
303316
}
304317
if ((id >= this->_bankStart) && (id <= this->_bankEnd)) {
305318
int numInBank = id % BANK_NUM_TRACKS;
@@ -340,7 +353,6 @@ class NiMidiSurface: public BaseSurface {
340353
void _onMidiEvent(MIDI_event_t* event) override {
341354
if (event->midi_message[0] != MIDI_CC) {
342355
return;
343-
// ToDo: Analyze other incoming MIDI messages too, like Sysex, MCU etc
344356
}
345357
unsigned char& command = event->midi_message[1];
346358
unsigned char& value = event->midi_message[2];
@@ -413,6 +425,7 @@ class NiMidiSurface: public BaseSurface {
413425
// ToDo: Scrubbing very slow. Rather than just amplifying this value
414426
// have to evaluate incoming MIDI stream to allow for both fine as well
415427
// coarse scrubbing
428+
// Or move to next beat, bar etc
416429
CSurf_ScrubAmt(convertSignedMidiValue(value));
417430
break;
418431
case CMD_TRACK_SELECTED:
@@ -513,7 +526,7 @@ class NiMidiSurface: public BaseSurface {
513526
}
514527
// If no tracks are soloed then muted tracks shall show no peaks
515528
else {
516-
if (*(bool*)GetSetMediaTrackInfo(track, "B_MUTE", nullptr)) {
529+
if (g_muteStateBank[numInBank]) {
517530
peakBank[j] = 1;
518531
peakBank[j + 1] = 1;
519532
}
@@ -526,8 +539,8 @@ class NiMidiSurface: public BaseSurface {
526539
}
527540
}
528541
else {
529-
// Tracks muted by solo show peaks but they appear greyed out. Muted tracks that are NOT soloed shall show no peaks.
530-
if ((g_soloStateBank[numInBank] == 0) && (*(bool*)GetSetMediaTrackInfo(track, "B_MUTE", nullptr))) {
542+
// Muted tracks that are NOT soloed shall show no peaks. Tracks muted by solo show peaks but they appear greyed out.
543+
if ((g_soloStateBank[numInBank] == 0) && (g_muteStateBank[numInBank])) {
531544
peakBank[j] = 1;
532545
peakBank[j + 1] = 1;
533546
}
@@ -553,6 +566,7 @@ class NiMidiSurface: public BaseSurface {
553566
this->_bankEnd = this->_bankStart + BANK_NUM_TRACKS - 1; // avoid ambiguity: track counting always zero based
554567
int numTracks = CSurf_NumTracks(false);
555568
// Set bank select button lights
569+
// ToDo: Consider optimizing this piece of code
556570
int bankLights = 3; // left and right on
557571
if (numTracks < BANK_NUM_TRACKS) {
558572
bankLights = 0; // left and right off
@@ -613,6 +627,7 @@ class NiMidiSurface: public BaseSurface {
613627
int selected = *(int*)GetSetMediaTrackInfo(track, "I_SELECTED", nullptr);
614628
this->_sendSysex(CMD_TRACK_SELECTED, selected, numInBank);
615629
bool muted = *(bool*)GetSetMediaTrackInfo(track, "B_MUTE", nullptr);
630+
g_muteStateBank[numInBank] = muted;
616631
this->_sendSysex(CMD_TRACK_MUTED, muted ? 1 : 0, numInBank);
617632
double volume = *(double*)GetSetMediaTrackInfo(track, "D_VOL", nullptr);
618633
char volText[64];

0 commit comments

Comments
 (0)