Class MidiSynth

java.lang.Object
org.jjazz.midi.api.MidiSynth
Direct Known Subclasses:
FavoriteMidiSynth, GM2Synth, GMSynth, GSSynth, XGSynth

public class MidiSynth extends Object
A MidiSynth is a collection of InstrumentBanks.

A MidiSynth contains at least one InstrumentBank with one instrument.

You can optionnaly specify if this MidiSynth is GM/GM2/XG/GS compatible, and indicate the base MidiAddress of the GM bank.

  • Constructor Details

    • MidiSynth

      public MidiSynth(String name, String manufacturer)
      Create an empty MidiSynth with no Midi standard compatibility, and no associated file.

      Parameters:
      name - If name contains comas (',') they are removed.
      manufacturer -
  • Method Details

    • hashCode

      public int hashCode()
      The method relies only on the name and file fields.
      Overrides:
      hashCode in class Object
      Returns:
    • equals

      public boolean equals(Object obj)
      The method relies only on the name and file fields.
      Overrides:
      equals in class Object
      Returns:
    • loadFromFile

      public static MidiSynth loadFromFile(File file) throws IOException
      Return the first non-empty MidiSynth found in the specified instrument definition file (.ins).

      Parameters:
      file -
      Returns:
      A MidiSynth associated to the input file
      Throws:
      IOException - If file access, or if no valid (non-empty) MidiSynth found in the file.
      See Also:
    • setCompatibility

      public void setCompatibility(Boolean isGMcompatible, Boolean isGM2compatible, Boolean isXGcompatible, Boolean isGScompatible)
      Set the compatibility of this MidiSynth with the Midi standards.

      No check is performed on the actual Instruments of this MidiSynth to control the validity of this compatibility.

      The following are automatically enforced:
      - If a synth is GM2/XG/GS compatible, then it is also GM compatible and GM bank base adress is set to MSB=LSB=0
      - If a synth is GS compatible, then it can't be GM2 nor XG compatible

      Parameters:
      isGMcompatible - If null parameter is ignored.
      isGM2compatible - If null parameter is ignored.
      isXGcompatible - If null parameter is ignored.
      isGScompatible - If null parameter is ignored.
    • isGMcompatible

      public boolean isGMcompatible()
    • isGM2compatible

      public boolean isGM2compatible()
    • isXGcompatible

      public boolean isXGcompatible()
    • isGScompatible

      public boolean isGScompatible()
    • addBank

      public void addBank(InstrumentBank<?> bank)
      Add a bank to this MidiSynth.

      This also assigns the bank's MidiSynth to this object.

      Parameters:
      bank -
    • getBanks

      public List<InstrumentBank<?>> getBanks()
    • getBank

      public InstrumentBank<?> getBank(String bankName)
      Find the bank whose name matches bankName (ignoring case).
      Parameters:
      bankName -
      Returns:
      Null if not found
    • getInstruments

      public List<Instrument> getInstruments()
      Get all the instruments from this MidiSynth.
      Returns:
    • getDrumsInstruments

      public List<Instrument> getDrumsInstruments()
      Get all the Drums/Percussion instruments from this MidiSynth.
      Returns:
      Returned instruments have isDrumKit() set to true.
    • getDrumsInstruments

      public List<Instrument> getDrumsInstruments(DrumKit kit, boolean tryHarder)
      Get all the drums/percussion instruments which match the specified DrumKit.
      Parameters:
      kit -
      tryHarder - If true and no instrument matched the specified kit, then try again but with a more flexible matching algorithm. Default implementation starts a second search using kit.Type.STANDARD.
      Returns:
      Can be empty.
    • getNonDrumsInstruments

      public List<Instrument> getNonDrumsInstruments()
      Get all the non Drums/Percussion instruments from this MidiSynth.
      Returns:
      Returned instruments have isDrumKit() set to false.
    • findInstruments

      public List<Instrument> findInstruments(String text)
      Find instruments in this object's banks which match the given string (ignoring case).
      Parameters:
      text -
      Returns:
    • contains

      public boolean contains(Instrument ins)
      Check whether this MidiSynth contains this instrument.
      Parameters:
      ins -
      Returns:
    • getInstrument

      public Instrument getInstrument(String patchName)
      Find an instrument with the specified patchName.
      Parameters:
      patchName -
      Returns:
      Null if instrument not found in the MidiSynth banks.
    • getInstrument

      public final Instrument getInstrument(MidiAddress addr)
      Find the instrument with the specified address.

      Parameters:
      addr -
      Returns:
      Null if instrument not found in the MidiSynth banks.
    • setGM1BankBaseMidiAddress

      public void setGM1BankBaseMidiAddress(MidiAddress ma)
      Set the base MidiAddress used to directly access the first instrument (Program Change=0) of the GM bank of this MidiSynth.

      GM standard does not define a GM bank select messages. The "old" way to access the GM sounds is to first send a Sysex message "Set GM Mode ON" then a Program Change message. But as most synths now have many banks, it's usually possible to directly access the GM sounds using bank select messages. This method lets you specify the GM bank select mechanism used by this synth.

      Examples:
      - On most Yamaha synths the GM bank can be directly accessed using LSB=0 and MSB=0.
      - On Roland JV-1080 the base GM bank address is MSB=81, LSB=3.

      Note that GM2/XG/GS compatible instruments are also GM-compatible and expect the GM bank to be at MSB=0 LSB=0.

      Parameters:
      ma - Must have Program Change==0.
      See Also:
    • getGM1BankBaseMidiAddress

      public MidiAddress getGM1BankBaseMidiAddress()
      Get the MidiAddress to be used to directly access the first instrument (piano) of the GM bank of this MidiSynth.

      IMPORTANT: value is meaningless if this MidiSynth is not GM-compatible.

      This method is required because synths can have a GM bank anywhere, eg the JV-1080 synth has its GM Bank Midi address at MSB=83, LSB=3.

      Returns:
      Can't be null. If not explicitly set, return by default new MidiAddress(0, 0, 0, MidiAddress.BankSelectMethod.MSB_LSB).
      See Also:
    • getGM1BankMidiAddress

      public MidiAddress getGM1BankMidiAddress(int programChange)
      Get the MidiAddress of the specified GM bank instrument.
      Parameters:
      programChange - Program change of the GM instrument
      Returns:
      Null if this MidiSynth is not GM-compatible
    • isGM1BankMidiAddress

      public boolean isGM1BankMidiAddress(MidiAddress addr)
      Return true if this MidiSynth is GM-compatible and the specified MidiAddress is part of the this synth'GM bank.
      Parameters:
      addr -
      Returns:
    • getMidiAddressMatchingCoverage

      public float getMidiAddressMatchingCoverage(InstrumentBank<?> bank)
      Get the percentage of MidiAddresses from the specified bank which match an instrument in this MidiSynth.
      Parameters:
      bank -
      Returns:
      A value between 0 and 1.
    • getInstruments

      public List<Instrument> getInstruments(Predicate<Instrument> tester)
      Get all the instruments which match the specified predicate.
      Parameters:
      tester -
      Returns:
    • getInstrumentsFromSubstitute

      public List<Instrument> getInstrumentsFromSubstitute(GM1Instrument sub)
      Get all the instruments whose substitute is sub.
      Parameters:
      sub - Can be null
      Returns:
    • getNbInstruments

      public int getNbInstruments()
      The total number of patches in the banks of this synth.
      Returns:
    • getFile

      public File getFile()
      The file used to create this MidiSynth.
      Returns:
      Can be null if instance was not created using the loadFromFile() method.
      See Also:
    • getName

      public String getName()
      Returns:
      the name
    • getManufacturer

      public String getManufacturer()
      Returns:
      the manufacturer
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • dump

      public void dump()
    • saveAsString

      public String saveAsString()
      Save this MidiSynth as a string so that it can be retrieved by loadFromString().

      Returns:
      A string "Name#:#FilePath". FilePath equals "NOT_SET" if no file associated.
      See Also:
    • loadFromString

      public static MidiSynth loadFromString(String s)
      Get the MidiSynth corresponding to the string produced by saveAsString().

      Parameters:
      s -
      Returns:
      Null if no MidiSynth could be found corresponding to s.
      See Also: