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
|
||||
|
|
|
@ -32,8 +32,9 @@ CXXFILES= ../NuEVI/menu.cpp \
|
|||
src/Print.cpp \
|
||||
src/simserial.cpp \
|
||||
src/simwire.cpp \
|
||||
src/simmidi.cpp \
|
||||
src/simusbmidi.cpp \
|
||||
src/filters.cpp \
|
||||
../NuEVI/midi.cpp \
|
||||
src/Adafruit_GFX_sim.cpp \
|
||||
src/Adafruit_SSD1306_sim.cpp \
|
||||
src/Adafruit_MPR121_sim.cpp \
|
||||
|
|
|
@ -67,9 +67,29 @@ public:
|
|||
void println(const char* str);
|
||||
void print(const char* str);
|
||||
void print(uint32_t intValue);
|
||||
void write(const uint8_t str);
|
||||
void flush();
|
||||
|
||||
};
|
||||
|
||||
class SimUsbMidi
|
||||
{
|
||||
public:
|
||||
void sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t cable=0);
|
||||
void sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t cable=0);
|
||||
void sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t cable=0);
|
||||
void sendProgramChange(uint8_t program, uint8_t channel, uint8_t cable=0);
|
||||
void sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t cable=0);
|
||||
void sendPitchBend(int value, uint8_t channel, uint8_t cable=0);
|
||||
void sendSysEx(uint16_t length, const uint8_t *data, bool hasTerm=false, uint8_t cable=0);
|
||||
bool read(uint8_t channel=0);
|
||||
};
|
||||
|
||||
extern SimSerial Serial;
|
||||
extern SimSerial Serial3; //Used for MIDI serial putput with default hardware
|
||||
extern SimUsbMidi usbMIDI;
|
||||
|
||||
//extern void putString(int row, int col, int color, const char* msg, const FONT_INFO fontInfo);
|
||||
|
||||
|
|
|
@ -26,7 +26,8 @@ extern Adafruit_SSD1306 display;
|
|||
extern Adafruit_MPR121 touchSensor;
|
||||
SimWire Wire;
|
||||
SimSerial Serial;
|
||||
|
||||
SimSerial Serial3; //Midi
|
||||
SimUsbMidi usbMIDI;
|
||||
|
||||
static const int scale = 3;
|
||||
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
#include <Arduino.h>
|
||||
#include "midi.h"
|
||||
|
||||
void midiSetChannel(byte __attribute__((unused)) channel){}
|
||||
|
||||
byte midiGetChannel(){ return 1; }
|
||||
|
||||
void midiSendProgramChange(int __attribute__((unused)) patch)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendControlChange(int __attribute__((unused)) ccParam, int __attribute__((unused)) ccValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendNoteOn(byte __attribute__((unused)) note, int __attribute__((unused)) velocity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendNoteOff(byte __attribute__((unused)) note)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendAfterTouch(byte __attribute__((unused)) value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiSendPitchBend(int __attribute__((unused)) value)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiDiscardInput()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiReset()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void midiPanic()
|
||||
{
|
||||
// turn all notes off
|
||||
}
|
||||
|
||||
void midiInitialize(byte __attribute__((unused)) channel)
|
||||
{
|
||||
|
||||
}
|
|
@ -41,3 +41,15 @@ void SimSerial::println(const char *str)
|
|||
printf( "[Serial::println] %s\n", str );
|
||||
}
|
||||
|
||||
//Used to send serial midi
|
||||
void SimSerial::write(const uint8_t __unused str)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void SimSerial::flush()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
|
60
simulation/src/simusbmidi.cpp
Normal file
60
simulation/src/simusbmidi.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
#include "Arduino.h"
|
||||
|
||||
/*************************************
|
||||
* Stub simulation of Teensy usbMidi
|
||||
*/
|
||||
|
||||
|
||||
void SimUsbMidi::sendNoteOff(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::noteOff] note %03d vel %03d ch %02d\n", note, velocity, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendNoteOn(uint8_t note, uint8_t velocity, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::noteOn] note %03d vel %03d ch %02d\n", note, velocity, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendPolyPressure(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::polyPressure] note %03d p %03d ch %02d\n", note, pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendAfterTouchPoly(uint8_t note, uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::afterTouchPoly] note %03d p %03d ch %02d\n", note, pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendControlChange(uint8_t control, uint8_t value, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::controlChange] cc %03d val %03d ch %02d\n", control, value, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendProgramChange(uint8_t program, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::programChange] prg %03d ch %02d\n", program, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendAfterTouch(uint8_t pressure, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::afterTouch] p %03d ch %02d\n", pressure, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendPitchBend(int value, uint8_t channel, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::pitchBend] pb %05d ch %02d\n", value, channel);
|
||||
}
|
||||
|
||||
void SimUsbMidi::sendSysEx(uint16_t length, const uint8_t __unused *data, bool __unused hasTerm, uint8_t __unused cable)
|
||||
{
|
||||
printf( "[usbMIDI::sysEx] len %d\n", length);
|
||||
}
|
||||
|
||||
bool SimUsbMidi::read(uint8_t __unused channel) {
|
||||
return false;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue