bugfixes, better MusicXML support and 1.1.0
This commit is contained in:
@@ -79,9 +79,11 @@ struct ScoreTests {
|
||||
#expect(abs(events[1].beat - third) < 1e-15)
|
||||
#expect(abs(events[2].beat - 2.0 * third) < 1e-15)
|
||||
// Total span = 2 beats — verify via lastBeat()
|
||||
// duration is "played" duration = nominal × articulation.scale; nominal=2/3, scale=1.0
|
||||
// duration is the notated duration; nominal=2/3, articulation=.normal (scale=1.0)
|
||||
// so notated == performed == 2/3 beat.
|
||||
for e: ScoreEvent in events {
|
||||
#expect(abs(e.duration - third) < 1e-15)
|
||||
#expect(abs(e.performedDuration - third) < 1e-15)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,6 +152,17 @@ struct ScoreTests {
|
||||
#expect(events[1].beat == 1.5)
|
||||
}
|
||||
|
||||
@Test func dotConveniencePropertiesMatchStatics() {
|
||||
// `.dotted` / `.doubleDotted` computed properties equal the static funcs.
|
||||
#expect(NoteDuration.quarter.dotted.beats == NoteDuration.dotted(.quarter).beats)
|
||||
#expect(NoteDuration.quarter.dotted.beats == 1.5)
|
||||
#expect(NoteDuration.half.doubleDotted.beats == NoteDuration.doubleDotted(.half).beats)
|
||||
#expect(NoteDuration.quarter.doubleDotted.beats == 1.75)
|
||||
// Double-dotted is 7/4, NOT the 9/4 of chaining `.dotted.dotted`.
|
||||
#expect(NoteDuration.quarter.doubleDotted.beats != NoteDuration.quarter.dotted.dotted.beats)
|
||||
#expect(NoteDuration.quarter.dotted.dotted.beats == 2.25)
|
||||
}
|
||||
|
||||
// MARK: - 8. Dynamic → velocity mapping
|
||||
|
||||
@Test func dynamicMapsToVelocity() {
|
||||
@@ -172,10 +185,15 @@ struct ScoreTests {
|
||||
Note(.c, 4, dur: .quarter, dyn: .mf, art: .accent),
|
||||
])
|
||||
let events: [ScoreEvent] = part.flatten()
|
||||
// staccato: duration × 0.5
|
||||
#expect(abs(events[0].duration - 0.5) < 1e-15)
|
||||
// accent: duration unchanged, velocity = mf + 0.15
|
||||
// staccato: notated duration is unchanged (quarter = 1.0 beat);
|
||||
// performedDuration applies the 0.5 scale.
|
||||
#expect(events[0].duration == 1.0, "notated duration is always the written beat value")
|
||||
#expect(abs(events[0].performedDuration - 0.5) < 1e-15,
|
||||
"staccato performed duration = notated × 0.5")
|
||||
// accent: notated duration unchanged, velocity = mf + 0.15
|
||||
#expect(events[1].duration == 1.0)
|
||||
#expect(events[1].performedDuration == 1.0,
|
||||
"accent does not alter performed duration (scale = 1.0)")
|
||||
#expect(abs(events[1].velocity - (Dynamic.mf.velocity + 0.15)) < 1e-15)
|
||||
}
|
||||
|
||||
@@ -188,6 +206,35 @@ struct ScoreTests {
|
||||
#expect(events[0].velocity == 1.0)
|
||||
}
|
||||
|
||||
// MARK: - 9b. performedDuration covers all articulation cases
|
||||
|
||||
@Test func performedDurationAllArticulations() {
|
||||
// Half note (2.0 beats notated) under each articulation.
|
||||
let part: ScorePart = ScorePart(name: "p", elements: [
|
||||
Note(.c, 4, dur: .half, art: .normal),
|
||||
Note(.c, 4, dur: .half, art: .staccato),
|
||||
Note(.c, 4, dur: .half, art: .staccatissimo),
|
||||
Note(.c, 4, dur: .half, art: .legato),
|
||||
Note(.c, 4, dur: .half, art: .tenuto),
|
||||
Note(.c, 4, dur: .half, art: .accent),
|
||||
Note(.c, 4, dur: .half, art: .marcato),
|
||||
])
|
||||
let events: [ScoreEvent] = part.flatten()
|
||||
// All notated durations must be the half note (2.0 beats).
|
||||
for e: ScoreEvent in events {
|
||||
#expect(e.duration == 2.0,
|
||||
"notated duration must always equal the written beat value (\(e.articulation))")
|
||||
}
|
||||
// Performed durations apply each articulation's durationScale.
|
||||
#expect(abs(events[0].performedDuration - 2.0) < 1e-15, "normal ×1.0")
|
||||
#expect(abs(events[1].performedDuration - 1.0) < 1e-15, "staccato ×0.5")
|
||||
#expect(abs(events[2].performedDuration - 0.5) < 1e-15, "staccatissimo ×0.25")
|
||||
#expect(abs(events[3].performedDuration - 2.1) < 1e-12, "legato ×1.05")
|
||||
#expect(abs(events[4].performedDuration - 2.0) < 1e-15, "tenuto ×1.0")
|
||||
#expect(abs(events[5].performedDuration - 2.0) < 1e-15, "accent ×1.0")
|
||||
#expect(abs(events[6].performedDuration - 1.7) < 1e-12, "marcato ×0.85")
|
||||
}
|
||||
|
||||
// MARK: - 10. DSL: full Score with parts + builders
|
||||
|
||||
@Test func dslAssemblesFullScore() {
|
||||
|
||||
Reference in New Issue
Block a user