1.0.0 release

This commit is contained in:
2026-06-01 18:27:40 -07:00
parent b1ab0f102c
commit 1f20fcab20
1151 changed files with 230703 additions and 14 deletions
@@ -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 MIDI setup factory that opens the CoreMIDI client, registers a handler for incoming MIDIMessage values (noteOn / noteOff / controlChange / …), and returns a started MIDI instance. The handler closure runs on the lyrebird.midi queue — not the RT thread.</string>
<key>Summary</key>
<string>Lyrebird MIDI Handler (CoreMIDI input)</string>
<key>SortOrder</key>
<string>31</string>
<key>AllowedTypes</key>
<array>
<string>public.swift-source</string>
</array>
<key>DefaultCompletionName</key>
<string>MyMIDIHandler</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>MIDI handler name:</string>
<key>Description</key>
<string>Name of the factory function / type (also used as the file name).</string>
<key>Type</key>
<string>text</string>
<key>Default</key>
<string>MyMIDIHandler</string>
</dict>
</array>
</dict>
</plist>
@@ -0,0 +1,92 @@
//___FILEHEADER___
import Foundation
import LyrebirdSynth
// MARK: - ___FILEBASENAMEASIDENTIFIER___
/// Factory that wires up CoreMIDI input for `engine` and returns a started
/// `MIDI` instance.
///
/// The handler closure runs on the `lyrebird.midi` dispatch queue — not the
/// RT audio thread. From here you can:
/// - Mutate `@LiveParam` slots on Synthesizers (atomic, RT-safe)
/// - Call `engine.add(_:)` / `engine.remove(_:)` (lock-free, applied at the
/// next block boundary)
/// - Start / stop / pause `LyrebirdTask`s
///
/// ## Usage
/// ```swift
/// let midi = try make___FILEBASENAMEASIDENTIFIER___(engine: engine)
/// // …
/// midi.stop() // before engine deallocates
/// ```
///
/// - Parameter engine: Running `SynthesisEngine` whose Synthesizers receive
/// MIDI-driven parameter changes.
/// - Returns: Started `MIDI` with one handler registered.
/// - Throws: `MIDIError.alreadyStarted` if `start()` is called twice.
public func make___FILEBASENAMEASIDENTIFIER___(
engine: SynthesisEngine,
clientName: String = "Lyrebird"
) throws -> MIDI {
let midi = MIDI(engine: engine, clientName: clientName)
_ = midi.addHandler(name: "___FILEBASENAMEASIDENTIFIER___") { message, _ in
switch message {
case .noteOn(let channel, let note, let velocity):
// velocity == 0 is a "running-status" note off — handle as note off.
if velocity == 0 {
handleNoteOff(channel: channel, note: note, velocity: 0)
} else {
handleNoteOn(channel: channel, note: note, velocity: velocity)
}
case .noteOff(let channel, let note, let velocity):
handleNoteOff(channel: channel, note: note, velocity: velocity)
case .controlChange(let channel, let controller, let value):
handleControlChange(channel: channel, controller: controller, value: value)
default:
// pitch bend, channel pressure, polyphonic aftertouch, program
// change, system messages — extend MIDIMessage handling here.
break
}
}
try midi.start()
return midi
}
// MARK: - Per-message handlers (replace bodies with your own)
private func handleNoteOn(channel: UInt8, note: UInt8, velocity: UInt8) {
// TODO: convert (note, velocity) to (Hz, amp) and spawn a voice synth, e.g.
//
// let synth = MyVoice()
// synth.frequency = midiNoteToHz(note)
// synth.amplitude = Double(velocity) / 127.0
// try engine.add(synth)
// voicesByNote[note] = synth
_ = (channel, note, velocity)
}
private func handleNoteOff(channel: UInt8, note: UInt8, velocity: UInt8) {
// TODO: release / remove the voice synth that handleNoteOn started.
_ = (channel, note, velocity)
}
private func handleControlChange(channel: UInt8, controller: UInt8, value: UInt8) {
// TODO: map CCs to Synthesizer @LiveParams. E.g.:
//
// switch controller {
// case 7: masterSynth.amp = Double(value) / 127.0 // CC7 = volume
// case 74: filterSynth.cutoff = ccToCutoff(value) // CC74 = brightness
// default: break
// }
_ = (channel, controller, value)
}
/// Standard MIDI note number → Hz using the 12-tone equal-tempered scale
/// anchored at A4 = 69 = 440 Hz.
private func midiNoteToHz(_ note: UInt8) -> Double {
440.0 * pow(2.0, (Double(note) - 69.0) / 12.0)
}