cp-midi-player 0.0.0-stage → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +201 -2
  3. package/dist/GeneralUser-GS-LICENSE.txt +47 -0
  4. package/dist/GeneralUser-GS.sf3 +0 -0
  5. package/dist/JetBrainsMono-OFL.txt +93 -0
  6. package/dist/JetBrainsMono-Variable.ttf +0 -0
  7. package/dist/LICENSE +22 -0
  8. package/dist/cp-midi-player.iife.js +1741 -0
  9. package/dist/cp-midi-player.iife.js.map +7 -0
  10. package/dist/cp-midi-player.js +1741 -0
  11. package/dist/cp-midi-player.js.map +7 -0
  12. package/dist/spessasynth_processor.min.js +18 -0
  13. package/dist/types/arrangement-view.d.ts +19 -0
  14. package/dist/types/asset-base.d.ts +11 -0
  15. package/dist/types/audio-sync.d.ts +53 -0
  16. package/dist/types/canonical-midi.d.ts +39 -0
  17. package/dist/types/cp-midi-player.d.ts +75 -0
  18. package/dist/types/download.d.ts +3 -0
  19. package/dist/types/esm.d.ts +6 -0
  20. package/dist/types/gm-programs.d.ts +2 -0
  21. package/dist/types/idle-audio-engines.d.ts +7 -0
  22. package/dist/types/instrument-icons.d.ts +2 -0
  23. package/dist/types/instrument-thumbnails.d.ts +13 -0
  24. package/dist/types/musical-time.d.ts +3 -0
  25. package/dist/types/note-chase.d.ts +17 -0
  26. package/dist/types/piano-roll-seek.d.ts +15 -0
  27. package/dist/types/pitch-range.d.ts +10 -0
  28. package/dist/types/playback-coordinator.d.ts +16 -0
  29. package/dist/types/playback-midi.d.ts +7 -0
  30. package/dist/types/player.d.ts +86 -0
  31. package/dist/types/preset-resolution.d.ts +6 -0
  32. package/dist/types/timeline-ruler.d.ts +7 -0
  33. package/dist/types/track-audibility.d.ts +17 -0
  34. package/dist/types/track-mixer.d.ts +7 -0
  35. package/dist/types/track-preset.d.ts +18 -0
  36. package/dist/types/transport-clock.d.ts +16 -0
  37. package/dist/types/view-window.d.ts +9 -0
  38. package/dist/types/viewer-state.d.ts +29 -0
  39. package/dist/types/worklet-fallback.d.ts +31 -0
  40. package/package.json +63 -4
