Hello all,
I needed a converter serial midi to usb, and was wondering how to pass thru raw data from usb to serial ( and vice versa ) without needing to use the type specific usb_midi.h using a teensy 3.2
> in effect without having to write callbacks for every midi type.
I was specifically looking for a raw function in usb_midi.h without needing to dissect the midi stream as the usb_midi_read function does.
Is it a requirement for usb to send data packed ? > in this case the complete midi command eg. noteon note velocity as a single data packet ?
or more precise can I ( as long as I don't merge multiple streams ) treat midi as a stateless protocol, and make the teensy send 1 byte packets to it's usb port ?
> every byte that enters it's UART get passed to the usb port and vice versa ( I know it's inefficient, but makes a very small program )
I'd really appreciate it if someone finds the time to tell me how to change this to a working example > using the proper usb-midi port instead of the COM that I'm using now.
and without using libraries.
sample code
In the end I wrote it with callbacks. As I needed to merge streams.
In usb_midi.h I found a possible bug that prevents the sendRealTime function to pass on any other command but F0 ( no F1 - FF > no start / stop / clock / continue / AS / Sytemreset)
I'm not sure if I'm missing a flag so I won't post it as a bug.
fix:
-- uint32_t data = ( (type & 0xFF) | ((type << 8) & 0xFF00) );
++ uint32_t data = ( (0x0F) | ((type << 8) & 0xFF00) );
see > hardware\teensy\avr\cores\usb_midi\usb_api.cpp line 278
I have a profound knowledge of midi, don't go easy on me > Have been programming (8051) midi controllers in ASM for years, but very new to working with c and arduino's so forgive my ignorance.
thanks
djamu
I needed a converter serial midi to usb, and was wondering how to pass thru raw data from usb to serial ( and vice versa ) without needing to use the type specific usb_midi.h using a teensy 3.2
> in effect without having to write callbacks for every midi type.
I was specifically looking for a raw function in usb_midi.h without needing to dissect the midi stream as the usb_midi_read function does.
Is it a requirement for usb to send data packed ? > in this case the complete midi command eg. noteon note velocity as a single data packet ?
or more precise can I ( as long as I don't merge multiple streams ) treat midi as a stateless protocol, and make the teensy send 1 byte packets to it's usb port ?
> every byte that enters it's UART get passed to the usb port and vice versa ( I know it's inefficient, but makes a very small program )
I'd really appreciate it if someone finds the time to tell me how to change this to a working example > using the proper usb-midi port instead of the COM that I'm using now.
and without using libraries.
sample code
Code:
//
// raw serial midi to usb / usb to midi for use with DAW
// test, not to be used for production > merging is flawed, see comment on line 32
//
#define ledPin 13
//#define HWSERIAL1 Serial1
//#define HWSERIAL2 Serial2
//#define HWSERIAL3 Serial3
IntervalTimer blink_led_timer;
unsigned long blinktimer = 500000; //0.5 sec
void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(115200);
Serial1.begin(31250);
// Serial2.begin(31250);
// Serial3.begin(31250);
// Serial.println("MIDI Input Test");
blink_led_timer.begin(blink_led, blinktimer);
blink_led_timer.priority(254);
}
void loop() {
int incomingByte;
if (Serial1.available() > 0) { // UART to USB
incomingByte = Serial1.read();
// Serial.print(incomingByte, BYTE);
Serial.write(incomingByte); // usb out
Serial1.write(incomingByte); // midi thru > comment out to disable
// mind that merging multiple inputs this way is incorrect, midi isn't necessarily stateless
// series of notes may be send as "NoteOn Note Velocity, Note Velocity, Note Velocity etc ... " as long as command stays the same
// simply merging inputs can break this.
//
}
if (Serial.available() > 0) { // USB to UART
incomingByte = Serial.read();
// Serial1.print(incomingByte, BYTE);
Serial1.write(incomingByte);
}
}
void blink_led() {
digitalWriteFast(ledPin, !(digitalReadFast(ledPin))); // blinkled
}
In the end I wrote it with callbacks. As I needed to merge streams.
In usb_midi.h I found a possible bug that prevents the sendRealTime function to pass on any other command but F0 ( no F1 - FF > no start / stop / clock / continue / AS / Sytemreset)
I'm not sure if I'm missing a flag so I won't post it as a bug.
fix:
-- uint32_t data = ( (type & 0xFF) | ((type << 8) & 0xFF00) );
++ uint32_t data = ( (0x0F) | ((type << 8) & 0xFF00) );
see > hardware\teensy\avr\cores\usb_midi\usb_api.cpp line 278
I have a profound knowledge of midi, don't go easy on me > Have been programming (8051) midi controllers in ASM for years, but very new to working with c and arduino's so forgive my ignorance.
thanks
djamu
Last edited: