Nicer MIDI initialization

This commit is contained in:
John Stäck 2019-03-02 09:10:45 +01:00
parent c70858709e
commit a56cddf5e4
3 changed files with 15 additions and 10 deletions

View file

@ -325,7 +325,7 @@ int mainState; // The state of the main state machine
int initial_breath_value; // The breath value at the time we observed the transition int initial_breath_value; // The breath value at the time we observed the transition
byte activeMIDIchannel=1; // MIDI channel byte activeMIDIchannel; // MIDI channel
byte activePatch=0; byte activePatch=0;
byte doPatchUpdate=0; byte doPatchUpdate=0;
@ -625,8 +625,8 @@ void setup() {
doPatchUpdate=1; doPatchUpdate=1;
} }
Serial3.begin(31250); // start serial with midi baudrate 31250 activeMIDIchannel = MIDIchannel;
Serial3.flush(); midiInitialize(MIDIchannel);
//Serial.begin(9600); // debug //Serial.begin(9600); // debug

7
midi.h
View file

@ -6,8 +6,8 @@
#define USE_MIDI_SERIAL #define USE_MIDI_SERIAL
//Set / get current midi channel //Set / get current midi channel
void midiSetChannel(int channel); void midiSetChannel(byte channel);
int midiGetChannel(); byte midiGetChannel();
void midiSendProgramChange(int patch); void midiSendProgramChange(int patch);
void midiSendControlChange(int ccParam, int ccValue); void midiSendControlChange(int ccParam, int ccValue);
@ -20,7 +20,6 @@ void midiSendPitchBend(int value);
void midiReset(); // reset controllers void midiReset(); // reset controllers
void midiPanic(); // turn all notes off void midiPanic(); // turn all notes off
void dinMIDIsendPitchBend(int pb, byte ch); // Send din pitchbend void midiInitialize(byte channel=1);
void dinMIDIsendAfterTouch(byte value, byte ch); // Send din aftertouch
#endif #endif

View file

@ -1,14 +1,14 @@
#include "midi.h" #include "midi.h"
#include "hardware.h" #include "hardware.h"
int midiChannel = 1; int midiChannel;
void midiSetChannel(int channel) { void midiSetChannel(byte channel) {
midiChannel = constrain(channel, 1, 16); midiChannel = constrain(channel, 1, 16);
} }
int midiGetChannel() { byte midiGetChannel() {
return midiChannel; return midiChannel;
} }
@ -63,6 +63,12 @@ void midiPanic() { // all notes off
} }
} }
void midiInitialize(byte channel) {
MIDI_SERIAL.begin(31250); // start serial with midi baudrate 31250
MIDI_SERIAL.flush();
midiSetChannel(channel);
}
//Serial midi functions //Serial midi functions