bugfixes, better MusicXML support and 1.1.0
This commit is contained in:
+44
@@ -0,0 +1,44 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTD/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>Kind</key>
|
||||
<string>Xcode.IDEKit.TextSubstitutionFileTemplateKind</string>
|
||||
<key>Platforms</key>
|
||||
<array>
|
||||
<string>com.apple.platform.macosx</string>
|
||||
<string>com.apple.platform.iphoneos</string>
|
||||
</array>
|
||||
<key>Description</key>
|
||||
<string>A Score factory function — emits a make<Name>() that builds a two-part Score with the DSL (Note, Rest, Chord, Tuplet, dynamics, articulations) and shows how to export MusicXML with toMusicXMLString() / toMusicXMLData() and round-trip via Score.fromMusicXML(). Pitch spelling is preserved through export.</string>
|
||||
<key>Summary</key>
|
||||
<string>Lyrebird Score (MusicXML factory)</string>
|
||||
<key>SortOrder</key>
|
||||
<string>26</string>
|
||||
<key>AllowedTypes</key>
|
||||
<array>
|
||||
<string>public.swift-source</string>
|
||||
</array>
|
||||
<key>DefaultCompletionName</key>
|
||||
<string>MyScore</string>
|
||||
<key>MainTemplateFile</key>
|
||||
<string>___FILEBASENAME___.swift</string>
|
||||
<key>Options</key>
|
||||
<array>
|
||||
<dict>
|
||||
<key>Identifier</key>
|
||||
<string>productName</string>
|
||||
<key>Required</key>
|
||||
<true/>
|
||||
<key>Name</key>
|
||||
<string>Score name:</string>
|
||||
<key>Description</key>
|
||||
<string>Name of the score factory (also used as the file name). The factory function is named make<Name>().</string>
|
||||
<key>Type</key>
|
||||
<string>text</string>
|
||||
<key>Default</key>
|
||||
<string>MyScore</string>
|
||||
</dict>
|
||||
</array>
|
||||
</dict>
|
||||
</plist>
|
||||
Vendored
+80
@@ -0,0 +1,80 @@
|
||||
//___FILEHEADER___
|
||||
|
||||
import Foundation
|
||||
import LyrebirdSynth
|
||||
|
||||
// MARK: - ___FILEBASENAMEASIDENTIFIER___
|
||||
|
||||
/// Factory for a `Score` authored with the Lyrebird score DSL.
|
||||
///
|
||||
/// The DSL covers every notated element:
|
||||
/// - `Note(letter, octave, dur:dyn:art:)` — a single pitch
|
||||
/// - `Rest(dur:)` — silence that advances the cursor
|
||||
/// - `Chord([(letter, octave), …], dur:dyn:art:)` — simultaneous pitches
|
||||
/// - `Tuplet(n, inTimeOf: m) { … }` — exact-ratio tuplets (`Fraction` math)
|
||||
/// - `Generate(count) { i in … }` — index-driven algorithmic generation
|
||||
/// - `PatternNotes(count:midi:…)` — notes pulled from a `Pattern` source
|
||||
///
|
||||
/// Expressive and layout features (see the Lyrebird ScoreSystem docs):
|
||||
/// - `Crescendo { }` / `Diminuendo { }` hairpins and `Slur { }` spans
|
||||
/// - per-note `spanners:` for overlapping spans, `.beginGlissando` / slides
|
||||
/// - per-note `display:` (`NoteDisplay`) — notehead shape, size, hide stem/beam
|
||||
/// - `Section("…") { … }` blocks assembled into one score (rehearsal marks)
|
||||
/// - `pageLayout:` (`PageLayout`) — page size, orientation, margins, scaling
|
||||
///
|
||||
/// Pitch spelling (letter + accidental, including double accidentals and
|
||||
/// quarter-tones) is preserved through MusicXML export.
|
||||
///
|
||||
/// ## Usage
|
||||
/// ```swift
|
||||
/// let score = make___FILEBASENAMEASIDENTIFIER___()
|
||||
///
|
||||
/// // Export to MusicXML 4.0 (score-partwise).
|
||||
/// let xml = score.toMusicXMLString()
|
||||
/// try xml.write(to: URL(fileURLWithPath: "score.musicxml"),
|
||||
/// atomically: true, encoding: .utf8)
|
||||
///
|
||||
/// // Round-trip back into a Score.
|
||||
/// let restored = try Score.fromMusicXML(data: score.toMusicXMLData())
|
||||
///
|
||||
/// // Walk the flattened, beat-sorted events to drive playback or rendering.
|
||||
/// for event in score.allEvents where !event.isRest {
|
||||
/// // event.beat, event.performedDuration (sounding beats),
|
||||
/// // event.duration (notated beats), event.pitch.frequency (Hz),
|
||||
/// // event.velocity ([0, 1]), event.articulation, event.channel
|
||||
/// }
|
||||
/// ```
|
||||
public func make___FILEBASENAMEASIDENTIFIER___() -> Score {
|
||||
Score(bpm: 120, timeSignature: TimeSignature(4, 4)) {
|
||||
// Lead — melody covering dynamics, articulations, a hairpin, and a tuplet.
|
||||
Part("lead") {
|
||||
// A crescendo hairpin over the opening arpeggio (notation-only).
|
||||
Crescendo {
|
||||
Note(.named(.c, 5), dur: .quarter, dyn: .mf, art: .staccato)
|
||||
Note(.named(.e, 5), dur: .quarter, dyn: .mf, art: .staccato)
|
||||
Note(.named(.g, 5), dur: .quarter, dyn: .f, art: .accent)
|
||||
}
|
||||
Rest(dur: .quarter)
|
||||
Tuplet(3, inTimeOf: 2) {
|
||||
Note(.named(.b, 5), dur: .quarter, dyn: .mp)
|
||||
Note(.named(.a, 5), dur: .quarter, dyn: .mp)
|
||||
Note(.named(.g, 5), dur: .quarter, dyn: .mp)
|
||||
}
|
||||
Chord([.named(.c, 5), .named(.e, 5), .named(.g, 5)], dur: .half, dyn: .f, art: .tenuto)
|
||||
}
|
||||
// Bass — sustained harmonic support on a second MIDI channel.
|
||||
Part("bass", channel: 1) {
|
||||
Note(.named(.c, 3), dur: .whole, dyn: .mp)
|
||||
Note(.named(.g, 2), dur: .half, dyn: .p)
|
||||
Note(.named(.c, 3), dur: .half, dyn: .mp, art: .tenuto)
|
||||
}
|
||||
// Texture — algorithmic generation. `Generate` maps an index range
|
||||
// through the builder; `PatternNotes` pulls from a `Pattern` source.
|
||||
Part("texture", channel: 2) {
|
||||
Generate(8) { i in
|
||||
Note(midi: 72 + (i % 6) * 2, dur: .sixteenth, dyn: .pp, art: .staccato)
|
||||
}
|
||||
PatternNotes(count: 4, midi: Pattern.series(start: 60, step: 3, length: 4), dur: .eighth, dyn: .p)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user