diff --git a/common.js b/common.js new file mode 100644 index 0000000..20f797c --- /dev/null +++ b/common.js @@ -0,0 +1,54 @@ +function DropDown(props) { + return e('select', {type: "number", onChange: props.onChange, value: props.value}, + ...props.options.map((item) => Option(item))); +} + +function ListItem(child){ + return e('li', null, child); +} + +function Label(text){ + return e('div', {className: 'label'}, text); +} + +function NumberBox(props){ + return e('input', {type: "number", onChange: props.onChange, value: props.value, className: props.className}, null); +} + +function TextBox(props){ + return e('input', {type: "text", value: props.value, onChange: props.onChange}); +} + +function Option(str){ + return e("option", null, str); +} + +function Button(props){ + return e('button', {onClick: props.onClick}, props.text); +} + +function Switch(props){ + return e('label', {className: 'switch'}, + e('input', {type: 'checkbox', onClick: props.ontoggle}, null), + e('span', {className: 'slider round'}, null)) +} + +function CreateParamChanger(arr, setArr, index){ + return (event) => { + let newArr = arr.slice(); + newArr[index] = event.target.value; + setArr(newArr); + log(`${index} ${event.target.value}`); + } +} + +function CreateMatrixParamChanger(matrix, setMatrix, i, j){ + return (event) => { + var newMatrix = matrix.map(function(arr) { + return arr.slice(); + }); + newMatrix[i][j] = event.target.value; + setMatrix(newMatrix); + log(`${i}, ${j} ${event.target.value}`); + } +} \ No newline at end of file diff --git a/enums.js b/enums.js new file mode 100644 index 0000000..cfc45e8 --- /dev/null +++ b/enums.js @@ -0,0 +1,30 @@ +///////////////////////// +// ENUMERATORS +///////////////////////// + + +// NOT A REACT FUNCTIONAL COMPONENT. MERELY RETURNS AN ARRAY WHICH IS UNPACKED +function EnumeratorItems(index, enumBreakPoints, setEnumBreakPoints, enumNames, setEnumNames){ + let items = [] + + for (let i = 0; i < MAXENUMPOINTS; i++){ + items.push(ListItem(e(TextBox, {onChange: CreateMatrixParamChanger(enumNames, setEnumNames, index, i), value: enumNames[index][i]}, null))); + // Add 1 to make up for the lower enum bound + items.push(ListItem(e(NumberBox, {onChange: CreateMatrixParamChanger(enumBreakPoints, setEnumBreakPoints, index, i + 1), value:enumBreakPoints[index][i + 1]}, null))); + } + return items; +} + +function EnumeratorRow(props){ + let content = e('ul', {className: 'lfo-item'}, + ListItem(DropDown({onChange: props.setDjParam, value: props.djParam, options: PARAMOPTIONS})), + ListItem(e(NumberBox, {onChange: props.setEnumItemCounts, value:props.enumItems, className: 'enum-count'}, null)), + ListItem(e(NumberBox, {onChange: CreateMatrixParamChanger(props.enumBreakPoints, props.setEnumBreakPoints, props.index, 0), value:props.enumBreakPoints[props.index][0]}, null)), + ...(EnumeratorItems(props.index, props.enumBreakPoints, props.setEnumBreakPoints, props.enumNames, props.setEnumNames).slice(0, props.enumItems * 2)), + ListItem(e(Button, {text:'+', onClick: props.addEnum}, null)), + ListItem(e(Button, {text:'-', onClick: props.removeEnum}, null)) + ); + if (props.visible){ + return content; + }; +} \ No newline at end of file diff --git a/lfogui.html b/lfogui.html index 92f2b19..dad76a3 100644 --- a/lfogui.html +++ b/lfogui.html @@ -144,6 +144,14 @@ .enum-count { background-color: aquamarine; } + + .label { + background-color: aliceblue; + padding: 0 4px 0 4px; + margin: 0 2px 0 2px; + border-color: #333333; + border-width: 1px; + } @@ -153,6 +161,9 @@ + + +