UNPKG

shimi

Version:

A JS framework for building complex MIDI applications

118 lines (117 loc) 4.78 kB
import { ClockChildFinishedEvent, IClockChild } from './Clock'; import { IMidiIn } from './MidiIn'; import { IMetronome } from './Metronome'; import { Clip } from './Clip'; import ShimiEvent, { ShimiEventData } from './ShimiEvent'; /** * The ClipRecorderEventData class extends ShimiEventData. It contains a reference to the source ClipRecorder that created the event data, as well as information about the clip which the recorder has been constructing. * * @category Clips */ export declare class ClipRecorderEventData extends ShimiEventData<ClipRecorder> { /** The Clip object which has been under construction by the ClipRecorder. */ get clip(): Clip; private _clip; constructor(source: ClipRecorder, clip: Clip); } /** * The ClipRecorderEvent class extends ShimiEvent, providing an object which can be subscribed to. * * It distributes events which point back to the source ClipRecorder, and a ClipRecorderEventData object that contains the event information. * * @category Clips */ export declare class ClipRecorderEvent extends ShimiEvent<ClipRecorderEventData, ClipRecorder> { } /** * The ClipRecorder class subscribes to an IMidiIn and records incoming MIDI data into a clip. * * Once the ClipRecorder has finished, a new clip is dispatched from the newClip event. * * @category Clips */ export default class ClipRecorder implements IClockChild { /** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */ get typeName(): string; /** The metronome which the recorder uses for tracking passed beats. */ get metronome(): IMetronome; set metronome(value: IMetronome); private _metronome; /** The MIDI input which data gets recorded from. */ get midiIn(): IMidiIn; set midiIn(value: IMidiIn); private _midiIn; private _addMidiInSubscriptions; private _removeMidiInSubscriptions; /** * How many beats to stop the clip recording after. * * This also sets the duration of the clip that will be returned at the end of the recording. * * The default value is 4. If this is set to null, then the recorder will only stop when explicitly told, and the returned clip's length will be however long the recorder ended up running for. */ get beatCount(): number; set beatCount(value: number); private _beatCount; /** How many beats have passed since recording started. */ get beatsPassed(): number; private _beatsPassed; /** The clip which gets built up and returned. */ private _clip; /** * The newClip event dispatches a new clip object once recording has completed. * * This example will create a ClipRecorder that records a 16 beat phrase. Once done, the phrase is automatically played back on loop: * ``` * const clipRecorder = new ClipRecorder(metronome, midiIn); * clipRecorer.beatCount = 16; * clipRecorder.newClip.add(evt => { * const clipPlayer = new ClipPlayer(evt.clip, metronome, midiOut); * clock.addChild(clipPlayer); * }); * clock.addChild(clipRecorder); * ``` */ get newClip(): ClipRecorderEvent; private _newClip; /** * @param metronome The metronome which the recorder uses for tracking passed beats. * @param midiIn The MIDI input which data gets recorded from. */ constructor(metronome: IMetronome, midiIn: IMidiIn); private _getClipPosition; private _inProgressNotes; private _onNoteOn; private _onNoteOff; private _onControlChange; private _onPitchBend; /** Provides a way of identifying recorders so they can be easily retrieved later. */ get ref(): string; set ref(value: string); private _ref; /** * This method is intended to be called by a clock to provide regular updates. It should not be called by consumers of the library. * @param deltaMs How many milliseconds have passed since the last update cycle. * @returns */ update(deltaMs: number): void; /** Returns true if the clip recorder has finished recording. */ get isFinished(): boolean; private _isFinished; /** This event fires when the clip recorder finishes. */ get finished(): ClockChildFinishedEvent; private _finished; /** Calling this tells the clip recorder to stop whatever it's doing and that it will no longer be used. */ finish(): void; /** * Provides a way for setting the ref through a chained function call. For example: * * ``` * clock.addChild(new ClipRecorder(metronome, midiIn).withRef('recorder')); * ``` * * @param ref The ref to set on the object. * @returns The calling object. */ withRef(ref: string): IClockChild; }