Class InstrumentBank<T extends Instrument>

java.lang.Object
org.jjazz.midi.api.InstrumentBank<T>
Type Parameters:
T -
Direct Known Subclasses:
GM1Bank, GM2Bank, GSBank, GSBank_SC88Pro, NotSetBank, XGBank

public class InstrumentBank<T extends Instrument> extends Object
A set of Instruments grouped in a bank.

It must be guaranteed that Instruments have a unique patch name in the bank.

  • Constructor Details

    • InstrumentBank

      public InstrumentBank(String name, int msb, int lsb)
      Create an empty bank with BankSelectMethod.MSB_LSB.
      Parameters:
      name -
      msb -
      lsb -
    • InstrumentBank

      public InstrumentBank(String name, int msb, int lsb, MidiAddress.BankSelectMethod m)
      Create an InstrumentBank.
      Parameters:
      name -
      msb - The default Most Significant Byte or "Control 0".
      lsb - The default Least Significant Byte or "Control 32"
      m - The default bank select method. Can't be null.
  • Method Details

    • setMidiSynth

      public void setMidiSynth(MidiSynth synth)
      Associate a MidiSynth to this bank.

      IMPORTANT: this method can be called only once (because a bank can't be assigned to 2 different MidiSynths).

      It is the responsibility of the specified MidiSynth to add the bank.

      Parameters:
      synth - A non null value, the MidiSynth this InstrumentBank belongs to
    • getMidiSynth

      public MidiSynth getMidiSynth()
      The MidiSynth this bank belongs to.
      Returns:
      Can be null
    • getDefaultBankSelectMethod

      public MidiAddress.BankSelectMethod getDefaultBankSelectMethod()
      The default BankSelect method.

      Note that individual instruments belonging to this bank can have a different BankSelect method.

      Returns:
      Can't be null.
    • getDefaultBankSelectMSB

      public int getDefaultBankSelectMSB()
      The default BankSelect MSB (Midi control #0).

      Note that individual instruments belonging to this bank can have a different BankSelect MSB.

      Returns:
      [0;127] Bank Select Most Significant Byte (MIdi control #0).
    • getDefaultBankSelectLSB

      public int getDefaultBankSelectLSB()
      The default BankSelect LSB (Midi control #32).

      Note that individual instruments belonging to this bank can have a different BankSelect LSB.

      Returns:
      [0;127] Bank Select Most Significant Byte (Midi control #32)
    • addInstrument

      public void addInstrument(T instrument)
      Add the instrument to the bank.

      The method sets the instrument's bank to this bank. It is the responsibility of the caller to check that instrument's patchName is not used twice in the bank.

      Parameters:
      instrument -
    • removeInstrument

      public void removeInstrument(T instrument)
      Remove an Instrument from this bank.
      Parameters:
      instrument -
    • getKeyMaps

      public List<DrumKit.KeyMap> getKeyMaps()
      Get all the DrumKit.KeyMaps used by this bank.
      Returns:
    • getTypes

      public List<DrumKit.Type> getTypes()
      Get all the DrumKit.Types used by this bank.
      Returns:
    • clear

      public void clear()
      Empty the bank.
    • getSize

      public int getSize()
      The number of instruments in the bank.
      Returns:
    • getName

      public String getName()
      The name of the bank.
      Returns:
    • getIndex

      public int getIndex(Instrument ins)
      The index of the specified instrument.
      Parameters:
      ins -
      Returns:
      -1 if not found
    • getInstruments

      public List<T> getInstruments()
      Get all the instruments of the bank.
      Returns:
    • getNextInstrument

      public T getNextInstrument(Instrument ins)
      The next instrument in the database after the specified instrument.

      Return the 1st element of the database if ins is the last element.

      Parameters:
      ins -
      Returns:
    • getPreviousInstrument

      public T getPreviousInstrument(Instrument ins)
      The previous instrument in the database after the specified instrument.

      Return the 1st element of the database if ins is the last element.

      Parameters:
      ins -
      Returns:
    • getInstrument

      public T getInstrument(String patchName)
      Get the instrument whose patchName matches (ignoring case) the specified name.
      Parameters:
      patchName -
      Returns:
      null if not found
    • getInstrument

      public T getInstrument(MidiAddress address)
      Get the instrument at the specified MidiAddress.
      Parameters:
      address -
      Returns:
      null if not found
    • getInstrument

      public T getInstrument(int index)
      Get the instrument which is specified index in the bank.
      Parameters:
      index -
      Returns:
    • getNonDrumsInstruments

      public List<T> getNonDrumsInstruments()
      Get the non Drums/Percussion instruments.
      Returns:
      Returned instruments have isDrumKit() set to false.
    • getDrumsInstruments

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

      public List<T> 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.
    • getInstrumentsFromSubstitute

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

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

      public List<T> getInstrumentsFromFamily(Family f)
      Get the instruments whose substitute's family is f.
      Parameters:
      f - Can't be null
      Returns:
    • findInstruments

      public List<T> findInstruments(String text)
      Find the instruments whose patchName contains specified text (ignoring case).
      Parameters:
      text -
      Returns:
    • toString

      public String toString()
      Overrides:
      toString in class Object