@@ -0,0 +1,19 @@
1
+ export type ArrangementNote = {
2
+ midi: number;
3
+ time: number;
4
+ duration: number;
5
+ };
6
+ export type ArrangementNoteRect = {
7
+ x: number;
8
+ y: number;
9
+ width: number;
10
+ height: number;
11
+ };
12
+ export declare function getArrangementCanvasHeight(trackCount: number, trackHeight: number, headerHeight: number, viewportHeight: number): number;
13
+ export declare function getPianoRollCanvasHeight(pitchCount: number, rowHeight: number, headerHeight: number, viewportHeight: number): number;
14
+ export declare function getArrangementNoteRect(note: ArrangementNote, minPitch: number, maxPitch: number, trackIndex: number, trackHeight: number, headerHeight: number, width: number, viewStart: number, viewEnd: number): ArrangementNoteRect;
15
+ /** Place audio rows before the specified MIDI track (1-based); default above MIDI. */
16
+ export declare function getArrangementTrackOrder(midiCount: number, audioBefore: readonly (number | undefined)[]): {
17
+ kind: "audio" | "midi";
18
+ index: number;
19
+ }[];
@@ -0,0 +1,11 @@
1
+ export declare const PACKAGE_NAME = "cp-midi-player";
2
+ /**
3
+ * Where the player finds its worklet, SoundFont and font.
4
+ *
5
+ * When the script is itself a file from `dist/` (a self-hosted copy, or a CDN
6
+ * URL that names the file), the assets sit next to it. Anything else, such as
7
+ * a bare CDN URL (`cdn.jsdelivr.net/npm/cp-midi-player`) or a bundler output
8
+ * (`index-3f2a.js`, `node_modules/.vite/deps/...`), gets the same version's
9
+ * `dist/` from jsDelivr.
10
+ */
11
+ export declare function resolveAssetBase(scriptUrl: string | undefined, version: string): string;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Audio tracks play as AudioBufferSourceNodes in the synthesizer's own
3
+ * AudioContext, so the recording and the MIDI share one sample clock. The only
4
+ * way they can part is a transport change (play, pause, seek, tempo-free
5
+ * rebuild), which shows up as a position error and is fixed by restarting the
6
+ * source at the right offset.
7
+ */
8
+ /** A playing source further than this from the MIDI position is restarted. */
9
+ export declare const AUDIO_RESTART_SECONDS = 0.03;
10
+ /** A recording that starts this soon after the playhead is scheduled sample-accurately. */
11
+ export declare const AUDIO_SCHEDULE_AHEAD_SECONDS = 0.5;
12
+ /** The MIDI clock counts as settled once it tracks the context clock this closely. */
13
+ export declare const MASTER_SETTLED_SECONDS = 0.01;
14
+ export type ClockSample = {
15
+ contextTime: number;
16
+ masterTime: number;
17
+ };
18
+ /**
19
+ * The sequencer reports a lagging position for a few frames after it resumes.
20
+ * Audio is started only once the MIDI clock advances in step with the context clock.
21
+ */
22
+ export declare function isMasterClockSettled(previous: ClockSample | undefined, current: ClockSample): boolean;
23
+ export type AudioSyncInput = {
24
+ /** MIDI transport time in seconds. */
25
+ masterTime: number;
26
+ /** True while the MIDI engine is actually advancing. */
27
+ masterRunning: boolean;
28
+ /** See isMasterClockSettled; starting waits for it, keeping and stopping do not. */
29
+ masterSettled: boolean;
30
+ /** Seconds into the MIDI where the recording starts (negative trims its start). */
31
+ offset: number;
32
+ /** Recording duration in seconds. */
33
+ duration: number;
34
+ /**
35
+ * Where the current source is (or will be) in the recording now, or undefined
36
+ * when no source is scheduled. May be negative for a source scheduled to start later.
37
+ */
38
+ sourcePosition: number | undefined;
39
+ };
40
+ export type AudioSyncPlan = {
41
+ action: "stop";
42
+ } | {
43
+ action: "keep";
44
+ }
45
+ /** Start a new source after `delay` seconds, `bufferOffset` seconds into the recording. */
46
+ | {
47
+ action: "start";
48
+ delay: number;
49
+ bufferOffset: number;
50
+ };
51
+ export declare function planAudioSync(input: AudioSyncInput): AudioSyncPlan;
52
+ /** Peak amplitude per bin across all channels, for drawing a waveform. */
53
+ export declare function computeWaveformPeaks(channels: readonly Float32Array[], binCount: number): Float32Array;
@@ -0,0 +1,39 @@
1
+ import { BasicMIDI } from "spessasynth_core";
2
+ export type TrackId = string;
3
+ export type CanonicalNote = {
4
+ midi: number;
5
+ time: number;
6
+ duration: number;
7
+ velocity: number;
8
+ ticks: number;
9
+ };
10
+ export type TimeSignatureChange = {
11
+ ticks: number;
12
+ numerator: number;
13
+ denominator: number;
14
+ };
15
+ export type CanonicalTrack = {
16
+ id: TrackId;
17
+ sourceTrackIndex: number;
18
+ sourcePort: number;
19
+ sourceChannel?: number;
20
+ playbackPort?: number;
21
+ playbackChannel?: number;
22
+ playbackChannelIndex?: number;
23
+ name: string;
24
+ program?: number;
25
+ instrument: string;
26
+ instrumentFamily: string;
27
+ isDrums: boolean;
28
+ notes: CanonicalNote[];
29
+ };
30
+ export type CanonicalMidiDocument = {
31
+ original: BasicMIDI;
32
+ duration: number;
33
+ ppq: number;
34
+ timeSignatures: TimeSignatureChange[];
35
+ tracks: CanonicalTrack[];
36
+ };
37
+ export declare function parseCanonicalMidi(binary: ArrayBuffer, fileName?: string): CanonicalMidiDocument;
38
+ export declare function createTrackId(trackIndex: number, port: number, channel?: number): TrackId;
39
+ export declare function isChannelMessage(statusByte: number): boolean;
@@ -0,0 +1,75 @@
1
+ import { type AudioTrackSource, type CpMidiPlayer, type TrackRailMode } from "./player";
2
+ export type { AudioTrackSource, CpMidiPlayer, SoundFontSource, TrackRailMode } from "./player";
3
+ export type MountOptions = {
4
+ /** MIDI file URL or bytes. */
5
+ src: string | ArrayBuffer;
6
+ /** Shown in messages and used for the WAV export name. */
7
+ fileName?: string;
8
+ /**
9
+ * SF2/SF3/DLS as a URL or as bytes. Defaults to the bundled GeneralUser GS (SF3)
10
+ * next to the script. Pass bytes where the host cannot serve SoundFont files.
11
+ */
12
+ soundFont?: string | ArrayBuffer;
13
+ soundFontLabel?: string;
14
+ /** Folder holding the worklet, SoundFont and font. Defaults to the script's folder. */
15
+ assetBase?: string;
16
+ /** "auto" follows prefers-color-scheme. */
17
+ theme?: "auto" | "dark" | "light";
18
+ /** Pause other players on the page when this one starts. Default true. */
19
+ exclusive?: boolean;
20
+ /** Fetch the SoundFont at mount instead of on first play. Default true. */
21
+ preloadSoundFont?: boolean;
22
+ /** localStorage key for remembering mute/solo/volume/view state. Off by default. */
23
+ persistKey?: string;
24
+ /** Show the Export WAV button (downloads a file). Default true. */
25
+ wavExport?: boolean;
26
+ /** Show the SoundFont menu so visitors can load their own bank. Default false. */
27
+ soundFontMenu?: boolean;
28
+ /** Initial view: "arrangement" (tracks, the default) or "piano-roll". */
29
+ viewMode?: "piano-roll" | "arrangement";
30
+ /**
31
+ * The track list beside the notes: "open" (the default) or "collapsed" to its
32
+ * instrument icons, which visitors can toggle; "hidden" leaves it out entirely,
33
+ * along with the Tracks/Roll switch.
34
+ */
35
+ trackRail?: TrackRailMode;
36
+ /** Draw a piano keyboard beside the Roll view's pitch rows. Default false. */
37
+ pianoKeys?: boolean;
38
+ /**
39
+ * Starting height of each track in the Tracks view, 52–180 px. Without it tracks
40
+ * fit the player's height (up to 88 px). Visitors can still change it.
41
+ */
42
+ trackHeight?: number;
43
+ /** Recordings (mix, stems) that play in step with the MIDI as extra mixer rows. */
44
+ audioTracks?: readonly AudioTrackSource[];
45
+ };
46
+ export declare function setDefaultAssetBase(base: string): void;
47
+ /** Render a player into target's shadow root. Call destroy() on the result to remove it. */
48
+ export declare function mount(target: HTMLElement, options: MountOptions): CpMidiPlayer;
49
+ /**
50
+ * <cp-midi-player src="song.mid" audio="song.mp3"></cp-midi-player>
51
+ *
52
+ * Stems go in child elements, each becoming a mixer row that plays in step with the MIDI:
53
+ * <cp-midi-player src="song.mid">
54
+ * <cp-midi-player-audio src="vocals.mp3" label="Vocals"></cp-midi-player-audio>
55
+ * </cp-midi-player>
56
+ *
57
+ * Emits bubbling "play" and "pause" events; exposes play(), pause(), stop(), seek(), currentTime.
58
+ */
59
+ export declare class CpMidiPlayerElement extends HTMLElement {
60
+ #private;
61
+ static observedAttributes: string[];
62
+ get player(): CpMidiPlayer | undefined;
63
+ get currentTime(): number;
64
+ set currentTime(seconds: number);
65
+ get duration(): number;
66
+ get playing(): boolean;
67
+ play(): Promise<void>;
68
+ pause(): void;
69
+ stop(): void;
70
+ seek(seconds: number): void;
71
+ connectedCallback(): void;
72
+ disconnectedCallback(): void;
73
+ attributeChangedCallback(name: string, oldValue: string | null, value: string | null): void;
74
+ }
75
+ export declare function defineElement(tagName?: string): void;
@@ -0,0 +1,3 @@
1
+ export type DownloadProgress = (received: number, total?: number) => void;
2
+ /** Time out stalled transfers, while allowing large banks on slow connections. */
3
+ export declare function downloadBuffer(url: string, onProgress?: DownloadProgress, stallTimeout?: number): Promise<ArrayBuffer>;
@@ -0,0 +1,6 @@
1
+ export * from "./cp-midi-player";
2
+ declare global {
3
+ interface HTMLElementTagNameMap {
4
+ "cp-midi-player": import("./cp-midi-player").CpMidiPlayerElement;
5
+ }
6
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getGMProgramName(program: number, isDrums: boolean): string;
2
+ export declare function getGMProgramFamily(program: number, isDrums: boolean): string;
@@ -0,0 +1,7 @@
1
+ /** Retain the three most recently used idle engines for instant resume. */
2
+ export declare class IdleAudioEngines {
3
+ private idle;
4
+ retire(key: object, release: () => void): void;
5
+ cancel(key: object): void;
6
+ }
7
+ export declare const idleAudioEngines: IdleAudioEngines;
@@ -0,0 +1,2 @@
1
+ export declare function getInstrumentIconSvg(index: number): string;
2
+ export declare const instrumentIconCount: number;
@@ -0,0 +1,13 @@
1
+ export interface InstrumentFamilyPalette {
2
+ solid: string;
3
+ glow: string;
4
+ surface: string;
5
+ surfaceStrong: string;
6
+ border: string;
7
+ text: string;
8
+ }
9
+ export declare function resolveInstrumentFamily(family: string, isDrums: boolean, trackName: string, hasNotes: boolean): string;
10
+ export declare function getInstrumentThumbnailIndex(family: string, isDrums: boolean): number;
11
+ export declare function getInstrumentFamilyClass(family: string, isDrums: boolean): string;
12
+ export declare function getInstrumentFamilyColor(family: string, isDrums: boolean, variant?: number): string;
13
+ export declare function getInstrumentFamilyPalette(family: string, isDrums: boolean, variant?: number): InstrumentFamilyPalette;
@@ -0,0 +1,3 @@
1
+ import type { TimeSignatureChange } from "./canonical-midi.ts";
2
+ export declare function ticksToMeasures(ticks: number, ppq: number, signatures: readonly TimeSignatureChange[]): number;
3
+ export declare function signatureAtTick(ticks: number, signatures: readonly TimeSignatureChange[]): TimeSignatureChange;
@@ -0,0 +1,17 @@
1
+ export type ChaseableNote = {
2
+ midi: number;
3
+ time: number;
4
+ duration: number;
5
+ velocity: number;
6
+ };
7
+ export type ChaseableTrack = {
8
+ enabled: boolean;
9
+ playbackChannelIndex?: number;
10
+ notes: ChaseableNote[];
11
+ };
12
+ export type ChasedNote = {
13
+ channel: number;
14
+ midi: number;
15
+ velocity: number;
16
+ };
17
+ export declare function getActiveNotesAtTime(tracks: ChaseableTrack[], time: number): ChasedNote[];
@@ -0,0 +1,15 @@
1
+ export type SeekableNote = {
2
+ midi: number;
3
+ time: number;
4
+ duration: number;
5
+ };
6
+ export type SeekableTrack = {
7
+ enabled: boolean;
8
+ notes: SeekableNote[];
9
+ };
10
+ export type PianoRollSeek = {
11
+ displayTime: number;
12
+ engineTime: number;
13
+ snappedToNote: boolean;
14
+ };
15
+ export declare function resolvePianoRollSeek(tracks: SeekableTrack[], clickedTime: number, clickedMidi?: number): PianoRollSeek;
@@ -0,0 +1,10 @@
1
+ export type PitchRangeTrack = {
2
+ notes: readonly {
3
+ midi: number;
4
+ }[];
5
+ };
6
+ export type PitchRange = {
7
+ min: number;
8
+ max: number;
9
+ };
10
+ export declare function getMidiPitchRange(tracks: readonly PitchRangeTrack[]): PitchRange;
@@ -0,0 +1,16 @@
1
+ export declare class PlaybackCoordinator {
2
+ currentTime: number;
3
+ pendingEngineTime: number;
4
+ engineSeekPending: boolean;
5
+ playing: boolean;
6
+ private rebuildCount;
7
+ get rebuilding(): boolean;
8
+ updateFromEngine(time: number, duration: number): void;
9
+ requestPlay(): void;
10
+ requestPause(engineTime: number | undefined, duration: number): void;
11
+ seek(time: number, engineTime: number, duration: number): void;
12
+ beginRebuild(engineTime: number | undefined, duration: number): boolean;
13
+ completeRebuild(): boolean;
14
+ markEngineResumed(): void;
15
+ finish(): void;
16
+ }
@@ -0,0 +1,7 @@
1
+ import { BasicMIDI } from "spessasynth_core";
2
+ import { type CanonicalTrack, type TrackId } from "./canonical-midi.ts";
3
+ import type { TrackPresetSelection } from "./track-preset.ts";
4
+ export type PlaybackMidiOptions = {
5
+ patchOverrides?: ReadonlyMap<TrackId, TrackPresetSelection>;
6
+ };
7
+ export declare function buildPlaybackMidi(original: BasicMIDI, tracks: readonly CanonicalTrack[], enabledTrackIds: ReadonlySet<TrackId>, options?: PlaybackMidiOptions): ArrayBuffer;
@@ -0,0 +1,86 @@
1
+ import { type DownloadProgress } from "./download";
2
+ import { type PersistedViewerState, type ViewerMode } from "./viewer-state";
3
+ export type SoundFontSource = {
4
+ url: string;
5
+ label: string;
6
+ custom: boolean;
7
+ };
8
+ export type AudioExportWriter = {
9
+ write(chunk: Uint8Array): Promise<void>;
10
+ /** Resolves with the saved file name once the export is durable. */
11
+ finish(): Promise<string | undefined>;
12
+ abort(message: string): void;
13
+ };
14
+ /** Everything the player needs from its surroundings (VS Code, a web page, ...). */
15
+ export type PlayerHost = {
16
+ loadState?(): unknown;
17
+ saveState?(state: PersistedViewerState): void;
18
+ persistViewMode?(viewMode: ViewerMode): void;
19
+ /** Ask the host for another bank; the host answers with player.setSoundFont(). */
20
+ requestSoundFont?(kind: "default" | "custom"): void;
21
+ /** Resolves undefined when the user cancels. Omit to hide WAV export. */
22
+ beginAudioExport?(suggestedName: string): Promise<AudioExportWriter | undefined>;
23
+ fetchSoundBank?(url: string, onProgress?: DownloadProgress): Promise<ArrayBuffer>;
24
+ onPlaybackChange?(playing: boolean): void;
25
+ };
26
+ /** A recording that plays in step with the MIDI, e.g. the source mix or a stem. */
27
+ export type AudioTrackSource = {
28
+ url: string;
29
+ label: string;
30
+ /** Seconds into the MIDI where the recording starts (negative trims its start). */
31
+ offset?: number;
32
+ /** Display before this MIDI track (1-based). Omit to display above all MIDI. */
33
+ beforeMidiTrack?: number;
34
+ };
35
+ export type PlayerConfig = {
36
+ /** Element the player renders into. */
37
+ app: HTMLElement;
38
+ /** Receives global shortcuts (Space, Escape, menu arrows). */
39
+ keyboardTarget: EventTarget;
40
+ /** Receives outside clicks that close the SoundFont menu. */
41
+ pointerTarget: EventTarget;
42
+ midi: string | ArrayBuffer;
43
+ fileName: string;
44
+ workletUrl: string;
45
+ soundFont?: SoundFontSource;
46
+ /** Load the bank immediately instead of on first play or export. */
47
+ preloadSoundFont?: boolean;
48
+ /** Explicit starting state; its view mode overrides a remembered one. */
49
+ viewerState?: unknown;
50
+ /** View used when neither viewerState nor saved state names one. */
51
+ defaultViewMode?: ViewerMode;
52
+ /**
53
+ * The track rail: "open" (default) or "collapsed" to its instrument icons, which
54
+ * a visitor can toggle and saved state remembers; "hidden" removes it and its toggle.
55
+ */
56
+ trackRail?: TrackRailMode;
57
+ /** Draw a piano keyboard beside the Roll view's pitch rows. Off by default. */
58
+ pianoKeys?: boolean;
59
+ /**
60
+ * Starting track height in the Tracks view, 52–180 px; without it rows fit the
61
+ * player's height. A height the visitor picks (and saved state keeps) wins.
62
+ */
63
+ trackHeight?: number;
64
+ audioTracks?: readonly AudioTrackSource[];
65
+ host: PlayerHost;
66
+ };
67
+ export type TrackRailMode = "open" | "collapsed" | "hidden";
68
+ export type CpMidiPlayer = {
69
+ readonly duration: number;
70
+ /** MIDI tracks plus audio tracks, once ready has resolved. */
71
+ readonly trackCount: number;
72
+ /** The track height the page or the visitor chose, in px; undefined while tracks fit the player. */
73
+ readonly trackHeight: number | undefined;
74
+ readonly currentTime: number;
75
+ readonly playing: boolean;
76
+ readonly ready: Promise<void>;
77
+ play(): Promise<void>;
78
+ pause(): void;
79
+ stop(): void;
80
+ seek(seconds: number): void;
81
+ /** Repaint the canvas, e.g. after the theme changed; colors are read from CSS. */
82
+ redraw(): void;
83
+ setSoundFont(source: SoundFontSource): void;
84
+ destroy(): void;
85
+ };
86
+ export declare function createCpMidiPlayer(config: PlayerConfig): CpMidiPlayer;
@@ -0,0 +1,6 @@
1
+ import { type MIDIPatch, type MIDIPatchFull, type MIDISystem } from "spessasynth_core";
2
+ export type PresetResolution = {
3
+ name: string;
4
+ fallback: boolean;
5
+ };
6
+ export declare function resolvePreset(presets: MIDIPatchFull[], requested: MIDIPatch, system: MIDISystem): PresetResolution | undefined;
@@ -0,0 +1,7 @@
1
+ export type RulerSubdivision = 1 | 2 | 4;
2
+ /**
3
+ * Keeps ruler details useful at every horizontal zoom level without turning
4
+ * the header into a dense barcode.
5
+ */
6
+ export declare function chooseRulerSubdivision(quarterNoteWidth: number): RulerSubdivision;
7
+ export declare function getRulerTickLength(kind: "measure" | "beat" | "subdivision"): number;
@@ -0,0 +1,17 @@
1
+ export type AudibilityTrack = {
2
+ id: string;
3
+ enabled: boolean;
4
+ solo: boolean;
5
+ };
6
+ export declare function hasSoloedTracks(tracks: readonly Pick<AudibilityTrack, "solo">[]): boolean;
7
+ export declare function isTrackAudible(track: Pick<AudibilityTrack, "enabled" | "solo">, anyTrackSoloed: boolean): boolean;
8
+ export declare function getAudibleTrackIds(tracks: readonly AudibilityTrack[]): Set<string>;
9
+ export declare function haveSameTrackIds(left: ReadonlySet<string>, right: ReadonlySet<string>): boolean;
10
+ export declare function toggleTrackMute(track: AudibilityTrack): void;
11
+ export declare function toggleTrackSolo(track: AudibilityTrack): void;
12
+ /**
13
+ * The live engine must always keep a timed MIDI sequence loaded. When every
14
+ * track is muted, retain all tracks in the engine and silence their channel
15
+ * gains instead of loading a note-less sequence that cannot advance reliably.
16
+ */
17
+ export declare function getEngineTrackIds(tracks: readonly AudibilityTrack[]): Set<string>;
@@ -0,0 +1,7 @@
1
+ export type MixableTrack = {
2
+ id: string;
3
+ gain: number;
4
+ };
5
+ export declare const MAX_TRACK_GAIN = 2;
6
+ export declare function updateTrackGain(tracks: MixableTrack[], trackId: string, gain: number): boolean;
7
+ export declare function collectTrackGains(tracks: readonly MixableTrack[]): Record<string, number>;
@@ -0,0 +1,18 @@
1
+ export type TrackPresetSelection = {
2
+ bankMSB: number;
3
+ bankLSB: number;
4
+ program: number;
5
+ isGMGSDrum: boolean;
6
+ name: string;
7
+ };
8
+ export type SoundFontPreset = TrackPresetSelection & {
9
+ isDrum?: boolean;
10
+ };
11
+ export declare const CHOIR_AAHS_PROGRAM = 52;
12
+ export declare function getDefaultTrackPreset(track: {
13
+ program?: number;
14
+ isDrums: boolean;
15
+ }): TrackPresetSelection | null;
16
+ export declare function presetKey(preset: Pick<TrackPresetSelection, "bankMSB" | "bankLSB" | "program" | "isGMGSDrum">): string;
17
+ export declare function findPresetByKey<T extends SoundFontPreset>(presets: readonly T[], key: string): T | undefined;
18
+ export declare function normalizeTrackPreset(value: unknown): TrackPresetSelection | null | undefined;
@@ -0,0 +1,16 @@
1
+ export type TransportSequencer = {
2
+ paused: boolean;
3
+ currentTime: number;
4
+ play(): void;
5
+ };
6
+ /**
7
+ * SpessaSynth advances a paused seek to the next MIDI event while reconstructing
8
+ * channel state. Enter playing state first so the requested wall-clock position
9
+ * remains exact, including silent gaps between events.
10
+ */
11
+ export declare function resumeTransport(sequencer: TransportSequencer, targetTime: number, seekPending: boolean): void;
12
+ /**
13
+ * Apply seeks immediately while playing. While paused, defer the seek until
14
+ * resume so SpessaSynth cannot replace the requested time with the next event.
15
+ */
16
+ export declare function seekTransport(sequencer: TransportSequencer, targetTime: number): boolean;
@@ -0,0 +1,9 @@
1
+ export interface ViewWindow {
2
+ start: number;
3
+ end: number;
4
+ }
5
+ export declare function resetViewWindowToStart(viewStart: number, viewEnd: number, duration: number): ViewWindow;
6
+ export declare function centerViewWindow(time: number, viewStart: number, viewEnd: number, duration: number): ViewWindow;
7
+ export declare function followPlaybackView(time: number, viewStart: number, viewEnd: number, duration: number, followRatio?: number): ViewWindow;
8
+ export declare function zoomViewWindow(anchorTime: number, anchorRatio: number, factor: number, viewStart: number, viewEnd: number, duration: number, minimumWindow?: number): ViewWindow;
9
+ export declare function panViewWindow(deltaSeconds: number, viewStart: number, viewEnd: number, duration: number): ViewWindow;
@@ -0,0 +1,29 @@
1
+ import { type TrackPresetSelection } from "./track-preset.ts";
2
+ export type ViewerMode = "piano-roll" | "arrangement";
3
+ export type PersistedTrackState = {
4
+ enabled: boolean;
5
+ solo: boolean;
6
+ gain: number;
7
+ presetOverride?: TrackPresetSelection | null;
8
+ };
9
+ export type PersistedViewerState = {
10
+ presetDefaultsVersion: number;
11
+ followPlayhead: boolean;
12
+ viewMode: ViewerMode;
13
+ arrangementTrackHeight: number;
14
+ arrangementTrackHeightManual: boolean;
15
+ pianoRollRowHeight: number;
16
+ trackRailCollapsed: boolean;
17
+ tracks: Record<string, PersistedTrackState>;
18
+ };
19
+ export declare const DEFAULT_ARRANGEMENT_TRACK_HEIGHT = 88;
20
+ export declare const DEFAULT_PIANO_ROLL_ROW_HEIGHT = 8;
21
+ export declare const CURRENT_PRESET_DEFAULTS_VERSION = 2;
22
+ export declare function normalizeViewerState(value: unknown): Partial<PersistedViewerState>;
23
+ export declare function collectViewerTrackState(tracks: readonly {
24
+ id: string;
25
+ enabled: boolean;
26
+ solo: boolean;
27
+ gain: number;
28
+ presetOverride: TrackPresetSelection | null;
29
+ }[]): Record<string, PersistedTrackState>;
@@ -0,0 +1,31 @@
1
+ /**
2
+ * AudioWorklet is only exposed in secure contexts (HTTPS or localhost). On a
3
+ * plain-HTTP page this module runs the same spessasynth processor script on
4
+ * the main thread instead, driven by a ScriptProcessorNode for live playback
5
+ * and pumped by hand for offline rendering.
6
+ *
7
+ * The processor script is evaluated with stand-ins for the worklet globals it
8
+ * touches (AudioWorkletProcessor, registerProcessor, sampleRate, currentTime);
9
+ * it reads `currentTime` only once, at construction, and counts samples after
10
+ * that, so a fixed value per evaluation is enough.
11
+ */
12
+ export type FallbackWorkletNode = {
13
+ readonly context: BaseAudioContext;
14
+ readonly port: MessagePort;
15
+ connect(destination: AudioNode, output?: number): void;
16
+ disconnect(): void;
17
+ /** Offline contexts only: renders the processor into `target` from its start. */
18
+ renderInto(target: AudioBuffer, onProgress?: (fraction: number) => void): Promise<void>;
19
+ };
20
+ export type WorkletNodeCreator = (context: BaseAudioContext, name: string, options?: AudioWorkletNodeOptions) => AudioWorkletNode;
21
+ /**
22
+ * Chrome keeps the AudioWorkletNode constructor on insecure pages but leaves
23
+ * `context.audioWorklet` undefined, so test the context itself.
24
+ */
25
+ export declare function needsWorkletFallback(context: BaseAudioContext): boolean;
26
+ /**
27
+ * Loads the processor script and returns a node creator for
28
+ * `new WorkletSynthesizer(context, { audioNodeCreators: { worklet } })`.
29
+ * `nodes` receives each node created, so offline renders can be pumped.
30
+ */
31
+ export declare function createFallbackWorkletCreator(workletUrl: string, context: BaseAudioContext, nodes?: FallbackWorkletNode[]): Promise<WorkletNodeCreator>;
package/package.json CHANGED
@@ -1,6 +1,65 @@
1
1
  {
2
2
  "name": "cp-midi-player",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.0",
4
+ "description": "Drop-in multi-track MIDI player for web pages: a <cp-midi-player> custom element with track and piano-roll views, mute/solo mixer, SoundFont playback, and audio stems in sync.",
5
+ "license": "MIT",
6
+ "type": "module",
7
+ "main": "./dist/cp-midi-player.js",
8
+ "module": "./dist/cp-midi-player.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/types/esm.d.ts",
12
+ "default": "./dist/cp-midi-player.js"
13
+ },
14
+ "./iife": "./dist/cp-midi-player.iife.js",
15
+ "./dist/*": "./dist/*",
16
+ "./package.json": "./package.json"
17
+ },
18
+ "files": [
19
+ "dist"
20
+ ],
21
+ "keywords": [
22
+ "midi",
23
+ "midi-player",
24
+ "web-component",
25
+ "custom-element",
26
+ "piano-roll",
27
+ "soundfont",
28
+ "sf2",
29
+ "stems",
30
+ "daw",
31
+ "music",
32
+ "listening-test",
33
+ "music-transcription"
34
+ ],
35
+ "scripts": {
36
+ "clean": "node scripts/clean.mjs",
37
+ "build": "node scripts/build.mjs && tsc -p tsconfig.types.json",
38
+ "typecheck": "tsc --noEmit",
39
+ "test": "node --experimental-strip-types --test tests/*.test.mjs",
40
+ "make-sf3": "node scripts/make-sf3.mjs",
41
+ "prepack": "npm run build"
42
+ },
43
+ "devDependencies": {
44
+ "spessasynth_core": "^4.3.15",
45
+ "spessasynth_lib": "^4.3.11",
46
+ "esbuild": "^0.25.5",
47
+ "typescript": "^5.8.3"
48
+ },
49
+ "types": "./dist/types/esm.d.ts",
50
+ "jsdelivr": "./dist/cp-midi-player.js",
51
+ "unpkg": "./dist/cp-midi-player.js",
52
+ "sideEffects": true,
53
+ "repository": {
54
+ "type": "git",
55
+ "url": "git+https://github.com/tanchihpin0517/cp-midi-player.git"
56
+ },
57
+ "homepage": "https://tanchihpin0517.github.io/cp-midi-player/",
58
+ "bugs": {
59
+ "url": "https://github.com/tanchihpin0517/cp-midi-player/issues"
60
+ },
61
+ "author": "Chih-Pin Tan",
62
+ "contributors": [
63
+ "Song-Ze (Jimmy) Yu"
64
+ ]
65
+ }