logo SERENITY
Game Systems Foundation
Search Results for

    Show / Hide Table of Contents

    Class MusicBarTimeCalculator

    Converts DAW-style musical positions (tempo, time signature and bar number) into absolute time in seconds.
    Shared by the music track authoring editor and the runtime track definition so both resolve loop points identically.

    Inheritance
    object
    MusicBarTimeCalculator
    Inherited Members
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    object.GetType()
    object.MemberwiseClone()
    Namespace: Serenity.MusicPlayer.Domain.Services
    Assembly: Serenity.MusicPlayer.Domain.dll
    Syntax
    public static class MusicBarTimeCalculator
    Remarks

    Bars are 1-indexed following DAW convention: bar 1 starts at 0 seconds. A loop region is expressed as a start bar (the downbeat where playback resumes) and an end bar (the downbeat where the loop restarts, treated as exclusive), so its length is (endBar - startBar) bars.

    Methods

    BarToSeconds(int, float, int, int)

    Returns the absolute start time, in seconds, of the downbeat of the given 1-indexed bar.

    Declaration
    public static float BarToSeconds(int bar, float bpm, int beatsPerBar, int beatUnit)
    Parameters
    Type Name Description
    int bar

    1-indexed bar number; bar 1 maps to 0 seconds.

    float bpm

    Tempo in quarter-note beats per minute. Must be greater than zero.

    int beatsPerBar

    Time signature numerator (beats per bar).

    int beatUnit

    Time signature denominator (the note value that gets one beat). Must be greater than zero.

    Returns
    Type Description
    float

    Seconds from the start of the timeline to the bar's downbeat, or 0 for invalid input.

    SecondsPerBar(float, int, int)

    Returns the number of seconds spanned by a single bar for the given tempo and time signature.

    Declaration
    public static float SecondsPerBar(float bpm, int beatsPerBar, int beatUnit)
    Parameters
    Type Name Description
    float bpm

    Tempo in quarter-note beats per minute. Must be greater than zero.

    int beatsPerBar

    Time signature numerator (beats per bar).

    int beatUnit

    Time signature denominator (the note value that gets one beat, e.g. 4 = quarter note). Must be greater than zero.

    Returns
    Type Description
    float

    Seconds per bar, or 0 when bpm or beatUnit are non-positive.

    In this article
    © 2026 Serenity. All Rights Reserved