We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Pages: 1 2 
RWMidi MIDI Library (Read 14884 times)
RWMidi MIDI Library
Sep 10th, 2008, 8:29am
 
Hi,

I developed a small MIDI library for processing, mostly because I need to receive and send SYSEX messages and had trouble doing this with promidi. It works under Linux, MacOSX and Windows. Here is a small blog post I wrote about it: http://ruinwesen.com/blog?id=95 , here is the library itself: http://ruinwesen.com/support-files/rwmidi.zip and here is the documentation: http://ruinwesen.com/support-files/rwmidi/documentation/RWMidi.html .

This is a small example sketch:

import rwmidi.*;

MidiInput input;
MidiOutput output;

void setup() {
 input = RWMidi.getInputDevices()[0].createInput(this);
 output = RWMidi.getOutputDevices()[0].createOutput();
}

void noteOnReceived(Note note) {
 println("note on " + note.getPitch());
}

void sysexReceived(rwmidi.SysexMessage msg) {
 println("sysex " + msg);
}

void mousePressed() {
 int ret =    output.sendNoteOn(0, 3, 3);
 ret = output.sendSysex(new byte[] {(byte)0xF0, 1, 2, 3, 4, (byte)0xF7});
}

void draw() {
}

Hope you enjoy!
Re: RWMidi MIDI Library
Reply #1 - Sep 24th, 2008, 10:05pm
 
Awesome. im going to give this a try tonight.
Re: RWMidi MIDI Library
Reply #2 - Sep 24th, 2008, 10:28pm
 
great allows me to send NoteONs and NoteOffs manually.

proMIDI requires that you precompute a duration for each note but when doing stuff live you never know how long the note will be held.

I can now contine some of my old projects that reached a dead end because of this reason.

Thanks a lot.
Re: RWMidi MIDI Library
Reply #3 - Sep 27th, 2008, 4:26pm
 
thx cortan!

I uploaded a screencast showing how to build a game of life sequencer with rwmidi and processing:

http://ruinwesen.com/blog#post-133

and the sourcecode is at: http://ruinwesen.com/support

Cheers, manuel
Re: RWMidi MIDI Library
Reply #4 - Sep 30th, 2008, 9:24pm
 
Thanks Wesen, just checked it out.  Very cool, and fun tutorial. Sort of Along similar lines as my current project.

Im doing pitch detection in polyphonic sound source and then sending the detected pitches to MIDI out and recording them in Reason 4.0.

Sort of like a wav to MIDI converter in many ways.

http://www.vimeo.com/1852199

I added your vimeo contact.

Cheers.

Re: RWMidi MIDI Library
Reply #5 - Oct 18th, 2008, 11:59pm
 
I'm really enjoying this library - thanks so much for it.  Here are a couple more examples using it.

