phase control

This commit is contained in:
Kieran McAuliffe 2024-07-22 16:03:47 +02:00
parent b82b278727
commit 6e1da9fb59
5 changed files with 71 additions and 71 deletions

View File

@ -16,7 +16,7 @@ function NumberBox(props){
}
function TextBox(props){
return e('input', {type: "text", value: props.value, onChange: props.onChange});
return e('input', {type: "text", value: props.value, onChange: props.onChange, id: props.id});
}
function Option(str, value){
@ -33,12 +33,12 @@ function Switch(props){
e('span', {className: 'slider round'}, null))
}
function CreateParamChanger(arr, setArr, index){
function CreateParamChanger(arr, setArr, index, cb=() => {}){
return (event) => {
let newArr = arr.slice();
newArr[index] = event.target.value;
setArr(newArr);
cb();
log(`${index} ${event.target.value}`);
}
}

View File

@ -52,6 +52,6 @@ function enumerate(name, inval, count, keys, vals){
}
//window.max.outlet(name + " " + output);
window.max.outlet(name + " " + output);
}

View File

@ -39,15 +39,63 @@
"subpatcher_template" : "",
"assistshowspatchername" : 0,
"boxes" : [ {
"box" : {
"id" : "obj-28",
"linecount" : 2,
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 493.0, 444.0, 161.0, 35.0 ],
"text" : "\"harmoniclarity 0.572005391276114\""
}
}
, {
"box" : {
"id" : "obj-19",
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 541.52631402015686, 69.0, 150.0, 20.0 ],
"text" : "self explanatory"
}
}
, {
"box" : {
"id" : "obj-14",
"linecount" : 3,
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 817.0, 45.0, 150.0, 47.0 ],
"text" : "self explanatory. Warning-will overwrite whatever is saved."
}
}
, {
"box" : {
"id" : "obj-11",
"linecount" : 4,
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 1054.0, 325.0, 150.0, 60.0 ],
"text" : "You can use the `phase` control to phase offset two LFOs of the same frequency"
}
}
, {
"box" : {
"id" : "obj-7",
"linecount" : 3,
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 89.0, 227.0, 197.0, 47.0 ],
"patching_rect" : [ 109.0, 285.0, 197.0, 47.0 ],
"presentation_linecount" : 3,
"text" : "This parameter is defined in the modulators, and when sent will act as the center value for that LFO"
"text" : "This parameter is defined in the enumerators but not the modulators"
}
}
@ -58,7 +106,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 126.0, 276.0, 94.0, 22.0 ],
"patching_rect" : [ 146.0, 334.0, 94.0, 22.0 ],
"text" : "param scale 1.6"
}
@ -94,7 +142,7 @@
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 126.0, 135.0, 197.0, 47.0 ],
"patching_rect" : [ 115.0, 201.0, 197.0, 47.0 ],
"text" : "This parameter is defined in the modulators, and when sent will act as the center value for that LFO"
}
@ -118,22 +166,10 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 146.0, 193.0, 121.0, 22.0 ],
"patching_rect" : [ 135.0, 259.0, 121.0, 22.0 ],
"text" : "param metriclarity 40"
}
}
, {
"box" : {
"id" : "obj-17",
"linecount" : 2,
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 734.0, 39.0, 150.0, 33.0 ],
"text" : "question for Georg: what should `phase` do?"
}
}
, {
"box" : {
@ -165,7 +201,7 @@
"data" : {
"enumArrays" : [ [ 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "2", 2, 2, 2, "2", "2", "2", "2", "2", "2" ], [ "event_length", "meter", "stream", "scale", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation" ] ],
"enumMats" : [ [ [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ "0", "1", "2", 3, 4, 5, 6, 7, 8, 9, 10 ], [ "0", "1", "2", 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ], [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] ], [ [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "3 4", "7 8", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "0", "1", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "pentatonic", "major", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ], [ "param", "param", "param", "param", "param", "param", "param", "param", "param", "param" ] ] ],
"modArrays" : [ [ 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "Sine", "SawUp", "SawDown", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine" ], [ "metriclarity", "stream", "meter", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation" ], [ "1", "0.3", "0.1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "30", "2", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" ] ]
"modArrays" : [ [ 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ], [ "Sine", "SawUp", "SawDown", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine", "Sine" ], [ "metriclarity", "stream", "meter", "harmoniclarity", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation", "attenuation" ], [ "0.6", "0.3", "0.1", "0.6", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "30", "2", "2", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1", "1" ], [ "0", "0", "0", "0.5", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0", "0" ] ]
}
}
@ -175,7 +211,7 @@
"numinlets" : 2,
"numoutlets" : 4,
"outlettype" : [ "dictionary", "", "", "" ],
"patching_rect" : [ 548.0, 604.0, 159.0, 22.0 ],
"patching_rect" : [ 22.0, 102.0, 159.0, 22.0 ],
"saved_object_attributes" : {
"embed" : 1,
"parameter_enable" : 0,
@ -185,17 +221,6 @@
"text" : "dict localStorage @embed 1"
}
}
, {
"box" : {
"id" : "obj-10",
"maxclass" : "newobj",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 424.52631402015686, 484.473682403564453, 91.0, 22.0 ],
"text" : "print @popup 1"
}
}
, {
"box" : {
@ -228,7 +253,7 @@
"maxclass" : "comment",
"numinlets" : 1,
"numoutlets" : 0,
"patching_rect" : [ 557.0, 520.0, 150.0, 74.0 ],
"patching_rect" : [ 31.0, 18.0, 150.0, 74.0 ],
"text" : "Storage for the matrix. Unfortunately, jsweb dictionary handling isn't great, so we can't use it like a native dict object"
}
@ -244,18 +269,6 @@
"text" : "loadbang"
}
}
, {
"box" : {
"id" : "obj-14",
"maxclass" : "message",
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 623.789473533630371, 69.0, 39.0, 22.0 ],
"text" : "dump"
}
}
, {
"box" : {
@ -264,7 +277,7 @@
"numinlets" : 2,
"numoutlets" : 1,
"outlettype" : [ "" ],
"patching_rect" : [ 328.894735336303711, 69.0, 104.0, 22.0 ],
"patching_rect" : [ 700.894735336303711, 69.0, 104.0, 22.0 ],
"text" : "save localStorage"
}
@ -301,13 +314,6 @@
"source" : [ "obj-12", 0 ]
}
}
, {
"patchline" : {
"destination" : [ "obj-2", 0 ],
"source" : [ "obj-14", 0 ]
}
}
, {
"patchline" : {
@ -332,7 +338,7 @@
}
, {
"patchline" : {
"destination" : [ "obj-10", 0 ],
"destination" : [ "obj-28", 1 ],
"source" : [ "obj-2", 0 ]
}

View File

@ -23,10 +23,9 @@ const ViewModes = Object.freeze({
var modPhases = Array(MAXLFOS).fill(0);
var firstUpdateTime = Date.now();
var lastUpdateTime = Date.now();
const MODULATORLABELS = ["-type-", "---shape---", "----param----", "freq", "amp", "phase"];
const ENUMERATORLABELS = ["--parameter--", "-points-"];
const MODULATORLABELS = ["-type-", "---shape---", "-------param-------", "--freq--", "--amp--", "--phase--"];
const ENUMERATORLABELS = ["---parameter---", "-# points-"];
function MasterLfoHandler(){
@ -179,11 +178,8 @@ function MasterLfoHandler(){
}
function handleTick(event) {
let newTime = Date.now()
let delta = (newTime - lastUpdateTime) / 1000;
lastUpdateTime = newTime
operateModulators(modVisibleArr, djParamArr, modCenterVals, freqArr, ampArr, shapeArr, modPhases, delta);
let time = (Date.now() - firstUpdateTime) / 1000;
operateModulators(modVisibleArr, djParamArr, modCenterVals, freqArr, ampArr, shapeArr, phaseArr, time);
}

View File

@ -45,7 +45,7 @@ function indexWave(type, phase){
}
}
function operateModulators(visibleArr, paramNames, centers, freqs, amps, waveTypes, phaseArr, delta){
function operateModulators(visibleArr, paramNames, centers, freqs, amps, waveTypes, phaseArr, time){
for (let i=0; i<paramNames.length; i++){
if (visibleArr[i]){
let name = paramNames[i];
@ -53,22 +53,20 @@ function operateModulators(visibleArr, paramNames, centers, freqs, amps, waveTyp
if (centers.hasOwnProperty(name)){
center = centers[name];
}
let output = operateModulator(center, freqs[i], amps[i], waveTypes[i], phaseArr, i, delta, name);
let output = operateModulator(center, freqs[i], amps[i], waveTypes[i], phaseArr, i, name, time);
window.dispatchEvent(new CustomEvent('enum', {'detail' : [name, output]}));
}
}
}
function operateModulator(center, freq, amp, waveType, phaseArr, phaseI, delta, name){
function operateModulator(center, freq, amp, waveType, phaseArr, phaseI, name, time){
let oldPhase = phaseArr[phaseI];
let newPhase = (oldPhase + freq * delta) % 1.00;
let unscaled = indexWave(waveType, newPhase);
let phase = (time * freq + parseFloat(phaseArr[phaseI])) % 1.00;
let unscaled = indexWave(waveType, phase);
let el = document.getElementById(`slider-${name}`);
if (el)
el.value = unscaled;
phaseArr[phaseI] = newPhase;
return unscaled * amp + center;
}