Merge pull request #13 from Trasselfrisyr/midisim
Deeper MIDI simulation
This commit is contained in:
commit
095dacdf7f
8 changed files with 130 additions and 83 deletions
|
@ -1,10 +1,12 @@
|
|||
#include <Arduino.h>
|
||||
|
||||
#include "midi.h"
|
||||
#include "hardware.h"
|
||||
|
||||
int midiChannel;
|
||||
|
||||
|
||||
void midiSetChannel(byte channel) {
|
||||
void midiSetChannel(uint8_t channel) {
|
||||
midiChannel = constrain(channel, 1, 16);
|
||||
}
|
||||
|
||||
|
@ -13,35 +15,35 @@ byte midiGetChannel() {
|
|||
}
|
||||
|
||||
|
||||
void midiSendProgramChange(int patch) {
|
||||
void midiSendProgramChange(uint8_t patch) {
|
||||
usbMIDI.sendProgramChange(patch-1, midiChannel);
|
||||
dinMIDIsendProgramChange(patch-1, midiChannel-1);
|
||||
}
|
||||
|
||||
void midiSendControlChange(int ccParam, int ccValue) {
|
||||
void midiSendControlChange(uint8_t ccParam, uint8_t ccValue) {
|
||||
usbMIDI.sendControlChange(ccParam, ccValue, midiChannel);
|
||||
dinMIDIsendControlChange(ccParam, ccValue, midiChannel - 1);
|
||||
}
|
||||
|
||||
void midiSendNoteOn(byte note, int velocity) {
|
||||
void midiSendNoteOn(uint8_t note, uint8_t velocity) {
|
||||
usbMIDI.sendNoteOn(note, velocity, midiChannel);
|
||||
dinMIDIsendNoteOn(note, velocity, midiChannel - 1);
|
||||
}
|
||||
|
||||
void midiSendNoteOff(byte note) {
|
||||
void midiSendNoteOff(uint8_t note) {
|
||||
//Always send velocity 0 on note off to avoid confusing some synthesizers
|
||||
usbMIDI.sendNoteOn(note, 0, midiChannel);
|
||||
dinMIDIsendNoteOn(note, 0, midiChannel - 1);
|
||||
}
|
||||
|
||||
|
||||
void midiSendAfterTouch(byte value) {
|
||||
void midiSendAfterTouch(uint8_t value) {
|
||||
usbMIDI.sendAfterTouch(value, midiChannel);
|
||||
dinMIDIsendAfterTouch(value, midiChannel - 1);
|
||||
}
|
||||
|
||||
|
||||
void midiSendPitchBend(int value) {
|
||||
void midiSendPitchBend(uint16_t value) {
|
||||
#if defined(NEWTEENSYDUINO)
|
||||
usbMIDI.sendPitchBend(value-8192, midiChannel); // newer teensyduino "pitchBend-8192" older just "pitchBend"... strange thing to change
|
||||
#else
|
||||
|
@ -70,7 +72,7 @@ void midiPanic() { // all notes off
|
|||
}
|
||||
}
|
||||
|
||||
void midiInitialize(byte channel) {
|
||||
void midiInitialize(uint8_t channel) {
|
||||
MIDI_SERIAL.begin(31250); // start serial with midi baudrate 31250
|
||||
MIDI_SERIAL.flush();
|
||||
midiSetChannel(channel);
|
||||
|
@ -81,7 +83,7 @@ void midiInitialize(byte channel) {
|
|||
//Serial midi functions
|
||||
|
||||
// Send a three byte din midi message
|
||||
void midiSend3B(byte midistatus, byte data1, byte data2) {
|
||||
void midiSend3B(uint8_t midistatus, uint8_t data1, uint8_t data2) {
|
||||
MIDI_SERIAL.write(midistatus);
|
||||
MIDI_SERIAL.write(data1);
|
||||
MIDI_SERIAL.write(data2);
|
||||
|
@ -90,7 +92,7 @@ void midiSend3B(byte midistatus, byte data1, byte data2) {
|
|||
//**************************************************************
|
||||
|
||||
// Send a two byte din midi message
|
||||
void midiSend2B(byte midistatus, byte data) {
|
||||
void midiSend2B(uint8_t midistatus, uint8_t data) {
|
||||
MIDI_SERIAL.write(midistatus);
|
||||
MIDI_SERIAL.write(data);
|
||||
}
|
||||
|
@ -98,7 +100,7 @@ void midiSend2B(byte midistatus, byte data) {
|
|||
//**************************************************************
|
||||
|
||||
// Send din pitchbend
|
||||
void dinMIDIsendPitchBend(int pb, byte ch) {
|
||||
void dinMIDIsendPitchBend(uint16_t pb, uint8_t ch) {
|
||||
int pitchLSB = pb & 0x007F;
|
||||
int pitchMSB = (pb >>7) & 0x007F;
|
||||
midiSend3B((0xE0 | ch), pitchLSB, pitchMSB);
|
||||
|
@ -107,34 +109,34 @@ void dinMIDIsendPitchBend(int pb, byte ch) {
|
|||
//**************************************************************
|
||||
|
||||
// Send din control change
|
||||
void dinMIDIsendControlChange(byte ccNumber, int cc, byte ch) {
|
||||
void dinMIDIsendControlChange(uint8_t ccNumber, uint8_t cc, uint8_t ch) {
|
||||
midiSend3B((0xB0 | ch), ccNumber, cc);
|
||||
}
|
||||
|
||||
//**************************************************************
|
||||
|
||||
// Send din note on
|
||||
void dinMIDIsendNoteOn(byte note, int vel, byte ch) {
|
||||
void dinMIDIsendNoteOn(uint8_t note, uint8_t vel, uint8_t ch) {
|
||||
midiSend3B((0x90 | ch), note, vel);
|
||||
}
|
||||
|
||||
//**************************************************************
|
||||
|
||||
// Send din note off
|
||||
void dinMIDIsendNoteOff(byte note, int vel, byte ch) {
|
||||
void dinMIDIsendNoteOff(uint8_t note, uint8_t vel, uint8_t ch) {
|
||||
midiSend3B((0x80 | ch), note, vel);
|
||||
}
|
||||
|
||||
//**************************************************************
|
||||
|
||||
// Send din aftertouch
|
||||
void dinMIDIsendAfterTouch(byte value, byte ch) {
|
||||
void dinMIDIsendAfterTouch(uint8_t value, uint8_t ch) {
|
||||
midiSend2B((0xD0 | ch), value);
|
||||
}
|
||||
|
||||
//**************************************************************
|
||||
|
||||
// Send din program change
|
||||
void dinMIDIsendProgramChange(byte value, byte ch) {
|
||||
void dinMIDIsendProgramChange(uint8_t value, uint8_t ch) {
|
||||
midiSend2B((0xC0 | ch), value);
|
||||
}
|
25
NuEVI/midi.h
25
NuEVI/midi.h
|
@ -6,20 +6,27 @@
|
|||
#define USE_MIDI_SERIAL
|
||||
|
||||
//Set / get current midi channel
|
||||
void midiSetChannel(byte channel);
|
||||
byte midiGetChannel();
|
||||
void midiSetChannel(uint8_t channel);
|
||||
uint8_t midiGetChannel();
|
||||
|
||||
void midiSendProgramChange(int patch);
|
||||
void midiSendControlChange(int ccParam, int ccValue);
|
||||
void midiSendNoteOn(byte note, int velocity);
|
||||
void midiSendNoteOff(byte note);
|
||||
void midiSendAfterTouch(byte value);
|
||||
void midiSendPitchBend(int value);
|
||||
void midiSendProgramChange(uint8_t patch);
|
||||
void midiSendControlChange(uint8_t ccParam, uint8_t ccValue);
|
||||
void midiSendNoteOn(uint8_t note, uint8_t velocity);
|
||||
void midiSendNoteOff(uint8_t note);
|
||||
void midiSendAfterTouch(uint8_t value);
|
||||
void midiSendPitchBend(uint16_t value);
|
||||
|
||||
void midiDiscardInput(void);
|
||||
void midiReset(); // reset controllers
|
||||
void midiPanic(); // turn all notes off
|
||||
|
||||
void midiInitialize(byte channel=1);
|
||||
void midiInitialize(uint8_t channel=1);
|
||||
|
||||
void dinMIDIsendControlChange(uint8_t ccNumber, uint8_t cc, uint8_t ch);
|
||||
void dinMIDIsendNoteOn(uint8_t note, uint8_t vel, uint8_t ch);
|
||||
void dinMIDIsendNoteOff(uint8_t note, uint8_t vel, uint8_t ch);
|
||||
void dinMIDIsendAfterTouch(uint8_t value, uint8_t ch);
|
||||
void dinMIDIsendProgramChange(uint8_t value, uint8_t ch);
|
||||
void dinMIDIsendPitchBend(uint16_t pb, uint8_t ch);
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue