// NoteDivision.swift // Lyrebird // // Copyright (c) 2026 Joshua Parmenter / realizedsound // SPDX-License-Identifier: MIT import Foundation /// A rhythmic note value, expressed as a fraction of a bar and measured in quarter-note beats. /// /// Used to lock a tempo-syncable pedal parameter (a delay time, an LFO rate) to the shared /// ``ShoeGaze/clock``. The synced period in seconds is `(60 / bpm) * beats`; a delay time uses /// that period directly, an LFO rate uses its inverse (one cycle per division). /// /// Cases are ordered longest-first so a stepped selector reads top-to-bottom from slow to fast. public enum NoteDivision: String, Codable, CaseIterable, Sendable { /// Whole note — four quarter-note beats. case whole /// Dotted half note — three beats. case dottedHalf /// Half note — two beats. case half /// Dotted quarter note — one and a half beats. case dottedQuarter /// Quarter note — one beat. case quarter /// Dotted eighth note — three-quarters of a beat. case dottedEighth /// Quarter-note triplet — two-thirds of a beat. case quarterTriplet /// Eighth note — half a beat. case eighth /// Eighth-note triplet — one-third of a beat. case eighthTriplet /// Sixteenth note — a quarter of a beat. case sixteenth /// Sixteenth-note triplet — one-sixth of a beat. case sixteenthTriplet /// Length of this division in quarter-note beats (a quarter note is `1`). public var beats: Double { switch self { case .whole: return 4.0 case .dottedHalf: return 3.0 case .half: return 2.0 case .dottedQuarter: return 1.5 case .quarter: return 1.0 case .quarterTriplet: return 2.0 / 3.0 case .dottedEighth: return 0.75 case .eighth: return 0.5 case .eighthTriplet: return 1.0 / 3.0 case .sixteenth: return 0.25 case .sixteenthTriplet: return 1.0 / 6.0 } } /// Short label for a selector stop (e.g. `"1/4"`, `"1/8."`, `"1/8T"`). public var label: String { switch self { case .whole: return "1/1" case .dottedHalf: return "1/2." case .half: return "1/2" case .dottedQuarter: return "1/4." case .quarter: return "1/4" case .quarterTriplet: return "1/4T" case .dottedEighth: return "1/8." case .eighth: return "1/8" case .eighthTriplet: return "1/8T" case .sixteenth: return "1/16" case .sixteenthTriplet: return "1/16T" } } }