List of usage examples for javax.sound.midi Sequencer addControllerEventListener
int[] addControllerEventListener(ControllerEventListener listener, int[] controllers);
From source file:Main.java
public static void main(String[] args) { JFrame frame = new JFrame(); DrawPanel dp = new DrawPanel(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setContentPane(dp);/*ww w. j a v a 2s . com*/ frame.pack(); frame.setLocationByPlatform(true); try { Sequence seq = new Sequence(Sequence.PPQ, 4); Track track = seq.createTrack(); for (int i = 0; i < 120; i += 4) { int d = (int) Math.abs(new Random().nextGaussian() * 24) + 32; track.add(makeEvent(ShortMessage.NOTE_ON, 1, d, 127, i)); track.add(makeEvent(ShortMessage.CONTROL_CHANGE, 1, 127, 0, i)); track.add(makeEvent(ShortMessage.NOTE_OFF, 1, d, 127, i)); } Sequencer sequencer = MidiSystem.getSequencer(); sequencer.open(); sequencer.setSequence(seq); sequencer.addControllerEventListener(dp, new int[] { 127 }); sequencer.start(); } catch (Exception e) { e.printStackTrace(); } frame.setVisible(true); }