usbmidi host on teensyduino 1.8.13 vs. 1.8.19

lokki

Well-known member
hi there,

i have some usb-midi host sketch that works on 1.8.13 but doesn't work on 1.8.19 (it compiles but there are a lot of hanging notes etc.)

the code runs on a teensy 3.6

which version of usb-host 3.6 was used for 1.8.13 and which vor 1.8.19?

maybe i can compare the two versions on GitHub and find the problem.


not saying there is a bug in the library, it might well be my code that is bugged, but only 1.8.19 exhibits problems.
 
Sorry, I know very little about MIDI and have not used it.

But looks like there has only been one change made to main usb_midi.c code between those two releases.

The one function changed from:
Code:
void usb_midi_flush_output(void)
{
	if (tx_noautoflush == 0 && tx_packet && tx_packet->index > 0) {
		tx_packet->len = tx_packet->index * 4;
		usb_tx(MIDI_TX_ENDPOINT, tx_packet);
		tx_packet = NULL;
	}

to:
Code:
void usb_midi_flush_output(void)
{
	if (tx_noautoflush == 0) {
		tx_noautoflush = 1;
		if (tx_packet && tx_packet->index > 0) {
			tx_packet->len = tx_packet->index * 4;
			usb_tx(MIDI_TX_ENDPOINT, tx_packet);
			tx_packet = NULL;
		}
		tx_noautoflush = 0;
	}
}
Nothing changed in the descriptor associated with midi.
As for low level usb, looks like one structure (bdt_t) had the volatile added to it

So as an experiment you might try changing that flush... function back and see if that makes a difference. If so probably someone like Paul will need to figure out
what is going on.
 
thanks for the input. but the file you described would be for regular usb-midi, right? i am talking about usb-host midi... and especially about sending (not so much receiving) midi via usb-host
 
Can you post your code or reduce it to a smaller sketch which reproduces the problem?
Which version(s) of Teensyduino are you using with 1.8.13 and 1.8.19? (Note that 1.8.13 and 1.8.19 are the Arduino IDE version numbers, not Teensyduino)

Pete
 
oops, sorry.

I don't see any changes in the midi.cpp file in USBHost_t36 between those two releases.
Not sure of other related things.
 
here is a very stripped down version of my sketch, basically it searches for one device on the hub and sends DIN-midi signals to one of the connected synths.

i can play notes on my DIN controller, but they all hang. it is as if noteOff values were not sent.

Code:
#pragma GCC optimize ("-O3")


#include <Arduino.h>

#include <MIDI.h>        // access to serial (5 pin DIN) MIDI
#include <USBHost_t36.h>


MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI1);


// Create the ports for USB devices plugged into Teensy's 2nd USB port (via hubs)
USBHost myusb;
USBHub hub1(myusb);
USBHub hub2(myusb);
USBHub hub3(myusb);
USBHub hub4(myusb);
//USBSerial userial(myusb);
MIDIDevice midi01(myusb);
MIDIDevice midi02(myusb);
MIDIDevice midi03(myusb);
MIDIDevice midi04(myusb);
MIDIDevice midi05(myusb);
MIDIDevice midi06(myusb);
MIDIDevice midi07(myusb);

MIDIDevice * midilist[7] = {
  &midi01, &midi02, &midi03, &midi04, &midi05, &midi06, &midi07,};



//usb host stuff serials of attached devices
int serialNumbers[7];
//specific devices are saved to be able to send/receive to specific devices regardless of order they are plugged in
int pulse2 = 7;
int blofeld = 7;
int keysaxo = 7;
int footpedal = 7;
int minitaur = 7;
int macmini = 7;
int preenfm = 7;
bool qunexus_sustain = 0;



//--------- Setup ----------------//
void setup() {

MIDI1.begin(MIDI_CHANNEL_OMNI);
MIDI1.turnThruOff();  

  




    
    
   
    myusb.begin();
     delay(1500);
for (int i=0; i<7; i++) {
  if (midilist[i]->manufacturer() != NULL && midilist[i]->serialNumber() != NULL) {
     Serial.println("-----------------------------------"); 
     Serial.print("Serial:"); 
     Serial.println((char*)midilist[i]->serialNumber());
     Serial.print("ProductID:"); 
     Serial.println(midilist[i]->idProduct());
     Serial.println("-----------------------------------"); 
     
    // if (!strcmp(midilist[i]->serialNumber(), 9)) { //Waldorf Pulse2
    if (midilist[i]->idProduct() == 22) {
      Serial.println("here is Pulse2");
      pulse2 = i;
     }

     if (midilist[i]->idProduct() == 82) {
      Serial.println("here is blofeld at edirol");
      blofeld = i;
     }

     if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"003600433435511733353932")) {//Axoloti for qunexus/vocoder serial
      Serial.println("here is axovocoder");
      keysaxo = i;
     }
 
if (midilist[i]->idProduct() == 22336) {//preenfm3 
      Serial.println("here is preenfm3");
      preenfm = i;
     }
     if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"EncoderFanel")) {//teensy 4.0 footcontroller
      Serial.println("here is the footcontroller");
      footpedal = i;
     }
