Class MidiIO

java.lang.Object
com.softsynth.jmsl.midi.MidiIO
All Implemented Interfaces:
Editable, MusicDevice
Direct Known Subclasses:
MidiIO_JavaSound

public abstract class MidiIO
extends java.lang.Object
implements MusicDevice
Abstract class that provides access to a MIDI device. Also includes Midi "note on" and "note off" methods.
Author:
Phil Burk and Nick Didkovsky
  • Field Summary

    Fields
    Modifier and Type Field Description
    static int CHANNEL_AFTERTOUCH  
    static int CONTROL_CHANGE  
    static int MIDI_PAN_CONTROL_INDEX  
    static int MIDI_VOLUME_CONTROL_INDEX  
    static int NOTE_OFF  
    static int NOTE_ON  
    static int PITCH_BEND  
    static int PITCH_BEND_CENTER
    Value for bendPitch for zero bend.
    static int PITCH_BEND_MAX  
    static int POLYPHONIC_AFTERTOUCH  
    static int PROGRAM_CHANGE  
  • Constructor Summary

    Constructors
    Constructor Description
    MidiIO()  
  • Method Summary

    Modifier and Type Method Description
    void addEditListener​(EditListener listener)
    unimplemented
    void addMidiParser​(MidiParser parser)
    Add a listener/parser for raw MIDI input messages.
    void allNotesOff​(double timeStamp, int channel)
    Turn off all notes on the given MIDI channel at the given time.
    void allNotesOff​(int channel)
    Turn off all notes on the given MIDI channel.
    void bendPitch​(double playTime, int channel, int bendAmount)
    Send a control message over the given MIDI channel at the given time.
    void bendPitch​(int channel, int bendAmount)
    Bend the pitch of all notes on the given MIDI channel.
    void clearMidiLog()
    Remove all logged MIDI events from MIDI event logger
    boolean close()
    Calls closeDevices() if not already closed.
    abstract boolean closeDevices()  
    void control​(double playTime, int channel, int controlIndex, int value)
    Send a control message over the given MIDI channel at the given time.
    void control​(int channel, int controlIndex, int value)
    Send a control message over the given MIDI channel.
    void controlContinuous​(double playTime, int channel, int controlIndex, int value)
    Send a control message over the given MIDI channel at the given time.
    void controlContinuous​(int channel, int controlIndex, int value)
    Send a continuous control message over the given MIDI channel.
    static MidiIO createMidiIO()
    Create an appropriate MidiIO.
    void edit​(java.awt.Frame f)
    If Frame is null, MidiInitDialog is called with new Frame()
    boolean getEditEnabled()  
    int getInDevice()  
    abstract java.lang.String[] getInputDeviceNames()  
    java.util.Vector getMidiParser()  
    int getOutDevice()  
    abstract java.lang.String[] getOutputDeviceNames()  
    java.lang.String getPreferredInDevName()  
    java.lang.String getPreferredOutDevName()  
    boolean getQuiet()  
    void logMessage​(double timeStamp, int status, int data1, int data2)
    Add timestamped event to midi logger if setMidiLogging is true
    void logMessage​(int status, int data1, int data2)
    Add event to midi logger if setMidiLogging is true
    static void main​(java.lang.String[] args)  
    void noteOff​(double timeStamp, int channel, int pitch)  
    void noteOff​(double timeStamp, int channel, int pitch, int velocity)  
    void noteOff​(int channel, int pitch)
    Turn on MIDI note at the specified time.
    void noteOff​(int channel, int pitch, int velocity)  
    void noteOn​(double playTime, int channel, int pitch, int velocity)
    Turn on MIDI note at the specified time.
    void noteOn​(int channel, int pitch, int velocity)  
    boolean open()
    Only calls openDevices() if not already open
    abstract boolean openDevices​(int inDevice, int outDevice)  
    void printMidiLog()  
    void programChange​(double playTime, int channel, int index_0_127)  
    void programChange​(int channel, int index_0_127)
    Send a program change message over the given MIDI channel.
    void removeEditListener​(EditListener listener)
    unimplemented
    void removeMidiParser​(MidiParser parser)  
    void scheduleMessage​(double playTime, int status, int data1, int data2)
    Put MIDI message into EventScheduler.
    abstract void sendMessage​(double timeStamp, int status, int data1, int data2)  
    abstract void sendMessage​(int status, int data1, int data2)  
    void setEditEnabled​(boolean f)
    Set a flag.
    void setInDevice​(int devID)  
    void setInDevice​(java.lang.String requestedDeviceName)  
    void setMidiLogging​(boolean flag)
    Turn logging of Midi events on or off
    void setOutDevice​(int devID)  
    void setOutDevice​(java.lang.String requestedDeviceName)  
    void setQuiet​(boolean f)
    if true, no midi output; calls to various send methods simply return
    abstract void startListening()  
    abstract void stopListening()  
    abstract void synchClocks()
    Synchronize JMSL.clock with Midi clock.
    void sysex​(byte[] data)
    Send data[] as sysex.
    abstract void sysex​(double timeStamp, byte[] data)
    Send data[] as sysex at specified time.
    void test1()
    Play a couple notes using different programs.
    void test2()
    Schedule ascending major arpeggio using event buffer.
    void test3()  
    void writeMidiFile​(java.lang.String filename)  

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • MidiIO

      public MidiIO()
  • Method Details

    • setInDevice

      public void setInDevice​(int devID)
    • setInDevice

      public void setInDevice​(java.lang.String requestedDeviceName)
    • setOutDevice

      public void setOutDevice​(java.lang.String requestedDeviceName)
    • getPreferredInDevName

      public java.lang.String getPreferredInDevName()
    • getPreferredOutDevName

      public java.lang.String getPreferredOutDevName()
    • getInDevice

      public int getInDevice()
    • setOutDevice

      public void setOutDevice​(int devID)
    • getOutDevice

      public int getOutDevice()
    • setQuiet

      public void setQuiet​(boolean f)
      if true, no midi output; calls to various send methods simply return
    • getQuiet

      public boolean getQuiet()
      Returns:
      quiet flag (when true, subclasses of MidiIO ought to call midilogger.log but not send the message to device)
    • openDevices

      public abstract boolean openDevices​(int inDevice, int outDevice)
    • closeDevices

      public abstract boolean closeDevices()
    • synchClocks

      public abstract void synchClocks()
      Synchronize JMSL.clock with Midi clock. Implementation dependent. Used to convert incoming Midi timestamps to JMSL double time, and to convert JMSL time to Midi timestamps. Implemented by MidiIO_MidiSare
    • open

      public boolean open()
      Only calls openDevices() if not already open
      Specified by:
      open in interface MusicDevice
    • close

      public boolean close()
      Calls closeDevices() if not already closed. Your application should call JMSL.closeMusicDevices() instead of closing this MidiIO explicitely.
      Specified by:
      close in interface MusicDevice
    • edit

      public void edit​(java.awt.Frame f)
      If Frame is null, MidiInitDialog is called with new Frame()
      Specified by:
      edit in interface Editable
    • setEditEnabled

      public void setEditEnabled​(boolean f)
      Description copied from interface: Editable
      Set a flag. For example you might setEditEnabled(false) after first edit(), or you might hard code values for some Editable class and so want to disable editing.
      Specified by:
      setEditEnabled in interface Editable
    • getEditEnabled

      public boolean getEditEnabled()
      Specified by:
      getEditEnabled in interface Editable
      Returns:
      flag
    • addEditListener

      public void addEditListener​(EditListener listener)
      unimplemented
      Specified by:
      addEditListener in interface Editable
    • removeEditListener

      public void removeEditListener​(EditListener listener)
      unimplemented
      Specified by:
      removeEditListener in interface Editable
    • sendMessage

      public abstract void sendMessage​(int status, int data1, int data2)
    • sendMessage

      public abstract void sendMessage​(double timeStamp, int status, int data1, int data2)
    • getInputDeviceNames

      public abstract java.lang.String[] getInputDeviceNames()
    • getOutputDeviceNames

      public abstract java.lang.String[] getOutputDeviceNames()
    • startListening

      public abstract void startListening()
    • stopListening

      public abstract void stopListening()
    • logMessage

      public void logMessage​(int status, int data1, int data2)
      Add event to midi logger if setMidiLogging is true
    • logMessage

      public void logMessage​(double timeStamp, int status, int data1, int data2)
      Add timestamped event to midi logger if setMidiLogging is true
    • setMidiLogging

      public void setMidiLogging​(boolean flag)
      Turn logging of Midi events on or off
    • clearMidiLog

      public void clearMidiLog()
      Remove all logged MIDI events from MIDI event logger
    • printMidiLog

      public void printMidiLog()
    • writeMidiFile

      public void writeMidiFile​(java.lang.String filename) throws java.io.IOException
      Throws:
      java.io.IOException
    • createMidiIO

      public static MidiIO createMidiIO() throws java.io.IOException
      Create an appropriate MidiIO. This allows us to specify the default Midi IO device in one location. Default returns MidiIO_MidiShare.instance() singleton
      Throws:
      java.io.IOException
    • getMidiParser

      public java.util.Vector getMidiParser()
      Returns:
      Vector of MidiParsers (could be empty)
    • scheduleMessage

      public void scheduleMessage​(double playTime, int status, int data1, int data2)
      Put MIDI message into EventScheduler.
    • programChange

      public void programChange​(int channel, int index_0_127)
      Send a program change message over the given MIDI channel.
      Parameters:
      channel - can range from 1 to 16.
      index_0_127 - can range from 0 to 127.
    • programChange

      public void programChange​(double playTime, int channel, int index_0_127)
    • control

      public void control​(int channel, int controlIndex, int value)
      Send a control message over the given MIDI channel.
      Parameters:
      channel - can range from 1 to 16.
      controlIndex - can range from 0 to 127.
      value - can range from 0 to 127.
    • control

      public void control​(double playTime, int channel, int controlIndex, int value)
      Send a control message over the given MIDI channel at the given time.
    • controlContinuous

      public void controlContinuous​(int channel, int controlIndex, int value)
      Send a continuous control message over the given MIDI channel.
      Parameters:
      channel - can range from 1 to 16.
      controlIndex - can range from 0 to 31.
      value - can range from 0 to 0x3FFF or 16383.
    • controlContinuous

      public void controlContinuous​(double playTime, int channel, int controlIndex, int value)
      Send a control message over the given MIDI channel at the given time.
    • allNotesOff

      public void allNotesOff​(int channel)
      Turn off all notes on the given MIDI channel.
    • allNotesOff

      public void allNotesOff​(double timeStamp, int channel)
      Turn off all notes on the given MIDI channel at the given time.
    • bendPitch

      public void bendPitch​(int channel, int bendAmount)
      Bend the pitch of all notes on the given MIDI channel.
      Parameters:
      channel - can range from 1 to 16.
      bendAmount - can range from 0 to 0x3FFF. For no bend, send 0x2000.
    • bendPitch

      public void bendPitch​(double playTime, int channel, int bendAmount)
      Send a control message over the given MIDI channel at the given time.
    • noteOn

      public void noteOn​(int channel, int pitch, int velocity)
    • noteOn

      public void noteOn​(double playTime, int channel, int pitch, int velocity)
      Turn on MIDI note at the specified time.
    • noteOff

      public void noteOff​(int channel, int pitch, int velocity)
    • noteOff

      public void noteOff​(int channel, int pitch)
      Turn on MIDI note at the specified time.
    • noteOff

      public void noteOff​(double timeStamp, int channel, int pitch, int velocity)
    • noteOff

      public void noteOff​(double timeStamp, int channel, int pitch)
    • sysex

      public void sysex​(byte[] data)
      Send data[] as sysex. User should not include F0 and F7 (SysEx start/stop) in data[]!!!
    • sysex

      public abstract void sysex​(double timeStamp, byte[] data)
      Send data[] as sysex at specified time. User should not include F0 and F7 (SysEx start/stop) in data[]!
    • addMidiParser

      public void addMidiParser​(MidiParser parser)
      Add a listener/parser for raw MIDI input messages.
    • removeMidiParser

      public void removeMidiParser​(MidiParser parser)
    • test1

      public void test1()
      Play a couple notes using different programs.
    • test2

      public void test2()
      Schedule ascending major arpeggio using event buffer.
    • test3

      public void test3()
    • main

      public static void main​(java.lang.String[] args)