Skip to content

Commit

Permalink
Introduce ElemNode type in stdlib
Browse files Browse the repository at this point in the history
  • Loading branch information
nick-thompson committed Sep 22, 2023
1 parent 105096c commit 0ada610
Show file tree
Hide file tree
Showing 9 changed files with 215 additions and 212 deletions.
4 changes: 2 additions & 2 deletions js/packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import * as fi from './lib/filters';
import * as os from './lib/oscillators';
import * as si from './lib/signals';

import type {t as NodeRepr_t} from './src/NodeRepr.gen';
export type {NodeRepr_t};
import type {ElemNode, NodeRepr_t} from './nodeUtils';
export type {ElemNode, NodeRepr_t};

const stdlib = {
...co,
Expand Down
144 changes: 72 additions & 72 deletions js/packages/core/lib/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
resolve,
} from '../nodeUtils';

import type {t as NodeRepr_t} from '../src/NodeRepr.gen';
import type {ElemNode, NodeRepr_t} from '../nodeUtils';


// Generic
Expand All @@ -31,8 +31,8 @@ export function time(): NodeRepr_t {
}

// Counter node
export function counter(gate: NodeRepr_t | number): NodeRepr_t;
export function counter(props: OptionalKeyProps, gate: NodeRepr_t | number): NodeRepr_t;
export function counter(gate: ElemNode): NodeRepr_t;
export function counter(props: OptionalKeyProps, gate: ElemNode): NodeRepr_t;
export function counter(a, b?) {
if (typeof a === "number" || isNode(a)) {
return createNode("counter", {}, [resolve(a)]);
Expand All @@ -42,8 +42,8 @@ export function counter(a, b?) {
}

// Accum node
export function accum(xn: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t;
export function accum(props: OptionalKeyProps, xn: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t;
export function accum(xn: ElemNode, reset: ElemNode): NodeRepr_t;
export function accum(props: OptionalKeyProps, xn: ElemNode, reset: ElemNode): NodeRepr_t;
export function accum(a, b, c?) {
if (typeof a === "number" || isNode(a)) {
return createNode("accum", {}, [resolve(a), resolve(b)]);
Expand All @@ -53,8 +53,8 @@ export function accum(a, b, c?) {
}

// Phasor node
export function phasor(rate: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t;
export function phasor(props: OptionalKeyProps, rate: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t;
export function phasor(rate: ElemNode, reset: ElemNode): NodeRepr_t;
export function phasor(props: OptionalKeyProps, rate: ElemNode, reset: ElemNode): NodeRepr_t;
export function phasor(a, b, c?) {
if (typeof a === "number" || isNode(a)) {
return createNode("phasor", {}, [resolve(a), resolve(b)]);
Expand All @@ -64,8 +64,8 @@ export function phasor(a, b, c?) {
}

// Latch node
export function latch(t: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function latch(props: OptionalKeyProps, t: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function latch(t: ElemNode, x: ElemNode): NodeRepr_t;
export function latch(props: OptionalKeyProps, t: ElemNode, x: ElemNode): NodeRepr_t;
export function latch(a, b, c?) {
if (typeof a === "number" || isNode(a)) {
return createNode("latch", {}, [resolve(a), resolve(b)]);
Expand All @@ -80,8 +80,8 @@ type MaxHoldNodeProps = {
hold?: number,
};

export function maxhold(x: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t;
export function maxhold(props: MaxHoldNodeProps, x: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t;
export function maxhold(x: ElemNode, reset: ElemNode): NodeRepr_t;
export function maxhold(props: MaxHoldNodeProps, x: ElemNode, reset: ElemNode): NodeRepr_t;
export function maxhold(a, b, c?) {
if (typeof a === "number" || isNode(a)) {
return createNode("maxhold", {}, [resolve(a), resolve(b)]);
Expand All @@ -96,8 +96,8 @@ type OnceNodeProps = {
arm?: boolean,
};

export function once(x: NodeRepr_t | number): NodeRepr_t;
export function once(props: OnceNodeProps, x: NodeRepr_t | number): NodeRepr_t;
export function once(x: ElemNode): NodeRepr_t;
export function once(props: OnceNodeProps, x: ElemNode): NodeRepr_t;
export function once(a, b?) {
if (typeof a === "number" || isNode(a)) {
return createNode("once", {}, [resolve(a)]);
Expand Down Expand Up @@ -147,7 +147,7 @@ type SampleNodeProps = {
stopOffset?: number,
};

export function sample(props: SampleNodeProps, trigger: NodeRepr_t | number, rate: NodeRepr_t | number): NodeRepr_t {
export function sample(props: SampleNodeProps, trigger: ElemNode, rate: ElemNode): NodeRepr_t {
return createNode("sample", props, [resolve(trigger), resolve(rate)]);
}

Expand All @@ -157,7 +157,7 @@ type TableNodeProps = {
path?: string,
};

export function table(props: TableNodeProps, t: NodeRepr_t | number): NodeRepr_t {
export function table(props: TableNodeProps, t: ElemNode): NodeRepr_t {
return createNode("table", props, [resolve(t)]);
}

Expand All @@ -167,7 +167,7 @@ type ConvolveNodeProps = {
path?: string,
};

export function convolve(props: ConvolveNodeProps, x: NodeRepr_t | number): NodeRepr_t {
export function convolve(props: ConvolveNodeProps, x: ElemNode): NodeRepr_t {
return createNode("convolve", props, [resolve(x)]);
}

Expand All @@ -180,7 +180,7 @@ type SeqNodeProps = {
loop?: boolean,
};

export function seq(props: SeqNodeProps, trigger: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t {
export function seq(props: SeqNodeProps, trigger: ElemNode, reset: ElemNode): NodeRepr_t {
return createNode("seq", props, [resolve(trigger), resolve(reset)]);
}

Expand All @@ -193,7 +193,7 @@ type Seq2NodeProps = {
loop?: boolean,
};

export function seq2(props: Seq2NodeProps, trigger: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t {
export function seq2(props: Seq2NodeProps, trigger: ElemNode, reset: ElemNode): NodeRepr_t {
return createNode("seq2", props, [resolve(trigger), resolve(reset)]);
}

Expand All @@ -208,7 +208,7 @@ type SparSeqNodeProps = {
tickInterval?: number,
};

export function sparseq(props: SparSeqNodeProps, trigger: NodeRepr_t | number, reset: NodeRepr_t | number): NodeRepr_t {
export function sparseq(props: SparSeqNodeProps, trigger: ElemNode, reset: ElemNode): NodeRepr_t {
return createNode("sparseq", props, [resolve(trigger), resolve(reset)]);
}

Expand All @@ -218,13 +218,13 @@ type SparSeq2NodeProps = {
seq?: Array<{value: number, time: number}>,
};

export function sparseq2(props: SparSeq2NodeProps, time: NodeRepr_t | number): NodeRepr_t {
export function sparseq2(props: SparSeq2NodeProps, time: ElemNode): NodeRepr_t {
return createNode("sparseq2", props, [resolve(time)]);
}

// Pole node
export function pole(p: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function pole(props: OptionalKeyProps, p: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function pole(p: ElemNode, x: ElemNode): NodeRepr_t;
export function pole(props: OptionalKeyProps, p: ElemNode, x: ElemNode): NodeRepr_t;
export function pole(a, b, c?) {
if (typeof a === "number" || isNode(a)) {
return createNode("pole", {}, [resolve(a), resolve(b)]);
Expand All @@ -234,8 +234,8 @@ export function pole(a, b, c?) {
}

// Env node
export function env(atkPole: NodeRepr_t | number, relPole: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function env(props: OptionalKeyProps, atkPole: NodeRepr_t | number, relPole: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function env(atkPole: ElemNode, relPole: ElemNode, x: ElemNode): NodeRepr_t;
export function env(props: OptionalKeyProps, atkPole: ElemNode, relPole: ElemNode, x: ElemNode): NodeRepr_t;
export function env(a, b, c, d?) {
if (typeof a === "number" || isNode(a)) {
return createNode("env", {}, [resolve(a), resolve(b), resolve(c)]);
Expand All @@ -245,8 +245,8 @@ export function env(a, b, c, d?) {
}

// Single sample delay node
export function z(x: NodeRepr_t | number): NodeRepr_t;
export function z(props: OptionalKeyProps, x: NodeRepr_t | number): NodeRepr_t;
export function z(x: ElemNode): NodeRepr_t;
export function z(props: OptionalKeyProps, x: ElemNode): NodeRepr_t;
export function z(a, b?) {
if (typeof a === "number" || isNode(a)) {
return createNode("z", {}, [resolve(a)]);
Expand All @@ -263,9 +263,9 @@ type DelayNodeProps = {

export function delay(
props: DelayNodeProps,
len: NodeRepr_t | number,
fb: NodeRepr_t | number,
x : NodeRepr_t | number,
len: ElemNode,
fb: ElemNode,
x : ElemNode,
): NodeRepr_t;

export function delay(a, b, c, d) {
Expand All @@ -276,27 +276,27 @@ export function delay(a, b, c, d) {
return createNode("delay", a, [resolve(b), resolve(c), resolve(d)]);
}

export function sdelay(props: DelayNodeProps, x: NodeRepr_t | number): NodeRepr_t {
export function sdelay(props: DelayNodeProps, x: ElemNode): NodeRepr_t {
return createNode("sdelay", props, [resolve(x)]);
}

// Multimode1p
export function prewarp(fc: NodeRepr_t | number): NodeRepr_t {
export function prewarp(fc: ElemNode): NodeRepr_t {
return createNode("prewarp", {}, [fc]);
}

export function mm1p(
fc: NodeRepr_t | number,
x: NodeRepr_t | number,
fc: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function mm1p(
props: {
key?: string,
mode?: string,
},
fc: NodeRepr_t | number,
x: NodeRepr_t | number,
fc: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function mm1p(a, b, c?) {
Expand All @@ -315,19 +315,19 @@ export function mm1p(a, b, c?) {

// SVF
export function svf(
fc: NodeRepr_t | number,
q: NodeRepr_t | number,
x: NodeRepr_t | number,
fc: ElemNode,
q: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function svf(
props: {
key?: string,
mode?: string,
},
fc: NodeRepr_t | number,
q: NodeRepr_t | number,
x: NodeRepr_t | number,
fc: ElemNode,
q: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function svf(a, b, c, d?) {
Expand All @@ -347,21 +347,21 @@ export function svf(a, b, c, d?) {
}

export function svfshelf(
fc: NodeRepr_t | number,
q: NodeRepr_t | number,
gainDecibels: NodeRepr_t | number,
x: NodeRepr_t | number,
fc: ElemNode,
q: ElemNode,
gainDecibels: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function svfshelf(
props: {
key?: string,
mode?: string,
},
fc: NodeRepr_t | number,
q: NodeRepr_t | number,
gainDecibels: NodeRepr_t | number,
x: NodeRepr_t | number,
fc: ElemNode,
q: ElemNode,
gainDecibels: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function svfshelf(a, b, c, d, e?) {
Expand All @@ -384,22 +384,22 @@ export function svfshelf(a, b, c, d, e?) {

// Biquad node
export function biquad(
b0: NodeRepr_t | number,
b1: NodeRepr_t | number,
b2: NodeRepr_t | number,
a1: NodeRepr_t | number,
a2: NodeRepr_t | number,
x: NodeRepr_t | number,
b0: ElemNode,
b1: ElemNode,
b2: ElemNode,
a1: ElemNode,
a2: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function biquad(
props: OptionalKeyProps,
b0: NodeRepr_t | number,
b1: NodeRepr_t | number,
b2: NodeRepr_t | number,
a1: NodeRepr_t | number,
a2: NodeRepr_t | number,
x: NodeRepr_t | number,
b0: ElemNode,
b1: ElemNode,
b2: ElemNode,
a1: ElemNode,
a2: ElemNode,
x: ElemNode,
): NodeRepr_t;

export function biquad(a, b, c, d, e, f, g?) {
Expand Down Expand Up @@ -437,7 +437,7 @@ export function tapIn(props: TapInNodeProps): NodeRepr_t {
return createNode("tapIn", props, []);
}

export function tapOut(props: TapOutNodeProps, x: NodeRepr_t | number): NodeRepr_t {
export function tapOut(props: TapOutNodeProps, x: ElemNode): NodeRepr_t {
return createNode("tapOut", props, [resolve(x)]);
}

Expand All @@ -447,8 +447,8 @@ type MeterNodeProps = {
name?: string,
};

export function meter(x: NodeRepr_t | number): NodeRepr_t;
export function meter(props: MeterNodeProps, x: NodeRepr_t | number): NodeRepr_t;
export function meter(x: ElemNode): NodeRepr_t;
export function meter(props: MeterNodeProps, x: ElemNode): NodeRepr_t;
export function meter(a, b?) {
if (typeof a === "number" || isNode(a)) {
return createNode("meter", {}, [resolve(a)]);
Expand All @@ -463,8 +463,8 @@ type SnapshotNodeProps = {
name?: string,
};

export function snapshot(trigger: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function snapshot(props: SnapshotNodeProps, trigger: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function snapshot(trigger: ElemNode, x: ElemNode): NodeRepr_t;
export function snapshot(props: SnapshotNodeProps, trigger: ElemNode, x: ElemNode): NodeRepr_t;
export function snapshot(a, b, c?) {
if (typeof a === "number" || isNode(a)) {
return createNode("snapshot", {}, [resolve(a), resolve(b)]);
Expand All @@ -481,8 +481,8 @@ type ScopeNodeProps = {
channels?: number,
};

export function scope(...args : Array<NodeRepr_t | number>): NodeRepr_t;
export function scope(props: ScopeNodeProps, ...args : Array<NodeRepr_t | number>): NodeRepr_t;
export function scope(...args : Array<ElemNode>): NodeRepr_t;
export function scope(props: ScopeNodeProps, ...args : Array<ElemNode>): NodeRepr_t;
export function scope(a, ...bs) {
if (typeof a === "number" || isNode(a)) {
return createNode("scope", {}, [a, ...bs].map(resolve));
Expand All @@ -498,8 +498,8 @@ type FFTNodeProps = {
size?: number,
};

export function fft(x: NodeRepr_t | number): NodeRepr_t;
export function fft(props: FFTNodeProps, x: NodeRepr_t | number): NodeRepr_t;
export function fft(x: ElemNode): NodeRepr_t;
export function fft(props: FFTNodeProps, x: ElemNode): NodeRepr_t;
export function fft(a, b?) {
if (typeof a === "number" || isNode(a)) {
return createNode("fft", {}, [resolve(a)]);
Expand All @@ -514,8 +514,8 @@ type CaptureNodeProps = {
size?: number,
};

export function capture(g: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function capture(props: CaptureNodeProps, g: NodeRepr_t | number, x: NodeRepr_t | number): NodeRepr_t;
export function capture(g: ElemNode, x: ElemNode): NodeRepr_t;
export function capture(props: CaptureNodeProps, g: ElemNode, x: ElemNode): NodeRepr_t;
export function capture(a, b, c?) {
if (typeof a === "number" || isNode(a)) {
return createNode("capture", {}, [resolve(a), resolve(b)]);
Expand Down
Loading

0 comments on commit 0ada610

Please sign in to comment.