joshnishikawa / MIDIcontroller

A library for creating Teensy MIDI controllers with support for hold or latch buttons, potentiometers, encoders, capacitive sensors, Piezo transducers and other velocity sensitive inputs with aftertouch.
223 stars 19 forks source link

Malfunctioning usbMIDI.setHandleSystemExclusive(mySystemExclusive) on Teensy 2.0 returns wrong size! #21

Closed ruiseixasm closed 1 year ago

ruiseixasm commented 2 years ago

Hi,

I have the following function:

    void BoxMidi::mySystemExclusive (unsigned char *array, unsigned int size) {
        if (sysex_load == on && handlerSysEx != nullptr) {
            handlerSysEx(array, size);
        } else if (interfacesAreRouted()) {
            MIDI.sendSysEx(size, array);
            usbMIDI.sendSysEx(size, array);
        }
    }

And it is handled to the midi serial and usb functions this way:

        MIDI.setHandleSystemExclusive(mySystemExclusive);
        usbMIDI.setHandleSystemExclusive(mySystemExclusive);

However, when sending a file with 64 bytes on each line, while the serial midi returns the right size of the stream, 64, the usb version returns a different value, 60! Is this a bug or I'm using your library (usb) wrongly?

Thanks

Found now that for 48 bytes per stream instead of 64 it works fine.

joshnishikawa commented 2 years ago

I don't see anything in your code that relates to this library. I didn't write the usbMIDI library. The MIDIcontroller library just reads various types of inputs and sends NOTE or CC messages using the usbMIDI library.

ruiseixasm commented 2 years ago

Thanks for the answer. I thought it was your library because that's what is written here:

This page documents the MIDI message functions. However, for building a MIDI controller, this MIDIcontroller library provides easy-to-use functions to communicate MIDI messages for buttons, knobs, encoders and other commonly used hardware.

Do you know where I can find the usbMIDI library?

Thanks

joshnishikawa commented 2 years ago

Oh nice, I didn't realize that link was there. Well, it does say, "to communicate MIDI messages" but, currently this library only handles NOTE and CC. I'd like to implement support for multi-byte MIDI and sysex but I can't commit to a timeline. My dream is to someday receive a pull request.

Anyway yes, the usb_api.h file on my system is in Arduino/hardware/teensy/avr/cores/usb_midi and line 8 says this... #define USB_MIDI_SYSEX_MAX 60 // maximum sysex length we can receive You could try just changing that to... #define USB_MIDI_SYSEX_MAX 64 I have no idea if that will work but, if it does, I'm pretty sure it will stop working when you reinstall teenyduino. Just keep that in mind.

ruiseixasm commented 2 years ago

Ok, I see, but the code is embedded on the Teensy board in some inaccessible place. So there isn't any possibility of change it!

Anyway, why 60 and not 64 or other power of 2 number? Is there any particular reason for 60, it seems a little strange the choice of that number.

joshnishikawa commented 2 years ago

No, it's on my computer in the folder where Arduino is installed... C:\Arduino\hardware\teensy\avr\cores\usb_midi\usb_api.h Your Arduino folder might be installed somewhere else but that's where you'll find usb_api.h Take a look. Try changing it to 64 on line 8. It might just work.

ruiseixasm commented 1 year ago

Ok, I will check that, but I don't know for sure if the Teensy boards follow the same logic. I'm using VS Code with Platform IO.