Class MidiMix
- All Implemented Interfaces:
PropertyChangeListener
,VetoableChangeListener
,Serializable
,EventListener
,SgsChangeListener
The object manages the solo functionality between the InstrumentMixes.
A Song can be associated to the MidiMix so that InstrumentMixes are kept up to date with song's songStructure and user phrase changes.
If MidiMix is modified the corresponding property change event is fired (e.g. PROP_INSTRUMENT_MUTE) then the PROP_MODIFIED_OR_SAVED_OR_RESET change event is also fired.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
static final int
static final String
oldValue=channel, newValue=true/false.static final String
New or removed InstrumentMix.static final String
A drums instrument has changed with different keymap.static final String
oldValue=InstumentMix, newValue=mute boolean state.static final String
oldValue=InstumentMix, newValue=transposition value.static final String
oldValue=InstumentMix, newValue=velocity shift value.static final String
This property changes when the MidiMix is modified (false->true) or saved (true->false).static final String
Fired each time a MidiMix parameter which impacts music generation is modified, like instrument transposition.static final String
A RhythmVoice has replaced another one, e.g. this is used to change the name of a user track.static final String
The channel of a RhythmVoice has been changed by user. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfinal void
addInstrumentMixes
(MidiMix fromMm, Rhythm r) Add RhythmVoices (of Rhythm instances only, UserRhythmVoices are skipped) and InstrumentMixes copies from mm into this MidiMix.void
void
addPropertyChangeListener
(String propertyName, PropertyChangeListener l) void
void
Some change events might need to be authorized by all listeners before being processed by songStructureChanged().void
checkConsistency
(Song sg, boolean fullCheck) Check if this MidiMix is consistent with the specified song.int
findFreeChannel
(boolean findDrumsChannel) Return a free channel to be used in this MidiMix.int
Find the channel corresponding to the specified InstrumentMix.int
getChannel
(RhythmVoice rvKey) Get the Midi channel associated to the specified RhythmVoice.getChannelsNeedingDrumsRerouting
(HashMap<Integer, Instrument> mapChannelNewIns) Get the channels which normally need drums rerouting.Get a deep copy of this MidiMix.The channels which should be rerouted to the GM Drums channel.getFile()
The file where this object is stored.getInstrumentMix
(int channel) Get the instrumet mix for the specified channel.Get the instrumet mix for the specified RhythmVoice.The non-null instrument mixes ordered by channel.All InstrumentMixes ordered by channel.getRhythmVoice
(int channel) Get the RhythmVoice for the specified Midi channel.Get all the RhythmVoices corresponding to the non-null InstrumentMixes.getSong()
Get the list of used channels in this MidiMix.Get the list of used channels for specified rhythm in this MidiMix.Return the list user phrase Midi channels.getUserRhythmVoice
(String name) Get the user phrase RhythmVoice key for the specified name.Return the subset of RhythmVoices which are UserRhythmVoices.void
Import InstrumentMixes from mm into this object.static MidiMix
loadFromFile
(File f) boolean
needSave()
void
void
void
removePropertyChangeListener
(String propertyName, PropertyChangeListener l) void
void
replaceRhythmVoice
(RhythmVoice oldRv, RhythmVoice newRv) Replace an existing RhythmVoice by a new one.void
saveToFile
(File f, boolean isCopy) Save this MidiMix to a file.boolean
saveToFileNotify
(File f, boolean isCopy) Same as saveToFile() but notify user if problems.void
setDrumsReroutedChannel
(boolean b, int channel) Enable or disable the rerouting of specified channel to GM Drums channel.void
void
setInstrumentMix
(int channel, RhythmVoice rvKey, InstrumentMix insMix) Assign an InstrumentMix to a midi channel and to a key.void
setRhythmVoiceChannel
(RhythmVoice rv, int newChannel) Change the channel of a RhythmVoice.final void
Associate a song to this MidiMix : listen to song changes to keep this MidiMix consistent.void
Process the change.toString()
void
-
Field Details
-
MIX_FILE_EXTENSION
- See Also:
-
PROP_CHANNEL_INSTRUMENT_MIX
New or removed InstrumentMix.OldValue=the old InstrumentMix, newValue=channel
- See Also:
-
PROP_CHANNEL_DRUMS_REROUTED
oldValue=channel, newValue=true/false.- See Also:
-
PROP_INSTRUMENT_MUTE
oldValue=InstumentMix, newValue=mute boolean state.- See Also:
-
PROP_DRUMS_INSTRUMENT_KEYMAP
A drums instrument has changed with different keymap.oldValue=channel, newValue=old keymap (may be null)
- See Also:
-
PROP_INSTRUMENT_TRANSPOSITION
oldValue=InstumentMix, newValue=transposition value.- See Also:
-
PROP_INSTRUMENT_VELOCITY_SHIFT
oldValue=InstumentMix, newValue=velocity shift value.- See Also:
-
PROP_RHYTHM_VOICE
A RhythmVoice has replaced another one, e.g. this is used to change the name of a user track.oldValue=old RhythmVoice, newValue=new RhythmVoice
- See Also:
-
PROP_RHYTHM_VOICE_CHANNEL
The channel of a RhythmVoice has been changed by user.oldValue=old channel, newValue=new channel
- See Also:
-
PROP_MODIFIED_OR_SAVED
This property changes when the MidiMix is modified (false->true) or saved (true->false).- See Also:
-
PROP_MUSIC_GENERATION
Fired each time a MidiMix parameter which impacts music generation is modified, like instrument transposition.OldValue=the property name that triggers the musical change, newValue=optional associated data.
Use PROP_MODIFIED_OR_SAVED to get notified of any MidiMix change, including non-musical ones like track mute change, etc.
- See Also:
-
NB_AVAILABLE_CHANNELS
public static final int NB_AVAILABLE_CHANNELS- See Also:
-
-
Constructor Details
-
MidiMix
public MidiMix()Create an empty MidiMix. -
MidiMix
create an empty MidiMix and associate it to specified song.- Parameters:
s
-
-
-
Method Details
-
getDeepCopy
Get a deep copy of this MidiMix.Mutable internal objects are deeply copied, e.g. InstrumentMixes.
Not copied: undoableListeners, isSaveNeeded.- Returns:
-
setSong
Associate a song to this MidiMix : listen to song changes to keep this MidiMix consistent.Listen to rhythms and user phrases changes.
- Parameters:
sg
- Can be null.- Throws:
IllegalArgumentException
- If checkConsistency(sg, false) fails.
-
checkConsistency
Check if this MidiMix is consistent with the specified song.Check that all RhythmVoices of this MidiMix belong to song rhythms. Check user tracks consistency between midiMix and song.
- Parameters:
sg
-fullCheck
- If true also check that all song RhythmVoices are used in this MidiMix.- Throws:
SongCreationException
- If an inconsistency is detected
-
getSong
-
getUserChannels
Return the list user phrase Midi channels.- Returns:
-
getUserRhythmVoices
Return the subset of RhythmVoices which are UserRhythmVoices.- Returns:
-
getUserRhythmVoice
Get the user phrase RhythmVoice key for the specified name.- Parameters:
name
-- Returns:
- Null if not found
-
setInstrumentMix
Assign an InstrumentMix to a midi channel and to a key.Replace any existing InstrumentMix associated to the midi channel. The solo and "drums rerouted channel" status are reset to off for the channel.
Fire a PROP_CHANNEL_INSTRUMENT_MIX change event for this channel, and one UndoableEvent.- Parameters:
channel
- A valid midi channel number.rvKey
- Can be null if insMix is also null. If a song is set, must be consistent with its rhythms and user phrases. Can't be a RhythmVoiceDelegate.insMix
- Can be null if rvKey is also null.- Throws:
IllegalArgumentException
- if insMix is already part of this MidiMix for a different channel, or if rvKey is a RhythmVoiceDelegate.
-
replaceRhythmVoice
Replace an existing RhythmVoice by a new one.Fire a PROP_RHYTHM_VOICE and an undoable event.
- Parameters:
oldRv
- Must be a RhythmVoice used by this MidiMix.newRv
- Must not be already used by this MidiMix.
-
setRhythmVoiceChannel
Change the channel of a RhythmVoice.Fire a PROP_RHYTHM_VOICE_CHANNEL and an undoable event.
- Parameters:
rv
- Must be a RhythmVoice used by this MidiMix.newChannel
- Must be a free channel
-
getInstrumentMix
Get the instrumet mix for the specified channel.- Parameters:
channel
- A valid midi channel number- Returns:
- The InstrumentMix assigned to the specified Midi channel, or null if no InstrumentMix for this channel.
-
getInstrumentMix
Get the instrumet mix for the specified RhythmVoice.- Parameters:
rv
- If it's a RhythmVoiceDelegate, return the channel associated to its source RhythmVoice.- Returns:
- The InstrumentMix associated to rv. Null if no InstrumentMix found.
-
getChannel
Find the channel corresponding to the specified InstrumentMix.- Parameters:
im
-- Returns:
- -1 if InstrumentMix not found.
-
geRhythmVoice
- Parameters:
im
-- Returns:
- null if InstrumentMix not found.
-
getRhythmVoice
Get the RhythmVoice for the specified Midi channel.- Parameters:
channel
-- Returns:
- The RhythmVoice key corresponding to specified channel. Can be null.
-
getChannel
Get the Midi channel associated to the specified RhythmVoice.- Parameters:
rvKey
- If it's a RhythmVoiceDelegate, return the channel associated to its source RhythmVoice.- Returns:
- -1 if key not found.
-
getUsedChannels
Get the list of used channels in this MidiMix.- Returns:
- The list of Midi channel numbers for which a non-null InstrumentMix is assigned.
-
getUsedChannels
Get the list of used channels for specified rhythm in this MidiMix.- Parameters:
r
- If null return all used channels. If r is an AdaptedRhythm, returns the channels from it source rhythm.- Returns:
- The list of Midi channel numbers for rhythm r and for which a non-null InstrumentMix is assigned.
-
getUnusedChannels
- Returns:
- The list of Midi channel numbers for which no InstrumentMix is assigned.
-
getRhythmVoices
Get all the RhythmVoices corresponding to the non-null InstrumentMixes.Returned list includes UserRhythmVoice instances as well. The list does not contain RhythmVoiceDelegate instances.
- Returns:
-
getDrumsReroutedChannels
The channels which should be rerouted to the GM Drums channel.- Returns:
- Note that returned list is not ordered. Can be empty.
-
setDrumsReroutedChannel
public void setDrumsReroutedChannel(boolean b, int channel) Enable or disable the rerouting of specified channel to GM Drums channel.If enabled, the related InstrumentMix/Settings will be disabled, and vice versa.
- Parameters:
b
-channel
-
-
getChannelsNeedingDrumsRerouting
Get the channels which normally need drums rerouting.A channel needs rerouting if all the following conditions are met:
0/ InsMix at MidiConst.CHANNEL_DRUMS has its instrument Midi message enabled
1/ channel != MidiConst.CHANNEL_DRUMS
2/ rv.isDrums() == true and rerouting is not already enabled
3/ instrument (or new instrument if one is provided in the mapChannelNewIns parameter) is the VoidInstrument- Parameters:
mapChannelNewIns
- Optional channel instruments to be used for the exercise. Ignored if null. See OutputSynth.getNeedFixInstruments().- Returns:
- Can be empty
-
findFreeChannel
public int findFreeChannel(boolean findDrumsChannel) Return a free channel to be used in this MidiMix.Try to keep channels in one section above the drums channel reserved to Drums. If not enough channels extend to channel below the drums channel.
- Parameters:
findDrumsChannel
- If true try to use CHANNEL_DRUMS if it is available.- Returns:
- -1 if no channel found
-
addInstrumentMixes
Add RhythmVoices (of Rhythm instances only, UserRhythmVoices are skipped) and InstrumentMixes copies from mm into this MidiMix.Copies have solo/drumsRerouting set to OFF. Method uses findFreeChannel() to allocate the new channels of mm if they are not free in this MidiMix.
The operation will fire UndoableEvent edits.
- Parameters:
fromMm
-r
- If non null, copy fromMm instrumentMixes only if they belong to rhythm r (if r is an AdaptedRhythm, use its source rhythm).- Throws:
MidiUnavailableException
- If not enough channels available to accommodate mm instruments.
-
getFile
The file where this object is stored.- Returns:
- Null if not set.
-
setFile
-
importInstrumentMixes
Import InstrumentMixes from mm into this object.Import is first done on matching RhythmVoices from the same rhythm. Then import only when RvTypes match. For UserRhythmVoices import is done only if name matches.
Create new copy instances of Instruments Mixes with solo OFF.The operation will fire UndoableEvent(s).
- Parameters:
mm
-
-
needSave
public boolean needSave()- Returns:
- True if MidiMix has some unsaved changes.
-
saveToFileNotify
Same as saveToFile() but notify user if problems.- Parameters:
f
-isCopy
-- Returns:
- False if a problem occured
-
saveToFile
Save this MidiMix to a file.This will fire a PROP_MODIFIED_OR_SAVED change event (true=>false).
- Parameters:
f
-isCopy
- Indicate that we save a copy, ie perform the file save but nothing else (eg no PROP_MODIFIED_OR_SAVED state change)- Throws:
IOException
-
getInstrumentMixesPerChannel
All InstrumentMixes ordered by channel.- Returns:
- A 16 items list, one instrumentMix per channel (some items can be null)
-
getInstrumentMixes
The non-null instrument mixes ordered by channel.- Returns:
- Can be an empty list.
-
addUndoableEditListener
-
removeUndoableEditListener
-
addPropertyChangeListener
-
removePropertyChangeListener
-
addPropertyChangeListener
-
removePropertyChangeListener
-
toString
-
toDumpString
-
loadFromFile
- Parameters:
f
-- Returns:
- Null if MidiMix could not be created for some reason.
- Throws:
IOException
- If problem occured while reading file
-
authorizeChange
Description copied from interface:SgsChangeListener
Some change events might need to be authorized by all listeners before being processed by songStructureChanged().- Specified by:
authorizeChange
in interfaceSgsChangeListener
- Parameters:
e
- The change to authorize.- Throws:
UnsupportedEditException
- Listener shall throw this exception if change is not acceptable. Exception message might be shown to user to explain the problem.
-
songStructureChanged
Description copied from interface:SgsChangeListener
Process the change.Note that this method might be called outside of the EDT.
- Specified by:
songStructureChanged
in interfaceSgsChangeListener
-
vetoableChange
- Specified by:
vetoableChange
in interfaceVetoableChangeListener
- Throws:
PropertyVetoException
-
propertyChange
- Specified by:
propertyChange
in interfacePropertyChangeListener
-