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 › reading scores out of midi files
Page Index Toggle Pages: 1
reading scores out of midi files (Read 859 times)
reading scores out of midi files
May 23rd, 2008, 9:10pm
 
Hi to all,

i search a way to read scores out of midi files.

Im totally new to the midi field. Can anybody give me a tip what is the best way to make this?

thanks beforehand. Smiley
Re: reading scores out of midi files
Reply #1 - May 24th, 2008, 12:08am
 
Midi notes are stored with numbers.

60 is known as 'middle C' (C4)
61 is C#
62 D
etc.

There is a Processing library which can read MIDI input signals, but I'm not sure it can read MIDI files.

Processing > Reference > Librairies > proMidi > Note > getPitch()

Re: reading scores out of midi files
Reply #2 - May 24th, 2008, 9:32am
 
I wanted to test the proMidi library, but i got a lot of error messages, already in the examples.

And nowhere i can find a little sketch, where i can see how i can upload an simple midi file.

The next Library i tested arround with was jm-Etude.

Here i can see that a midi file uploaded into processing, but when i wanted to play the music, i also got an error.

Code:

import jmetude.*;

Etude e;
String[] parts;

void setup() {
size(400,400);
Etude e = new Etude(this);
e.createScore("song", "C:/song.mid" );
String[] parts = e.getScoreParts("song");
}

void draw() {

}

void mousePressed() {

e.stopMIDI();
e.playMIDI("song");

}


And now Im got a little stuck. Is there anywhere a little tutorial with midi and processing, where i can learn the first steps?
Re: reading scores out of midi files
Reply #3 - May 24th, 2008, 6:57pm
 
It's impossible to upload midi files with promidi 2.0.
Try this

import javax.sound.midi.*;

Sequence sequence = MidiSystem.getSequence(new File("C:/song.mid"));
Re: reading scores out of midi files
Reply #4 - May 25th, 2008, 10:10am
 
Becouse in my opinion jm.etude is easyer to understand i going on playing around with it.

And I managed to play a midi song.

Code:


import jmetude.*;

Etude e;
String[] parts;
String[] phrases;
float notes[][];


void setup() {

size(800,200);
e = new Etude(this);
e.createScore("title", "C:/song.mid" );

String[] parts = e.getScoreParts("title");
println("Parts: " + parts.length);

String[] phrases = e.getPartPhrases(parts[0]);
println("Phrases: " + phrases.length);

float[][] notes = e.getPhraseNotes(phrases[0]);

println("notes: " + notes.length);

e.createPhrase("phrase");
e.addPhraseNoteList("phrase", notes);


for(int i = 0; i < notes.length; i++)
{
println(notes[i][0]);
}


}

void draw() {

for(int i = 0; i < notes.length; i++)
{
println(notes[i][0]);
}

}

void mousePressed() {

e.stopMIDI();
e.playMIDI("title");

}



But i dont understand one thing.
In the setup void the println command works without any problem. But in the draw void i got a NullPointerException.

Can anybody explain me why?
Re: reading scores out of midi files
Reply #5 - May 25th, 2008, 9:14pm
 
The reason is this line in setup():

Code:
float[][] notes = e.getPhraseNotes(phrases[0]); 



You are defining "notes" as a local variable, which takes precedence over the global variable with the same name. So when you try to use notes inside draw() you're referring to the global variable, which has not been initialized.

The solution is simple. Use the following instead:

Code:
notes = e.getPhraseNotes(phrases[0]); 



That way both draw() and setup() refer to the global variable, which has been properly initialized in setup().
Re: reading scores out of midi files
Reply #6 - May 26th, 2008, 10:12am
 
Ahh i understand,

thx watz. Smiley
Page Index Toggle Pages: 1