This first one is an implementation of my "Whitney Music Box" (http://www.coverpop.com/whitney/) that uses MIDI.

http://www.coverpop.com/sfiles/whitney_music.zip

The second one is another generative music experiment, this time using the physics of a bunch of balls in a spinning cylinder.  The balls make noises when they collide against each other or the cylinder.  Large balls make lower pitches.  Harder collisions have higher note velocities.

This example also supports MIDI input, if you turn it on in the code - I'm using the XYZ knobs on my Alesis micron to control it.  You can use it as an example of how to employ MIDI controllers.

The default settings, however, use the mouse.

http://www.coverpop.com/sfiles/verlet_music.zip

Interestingly, you can run both at the same time, in Processing, and get an interesting combination of order and chaos.

- Jim Bumgardner (KrazyDad)
Re: RWMidi MIDI Library
Reply #6 - Nov 5th, 2008, 1:12am
 
Hello wesen,
Loving the rwmidi lib but I'm having trouble with using it with OPENGL.

I've reported a problem using the promidi lib when trying to feed midi events from logic pro into a processing class running as an applet built with eclipse, when I specify OPENGL in the size method of the setup:
http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1225761545

Thinking the problem might be proMidi, I switched to rwmidi, and have written this class:

Code:


package Ching;
import processing.core.*;
import processing.opengl.*;
import rwmidi.*;

public class Ting extends PApplet {
private static final long serialVersionUID = 1L;

MidiInput iac00;

public void setup()
{
size(1920, 1080, OPENGL);
smooth();
background(70);

// Show available MIDI output devices in console
MidiInputDevice devices[] = RWMidi.getInputDevices();
for (int i = 0; i < devices.length; i++) {
println(i + ": " + devices[i].getName());
}
// Currently we assume the first device (#0) is the one we want
iac00 = RWMidi.getInputDevices()[0].createInput(this,8);
iac00.plug(this, "gantry");
}

public void draw(){
}

public void gantry(Note note) {
int vel = note.getVelocity();
rect(10*vel,20*vel,90,50);
}
}


I've got midi events coming through on midi channel 8 from logic.

First, I'm a bit confused as to how to get midi in on multiple channels through the IAC interface on OSX (10.5.5)  - I'm using createInput and not  the subsequent plug to specify the channel, but if I specify a specific channel it's fine, if I try -1 nothing gets written to the view port.

Second, when I run the code above I get the following message in the console window and the applet exits:

Invalid memory access of location 00000000 eip=9455b2ec

From your knowledge of rwmidi (and I'm guessing proMidi) is there anything you can think of which might be causing this?  When I run it using P3D instead of OPENGL, I don't get this error - but I don't think P3D isn't going to cut what I want to do.

Can't wait to get this pipe setup.  My mind is working overtime on the possibilities.

Thanks IA
s.
Re: RWMidi MIDI Library
Reply #7 - Nov 18th, 2008, 6:27pm
 
Hello Wesen,

I hate to appear stupid, but sadly I am a newbie in oh so many ways.

Question re; sendProgramChange(int p1);

The documentation says p1 is the channel.
In actual use p1 is the program number (instrument).
It will not take any more parameters.

How do I say "set THIS channel to THIS instrument"?

And, while I hate to admit it, I don't really understand what a "wrapper" is, so I don't get the usage of just ProgramChange at all.  Is it a datatype, a constructor, something else?

I would love a simple code example that shows "on this device (I know how to do that part) set channel 3 to instrument 50).

tkx!  Greg
Re: RWMidi MIDI Library
Reply #8 - Nov 29th, 2008, 5:15pm
 
Hopefully someone can help me with this.

When I was using an iMac with ProMidi, it recognized my MIDI setup:
my IAC Driver and my Keystation Series MIDI keyboard driver.

Since then I bought a MacBook Pro (Intel, OSX Leopard) and ProMidi no longer recognizes any MIDI devices.

I tried RWMidi using RWMidi.getInputDevices(); and getOutputDevices();. The only input I get is "Real Time Sequencer Sun Microsystems." I get the Sun Sequencer also for output plus "Java Sound Synthesizer Sun Microsystems."

Is there some mistake I'm making or do I need to make any adjustments to the code?

If anyone could tell me what I should do with RWMidi or any other Processing MIDI library, I'd really appreciate it.

Thank you for your help.

Peterf
Re: RWMidi MIDI Library
Reply #9 - Nov 29th, 2008, 9:12pm
 
Hey Peterf,
I'm brand new to Processing and to MIDI, but I'm having exactly the same problem as you are. OSX 10.5, and neither promidi nor rwmidi recognize the IAC driver nor my external eKeys-49 USB MIDI Keyboard.

The "promidi_information" program gives:

<< inputs: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<< outputs: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
output 0 : Java Sound Synthesizer
<<>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<< inputs: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
<< outputs: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
output 0 : Java Sound Synthesizer
<<<<<<<<<   >>>>>>>>>>>>>>>>>>>>>

printPorts recoded 2
<< inputs: >>>>>>>>>>>>>>>>>>>>>>
<< outputs: >>>>>>>>>>>>>>>>>>>>>
output 00: Java Sound Synthesizer
<<<<<<<<<   >>>>>>>>>>>>>>>>>>>>>

and the rwmidi shows:
[0] "Real Time Sequencer Sun Microsystems"
for its inputs and:
[0] "Real Time Sequencer Sun Microsystems"
[1] "Java Sound Synthesizer Sun Microsystems"
for its outputs.

I'm on OSX 10.5.5 and using the Processing 1.0, promidi 2.0, and rwmidi from October 25, 2008.

Does anyone know how to get the IAC Driver working with either promidi or rwmidi?

Maybe it's a OSX 10.5 bug, if you didn't have problems before?
Re: RWMidi MIDI Library
Reply #10 - Nov 29th, 2008, 9:30pm
 
Hi,

you have to install mandolane or mmj ( http://humatic.de/htools/mmj.htm ) to allow java to access the midi stack under osx. After that it should show the correct entries.

Cheers, manuel
Re: RWMidi MIDI Library
Reply #11 - Nov 29th, 2008, 9:38pm
 
Awesome! mmj seems to have done the trick! Thanks, Manuel!
Re: RWMidi MIDI Library
Reply #12 - Nov 30th, 2008, 12:25am
 
It worked for met too!

Thanks manuel,

Peterf
Re: RWMidi MIDI Library
Reply #13 - Mar 7th, 2009, 10:33am
 
First off, thanks to both WESEN and the developer of mmj. A platform like OSX shouldn't need 3rd party support for something like this, but since it does, it's great that folks have stepped up with free solutions.

RWMIDI works great for notes, but controller and program change messages aren't working for me. Am I missing something, or worse, doing something completely wrong? ;)



Sample Code:

import rwmidi.*;

MidiInput input;
MidiOutput output;


void setup() {
 input = RWMidi.getInputDevices()[0].createInput(this);
 output = RWMidi.getOutputDevices()[0].createOutput();
 
 println( "Output:" );
 
 String[] outDevices = RWMidi.getOutputDeviceNames() ;
 
 int l = outDevices.length ;
 
 for (int i = 0; i < l; i++) {
   println( outDevices[i] ) ;
 }
 
 println( "Input:" ) ;
 
 String[] inDevices = RWMidi.getInputDeviceNames() ;
 
 int ll = inDevices.length ;
 
 for (int i = 0; i < ll; i++) {
   println( inDevices[i] ) ;
 }
 
}


void noteOnReceived(Note note) {
 println("note on " + note.getPitch());
}

void sysexReceived(rwmidi.SysexMessage msg) {
 println("sysex " + msg);
}

void programChangeReceived(rwmidi.ProgramChange pc){
 println("prog change recieved");
}

void controllerChangeReceived(rwmidi.Controller cntrl){
 println("cc recieved");
 //println( controller.getCC() ) ;
 //println( controller.getValue() ) ;
}

void mousePressed() {
 int ret =    output.sendNoteOn(0, 3, 3);
}

void draw() {
}

thanks,

-- Ad.
Re: RWMidi MIDI Library
Reply #14 - Aug 26th, 2009, 2:27pm
 
hey everyone...

n00b question here...

I've followed so far and installed all the correct libraries within P5 and OSX... I have some code that is seeing my controller, i.e.

void noteOnReceived(Note note) {
 println("note on " + note.getPitch());
}

... is displaying values in my console. What I cannot seem to get to work is equating the Integer returned from getPitch to another conditional within my code.

I have a feeling that this is a very basic syntax error on my part, but it's partly that I don't understand the inner workings of midi more than using it to map triggers in an a/v program, so I am not sure if using the getPitch statement is the best thing to go ahead with, or if there is something else I have overlooked.

Here is the sample code:

import rwmidi.*;
MidiInput midiInput;
MidiOutput midiOutput;

int r1;
int r2;
int r3;
int r4;

void setup() {
 size(800, 800);
 background(0);
 noStroke();
 
 fill(255);
 rect(0, 0, 200, 200);
 fill(239);
 rect(200, 0, 200, 200);
 fill(223);
 rect(400, 0, 200, 200);
 fill(207);
 rect(600, 0, 200, 200);

 fill(191);
 rect(0, 200, 200, 200);
 fill(175);
 rect(200, 200, 200, 200);
 fill(159);
 rect(400, 200, 200, 200);
 fill(143);
 rect(600, 200, 200, 200);

 fill(127);
 rect(0, 400, 200, 200);
 fill(111);
 rect(200, 400, 200, 200);
 fill(95);
 rect(400, 400, 200, 200);
 fill(79);
 rect(600, 400, 200, 200);

 fill(63);
 rect(0, 600, 200, 200);
 fill(47);
 rect(200, 600, 200, 200);
 fill(31);
 rect(400, 600, 200, 200);
 fill(15);
 rect(600, 600, 200, 200);

 MidiInputDevice inDevices[] = RWMidi.getInputDevices();
 for (int i = 0; i < inDevices.length; i++) {
   println("In " + i + ": " + inDevices[i].getName());
 }
 MidiOutputDevice outDevices[] = RWMidi.getOutputDevices();
 for (int i = 0; i < outDevices.length; i++) {
   println("Out " + i + ": " + outDevices[i].getName());
 }
 midiInput =  inDevices[2].createInput(this);
 midiOutput = outDevices[2].createOutput();

}

void draw() {
 
}


void noteOnReceived(Note note) {
 println("note on " + note.getPitch());
}

int i = 43;  
   if (i = note.getPitch()) {
     noStroke();
     fill(255);
     rect(0, 0, 200, 200);
   }
   else {
     noStroke();
     fill(0);
     rect(0, 0, 200, 200);
   }


   
Obviously, what I am trying to do is affect the fill (as a substitute for alpha) of the rectangle based on whether a note is received. I am using a Trigger Finger, which has a 4x4 button array, matching the rectangles drawn (and I know I should rewrite the rect()'s in a class, but I'm a bit slow in OOP, with the end idea of using this as a live input / layer mask to a video mixer, overtop of another channel with live visuals.

Feel free to point out stupid mistakes...

~ J
Pages: 1 2