Class SongContext

java.lang.Object
org.jjazz.songcontext.api.SongContext
Direct Known Subclasses:
SongContextCopy, SongPartContext

public class SongContext extends Object
Collect various data about a Song context in order to facilitate music generation.

Note that a SongContext instance should be discarded if song is structurally modified, because some SongContext methods may return data not consistent anymore with the actual Song.

  • Constructor Details

    • SongContext

      public SongContext(Song s, MidiMix mm)
      Create a SongContext object for the whole song.
      Parameters:
      s -
      mm -
    • SongContext

      public SongContext(SongContext sgContext, IntRange newRange)
      Create a SongContext which reuse sgContext's Song and MidiMix, but with the specified range.
      Parameters:
      sgContext -
      newRange -
    • SongContext

      public SongContext(Song s, MidiMix mm, IntRange bars)
      Create a SongContext object for whole or part of a song.
      Parameters:
      s -
      mm -
      bars - If null, the range will represent the whole song from first to last bar.
  • Method Details

    • clone

      public SongContext clone()
      Clone the SongContext reusing the same song and midi mix.
      Returns:
    • deepClone

      public SongContext deepClone(boolean register)
      Deep clone the SongContext : make a copy of the song and the midimix.
      Parameters:
      register - If true the created song is registered by the SongFactory
      Returns:
      See Also:
    • getSong

      public Song getSong()
      Music should be produced for this song.
      Returns:
    • getMidiMix

      public MidiMix getMidiMix()
      Music should be produced for this MidiMix.
      Returns:
    • getBarRange

      public IntRange getBarRange()
      Music should be produced only for this range of bars.

      The range can start/end anywhere in the song (including in the middle of a song part).

      Returns:
    • getBeatRange

      public FloatRange getBeatRange()
      The range (computed at the time of this object creation) for which music should be produced.

      The range can start/end anywhere in the song (including in the middle of a song part). If getBarRange().from > 0 then toBeatRange().from is also > 0.

      Returns:
    • getTickRange

      public LongRange getTickRange()
      The tick range (computed at the time of this object creation) corresponding to getBarRange() or getBeatRange().

      The range can start/end anywhere in the song (including in the middle of a song part). If toBeatRange().from > 0 then getTickRange().from is also > 0.

      Returns:
    • getSongParts

      public List<SongPart> getSongParts()
      Get all the song parts (at the time of this object creation) which are contained in this context.

      Returns:
      Can be empty.
      See Also:
    • getSptBarRange

      public IntRange getSptBarRange(SongPart spt)
      Get the intersection between the song part bar range and this SongContext bar range.

      Parameters:
      spt -
      Returns:
      Can be the EMPTY_RANGE if spt is not part of this context.
    • getSptBeatRange

      public FloatRange getSptBeatRange(SongPart spt)
      Get the intersection between the song part beat range and this SongContext beat range.

      Parameters:
      spt -
      Returns:
    • getSptTickRange

      public LongRange getSptTickRange(SongPart spt)
      Get the range of ticks of spt belonging to this context.
      Parameters:
      spt -
      Returns:
    • contains

      public boolean contains(SongPart spt)
      Check if the specified spt has at least one bar in the range of this context.
      Parameters:
      spt -
      Returns:
    • getUniqueRhythms

      public List<Rhythm> getUniqueRhythms()
      Get the list of unique rhythms used in this context.
      Returns:
    • getUniqueRhythmVoices

      public List<RhythmVoice> getUniqueRhythmVoices()
      Get the list of unique rhythm voices used in this context.
      Returns:
    • toPosition

      public Position toPosition(long relativeTick)
      Converts a tick position relative to this context into an absolute SongStructure Position.
      Parameters:
      relativeTick - 0 for the start of this context bar range.
      Returns:
      Null if tick is out of the bounds of this context.
    • toPositionInBeats

      public float toPositionInBeats(long relativeTick)
      Converts a tick position relative to this context into an absolute SongStructure position in beats.
      Parameters:
      relativeTick - 0 for the start of this context bar range.
      Returns:
      -1 if tick is out of the bounds of this context.
    • toClsPosition

      public Position toClsPosition(long relativeTick)
      Converts a tick position relative to this context into a ChordLeadSheet Position.
      Parameters:
      relativeTick -
      Returns:
      Null if tick is out of the bounds of this context.
    • toRelativeTick

      public long toRelativeTick(Position pos)
      Compute the tick relative to this context for the given absolute position expressed in bar/beat.

      Parameters:
      pos -
      Returns:
      -1 if pos is outside this context range. Returns 0 for the first bar/beat of the context range.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object