Meter

public struct Meter

Abstract structure of beats which are concretely represented in a measure.

To create a basic meter, it is a simple as:

let common = Meter(4,4)
let waltz = Meter(3,4)
let ferneyhough = Meter(3,12)

A fractional meter can be created like so:

let fractional = Meter(Fraction(3,5),16)

Any number of meters can be combined into an additive meter:

let blueRondo = Meter(2,8) + Meter(2,8) + Meter(2,8) + Meter(3,8)
let czernowinSQm5 = Meter(Meter(1,4),Meter(3,16))

Basic and fractional meters can also be combined:

let czernowinSQm7 = Meter(Meter(1,4),Meter(Fraction(2,3),4))
  • A collection of contiguous Meter values indexed by their fractional offset.

    Example Usage

    You can create a Meter.Collection in several different ways:

    With an array literal of Meter values:

    let _: Meter.Collection = [Meter(3,4), Meter(5,16), Meter(5,8)]
    

    With the standard initializer:

    let _ = Meter.Collection([Meter(3,4), Meter(5,16), Meter(5,8)])
    

    You can also add an fractional offset, if needed:

    let _ = Meter.Collection([Meter(3,4), Meter(5,16), Meter(5,8)], offset: Fraction(3,64))
    

    Lastly, you can construct a Meter.Collection over time with a MeterCollectionBuilder:

    let _ = MeterCollectionBuilder(offset: Fraction(21,16)
        .add(Meter(3,4)
        .add(Meter(2,4)
        .add(Meter(5,8)
        .add(Meter(13,64)
        .add(Meter(7,16)
        .build()
    

    To get a fragment of a Meter.Collection, supply a desired range:

    let meters: Meter.Collection = [Meter(4,4), Meter(3,4), Meter(5,4)]
    let range = Fraction(7,16) ..< Fraction(31,16)
    let fragment = meters.fragment(in: range)
    

    This will return a collection of Meter.Fragment values in the given rage.

    Declaration

    Swift

    public typealias Collection = ContiguousSegmentCollection<Meter>
  • A fragment of a Meter. Wrapping a base meter along with the range of the fragment.

    See more

    Declaration

    Swift

    public struct Fragment
  • Creates a Meter with the given beats and subdivision.

    Declaration

    Swift

    public init(_ beats: Int, _ subdivision: Int)
  • Creates a fractional meter, with the given fraction and subdivision.

    Declaration

    Swift

    public init(_ fraction: Fraction, _ subdivision: Int)
  • Creates a Meter by aggregating all of the given meters.

    Declaration

    Swift

    public init<C>(_ meters: C) where C : Collection, C.Element == Meter
  • Declaration

    Swift

    public var beatOffsets: [Fraction] { get }

    Return Value

    The offsets of each beat contained herein.

  • Declaration

    Swift

    public static var zero: Meter { get }

    Return Value

    A Meter with no duration.

  • Declaration

    Swift

    public static func + (lhs: Meter, rhs: Meter) -> Meter

    Return Value

    An additive meter composed of the two given meters.

  • one

    Declaration

    Swift

    public static var one: Meter { get }

    Return Value

    A Meter with beats and subdivision values of 1.

  • Declaration

    Swift

    public static func * (lhs: Meter, rhs: Meter) -> Meter

    Return Value

    The multiplicative product of the given meters.

  • Declaration

    Swift

    public var numerator: Int { get }

    Return Value

    The numerator for Rational arithmetic.

  • Declaration

    Swift

    public var denominator: Int { get }

    Return Value

    The denominator for Rational arithmetic.

  • A Meter is measured by a Fraction.

    Declaration

    Swift

    public typealias Metric = Fraction
  • Declaration

    Swift

    public var length: Fraction { get }

    Return Value

    The fractional length of a Meter.

  • Creates a Meter with the given amount of beats over a subdivision of 1.

    Declaration

    Swift

    public init(integerLiteral beats: Int)