UNPKG

shimi

Version:

A JS framework for building complex MIDI applications

96 lines (95 loc) 4.14 kB
import { Arpeggio } from './Arpeggio'; import Chord from './Chord'; import { ClockChildFinishedEvent, IClockChild } from './Clock'; import { Note } from './index'; import { IMetronome } from './Metronome'; import { IMidiOut } from './MidiOut'; import PropertyTracker from './PropertyTracker'; /** * The Arpeggiator is much like to Arpeggios, what the ClipPlayer is to Clips. * * The Arpeggiator 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 notes to. It should hold a reference to an arpeggio, which defines the shape that it will play. And it should hold a reference which defines what chord it should play the arpeggio shape around. * * @category Chords & Scales */ export default class Arpeggiator implements IClockChild { /** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */ get typeName(): string; /** Which arpeggio to play */ get arpeggio(): Arpeggio; set arpeggio(value: Arpeggio); private _arpeggio; /** Which chord to play. Setting this will cause all currently playing notes to stop. */ get chord(): Chord; set chord(value: Chord); private _chord; /** The default channel for arpeggiated notes to be played on. */ get channel(): number; set channel(value: number); private _channel; /** Provides a way of identifying arpeggiators so they can easily be retrieved later */ get ref(): string; set ref(value: string); private _ref; /** The metronome which the player uses for tracking beat timings */ get metronome(): IMetronome; set metronome(value: IMetronome); private _metronome; /** The MidiOut which data from the arpeggio gets played on */ get midiOut(): IMidiOut; set midiOut(value: IMidiOut); private _midiOut; /** How many beats in the arpeggio to play for every beat that passes in actual time. For example: 1.5 means the arpeggio is played 1.5 times faster than it would normally. */ get speed(): number; set speed(value: number); private _speed; /** Which beat of the arpeggio playback is at */ get beat(): number; set beat(value: number); get beatTracker(): PropertyTracker<number>; private _beatTracker; /** If not running, then the arpeggiator won't do anything with each update cycle */ get running(): boolean; set running(value: boolean); private _running; /** * Allows attaching custom logic to modify each note produced by the arpeggiator. * * For example: * ``` * const arp = new Arpeggiator(arpeggio, metronome, midiOut); * arp.noteModifier = note => note.velocity = Math.floor(Math.random() * 128); //Give each arpeggiated note a random velocity * ``` */ get noteModifier(): ((note: Note) => void); set noteModifier(value: ((note: Note) => void)); private _noteModifier; /** Signifies whether the arpeggiator has stopped. */ get isFinished(): boolean; private _isFinished; /** This event fires when the arpeggiator finishes. */ get finished(): ClockChildFinishedEvent; private _finished; private _notes; constructor(arpeggio: Arpeggio, metronome: IMetronome, midiOut: IMidiOut); /** * 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 arpeggiator 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 Arpeggiator(arpeggio, metronome, midiOut).withRef('arpeggiator')); * ``` * * @param ref The ref to set on the object. * @returns The calling object. */ withRef(ref: string): IClockChild; private _endAllNotes; }