1 | import * as Classes from "./classes.js";
|
2 | import { FrequencyClass } from "./core/type/Frequency.js";
|
3 | import { MidiClass } from "./core/type/Midi.js";
|
4 | import { TicksClass } from "./core/type/Ticks.js";
|
5 | import { TimeClass } from "./core/type/Time.js";
|
6 | import { TransportTimeClass } from "./core/type/TransportTime.js";
|
7 | import { isDefined, isFunction } from "./core/util/TypeCheck.js";
|
8 | import { omitFromObject } from "./core/util/Defaults.js";
|
9 |
|
10 |
|
11 |
|
12 | function bindTypeClass(context, type) {
|
13 | return (...args) => new type(context, ...args);
|
14 | }
|
15 |
|
16 |
|
17 |
|
18 |
|
19 | export function fromContext(context) {
|
20 | const classesWithContext = {};
|
21 | Object.keys(omitFromObject(Classes, ["Transport", "Destination", "Draw"])).map((key) => {
|
22 | const cls = Classes[key];
|
23 | if (isDefined(cls) && isFunction(cls.getDefaults)) {
|
24 | classesWithContext[key] = class ToneFromContextNode extends cls {
|
25 | get defaultContext() {
|
26 | return context;
|
27 | }
|
28 | };
|
29 | }
|
30 | else {
|
31 |
|
32 | classesWithContext[key] = Classes[key];
|
33 | }
|
34 | });
|
35 | const toneFromContext = Object.assign(Object.assign({}, classesWithContext), { now: context.now.bind(context), immediate: context.immediate.bind(context), Transport: context.transport, Destination: context.destination, Listener: context.listener, Draw: context.draw, context,
|
36 |
|
37 | Midi: bindTypeClass(context, MidiClass), Time: bindTypeClass(context, TimeClass), Frequency: bindTypeClass(context, FrequencyClass), Ticks: bindTypeClass(context, TicksClass), TransportTime: bindTypeClass(context, TransportTimeClass) });
|
38 |
|
39 | return toneFromContext;
|
40 | }
|
41 |
|
\ | No newline at end of file |