USB Composite library MIDI

Post here first, or if you can't find a relevant section!
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

USB Composite library MIDI

Post 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.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: USB Composite library MIDI

Post by stevestrong »

Move the line where you declare your midi instance before the USBMIDI class definition.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USB Composite library MIDI

Post 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.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USB Composite library MIDI

Post 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.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: USB Composite library MIDI

Post by stevestrong »

I see that you have a circular reference issue.
Have you tried G**gle to check for a solution?
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USB Composite library MIDI

Post 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.
stevestrong
Posts: 502
Joined: Fri Dec 27, 2019 4:53 pm
Answers: 8
Location: Munich, Germany
Contact:

Re: USB Composite library MIDI

Post by stevestrong »

It would maybe better to review your code, to remove the circular reference.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USB Composite library MIDI

Post by Kprellz »

I posted my code in the first post
Last edited by Kprellz on Thu Jan 30, 2020 8:27 am, edited 1 time in total.
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USB Composite library MIDI

Post 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();
}
Kprellz
Posts: 17
Joined: Fri Jan 17, 2020 11:33 pm

Re: USB Composite library MIDI

Post 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.
Post Reply

Return to “General discussion”