Class JJazzMidiSystem

java.lang.Object
org.jjazz.midi.api.JJazzMidiSystem

public final class JJazzMidiSystem extends Object
Manage the Midi IN and OUT devices for the JJazz application, plus some convenience methods.

Scan the available Midi IN/OUT devices at startup. Restore the default Midi IN/OUT devices when possible using Preferences.

The application should only connect to JJazzMidiIn and JJazzMidiOut virtual devices. These devices are implemented by a MidiFilter object, enabling filtering and dumping. These devices are connected internally to the selected physical MIDI In/Out devices.

Manage a Midi master volume: a factor between 0 and 2 (default=1) which is used on all volume Midi messages.

  • Field Details

  • Method Details

    • getInstance

      public static JJazzMidiSystem getInstance()
    • getInDeviceList

      public List<MidiDevice> getInDeviceList()
      Scan the MidiSystem for IN MidiDevices.
      Returns:
      A List containing the MIDI out devices. Java Sequencer is excluded.
    • getOutDeviceList

      public List<MidiDevice> getOutDeviceList()
      Scan the MidiSystem for OUT MidiDevices.
      Returns:
      A List containing the available MIDI out devices, excluding the Java synth and the Java Sequencer.
    • getJJazzMidiInDevice

      public JJazzMidiDevice getJJazzMidiInDevice()
      Returns:
      The Midi IN device to be used by the application.
    • getJJazzMidiOutDevice

      public JJazzMidiDevice getJJazzMidiOutDevice()
      Returns:
      The Midi OUT device to be used by the application.
    • getDefaultInDevice

      public MidiDevice getDefaultInDevice()
      Returns:
      The default MIDI in device. Null if not set.
    • getDefaultOutDevice

      public MidiDevice getDefaultOutDevice()
      Returns:
      The default MIDI out device. Null if not set.
    • getDefaultSequencer

      public Sequencer getDefaultSequencer()
      Get the java sequencer opened and ready to play music on the JJazzMidiOutDevice.

      In general you should use MusicController.acquireSequencer(Object lock), as it allows for access synchronization between various users.

      Returns:
    • getJavaInternalSynth

      public Synthesizer getJavaInternalSynth()
      The internal Java synth.
      Returns:
      Can be null if no java synth.
    • getDefaultJavaSynthPreferredSoundFontFile

      public File getDefaultJavaSynthPreferredSoundFontFile()
      The default internal synth soundfont/DLS file stored in the Preferences.
      Returns:
      Can be null if no soundfont/DLS file set.
    • resetJavaInternalSynth

      public void resetJavaInternalSynth()
      This unloads all previously loaded instruments in the internal Java Synth.

      Note that the builtin GM instruments remain.

    • editMidiFileWithExternalEditor

      public void editMidiFileWithExternalEditor(File midiFile) throws IOException
      Edit the specified file with the registered editor, and wait for editor to exit.
      Parameters:
      midiFile -
      Throws:
      IOException
    • setExternalMidiEditor

      public void setExternalMidiEditor(File editorFile)
      Set the path to an external Midi file editor.
      Parameters:
      editorFile -
    • getExternalMidiEditor

      public File getExternalMidiEditor()
      Get the path to an external Midi file editor.

      Returns:
      Can be an empty path
    • loadSoundbankFileOnSynth

      public boolean loadSoundbankFileOnSynth(File f, boolean silentRun)
      Try to load the soundfont2 (or DLS) file in the default Java synth.

      Previous soundbank instruments are unloaded first. This triggers a specific task since loading a soundfont can take some time.

      Parameters:
      f -
      silentRun - If false wait until completion of the task and show progress bar. If true nothing is shown and method immediatly returns true.
      Returns:
      true If success. If silentRun=true always return true.
    • setDefaultOutDevice

      public void setDefaultOutDevice(MidiDevice md) throws MidiUnavailableException
      Connect the output of JJazzMidiOut device to this device.

      Fire a PROP_MIDI_OUT property chane event.property change event if device is modified.

      Parameters:
      md - Can be null.
      Throws:
      MidiUnavailableException - If exception occurs, the default OUT device is unchanged.
    • closeDefaultOutDevice

      public void closeDefaultOutDevice()
      Close the default out device.

      Special handling of the Java Internal Synth.

    • setDefaultInDevice

      public void setDefaultInDevice(MidiDevice md) throws MidiUnavailableException
      Set the default MIDI In device.

      Fire a PROP_MIDI_IN property change event if device is modified.

      Parameters:
      md - Can be null.
      Throws:
      MidiUnavailableException - If exception occurs, the default IN device is unchanged.
    • closeDefaultInDevice

      public void closeDefaultInDevice()
    • closeAll

      public void closeAll()
      Close default In and Out devices.
    • setThruMode

      public void setThruMode(boolean b)
      Enable/Disable redirection of MIDI in to out (MIDI thru).

      Fire the PROP_MIDI_THRU property change event.

      Parameters:
      b - Enable if true, disable if false.
    • isThruMode

      public boolean isThruMode()
      Returns:
      True if thru mode is enabled.
    • panic

      public void panic()
      The Midi panic method.

      Send ALL_NOTES_OFF + SUSTAIN OFF + RESET_ALL_CONTROLLERS on all channels on the default JJazz midi out device.

    • getMasterVolumeFactor

      public float getMasterVolumeFactor()
      Returns:
      the masterVolumeFactor A value between 0 and 2. Default is 1.
    • setMasterVolumeFactor

      public void setMasterVolumeFactor(float f)
      Set the master volume factor.

      All volume Midi messages are multiplicated by this factor.
      Fire the PROP_MASTER_VOL_FACTOR property chane event.

      Parameters:
      f - The master volume Factor to set. Must be between 0 and 2.
    • getMidiOutLogConfig

      public EnumSet<MidiFilter.ConfigLog> getMidiOutLogConfig()
      Get the default Jazz Midi Out device MidiFilter log config.

      Can be used to adjust Midi Out log settings, e.g: getMidiOutLogConfig().add(MidiFilter.ConfigLog.LOG_ALL_PASSED);

      Returns:
    • setMidiOutFiltering

      public void setMidiOutFiltering(boolean b)
      Filter out (discard) all Midi messages sent to Midi Out.

      Fire a PROP_MIDI_OUT_FILTERING property change event.

      Parameters:
      b - Filtering is ON is b is true, OFF otherwise.
    • isMidiOutFilteringOn

      public boolean isMidiOutFilteringOn()
      Returns:
      True if Midi out filtering is ON.
    • sendMidiMessagesOnJJazzMidiOut

      public void sendMidiMessagesOnJJazzMidiOut(MidiMessage... mms)
      Send the specified MidiMessages on the JJazzMidiOut device with timing -1 (immediate play).

      Midi volume messages are multiplicated by the master volume factor.

      Parameters:
      mms -
    • getMidiDevice

      public MidiDevice getMidiDevice(List<MidiDevice> midiDevices, String mdName)
      Find the MidiDevice whose Device.Info.name() is equals to mdName in the devices list.
      Parameters:
      midiDevices -
      mdName - Can be null
      Returns:
      Null if not found.
    • getVirtualMidiSynthDevice

      public MidiDevice getVirtualMidiSynthDevice()
      Get the VirtualMidiSynth MidiDevice, if present on a Windows system.
      Returns:
      Can be null.
    • addPropertyChangeListener

      public void addPropertyChangeListener(PropertyChangeListener l)
    • removePropertyChangeListener

      public void removePropertyChangeListener(PropertyChangeListener l)
    • addPropertyChangeListener

      public void addPropertyChangeListener(String propName, PropertyChangeListener l)
    • removePropertyChangeListener

      public void removePropertyChangeListener(String propName, PropertyChangeListener l)
    • getDeviceFriendlyName

      public String getDeviceFriendlyName(MidiDevice md)
      Get a friendly name for a MidiDevice.

      Remove any trailing "_MD" from the MidiDevice name. Also give a better name to "Gervill" Java internal synth. the Java default synth (sometimes "Gervill") to JAVA_INTERNAL_SYNTH_NAME. Use DeviceInfo.name otherwise.

      Parameters:
      md -
      Returns: