Page 1 of 2

USB Composite library MIDI

Posted: Mon Jan 27, 2020 10:14 am
by Kprellz
Hey all!
Had a question about working with the midi portion of the USB composite library. I'm trying to set up a piece of code that when a certain midi note is receive will spit out a different midi note here is my code:

Code: Select all

#include <USBComposite.h>


class myMidi : public USBMIDI {
 virtual void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity) {
  if((channel == 0) && ( note == 0x00) && (velocity == 0x00)){
    midi.sendNoteOn(0, 0x00, 0x7f);
  }
 }
 virtual void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity) {
   
  }
  
};

myMidi midi;
USBCompositeSerial CompositeSerial;

void setup() {
    USBComposite.setProductId(0x0030);
   
    midi.registerComponent();
    CompositeSerial.registerComponent();
    USBComposite.begin();
}

void loop() {
  midi.poll();
}
Now this code does not compile because when i do midi.sendNoteOn, "midi" hasnt been declared yet. basically i'm wondering if theres a way to make this work more along the lines of the regular arduino midi library. where i can send a receive midi information without having to poll and make a class with event handlers.

Re: USB Composite library MIDI

Posted: Mon Jan 27, 2020 12:17 pm
by stevestrong
Move the line where you declare your midi instance before the USBMIDI class definition.

Re: USB Composite library MIDI

Posted: Mon Jan 27, 2020 6:57 pm
by Kprellz
If I move myMidi midi; i get the error myMidi is not a type because the class myMidi isnt delcared yet, so thats my issues.

Re: USB Composite library MIDI

Posted: Tue Jan 28, 2020 1:55 am
by Kprellz
Is there a way i can use both Libraries? I know the midi libary by 47 works with the stm32, but then I want to use the USB composite library to make the stm32 midi class compliant. i've tried putting them together but i keep getting errors because they use most of the same keywords.

Re: USB Composite library MIDI

Posted: Tue Jan 28, 2020 8:33 am
by stevestrong
I see that you have a circular reference issue.
Have you tried G**gle to check for a solution?

Re: USB Composite library MIDI

Posted: Tue Jan 28, 2020 10:48 am
by Kprellz
Certainly been trying! at this point i'm either thinking of bailing on the STM32 or trying to use serial read and build my own way of doing midi input. i've been trying to go through the old stm32duino site manually, i've seen a couple references to this issue but no proper solutions. sucks i cant use the search feature on the old site.

Re: USB Composite library MIDI

Posted: Tue Jan 28, 2020 2:54 pm
by stevestrong
It would maybe better to review your code, to remove the circular reference.

Re: USB Composite library MIDI

Posted: Tue Jan 28, 2020 5:10 pm
by Kprellz
I posted my code in the first post

Re: USB Composite library MIDI

Posted: Thu Jan 30, 2020 7:56 am
by Kprellz

Code: Select all

#include <USBComposite.h>


class myMidi : public USBMIDI {
 virtual void handleNoteOff(unsigned int channel, unsigned int note, unsigned int velocity) {
  midi.sendNoteOn(0x00, 0x00, 0x00);
 }
 virtual void handleNoteOn(unsigned int channel, unsigned int note, unsigned int velocity) {
  
  }
  
};

myMidi midi;
USBCompositeSerial CompositeSerial;

void setup() {
    USBComposite.setProductId(0x0030);
   
    midi.registerComponent();
    CompositeSerial.registerComponent();
    USBComposite.begin();
}

void loop() {
  midi.poll();
}

Re: USB Composite library MIDI

Posted: Sat Feb 01, 2020 1:27 am
by Kprellz
I ended up figuring this out for anyone else who may be having issues rather than midi::sendNoteOn you need to use USBMIDI:: in the my midi class, then after myMidi midi; is declared you can use the regular midi:: operator.