UNPKG

wave-roll

Version:

JavaScript Library for Comparative MIDI Piano-Roll Visualization

225 lines 8.22 kB
import { NoteData, ParsedMidi, InstrumentFamily } from "@/lib/midi/types"; import { ColorPalette, MultiMidiState } from "./types"; /** * Manages multiple MIDI files with visualization */ export declare class MultiMidiManager { private state; private colorIndex; private onStateChange?; /** Multiple subscribers for UI components */ private listeners; constructor(); /** * Set state change callback */ setOnStateChange(callback: (state: MultiMidiState) => void): void; /** * Subscribe to state changes. Returns an unsubscribe function. */ subscribe(cb: (state: MultiMidiState) => void): () => void; /** * Get current state */ getState(): MultiMidiState; /** * Get active palette */ private getActivePalette; /** * Get next color from active palette */ private getNextColor; /** * Reset color index to match current file count */ private resetColorIndex; /** * Add a MIDI file */ addMidiFile(fileName: string, parsedData: ParsedMidi, displayName?: string, originalInput?: File | string): string; /** * Extract initial BPM from parsed MIDI data. * Uses tempo event at or closest to time=0. * Falls back to 120 BPM if no tempo events are present. */ private extractInitialBpm; /** * Remove a MIDI file */ removeMidiFile(id: string): void; /** * Toggle visibility of a MIDI file */ toggleVisibility(id: string): void; /** * Toggle mute state of a MIDI file (audio only) */ toggleMute(id: string): void; /** * Set visibility of a specific track within a MIDI file. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) * @param visible - Whether the track should be visible */ setTrackVisibility(fileId: string, trackId: number, visible: boolean): void; /** * Toggle visibility of a specific track within a MIDI file. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ toggleTrackVisibility(fileId: string, trackId: number): void; /** * Check if a specific track is visible. * Returns true if trackVisibility is not set (default visible). * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ isTrackVisible(fileId: string, trackId: number): boolean; /** * Toggle sustain pedal visibility for a specific track within a MIDI file. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ toggleTrackSustainVisibility(fileId: string, trackId: number): void; /** * Check if sustain pedal is visible for a specific track. * Returns true if trackSustainVisibility is not set (default visible). * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ isTrackSustainVisible(fileId: string, trackId: number): boolean; /** * Toggle mute state of a specific track within a MIDI file. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ toggleTrackMute(fileId: string, trackId: number): void; /** * Check if a specific track is muted. * Returns false if trackMuted is not set (default unmuted). * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ isTrackMuted(fileId: string, trackId: number): boolean; /** * Set volume for a specific track within a MIDI file. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) * @param volume - Volume level (0-1) */ setTrackVolume(fileId: string, trackId: number, volume: number): void; /** * Get volume for a specific track. * Returns 1.0 if trackVolume is not set (default full volume). * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ getTrackVolume(fileId: string, trackId: number): number; /** * Get last non-zero volume for a specific track. * Used to restore volume when unmuting a track. * Returns 1.0 if trackLastNonZeroVolume is not set (default full volume). * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ getTrackLastNonZeroVolume(fileId: string, trackId: number): number; /** * Set auto instrument state for a specific track within a MIDI file. * When enabled, the track will use its instrumentFamily soundfont instead of default piano. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) * @param useAuto - Whether to use auto instrument matching */ setTrackAutoInstrument(fileId: string, trackId: number, useAuto: boolean): void; /** * Check if a specific track uses auto instrument matching. * Returns true if trackUseAutoInstrument is not set (default auto-instrument). * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ isTrackAutoInstrument(fileId: string, trackId: number): boolean; /** * Get the instrument family for a specific track. * Looks up the instrumentFamily from the parsed MIDI track data. * Returns 'piano' as fallback if track info is not available. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ getTrackInstrumentFamily(fileId: string, trackId: number): InstrumentFamily; /** * Get the MIDI Program Number for a specific track. * Returns 118 (synth_drum) for drum tracks (channel 9/10). * Returns 0 (acoustic_grand_piano) as fallback if track info is not available. * @param fileId - The ID of the MIDI file * @param trackId - The track ID (0-based index) */ getTrackProgram(fileId: string, trackId: number): number; /** * Update name */ updateName(id: string, name: string): void; /** * Update file color */ updateColor(id: string, color: number): void; /** * Reorder files within the state array. * @param sourceIndex - The current index of the file. * @param targetIndex - The desired index after the move. */ reorderFiles(sourceIndex: number, targetIndex: number): void; /** * Set active palette */ setActivePalette(paletteId: string): void; /** * Add custom palette */ addCustomPalette(palette: ColorPalette): void; /** * Update an existing custom palette. Only applicable to user-defined palettes. * If the palette is currently active, note that colors of existing files will be reassigned. * @param id Palette identifier * @param patch Partial properties to update (name and/or colors) */ updateCustomPalette(id: string, patch: Partial<Omit<ColorPalette, "id">>): void; /** * Remove a user-defined custom palette. * If the palette is active, fall back to another palette and reassign colors. */ removeCustomPalette(id: string): void; /** * Get combined notes from visible files, respecting track visibility. * Notes from hidden tracks are excluded. */ getVisibleNotes(): Array<{ note: NoteData; color: number; fileId: string; }>; /** * Get total duration across all visible files */ getTotalDuration(): number; /** * Clear all files */ clearAll(): void; /** * Notify state change */ private notifyStateChange; /** * Toggle sustain overlay visibility of a MIDI file (visualisation only) */ toggleSustainVisibility(id: string): void; /** * Reparse all MIDI files with new settings (e.g., pedal elongate) */ reparseAllFiles(options?: { applyPedalElongate?: boolean; pedalThreshold?: number; }, onProgress?: (current: number, total: number) => void): Promise<void>; } //# sourceMappingURL=multi-midi-manager.d.ts.map