| Author |
Message |
|
|
CongoZombie
|
Posted: Fri Jul 18, 2008 4:05 pm |
|
|
| Joined: Wed Jul 16, 2008 1:35 amPosts: 42 |
Ok, so after some problems with RtMIDI, I decided to start writing my own library.
Currently it is only for OS X and it only handles MIDI out. It currently only writes to a virtual midi device so I can connect my openFrameworks app directly to audio software. I hope to be updating it so it can take MIDI data into the software as well as looking at adding support for Windows and Linux (though if anyone more in the know about those platforms wants to lend a hand, please feel free).
I tried to keep the syntax simple:
Add a constructor:
Code: ofxMidiOut midiOut;
then the midi commands are as follows: Code: midiOut.sendNoteOn(channel, midiNoteNumber, velocity); midiOut.sendNoteOff(channel, midiNoteNumber, velocity); midiOut.sendControlChange(channel, controlNumber, controlValue);
Where:
channel = midi channel (1-16)
midiNoteNumber = midi note number (0-127)
velocity = velocity (0-127)
controlNumber = midi controller number (0-119)
controlValue = controller value (0-127)
NOTE: I haven't put in any error checking for values yet, so if make sure that you put correct values into the send functions.
Also, If I'm doing anything naughty and I should be deleting pointers or whatever, please let me know.
The latest Zip can be found here, courtesy of kylemcdonald http://rpi.edu/~mcdonk/random/ofxMidi.zip
If you are using OS X, you will need to add '-framework CoreMIDI' to your linker flags in order to use this library.
Last edited by CongoZombie on Thu Oct 23, 2008 1:14 am, edited 2 times in total.
|
|
Top
|
|
|
nikhan
|
Posted: Sun Jul 27, 2008 7:54 am |
|
|
| Joined: Tue Nov 13, 2007 10:34 amPosts: 14 |
thank you so much for this!
I am still a bit of a novice when it comes to C++, and had some trouble initially figuring this out. Just FYI to anyone who may be having trouble, be sure to include
-framework CoreMIDI
in your linker flags.
|
|
Top
|
|
|
CongoZombie
|
Posted: Sun Jul 27, 2008 1:03 pm |
|
|
| Joined: Wed Jul 16, 2008 1:35 amPosts: 42 |
Thanks nikhan, I totally forgot to mention that you needed to include the CoreMIDI framework! I shall try to add more to the library soon.
|
|
Top
|
|
|
zach
|
Posted: Sun Jul 27, 2008 1:29 pm |
|
|
Site AdminJoined: Mon Feb 05, 2007 9:31 pmPosts: 1807Location: brooklyn |
cool ! very nice to see this --
it'd be good to know what where the problems you had with rtMidi -- I'm curious -- can you elaborate?
take care!
zach
|
|
Top
|
|
|
CongoZombie
|
Posted: Sun Jul 27, 2008 1:43 pm |
|
|
| Joined: Wed Jul 16, 2008 1:35 amPosts: 42 |
I made a thread about my problems with rtMIDI here http://www.openframeworks.cc/forum/viewtopic.php?t=903
Basically I had a problem with some kind of conversion happening in one of the rtMIDI functions.
I wrote this version so that the syntax would be easier to use as you don't have to constuct the messages from bytes and can simply pass the parameters.
|
|
Top
|
|
|
zach
|
Posted: Sun Jul 27, 2008 1:48 pm |
|
|
Site AdminJoined: Mon Feb 05, 2007 9:31 pmPosts: 1807Location: brooklyn |
hmm - somehow I missed that thread --
just wanted to point out that there is some example code of using rtMidi here:
http://www.openframeworks.cc/files/ofMidiWork_2.zip
i've improved it recently in france for a project and will upload it (changed it to be more inline with the midi spec / usage) -- I didn't have alot of issues with rtMidi and this code does the construction of messages, etc.
take care!
zach
|
|
Top
|
|
|
kylemcdonald
|
Posted: Tue Sep 23, 2008 5:45 pm |
|
|
| Joined: Fri Jun 27, 2008 4:49 amPosts: 453Location: Brooklyn |
I had issues with rtMidi too, so I've added Windows support for Andy's ofxMidi addon.
ofxMidi.zip
It'd be great if someone on OSX could build the included Code Blocks project and make sure I didn't break anything.
Also, I don't think you can create an exact analogue to the OSX code in Windows. In OSX you create a "virtual port", but in Windows you just have to pick a port to use. So the default constructor on Windows just uses the highest numbered MIDI port.
|
|
Top
|
|
|
CongoZombie
|
Posted: Sat Sep 27, 2008 1:37 am |
|
|
| Joined: Wed Jul 16, 2008 1:35 amPosts: 42 |
Thanks Kyle,
I'm going to take a look at this soon and maybe try and add linux support as well as support for more MIDI commands. I'll take a look at the example and make an Xcode project for it too.
|
|
Top
|
|
|
kylemcdonald
|
Posted: Wed Oct 15, 2008 10:23 am |
|
|
| Joined: Fri Jun 27, 2008 4:49 amPosts: 453Location: Brooklyn |
I made a minor change and uploaded the new code here: http://rpi.edu/~mcdonk/of/ofxMidi.zip
I just really needed the following:
Code: unsigned char ofxMidiOut::getNoteNumber(char letter, int octave) { return (octave + 1) * 12 + ((int) letter) - 99; }
|
|
Top
|
|
|
theo
|
Posted: Tue Oct 21, 2008 11:44 pm |
|
|
| Site AdminJoined: Thu Mar 01, 2007 10:03 pmPosts: 916Location: Amsterdam |
wow - works great! just had a ton of fun with IAC and VSTs on mac.
one thing that might be worth adding to the instructions is that you need to link against the Core Midi Framework.
It wouldn't link until I dragged in Core Midi to the xcode project.
Cheers!
theo
|
|
Top
|
|
|
kylemcdonald
|
Posted: Wed Oct 22, 2008 1:56 am |
|
|
| Joined: Fri Jun 27, 2008 4:49 amPosts: 453Location: Brooklyn |
theo wrote: wow - works great! just had a ton of fun with IAC and VSTs on mac.
one thing that might be worth adding to the instructions is that you need to link against the Core Midi Framework.
It wouldn't link until I dragged in Core Midi to the xcode project.
Cheers! theo
I'm just surprised I didn't break anything when I augmented the code  Thanks for the tip Theo!
|
|
Top
|
|
|
CongoZombie
|
Posted: Wed Oct 22, 2008 10:20 pm |
|
|
| Joined: Wed Jul 16, 2008 1:35 amPosts: 42 |
theo wrote: wow - works great! just had a ton of fun with IAC and VSTs on mac.
one thing that might be worth adding to the instructions is that you need to link against the Core Midi Framework.
It wouldn't link until I dragged in Core Midi to the xcode project.
Cheers! theo
yeah, sorry- I forgot to mention that in the original post. I think I'll invest the time to take a look into the RTMIDI library to see how the midi in linux is handled. I'll install Ubuntu on Vmware Fusion now.
I'll update the original post to mention the need for the CoreMIDI framework too.
|
|
Top
|
|
|
theo
|
Posted: Thu Oct 30, 2008 3:08 am |
|
|
| Site AdminJoined: Thu Mar 01, 2007 10:03 pmPosts: 916Location: Amsterdam |
found a bug -
in the mac part of sendMidi - the code for putting the channel in is doing unnecessary bit-shifting
the result is you can't send midi except on channel 1
Code: data[0] = (Byte)( midiType | ((channel - 1) << 4) );
should be Code: data[0] = (Byte)( midiType | ((channel - 1)));
|
|
Top
|
|
|
CongoZombie
|
Posted: Thu Oct 30, 2008 3:22 am |
|
|
| Joined: Wed Jul 16, 2008 1:35 amPosts: 42 |
Thanks Theo,
I have no idea what I must have been thinking... what a weird thing to do!
I'm still working on linux. Unfortunately the APIs don't seem as simple as the Apple ones :/
|
|
Top
|
|
|
|