Skip to content

Split useMidiPlayer.ts into focused modules + grow frontend tests - #116

Merged
TwDover merged 1 commit into
mainfrom
refactor/split-usemidiplayer
Jul 28, 2026
Merged

Split useMidiPlayer.ts into focused modules + grow frontend tests#116
TwDover merged 1 commit into
mainfrom
refactor/split-usemidiplayer

Conversation

@TwDover

@TwDover TwDover commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Split useMidiPlayer.ts into focused modules + grow frontend tests

Break the 1228-line useMidiPlayer.ts composable (1228 -> 610) into focused,
mostly-testable modules — the offline WAV render, shared constants, synth
voices, voice routing, and the scheduler trigger callbacks — and cover the
fragile extracted logic with tests (96 -> 123).

New modules (pure moves — no behaviour change):

  • composables/playerConstants.ts — style-classification Sets +
    PLAYER_PARTS/PlayerPart/CHANNEL_PART, so live playback and the offline
    render read one source (no import cycle). useMidiPlayer re-exports
    PLAYER_PARTS/PlayerPart so external importers are unaffected.
  • composables/useOfflineRender.ts — the parallel per-part WAV export
    (offlineRenderRaw, sumPartBuffers, partHasNotes, limitMix, renderOfflineFast,
    isRendering). The pause-on-export stays a thin wrapper in useMidiPlayer,
    which owns the playback refs.
  • soundfonts/synthVoices.ts — the 7 live-playback synth voice factories (next
    to synthDrums.ts); they take the player's disposables array so cleanup still
    disposes their nodes.
  • composables/voiceRouting.ts — the pure melodic voice-selection decision
    (resolveMelodicVoiceKind) + CC10 pan (panFromCC10); getMelodicInstrument now
    switches on the returned kind.
  • composables/scheduler.ts — the Tone.Part per-note trigger callbacks
    (drumTriggerCallback/voiceTriggerCallback): mute gating, the kick sidechain
    pump, and trigger args, injected into toggle so they test without a Tone
    context.

New tests: wavEncoder (RIFF header / interleave / clamp / mono), voiceRouting
(voice-selection precedence + pan), scheduler (mute gating, pump, trigger args),
and partHasNotes channel->part mapping.

Verified: vue-tsc + eslint + production build + 123 vitest green. Live playback

  • WAV export smoke-tested in the desktop app.

@TwDover
TwDover merged commit 5d21d67 into main Jul 28, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant