b6fdee8bfc
Consolidated release: the cross-platform Linux port (engine, generators, CLI, REPL, NRT, portable DSP), live ALSA audio + ALSA MIDI + POSIX OSC + portable WAV codec, the GTK4 GUI (LyrebirdUI on the SwiftOpenUI backend), and the Linux live-coding scratchpad (LiveCompile). Apple platforms unchanged; all additive. See RELEASES.md and LINUX_README.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
77 lines
3.2 KiB
Swift
77 lines
3.2 KiB
Swift
// ALSASeqMIDIEventTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import LyrebirdSynth
|
|
|
|
// The seq-event → MIDIMessage mapping is the one piece of the Linux MIDI backend
|
|
// that carries real semantic decisions (note-on velocity 0 → note-off, the
|
|
// pitch-bend offset). It is pure Swift, so it is pinned here on every platform
|
|
// rather than only against a connected controller.
|
|
|
|
@Suite("ALSA sequencer MIDI mapping")
|
|
struct ALSASeqMIDIEventTests {
|
|
|
|
@Test func noteOnMaps() {
|
|
#expect(midiMessage(for: .noteOn(channel: 2, note: 60, velocity: 100))
|
|
== .noteOn(channel: 2, note: 60, velocity: 100))
|
|
}
|
|
|
|
@Test func noteOnWithZeroVelocityBecomesNoteOff() {
|
|
// The exact convention the CoreMIDI path applies, so a controller that
|
|
// sends note-on/vel-0 for note-off behaves the same on both platforms.
|
|
#expect(midiMessage(for: .noteOn(channel: 0, note: 64, velocity: 0))
|
|
== .noteOff(channel: 0, note: 64, velocity: 0))
|
|
}
|
|
|
|
@Test func noteOffMaps() {
|
|
#expect(midiMessage(for: .noteOff(channel: 9, note: 40, velocity: 20))
|
|
== .noteOff(channel: 9, note: 40, velocity: 20))
|
|
}
|
|
|
|
@Test func controllerMaps() {
|
|
#expect(midiMessage(for: .controller(channel: 1, param: 7, value: 127))
|
|
== .controlChange(channel: 1, controller: 7, value: 127))
|
|
}
|
|
|
|
@Test func programAndPressureMap() {
|
|
#expect(midiMessage(for: .programChange(channel: 3, program: 12))
|
|
== .programChange(channel: 3, program: 12))
|
|
#expect(midiMessage(for: .channelPressure(channel: 3, pressure: 55))
|
|
== .aftertouch(channel: 3, pressure: 55))
|
|
#expect(midiMessage(for: .keyPressure(channel: 3, note: 60, pressure: 44))
|
|
== .polyAftertouch(channel: 3, note: 60, pressure: 44))
|
|
}
|
|
|
|
@Test func pitchBendPreservesSignedValue() {
|
|
#expect(midiMessage(for: .pitchBend(channel: 0, value: 0))
|
|
== .pitchBend(channel: 0, value: 0))
|
|
#expect(midiMessage(for: .pitchBend(channel: 5, value: -8192))
|
|
== .pitchBend(channel: 5, value: -8192))
|
|
#expect(midiMessage(for: .pitchBend(channel: 5, value: 8191))
|
|
== .pitchBend(channel: 5, value: 8191))
|
|
}
|
|
|
|
@Test func pitchBendClampsOutOfRangeRatherThanWrapping() {
|
|
// An out-of-range value must saturate, not overflow the 14-bit field.
|
|
#expect(midiMessage(for: .pitchBend(channel: 0, value: 99999))
|
|
== .pitchBend(channel: 0, value: 8191))
|
|
#expect(midiMessage(for: .pitchBend(channel: 0, value: -99999))
|
|
== .pitchBend(channel: 0, value: -8192))
|
|
}
|
|
|
|
@Test func realtimeAndSysexMap() {
|
|
#expect(midiMessage(for: .clock) == .clock)
|
|
#expect(midiMessage(for: .start) == .start)
|
|
#expect(midiMessage(for: .continue) == .continue)
|
|
#expect(midiMessage(for: .stop) == .stop)
|
|
#expect(midiMessage(for: .activeSensing) == .activeSensing)
|
|
#expect(midiMessage(for: .reset) == .reset)
|
|
#expect(midiMessage(for: .sysex([0xF0, 0x7E, 0x7F, 0xF7]))
|
|
== .sysex([0xF0, 0x7E, 0x7F, 0xF7]))
|
|
}
|
|
}
|