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 aMeterCollectionBuilder
: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>
-
The context of a
See moreMeter.Fragment
in a container.Declaration
Swift
public struct Context : Equatable
-
Creates a
Meter
with the givenbeats
andsubdivision
.Declaration
Swift
public init(_ beats: Int, _ subdivision: Int)
-
Creates a fractional meter, with the given
fraction
andsubdivision
.Declaration
Swift
public init(_ fraction: Fraction, _ subdivision: Int)
-
Creates a
Meter
by aggregating all of the givenmeters
.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.
-
Declaration
Swift
public static var one: Meter { get }
Return Value
A
Meter
withbeats
andsubdivision
values of1
. -
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
forRational
arithmetic. -
Declaration
Swift
public var denominator: Int { get }
Return Value
The
denominator
forRational
arithmetic.
-
A
Meter
is measured by aFraction
.Declaration
Swift
public typealias Metric = Fraction
-
Declaration
Swift
public var length: Fraction { get }
Return Value
The fractional length of a
Meter
.
-
Declaration
Swift
public func fragment(in range: Range<Fraction>) -> Meter.Fragment
Return Value
A
Meter.Fragment
in the givenrange
.
-
Creates a
Meter
with the given amount ofbeats
over a subdivision of1
.Declaration
Swift
public init(integerLiteral beats: Int)