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 and serial output question....
Page Index Toggle Pages: 1
Promidi and serial output question.... (Read 1482 times)
Promidi and serial output question....
Mar 9th, 2006, 7:56pm
 
hello, i'm trying to write a small program that will send data via serial port on my computer to my arduino board to turn on an led. this is just the first step of a much larger project.

the arduino board code is fine, as i have tested it with a processing example that sends a capital "A" out of the serial port when the letter "A" is pressed on the keyboard, and it works just fine.

however....

now i'm trying to get processing to listen to a midi note signal from Ableton live, instead of pressing the keyboard, but i cant seem to get it working. here is the code i've writen/cut and pasted from various sources.

if some one would be so kind as to cast their eye over it then i would be greatly appreciative!

many thanks,

bod.



import promidi.*; //import Promidi library
import processing.serial.*; //import serial library

Serial myPort;    // The serial port:  

println(Serial.list());// List all the available serial ports:
myPort = new Serial(this, Serial.list()[0], 9600); //open serial port 0, at 9600 baud rate

MidiIO midiIO;

 midiIO = MidiIO.getInstance(this);
 println("printPorts of midiIO");
 midiIO.printPorts(); //print midi IO ports
 midiIO.openInput(0); //open midi input port 0
 
}{
 getPitch(); //get pitch of the incoming midi note
 getMidiChannel(); { //get midi channel of incoming note
   if (Pitch == '0') {
     if (MidiChannel == '0') {
     myPort.write(65); //send capital "A" out of serial port
   }
Re: Promidi and serial output question....
Reply #1 - Mar 9th, 2006, 10:37pm
 
suppose i should be a bit more specific really... sorry.

i'm trying to get processing to listen to the fisrt midi note (0 to 127) of the first midi channel (1 to 16). i've succesfully run the examples in the Promidi library, but when it comes to writing my own codes i loose it somewhere. i think its in this bit....

getPitch(); //get pitch of the incoming midi note
  getMidiChannel(); { //get midi channel of incoming note
    if (Pitch == '0') {  
 if (MidiChannel == '0') {
 myPort.write(65); //send capital "A" out of serial port
    }                          



i can see that the midi port i have selected is open, and so is the serial output. i'm using a pc running windows XP.

hope this is a bit more clear.

cheers again,

bod.

Re: Promidi and serial output question....
Reply #2 - Mar 10th, 2006, 10:57pm
 
Hi Bod

Try this

Code:

import promidi.*; //import Promidi library
import processing.serial.*; //import serial library

Serial myPort; // The serial port:

import promidi.*;

MidiIO midiIO;

void setup(){
size(200,200);
smooth();
background(0);

println(Serial.list());// List all the available serial ports:
myPort = new Serial(this, Serial.list()[0], 9600); //open serial port 0, at 9600 baud rate

midiIO = MidiIO.getInstance(this);
println("printPorts of midiIO");
midiIO.printPorts();
midiIO.openInput(0);
}

void draw(){

}

void noteOn(Note note){
int pitch = note.getPitch();
int midiChannel = note.getMidiChannel();

if (pitch == '0') {
if (midiChannel == '0') {
myPort.write(65); //send capital "A" out of serial port
}
}
}


From the code you have posted it seems to me that you need to learn some more basics first. Try to get a deeper understanding on writing and calling functions.
Re: Promidi and serial output question....
Reply #3 - Mar 11th, 2006, 9:27am
 
cheers tex. your right, i've thrown myself in at the deep end with this....

thanks for looking at the code for me though!
Re: Promidi and serial output question....
Reply #4 - Mar 29th, 2006, 7:27pm
 
ok, i've got this all sorted apart from the midichannel issue.

the program listens to incoming midi notes, and if midi note 1 is heard, it sends a capital H to the serial output, and a captial A when it hears the corresponding note off. this is used to switch an led on and off via my arduino board.

i've tried all sorts of combinations and different codes to get it to listen to a specific note on a specific midi channel, but i guess i still have a lot to learn...

does any one have any tips on how to get this code to listen to midichannel data?

import processing.serial.*;
import promidi.*; //import promidi library

Serial myPort;
MidiIO midiIO; //midi in out comand

void setup() {
 size(200,200); //size of window
//smooth();
background(215); //background colour
myPort = new Serial(this, Serial.list()[0], 9600);
midiIO = MidiIO.getInstance(this);
println("printPorts of midiIO");
midiIO.printPorts(); //prints midi ports available
midiIO.openInput(0); //opens input 1 from ports available
}

 void noteOn(Note note){
 int pit = note.getPitch();
 println("noteOn " + pit); //prints note in pitch
 if(pit == 0) { //if the note is 1
   myPort.write('H');
   }
   
 }
 
 void noteOff(Note note){
 int pit = note.getPitch();
 println("noteOff " + pit); //prints note off pitch
 if(pit == 0) { //if the note is 1
   myPort.write('A');
   }
   }


cheers in advance,


bod.
Page Index Toggle Pages: 1