Skip to content

Commit 185606c

Browse files
authored
Merge pull request #26 from brummbrum/4D_EncoderLights
4DEncoder Track Navigation LEDs
2 parents 963cf1d + a43f8cf commit 185606c

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/niMidi.cpp

+27-7
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
*/
1010

1111
// #define CALLBACK_DIAGNOSTICS
12-
// #define DEBUG_DIAGNOSTICS
13-
// #define BASIC_DIAGNOSTICS
12+
#define DEBUG_DIAGNOSTICS
13+
#define BASIC_DIAGNOSTICS
1414

1515
#include <string>
1616
#include <sstream>
@@ -229,9 +229,6 @@ class NiMidiSurface: public BaseSurface {
229229
this->_sendCc(CMD_LOOP, 0);
230230
}
231231
}
232-
233-
// ToDo: add button lights for 4D encoder navigation (blue LEDs)
234-
235232

236233
virtual void SetTrackListChange() override {
237234
#ifdef CALLBACK_DIAGNOSTICS
@@ -288,7 +285,19 @@ class NiMidiSurface: public BaseSurface {
288285
this->_bankStart = id - numInBank;
289286
if (this->_bankStart != oldBankStart) {
290287
// Update everything
291-
this->_allMixerUpdate(); // Note: this will also update the g_muteStateBank and g_soloStateBank caches
288+
this->_allMixerUpdate(); // Note: this will also update 4D track nav LEDs, g_muteStateBank and g_soloStateBank caches
289+
}
290+
else {
291+
// Update 4D Encoder track navigation LEDs
292+
int numTracks = CSurf_NumTracks(false);
293+
int trackNavLights = 3; // left and right on
294+
if (g_trackInFocus < 2) {
295+
trackNavLights &= 2; // left off
296+
}
297+
if (g_trackInFocus >= numTracks) {
298+
trackNavLights &= 1; // right off
299+
}
300+
this->_sendCc(CMD_NAV_TRACKS, trackNavLights);
292301
}
293302
if (g_trackInFocus != 0) {
294303
// Mark selected track as available and update Mute and Solo Button lights
@@ -556,6 +565,7 @@ class NiMidiSurface: public BaseSurface {
556565
this->_onBankSelect(convertSignedMidiValue(value));
557566
break;
558567
case CMD_NAV_CLIPS:
568+
// ToDo: Consider to also update the 4D encoder LEDs depending on marker presence and playhead position
559569
// Value is -1 or 1.
560570
Main_OnCommand(value == 1 ?
561571
40173 : // Markers: Go to next marker/project end
@@ -715,7 +725,7 @@ class NiMidiSurface: public BaseSurface {
715725
int numInBank = 0;
716726
this->_bankEnd = this->_bankStart + BANK_NUM_TRACKS - 1; // avoid ambiguity: track counting always zero based
717727
int numTracks = CSurf_NumTracks(false);
718-
// Set bank select button lights
728+
// Update bank select button lights
719729
// ToDo: Consider optimizing this piece of code
720730
int bankLights = 3; // left and right on
721731
if (numTracks < BANK_NUM_TRACKS) {
@@ -736,6 +746,16 @@ class NiMidiSurface: public BaseSurface {
736746
this->_sendSysex(CMD_TRACK_AVAIL, 0, i);
737747
}
738748
}
749+
// Update 4D Encoder track navigation LEDs
750+
int trackNavLights = 3; // left and right on
751+
if (g_trackInFocus < 2) {
752+
trackNavLights &= 2; // left off
753+
}
754+
if (g_trackInFocus >= numTracks) {
755+
trackNavLights &= 1; // right off
756+
}
757+
this->_sendCc(CMD_NAV_TRACKS, trackNavLights);
758+
// Update current bank
739759
for (int id = this->_bankStart; id <= this->_bankEnd; ++id, ++numInBank) {
740760
MediaTrack* track = CSurf_TrackFromID(id, false);
741761
if (!track) {

0 commit comments

Comments
 (0)