My List

Wednesday, September 19, 2007

Notes of jMusic (1) - Basic Structure

jMusic is a programming library written for musicians in the Java programming language. jMusic is designed to be used as a compositional medium, therefore it is primarily designed for musicians - not computer programmers. However, many people find jMusic a useful API for music software development, in particular for digital instrument making.

Score (Contains any number of Parts)
|
+---- Part (Contains any number of Phrases)
|
+---- Phrase (Contains any number of Notes.)
|
+---- Note (Holds information about a single musical event.)

Notes (jm.music.data.Note)
Contain information:

1. Pitch - the note's pitch
2. Dynamic - the loudness of the note
3. RhythmValue - the length of the note (e.g., Crotchet)
4. Pan - the notes position in the stereo (or more) spectrum.
5. Duration - the length of the note in milliseconds
6. Offset - an deviation from the 'normal' start time of the note

Notes with a pitch of the minimum integer are rests, those between 0 <> 127 are exactly the same as normal sounding notes numbered like the MIDI specification. Notes with a pitch specified as a double value, e.g., 440.0, are frequency values for the note pitch. In general, note pitch refers to the chromatic key number (as per MIDI) as an int and the note frequency refer to the value in hertz as a double value.

Phrases
Every Phrase objects contains a list of notes. The list that does all these things is java.util.Vector.

Parts
Part is a class that surprisingly enough holds the notes (in phrases) to be played by an instrument. A part contains a vector that contains lots of phrases (sound familiar). A part also has a title ("Violin 1" for example), a channel, and an instrument.

Scores
The Score class is used to hold score data. Score data includes is primarily made up of a vector of Part objects. Commonly score data is algorithmically generated or read from a standard MIDI file, but can also be read and saved to file using Java's object serialization. In this way a Score's data can be saved in a more native context. To find out how to read from and write to standard MIDI files or to use object serializationcheck out the jm.util.Read and jm.util.Write classes.

// give this class access to the jMusic classes
import jm.JMC;
import jm.music.data.*;
import jm.util.*;

/**
* This is the simplest jMusic program of all.
* The eqivalent to a programming language's 'Hello World'
*/

public final class HelloWorld implements JMC {
public static void main(String[] args){

//create a middle C minim (half note)
Note n = new Note(C4, MINIM);

//create a phrase
Phrase phr = new Phrase();

//put the note inside the phrase
phr.addNote(n);

//pack the phrase into a part
Part p = new Part();
p.addPhrase(phr);

//pack the part into a score titled 'Bing'
Score s = new Score("HelloWorld");
s.addPart(p);

//write the score as a MIDI file to disk
Write.midi(s, "HelloWorld.mid");
}
}


No comments:

Post a Comment