/* * Created on Jun 30, 2004 * */ package jmslexamples; import java.awt.*; import java.awt.event.*; import com.softsynth.jmsl.JMSL; import com.softsynth.jmsl.midi.MidiListener; import com.softsynth.jmsl.midi.MidiListenerAdapter; /** * @author Nick Didkovsky, email: didkovn@mail.rockefeller.edu, (c) 2004 Nick Didkovsky, all rights reserved. * */ public class MidiNoteSimulatorCheckbox extends Checkbox implements ItemListener { private int pitch; private MidiListener midiListener; public MidiNoteSimulatorCheckbox(String label, int pitch, MidiListener midiListener) { super(label); this.pitch = pitch; this.midiListener = midiListener; this.addItemListener(this); } public void itemStateChanged(ItemEvent arg0) { if (getState()) { midiListener.handleNoteOn(JMSL.realTime(), 1, pitch, 80); } else { midiListener.handleNoteOff(JMSL.realTime(), 1, pitch, 0); } } public static void main(String[] args) { MidiListenerAdapter midiListener = new MidiListenerAdapter() { public void handleNoteOn(double timeStamp, int channel, int pitch, int velocity) { System.out.println( "Note ON : ch " + channel + ", pitch " + pitch + ", vel " + velocity); } public void handleNoteOff(double timeStamp, int channel, int pitch, int velocity) { System.out.println( "Note OFF : ch " + channel + ", pitch " + pitch + ", vel " + velocity); } }; Frame midiSimFrame = new Frame("Simulate MIDI notes"); midiSimFrame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); midiSimFrame.setLayout(new GridLayout(16, 0)); for (int i = 1; i < 128; i++) { midiSimFrame.add(new MidiNoteSimulatorCheckbox(i + "", i, midiListener)); } midiSimFrame.pack(); midiSimFrame.setVisible(true); } }