Class MidiSynth
- Direct Known Subclasses:
FavoriteMidiSynth
,GM2Synth
,GMSynth
,GSSynth
,XGSynth
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Required by the MidiSynth serialization process : an implementation must be available in the global lookup. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addBank
(InstrumentBank<?> bank) Add a bank to this MidiSynth.boolean
contains
(Instrument ins) Check whether this MidiSynth contains this instrument.void
dump()
boolean
The method relies only on the name and file fields.findInstruments
(String text) Find instruments in this object's banks which match the given string (ignoring case).Find the bank whose name matches bankName (ignoring case).List<InstrumentBank<?>>
getBanks()
Get all the Drums/Percussion instruments from this MidiSynth.getDrumsInstruments
(DrumKit kit, boolean tryHarder) Get all the drums/percussion instruments which match the specified DrumKit.getFile()
The file used to create this MidiSynth.Get the MidiAddress to be used to directly access the first instrument (piano) of the GM bank of this MidiSynth.getGM1BankMidiAddress
(int programChange) Get the MidiAddress of the specified GM bank instrument.getInstrument
(String patchName) Find an instrument with the specified patchName.final Instrument
getInstrument
(MidiAddress addr) Find the instrument with the specified address.Get all the instruments from this MidiSynth.getInstruments
(Predicate<Instrument> tester) Get all the instruments which match the specified predicate.Get all the instruments whose substitute is sub.float
Get the percentage of MidiAddresses from the specified bank which match an instrument in this MidiSynth.getName()
int
The total number of patches in the banks of this synth.Get all the non Drums/Percussion instruments from this MidiSynth.int
hashCode()
The method relies only on the name and file fields.boolean
Return true if this MidiSynth is GM-compatible and the specified MidiAddress is part of the this synth'GM bank.boolean
boolean
boolean
boolean
static MidiSynth
loadFromFile
(File file) Return the first non-empty MidiSynth found in the specified instrument definition file (.ins).static MidiSynth
Get the MidiSynth corresponding to the string produced by saveAsString().Save this MidiSynth as a string so that it can be retrieved by loadFromString().void
setCompatibility
(Boolean isGMcompatible, Boolean isGM2compatible, Boolean isXGcompatible, Boolean isGScompatible) Set the compatibility of this MidiSynth with the Midi standards.void
Set the base MidiAddress used to directly access the first instrument (Program Change=0) of the GM bank of this MidiSynth.toString()
-
Constructor Details
-
MidiSynth
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. -
equals
The method relies only on the name and file fields. -
loadFromFile
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
Add a bank to this MidiSynth.This also assigns the bank's MidiSynth to this object.
- Parameters:
bank
-
-
getBanks
-
getBank
Find the bank whose name matches bankName (ignoring case).- Parameters:
bankName
-- Returns:
- Null if not found
-
getInstruments
Get all the instruments from this MidiSynth.- Returns:
-
getDrumsInstruments
Get all the Drums/Percussion instruments from this MidiSynth.- Returns:
- Returned instruments have isDrumKit() set to true.
-
getDrumsInstruments
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
Get all the non Drums/Percussion instruments from this MidiSynth.- Returns:
- Returned instruments have isDrumKit() set to false.
-
findInstruments
Find instruments in this object's banks which match the given string (ignoring case).- Parameters:
text
-- Returns:
-
contains
Check whether this MidiSynth contains this instrument.- Parameters:
ins
-- Returns:
-
getInstrument
Find an instrument with the specified patchName.- Parameters:
patchName
-- Returns:
- Null if instrument not found in the MidiSynth banks.
-
getInstrument
Find the instrument with the specified address.- Parameters:
addr
-- Returns:
- Null if instrument not found in the MidiSynth banks.
-
setGM1BankBaseMidiAddress
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
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
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
Return true if this MidiSynth is GM-compatible and the specified MidiAddress is part of the this synth'GM bank.- Parameters:
addr
-- Returns:
-
getMidiAddressMatchingCoverage
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
Get all the instruments which match the specified predicate.- Parameters:
tester
-- Returns:
-
getInstrumentsFromSubstitute
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
The file used to create this MidiSynth.- Returns:
- Can be null if instance was not created using the loadFromFile() method.
- See Also:
-
getName
- Returns:
- the name
-
getManufacturer
- Returns:
- the manufacturer
-
toString
-
dump
public void dump() -
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
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:
-