Author Message

<  extend  ~  midi input

PostPosted: Sun Jun 22, 2008 6:24 pm
User avatarJoined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK
Hi all, I want to control some of the variables in my app with a midi controller and was wondering what the best option is? I almost considered writing a little app in processing to map incoming midi CC to OSC, but I was hoping there's a better way! I read somewhere that there was the beginnings of a midi addon, though output only - was wondering what the latest situation is?

Cheers,


Offline Profile
PostPosted: Mon Sep 22, 2008 4:33 pm
Site AdminJoined: Wed Apr 11, 2007 1:02 amPosts: 1192Location: barcelona
Hi

I've used sometimes a processing app that generates osc messages from midi input but it's a little ineficient. I needed something like that for an app i'm working in so i've made an ofxMidiInput.

It uses rtMidi, I'm only using it to receive values from one of those midi usb tables with knobs and sliders, so perhaps the way it's programmed is not the best for real midi uses.

It's based on poco events, you just need to extend ofxMidiListener in the class you want to receive the event and overwrite the method newMessage. I've seen in other midi input libraries, like the one in processing that it generates diferent types of messages like noteon, noteoff, controllerin... but with rtmidi I only receive the id the value and the number of milliseconds since the last message.

http://65.111.166.199/openframeworks/ofxMidiIn.zip


EDIT:

to use this in the diferent platforms some compiler flags are needed:

linux:

-D __LINUX_ALSASEQ__

or just add at the begining of rtMidi.h:

#define __LINUX_ALSASEQ__


mac:

-D __MACOSX_CORE__ -framework CoreMidi -framework CoreAudio -framework CoreFoundation

although CoreAudio framework should be already there


windows:

-D __WINDOWS_MM__ -lwinmm -llib -lmultithreaded

haven't tested in windows but from the rtMidi page should be something like that


Last edited by arturo on Thu Sep 25, 2008 10:03 am, edited 1 time in total.

Offline Profile
PostPosted: Mon Sep 22, 2008 8:45 pm
User avatarJoined: Mon May 14, 2007 10:57 amPosts: 720Location: Melbourne, Australia
Wow, great work arturo.
I haven't installed poco yet so I can't yet try it. But it sounds like you have it all there.

Quote:
like the one in processing that it generates diferent types of messages like noteon, noteoff, controllerin... but with rtmidi I only receive the id the value and the number of milliseconds since the last message.


I'm guessing the id represents the type of midi message, i.e.
Note Off, Note On, AfterTouch, Control Change, Program Change etc

and the value is just the corresponding value between 0-127.

Pitch wheel messages have a higher resolution, so they might not be detected properly. Otherwise it looks like it should work with all other messages.



_________________
Pierre Proske - www.digitalstar.net
Offline Profile
PostPosted: Tue Sep 23, 2008 10:53 am
Site AdminJoined: Wed Apr 11, 2007 1:02 amPosts: 1192Location: barcelona
Well, the id is just the number of the control that it's being activated. I think the type of event has something to do with the timestamp and the values that are being generated, but don't know how it works.

I also receive another value that might be the type of message, but it's always the same: 176 for buttons and sliders, and the java library actually generates diferent messages for those...


Offline Profile
PostPosted: Tue Sep 23, 2008 10:57 am
User avatarJoined: Tue May 27, 2008 10:03 amPosts: 691Location: London, UK
Hey arturo, thanks for that will hava look. I ended up using Quartz Composer to map the midi to OSC, not the most efficient but quickest to implement. will check out your addon though cos I use it a lot..


Offline Profile
PostPosted: Wed Oct 22, 2008 9:12 am
Joined: Wed Aug 22, 2007 1:02 pmPosts: 3Location: Amsterdam, NL
Thanks for creating this wonderful MIDI input addon, very useful for a project I'm working on at the moment. Currently, I'm also having QC mapping midi to OSC to use midi information in Open Frameworks, though I would really go for direct input in OF.

Unfortunately, I don't get Poco added to my project in XCode, which is needed for your addon. Whenever I add Poco libs to a project I get this waterfall of errors telling me that '::memcpy' has not been declared and 99 similar messages for 'memmove', 'strcpy', etc. etc.

I have the feeling I'm doing something wrong in my build parameters, could anyone post a working xCode project for this addon?

-> EDIT: Great I found this nice threat on poco which solved my problem: http://www.openframeworks.cc/forum/view ... =2371#2371, sorry for being too fast on my question



_________________
Studio Sophisti Interactive Product Design
Amsterdam, The Netherlands
www.studiosophisti.nl
Offline Profile
PostPosted: Sun Nov 23, 2008 3:21 pm
Joined: Fri Sep 26, 2008 3:55 pmPosts: 34
Thanks for this - exactly what I needed!

I added:

ofxMidiIn.cpp

Code:
   
      eventArgs.msgType=(int)message->at(0);


ofxMidiEvents.h

Code:
protected:

   virtual void newMessage(int port, int msgType, int id, int value, double timestamp){};

