Class SongFactory

java.lang.Object
org.jjazz.song.api.SongFactory
All Implemented Interfaces:
PropertyChangeListener, EventListener

public class SongFactory extends Object implements PropertyChangeListener
Manage the creation and the registration of the songs.

All songs created by this factory are automatically registered. Registered songs are unregistered when song is closed.

  • Method Details

    • getInstance

      public static SongFactory getInstance()
    • getRegisteredSongs

      public Set<Song> getRegisteredSongs()
      Returns:
      An unmodifiable set of the songs registered by this factory.
    • registerSong

      public void registerSong(Song sg)
      Register a song if it was not created by this SongFactory.
      Parameters:
      sg -
    • getNewSongName

      public String getNewSongName(String baseName)
      Provide a new song name which is not used by any currently opened song.
      Parameters:
      baseName - Can't be blank
      Returns:
    • unregisterSong

      public void unregisterSong(Song song)
      Remove a song from the list returned by getRegisteredSong().
      Parameters:
      song -
    • findSong

      public Song findSong(SongStructure sgs)
      Find in the created song the first one which uses the specified SongStructure.
      Parameters:
      sgs -
      Returns:
    • findSong

      public Song findSong(ChordLeadSheet cls)
      Find in the created song the first one which uses the specified ChordLeadSheet.
      Parameters:
      cls -
      Returns:
    • createSong

      public Song createSong(String name, ChordLeadSheet cls) throws UnsupportedEditException
      Create a Song from the specified chordleadsheet.
      Parameters:
      name -
      cls -
      Returns:
      Throws:
      UnsupportedEditException - Can happen if too many timesignature changes resulting in not enough Midi channels for the various rhythms.
    • createSong

      public Song createSong(String name, SongStructure sgs) throws UnsupportedEditException
      Create a Song from a SongStructure and its parent ChordLeadSheet.
      Parameters:
      name -
      sgs - sgs.getParentChordLeadSheet() must be non null
      Returns:
      Throws:
      UnsupportedEditException - Can happen if too many timesignature changes resulting in not enough Midi channels for the various rhythms.
    • createSong

      public Song createSong(String name, SongStructure sgs, boolean noClsSgsLink) throws UnsupportedEditException
      Create a Song from a SongStructure and its parent ChordLeadSheet, possibly unlinked.
      Parameters:
      name -
      sgs - sgs.getParentChordLeadSheet() must be non null
      noClsSgsLink - If true, there will be no automatic update between the ChordLeadSheet and the SongStructure. To be used with care only for special purposes (e.g. unit tests), as the Song might be in an inconsistent state.
      Returns:
      Throws:
      UnsupportedEditException - Can happen if too many timesignature changes resulting in not enough Midi channels for the various rhythms.
    • createEmptySong

      public Song createEmptySong(String songName)
      Create a 8-bar empty song with only the 4/4 initial Section named "A" and its corresponding SongPart.
      Parameters:
      songName -
      Returns:
    • createEmptySong

      public Song createEmptySong(String songName, int nbBars, String initSectionName, TimeSignature ts, String initialChord)
      Create an empty song with the specified parameters.

      Parameters:
      songName - The name of the song
      nbBars -
      initSectionName - The name of the initial section
      ts - The time signature of the initial section
      initialChord - eg "Cm7". A string describing an initial chord to be put at the start of the song. If null no chord is inserted.
      Returns:
    • isSongNameUsed

      public boolean isSongNameUsed(String name)
    • getCopy

      public Song getCopy(Song song, boolean noClsSgsLink, boolean register)
      Return a deep copy of the specified song.

      Listeners or file are NOT copied. Returned song is not closed, even if the original song was.

      Parameters:
      song -
      noClsSgsLink - If true, updating the chord leadsheet will not update the song structure
      register - If true register the created song
      Returns:
    • propertyChange

      public void propertyChange(PropertyChangeEvent e)
      Specified by:
      propertyChange in interface PropertyChangeListener