From 44e929d5c505d9c5436baaebb17506e162525866 Mon Sep 17 00:00:00 2001 From: Marco Christian Krenn Date: Thu, 23 Nov 2023 17:18:56 +0100 Subject: [PATCH] streamline series nodes - sort inputs on series - fix output for arithmetic series - update harmonic series --- .../flow/nodes/series/arithmeticNode.tsx | 29 ++++++------ .../flow/nodes/series/geometricNode.tsx | 46 +++++++++--------- .../flow/nodes/series/harmonicNode.tsx | 47 ++++++++++--------- .../src/nodes/series/arithmetic.ts | 37 ++++++++------- .../src/nodes/series/geometric.ts | 6 +-- .../graph-engine/src/nodes/series/harmonic.ts | 33 ++++++------- 6 files changed, 102 insertions(+), 96 deletions(-) diff --git a/packages/graph-editor/src/components/flow/nodes/series/arithmeticNode.tsx b/packages/graph-editor/src/components/flow/nodes/series/arithmeticNode.tsx index a70d1b53..c504dfd8 100644 --- a/packages/graph-editor/src/components/flow/nodes/series/arithmeticNode.tsx +++ b/packages/graph-editor/src/components/flow/nodes/series/arithmeticNode.tsx @@ -39,20 +39,6 @@ const ArithmeticNode = (props) => { return ( - - - - {input?.base ? ( - - ) : ( - - )} - - Steps Down @@ -80,6 +66,21 @@ const ArithmeticNode = (props) => { )} + + + + {input?.base ? ( + + ) : ( + + )} + + + diff --git a/packages/graph-editor/src/components/flow/nodes/series/geometricNode.tsx b/packages/graph-editor/src/components/flow/nodes/series/geometricNode.tsx index 7dad2c0b..887b302e 100644 --- a/packages/graph-editor/src/components/flow/nodes/series/geometricNode.tsx +++ b/packages/graph-editor/src/components/flow/nodes/series/geometricNode.tsx @@ -39,26 +39,7 @@ const GeometricNode = (props) => { return ( - - Base - {input.base ? ( - - ) : ( - - )} - - - Ratio - {input.ratio ? ( - - ) : ( - - )} - + Steps Down {input.stepsDown ? ( @@ -71,8 +52,9 @@ const GeometricNode = (props) => { /> )} + - Steps + Steps Up {input.steps ? ( ) : ( @@ -84,6 +66,28 @@ const GeometricNode = (props) => { )} + + Base + {input.base ? ( + + ) : ( + + )} + + + + Ratio + {input.ratio ? ( + + ) : ( + + )} + + Precision diff --git a/packages/graph-editor/src/components/flow/nodes/series/harmonicNode.tsx b/packages/graph-editor/src/components/flow/nodes/series/harmonicNode.tsx index de230bd3..a197d9ec 100644 --- a/packages/graph-editor/src/components/flow/nodes/series/harmonicNode.tsx +++ b/packages/graph-editor/src/components/flow/nodes/series/harmonicNode.tsx @@ -39,26 +39,7 @@ const HarmonicNode = (props) => { return ( - - Base - {input.base ? ( - - ) : ( - - )} - - - Ratio - {input.ratio ? ( - - ) : ( - - )} - + Steps Down {input.stepsDown ? ( @@ -71,8 +52,9 @@ const HarmonicNode = (props) => { /> )} + - Steps + Steps Up {input.steps ? ( ) : ( @@ -83,6 +65,29 @@ const HarmonicNode = (props) => { /> )} + + + Base + {input.base ? ( + + ) : ( + + )} + + + + Ratio + {input.ratio ? ( + + ) : ( + + )} + + Notes {input.notes ? ( diff --git a/packages/graph-engine/src/nodes/series/arithmetic.ts b/packages/graph-engine/src/nodes/series/arithmetic.ts index cb5af8c9..e098c3b5 100644 --- a/packages/graph-engine/src/nodes/series/arithmetic.ts +++ b/packages/graph-engine/src/nodes/series/arithmetic.ts @@ -10,50 +10,51 @@ export const defaults = { precision: 2, }; +export type ArithemeticValue = { + index: number; + value: number; +}; + export const process = (input, state) => { const final = { ...state, ...input, }; - const sizes: Output = []; + const values: ArithemeticValue[] = []; //Fixes issue with string concatenation const base = parseFloat(final.base); const shift = 10 ** final.precision; for (let i = Math.abs(final.stepsDown); i > 0; i--) { const value = Math.round((base - final.increment * i) * shift) / shift; - sizes.push({ - step: 0 - i, - size: value, + values.push({ + index: 0 - i, + value: value, }); } - sizes.push({ - step: 0, - size: Math.round(final.base * shift) / shift, + values.push({ + index: 0, + value: Math.round(final.base * shift) / shift, }); for (let i = 0; i < Math.abs(final.steps); i++) { const value = Math.round((base + final.increment * (i + 1)) * shift) / shift; - sizes.push({ - step: i + 1, - size: value, + values.push({ + index: i + 1, + value: value, }); } - return sizes; + return values; }; -export type Output = { - size: number; - step: number; -}[]; -export const mapOutput = (input, state, processed) => { - const mapped = { asArray: processed.map((item) => item.size) }; +export const mapOutput = (input, state, processed: ArithemeticValue[]) => { + const mapped = { asArray: processed }; processed.forEach((item) => { - mapped[`${item.step}`] = item.size; + mapped[item.index] = item.value; }); return mapped; }; diff --git a/packages/graph-engine/src/nodes/series/geometric.ts b/packages/graph-engine/src/nodes/series/geometric.ts index d86c63f8..5c816aca 100644 --- a/packages/graph-engine/src/nodes/series/geometric.ts +++ b/packages/graph-engine/src/nodes/series/geometric.ts @@ -24,13 +24,13 @@ export const process = (input, state) => { const values: GeometricValue[] = []; const shift = 10 ** final.precision; - for (let i = 0 - final.stepsDown; i < final.steps; i++) { + for (let i = 0 - final.stepsDown; i <= final.steps; i++) { const value = Math.round((final.base * Math.pow(final.ratio, i)) * shift) / shift; values.push({ - value, index: i, + value }); - } + } return values; }; diff --git a/packages/graph-engine/src/nodes/series/harmonic.ts b/packages/graph-engine/src/nodes/series/harmonic.ts index 20b03144..1493e013 100644 --- a/packages/graph-engine/src/nodes/series/harmonic.ts +++ b/packages/graph-engine/src/nodes/series/harmonic.ts @@ -4,17 +4,16 @@ export const type = NodeTypes.HARMONIC_SERIES; export const defaults = { base: 16, - ratio: 1.5, + ratio: 2, stepsDown: 0, steps: 5, - notes: 1, + notes: 5, precision: 2, }; type HarmonicValue = { - size: number; - frequency: number; - note: number; + index: number; + value: number; }; export const process = (input, state) => { @@ -25,28 +24,24 @@ export const process = (input, state) => { const values: HarmonicValue[] = []; - for (let i = 0 - final.stepsDown; i < final.steps; i++) { - for (let j = 0; j < final.notes; j++) { - const shift = 10 ** final.precision; - const size = - final.base * Math.pow(final.ratio, (i * final.notes + j) / final.notes); - const rounded = Math.round(size * shift) / shift; - values.push({ - size: rounded, - frequency: i, - note: j, - }); - } + for (let i = 0 - final.stepsDown; i <= final.steps; i++) { + const shift = 10 ** final.precision; + const size = final.base * Math.pow(final.ratio, (i / final.notes)); + const rounded = Math.round(size * shift) / shift; + values.push({ + index: i, + value: rounded, + }); } - return values; + return values; }; export const mapOutput = (input, state, processed: HarmonicValue[]) => { const mapped = { asArray: processed }; processed.forEach((item) => { - mapped[`${item.frequency}-${item.note}`] = item.size; + mapped[item.index] = item.value; }); return mapped; };