13 Commits

Author SHA1 Message Date
64f1455f69 fixed userwave update 2024-10-14 09:16:05 +02:00
34e99f09fd lock mode 2024-10-11 12:52:54 +02:00
86a994546e Merge pull request 'noise-functions' (#3) from noise-functions into main
Reviewed-on: #3
2024-10-10 12:25:22 +02:00
d22cdc8401 basic random value noise functions 2024-10-10 12:23:50 +02:00
trian-gles
43e517cc4e added new init values 2024-09-26 12:40:47 +02:00
a608b083f3 working sine interpolation 2024-09-25 15:59:27 +02:00
83cf801ec3 merge conflict 2024-09-24 14:35:37 +02:00
trian-gles
45e168ba11 UI changes 2024-09-24 14:35:01 +02:00
37a65058bc Merge pull request 'musical-timing-phase' (#2) from musical-timing-phase into main
Reviewed-on: #2
2024-09-03 11:37:51 +02:00
trian-gles
45847fbae4 phase calculated from ticks 2024-09-03 11:34:32 +02:00
trian-gles
c794b5bc2f separated phase handling into two options 2024-09-02 16:58:18 +02:00
trian-gles
c8c410a38f UI changes 2024-08-08 15:31:57 +02:00
985b6c832f Merge pull request 'user defined wavetable shape' (#1) from user-defined-table into main
Reviewed-on: #1
2024-08-08 14:32:34 +02:00
6 changed files with 507 additions and 246 deletions

View File

@@ -5,7 +5,8 @@ function isNumeric(str) {
} }
function DropDown(props) { function DropDown(props) {
return e('select', {type: "number", onChange: props.onChange, value: props.value}, let className = props.locked ? 'locked-component' : '';
return e('select', {className, type: "number", onChange: props.onChange, value: props.value},
...props.options.map((item) => Option(item))); ...props.options.map((item) => Option(item)));
} }
@@ -18,11 +19,13 @@ function Label(text){
} }
function NumberBox(props){ function NumberBox(props){
return e('input', {type: "number", onChange: props.onChange, step: props.step, value: props.value, className: props.className}, null); let extraClassName = props.locked ? ' locked-component' : '';
return e('input', {type: "number", onChange: props.onChange, step: props.step, value: props.value, className: props.className + extraClassName}, null);
} }
function TextBox(props){ function TextBox(props){
return e('input', {type: "text", value: props.value, onChange: props.onChange, id: props.id}); let className = props.locked ? 'locked-component' : '';
return e('input', {className, type: "text", value: props.value, onChange: props.onChange, id: props.id});
} }
function Option(str, value){ function Option(str, value){
@@ -30,7 +33,8 @@ function Option(str, value){
} }
function Button(props){ function Button(props){
return e('button', {onClick: props.onClick}, props.text); let className = props.locked ? 'locked-component' : '';
return e('button', {onClick: props.onClick, className}, props.text);
} }
function Switch(props){ function Switch(props){

View File

@@ -5,13 +5,13 @@
// NOT A REACT FUNCTIONAL COMPONENT. MERELY RETURNS AN ARRAY WHICH IS UNPACKED // NOT A REACT FUNCTIONAL COMPONENT. MERELY RETURNS AN ARRAY WHICH IS UNPACKED
function EnumeratorItems(index, enumBreakPoints, setEnumBreakPoints, enumNames, setEnumNames, djParam){ function EnumeratorItems(index, enumBreakPoints, setEnumBreakPoints, enumNames, setEnumNames, djParam, locked){
let items = []; let items = [];
for (let i = 0; i < MAXENUMPOINTS; i++){ for (let i = 0; i < MAXENUMPOINTS; i++){
items.push(ListItem(e(TextBox, {onChange: CreateMatrixParamChanger(enumNames, setEnumNames, index, i), value: enumNames[index][i], id:`text-${djParam}-${enumNames[index][i]}`}, null))); items.push(ListItem(e(TextBox, {locked, onChange: CreateMatrixParamChanger(enumNames, setEnumNames, index, i), value: enumNames[index][i], id:`text-${djParam}-${enumNames[index][i]}`}, null)));
// Add 1 to make up for the lower enum bound // 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))); items.push(ListItem(e(NumberBox, {locked, onChange: CreateMatrixParamChanger(enumBreakPoints, setEnumBreakPoints, index, i + 1), value:enumBreakPoints[index][i + 1]}, null)));
} }
return items; return items;
} }
@@ -20,13 +20,13 @@ function EnumeratorRow(props){
let linkedText = props.linked ? "<- mods" : ""; let linkedText = props.linked ? "<- mods" : "";
let content = e('ul', {className: 'lfo-item', id: `${props.djParam}-enum-row`}, let content = e('ul', {className: 'lfo-item', id: `${props.djParam}-enum-row`},
ListItem(DropDown({onChange: props.setInstanceNum, value:props.instanceNum, options: INSTANCEOPTIONS})), ListItem(DropDown({locked:props.locked, onChange: props.setInstanceNum, value:props.instanceNum, options: INSTANCEOPTIONS})),
ListItem(DropDown({onChange: props.setDjParam, value: props.djParam, options: MODPARAMOPTIONS})), ListItem(DropDown({locked:props.locked, onChange: props.setDjParam, value: props.djParam, options: MODPARAMOPTIONS})),
ListItem(e(NumberBox, {onChange: props.setEnumItemCounts, step:1, value:props.enumItems, className: 'enum-count'}, null)), ListItem(e(NumberBox, {locked:props.locked, onChange: props.setEnumItemCounts, step:1, 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], step:0.1}, null)), ListItem(e(NumberBox, {locked:props.locked, onChange: CreateMatrixParamChanger(props.enumBreakPoints, props.setEnumBreakPoints, props.index, 0), value:props.enumBreakPoints[props.index][0], step:0.1}, null)),
...(EnumeratorItems(props.index, props.enumBreakPoints, props.setEnumBreakPoints, props.enumNames, props.setEnumNames, props.djParam).slice(0, props.enumItems * 2)), ...(EnumeratorItems(props.index, props.enumBreakPoints, props.setEnumBreakPoints, props.enumNames, props.setEnumNames, props.djParam, props.locked).slice(0, props.enumItems * 2)),
ListItem(e(Button, {text:'+', onClick: props.addEnum}, null)), ListItem(e(Button, {locked:props.locked, text:'+', onClick: props.addEnum}, null)),
ListItem(e(Button, {text:'-', onClick: props.removeEnum}, null)), ListItem(e(Button, {locked:props.locked, text:'-', onClick: props.removeEnum}, null)),
ListItem(e("div", {className:"linked"}, linkedText)) ListItem(e("div", {className:"linked"}, linkedText))
); );
if (props.visible){ if (props.visible){

View File

@@ -10,7 +10,7 @@
} }
, ,
"classnamespace" : "box", "classnamespace" : "box",
"rect" : [ 34.0, 76.0, 981.0, 763.0 ], "rect" : [ 34.0, 76.0, 1155.0, 763.0 ],
"bglocked" : 0, "bglocked" : 0,
"openinpresentation" : 0, "openinpresentation" : 0,
"default_fontsize" : 12.0, "default_fontsize" : 12.0,
@@ -39,6 +39,44 @@
"subpatcher_template" : "", "subpatcher_template" : "",
"assistshowspatchername" : 0, "assistshowspatchername" : 0,
"boxes" : [ { "boxes" : [ {
"box" : {
"fontname" : "Arial",
"fontsize" : 13.0,
"id" : "obj-29",
"maxclass" : "newobj",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "bang" ],
"patching_rect" : [ 465.0, 141.0, 210.0, 23.0 ],
"text" : "metro @interval 40 ticks @active 1"
}
}
, {
"box" : {
"id" : "obj-28",
"maxclass" : "button",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "bang" ],
"parameter_enable" : 0,
"patching_rect" : [ 826.0, 79.0, 24.0, 24.0 ]
}
}
, {
"box" : {
"id" : "obj-3",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 817.0, 147.0, 80.0, 22.0 ],
"text" : "prepend ticks"
}
}
, {
"box" : { "box" : {
"id" : "obj-54", "id" : "obj-54",
"maxclass" : "newobj", "maxclass" : "newobj",
@@ -130,7 +168,7 @@
"numoutlets" : 1, "numoutlets" : 1,
"outlettype" : [ "" ], "outlettype" : [ "" ],
"patching_rect" : [ 586.0, 713.0, 89.0, 36.0 ], "patching_rect" : [ 586.0, 713.0, 89.0, 36.0 ],
"text" : "harmoniclarity 40.156651" "text" : "harmoniclarity 14.213599"
} }
} }
@@ -143,7 +181,7 @@
"numoutlets" : 1, "numoutlets" : 1,
"outlettype" : [ "" ], "outlettype" : [ "" ],
"patching_rect" : [ 491.0, 713.0, 85.0, 36.0 ], "patching_rect" : [ 491.0, 713.0, 85.0, 36.0 ],
"text" : "event_length 29.843349" "text" : "event_length 55.786401"
} }
} }
@@ -156,7 +194,7 @@
"numoutlets" : 1, "numoutlets" : 1,
"outlettype" : [ "" ], "outlettype" : [ "" ],
"patching_rect" : [ 385.0, 715.0, 84.0, 36.0 ], "patching_rect" : [ 385.0, 715.0, 84.0, 36.0 ],
"text" : "metriclarity 22.176645" "text" : "metriclarity 79.192955"
} }
} }
@@ -244,18 +282,6 @@
"text" : "prepend timesig" "text" : "prepend timesig"
} }
}
, {
"box" : {
"id" : "obj-52",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 545.0, 135.0, 89.0, 22.0 ],
"text" : "prepend tempo"
}
} }
, { , {
"box" : { "box" : {
@@ -299,8 +325,7 @@
"numinlets" : 1, "numinlets" : 1,
"numoutlets" : 5, "numoutlets" : 5,
"outlettype" : [ "preset", "int", "preset", "int", "" ], "outlettype" : [ "preset", "int", "preset", "int", "" ],
"patching_rect" : [ 934.0, 27.0, 100.0, 40.0 ], "patching_rect" : [ 934.0, 27.0, 100.0, 40.0 ]
"pattrstorage" : "storage"
} }
} }
@@ -784,6 +809,27 @@
"source" : [ "obj-27", 1 ] "source" : [ "obj-27", 1 ]
} }
}
, {
"patchline" : {
"destination" : [ "obj-47", 0 ],
"source" : [ "obj-28", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-47", 0 ],
"source" : [ "obj-29", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"source" : [ "obj-3", 0 ]
}
} }
, { , {
"patchline" : { "patchline" : {
@@ -886,8 +932,8 @@
} }
, { , {
"patchline" : { "patchline" : {
"destination" : [ "obj-52", 0 ], "destination" : [ "obj-3", 0 ],
"source" : [ "obj-47", 4 ] "source" : [ "obj-47", 7 ]
} }
} }
@@ -904,13 +950,6 @@
"source" : [ "obj-5", 0 ] "source" : [ "obj-5", 0 ]
} }
}
, {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"source" : [ "obj-52", 0 ]
}
} }
, { , {
"patchline" : { "patchline" : {

View File

@@ -1,181 +1,272 @@
html, * {
body { --locked-color: #5fadbf;
width: 100%; --unlocked-color: #ff5153;
height: 100%; }
margin: 0px;
border: 0;
overflow: hidden; /* Disable scrollbars */
display: block; /* No floating content on sides */
}
ul { html, body {
list-style-type: none; width: 100%;
margin: 0; height: 100%;
padding: 0; margin: 0px;
overflow: hidden; border: 0;
background-color: #333333; overflow: hidden; /* Disable scrollbars */
} display: block; /* No floating content on sides */
}
li { ul {
float: left; list-style-type: none;
} margin: 0;
padding: 0;
overflow: hidden;
background-color: #333333;
}
li {
input[type=number] { float: left;
width: 50px; }
margin: 0;
padding: 0;
}
input[type=text] {
width: 60px;
margin: 0;
padding: 0;
font-weight: bold;
}
.timeInput { input[type=number] {
width: 80px; width: 50px;
margin: 0; margin: 0;
padding: 0; padding: 0;
} }
#matrix { input[type=text] {
background-color: aquamarine; width: 60px;
height: 100%; margin: 0;
width: 100%; padding: 0;
} font-weight: bold;
}
.numbox-unclicked { .timeInput {
user-select: none; width: 80px;
border: solid; margin: 0;
font-size: 12vw; padding: 0;
} }
.numbox-clicked { #matrix {
user-select: none; background-color: aquamarine;
border : solid; height: 100%;
font-size: 12vw; width: 100%;
} }
.param-input-label { .numbox-unclicked {
width: 93%; user-select: none;
font-size: 5vw; border: solid;
} font-size: 12vw;
}
.lfo-input-label { .numbox-clicked {
width: 40%; user-select: none;
font-size: 5vw; border : solid;
} font-size: 12vw;
}
/* The switch - the box around the slider */ .param-input-label {
.switch { width: 93%;
position: relative; font-size: 5vw;
display: inline-block; }
width: 30px;
height: 17px;
}
/* Hide default HTML checkbox */ .lfo-input-label {
.switch input { width: 40%;
opacity: 0; font-size: 5vw;
width: 0; }
height: 0;
}
/* The slider */ /* The switch - the box around the slider */
.slider { .switch {
position: absolute; position: relative;
cursor: pointer; display: inline-block;
top: 0; width: 30px;
left: 0; height: 17px;
right: 0; }
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
.slider:before { /* Hide default HTML checkbox */
position: absolute; .switch input {
content: ""; opacity: 0;
height: 13px; width: 0;
width: 13px; height: 0;
left: 2px; }
bottom: 2px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider { /* The slider */
background-color: #2196F3; .slider {
} position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: .4s;
transition: .4s;
}
input:focus + .slider { .slider:before {
box-shadow: 0 0 1px #2196F3; position: absolute;
} content: "";
height: 13px;
width: 13px;
left: 2px;
bottom: 2px;
background-color: white;
-webkit-transition: .4s;
transition: .4s;
}
input:checked + .slider:before { input:checked + .slider {
-webkit-transform: translateX(13px); background-color: #2196F3;
-ms-transform: translateX(13px); }
transform: translateX(13px);
}
/* Rounded sliders */ input:focus + .slider {
.slider.round { box-shadow: 0 0 1px #2196F3;
border-radius: 17px; }
}
.slider.round:before { input:checked + .slider:before {
border-radius: 50%; -webkit-transform: translateX(13px);
} -ms-transform: translateX(13px);
transform: translateX(13px);
}
h5 { /* Rounded sliders */
margin: 0; .slider.round {
padding: 0; border-radius: 17px;
} }
.enum-count { .slider.round:before {
background-color: aquamarine; border-radius: 50%;
} }
.label { h5 {
background-color: aliceblue; margin: 0;
padding: 0 4px 0 4px; padding: 0;
margin: 0 2px 0 2px; }
border-color: #333333;
border-width: 1px;
}
.base-val { .enum-count {
background-color: lightgray; background-color: aquamarine;
border-color: #333333; }
border-width: 1px;
width: 50px;
margin-left: 2px;
margin-top: 1px;
}
.linked { .label {
color: red; background-color: aliceblue;
border-width: 1px; padding: 0 4px 0 4px;
width: 50px; margin: 0 2px 0 2px;
font-size: small; border-color: #333333;
margin-left: 2px; border-width: 1px;
margin-top: 5px; }
}
@keyframes pulse-animation { .base-val {
0% { background-color: lightgray;
color: black; border-color: #333333;
} border-width: 1px;
100% { width: 50px;
color: red; margin-left: 2px;
} margin-top: 1px;
} }
#pulse { .linked {
animation: pulse-animation 0.2s normal; color: red;
} border-width: 1px;
width: 50px;
font-size: small;
margin-left: 2px;
margin-top: 5px;
}
@keyframes pulse-animation {
0% {
color: black;
}
100% {
color: red;
}
}
#pulse {
animation: pulse-animation 0.2s normal;
}
/* :::::::::::::: LOCK CSS */
.locked-component {
pointer-events: none;
background-color: #333333;
color : white;
}
.container {
display: flex;
width: 100%;
justify-content: space-between;
}
/* Locked */
.lock {
margin-top: 14px;
width: 24px;
height: 21px;
border: 3px solid var(--locked-color);
border-radius: 5px;
position: relative;
cursor: pointer;
-webkit-transition: all 0.1s ease-in-out;
transition: all 0.1s ease-in-out;
}
.lock:after {
content: "";
display: block;
background: var(--locked-color);
width: 3px;
height: 7px;
position: absolute;
top: 50%;
left: 50%;
margin: -3.5px 0 0 -2px;
-webkit-transition: all 0.1s ease-in-out;
transition: all 0.1s ease-in-out;
}
.lock:before {
content: "";
display: block;
width: 10px;
height: 10px;
bottom: 100%;
position: absolute;
left: 50%;
margin-left: -8px;
border: 3px solid var(--locked-color);
border-top-right-radius: 50%;
border-top-left-radius: 50%;
border-bottom: 0;
-webkit-transition: all 0.1s ease-in-out;
transition: all 0.1s ease-in-out;
}
/* Locked Hover */
.lock:hover:before {
height: 12px;
}
/* Unlocked */
.unlocked {
transform: rotate(10deg);
}
.unlocked:before {
bottom: 130%;
left: 31%;
margin-left: -11.5px;
transform: rotate(-45deg);
}
.unlocked,
.unlocked:before {
border-color: var(--unlocked-color);
}
.unlocked:after {
background: var(--unlocked-color);
}
/* Unlocked Hover */
.unlocked:hover {
transform: rotate(3deg);
}
.unlocked:hover:before {
height: 10px;
left: 40%;
bottom: 124%;
transform: rotate(-30deg);
}

