dn-m / Music

Structures for the creation, analysis, and performance of music in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Duration/Meter] Audit Additive conformance of Meter

jsbean opened this issue · comments

Meter and Meter.Kind are both currently Additive (and Multiplicative). Because a Meter.Kind can be any of { .single, .fractional, or .additive }, the + operator make returns an .additive sum of the two given Meter values.

This is interesting on a small scale, but blows up (showstoppingly) on a large scale. For example,

Meter(3,4) + Meter(2,4) // => Meter(kind: .additive([.single(3,4), .single(2,4)]))

This keeps building out a larger and larger .additive Meter which must keep allocating arrays for each new pair.

Consider switching on the kinds of the incoming Meter values for +. If they are both .single, return a .single. This could potentially save a lot of computation.