MIDI Events : MIDI « J2ME « Java Tutorial






MIDI Events
import javax.microedition.lcdui.Alert;
import javax.microedition.lcdui.Display;
import javax.microedition.media.Manager;
import javax.microedition.media.Player;
import javax.microedition.media.control.MIDIControl;
import javax.microedition.midlet.MIDlet;

public class MIDIEventsMIDlet extends MIDlet {

  Display display = null;

  Alert alert = new Alert("Message");

  public MIDIEventsMIDlet() {
    display = Display.getDisplay(this);
    alert.setString("Working...");
    alert.setTimeout(Alert.FOREVER);
  }

  public void startApp() {
    display.setCurrent(alert);

    try {
      Player p = Manager.createPlayer(Manager.MIDI_DEVICE_LOCATOR);
      p.prefetch();
      MIDIControl mControl = (MIDIControl) p
          .getControl("javax.microedition.media.control.MIDIControl");

      if (mControl == null)
        throw new Exception("MIDIControl not available");
      mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 100);

      Thread.sleep(100);
      mControl.shortMidiEvent(192 | 11, 14, 0);

      Thread.sleep(100);

      mControl.shortMidiEvent(MIDIControl.CONTROL_CHANGE | 11, 7, 50);

      Thread.sleep(100);
      mControl.shortMidiEvent(MIDIControl.NOTE_ON | 11, 60, 0);

    } catch (Exception e) {
      alert.setString(e.getMessage());
    }
  }

  public void pauseApp() {
  }

  public void destroyApp(boolean unconditional) {
  }
}








31.57.MIDI
31.57.1.Play MIDI
31.57.2.Controllable MIDI
31.57.3.MIDI Capabilities
31.57.4.MIDI EventsMIDI Events
31.57.5.Mixing Audio