UNPKG

wave-roll

Version:

JavaScript Library for Comparative MIDI Piano-Roll Visualization

75 lines 3.05 kB
import { ParsedMidi, MidiInput, NoteData, ControlChangeEvent, InstrumentFamily } from "@/lib/midi/types"; export interface SustainRegion { start: number; end: number; duration: number; } /** * GM Program Number to Instrument Family mapping. * Based on General MIDI Level 1 specification. * Reference: https://gleitz.github.io/midi-js-soundfonts/FluidR3_GM/names.json */ export declare function getInstrumentFamily(program: number, channel: number): InstrumentFamily; /** * Get a human-readable default name for an instrument family. */ export declare function getInstrumentFamilyName(family: InstrumentFamily): string; /** * Apply sustain pedal elongation to MIDI notes. * * Algorithm (based on onsets-and-frames): * 1) When sustain pedal is pressed (CC64 >= threshold), notes continue sounding after note-off * 2) Notes are released when sustain pedal is released (CC64 < threshold) or when the same pitch is re-played * 3) Handles multiple simultaneous notes of the same pitch via stacking (FIFO) */ export declare function applySustainPedalElongation(notes: NoteData[], controlChanges: ControlChangeEvent[], threshold?: number, channel?: number): NoteData[]; /** * Safe wrapper with validation and optional max elongation. */ export declare function applySustainPedalElongationSafe(notes: NoteData[], controlChanges: ControlChangeEvent[], options?: { threshold?: number; channel?: number; maxElongation?: number; verbose?: boolean; }): NoteData[]; /** * Analyze sustain pedal usage from CC64 events. */ export declare function analyzeSustainPedalUsage(controlChanges: ControlChangeEvent[], threshold?: number): { hasSustain: boolean; sustainCount: number; averageSustainDuration: number; totalSustainTime: number; sustainRegions: SustainRegion[]; }; /** * Parses a MIDI file and extracts musical data in the Tone.js format * * This function can load MIDI files from either a URL or a File object, * then parses them using the @tonejs/midi library. It focuses on the first * piano track and extracts notes, timing, and metadata. * * @param input - Either a URL string or a File object containing the MIDI data * @returns Promise that resolves to a ParsedMidi object containing all extracted data * @throws Error if the MIDI file cannot be loaded or parsed * * @example * ```typescript * // Load from URL * const midiData = await parseMidi('https://example.com/song.mid'); * * // Load from File object (e.g., from file input) * const fileInput = document.querySelector('input[type="file"]') as HTMLInputElement; * const file = fileInput.files[0]; * const midiData = await parseMidi(file); * * // console.log(`Song: ${midiData.header.name}`); * // console.log(`Duration: ${midiData.duration} seconds`); * // console.log(`Notes: ${midiData.notes.length}`); * ``` */ export declare function parseMidi(input: MidiInput, options?: { applyPedalElongate?: boolean; pedalThreshold?: number; }): Promise<ParsedMidi>; //# sourceMappingURL=midi-parser.d.ts.map