Class Song
- All Implemented Interfaces:
PropertyChangeListener
,Serializable
,EventListener
,ClsChangeListener
,SgsChangeListener
Contents are a chord leadsheet, the related song structure, some parameters and some optional client properties.
Songs can be created using the SongFactory methods.
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Fired when the close() method is called.static final String
static final String
This property changes each time the song is modified (oldValue=false, newValue=true), or saved (oldValue=true, newValue=false) or Song.setSaveNeeded(false) is called (oldValue=null, newValue=false)static final String
Fired each time the musical content of the song is modified.static final String
static final String
newValue = new size in bars.static final String
static final String
static final String
static final String
If a user phrase is removed: oldValue=name_of_removed_phrase and newValue=removed_phrase.
If a user phrase is added, oldValue=null and newValue=name_of_new_phrasestatic final String
An existing phrase was replaced by another. oldValue=old_phrase, newValue=name_of_phrase. -
Method Summary
Modifier and TypeMethodDescriptionvoid
void
addPropertyChangeListener
(String propertyName, PropertyChangeListener l) void
void
void
Some change events might need to be authorized by all listeners before being processed by chordLeadSheetChanged().void
Some change events might need to be authorized by all listeners before being processed by songStructureChanged().void
Process the change.void
close
(boolean releaseRhythmResources) To be called to cleanup the song when song will not be used anymore.The comments associated to this song.getFile()
The file where this song is stored.getName()
The song name.int
getSize()
Convenience method which delegates to getSongStructure().getSizeInBars().getTags()
int
getTempo()
Get the preferred tempo for this song.getUserPhrase
(String name) Get the user phrase associated to specified name.Get all the names of the user phrases.boolean
isClosed()
boolean
void
void
void
removePropertyChangeListener
(String propertyName, PropertyChangeListener l) void
removeUserPhrase
(String name) Remove the user phrase associated to name.void
void
renameUserPhrase
(String name, String newName) Rename a user phrase.void
saveToFile
(File songFile, boolean isCopy) Save this song to a file (XML format).boolean
saveToFileNotify
(File f, boolean isCopy) Same as SaveToFile but notify user if problem.void
setComments
(String newComments) Set the comments.void
Set the file from which the song can be read/written.final void
Set the song name.void
setSaveNeeded
(boolean b) Set the value of the saveNeeded property.void
Set the list of String tags associated to this song, e.g.final void
setTempo
(int newTempo) Set the preferred tempo for this song.void
setUserPhrase
(String name, Phrase p) Set the user phrase for the specified name.void
Process the change.toString()
-
Field Details
-
PROP_NAME
- See Also:
-
PROP_COMMENTS
- See Also:
-
PROP_TAGS
- See Also:
-
PROP_TEMPO
- See Also:
-
PROP_VETOABLE_PHRASE_NAME
- See Also:
-
PROP_SIZE_IN_BARS
newValue = new size in bars. OldValue=old size in bars- See Also:
-
PROP_VETOABLE_USER_PHRASE
If a user phrase is removed: oldValue=name_of_removed_phrase and newValue=removed_phrase.
If a user phrase is added, oldValue=null and newValue=name_of_new_phrase- See Also:
-
PROP_VETOABLE_USER_PHRASE_CONTENT
An existing phrase was replaced by another. oldValue=old_phrase, newValue=name_of_phrase.- See Also:
-
PROP_CLOSED
Fired when the close() method is called.- See Also:
-
PROP_MODIFIED_OR_SAVED_OR_RESET
This property changes each time the song is modified (oldValue=false, newValue=true), or saved (oldValue=true, newValue=false) or Song.setSaveNeeded(false) is called (oldValue=null, newValue=false)- See Also:
-
PROP_MUSIC_GENERATION
Fired each time the musical content of the song is modified.OldValue=the property name or ClsActionEvent/SgsActionEvent actionId that triggered the musical change.
NewValue=the optional associated dataUse PROP_MODIFIED_OR_SAVED_OR_RESET to get notified of any song change, including non-musical ones like tempo change, phrase name change, etc.
- See Also:
-
-
Method Details
-
getClientProperties
-
renameUserPhrase
Rename a user phrase.Fire a PROP_VETOABLE_PHRASE_NAME change event (actually this property change event should never been vetoed, but this allows caller to use a single vetoable listener for all user phrase events).
- Parameters:
name
- Must be the name of an existing phrasenewName
-
-
setUserPhrase
Set the user phrase for the specified name.If a user phrase was already associated to name, it's replaced. Fire a VeotableChange PROP_VETOABLE_USER_PHRASE if no phrase is replaced, otherwise use PROP_VETOABLE_USER_PHRASE_CONTENT. Actually the possibility of a veto is only when a new phrase is added (e.g. if MidiMix does not have an available Midi channel). Other user phrase PROP_ events for simplicity only (one listener required).
This song will listen to p's changes and fire a PROP_MODIFIED_OR_SAVED_OR_RESET change event when a non-adjusting change is made.
- Parameters:
name
- Can't be blank.p
- Can't be null. No defensive copy is done, p is directly reused. No control is done on the phrase consistency Vs the song.- Throws:
PropertyVetoException
- If no Midi channel available for the user phrase- See Also:
-
removeUserPhrase
Remove the user phrase associated to name.Fire a PROP_VETOABLE_USER_PHRASE event.
- Parameters:
name
-- Returns:
- The removed phrase or null
-
getUserPhraseNames
Get all the names of the user phrases.- Returns:
- Can't be null.
-
getUserPhrase
Get the user phrase associated to specified name.Returned phrase might be longer than the song.
The song listens to the returned phrase so that if a significant change (non-adusting) is made to it, the song will fire a PROP_MODIFIED_OR_SAVED_OR_RESET change event.
- Parameters:
name
-- Returns:
- Null if no phrase associated to name. The Phrase channel should be ignored.
-
getChordLeadSheet
-
getSongStructure
-
getSize
public int getSize()Convenience method which delegates to getSongStructure().getSizeInBars().- Returns:
-
getTempo
public int getTempo()Get the preferred tempo for this song.- Returns:
-
setTempo
public final void setTempo(int newTempo) Set the preferred tempo for this song.Fire a PROP_TEMPO property change event.
- Parameters:
newTempo
-
-
setTags
Set the list of String tags associated to this song, e.g. "rock", "dance-oriented", etc...Fire a PROP_TAGS property change events.
- Parameters:
newTags
- Must not be null but can be an empty list. Tags are space-trimmed and converted to lower case.
-
getTags
- Returns:
- List can be empty if not tags. Tags are lowercase.
-
getName
The song name.- Returns:
-
setName
Set the song name.Fire a PROP_NAME property change event.
- Parameters:
newName
- A non-empty string.
-
close
public void close(boolean releaseRhythmResources) To be called to cleanup the song when song will not be used anymore.Fire a PROP_CLOSED property change event.
- Parameters:
releaseRhythmResources
- True if the method should also call releaseResources() for each used rhythm.
-
isClosed
public boolean isClosed()- Returns:
- True if close() has been called.
-
getComments
The comments associated to this song.- Returns:
- Can be an empty String.
-
setComments
Set the comments.Fire the PROP_COMMENTS change event.
- Parameters:
newComments
-
-
getFile
The file where this song is stored.- Returns:
- Can be null for example if it's a builtin song or created programmatically.
-
setFile
Set the file from which the song can be read/written.- Parameters:
f
- Can be null.
-
saveToFileNotify
Same as SaveToFile but notify user if problem.- Parameters:
f
-isCopy
-- Returns:
- False if problem
-
saveToFile
Save this song to a file (XML format).Song's file and name is set to f and f's name. Fire a PROP_MODIFIED_OR_SAVED_OR_RESET property change event with oldValue=true and newValue=false.
- Parameters:
songFile
-isCopy
- Indicate that the save operation if for a copy, ie just perform the save operation and do nothing else (song name is not set, etc.)- Throws:
IOException
- See Also:
-
isSaveNeeded
public boolean isSaveNeeded()- Returns:
- True if song has some unsaved changes.
-
setSaveNeeded
public void setSaveNeeded(boolean b) Set the value of the saveNeeded property.Fire a PROP_MODIFIED_OR_SAVED_OR_RESET change event.
- Parameters:
b
-
-
addUndoableEditListener
-
removeUndoableEditListener
-
addPropertyChangeListener
-
addPropertyChangeListener
-
removePropertyChangeListener
-
removePropertyChangeListener
-
addVetoableChangeListener
-
removeVetoableChangeListener
-
toString
-
propertyChange
- Specified by:
propertyChange
in interfacePropertyChangeListener
-
authorizeChange
Description copied from interface:ClsChangeListener
Some change events might need to be authorized by all listeners before being processed by chordLeadSheetChanged().- Specified by:
authorizeChange
in interfaceClsChangeListener
- 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.
-
chordLeadSheetChanged
Description copied from interface:ClsChangeListener
Process the change.Note that this method might be called outside of the EDT.
- Specified by:
chordLeadSheetChanged
in interfaceClsChangeListener
-
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
-