How to use midi with juce


#1

i’m a newbie in juce and c++ …
i try to use midi and it doesn’t work …

MidiOutput* midiOutput;
MidiMessage* midiMessage;
midiOutput=MidiOutput::openDevice(0);
midiMessage->noteOn(1,50,(UINT8) 127);
midiOutput->sendMessageNow(*midiMessage);

i know how to use midi with windows api but when i include <windows.h> i get a lot of compilation errors …

i also know it’s very basic questions but i search examples in the forum and i found nothing and there is no midi in the demo

many thanks for your answer !!!


#2

your main problem is with your midiMessage.

notice how you’re trying to use a pointer (MidiMessage*) before you’ve set it to anything. You don’t need to have a pointer … you could say

midiOutput->sendMessageNow (MidiMessage::noteOn(1,50,127));

The noteOn function is a static member of the MidiMessage class, which means you can call it from outside any particular instance. It will generate for you an object, which you can use as above, or have a line like…

MidiMessage m (MidiMessage::noteOn(1,50,127));

… to create one in scope to be used for multiple tasks. You’d then of course use

midiOutput->sendMessageNow (m);


#3

thanks haydxn !!! it works
i’m beginning … c++ and pointers are not easy … :wink:


#4