View File

@@ -20,6 +20,11 @@ const ViewModes = Object.freeze({
ENUM: 1 ENUM: 1
}); });
const LockModes = Object.freeze({
UNLOCK: 0,
LOCK: 1
});
var modPhases = Array(MAXLFOS).fill(0); var modPhases = Array(MAXLFOS).fill(0);
var firstUpdateTime = Date.now(); var firstUpdateTime = Date.now();
@@ -43,18 +48,28 @@ function MasterLfoHandler(){
setViewMode(ViewModes.MOD); setViewMode(ViewModes.MOD);
}; };
const [lockMode, setLockMode] = React.useState(LockModes.LOCK);
const toggleLockMode = () => {
if (lockMode === LockModes.UNLOCK)
setLockMode(LockModes.LOCK);
else
setLockMode(LockModes.UNLOCK);
};
/// MODULATOR ARRAYS /// MODULATOR ARRAYS
const [userDefinedWave, setUserDefinedWave] = React.useState(Array(50).fill(0)); const [userDefinedWave, setUserDefinedWave] = React.useState(Array(50).fill(0));
const [modVisibleArr, setModVisibleArr] = React.useState(initVisArr); const [modVisibleArr, setModVisibleArr] = React.useState(initVisArr);
const [modTypeArr, setModTypeArr] = React.useState(Array(MAXLFOS).fill('LFO'));
const [modInstanceNumArr, setModInstanceNumArr] = React.useState(Array(MAXLFOS).fill('1')); const [modInstanceNumArr, setModInstanceNumArr] = React.useState(Array(MAXLFOS).fill('1'));
const [modCenterVals, setModCenterVals] = React.useState({'1':{}, '2':{}, '3':{}, '4':{}}); const [modCenterVals, setModCenterVals] = React.useState({'1':{}, '2':{}, '3':{}, '4':{}});
const [bpm, setBpm] = React.useState(100); const [ticks, setTicks] = React.useState(0);
const [beatsInMeasure, setBeatsInMeasure] = React.useState(4); const [beatsInMeasure, setBeatsInMeasure] = React.useState(4);
const [noiseTypeArr, setNoiseTypeArr] = React.useState(Array(MAXLFOS).fill('Sine Int.'));
const [shapeArr, setShapeArr] = React.useState(Array(MAXLFOS).fill('Sine')); const [shapeArr, setShapeArr] = React.useState(Array(MAXLFOS).fill('Sine'));
const [djParamArr, setDjParamArr] = React.useState(Array(MAXLFOS).fill('NONE')); const [djParamArr, setDjParamArr] = React.useState(Array(MAXLFOS).fill('NONE'));
@@ -64,11 +79,15 @@ function MasterLfoHandler(){
const [minArr, setMinArr] = React.useState(Array(MAXLFOS).fill('0')); const [minArr, setMinArr] = React.useState(Array(MAXLFOS).fill('0'));
const [maxArr, setMaxArr] = React.useState(Array(MAXLFOS).fill('1')); const [maxArr, setMaxArr] = React.useState(Array(MAXLFOS).fill('1'));
const [phaseArr, setPhaseArr] = React.useState(Array(MAXLFOS).fill('0')); const [initPhaseArr, setInitPhaseArr] = React.useState(Array(MAXLFOS).fill('0'));
const [lastPhaseArr, setLastPhaseArr] = React.useState(Array(MAXLFOS).fill(0));
const [cachedNoiseValueArr, setCachedNoiseValueArr] = React.useState(Array(MAXLFOS).fill([0, 0]));
const allModArrays = [modVisibleArr, modInstanceNumArr, shapeArr, djParamArr, freqArr, minArr, maxArr, phaseArr];
const allModSetters = [setModVisibleArr, setModInstanceNumArr, setShapeArr, setDjParamArr, setFreqArr, setMinArr, setMaxArr, setPhaseArr];
const modBlankVals = [true, '1', SHAPETYPES[0], MODPARAMOPTIONS[0], '1hz', '0', '1', '0']; const allModArrays = [modVisibleArr, modTypeArr, modInstanceNumArr, shapeArr, noiseTypeArr, djParamArr, freqArr, minArr, maxArr, initPhaseArr, lastPhaseArr, cachedNoiseValueArr];
const allModSetters = [setModVisibleArr, setModTypeArr, setModInstanceNumArr, setShapeArr, setNoiseTypeArr, setDjParamArr, setFreqArr, setMinArr, setMaxArr, setInitPhaseArr, lastPhaseArr, cachedNoiseValueArr];
const modBlankVals = [true, 'LFO', '1', SHAPETYPES[0], MODPARAMOPTIONS[0], "Sine Int.", '1hz', '0', '1', '0', 0, [0, 0]];
/// ENUMERATOR ARRAYS /// ENUMERATOR ARRAYS
@@ -112,7 +131,6 @@ function MasterLfoHandler(){
React.useEffect(() => { React.useEffect(() => {
function handleLoad(event) { function handleLoad(event) {
window.max.getDict(event.detail, (dict) => { window.max.getDict(event.detail, (dict) => {
for (let i = 0; i<allModArrays.length; i++) { for (let i = 0; i<allModArrays.length; i++) {
@@ -200,11 +218,8 @@ function MasterLfoHandler(){
function handleTick(event) { function handleTick(event) {
let time = (Date.now() - firstUpdateTime) / 1000; let time = (Date.now() - firstUpdateTime) / 1000;
operateModulators(modVisibleArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, phaseArr, userDefinedWave, time, bpm, beatsInMeasure); let noiseData = {lastPhaseArr, setLastPhaseArr, cachedNoiseValueArr, setCachedNoiseValueArr, noiseTypeArr};
} operateModulators(modVisibleArr, modTypeArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, initPhaseArr, noiseData, userDefinedWave, time, beatsInMeasure, ticks);
function handleBpm(event) {
setBpm(event.detail);
} }
function handleTimeSig(event) { function handleTimeSig(event) {
@@ -215,15 +230,19 @@ function MasterLfoHandler(){
setUserDefinedWave(event.detail); setUserDefinedWave(event.detail);
} }
function handleMaxTicks(event){
setTicks(event.detail);
}
window.addEventListener('loadDict', handleLoad); window.addEventListener('loadDict', handleLoad);
window.addEventListener('saveDict', handleSave); window.addEventListener('saveDict', handleSave);
window.addEventListener('tick', handleTick); window.addEventListener('tick', handleTick);
window.addEventListener('param', handleParam); window.addEventListener('param', handleParam);
window.addEventListener('enum', handleEnum); window.addEventListener('enum', handleEnum);
window.addEventListener('tempo', handleBpm);
window.addEventListener('timesig', handleTimeSig); window.addEventListener('timesig', handleTimeSig);
window.addEventListener('userWave', handleChangeUserWave); window.addEventListener('userWave', handleChangeUserWave);
window.addEventListener('maxTicks', handleMaxTicks);
return () => { return () => {
window.removeEventListener('loadDict', handleLoad); window.removeEventListener('loadDict', handleLoad);
@@ -231,11 +250,11 @@ function MasterLfoHandler(){
window.removeEventListener('tick', handleTick); window.removeEventListener('tick', handleTick);
window.removeEventListener('param', handleParam); window.removeEventListener('param', handleParam);
window.removeEventListener('enum', handleEnum); window.removeEventListener('enum', handleEnum);
window.removeEventListener('tempo', handleBpm);
window.removeEventListener('timesig', handleTimeSig); window.removeEventListener('timesig', handleTimeSig);
window.removeEventListener('userWave', handleChangeUserWave); window.removeEventListener('userWave', handleChangeUserWave);
window.removeEventListener('maxTicks', handleMaxTicks);
}; };
}, [...allModArrays, ...allEnumArrays, ...allEnumMats, modCenterVals, render, bpm, beatsInMeasure]); }, [...allModArrays, ...allEnumArrays, ...allEnumMats, userDefinedWave, modCenterVals, render, beatsInMeasure, ticks]);
function CheckLinked(inst, param, checkInstArr, checkParamArr){ function CheckLinked(inst, param, checkInstArr, checkParamArr){
@@ -256,10 +275,17 @@ function MasterLfoHandler(){
modContents.push( modContents.push(
e(LfoRow, { e(LfoRow, {
locked : lockMode,
instanceNum : modInstanceNumArr[i], instanceNum : modInstanceNumArr[i],
setInstanceNum: CreateParamChanger(modInstanceNumArr, setModInstanceNumArr, i), setInstanceNum: CreateParamChanger(modInstanceNumArr, setModInstanceNumArr, i),
type: modTypeArr[i],
setType: CreateParamChanger(modTypeArr, setModTypeArr, i),
shape: shapeArr[i], shape: shapeArr[i],
setShape: CreateParamChanger(shapeArr, setShapeArr, i), setShape: CreateParamChanger(shapeArr, setShapeArr, i),
noise: noiseTypeArr[i],
setNoise: CreateParamChanger(noiseTypeArr, setNoiseTypeArr, i),
djParam: djParamArr[i], djParam: djParamArr[i],
setDjParam: CreateParamChanger(djParamArr, setDjParamArr, i), setDjParam: CreateParamChanger(djParamArr, setDjParamArr, i),
centerVals: modCenterVals, centerVals: modCenterVals,
@@ -275,13 +301,15 @@ function MasterLfoHandler(){
max: maxArr[i], max: maxArr[i],
setMax: CreateParamChanger(maxArr, setMaxArr, i), setMax: CreateParamChanger(maxArr, setMaxArr, i),
phase: phaseArr[i], phase: initPhaseArr[i],
setPhase: CreateParamChanger(phaseArr, setPhaseArr, i), setPhase: CreateParamChanger(initPhaseArr, setInitPhaseArr, i),
visible: modVisibleArr[i], visible: modVisibleArr[i],
linked: CheckLinked(modInstanceNumArr[i], djParamArr[i], enumInstanceNumArr, enumDjParamArr), linked: CheckLinked(modInstanceNumArr[i], djParamArr[i], enumInstanceNumArr, enumDjParamArr),
addLfo: () => { addLfo: () => {
if (id < MAXLFOS - 1){ if (id < MAXLFOS - 1){
if (modVisibleArr[id + 1]){ if (modVisibleArr[id + 1]){
let emptyIndex = modVisibleArr.findIndex((item) => !item); let emptyIndex = modVisibleArr.findIndex((item) => !item);
@@ -297,6 +325,7 @@ function MasterLfoHandler(){
} }
} }
else { else {
log("adding lfo");
for (var j = 0; j < allModArrays.length; j++){ // no space below, easy. for (var j = 0; j < allModArrays.length; j++){ // no space below, easy.
let array = allModArrays[j]; let array = allModArrays[j];
array[id + 1] = modBlankVals[j]; array[id + 1] = modBlankVals[j];
@@ -328,7 +357,7 @@ function MasterLfoHandler(){
enumContents.push( enumContents.push(
e(EnumeratorRow, { e(EnumeratorRow, {
index: i, index: i,
locked : lockMode,
instanceNum : enumInstanceNumArr[i], instanceNum : enumInstanceNumArr[i],
setInstanceNum: CreateParamChanger(enumInstanceNumArr, setEnumInstanceNumArr, i), setInstanceNum: CreateParamChanger(enumInstanceNumArr, setEnumInstanceNumArr, i),
enumItems: enumItemCounts[i], enumItems: enumItemCounts[i],
@@ -410,8 +439,19 @@ function MasterLfoHandler(){
labels = ENUMERATORLABELS; labels = ENUMERATORLABELS;
} }
let lockClass;
if (lockMode == LockModes.LOCK){
lockClass = 'lock';
}
else {
lockClass = 'lock unlocked';
}
return e('div', null, return e('div', null,
e(Switch, {ontoggle: toggleViewMode}, null), e('div', {className: 'container'},
e(Switch, {ontoggle: toggleViewMode}, null),
e('span', {className: lockClass, onClick: toggleLockMode}, null)),
e('h5', null, title), e('h5', null, title),
e('ul', null, ...labels.map(x => ListItem(Label(x)))), e('ul', null, ...labels.map(x => ListItem(Label(x)))),
e('div', {id: 'grid'}, ...grid) e('div', {id: 'grid'}, ...grid)
@@ -432,14 +472,14 @@ if (!DEBUG){
window.dispatchEvent(new CustomEvent('param', {'detail' : [inst, paramName, val]})); window.dispatchEvent(new CustomEvent('param', {'detail' : [inst, paramName, val]}));
}); });
window.max.bindInlet("tempo", (val) => {
window.dispatchEvent(new CustomEvent('tempo', {'detail' : val}));
});
window.max.bindInlet("timesig", (top, bottom) => { window.max.bindInlet("timesig", (top, bottom) => {
window.dispatchEvent(new CustomEvent('timesig', {'detail' : [top, bottom]})); window.dispatchEvent(new CustomEvent('timesig', {'detail' : [top, bottom]}));
}); });
window.max.bindInlet("ticks", (val) => {
window.dispatchEvent(new CustomEvent('maxTicks', {'detail' : val}));
});
window.max.bindInlet("userWave", (...points) => { window.max.bindInlet("userWave", (...points) => {
window.dispatchEvent(new CustomEvent('userWave', {'detail' : points})); window.dispatchEvent(new CustomEvent('userWave', {'detail' : points}));
}); });

View File

@@ -2,7 +2,10 @@
// MODULATORS // MODULATORS
///////////////////////// /////////////////////////
var TYPEOPTIONS = ["LFO", "Noise"];
var SHAPETYPES = ["Sine", "SawUp", "SawDown", "Tri", "Square", "Custom"]; var SHAPETYPES = ["Sine", "SawUp", "SawDown", "Tri", "Square", "Custom"];
var NOISETYPES = ["Rand", "Line Int.", "Sine Int."]
var INSTANCEOPTIONS = ["1", "2", "3", "4"]; var INSTANCEOPTIONS = ["1", "2", "3", "4"];
@@ -10,6 +13,11 @@ const MODPARAMOPTIONS = ["NONE", "stream", "pulse_length", "eventfulness", "even
"harmoniclarity", "melodic_cohesion", "melody_scope", "tonic_pitch", "pitch_center", "pitch_range", "dynamics", "harmoniclarity", "melodic_cohesion", "melody_scope", "tonic_pitch", "pitch_center", "pitch_range", "dynamics",
"attenuation", "chordal_weight", "tonality-profile", "ostinato-buffer", "ostinato", "meter", "scale"]; "attenuation", "chordal_weight", "tonality-profile", "ostinato-buffer", "ostinato", "meter", "scale"];
const PhaseTypes = Object.freeze({
MUSICAL: Symbol("musical"),
TIME: Symbol("time")
});
function ControlType(){ function ControlType(){
return e('select', {className: 'control-type'}, Option("LFO")); return e('select', {className: 'control-type'}, Option("LFO"));
} }
@@ -23,11 +31,20 @@ function LfoRow(props){
if (!center) if (!center)
center = 0; center = 0;
let typeOption = null;
if (props.type == "LFO"){
typeOption = ListItem(DropDown({locked:props.locked, onChange: props.setShape, value:props.shape, options: SHAPETYPES}));
}
else if (props.type == "Noise"){
typeOption = ListItem(DropDown({locked:props.locked, onChange: props.setNoise, value:props.noise, options: NOISETYPES}));
}
let content = e('ul', {className: 'lfo-item'}, let content = e('ul', {className: 'lfo-item'},
ListItem(DropDown({onChange: props.setInstanceNum, value:props.instanceNum, options: INSTANCEOPTIONS})), ListItem(DropDown({locked:props.locked, onChange: props.setInstanceNum, value:props.instanceNum, options: INSTANCEOPTIONS})),
ListItem(ControlType()), ListItem(DropDown({locked:props.locked, options: TYPEOPTIONS, onChange: props.setType, value:props.type})),
ListItem(DropDown({onChange: props.setShape, value:props.shape, options: SHAPETYPES})), typeOption,
ListItem(DropDown({onChange: props.setDjParam, value: props.djParam, options: MODPARAMOPTIONS})), ListItem(DropDown({locked:props.locked, onChange: props.setDjParam, value: props.djParam, options: MODPARAMOPTIONS})),
ListItem(e("input", {onChange:props.setFreq, value:props.freq, className:"timeInput"}, null)), ListItem(e("input", {onChange:props.setFreq, value:props.freq, className:"timeInput"}, null)),
ListItem(e(NumberBox, {onChange:props.setMin, value:props.min, step:0.1}, null)), ListItem(e(NumberBox, {onChange:props.setMin, value:props.min, step:0.1}, null)),
ListItem(e(NumberBox, {onChange:props.setMax, value:props.max, step:0.1}, null)), ListItem(e(NumberBox, {onChange:props.setMax, value:props.max, step:0.1}, null)),
@@ -35,8 +52,8 @@ function LfoRow(props){
ListItem(e(NumberBox, {onChange:props.setPhase, value:props.phase, step:0.1}, null)), ListItem(e(NumberBox, {onChange:props.setPhase, value:props.phase, step:0.1}, null)),
ListItem(e("div", {className:"base-val"}, center.toString())), ListItem(e("div", {className:"base-val"}, center.toString())),
ListItem(e("input", {type: 'range', min: 0, max: 1, step: 0.01, readonly: true, id: `slider-${props.instanceNum}-${props.djParam}`})), ListItem(e("input", {type: 'range', min: 0, max: 1, step: 0.01, readonly: true, id: `slider-${props.instanceNum}-${props.djParam}`})),
ListItem(e(Button, {text:'+', onClick: props.addLfo}, null)), ListItem(e(Button, {text:'+', onClick: props.addLfo, locked: props.locked}, null)),
ListItem(e(Button, {text:'-', onClick: props.removeLfo}, null)), ListItem(e(Button, {text:'-', onClick: props.removeLfo, locked: props.locked}, null)),
ListItem(e("div", {className:"linked"}, linkedText)), ListItem(e("div", {className:"linked"}, linkedText)),
); );
if (props.visible){ if (props.visible){
@@ -61,7 +78,7 @@ function indexWave(type, phase, userDefinedWave){
} }
} }
function operateModulators(visibleArr, instanceNumArr, paramNames, centers, freqs, mins, maxs, waveTypes, phaseArr, userDefinedWave, currTime, bpm, beatsInMeasure){ function operateModulators(visibleArr, typeArr, instanceNumArr, paramNames, centers, freqs, mins, maxs, waveTypes, phaseArr, noiseData, userDefinedWave, currTime, beatsInMeasure, ticks){
for (let i=0; i<paramNames.length; i++){ for (let i=0; i<paramNames.length; i++){
if (visibleArr[i]){ if (visibleArr[i]){
@@ -71,54 +88,124 @@ function operateModulators(visibleArr, instanceNumArr, paramNames, centers, freq
if (centers[inst].hasOwnProperty(name)){ if (centers[inst].hasOwnProperty(name)){
center = centers[inst][name]; center = centers[inst][name];
} }
let output = operateModulator(center, inst, freqs[i], mins[i], maxs[i], waveTypes[i], phaseArr, i, userDefinedWave, name, currTime, bpm, beatsInMeasure);
let output = 0;
if (typeArr[i] == "LFO")
output = operateLFO(center, inst, freqs[i], mins[i], maxs[i], waveTypes[i], phaseArr, i, userDefinedWave, name, currTime, beatsInMeasure, ticks);
else
output = operateNoise(center, inst, freqs[i], mins[i], maxs[i], waveTypes[i], phaseArr, i, name, noiseData, currTime, beatsInMeasure, ticks);
if (name !== "NONE") if (name !== "NONE")
window.dispatchEvent(new CustomEvent('enum', {'detail' : [inst, name, output]})); window.dispatchEvent(new CustomEvent('enum', {'detail' : [inst, name, output]}));
} }
} }
} }
function operateModulator(center, inst, freq, min, max, waveType, phaseArr, phaseI, userDefinedWave, name, currTime, bpm, beatsInMeasure){ function operateLFO(center, inst, timeBaseStr, min, max, waveType, phaseArr, phaseIndex, userDefinedWave, name, currTime, beatsInMeasure, maxTicks){
let amp = parseFloat(max) - parseFloat(min); let amp = parseFloat(max) - parseFloat(min);
let phaseType;
let timeBase;
freq = parseLfoTime(freq, bpm, beatsInMeasure); [timeBase, phaseType] = parseLfoTime(timeBaseStr, beatsInMeasure);
let phase = (currTime * freq + parseFloat(phaseArr[phaseI])) % 1.00; let phase;
if (phaseType === PhaseTypes.TIME)
phase = (currTime * timeBase + parseFloat(phaseArr[phaseIndex])) % 1.00;
else if (phaseType === PhaseTypes.MUSICAL)
phase = (maxTicks % timeBase) / timeBase;
let unscaled = indexWave(waveType, phase, userDefinedWave); let unscaled = indexWave(waveType, phase, userDefinedWave);
let el = document.getElementById(`slider-${inst}-${name}`); syncDisplay(inst, name, unscaled);
if (el)
el.value = unscaled;
return unscaled * amp + center + parseFloat(min); return unscaled * amp + center + parseFloat(min);
} }
function syncDisplay(inst, name, val) {
let el = document.getElementById(`slider-${inst}-${name}`);
if (el)
el.value = val;
}
function parseLfoTime(lfoTime, bpm, beatsInMeasure){ // For now, we're only using sine interpolation
function operateNoise(center, inst, timeBaseStr, min, max, waveType, phaseArr, index, name, noiseData, currTime, beatsInMeasure, maxTicks){
let amp = parseFloat(max) - parseFloat(min);
let phaseType;
let timeBase;
let noiseType = noiseData.noiseTypeArr[index];
[timeBase, phaseType] = parseLfoTime(timeBaseStr, beatsInMeasure);
let phase;
if (phaseType === PhaseTypes.TIME)
phase = (currTime * timeBase + parseFloat(phaseArr[index])) % 1.00;
else if (phaseType === PhaseTypes.MUSICAL)
phase = (maxTicks % timeBase) / timeBase;
if (noiseData.cachedNoiseValueArr[index][0] == 0 || noiseData.lastPhaseArr[index] > phase){ // occurs if the phase reset to 0 or at the very start
noiseData.cachedNoiseValueArr[index][0] = noiseData.cachedNoiseValueArr[index][1];
if (noiseData.cachedNoiseValueArr[index][0] == 0)
noiseData.cachedNoiseValueArr[index][0] = center;
noiseData.cachedNoiseValueArr[index][1] = Math.random();
noiseData.setCachedNoiseValueArr(noiseData.cachedNoiseValueArr);
}
noiseData.lastPhaseArr[index] = phase;
noiseData.setLastPhaseArr(noiseData.lastPhaseArr);
let sinePhase = (Math.sin(Math.PI + Math.PI * phase) + 1) / 2
//let unscaled = (noiseData.cachedNoiseValueArr[index][1] - noiseData.cachedNoiseValueArr[index][0]) * sinePhase + noiseData.cachedNoiseValueArr[index][0];
let unscaled = interpolateNoise(noiseData.noiseTypeArr[index], noiseData.cachedNoiseValueArr[index][0], noiseData.cachedNoiseValueArr[index][1], phase);
syncDisplay(inst, name, unscaled);
return unscaled * amp + center + parseFloat(min);
}
function interpolateNoise(type, cachedVal1, cachedVal2, phase){
let interpVal;
switch (type){
case "Sine Int.":
interpVal = (Math.sin(Math.PI + Math.PI * phase) + 1) / 2;
break;
case "Rand":
interpVal = 0;
break;
case "Line Int.":
interpVal = phase;
break;
}
return (cachedVal2 - cachedVal1) * interpVal + cachedVal1;
}
// actual returns the period for musical timing, to avoid floating point errors
function parseLfoTime(lfoTime, beatsInMeasure){
if (lfoTime.slice(-2) == "hz"){ if (lfoTime.slice(-2) == "hz"){
return parseFloat(lfoTime.slice(0, -2)); return [parseFloat(lfoTime.slice(0, -2)), PhaseTypes.TIME];
} }
else if (lfoTime.slice(-2) == "ms"){ else if (lfoTime.slice(-2) == "ms"){
return 1000 / parseFloat(lfoTime.slice(0, -2)); return [1000 / parseFloat(lfoTime.slice(0, -2)), PhaseTypes.TIME];
} }
else if (lfoTime.slice(-1) == "s"){ else if (lfoTime.slice(-1) == "s"){
return 1 / parseFloat(lfoTime.slice(0, -1)); return [1 / parseFloat(lfoTime.slice(0, -1)), PhaseTypes.TIME];
} }
else if ((lfoTime.match(/:/g) || []).length == 2){ else if ((lfoTime.match(/:/g) || []).length == 2){
return 1 / moment.duration(lfoTime).asSeconds(); return [1 / moment.duration(lfoTime).asSeconds(), PhaseTypes.TIME];
} }
else if ((lfoTime.match(/\./g) || []).length == 2){ else if ((lfoTime.match(/\./g) || []).length == 2){
return musicalTimingToFreq(...lfoTime.split('.'), bpm, beatsInMeasure) return [musicalTimingToFreq(...lfoTime.split('.'), beatsInMeasure), PhaseTypes.MUSICAL];
} }
else { else {
return 0; return [0, PhaseTypes.TIME];
} }
} }
function musicalTimingToFreq(bars, beats, ticks, bpm, beatsInMeasure){ function musicalTimingToFreq(bars, beats, ticks, beatsInMeasure){
let totalTicks = (parseFloat(bars) * parseFloat(beatsInMeasure) + beats) * 480 + parseFloat(ticks); let totalTicks = (parseFloat(bars) * parseFloat(beatsInMeasure) + parseFloat(beats)) * 480 + parseFloat(ticks);
let tpm = bpm * 480; return totalTicks;
let cyclesPerMinute = tpm / totalTicks;
let hz = cyclesPerMinute / 60;
return hz;
} }