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 › Realtime visualizie started MIDI sequence
Page Index Toggle Pages: 1
Realtime visualizie started MIDI sequence (Read 533 times)
Realtime visualizie started MIDI sequence
Nov 18th, 2009, 7:01am
 
Hallo,

I try to visualize MIDI Sequence by playing a Sequencer. I need to notify the NoteOn and NoteOn messages.
How to do it?
Java API supports only Meta and control events on the Sequencer.
How can I create listener for NoteOn and NoteOff events?

Code:
import java.io.File;
import java.io.IOException;

import javax.sound.midi.*
......
import processing.opengl.*;
import java.io.File;

private static Sequencer sm_sequencer = null;
private static Synthesizer sm_synthesizer = null;

void setup() {
 size(1200, 768, OPENGL);
 noLoop();
 frameRate(30);
 background(0);
}

void draw()
{
 play();
}

void play()
{
 String strFilename = "C:/Downloads/MIDI/bach/gold/goldberg.mid";
 File midiFile = new File(strFilename);
 Sequence sequence = null;
 sequence = MidiSystem.getSequence(midiFile);
 sm_sequencer = MidiSystem.getSequencer();

 sm_sequencer.addMetaEventListener(new MetaEventListener()
 {
   public void meta(MetaMessage event)
   {
     println("%%% MetaMessage: " + event);
     if (event.getType() == 47)
     { ...  }
   }
 }
 );

   sm_sequencer.open();
   sm_sequencer.setSequence(sequence);

 if (! (sm_sequencer instanceof Synthesizer))
 {
     sm_synthesizer = MidiSystem.getSynthesizer();
     sm_synthesizer.open();
     Receiver synthReceiver = sm_synthesizer.getReceiver();
     Transmitter seqTransmitter = sm_sequencer.getTransmitter();
     seqTransmitter.setReceiver(synthReceiver);
 }
 sm_sequencer.start();
}

void keyPressed() {
 int PCKeyCode = keyCode;
 if (keyCode == 38) {
   sm_sequencer.setTempoFactor(sm_sequencer.getTempoFactor() - 0.1);
 }
 else if(keyCode == 40) {
   sm_sequencer.setTempoFactor(sm_sequencer.getTempoFactor() + 0.1);
 }  
 println(keyCode + ":" + sm_sequencer.getTempoFactor());
}



Thanks for solutions!!!
László
Page Index Toggle Pages: 1