Hey guys, I’m sorry if this is the wrong place to post this and also if it’s a bit basic (I’m a complete novice with coding), but I’m struggling to find online any code for MIDI messages. I’m trying to get my application to play an audio sample whenever a MIDI key is struck but for that I need to know what the code for MIDI is so I can set it as an if statement. I believe there’s different numbers assigned for different keys (like 60 is middle C) so I imagine that has something to do with it. If it’s any help I’m coding in C++ using xCode on OS X (running the introjucer before hand so it accepts MIDI Input).
Here is a good page that presents the components of a midi message: http://www.midi.org/techspecs/midimessages.php .
A great starting point for concepts between MIDI and coding can be found here: https://docs.oracle.com/javase/tutorial/sound/overview-MIDI.html . It is for Java, but it gives good language agnostic concepts. The whole Java documentation for MIDI is quite good in my opinion.
If you want to play sounds depending on a key stroke, you should set up the Juce demo, and see how the "AudioSynthesiserDemo.cpp" file works.
Sorry about this but where can I download this "AudioSynthesiserDemo.cpp" file? I ran a google search and couldn't find it.
Also, I'm looking for some sort of source code of the whole reading MIDI messages so then I can copy it into the if statement with some changes (like changing which MIDI number it receives that corresponds to the key struck on the MIDI controller). Would the "AudioSynthesiserDemo.cpp" file cover this?
How would I implement the MidiMessage class in the code? Would it be something like "if MidiMessage = 60 then etc."? Being a complete novice I'm struggling to understand the class reference internet page.
As I told you, the "AudioSynthesiserDemo.cpp" file belongs to the source code of the Juce Demo application, you have this application when you download the whole Juce framework.
I do not have the file in front of me now so I cannot tell you if it contains exactly what you want, but yes, this file "plays" with midi messages, so it can be a good starting point.
Do not forget to check the classes API page for MidiMessage: https://www.juce.com/api/classMidiMessage.html. You should also check the classes MidiOutput and MidiBuffer, and see how these 3 classes are linked together. You can get very basic source code for playing a single midi sound in the forum thread I started: http://www.juce.com/forum/topic/midi-accuracy. It contains source code that is playing midi sounds (but not doing exactly what I want though...).
A MidiMessage is not only a number, so you cannot test "if midiMessage == 60". You should check the class page: https://www.juce.com/api/classMidiMessage.html. Here you can see a MidiMessage is composed of 3 bytes and a TimeStamp.
If your "60" code is the number of the note for the midiMessage (one of the 3 bytes), you should write something like "if midiMessage.getNoteNumber() == 60".