You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
1.6 KiB

import ddf.minim.*;
import ddf.minim.ugens.*;
import javax.sound.midi.*;
Minim minim;
AudioOutput out;
Sequencer sequencer;
Sequence sequence;
ArrayList<Blip> blips;
void setup() {
size( 640, 480 );
minim = new Minim(this);
out = minim.getLineOut();
try {
sequencer = MidiSystem.getSequencer( false );
// have to open it
sequencer.open();
// load our sequence
sequence = MidiSystem.getSequence( createInput( "bassline.MID" ) );
// put it in the sequencer
sequencer.setSequence( sequence );
// set the tempo
sequencer.setTempoInBPM( 128 );
// hook up an instance of our Receiver to the Sequencer's Transmitter
sequencer.getTransmitter().setReceiver( new MidiReceiver() );
// just keep looping
sequencer.setLoopCount( Sequencer.LOOP_CONTINUOUSLY );
// and away we go
sequencer.start();
}
catch( MidiUnavailableException ex ) // getSequencer can throw this
{
// oops there wasn't one.
println( "No default sequencer, sorry bud." );
}
catch( InvalidMidiDataException ex ) // getSequence can throw this
{
// oops, the file was bad
println( "The midi file was hosed or not a midi file, sorry bud." );
}
catch( IOException ex ) // getSequence can throw this
{
println( "Had a problem accessing the midi file, sorry bud." );
}
// and we need to make our Blip list
blips = new ArrayList<Blip>();
// and set our drawing preferences
rectMode( CENTER );
}
void draw()
{
background( 20 );
// just draw all the Blips!
for( int i = 0; i < blips.size(); ++i )
{
blips.get(i).draw();
}
}