if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"MTc537ef")) {//moog minitaur
      Serial.println("here is the minitaur");
      minitaur = i;
     }

if (!strcmp(reinterpret_cast<const char *>(midilist[i]->serialNumber()),"7795010")) {//mac mini via teensy lc
      Serial.println("here is the vital mac mini");
      macmini = i;
     }     

     /*if (!strcmp(midilist[i]->serialNumber(), "11390072173-1304284600")) { //Waldorf Blofeld Serial
      Serial.println("here is blofeld");
      blofeld = i;
     } */
     
  }
  delay(10);
  }
if (preenfm == 7)  preenfm = macmini;


   
  for (int i=0; i<7; i++) {
 if ((i != footpedal) && (i != pulse2) && (i != minitaur) && (i != keysaxo)) midilist[i]->sendProgramChange(0,1);
 if (i == pulse2) midilist[i]->sendProgramChange(0,6);
 if (i == minitaur) midilist[i]->sendProgramChange(0,8);
 if (i == keysaxo) midilist[i]->sendProgramChange(0,9);
 midilist[i]->send_now();
  }



        
}

//----------Main Loop---------------//
void loop() {

 
//------midi input from the qunexus keyboard-----------//
  if (MIDI1.read()) {
sendQunexus(MIDI1.getType(), MIDI1.getData1(), MIDI1.getData2(), MIDI1.getChannel() + 11);
  }
//---midi from the footpedal----//
myusb.Task();
midilist[footpedal]->read();

}

void sendQunexus(byte type, byte data1, byte data2, byte channel )
{
  if (channel > 12) {
    midilist[keysaxo]->send(type, data1, data2, channel);
    midilist[keysaxo]->send_now();
  } else {
     midilist[macmini]->send(type, data1, data2, channel);
    midilist[macmini]->send_now();
  }
}

this is on 1.8.19 Teensyduino 1.56

the same code works flawlessly on 1.8.13 Teensyduino 1.53
 
Just a (very long) shot from the hip: remove the #pragma and recompile on 1.8.19 Teensyduino 1.56 and try it. Then set the IDE to Tools|Optimize|Smallest Code and try again. Is there any difference?

Pete
 
thanks for the idea. unfortunately it does not change anything, even with #pragma removed and smallest code selected i get the same behaviour. but if memory serves correct i tried fastest code once with 1.53 and that also did not work correctly, so i stayed with faster...
 
Do you have any versions in between 1.8.13+TD 1.53 and 1.8.19+TD 1.56?
Can you try 1.8.15+TD 1.54 and/or 1.8.16+TD 1.55?

The write_packed function in USBHost_t36/midi.cpp changed after 1.8.13+TD 1.53 and trying the other releases might isolate what is causing the problem (if it is in the USBHost_t36 code). I'm still shooting wildly from the hip ;)

Pete
 
thanks for shooting again :)

i just tired with arduino 1.8.15 and teensyduino 1.54, the problem persists.

i hope this helps to narrow down the issue.
 
Just a thought … you’re apparently using element 7 of midilist[7], but this doesn’t exist, the elements are indexed 0 to 6.
 
yes and no...

this is a snippet from the larger project. as you can see in the setup routine, each of the connected devices are given an ID between 0 and 6, 7 is the initial value to make it easy to see, that a device has not been found or assigned. so in loop none of those variables can be set to 7, if all the devices are connected (which they have to be for my project)

i can double-check if keysaxo or footcontroller is set to 7 in loop but i highly doubt it. furthermore the issue is the same in the much larger project where i know that none of the devices is set to 7...
 
Can you send MIDI to a PC/MAC and monitor the received MIDI (e.g. with MIDI-OX)? I have used usbhost on a T3.6 to receive MIDI from a M-Audio keyboard and relay it to a PC and I don't have any trouble with it.

Pete
 
TD's underlying Midi library found in (Windows) C:\Program Files (x86)\Arduino\hardware\avr\teensy\libraries was updated to V5 post TD 1.53 which saw changes to the transport layer.

I encountered problems sending to DIN Midi although was a while ago so details are hazy, seem to recall replacing this lib with the one that shipped with TD 1.53 then had to pack up and enter the rabbithole of relocation..

Mentioning in case reverting to the earlier Midi lib changes anything for you.
 
Back
Top