shimi
Version:
A JS framework for building complex MIDI applications
129 lines (128 loc) • 5.75 kB
TypeScript
import { Clip } from './Clip';
import { IMetronome } from './Metronome';
import Note from './Note';
import { ClockChildFinishedEvent, IClockChild } from './Clock';
import { IMidiOut } from './MidiOut';
/**
* The ClipPlayer facilitates the playing of a clip.
*
* The ClipPlayer should be added to a clock to receive regular updates. It should hold a reference to a metronome for beat timings. It should hold a reference to a MIDI Out for it to send MIDI data to. And it should hold a reference to a clip, which it will play.
*
* @category Clips
*/
export default class ClipPlayer implements IClockChild {
/** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */
get typeName(): string;
/** The clip to play. */
get clip(): Clip;
set clip(value: Clip);
private _clip;
/**
* Which channel to play the clip on. Valid values range from 0 - 15.
*
* The default value is 0.
*/
get channel(): number;
set channel(value: number);
private _channel;
/** Provides a way of identifying a clip player so that it can be easily retrieved later. */
get ref(): string;
set ref(value: string);
private _ref;
/** The metronome which the player uses for tracking passed beats. */
get metronome(): IMetronome;
set metronome(value: IMetronome);
private _metronome;
/** The IMidiOut which MIDI data generated from the clip gets sent to. */
get midiOut(): IMidiOut;
set midiOut(value: IMidiOut);
private _midiOut;
/** How many beats in the clip to play for every beat that passes in actual time. For example: 1.5 means the clip is played 1.5 times faster than it would normally. */
get speed(): number;
set speed(value: number);
private _speed;
/** Which beat of the clip to start playing from. This allows for a clip player to begin playing a clip from half-way through for example. */
get startBeat(): number;
set startBeat(value: number);
private _startBeat;
/** How many beats should have passed before the clip player stops. The default value is null, meaning the ClipPlayer never stops, and continually loops playback of the clip. */
get beatCount(): number;
set beatCount(value: number);
private _beatCount;
/**
* If not running, then the player won't do anything with each update cycle. This allows a way to temporarily pause playback of the clip, without having to remove it from the clock.
*
* By default this is set to true.
*/
get running(): boolean;
set running(value: boolean);
private _running;
/** Allows attaching custom logic to modify each note produced by the clip player. The provided function should accept a note as its only parameter. For example:
* ```
* clipPlayer.noteModifier = (note) => {
* note.pitch += 12;
* note.velocity = 40 + Math.floor(Math.random() * 40);
* };
* ```
*/
get noteModifier(): ((note: Note) => void);
set noteModifier(value: ((note: Note) => void));
private _noteModifier;
/** How many beats have passed since the clip player started. */
get beatsPassed(): number;
private _beatsPassed;
/** Returns true if the clip player has finished playing its clip. */
get isFinished(): boolean;
private _isFinished;
/** This event fires when the clip player finishes. */
get finished(): ClockChildFinishedEvent;
private _finished;
/** If set to true, then no new notes will be generated by the player, and all existing ones will be stopped */
get muteNotes(): boolean;
set muteNotes(value: boolean);
private _muteNotes;
/** If set to true, then no control change events will be dispatched by the player */
get muteCCs(): boolean;
set muteCCs(value: boolean);
private _muteCCs;
/** If set to true, then no new bend events will be dispatched by the player */
get muteBends(): boolean;
set muteBends(value: boolean);
private _muteBends;
/** If set to true, then no events of any kind will be dispatched by the player. All existing notes will be stopped */
get muteAll(): boolean;
set muteAll(value: boolean);
private _notes;
/**
* @param clip The clip to play.
* @param metronome The metronome which the player uses for tracking passed beats.
* @param midiOut The IMidiOut which MIDI data generated from the clip gets sent to.
*/
constructor(clip: Clip, metronome: IMetronome, midiOut: IMidiOut);
/** Start the running of the clip player. This is not needed unless you've previously explicitly paused or stopped it. */
start(): void;
/** Halt playback of the clip, with the playback position retained to allow for it to be resumed later. */
pause(): void;
/** Halt playback of the clip, discarding all information about how much of the clip has already been played. */
stop(): void;
/**
* 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;
/** Calling this tells the clip player 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 ClipPlayer(clip, metronome, midiOut).withRef('player'));
* ```
*
* @param ref The ref to set on the object.
* @returns The calling object.
*/
withRef(ref: string): IClockChild;
private _endAllNotes;
}