bndr-js - v0.18.0 / MidiEmitter

Class: MidiEmitter

Hierarchy

Constructors

constructor

new MidiEmitter()

Overrides

Emitter.constructor

Defined in

src/generator/midi.ts:10open in new window

Filters

note

note(channel, note): Emitter<number>

Parameters

NameType
channelnumber
notenumber

Returns

Emitter<number>

Defined in

src/generator/midi.ts:41open in new window

Common Filters

change

change(equalFn?): Emitter<MIDIData>

Emits only when the value is changed

Parameters

NameTypeDefault valueDescription
equalFn(a: MIDIData, b: MIDIData) => booleanisEqualA comparator function. The event will be emitted when the function returns falsy value.

Returns

Emitter<MIDIData>

Inherited from

Emitter.change

Defined in

src/Emitter.ts:305open in new window


constant

constant<U>(value): Emitter<U>

Creates an emitter that emits a constant value every time the current emitter is emitted.

Type parameters

Name
U

Parameters

NameType
valueU

Returns

Emitter<U>

See

https://lodash.com/docs/4.17.15#throttleopen in new window

Inherited from

Emitter.constant

Defined in

src/Emitter.ts:393open in new window


debounce

debounce(wait, options): Emitter<unknown>

Creates debounced version of the current emitter.

Parameters

NameTypeDescription
waitnumberMilliseconds to wait.
optionsDebounceSettings

Returns

Emitter<unknown>

A new emitter

Inherited from

Emitter.debounce

Defined in

src/Emitter.ts:435open in new window


delay

delay(wait): Emitter<unknown>

Creates delayed version of the current emitter.

Parameters

NameTypeDescription
waitnumberMilliseconds to wait.

Returns

Emitter<unknown>

A new emitter

Inherited from

Emitter.delay

Defined in

src/Emitter.ts:460open in new window


delta

delta<U>(fn): Emitter<U>

Creates an emitter that emits the ‘difference’ between the current value and the previous value.

Type parameters

Name
U

Parameters

NameTypeDescription
fn(prev: MIDIData, curt: MIDIData) => UA function to calculate the difference

Returns

Emitter<U>

A new emitter

Inherited from

Emitter.delta

Defined in

src/Emitter.ts:679open in new window


down

down(): Emitter<true>

Creates an emitter that emits at the moment the current value changes from falsy to truthy.

Returns

Emitter<true>

Inherited from

Emitter.down

Defined in

src/Emitter.ts:268open in new window


filter

filter(fn): Emitter<MIDIData>

Filters events with the given predicate function

Parameters

NameTypeDescription
fn(value: MIDIData) => anyReturn truthy value to pass events

Returns

Emitter<MIDIData>

A new emitter

Inherited from

Emitter.filter

Defined in

src/Emitter.ts:237open in new window


filterMap

filterMap<U>(fn, initialValue?): Emitter<U>

Maps the current value to another type of value, and emits the mapped value only when the mapped value is not undefined.

Type parameters

Name
U

Parameters

NameTypeDescription
fn(value: MIDIData) => UA function to map the current value. Return undefined to skip emitting.
initialValue?U-

Returns

Emitter<U>

Inherited from

Emitter.filterMap

Defined in

src/Emitter.ts:252open in new window


fold

fold<U>(fn, initialState): Emitter<U>

Initializes with an initialState value. On each emitted event, calculates a new state based on the previous state and the current value, and emits this new state.

Type parameters

Name
U

Parameters

NameTypeDescription
fn(prev: U, value: MIDIData) => UA function to calculate a new state
initialStateUAn initial state value

Returns

Emitter<U>

A new emitter

Inherited from

Emitter.fold

Defined in

src/Emitter.ts:633open in new window


interval

interval(ms?, immediate?): Emitter<any>

Creates an emitter that keeps to emit the last value of the current emitter at the specified interval.

Parameters

NameTypeDefault valueDescription
msnumber0The interval in milliseconds. Set 0 to use requestAnimationFrame.
immediatebooleanfalseIf set to false, the new emitter waits to emit until the current emitter emits any value.

Returns

Emitter<any>

A new emitter.

Inherited from

Emitter.interval

