User Tools

Site Tools


cs276:handlemidi

This is an old revision of the document!


/*
 *  Handle MIDI
 *
 *  The notes array contains minimal MIDI note and duration information.  JMEtude functions
 *  handle creating a musical phrase using the MIDI data and playing the notes.
 */
 
import jmetude.*;
 
Etude e;
float notes[][] = {{60,1.0}, 
                   {62,1.0}, 
                   {64,1.0}, 
                   {65,1.0}, 
                   {67,1.0}, 
                   {69,1.0}, 
                   {71,1.0}, 
                   {72,4.0}};
 
void setup() {
    noLoop();
    size(200,100);
    e = new Etude(this);
    e.createPhrase("phrase");
    e.addPhraseNoteList("phrase", notes);
 
    // uncomment this next line to play an existing midi file instead
    // e.createScore("score", "gfhblast.mid");
}
 
void draw() {
  background(50);
  PImage splash = loadImage("splash.gif");
  image(splash, 0, 0);
}
 
void mousePressed() {
  e.stopMIDI();
  int inst = (int) random(0,127);
  e.setPhraseInstrument("phrase", inst);
  e.playMIDI("phrase");
}
cs276/handlemidi.1197492580.txt.gz · Last modified: 2007/12/12 14:49 by scarl