39 lines
1.6 KiB
Swift
39 lines
1.6 KiB
Swift
// _PartBuilder.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Foundation
|
|
|
|
/// Mutable per-part accumulator used during parsing.
|
|
internal struct _PartBuilder {
|
|
let id: String
|
|
let name: String
|
|
/// Clef read from the first `<clef>` element in this part. Defaults to
|
|
/// `.treble`; set once (first-clef-per-part wins) when the first `<clef>`
|
|
/// block is encountered — `clefWasSet` distinguishes "not yet parsed" from
|
|
/// a legitimately-parsed treble clef, so a later mid-part `<clef>` change
|
|
/// does not overwrite the first.
|
|
var clef: Clef = .treble
|
|
var clefWasSet: Bool = false
|
|
/// Key signature read from the first `<key>` element in this part.
|
|
/// Nil until a `<key>` block is parsed. Used to set a per-part override
|
|
/// when this part's key differs from the first part's key.
|
|
var keySignature: KeySignature? = nil
|
|
/// Transpose read from the `<transpose>` element in this part.
|
|
/// Nil until a `<transpose>` block is parsed.
|
|
var transpose: Transpose? = nil
|
|
/// Absolute cursor position in divisions. Updated after each note / rest is
|
|
/// committed; rewound by `<backup>` and advanced by `<forward>`.
|
|
var absoluteCursorDivisions: Int = 0
|
|
/// Beat-stamped events collected in document order. Voice grouping and
|
|
/// element reconstruction happen in `_MusicXMLParser.parsedScore()`.
|
|
var entries: [_PartEntry] = []
|
|
|
|
/// Replace the ScoreElement at the given index (used by tie-merge).
|
|
mutating func replaceElement(at index: Int, with element: ScoreElement) {
|
|
entries[index].element = element
|
|
}
|
|
}
|