Interface Snapshot

  • All Known Implementing Classes:
    Metronome

    public interface Snapshot

    An interface for probing details about the timeline established by a metronome, with respect to a particular moment in time. The Metronome class implements this interface and provides answers with respect to the moment at which you called each function, but if you need to work with more than one piece of information at a time, be sure to use Metronome.getSnapshot() so that each of your calculations refer to the same moment. Otherwise you risk getting misleading results, such as when you ask for a beat number in one call, and then the beat phase, and you have moved on to a different beat in between the calls.

    Snapshots in Afterglow also extend the notions of beat phase to enable oscillators with frequencies that are fractions or multiples of a beat. As of version 0.1.1, this concept has been ported from the Clojure version to here, but it is available as Metronome.enhancedPhase(long, double, double) rather than additional overloads of the snapshot methods.

    Author:
    James Elliott
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      double distanceFromBar()
      Determine how far in time the snapshot is from its closest bar boundary.
      double distanceFromBeat()
      Determine how far in time the snapshot is from its closest beat.
      double distanceFromPhrase()
      Determine how far in time the snapshot is from its closest phrase boundary.
      long getBar()
      Get the metronome's bar number.
      double getBarInterval()
      Get the metronome's bar length in time.
      double getBarPhase()
      Get the metronome's bar phase at the time of the snapshot, a value which starts at 0.0 at the very start of the bar, but never quite reaches 1.0, because that would be the start of the next bar.
      int getBarsPerPhrase()
      Get the metronome's phrase length in bars.
      int getBarWithinPhrase()
      Return the bar number of the snapshot relative to the start of the phrase: the phrase starts with bar 1, and the range goes up to the value of getBarsPerPhrase().
      long getBeat()
      Get the metronome's beat number.
      double getBeatInterval()
      Get the metronome's beat length in time.
      double getBeatPhase()
      Get the metronome's beat phase at the time of the snapshot, a value which starts at 0.0 at the very start of the beat, but never quite reaches 1.0, because that would be the start of the next beat.
      int getBeatsPerBar()
      Get the metronome's bar length in beats.
      int getBeatWithinBar()
      Return the beat number of the snapshot relative to the start of the bar: the down beat is 1, and the range goes up to the value of getBeatsPerBar().
      int getBeatWithinPhrase()
      Return the beat number of the snapshot relative to the start of the phrase: the phrase starts with beat 1, and the range goes up to the value of getBeatsPerBar() times getBarsPerPhrase().
      long getInstant()
      Get the point in time with respect to which the snapshot is computed.
      String getMarker()
      Returns the time represented by the snapshot as "phrase.bar.beat".
      long getPhrase()
      Get the metronome's phrase number.
      double getPhraseInterval()
      Get the metronome's phrase length in time.
      double getPhrasePhase()
      Get the metronome's phrase phase at the time of the snapshot, a value which starts at 0.0 at the very start of the phrase, but never quite reaches 1.0, because that would be the start of the next phrase.
      long getStartTime()
      Get the metronome's timeline origin.
      double getTempo()
      Get the metronome's tempo.
      long getTimeOfBar​(long bar)
      Determine the millisecond timestamp at which a particular bar will occur, given the metronome configuration when the snapshot was taken.
      long getTimeOfBeat​(long beat)
      Determine the millisecond timestamp at which a particular beat will occur, given the metronome configuration when the snapshot was taken.
      long getTimeOfPhrase​(long phrase)
      Determine the millisecond timestamp at which a particular phrase will occur, given the metronome configuration when the snapshot was taken.
      boolean isDownBeat()
      Checks whether the current beat at the time of the snapshot was the first beat in its bar.
      boolean isPhraseStart()
      Checks whether the current beat at the time of the snapshot was the first beat in its phrase.
    • Method Detail

      • getStartTime

        long getStartTime()
        Get the metronome's timeline origin.
        Returns:
        the point in time at which the metronome from which this snapshot was taken started counting
      • getTempo

        double getTempo()
        Get the metronome's tempo.
        Returns:
        the number of beats per minute at which the metronome from which this snapshot was taken was running
      • getBeatsPerBar

        int getBeatsPerBar()
        Get the metronome's bar length in beats.
        Returns:
        the number of beats which made up a bar in the metronome from which this snapshot was taken
      • getBarsPerPhrase

        int getBarsPerPhrase()
        Get the metronome's phrase length in bars.
        Returns:
        the number of beats which made up a bar in the metronome from which this snapshot was taken
      • getInstant

        long getInstant()
        Get the point in time with respect to which the snapshot is computed. The difference between this and getStartTime(), along with getTempo(), determine the other snapshot values.
        Returns:
        the moment represented by the snapshot
      • getBeatInterval

        double getBeatInterval()
        Get the metronome's beat length in time.
        Returns:
        the duration of a beat, in milliseconds, at the tempo when the snapshot was taken
      • getBarInterval

        double getBarInterval()
        Get the metronome's bar length in time.
        Returns:
        the duration of a bar, in milliseconds, at the tempo when the snapshot was taken
      • getPhraseInterval

        double getPhraseInterval()
        Get the metronome's phrase length in time.
        Returns:
        the duration of a phrase, in milliseconds, at the tempo when the snapshot was taken
      • getBeat

        long getBeat()
        Get the metronome's beat number.
        Returns:
        the beat number being played at the time represented by the snapshot; beats start at 1
      • getBar

        long getBar()
        Get the metronome's bar number.
        Returns:
        the bar number being played at the time represented by the snapshot; bars start at 1
      • getPhrase

        long getPhrase()
        Get the metronome's phrase number.
        Returns:
        the phrase number being played at the time represented by the snapshot; phrases start at 1
      • getBeatPhase

        double getBeatPhase()
        Get the metronome's beat phase at the time of the snapshot, a value which starts at 0.0 at the very start of the beat, but never quite reaches 1.0, because that would be the start of the next beat.
        Returns:
        how far we have have traveled through the current beat at the point in time represented by the snapshot
      • getBarPhase

        double getBarPhase()
        Get the metronome's bar phase at the time of the snapshot, a value which starts at 0.0 at the very start of the bar, but never quite reaches 1.0, because that would be the start of the next bar.
        Returns:
        how far we have traveled through the current bar at the point in time represented by the snapshot
      • getPhrasePhase

        double getPhrasePhase()
        Get the metronome's phrase phase at the time of the snapshot, a value which starts at 0.0 at the very start of the phrase, but never quite reaches 1.0, because that would be the start of the next phrase.
        Returns:
        how far we have traveled through the current phrase at the point in time represented by the snapshot
      • getTimeOfBeat

        long getTimeOfBeat​(long beat)
        Determine the millisecond timestamp at which a particular beat will occur, given the metronome configuration when the snapshot was taken.
        Parameters:
        beat - the number of the beat whose start time is desired
        Returns:
        the time at which the specified beat begins, rounded to the nearest millisecond
      • getBeatWithinBar

        int getBeatWithinBar()
        Return the beat number of the snapshot relative to the start of the bar: the down beat is 1, and the range goes up to the value of getBeatsPerBar().
        Returns:
        the beat number within the current bar being counted at the point in time represented by the snapshot
      • isDownBeat

        boolean isDownBeat()
        Checks whether the current beat at the time of the snapshot was the first beat in its bar.
        Returns:
        true if the snapshot was taken during the first beat of a bar
      • getBeatWithinPhrase

        int getBeatWithinPhrase()
        Return the beat number of the snapshot relative to the start of the phrase: the phrase starts with beat 1, and the range goes up to the value of getBeatsPerBar() times getBarsPerPhrase().
        Returns:
        the beat number within the current phrase being counted at the point in time represented by the snapshot
      • isPhraseStart

        boolean isPhraseStart()
        Checks whether the current beat at the time of the snapshot was the first beat in its phrase.
        Returns:
        true if the snapshot was taken during the first beat of a phrase
      • getTimeOfBar

        long getTimeOfBar​(long bar)
        Determine the millisecond timestamp at which a particular bar will occur, given the metronome configuration when the snapshot was taken.
        Parameters:
        bar - the number of the bar whose start time is desired
        Returns:
        the time at which the specified bar begins, rounded to the nearest millisecond
      • getBarWithinPhrase

        int getBarWithinPhrase()
        Return the bar number of the snapshot relative to the start of the phrase: the phrase starts with bar 1, and the range goes up to the value of getBarsPerPhrase().
        Returns:
        the bar number within the current phrase being counted at the point in time represented by the snapshot
      • getTimeOfPhrase

        long getTimeOfPhrase​(long phrase)
        Determine the millisecond timestamp at which a particular phrase will occur, given the metronome configuration when the snapshot was taken.
        Parameters:
        phrase - the number of the phrase whose start time is desired
        Returns:
        the time at which the specified phrase begins, rounded to the nearest millisecond
      • getMarker

        String getMarker()
        Returns the time represented by the snapshot as "phrase.bar.beat".
        Returns:
        a concise textual representation of the current metronome position at the time of the snapshot
      • distanceFromBeat

        double distanceFromBeat()
        Determine how far in time the snapshot is from its closest beat. The result will be positive if the beat has already occurred, and negative if it is coming up.
        Returns:
        the distance in milliseconds from the closest beat on the snapshot's timeline
      • distanceFromBar

        double distanceFromBar()
        Determine how far in time the snapshot is from its closest bar boundary. The result will be positive if the bar has already started, and negative if it is coming up.
        Returns:
        the distance in milliseconds from the closest bar boundary on the snapshot's timeline
      • distanceFromPhrase

        double distanceFromPhrase()
        Determine how far in time the snapshot is from its closest phrase boundary. The result will be positive if the phrase has already started, and negative if it is coming up.
        Returns:
        the distance in milliseconds from the closest phrase boundary on the snapshot's timeline