Java examples for javax.sound.midi:MidiEvent
Create a note on event for MIDI.
import javax.sound.midi.ShortMessage; import javax.sound.midi.MidiMessage; import javax.sound.midi.MidiEvent; import javax.sound.midi.Sequencer; import javax.sound.midi.Track; import javax.sound.midi.Sequence; import javax.sound.midi.MidiSystem; import javax.sound.midi.MetaMessage; import java.util.Vector; public class Main{ /** //from w w w. java2 s . c o m * Create a note on event. */ public static MidiEvent createNoteOnEvent(long tick, int note, int velocity) { return MidiHelper.createNoteOnEvent(tick, 0, note, velocity); } /** * Create a note on event. */ public static MidiEvent createNoteOnEvent(long tick, int channel, int note, int velocity) { ShortMessage shortMessage = new ShortMessage(); try { shortMessage.setMessage(ShortMessage.NOTE_ON, channel, note, velocity); } catch (Exception e) { e.printStackTrace(); System.exit(1); } return new MidiEvent(shortMessage, tick); } }