Skip to content

Commit 6e50dd7

Browse files
authored
Merge pull request #64 from anarkiwi/transnmi
only send nmi on ctrl message.
2 parents 0763d6b + a1381d6 commit 6e50dd7

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

vessel.ino

+17-12
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,16 @@ void inline blink() {
112112
#else
113113
#define blink()
114114
#endif
115-
115+
#define NMI_WRAP(x) \
116+
{ \
117+
if (vesselConfig.nmiEnabled) { \
118+
flagPin.write(HIGH); \
119+
x; \
120+
flagPin.write(LOW); \
121+
} else { \
122+
x; \
123+
} \
124+
}
116125
class FakeSerial {
117126
public:
118127
void begin(int BaudRate __attribute__((unused))) {}
@@ -122,6 +131,13 @@ public:
122131
outBuf[vesselConfig.outBufReadPtr++] = i;
123132
++vesselConfig.pendingOut;
124133
}
134+
inline __attribute__((always_inline)) void ctrl_write(byte i) {
135+
write(i);
136+
// send NMI on control message or sysex stop.
137+
if ((i | 0x80) && (i != midi::MidiType::SystemExclusiveStart)) {
138+
NMI_WRAP(blink());
139+
}
140+
}
125141
inline __attribute__((always_inline)) unsigned available() { return n; }
126142

127143
private:
@@ -142,16 +158,6 @@ struct VesselSettings : public midi::DefaultSettings {
142158

143159
MIDI_CREATE_CUSTOM_INSTANCE(FakeSerial, fs, MIDI, VesselSettings);
144160

145-
#define NMI_WRAP(x) \
146-
{ \
147-
if (vesselConfig.nmiEnabled) { \
148-
flagPin.write(HIGH); \
149-
x; \
150-
flagPin.write(LOW); \
151-
} else { \
152-
x; \
153-
} \
154-
}
155161
#define NMI_CMD_WRAP(x) \
156162
{ \
157163
if (!vesselConfig.nmiStatusOnlyEnabled) { \
@@ -285,7 +291,6 @@ inline bool transparentDrainOutBuf() {
285291
return true;
286292
}
287293
if (transparentUsbMidiRx()) {
288-
NMI_WRAP(blink());
289294
return true;
290295
}
291296
return false;

vesselusbmidi.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ midiEventPacket_t mPacket;
6262
return packets; \
6363
}
6464

65-
USBMIDIRX(transparentUsbMidiRx, PUSHBACK1(fs.write), PUSHBACK2(fs.write),
66-
PUSHBACK3(fs.write));
65+
USBMIDIRX(transparentUsbMidiRx, PUSHBACK1(fs.ctrl_write), PUSHBACK2(fs.ctrl_write),
66+
PUSHBACK3(fs.ctrl_write));
6767
USBMIDIRX(UsbMidiRx, PUSHBACK1(fs.qread), PUSHBACK2(fs.qread),
6868
PUSHBACK3(fs.qread));

0 commit comments

Comments
 (0)