Defined in

src/Emitter.ts:702open in new window


lerp

lerp(lerp, rate, threshold?): Emitter<MIDIData>

Smoothen the change rate of the input value.

Parameters

NameTypeDefault valueDescription
lerpLerp<MIDIData>undefinedA function to interpolate the current value and the target value.
ratenumberundefinedThe ratio of linear interpolation from the current value to the target value with each update.
thresholdnumber1e-4The threshold to determine whether the current value is close enough to the target value. If the difference between the current value and the target value is less than this value, the target value will be used as the current value and the interpolation will be stopped.

Returns

Emitter<MIDIData>

A new emitter

Inherited from

Emitter.lerp

Defined in

src/Emitter.ts:506open in new window


longPress

longPress(wait): Object

Parameters

NameType
waitnumber

Returns

Object

NameType
pressedEmitter<unknown>

Inherited from

Emitter.longPress

Defined in

src/Emitter.ts:476open in new window


map

map<U>(fn, initialValue?): Emitter<U>

Transforms the payload of event with the given function.

Type parameters

Name
U

Parameters

NameTypeDescription
fn(value: MIDIData) => UA function to transform the payload
initialValue?U-

Returns

Emitter<U>

A new emitter

Inherited from

Emitter.map

Defined in

src/Emitter.ts:224open in new window


not

not(): Emitter<boolean>

Creates an emitter whose payload is negated.

Returns

Emitter<boolean>

Inherited from

Emitter.not

Defined in

src/Emitter.ts:294open in new window


resetBy

resetBy(emitter, emitOnReset?): Emitter<MIDIData>

Reset the state of current emitter emitter when the given event is fired.

Parameters

NameTypeDefault valueDescription
emitterEmitter<any>undefinedThe emitter that triggers the current emitter to be reset.
emitOnResetbooleantrueIf set to true, the current emitter will be triggered when it is reset.

Returns

Emitter<MIDIData>

The current emitter emitter

Inherited from

Emitter.resetBy

Defined in

src/Emitter.ts:610open in new window


stash

stash(...triggers): Emitter<any>

Creates an emitter that emits the current value when one of the given events is fired.

Parameters

NameTypeDescription
...triggersEmitter<any>[]Emitters to trigger the current emitter to emit.

Returns

Emitter<any>

A new emitter

Inherited from

Emitter.stash

Defined in

src/Emitter.ts:659open in new window


throttle

throttle(wait, options?): Emitter<MIDIData>

Creates throttled version of the current emitter.

Parameters

NameTypeDescription
waitnumberMilliseconds to wait.
options?ThrottleSettings

Returns

Emitter<MIDIData>

See

https://lodash.com/docs/4.17.15#debouncedopen in new window

Inherited from

Emitter.throttle

Defined in

src/Emitter.ts:410open in new window


trail

trail(count?, emitAtCount?): Emitter<MIDIData[]>

Emits an array caching a specified number of values that were emitted in the past.

Parameters

NameTypeDefault valueDescription
countnumber2The number of cache frames. Set 0 to store caches infinitely.
emitAtCountbooleantrueWhen set to true, events will not be emitted until the count of cache reaches to count.

Returns

Emitter<MIDIData[]>

Inherited from

Emitter.trail

Defined in

src/Emitter.ts:739open in new window


up

up(): Emitter<true>

Creates an emitter that emits at the moment the current value changes from falsy to truthy.

Returns

Emitter<true>

Inherited from

Emitter.up

Defined in

src/Emitter.ts:281open in new window


while

while(emitter, resetOnDown?): Emitter<MIDIData>

Emits while the given event is truthy. The event will be also emitted when the given emitter is changed from falsy to truthy when the resetOnDown flag is set to true.

Parameters

NameTypeDefault valueDescription
emitterEmitter<boolean>undefinedAn emitter to filter the events
resetOnDownbooleantrueIf set to true, the returned emitter will be reset when the given emitter is down.

Returns

Emitter<MIDIData>

Inherited from

Emitter.while

Defined in

src/Emitter.ts:326open in new window

Methods

createDerived

createDerived<U>(options): Emitter<U>

Type parameters

Name
U

Parameters

