Files
Lyrebird/Sources/Lyrebird/Score/MusicXML/_NoteContext.swift
T

54 lines
2.5 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// _NoteContext.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Foundation
/// Per-`<note>` accumulator state for ``_MusicXMLParser``.
///
/// Every field is reset together at each `<note>` open (one
/// `noteContext = _NoteContext()` assignment instead of N individual resets)
/// and read in `commitCurrentNote()` — the "reset on open, commit on close"
/// pattern. Document- and part-level state (parts, meter map, repeat structure,
/// tempo changes, pickup tracking, the per-voice slur/wedge maps, the `in…`
/// element-nesting flags) stays on the parser class; only state that logically
/// belongs to the single note currently being parsed lives here.
///
/// The default values are the reset values, so `_NoteContext()` is the canonical
/// "fresh note" state.
internal struct _NoteContext {
/// `<rest/>` child seen — commit as a rest rather than a pitched note.
var isRest: Bool = false
/// `<chord/>` child seen — this note stacks onto the previous note's onset.
var isChord: Bool = false
/// `<grace>` child seen (no `<duration>`) — commit as a `.grace` element
/// without advancing the beat cursor.
var isGrace: Bool = false
/// `<grace slash="yes"/>`. `true` = acciaccatura; `false` = appoggiatura
/// (no slash attribute or `slash="no"`).
var graceSlashed: Bool = false
/// `<pitch><step>` letter (`"C"`…`"B"`); `nil` until `<step>` is read.
var pitchStep: String? = nil
/// `<pitch><alter>` chromatic offset in semitones (sharp `+`, flat `−`).
var pitchAlter: Double = 0.0
/// `<pitch><octave>`. Reset to the middle-C octave before `<octave>` is read.
var pitchOctave: Int = _MusicXMLParser.defaultMidiOctave
/// `<duration>` in divisions (ticks); `0` until read.
var durationDivisions: Int = 0
/// `<voice>` number (1-based). Default `1` when no `<voice>` is present.
var voice: Int = 1
/// `<staff>` number (1-based). Default `1` for single-staff parts.
var staff: Int = 1
/// Articulation parsed from `<notations><articulations>` children.
var articulation: Articulation = .normal
/// `<tie type="stop"/>` present on this note — drives tie-merge on decode.
/// (`<tie type="start"/>` is not tracked; the merge is stop-driven.)
var tieStop: Bool = false
/// `<slur type="start"/>` present on this note element.
var hasSlurStart: Bool = false
/// `<slur type="stop"/>` present on this note element.
var hasSlurStop: Bool = false
}