public:

   void newMessage(const void* sender, ofxMidiEventArgs& eventArgs){
      ofxMidiEventArgs& midiArgs = (ofxMidiEventArgs&)eventArgs;
      newMessage( ((ofxMidiIn*)sender)->getPort(), midiArgs.msgType, midiArgs.id, midiArgs.value, midiArgs.timestamp);
   }

};


to to give me the midi data types (as integers):
176 Control Change
144 Note On
128 Note Off
224 Pitchbend
240 Sysex Start
247 Sysex End

No luck getting a 14bit number for pitchbend, but maybe this is a problem with rtMidi?


Offline Profile
PostPosted: Mon Nov 24, 2008 7:44 pm
Site AdminJoined: Wed Apr 11, 2007 1:02 amPosts: 1192Location: barcelona
perhaps you already tried this, but in ofxMidiIn.cpp in the newMessage method theres:

Code:
if(nBytes == 3){...


I used that as all the messages the controller I was using had 3 bytes, but surely changing it will work with other types of messages. Please post the changes if you manage to do it so I can add it to the addon.


Offline Profile
PostPosted: Tue Nov 25, 2008 1:15 pm
Joined: Fri Mar 02, 2007 9:38 amPosts: 74Location: stockholm
Wow arthuro, we think alike. I just wrote a Midi class with Poco based events, with the exactly the same class names as you used... I like your style ;) I guess it's because i based it on the ofxHttp addon you & chris wrote


Offline Profile
PostPosted: Wed Nov 26, 2008 6:00 pm
Site AdminJoined: Wed Apr 11, 2007 1:02 amPosts: 1192Location: barcelona
:) Yes, the httpUtils, mailUtils and this one have really similar structure...

Did you find anything about other kind of messages? I only programmed this with a usb table with some knobs I had by then, but haven't tried with other devices.


Offline Profile
PostPosted: Wed Nov 26, 2008 6:36 pm
Joined: Fri Mar 02, 2007 9:38 amPosts: 74Location: stockholm
I only used it with a Maudio Trigger Finger, also USB. I thought (and still think) that all midi messages where (program, status, value). Then i just use another class to decode the midi events into values connected to defines representing the different keys, knobs and sliders on the Trigger Finger.


Offline Profile
PostPosted: Fri Mar 27, 2009 10:34 am
Joined: Fri Sep 26, 2008 3:55 pmPosts: 34
Hi there

Has anyone had any luck getting this to work in CodeBlocks on Windows?

I can't seem to set the right linker flags,a s I keep getting a whole slew of:


Code:
undefined reference to 'vtable for RtMidiIn'
undefined reference to....
etc



Some googling around tells me that this is because I don't have the right compile flags set, but am having trouble figuring out the correct ones.

Have tried linking to the libwinmm.a library - no luck...
Have tried using the compile flags above... -lmultithreaded leads to the compiler balking as it can't find this...

Any ideas?


Offline Profile
PostPosted: Tue May 19, 2009 5:35 pm
Site AdminJoined: Fri Mar 02, 2007 9:06 amPosts: 444Location: London
Hi (arturo)

I'm having a little trouble building.

My windows Codeblocks (0.06) project has these search directories...

"..\..\..\addons\ofxMidi\src"
"..\..\..\addons\ofxMidi\events"
"..\..\..\addons\ofxMidi\libs"

and these files are added
..\..\..\addons\ofxMidi\events\ofxMidiEvents.h
..\..\..\addons\ofxMidi\libs\RtMidi.cpp
..\..\..\addons\ofxMidi\libs\RtMidi.h
..\..\..\addons\ofxMidi\src\ofxMidiIn.cpp
..\..\..\addons\ofxMidi\src\ofxMidiIn.h

RtMidi.cpp is kicking up a load of errors, starting with

#include <pthread.h>
"No such file or directory"

What am I missing?

Thanks



_________________
http://www.chrisoshea.org
Offline Profile
PostPosted: Tue May 19, 2009 6:29 pm
Site AdminJoined: Wed Apr 11, 2007 1:02 amPosts: 1192Location: barcelona
hi chris

in RtMidi.h line 43:

#define __LINUX_ALSASEQ__

for windows should be:

#define __WINDOWS_MM__

and for mac:

#define __MACOSX_CORE__


Offline Profile
PostPosted: Thu May 21, 2009 4:18 pm
Site AdminJoined: Fri Mar 02, 2007 9:06 amPosts: 444Location: London
thanks art.

ive done that. now in ofxMidiEvents.h

for:
class ofxMidiEventArgs: public ofEventArgs{

it says build error:
expected class-name before '{' token

Thanks



_________________
http://www.chrisoshea.org
Offline Profile

Display posts from previous:  Sort by:

All times are UTC
Page 1 of 2
26 posts
Go to page 1, 2  Next
Users browsing this forum: Yahoo [Bot] and 2 guests
Search for:
Post new topic  Reply to topic
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum
cron