NameType
optionsEmitterOptions<U> & { propagate: (e: MIDIData, emit: (v: U) => void) => void }

Returns

Emitter<U>

Inherited from

Emitter.createDerived

Defined in

src/Emitter.ts:80open in new window


registerDerived

registerDerived(emitter, listener): void

Parameters

NameType
emitterEmitter<any>
listenerListener<MIDIData>

Returns

void

Inherited from

Emitter.registerDerived

Defined in

src/Emitter.ts:72open in new window


tween

tween(lerp, durationMs): Emitter<MIDIData>

Parameters

NameType
lerpLerp<MIDIData>
durationMsnumber

Returns

Emitter<MIDIData>

Inherited from

Emitter.tween

Defined in

src/Emitter.ts:560open in new window

Properties

_disposed

Protected _disposed: boolean = false

Inherited from

Emitter._disposed

Defined in

src/Emitter.ts:61open in new window


derivedEmitters

Protected Readonly derivedEmitters: Map<Emitter<any>, Listener<MIDIData>>

Stores all deviced events and their listeners. They will not be unregistered by removeAllListeners.

Inherited from

Emitter.derivedEmitters

Defined in

src/Emitter.ts:59open in new window


icon

Optional icon: IconSequence

Inherited from

Emitter.icon

Defined in

src/Emitter.ts:49open in new window


stateful

get stateful(): boolean

Returns true if the emitter has a state and can be reset.

Returns

boolean

Inherited from

Emitter.stateful

Defined in

src/Emitter.ts:137open in new window


value

get value(): T

The latest value emitted from the emitter. If the emitter has never fired before, it just returns undefined.

Returns

T

Inherited from

Emitter.value

Defined in

src/Emitter.ts:162open in new window

Accessors

disposed

get disposed(): boolean

Returns

boolean

Inherited from

Emitter.disposed

Defined in

src/Emitter.ts:63open in new window

Commom Filters

split

split(emitter, count, resetOnSwitch?): Emitter<MIDIData>[]

Splits the current emitter into multiple emitters. Each emitter emits only when the given emitter is changed to the corresponding index.

Parameters

NameTypeDefault valueDescription
emitterEmitter<any>undefinedAn emitter to filter the current event
countnumberundefinedThe number of emitters to be created.
resetOnSwitchbooleantrueIf set to true, the corresponding emitter will be reset when the index of current emitter is switched.

Returns

Emitter<MIDIData>[]

Inherited from

Emitter.split

Defined in

src/Emitter.ts:355open in new window

Event Handlers

dispose

dispose(): void

Disposes the emitter immediately and prevent to emit any value in the future

Returns

void

Inherited from

Emitter.dispose

Defined in

src/Emitter.ts:119open in new window


emit

emit(value): void

Manually emits the event.

Parameters

NameType
valueMIDIData

Returns

void

Inherited from

Emitter.emit

Defined in

src/Emitter.ts:190open in new window


log

log(message?): MidiEmitter

Parameters

NameTypeDefault value
messagestring'Bndr'

Returns

MidiEmitter

Inherited from

Emitter.log

Defined in

src/Emitter.ts:757open in new window


off

off(listener): void

Removes the listener function from the event.

Parameters

NameType
listenerListener<MIDIData>

Returns

void

Inherited from

Emitter.off

Defined in

src/Emitter.ts:181open in new window


on

on(listener): MidiEmitter

Adds the listener function for the event.

Parameters

NameTypeDescription
listenerListener<MIDIData>The callback function

Returns

MidiEmitter

Inherited from

Emitter.on

Defined in

src/Emitter.ts:171open in new window


once

once(listener): void

Adds a one-time listener function for the event

Parameters

NameType
listenerListener<MIDIData>

Returns

void

Inherited from

Emitter.once

Defined in

src/Emitter.ts:202open in new window


removeAllListeners

removeAllListeners(): void

Removes all listeners.

Returns

void

Inherited from

Emitter.removeAllListeners

Defined in

src/Emitter.ts:214open in new window


reset

reset(): void

Resets the state of the emitter.

Returns

void

Inherited from

Emitter.reset

Defined in

src/Emitter.ts:145open in new window