@blibliki/engine 0.1.17 → 0.1.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -1
- package/{build → dist/build}/Engine.d.ts +14 -22
- package/dist/build/core/IO/AudioNode.d.ts +35 -0
- package/dist/build/core/IO/Collection.d.ts +13 -0
- package/dist/build/core/IO/ForwardNode.d.ts +38 -0
- package/dist/build/core/IO/MidiNode.d.ts +30 -0
- package/dist/build/core/IO/Node.d.ts +36 -0
- package/dist/build/core/IO/index.d.ts +12 -0
- package/dist/build/core/Module/MonoModule.d.ts +67 -0
- package/dist/build/core/Module/PolyModule.d.ts +57 -0
- package/dist/build/core/Module/index.d.ts +6 -0
- package/{build → dist/build/core}/Note/index.d.ts +3 -0
- package/{build → dist/build/core/midi}/MidiDevice.d.ts +1 -1
- package/dist/build/core/midi/MidiEvent.d.ts +21 -0
- package/dist/build/core/midi/index.d.ts +5 -0
- package/dist/build/index.d.ts +9 -0
- package/{build/Module → dist/build/modules}/BitCrusher.d.ts +5 -1
- package/{build/Module → dist/build/modules}/Delay.d.ts +5 -1
- package/{build/Module → dist/build/modules}/Distortion.d.ts +5 -1
- package/{build/Module → dist/build/modules}/Effect.d.ts +7 -2
- package/{build/Module → dist/build/modules}/Envelope/AmpEnvelope.d.ts +10 -2
- package/{build/Module → dist/build/modules}/Envelope/Base.d.ts +30 -11
- package/{build/Module → dist/build/modules}/Envelope/FreqEnvelope.d.ts +10 -3
- package/{build/Module → dist/build/modules}/Filter.d.ts +13 -13
- package/{build/Module → dist/build/modules}/Master.d.ts +5 -2
- package/{build/Module → dist/build/modules}/MidiSelector.d.ts +9 -5
- package/{build/Module → dist/build/modules}/Oscillator.d.ts +15 -9
- package/{build/Module → dist/build/modules}/Reverb.d.ts +5 -1
- package/{build/Module → dist/build/modules}/Sequencer.d.ts +9 -5
- package/{build/Module → dist/build/modules}/VirtualMidi.d.ts +12 -8
- package/dist/build/modules/VoiceScheduler.d.ts +43 -0
- package/dist/build/modules/Volume.d.ts +26 -0
- package/dist/build/modules/index.d.ts +16 -0
- package/{build → dist/build}/routes.d.ts +6 -5
- package/dist/build/types.d.ts +5 -0
- package/dist/build/utils.d.ts +1 -0
- package/dist/main.cjs.js +33 -0
- package/dist/main.cjs.js.map +1 -0
- package/dist/main.esm.js +33 -0
- package/dist/main.esm.js.map +1 -0
- package/package.json +26 -22
- package/src/Engine.ts +27 -36
- package/src/core/IO/AudioNode.ts +77 -0
- package/src/core/IO/Collection.ts +76 -0
- package/src/core/IO/ForwardNode.ts +192 -0
- package/src/core/IO/MidiNode.ts +67 -0
- package/src/core/IO/Node.ts +117 -0
- package/src/core/IO/index.ts +47 -0
- package/src/core/Module/MonoModule.ts +219 -0
- package/src/core/Module/PolyModule.ts +206 -0
- package/src/core/Module/index.ts +15 -0
- package/src/{Note → core/Note}/index.ts +19 -4
- package/src/{MidiDeviceManager.ts → core/midi/MidiDeviceManager.ts} +20 -15
- package/src/core/midi/MidiEvent.ts +91 -0
- package/src/core/midi/index.ts +5 -0
- package/src/index.ts +8 -12
- package/src/{Module → modules}/BitCrusher.ts +15 -4
- package/src/{Module → modules}/Delay.ts +15 -4
- package/src/{Module → modules}/Distortion.ts +15 -4
- package/src/{Module → modules}/Effect.ts +10 -6
- package/src/modules/Envelope/AmpEnvelope.ts +23 -0
- package/src/{Module → modules}/Envelope/Base.ts +50 -31
- package/src/{Module → modules}/Envelope/FreqEnvelope.ts +18 -23
- package/src/{Module → modules}/Filter.ts +18 -46
- package/src/{Module → modules}/Master.ts +8 -2
- package/src/{Module → modules}/MidiSelector.ts +18 -14
- package/src/{Module → modules}/Oscillator.ts +27 -16
- package/src/{Module → modules}/Reverb.ts +15 -4
- package/src/{Module → modules}/Sequencer.ts +17 -13
- package/src/{Module → modules}/VirtualMidi.ts +16 -12
- package/src/modules/VoiceScheduler.ts +145 -0
- package/src/{Module → modules}/Volume.ts +23 -15
- package/src/{Module → modules}/index.ts +14 -21
- package/src/routes.ts +19 -18
- package/src/types.ts +3 -0
- package/src/utils.ts +18 -0
- package/build/Engine.js +0 -165
- package/build/Engine.js.map +0 -1
- package/build/MidiDevice.js +0 -45
- package/build/MidiDevice.js.map +0 -1
- package/build/MidiDeviceManager.js +0 -59
- package/build/MidiDeviceManager.js.map +0 -1
- package/build/MidiEvent.d.ts +0 -18
- package/build/MidiEvent.js +0 -64
- package/build/MidiEvent.js.map +0 -1
- package/build/Module/Base.d.ts +0 -63
- package/build/Module/Base.js +0 -138
- package/build/Module/Base.js.map +0 -1
- package/build/Module/BitCrusher.js +0 -22
- package/build/Module/BitCrusher.js.map +0 -1
- package/build/Module/DataSequencer.d.ts +0 -26
- package/build/Module/DataSequencer.js +0 -91
- package/build/Module/DataSequencer.js.map +0 -1
- package/build/Module/Delay.js +0 -30
- package/build/Module/Delay.js.map +0 -1
- package/build/Module/Distortion.js +0 -22
- package/build/Module/Distortion.js.map +0 -1
- package/build/Module/Effect.js +0 -22
- package/build/Module/Effect.js.map +0 -1
- package/build/Module/Envelope/AmpEnvelope.js +0 -14
- package/build/Module/Envelope/AmpEnvelope.js.map +0 -1
- package/build/Module/Envelope/Base.js +0 -106
- package/build/Module/Envelope/Base.js.map +0 -1
- package/build/Module/Envelope/FreqEnvelope.js +0 -50
- package/build/Module/Envelope/FreqEnvelope.js.map +0 -1
- package/build/Module/Envelope/index.js +0 -4
- package/build/Module/Envelope/index.js.map +0 -1
- package/build/Module/Filter.js +0 -100
- package/build/Module/Filter.js.map +0 -1
- package/build/Module/IO.d.ts +0 -39
- package/build/Module/IO.js +0 -59
- package/build/Module/IO.js.map +0 -1
- package/build/Module/Master.js +0 -12
- package/build/Module/Master.js.map +0 -1
- package/build/Module/MidiSelector.js +0 -50
- package/build/Module/MidiSelector.js.map +0 -1
- package/build/Module/Oscillator.js +0 -136
- package/build/Module/Oscillator.js.map +0 -1
- package/build/Module/PolyModule.d.ts +0 -49
- package/build/Module/PolyModule.js +0 -175
- package/build/Module/PolyModule.js.map +0 -1
- package/build/Module/Reverb.js +0 -30
- package/build/Module/Reverb.js.map +0 -1
- package/build/Module/Sequencer.js +0 -131
- package/build/Module/Sequencer.js.map +0 -1
- package/build/Module/VirtualMidi.js +0 -53
- package/build/Module/VirtualMidi.js.map +0 -1
- package/build/Module/VoiceScheduler.d.ts +0 -38
- package/build/Module/VoiceScheduler.js +0 -130
- package/build/Module/VoiceScheduler.js.map +0 -1
- package/build/Module/Volume.d.ts +0 -20
- package/build/Module/Volume.js +0 -48
- package/build/Module/Volume.js.map +0 -1
- package/build/Module/index.d.ts +0 -14
- package/build/Module/index.js +0 -66
- package/build/Module/index.js.map +0 -1
- package/build/Note/frequencyTable.js +0 -146
- package/build/Note/frequencyTable.js.map +0 -1
- package/build/Note/index.js +0 -81
- package/build/Note/index.js.map +0 -1
- package/build/index.d.ts +0 -8
- package/build/index.js +0 -5
- package/build/index.js.map +0 -1
- package/build/routes.js +0 -31
- package/build/routes.js.map +0 -1
- package/jest.config.js +0 -19
- package/src/MidiEvent.ts +0 -93
- package/src/Module/Base.ts +0 -223
- package/src/Module/DataSequencer.ts +0 -121
- package/src/Module/Envelope/AmpEnvelope.ts +0 -17
- package/src/Module/IO.ts +0 -85
- package/src/Module/PolyModule.ts +0 -234
- package/src/Module/VoiceScheduler.ts +0 -161
- package/test/Module/Oscillator.test.ts +0 -9
- package/tsconfig.json +0 -22
- /package/{build → dist/build/core}/Note/frequencyTable.d.ts +0 -0
- /package/{build → dist/build/core/midi}/MidiDeviceManager.d.ts +0 -0
- /package/{build/Module → dist/build/modules}/Envelope/index.d.ts +0 -0
- /package/src/{Note → core/Note}/frequencyTable.ts +0 -0
- /package/src/{MidiDevice.ts → core/midi/MidiDevice.ts} +0 -0
- /package/src/{Module → modules}/Envelope/index.ts +0 -0
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { now } from "tone";
|
|
2
|
+
import { ISequence } from "../../modules";
|
|
3
|
+
import Note, { INote } from "../Note";
|
|
4
|
+
|
|
5
|
+
const EventType: { [key: number]: MidiEventType } = {
|
|
6
|
+
0x80: "noteOff",
|
|
7
|
+
0x90: "noteOn",
|
|
8
|
+
0xb0: "cc",
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export type MidiEventType = "noteOn" | "noteOff" | "cc";
|
|
12
|
+
|
|
13
|
+
export default class MidiEvent {
|
|
14
|
+
note: Note;
|
|
15
|
+
voiceNo?: number;
|
|
16
|
+
readonly triggeredAt: number;
|
|
17
|
+
_type: MidiEventType;
|
|
18
|
+
private data: Uint8Array;
|
|
19
|
+
private event: MIDIMessageEvent;
|
|
20
|
+
|
|
21
|
+
static fromSequence(sequence: ISequence, triggeredAt: number): MidiEvent[] {
|
|
22
|
+
return sequence.notes.map((noteName) =>
|
|
23
|
+
this.fromNote(noteName, true, triggeredAt)
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static fromNote(
|
|
28
|
+
noteName: string | Note | INote,
|
|
29
|
+
noteOn: boolean = true,
|
|
30
|
+
triggeredAt?: number
|
|
31
|
+
): MidiEvent {
|
|
32
|
+
const note = noteName instanceof Note ? noteName : new Note(noteName);
|
|
33
|
+
|
|
34
|
+
const event = new MidiEvent(
|
|
35
|
+
new MIDIMessageEvent("", { data: note.midiData(noteOn) }),
|
|
36
|
+
triggeredAt
|
|
37
|
+
);
|
|
38
|
+
event.note = note;
|
|
39
|
+
|
|
40
|
+
return event;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static fromCC(cc: number, value: number, triggeredAt?: number): MidiEvent {
|
|
44
|
+
return new MidiEvent(
|
|
45
|
+
new MIDIMessageEvent("", { data: new Uint8Array([0xb0, cc, value]) }),
|
|
46
|
+
triggeredAt
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
constructor(event: MIDIMessageEvent, triggeredAt?: number) {
|
|
51
|
+
this.event = event;
|
|
52
|
+
this.triggeredAt = triggeredAt || now();
|
|
53
|
+
this.data = event.data;
|
|
54
|
+
this.defineNotes();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get statusByte(): number {
|
|
58
|
+
return this.data[0];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get firstData(): number {
|
|
62
|
+
return this.data[1];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get secondData(): number {
|
|
66
|
+
return this.data[2];
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get type() {
|
|
70
|
+
if (this._type) return this._type;
|
|
71
|
+
|
|
72
|
+
let type = EventType[this.statusByte & 0xf0];
|
|
73
|
+
|
|
74
|
+
if (type === "noteOn" && this.secondData === 0) {
|
|
75
|
+
type = "noteOff";
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (this._type = type);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get isNote() {
|
|
82
|
+
return this.type === "noteOn" || this.type === "noteOff";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
defineNotes() {
|
|
86
|
+
if (!this.isNote) return;
|
|
87
|
+
if (this.note) return;
|
|
88
|
+
|
|
89
|
+
this.note = new Note(this.event);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { default as MidiEvent } from "./MidiEvent";
|
|
2
|
+
export { default as MidiDevice } from "./MidiDevice";
|
|
3
|
+
export { default as MidiDeviceManager } from "./MidiDeviceManager";
|
|
4
|
+
export type { MidiDeviceInterface } from "./MidiDevice";
|
|
5
|
+
export type { MidiEventType } from "./MidiEvent";
|
package/src/index.ts
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
export { default } from "./Engine";
|
|
2
|
-
export {
|
|
3
|
-
export { default as
|
|
4
|
-
export { default as Note } from "./Note";
|
|
2
|
+
export { MidiDevice, MidiDeviceManager } from "./core/midi";
|
|
3
|
+
export { default as Note } from "./core/Note";
|
|
5
4
|
|
|
6
|
-
export type {
|
|
7
|
-
export type {
|
|
8
|
-
export type {
|
|
9
|
-
|
|
10
|
-
AudioModule,
|
|
11
|
-
ISequence,
|
|
12
|
-
IDataSequence,
|
|
13
|
-
} from "./Module";
|
|
5
|
+
export type { MidiDeviceInterface } from "./core/midi";
|
|
6
|
+
export type { INote } from "./core/Note";
|
|
7
|
+
export type { ModuleInterface, AudioModule } from "./core/Module";
|
|
8
|
+
export type { ISequence } from "./modules";
|
|
14
9
|
|
|
15
|
-
export type {
|
|
10
|
+
export type { RouteInterface, RouteProps } from "./routes";
|
|
11
|
+
export type { IIOSerialize as IOProps } from "./core/IO";
|
|
@@ -16,10 +16,21 @@ export default class BitCrusher extends Effect<
|
|
|
16
16
|
> {
|
|
17
17
|
static moduleName = "BitCrusher";
|
|
18
18
|
|
|
19
|
-
constructor(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
constructor(params: {
|
|
20
|
+
id?: string;
|
|
21
|
+
name: string;
|
|
22
|
+
props: Partial<BitCrusherInterface>;
|
|
23
|
+
}) {
|
|
24
|
+
const { id, name, props } = params;
|
|
25
|
+
|
|
26
|
+
super({
|
|
27
|
+
id,
|
|
28
|
+
name,
|
|
29
|
+
internalModule: new InternalBitCrasher(),
|
|
30
|
+
props: {
|
|
31
|
+
...InitialProps,
|
|
32
|
+
...props,
|
|
33
|
+
},
|
|
23
34
|
});
|
|
24
35
|
}
|
|
25
36
|
|
|
@@ -15,10 +15,21 @@ const InitialProps: Partial<DelayInterface> = {
|
|
|
15
15
|
export default class Delay extends Effect<FeedbackDelay, DelayInterface> {
|
|
16
16
|
static moduleName = "Delay";
|
|
17
17
|
|
|
18
|
-
constructor(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
constructor(params: {
|
|
19
|
+
id?: string;
|
|
20
|
+
name: string;
|
|
21
|
+
props: Partial<DelayInterface>;
|
|
22
|
+
}) {
|
|
23
|
+
const { id, name, props } = params;
|
|
24
|
+
|
|
25
|
+
super({
|
|
26
|
+
id,
|
|
27
|
+
name,
|
|
28
|
+
internalModule: new FeedbackDelay(),
|
|
29
|
+
props: {
|
|
30
|
+
...InitialProps,
|
|
31
|
+
...props,
|
|
32
|
+
},
|
|
22
33
|
});
|
|
23
34
|
}
|
|
24
35
|
|
|
@@ -16,10 +16,21 @@ export default class Distortion extends Effect<
|
|
|
16
16
|
> {
|
|
17
17
|
static moduleName = "Distortion";
|
|
18
18
|
|
|
19
|
-
constructor(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
constructor(params: {
|
|
20
|
+
id?: string;
|
|
21
|
+
name: string;
|
|
22
|
+
props: Partial<DistortionInterface>;
|
|
23
|
+
}) {
|
|
24
|
+
const { id, name, props } = params;
|
|
25
|
+
|
|
26
|
+
super({
|
|
27
|
+
id,
|
|
28
|
+
name,
|
|
29
|
+
internalModule: new InternalDistortion(),
|
|
30
|
+
props: {
|
|
31
|
+
...InitialProps,
|
|
32
|
+
...props,
|
|
33
|
+
},
|
|
23
34
|
});
|
|
24
35
|
}
|
|
25
36
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Signal } from "tone";
|
|
2
|
-
import Module, { Connectable } from "
|
|
2
|
+
import Module, { Connectable } from "../core/Module";
|
|
3
3
|
|
|
4
4
|
interface EffectLike extends Connectable {
|
|
5
5
|
wet: Signal<"normalRange">;
|
|
@@ -17,12 +17,16 @@ export default abstract class Effect<
|
|
|
17
17
|
InternalEffect extends EffectLike,
|
|
18
18
|
ModuleInterface extends EffectInterface
|
|
19
19
|
> extends Module<InternalEffect, ModuleInterface> {
|
|
20
|
-
constructor(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
constructor(params: {
|
|
21
|
+
id?: string;
|
|
22
|
+
name: string;
|
|
23
|
+
internalModule: InternalEffect;
|
|
24
|
+
props: Partial<ModuleInterface>;
|
|
25
|
+
}) {
|
|
26
|
+
const { id, name, internalModule, props } = params;
|
|
27
|
+
|
|
25
28
|
super(internalModule, {
|
|
29
|
+
id,
|
|
26
30
|
name,
|
|
27
31
|
props: { ...InitialProps, ...props } as ModuleInterface,
|
|
28
32
|
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { AmplitudeEnvelope } from "tone";
|
|
2
|
+
|
|
3
|
+
import Base, { EnvelopeInterface, PolyBase } from "./Base";
|
|
4
|
+
|
|
5
|
+
class MonoAmpEnvelope extends Base<AmplitudeEnvelope> {
|
|
6
|
+
constructor(params: { id?: string; name: string; props: EnvelopeInterface }) {
|
|
7
|
+
const { id, name, props } = params;
|
|
8
|
+
super({ id, name, internalModule: new AmplitudeEnvelope(), props });
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default class AmpEnvelope extends PolyBase<MonoAmpEnvelope> {
|
|
13
|
+
static moduleName = "AmpEnvelope";
|
|
14
|
+
|
|
15
|
+
constructor(params: {
|
|
16
|
+
id?: string;
|
|
17
|
+
name: string;
|
|
18
|
+
props: Partial<EnvelopeInterface>;
|
|
19
|
+
}) {
|
|
20
|
+
const { id, name, props } = params;
|
|
21
|
+
super({ id, name, child: MonoAmpEnvelope, props });
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { Envelope as Env } from "tone";
|
|
2
2
|
|
|
3
|
-
import Module, {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import Module, {
|
|
4
|
+
PolyModule,
|
|
5
|
+
Connectable,
|
|
6
|
+
Triggerable,
|
|
7
|
+
} from "../../core/Module";
|
|
8
|
+
import Note from "../../core/Note";
|
|
7
9
|
|
|
8
10
|
export const enum EnvelopeStages {
|
|
9
11
|
Attack = "attack",
|
|
@@ -17,12 +19,11 @@ const MIN_TIME = 0.01;
|
|
|
17
19
|
const SUSTAIN_MAX_VALUE = 1;
|
|
18
20
|
const SUSTAIN_MIN_VALUE = 0;
|
|
19
21
|
|
|
20
|
-
export interface EnvelopeInterface
|
|
22
|
+
export interface EnvelopeInterface {
|
|
21
23
|
attack: number;
|
|
22
24
|
decay: number;
|
|
23
25
|
sustain: number;
|
|
24
26
|
release: number;
|
|
25
|
-
voiceNo?: number;
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const InitialProps: EnvelopeInterface = {
|
|
@@ -39,15 +40,22 @@ export default abstract class EnvelopeModule<EnvelopeLike extends Env>
|
|
|
39
40
|
activeNote?: string;
|
|
40
41
|
triggeredAt: number;
|
|
41
42
|
|
|
42
|
-
constructor(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
constructor(params: {
|
|
44
|
+
id?: string;
|
|
45
|
+
name: string;
|
|
46
|
+
internalModule: EnvelopeLike;
|
|
47
|
+
props: EnvelopeInterface;
|
|
48
|
+
}) {
|
|
49
|
+
const { id, name, props, internalModule } = params;
|
|
50
|
+
|
|
47
51
|
super(internalModule, {
|
|
52
|
+
id,
|
|
48
53
|
name,
|
|
49
54
|
props: { ...InitialProps, ...props },
|
|
50
55
|
});
|
|
56
|
+
|
|
57
|
+
this.registerBasicInputs();
|
|
58
|
+
this.registerBasicOutputs();
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
get attack() {
|
|
@@ -110,14 +118,21 @@ export default abstract class EnvelopeModule<EnvelopeLike extends Env>
|
|
|
110
118
|
}
|
|
111
119
|
|
|
112
120
|
export abstract class PolyBase<
|
|
113
|
-
EnvelopeModule extends Module<Connectable,
|
|
121
|
+
EnvelopeModule extends Module<Connectable, EnvelopeInterface>
|
|
114
122
|
> extends PolyModule<EnvelopeModule, EnvelopeInterface> {
|
|
115
|
-
constructor(
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
constructor(params: {
|
|
124
|
+
id?: string;
|
|
125
|
+
name: string;
|
|
126
|
+
child: new (params: {
|
|
127
|
+
id?: string;
|
|
128
|
+
name: string;
|
|
129
|
+
props: EnvelopeInterface;
|
|
130
|
+
}) => EnvelopeModule;
|
|
131
|
+
props: Partial<EnvelopeInterface>;
|
|
132
|
+
}) {
|
|
133
|
+
const { id, name, child, props } = params;
|
|
120
134
|
super({
|
|
135
|
+
id,
|
|
121
136
|
name,
|
|
122
137
|
child,
|
|
123
138
|
props: { ...InitialProps, ...props },
|
|
@@ -125,30 +140,34 @@ export abstract class PolyBase<
|
|
|
125
140
|
|
|
126
141
|
this.registerBasicInputs();
|
|
127
142
|
this.registerBasicOutputs();
|
|
128
|
-
this.registerInputs();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
private registerInputs() {
|
|
132
|
-
this.registerInput({
|
|
133
|
-
name: "midi in",
|
|
134
|
-
pluggable: this.midiTriggered,
|
|
135
|
-
});
|
|
136
143
|
}
|
|
137
144
|
}
|
|
138
145
|
|
|
139
146
|
class MonoEnvelope extends EnvelopeModule<Env> {
|
|
140
|
-
constructor(name: string
|
|
141
|
-
|
|
147
|
+
constructor(params: { id?: string; name: string; props: EnvelopeInterface }) {
|
|
148
|
+
const { id, name, props } = params;
|
|
149
|
+
super({ id, name, internalModule: new Env(), props });
|
|
142
150
|
}
|
|
143
151
|
}
|
|
144
152
|
|
|
145
153
|
export class Envelope extends PolyBase<MonoEnvelope> {
|
|
146
154
|
static moduleName = "Envelope";
|
|
147
155
|
|
|
148
|
-
constructor(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
156
|
+
constructor(params: {
|
|
157
|
+
id?: string;
|
|
158
|
+
name: string;
|
|
159
|
+
props: Partial<EnvelopeInterface>;
|
|
160
|
+
}) {
|
|
161
|
+
const { id, name, props } = params;
|
|
162
|
+
|
|
163
|
+
super({
|
|
164
|
+
id,
|
|
165
|
+
name,
|
|
166
|
+
child: MonoEnvelope,
|
|
167
|
+
props: {
|
|
168
|
+
...InitialProps,
|
|
169
|
+
...props,
|
|
170
|
+
},
|
|
152
171
|
});
|
|
153
172
|
}
|
|
154
173
|
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { FrequencyEnvelope } from "tone";
|
|
2
2
|
|
|
3
3
|
import Filter from "../Filter";
|
|
4
|
-
import { Output } from "../IO";
|
|
5
|
-
|
|
6
4
|
import Base, { EnvelopeInterface, PolyBase } from "./Base";
|
|
7
5
|
|
|
8
6
|
interface FreqEnvelopeInterface extends Partial<EnvelopeInterface> {
|
|
@@ -18,10 +16,17 @@ export class MonoFreqEnvelope extends Base<FrequencyEnvelope> {
|
|
|
18
16
|
private _amount: number;
|
|
19
17
|
filter: Filter;
|
|
20
18
|
|
|
21
|
-
constructor(name: string
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
constructor(params: { id?: string; name: string; props: EnvelopeInterface }) {
|
|
20
|
+
const { id, name, props } = params;
|
|
21
|
+
|
|
22
|
+
super({
|
|
23
|
+
id,
|
|
24
|
+
name,
|
|
25
|
+
internalModule: new FrequencyEnvelope(),
|
|
26
|
+
props: {
|
|
27
|
+
...InitialProps,
|
|
28
|
+
...props,
|
|
29
|
+
},
|
|
25
30
|
});
|
|
26
31
|
}
|
|
27
32
|
|
|
@@ -48,22 +53,12 @@ export class MonoFreqEnvelope extends Base<FrequencyEnvelope> {
|
|
|
48
53
|
export default class FreqEnvelope extends PolyBase<MonoFreqEnvelope> {
|
|
49
54
|
static moduleName = "FreqEnvelope";
|
|
50
55
|
|
|
51
|
-
constructor(
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
this.registerOutput({
|
|
59
|
-
name: "frequency",
|
|
60
|
-
pluggable: this,
|
|
61
|
-
onPlug: (output: Output) => {
|
|
62
|
-
this.connect(output.audioModule, output.pluggable);
|
|
63
|
-
},
|
|
64
|
-
onUnPlug: (output: Output) => {
|
|
65
|
-
this.disconnect(output.audioModule, output.pluggable);
|
|
66
|
-
},
|
|
67
|
-
});
|
|
56
|
+
constructor(params: {
|
|
57
|
+
id?: string;
|
|
58
|
+
name: string;
|
|
59
|
+
props: Partial<EnvelopeInterface>;
|
|
60
|
+
}) {
|
|
61
|
+
const { id, name, props } = params;
|
|
62
|
+
super({ id, name, child: MonoFreqEnvelope, props });
|
|
68
63
|
}
|
|
69
64
|
}
|
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { Filter as InternalFilter, FilterRollOff } from "tone";
|
|
2
|
+
import Module, { PolyModule } from "../core/Module";
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
import Module, { Voicable } from "./Base";
|
|
5
|
-
import PolyModule from "./PolyModule";
|
|
6
|
-
|
|
7
|
-
interface FilterInterface extends Voicable {
|
|
4
|
+
interface FilterInterface {
|
|
8
5
|
cutoff: number;
|
|
9
6
|
filterType: BiquadFilterType;
|
|
10
7
|
resonance: number;
|
|
11
8
|
slope: FilterRollOff;
|
|
12
9
|
envelopeAmount: number;
|
|
13
|
-
voiceNo?: number;
|
|
14
10
|
}
|
|
15
11
|
|
|
16
|
-
|
|
12
|
+
type FilterProps = Partial<FilterInterface>;
|
|
17
13
|
|
|
18
14
|
const InitialProps: FilterInterface = {
|
|
19
15
|
cutoff: 20000,
|
|
@@ -24,13 +20,17 @@ const InitialProps: FilterInterface = {
|
|
|
24
20
|
};
|
|
25
21
|
|
|
26
22
|
class MonoFilter extends Module<InternalFilter, FilterInterface> {
|
|
27
|
-
|
|
23
|
+
constructor(params: { id?: string; name: string; props: FilterProps }) {
|
|
24
|
+
const { id, name, props } = params;
|
|
28
25
|
|
|
29
|
-
constructor(name: string, props: FilterProps) {
|
|
30
26
|
super(new InternalFilter({ type: "lowpass" }), {
|
|
27
|
+
id,
|
|
31
28
|
name,
|
|
32
29
|
props: { ...InitialProps, ...props },
|
|
33
30
|
});
|
|
31
|
+
|
|
32
|
+
this.registerBasicInputs();
|
|
33
|
+
this.registerBasicOutputs();
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
get cutoff() {
|
|
@@ -39,12 +39,7 @@ class MonoFilter extends Module<InternalFilter, FilterInterface> {
|
|
|
39
39
|
|
|
40
40
|
set cutoff(value: number) {
|
|
41
41
|
this._props = { ...this.props, cutoff: value };
|
|
42
|
-
|
|
43
|
-
if (this._envelope) {
|
|
44
|
-
this._envelope.frequency = value;
|
|
45
|
-
} else {
|
|
46
|
-
this.internalModule.frequency.value = value;
|
|
47
|
-
}
|
|
42
|
+
this.internalModule.frequency.value = value;
|
|
48
43
|
}
|
|
49
44
|
|
|
50
45
|
get filterType() {
|
|
@@ -85,24 +80,21 @@ class MonoFilter extends Module<InternalFilter, FilterInterface> {
|
|
|
85
80
|
|
|
86
81
|
set envelopeAmount(value: number) {
|
|
87
82
|
this._props = { ...this.props, envelopeAmount: value };
|
|
88
|
-
|
|
89
|
-
if (!this._envelope) return;
|
|
90
|
-
|
|
91
|
-
this._envelope.amount = value;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
conntectedEnvelope(envelope: MonoFreqEnvelope) {
|
|
95
|
-
this._envelope = envelope;
|
|
96
|
-
this._envelope.frequency = this.cutoff;
|
|
97
|
-
this._envelope.amount = this.envelopeAmount;
|
|
98
83
|
}
|
|
99
84
|
}
|
|
100
85
|
|
|
101
86
|
export default class Filter extends PolyModule<MonoFilter, FilterInterface> {
|
|
102
87
|
static moduleName = "Filter";
|
|
103
88
|
|
|
104
|
-
constructor(
|
|
89
|
+
constructor(params: {
|
|
90
|
+
id?: string;
|
|
91
|
+
name: string;
|
|
92
|
+
props: Partial<FilterInterface>;
|
|
93
|
+
}) {
|
|
94
|
+
const { id, name, props } = params;
|
|
95
|
+
|
|
105
96
|
super({
|
|
97
|
+
id,
|
|
106
98
|
name,
|
|
107
99
|
child: MonoFilter,
|
|
108
100
|
props: { ...InitialProps, ...props },
|
|
@@ -110,25 +102,5 @@ export default class Filter extends PolyModule<MonoFilter, FilterInterface> {
|
|
|
110
102
|
|
|
111
103
|
this.registerBasicInputs();
|
|
112
104
|
this.registerBasicOutputs();
|
|
113
|
-
this.registerInputs();
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
private registerInputs() {
|
|
117
|
-
this.registerInput({
|
|
118
|
-
name: "frequency",
|
|
119
|
-
pluggable: "frequency",
|
|
120
|
-
onPlug: (output) => {
|
|
121
|
-
this.conntectedEnvelope(output.audioModule as FreqEnvelope);
|
|
122
|
-
},
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
conntectedEnvelope(freqEnvelope: FreqEnvelope) {
|
|
127
|
-
freqEnvelope.audioModules.forEach((envelope) => {
|
|
128
|
-
if (envelope.voiceNo === undefined) return;
|
|
129
|
-
|
|
130
|
-
const filter = this.findVoice(envelope.voiceNo);
|
|
131
|
-
filter?.conntectedEnvelope(envelope);
|
|
132
|
-
});
|
|
133
105
|
}
|
|
134
106
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Destination, getDestination } from "tone";
|
|
2
|
-
import Module from "
|
|
2
|
+
import Module from "../core/Module";
|
|
3
3
|
|
|
4
4
|
export interface MasterInterface {}
|
|
5
5
|
|
|
@@ -9,11 +9,17 @@ export default class Master extends Module<
|
|
|
9
9
|
> {
|
|
10
10
|
static moduleName = "Master";
|
|
11
11
|
|
|
12
|
-
constructor() {
|
|
12
|
+
constructor({ id }: { id?: string }) {
|
|
13
13
|
super(getDestination(), {
|
|
14
|
+
id,
|
|
14
15
|
name: "Master",
|
|
15
16
|
});
|
|
16
17
|
|
|
17
18
|
this.registerBasicInputs();
|
|
18
19
|
}
|
|
20
|
+
|
|
21
|
+
dispose(): void {
|
|
22
|
+
this.inputs.unPlugAll();
|
|
23
|
+
this.outputs.unPlugAll();
|
|
24
|
+
}
|
|
19
25
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Engine from "../Engine";
|
|
2
|
-
import MidiEvent from "../
|
|
3
|
-
import Module, { DummnyInternalModule } from "
|
|
4
|
-
import {
|
|
2
|
+
import { MidiEvent } from "../core/midi";
|
|
3
|
+
import Module, { DummnyInternalModule } from "../core/Module";
|
|
4
|
+
import { MidiOutput } from "../core/IO";
|
|
5
5
|
|
|
6
6
|
export interface MidiSelectorInterface {
|
|
7
7
|
selectedId: string | null;
|
|
@@ -16,10 +16,16 @@ export default class MidiSelector extends Module<
|
|
|
16
16
|
MidiSelectorInterface
|
|
17
17
|
> {
|
|
18
18
|
static moduleName = "MidiSelector";
|
|
19
|
-
midiOutput:
|
|
20
|
-
|
|
21
|
-
constructor(
|
|
19
|
+
midiOutput: MidiOutput;
|
|
20
|
+
|
|
21
|
+
constructor(params: {
|
|
22
|
+
id?: string;
|
|
23
|
+
name: string;
|
|
24
|
+
props: Partial<MidiSelectorInterface>;
|
|
25
|
+
}) {
|
|
26
|
+
const { id, name, props } = params;
|
|
22
27
|
super(new DummnyInternalModule(), {
|
|
28
|
+
id,
|
|
23
29
|
name,
|
|
24
30
|
props: { ...InitialProps, ...props },
|
|
25
31
|
});
|
|
@@ -46,15 +52,9 @@ export default class MidiSelector extends Module<
|
|
|
46
52
|
}
|
|
47
53
|
|
|
48
54
|
private registerOutputs() {
|
|
49
|
-
this.midiOutput = this.
|
|
55
|
+
this.midiOutput = this.registerMidiOutput({ name: "midi out" });
|
|
50
56
|
}
|
|
51
57
|
|
|
52
|
-
private onMidiEvent = (midiEvent: MidiEvent) => {
|
|
53
|
-
this.midiOutput.connections.forEach((input) => {
|
|
54
|
-
input.pluggable(midiEvent);
|
|
55
|
-
});
|
|
56
|
-
};
|
|
57
|
-
|
|
58
58
|
private addEventListener(midiId: string | null) {
|
|
59
59
|
if (!this.onMidiEvent || !midiId) return; // Ugly hack because of weird super bug
|
|
60
60
|
|
|
@@ -62,10 +62,14 @@ export default class MidiSelector extends Module<
|
|
|
62
62
|
midiDevice?.addEventListener(this.onMidiEvent);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
+
private _onMidiEvent = (midiEvent: MidiEvent) => {
|
|
66
|
+
this.midiOutput.onMidiEvent(midiEvent);
|
|
67
|
+
};
|
|
68
|
+
|
|
65
69
|
private removeEventListener() {
|
|
66
70
|
if (!this.selectedId) return;
|
|
67
71
|
|
|
68
72
|
const midiDevice = Engine.midiDeviceManager.find(this.selectedId);
|
|
69
|
-
midiDevice?.removeEventListener(this.
|
|
73
|
+
midiDevice?.removeEventListener(this._onMidiEvent);
|
|
70
74
|
}
|
|
71
75
|
}
|