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 List<Song> getRegisteredSongs()
      All songs created by this object are automatically registered.
      Returns:
      A list of the songs registered by this object.
    • registerSong

      public void registerSong(Song sg)
      Register a song if it was not created by the SongManager.
      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:
    • createFromFile

      public Song createFromFile(File f) throws SongCreationException
      Get a Song object from a file.

      Song's getFile() will return f.
      Song's getName() will return f.getName().

      Parameters:
      f -
      Returns:
      Throws:
      SongCreationException
    • 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, ChordLeadSheet cls, SongStructure sgs) throws UnsupportedEditException
      Create a Song from the specified chordleadsheet.
      Parameters:
      name -
      cls -
      sgs - Must be kept consistent with cls changes (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.
    • createEmptySong

      public Song createEmptySong(String name)
      Create a 8-bar empty song.
      Parameters:
      name -
      Returns:
    • createEmptySong

      public Song createEmptySong(String name, int clsSize)
      Create an empty song of specified length.

      Initial section is "A" with a C starting chord symbol.

      Parameters:
      name - The name of the song
      clsSize - The number of bars of the song.
      Returns:
    • isSongNameUsed

      public boolean isSongNameUsed(String name)
    • getCopy

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

      Copy the following variables: chordleadsheet, songStructure, name, tempo, comments, tags, user phrases, clientProperties.
      ChordLeadSheetItem's clientProperties are copied.
      Listeners or file are NOT copied. Returned song is not closed, even if the original song was.

      Parameters:
      song -
      register - If true register the created song
      Returns:
    • getCopyUnlinked

      public Song getCopyUnlinked(Song song, boolean register)
      Return a copy of the song where the SongStructure does NOT listen to the ChordLeadsheet changes.

      WARNING: Because SongStructure and ChordLeadsheet are not linked, changing them might result in inconsistent states. This should be used only in special cases.

      Copy the following variables: chordleadsheet, songStructure, name, tempo, comments, tags, user phrases. Listeners or file are NOT copied.

      Parameters:
      song -
      register - If true register the created song.
      Returns:
    • propertyChange

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