shimi
Version:
A JS framework for building complex MIDI applications
103 lines (102 loc) • 5.89 kB
TypeScript
import { IMidiIn, MidiInEvent } from './MidiIn';
import { IMidiOut } from './MidiOut';
import * as messages from './MidiMessages';
import Note from './Note';
import { ClockChildFinishedEvent, IClockChild } from './Clock';
/**
* The MidiBus is a combination of both MidiIn & MidiOut. It gets data passed to it through the methods & properties that it implements from the IMidiOut interface, and in turn, distributes that data through the events that it implements from the IMidiIn interface.
*
* The typical use cases of this are when you want some common actions to be applied to MIDI data being generated from a number of different places within your shimi application. For example, you might have a number of different processes generating a number of different instrument parts, and want to make sure that simple pitch correction is applied to all parts.
*
* Rather than modify the logic of each separate process, you could instead have each process connect to a common MidiBus, then connect that MidiBus up to a MidiOut, and just insert pitch correction logic in that connection from MidiBus to MidiOut.
*
* @category Midi IO
*/
export default class MidiBus implements IMidiIn, IMidiOut, IClockChild {
/** Returns the name of this type. This can be used rather than instanceof which is sometimes unreliable. */
get typeName(): string;
constructor();
/** The noteOff property can be subscribed to, to receive all Note Off messages that pass through the MidiBus object. */
get noteOff(): MidiInEvent<messages.NoteOffMessage>;
private _noteOff;
/** The noteOn property can be subscribed to, to receive all Note On messages that pass through the MidiBus object. */
get noteOn(): MidiInEvent<messages.NoteOnMessage>;
private _noteOn;
/** The notePressure property can be subscribed to, to receive all Note Pressure messages that pass through the MidiBus object. */
get notePressure(): MidiInEvent<messages.NotePressureMessage>;
private _notePressure;
/** The controlChange property can be subscribed to, to receive all Control Change messages that pass through the MidiBus object. */
get controlChange(): MidiInEvent<messages.ControlChangeMessage>;
private _controlChange;
/** The programChange property can be subscribed to, to receive all Program Change messages that pass through the MidiBus object. */
get programChange(): MidiInEvent<messages.ProgramChangeMessage>;
private _programChange;
/** The channelPressure property can be subscribed to, to receive all Channel Pressure messages that pass through the MidiBus object. */
get channelPressure(): MidiInEvent<messages.ChannelPressureMessage>;
private _channelPressure;
/** The pitchBend property can be subscribed to, to receive all Pitch Bend messages that pass through the MidiBus object. */
get pitchBend(): MidiInEvent<messages.PitchBendMessage>;
private _pitchBend;
/** The tick property can be subscribed to, to receive all timing clock messages that pass through the MidiBus object. */
get tick(): MidiInEvent<messages.TickMessage>;
private _tick;
/** The songPosition property can be subscribed to, to receive all Song Position messages that pass through the MidiBus object. */
get songPosition(): MidiInEvent<messages.SongPositionMessage>;
private _songPosition;
/** The start property can be subscribed to, to receive all Start messages that pass through the MidiIn object. */
get start(): MidiInEvent<messages.StartMessage>;
private _start;
/** The continue property can be subscribed to, to receive all Continue messages that pass through the MidiIn object. */
get continue(): MidiInEvent<messages.ContinueMessage>;
private _continue;
/** The stop property can be subscribed to, to receive all Stop messages that pass through the MidiIn object. */
get stop(): MidiInEvent<messages.StopMessage>;
private _stop;
private _previousStatus;
receiveData(data: number[]): void;
/**
* The notes collection consists of notes which have been started, but not ended yet.
*
* The MidiBus will cycle through this collection on each update, checking to see if it needs to send out Note Offmessages for any, or update note pressure.
*/
get notes(): Array<Note>;
private _notes;
addNote(note: Note): Note;
stopNotes(filter?: (note: Note) => boolean): void;
/** Sends data from the passed in MIDI message to the connected MIDI port */
sendMessage(message: messages.IMidiMessage): void;
/**
* Sends a custom MIDI message to the connected MIDI port
* @param data An array of the data to be sent
*/
sendRawData(data: number[]): void;
/** Provides a way of identifying MidiBus so it can be easily retrieved later. */
get ref(): string;
set ref(value: string);
private _ref;
/** Returns true if the MidiBus has been instructed to stop everything by the `finish()` method. */
get isFinished(): boolean;
private _isFinished;
/** This event fires when the arpeggiator finishes. */
get finished(): ClockChildFinishedEvent;
private _finished;
/** Calling this tells the MidiBus 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 MidiBus().withRef('bus'));
* ```
*
* @param ref The ref to set on the object.
* @returns The calling object.
*/
withRef(ref: string): IClockChild;
/**
* This method is intended to be called by a clock to provide regular updates. It should be called by consumers of the library.
* @param msDelta How many milliseconds have passed since the last update cycle.
* @returns
*/
update(deltaMs: number): void;
}