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.
IndexProgramming Questions & HelpSound,  Music Libraries › proMIDI newb question
Page Index Toggle Pages: 1
proMIDI newb question (Read 710 times)
proMIDI newb question
Jul 24th, 2008, 11:32am
 
Hello, im fairly new to processing and im looking at an example from the proMIDI web page.  With the example

void noteOn(
 Note note,
 int deviceNumber,
 int midiChannel
){

how would i go about setting it to only one note.  I have a keyboard and hit the very bottom note and I println the pitch.  It reads 21.  I understand device # and midichannel, but was just wondering on how to just draw a circle for one note and a square for another note. Also i am tiring to get the example from the proMIDI web page http://www.texone.org/promidi/note_class_note.htm# to work but it says cannot find symbol "Controller". Thanks.  Matt.
Re: proMIDI newb question
Reply #1 - Jul 29th, 2008, 10:38am
 
Hey up

If I understand this right, you're getting the note value in your function, yes? If so, then just use a conditional within that function to do what you want. E.g.

if (note.getPitch() == 21) {

//make a square!
//or call a makeSquare() function that you've written elsewhere

} else if (note.getPitch() == 22) {

//make a circle...

}

There's plenty more complex things you could do with the getPitch value (e.g. access an index in an array of objects that do different things but all have a 'makeashape' method), but that's the basic principle I reckon.
Re: proMIDI newb question
Reply #2 - Jul 29th, 2008, 3:27pm
 
that's basically what i am looking for thanks.  But i have a keyboard then another midi controller.  would the code look something like this?

if (note.getPitch() == 21 && deviceNumber == 0) {
//do whatever here}

else if (note.getPitch() == 22 && deviceNumber == 0) {
//do something else}

else if (note.getPitch() == 22 && deviceNumber == 1) {
//do whatever else}

is there a max else if statements?
I'll worry about midi channels later. but i assume that it would just be another && midiChannel statement.  Thanks for the help.!
Re: proMIDI newb question
Reply #3 - Jul 29th, 2008, 4:00pm
 
Yup, that all looks good. No max on else ifs but it becomes cumbersome. Java has a switch you can use, but I don't know if processing has a version.

If you're starting to get into much larger sets of actions, there are ways around having to do a million if thens...
Re: proMIDI newb question
Reply #4 - Jul 29th, 2008, 4:09pm
 
deviceNumber does not work.  I am really banging my head against a wall with this. seems so simple but i just can not get the syntax right.
Re: proMIDI newb question
Reply #5 - Jul 29th, 2008, 4:11pm
 
Can you paste in your code?
Re: proMIDI newb question
Reply #6 - Jul 29th, 2008, 4:14pm
 
import promidi.*;

MidiIO midiIO;

void setup(){
 size(128*5,128*5);
 smooth();
 background(0);
 
 //get an instance of MidiIO
 midiIO = MidiIO.getInstance(this);
 println("printPorts of midiIO");
 
 //print a list of all available devices
 midiIO.printDevices();
 
 //open the first midi channel of the first device
 midiIO.openInput(0,0);
  midiIO.openInput(1,0);
 
}

void draw(){
 //nothing to do here
}

void noteOn(Note note, int device, int channel){
 int vel = note.getVelocity();
 int pit = note.getPitch();
 if (note.getPitch() == 21) {
    rect(100,100,50,250);

         } else if (note.getPitch() == 23) {

        ellipse(vel*5,pit*5,30,30);
     
        } else if (note.getPitch() == 1 && deviceNumber==0){
         
       ellipse(300,300,160,175);
        }
        println(note.getPitch());

}




quite messy but i am just tiring to get some sh*t to pop out on screen to make sure its working. and obviously the deviceNumber line doesnt work
Re: proMIDI newb question
Reply #7 - Jul 29th, 2008, 4:21pm
 
Questions:

Is your...

if (note.getPitch() == 21) {
    rect(100,100,50,250);

... working? Is it just the

if (note.getPitch() == 1 && deviceNumber==0)

that's not doing the job? If not, I can see why: the noteOn function takes in three variables - note (a Note class), and two ints - 'device' and 'channel'. So the device being used is stored in 'device' but you're using 'deviceNumber'. You say you're new to processing - are you new to java as well? If so, this will all currently seem rather confusing!

Anyhoo, let me know about the above and if using 'device' not 'deviceNumber' fixes things... i.e.:

if (note.getPitch() == 1 && device==0)
Re: proMIDI newb question
Reply #8 - Jul 29th, 2008, 4:24pm
 
yeah drawing the rect is no problem, its just the statement with deviceNumer that isnt.  Changing to device==0 does not do anything.  Yes i am brand new to java as well but have some background in flash actionscript.  Also ive tried to hardcode the deviceNumber into the noteOn function, but when i do

void noteOn(Note note, 0, 0)

i get an error saying unexpected token 0
Re: proMIDI newb question
Reply #9 - Jul 29th, 2008, 4:30pm
 
Also i have both devices open so it is seeing both my keyboard and controller.  they both work to draw the rect and ellipse i just want to be able to specify what device has control over just the rect or ellipse, if that makes sense.
Re: proMIDI newb question
Reply #10 - Jul 29th, 2008, 4:35pm
 
What are the devices that you're using? Both keyboards? Can you println out what output you get (if any) when you do something with device 0? (See below...)

You can't hardcode the values in - the noteOn function is overriding a method from the imported midi classes. The function is called each time there's a signal from any open device, and each time its called, a note object is passed in, in theory along with the channel and device number.

Just saw your other message: so they're both keyboards capable of sending pitch info, and you get the first ellipse or square regardless of which device sends the data?

What do you get with -

if (note.getPitch() == 21) {
    rect(100,100,50,250);
    println("device number: " + device);

 
}

?
Re: proMIDI newb question
Reply #11 - Jul 29th, 2008, 4:42pm
 
printPorts of midiIO
<< inputs: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
input 0 : Livid ohm Controller <MIn:0>
input 1 : Port 1 <MIn:1>
input 2 : Port 2 <MIn:2>

lol when i println device i get the ohm controller as device 2 and if fing works.  THANK YOU SO MUCH

} else if (note.getPitch() == 1 && device==2){
         
       ellipse(300,300,160,175);
        }

this works like a charm and yes i get the first ellipse and rect regardless of which device it comes from.  

THANKS AGAIN for letting my headache go away.

P.S how does this line work?
println("device number: " + device)

device is just in the proMidi library?

Re: proMIDI newb question
Reply #12 - Jul 29th, 2008, 4:44pm
 
Glad to help. Have fun!
Re: proMIDI newb question
Reply #13 - Jul 31st, 2008, 10:52am
 
Oh - only just saw the p.s.

'device' has been passed into the noteOn function. Actually, I'm going to call it the noteOn method, coz that's what it is in object-oriented-(OO)-speak! Have you used actionscript 3 much? All very OO. Anyway - what happens, I believe:

* proMidi's open ports listen for any inputs.
* if proMidi hears a noteOn from any of those inputs, it calls the noteOn method, passing in three things:

1. a Note object: this has been created for that note, and has its own methods that can be called, i.e. note.getPitch();
2. the number of device, attached to the int 'device'
3. the channel number, attach to the int 'channel'

So -

println("device number: " + device)

- prints out the device number that sent the noteOn signal.

Couple of other things: 1. Are you familiar with variable scope?

http://processing.org/learning/basics/variablescope.html

2. Have you come across pass by reference vs pass by value? It's amazing what a meal some folks make of this when teaching it: it's fairly straightforward but can seem totally confusing...

Page Index Toggle Pages: 1