5.2 KiB
5.2 KiB
Tasks: enterprise-audio-transport
Change ID: enterprise-audio-transport
Package: @suaveplan/audio-transport
Target path: packages/audio/audio-transport
Prerequisite packages on Verdaccio: @suaveplan/timing, @suaveplan/events, @suaveplan/fsm, @suaveplan/types, @suaveplan/error
1. Scaffold
- Create directory
packages/audio/audio-transport/withsrc/,tests/,src/__benchmarks__/, and all feature subdirectories per the layout inproposal.md. - Write
package.jsonat version0.1.0with"type": "module","sideEffects": false, fullexportsmap, deps:@suaveplan/timing workspace:^,@suaveplan/events workspace:^,@suaveplan/fsm workspace:^,@suaveplan/types workspace:^,@suaveplan/error workspace:^,zod catalog:forms. - Write
tsconfig.jsonextending@suaveplan/typescript-config/library.json. - Write
vitest.config.tsusingcreateTestConfig()from@suaveplan/testing/config. - Add
lint,typecheck,test,test:coverage,build,docs:checkscripts.
2. Types + errors
- Write
src/transport/transport.types.ts—TransportOptions,TransportTime,Ticks,BarsBeatsSixteenths,BPM,Subdivision,TransportCallback,TransportEventMap. - Write
src/scheduler/scheduler.types.ts—SchedulerState. - Write
src/tick-source/tick-source.types.ts—TickSourceState. - Write
src/signal/signal.types.ts—SignalConfig. - Write
src/time/time.types.ts—TimeToken,TimeParseResult. - Write co-located
.mdfiles for each types module (≥200 words). - Write
src/error-codes.ts—TransportErrorCode,AUDIO_TRANSPORT_ERROR_METADATA,registerTransportErrorCodes(). - Write Zod schemas:
TransportOptionsSchema,TransportTimeSchema,TicksSchema,BarsBeatsSixteenthsSchema.
3. Signal module
- Implement
src/signal/signal.ts—Signal<BPM>wrapper around@suaveplan/timingSignalwith ramp/hold curves for tempo automation. - Write
signal.test.tsandsignal.md.
4. Time parsing
- Implement
src/time/time.ts— parse musical time strings ("4n","8t","1m","2:1:0","+1","@4m"), convert to seconds and ticks,toSeconds,toTicks,toBarsBeatsSixteenths. - Write
time.test.tsandtime.md.
5. TickSource
- Implement
TickSourceinsrc/tick-source/tick-source.ts:getTicksAtTime,getTimeOfTick,setTicksAtTimewith tempo curve support.start,stop,pausewith offset handling.forEachTickBetweeniterating ticks between two audio times, invoking callback with sample-accuratetimeandticks.
- Write
tick-source.test.tsandtick-source.md.
6. TransportScheduler
- Implement
TransportSchedulerinsrc/scheduler/scheduler.ts:- Constructor takes
TransportandClock. start()begins the ~100Hz lookahead loop via@suaveplan/timingcreateScheduler.stop()halts the scheduler.- On each tick: emit FSM state changes between last update and now, then invoke
tickSource.forEachTickBetweento fire scheduled callbacks with sample-accurate times.
- Constructor takes
- Write
scheduler.test.tsandscheduler.md.
7. Transport
- Implement
Transportinsrc/transport/transport.ts:- Constructor accepts
TransportOptions; initializesTickSource, FSM state machine (stopped→playing→paused), and internal event list. start,stop,pausedrive FSM transitions and tick source.schedule,scheduleRepeat,scheduleOncereturn numeric event IDs; store callbacks in a priority queue.cancelremoves event by ID;cancelAfterremoves all events after a given time.bpmasSignal<BPM>with ramp/hold support.swing(0..1) andswingSubdivisionapplied per-tick during_processTick()using sine-based offset.toSeconds,toTicks,toBarsBeatsSixteenthsdelegate to time module.loop,loopStart,loopEnd— when enabled, transport jumps toloopStartafter crossingloopEnd.- Events:
start,stop,pause,loop,bpmvia@suaveplan/events. dispose()cancels all events, stops scheduler, and cleans up.
- Constructor accepts
- Write
transport.test.ts(≤500 lines): start/stop/pause, schedule/cancel, loop region, tempo ramp, swing application, time conversion round-trip. - Write
transport.md.
8. Benchmarks
- Write
src/__benchmarks__/transport.bench.ts— schedule 1 000 callbacks, 100 BPM ramps, 10 000 tick iterations.
9. Integration tests
- Write
tests/integration.test.ts— full transport lifecycle withFakeClock: start, schedule repeated callback, verify callback times are sample-accurate, loop jump, cancel after time, tempo automation curve.
10. Docs + verify + publish
- All co-located
.mdfiles (≥200 words each). - Write
README.mdat package root. bunx turbo lint typecheck test --filter=@suaveplan/audio-transport— green.bunx turbo test:coverage --filter=@suaveplan/audio-transport— 100%.bun scripts/publish.ts --package @suaveplan/audio-transport.- Fold
specs/audio-transport/spec.mdintoopenspec/specs/audio-transport/spec.md. - Archive to
openspec/archive/2026-05-14-enterprise-audio-transport/.