Question

I am creating a simple MIDI application in C# with an open source library that allows the user to specify a channel, pitch and velocity and add them to a Clock. This clock can then play all the notes in the sequence that they were added.

Everything works great and now I am in the process of creating a Java version of the application, the only trouble I seem to be having is that I can't find any simple tutorial or explanation of how the clock system works within MIDI Java.

Does the Clock exist in Java Sound Framework or is this something I will have to implement myself?

Thanks!

Was it helpful?

Solution

It's been a long time since I've touched the Java Midi stuff, but in general, to programmatically build a MIDI, you need to do the following steps.

Assuming import javax.sound.midi;:

  1. You need to create a Sequencer object:

    Sequence seq = new Sequence(Squence.PPQ, 500000);
    
  2. Next, you need to create a Track object (one per channel or one for everything, it's up to you):

    Track track = seq.createTrack();
    
  3. Now, you can add events to it:

    track.add(new MidiEvent(new ShortMessage(ShortMessage.NOTE_ON, 0, 60, 127), 0));
    track.add(new MidiEvent(new ShortMessage(ShortMessage.NOTE_OFF, 0, 60, 127), 1000));
    //etc.
    
  4. When you're done that, you can then play the Sequence like normal!

Check out the docs here: http://download.oracle.com/javase/7/docs/api/index.html?javax/sound/midi/MidiSystem.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top