Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c531597a8a | ||
![]() |
7d984fdfa2 | ||
![]() |
d0cc7ce94e |
28
README.md
28
README.md
@ -1,24 +1,8 @@
|
||||
# healing-soundscapes
|
||||
# healing-soundscapes modulator branch
|
||||
|
||||
A repository of patches for the intelligent speaker system to be used in hospital waiting areas.
|
||||
The patches require the installation of [drawsocket](https://github.com/drawsocket) and [MaxScore](http://computermusicnotation.com)
|
||||
PLEASE DON'T USE THE PRESET OBJECT TO SAVE PRESETS! CLICK ON THE CIRCLES NUMBERED 1-5. MAKE SURE YOU CLICK ON THE EXACT CENTER
|
||||
YOU THEN CAN USE THE PRESET OBJECT TO LOAD PRESETS
|
||||
|
||||
<img width="1624" alt="image" src="https://github.com/HfMT-ZM4/healing-soundscapes/assets/17442406/0251cad9-4f36-44f2-9e85-ed5c2500f3e2">
|
||||
|
||||
## Installation:
|
||||
Note that this repo served on Gitea must be cloned with SSH rather than HTTPS. The SSH port is 2222
|
||||
|
||||
If you're not sure what this means, but you know how to use Github Desktop, you can follow the tutorial at
|
||||
|
||||
[Teams Tutorial](https://teams.microsoft.com/l/message/19:K8SFmqtgHNmETeFMqunIiUqPx8njA5GmyttI788pXrQ1@thread.tacv2/1722428967353?tenantId=6fe94159-f184-4738-8023-3e026978a06c&groupId=0f95cf31-fcc5-4226-a9bf-d80b1703871e&parentMessageId=1722428967353&teamName=Healing%20Soundscapes&channelName=General&createdTime=1722428967353)
|
||||
|
||||
|
||||
## Instructions:
|
||||
1. When running drawsocket the first time, install resources by clicking on script npm install **drawsocket**
|
||||
2. Start drawsocket server by clicking on **script start**
|
||||
3. Dump html page by clicking on the button in the upper left-hand corner
|
||||
4. Open the browser interface by clicking on **\[p browser\]** or navigating to the URL given in the Max window in an external web browser or device (add /1 after the URL, e.g. 192.168.178.2:3002/1)
|
||||
5. Open your soundbank or create one
|
||||
6. Set the virtual sound sources to the desired positions
|
||||
7. Create a number of presets for your piece after selecting DJster parameter settings and
|
||||
8. Save presets to disk
|
||||
Things not yet implemented:
|
||||
- Noise functions. I'm thinking of having random values, linear interpolated random values, sine interpolated random values, and perlin noise. I'm not going to start working on this until earliest October
|
||||
- The necessary interfacing allowing for training and control by the MLP. Similarly, this should wait until October or later.
|
||||
|
File diff suppressed because it is too large
Load Diff
28
lfogui.html
Normal file
28
lfogui.html
Normal file
@ -0,0 +1,28 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<!--
|
||||
We start with a basic html 'page' that is the size of the jweb object,
|
||||
but has no scrollbars nor floating content.
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="./modulators/lfogui.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="lfo-container"></div>
|
||||
<script src="./modulators/moment.js"></script>
|
||||
<script src="./modulators/react.js"></script>
|
||||
<script src="./modulators/react-dom.js"></script>
|
||||
<script src="./modulators/common.js"></script>
|
||||
<script src="./modulators/enums.js"></script>
|
||||
<script src="./modulators/modulators.js"></script>
|
||||
<script src="./modulators/lfogui.js">
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
62
modulators/common.js
Normal file
62
modulators/common.js
Normal file
@ -0,0 +1,62 @@
|
||||
function isNumeric(str) {
|
||||
if (typeof str != "string") return false // we only process strings!
|
||||
return !isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
|
||||
!isNaN(parseFloat(str)) // ...and ensure strings of whitespace fail
|
||||
}
|
||||
|
||||
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, step: props.step, value: props.value, className: props.className}, null);
|
||||
}
|
||||
|
||||
function TextBox(props){
|
||||
return e('input', {type: "text", value: props.value, onChange: props.onChange, id: props.id});
|
||||
}
|
||||
|
||||
function Option(str, value){
|
||||
return e("option", {value: value}, 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, postCB=() => {}, preCB=(val) => val){
|
||||
return (event) => {
|
||||
let newArr = arr.slice();
|
||||
newArr[index] = preCB(event.target.value);
|
||||
setArr(newArr);
|
||||
postCB();
|
||||
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}`);
|
||||
|
||||
}
|
||||
}
|
72
modulators/enums.js
Normal file
72
modulators/enums.js
Normal file
@ -0,0 +1,72 @@
|
||||
/////////////////////////
|
||||
// ENUMERATORS
|
||||
/////////////////////////
|
||||
|
||||
|
||||
|
||||
// NOT A REACT FUNCTIONAL COMPONENT. MERELY RETURNS AN ARRAY WHICH IS UNPACKED
|
||||
function EnumeratorItems(index, enumBreakPoints, setEnumBreakPoints, enumNames, setEnumNames, djParam){
|
||||
let items = [];
|
||||
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)));
|
||||
// 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 linkedText = props.linked ? "<- mods" : "";
|
||||
|
||||
let content = e('ul', {className: 'lfo-item', id: `${props.djParam}-enum-row`},
|
||||
ListItem(DropDown({onChange: props.setInstanceNum, value:props.instanceNum, options: INSTANCEOPTIONS})),
|
||||
ListItem(DropDown({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, {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)),
|
||||
ListItem(e(Button, {text:'+', onClick: props.addEnum}, null)),
|
||||
ListItem(e(Button, {text:'-', onClick: props.removeEnum}, null)),
|
||||
ListItem(e("div", {className:"linked"}, linkedText))
|
||||
);
|
||||
if (props.visible){
|
||||
return content;
|
||||
};
|
||||
}
|
||||
|
||||
function denumerate(inval, count, keys, vals){
|
||||
let output = inval;
|
||||
for (let i=0; i < count; i++){
|
||||
log(vals[i]);
|
||||
if (inval == vals[i]){
|
||||
output = (parseFloat(keys[i]) + parseFloat(keys[i+1])) / 2; // linear interpolate
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
|
||||
function enumerate(name, inst, inval, count, keys, vals){
|
||||
let output = "OUT OF RANGE";
|
||||
for (let i=0; i < count + 1; i++){
|
||||
if (inval <= keys[i]){
|
||||
if (i > 0)
|
||||
output = vals[i - 1];
|
||||
break
|
||||
}
|
||||
}
|
||||
let highlightedItem = document.getElementById(`text-${name}-${output}`);
|
||||
|
||||
if (highlightedItem){
|
||||
|
||||
highlightedItem.style.animation = "pulse-animation 0.5s normal";
|
||||
|
||||
highlightedItem.addEventListener('animationend', () => {
|
||||
highlightedItem.style.animation = "";
|
||||
});
|
||||
}
|
||||
|
||||
if (name !== "NONE")
|
||||
window.max.outlet(inst + " " + name + " " + output);
|
||||
}
|
||||
|
2680
modulators/example-with-dj.maxpat
Normal file
2680
modulators/example-with-dj.maxpat
Normal file
File diff suppressed because it is too large
Load Diff
1036
modulators/example.maxpat
Normal file
1036
modulators/example.maxpat
Normal file
File diff suppressed because it is too large
Load Diff
181
modulators/lfogui.css
Normal file
181
modulators/lfogui.css
Normal file
@ -0,0 +1,181 @@
|
||||
html,
|
||||
body {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
margin: 0px;
|
||||
border: 0;
|
||||
overflow: hidden; /* Disable scrollbars */
|
||||
display: block; /* No floating content on sides */
|
||||
}
|
||||
|
||||
ul {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
overflow: hidden;
|
||||
background-color: #333333;
|
||||
}
|
||||
|
||||
li {
|
||||
float: left;
|
||||
}
|
||||
|
||||
|
||||
input[type=number] {
|
||||
width: 50px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
input[type=text] {
|
||||
width: 60px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.timeInput {
|
||||
width: 80px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#matrix {
|
||||
background-color: aquamarine;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.numbox-unclicked {
|
||||
user-select: none;
|
||||
border: solid;
|
||||
font-size: 12vw;
|
||||
}
|
||||
|
||||
.numbox-clicked {
|
||||
user-select: none;
|
||||
border : solid;
|
||||
font-size: 12vw;
|
||||
}
|
||||
|
||||
.param-input-label {
|
||||
width: 93%;
|
||||
font-size: 5vw;
|
||||
}
|
||||
|
||||
.lfo-input-label {
|
||||
width: 40%;
|
||||
font-size: 5vw;
|
||||
}
|
||||
|
||||
/* The switch - the box around the slider */
|
||||
.switch {
|
||||
position: relative;
|
||||
display: inline-block;
|
||||
width: 30px;
|
||||
height: 17px;
|
||||
}
|
||||
|
||||
/* Hide default HTML checkbox */
|
||||
.switch input {
|
||||
opacity: 0;
|
||||
width: 0;
|
||||
height: 0;
|
||||
}
|
||||
|
||||
/* The slider */
|
||||
.slider {
|
||||
position: absolute;
|
||||
cursor: pointer;
|
||||
top: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
background-color: #ccc;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
|
||||
.slider:before {
|
||||
position: absolute;
|
||||
content: "";
|
||||
height: 13px;
|
||||
width: 13px;
|
||||
left: 2px;
|
||||
bottom: 2px;
|
||||
background-color: white;
|
||||
-webkit-transition: .4s;
|
||||
transition: .4s;
|
||||
}
|
||||
|
||||
input:checked + .slider {
|
||||
background-color: #2196F3;
|
||||
}
|
||||
|
||||
input:focus + .slider {
|
||||
box-shadow: 0 0 1px #2196F3;
|
||||
}
|
||||
|
||||
input:checked + .slider:before {
|
||||
-webkit-transform: translateX(13px);
|
||||
-ms-transform: translateX(13px);
|
||||
transform: translateX(13px);
|
||||
}
|
||||
|
||||
/* Rounded sliders */
|
||||
.slider.round {
|
||||
border-radius: 17px;
|
||||
}
|
||||
|
||||
.slider.round:before {
|
||||
border-radius: 50%;
|
||||
}
|
||||
|
||||
h5 {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.base-val {
|
||||
background-color: lightgray;
|
||||
border-color: #333333;
|
||||
border-width: 1px;
|
||||
width: 50px;
|
||||
margin-left: 2px;
|
||||
margin-top: 1px;
|
||||
}
|
||||
|
||||
.linked {
|
||||
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;
|
||||
}
|
29
modulators/lfogui.html
Normal file
29
modulators/lfogui.html
Normal file
@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
|
||||
<!--
|
||||
We start with a basic html 'page' that is the size of the jweb object,
|
||||
but has no scrollbars nor floating content.
|
||||
-->
|
||||
|
||||
<head>
|
||||
<link rel="stylesheet" href="./lfogui.css">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="lfo-container"></div>
|
||||
|
||||
<script src="./react.js"></script>
|
||||
<script src="./react-dom.js"></script>
|
||||
<script src="./moment.js"></script>
|
||||
<script src="./common.js"></script>
|
||||
<script src="./enums.js"></script>
|
||||
<script src="./modulators.js"></script>
|
||||
<script src="./lfogui.js">
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
461
modulators/lfogui.js
Normal file
461
modulators/lfogui.js
Normal file
@ -0,0 +1,461 @@
|
||||
// const { createElement } = require("./react");
|
||||
const DEBUG = false;
|
||||
var log;
|
||||
if (DEBUG)
|
||||
log = console.log;
|
||||
else
|
||||
log = (msg) => {window.max.outlet("debug " + msg)};
|
||||
|
||||
const e = React.createElement;
|
||||
|
||||
let lfos = [];
|
||||
const MAXLFOS = 20;
|
||||
const MAXENUMS = 20;
|
||||
const MAXENUMPOINTS = 10;
|
||||
|
||||
|
||||
|
||||
const ViewModes = Object.freeze({
|
||||
MOD: 0,
|
||||
ENUM: 1
|
||||
});
|
||||
|
||||
|
||||
var modPhases = Array(MAXLFOS).fill(0);
|
||||
var firstUpdateTime = Date.now();
|
||||
|
||||
const MODULATORLABELS = ["inst", "-type-", "---shape---", "-------param-------", "--timebase--", "-min-", "-max", "-phase-", "center"];
|
||||
const ENUMERATORLABELS = ["inst", "---parameter---", "-# points-"];
|
||||
|
||||
|
||||
|
||||
|
||||
function MasterLfoHandler(){
|
||||
|
||||
let initVisArr = Array(MAXLFOS).fill(false);
|
||||
initVisArr[0] = true;
|
||||
|
||||
const [viewMode, setViewMode] = React.useState(ViewModes.MOD);
|
||||
const toggleViewMode = () => {
|
||||
if (viewMode === ViewModes.MOD)
|
||||
setViewMode(ViewModes.ENUM);
|
||||
else
|
||||
setViewMode(ViewModes.MOD);
|
||||
};
|
||||
|
||||
/// MODULATOR ARRAYS
|
||||
|
||||
const [userDefinedWave, setUserDefinedWave] = React.useState(Array(50).fill(0));
|
||||
|
||||
const [modVisibleArr, setModVisibleArr] = React.useState(initVisArr);
|
||||
const [modInstanceNumArr, setModInstanceNumArr] = React.useState(Array(MAXLFOS).fill('1'));
|
||||
|
||||
const [modCenterVals, setModCenterVals] = React.useState({'1':{}, '2':{}, '3':{}, '4':{}});
|
||||
|
||||
const [ticks, setTicks] = React.useState(0);
|
||||
const [beatsInMeasure, setBeatsInMeasure] = React.useState(4);
|
||||
|
||||
const [shapeArr, setShapeArr] = React.useState(Array(MAXLFOS).fill('Sine'));
|
||||
const [djParamArr, setDjParamArr] = React.useState(Array(MAXLFOS).fill('NONE'));
|
||||
|
||||
const [freqArr, setFreqArr] = React.useState(Array(MAXLFOS).fill('1hz'));
|
||||
|
||||
// const [ampArr, setAmpArr] = React.useState(Array(MAXLFOS).fill('1'));
|
||||
const [minArr, setMinArr] = React.useState(Array(MAXLFOS).fill('0'));
|
||||
const [maxArr, setMaxArr] = React.useState(Array(MAXLFOS).fill('1'));
|
||||
|
||||
const [phaseArr, setPhaseArr] = React.useState(Array(MAXLFOS).fill('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'];
|
||||
|
||||
|
||||
/// ENUMERATOR ARRAYS
|
||||
const [enumVisibleArr, setEnumVisibleArr] = React.useState(initVisArr);
|
||||
const [enumInstanceNumArr, setEnumInstanceNumArr] = React.useState(Array(MAXLFOS).fill('1'));
|
||||
const [enumItemCounts, setEnumItemCounts] = React.useState(Array(MAXENUMPOINTS).fill('2'));
|
||||
const [enumDjParamArr, setEnumDjParamArr] = React.useState(Array(MAXENUMPOINTS).fill('attenuation'));
|
||||
|
||||
let baseEnumBreakpoints = Array(MAXENUMS).fill(0).map(x => Array(MAXENUMPOINTS+ 1).fill(0));
|
||||
for (let i = 0; i < MAXENUMS; i++){
|
||||
for (let j=0; j < MAXENUMPOINTS + 1; j++){
|
||||
baseEnumBreakpoints[i][j] = j;
|
||||
}
|
||||
}
|
||||
const [enumBreakPoints, setEnumBreakPoints] = React.useState(baseEnumBreakpoints);
|
||||
|
||||
const getBlankEnumBreakPointRow = () => {
|
||||
let arr = []
|
||||
for (let i=0; i< MAXENUMPOINTS + 1; i++)
|
||||
arr.push(i)
|
||||
return arr;
|
||||
}
|
||||
|
||||
const getBlankEnumNameRow = () => {return Array(MAXENUMPOINTS).fill('param')};
|
||||
|
||||
let baseEnumNames = Array(MAXENUMS).fill(0).map(x => Array(MAXENUMPOINTS).fill('param'));
|
||||
const [enumNames, setEnumNames] = React.useState(baseEnumNames);
|
||||
|
||||
const allEnumArrays = [enumVisibleArr, enumInstanceNumArr, enumItemCounts, enumDjParamArr];
|
||||
const allEnumArrSetters = [setEnumVisibleArr, setEnumInstanceNumArr, setEnumItemCounts, setEnumDjParamArr];
|
||||
|
||||
const allEnumMats = [enumBreakPoints, enumNames];
|
||||
const allEnumMatSetters = [setEnumBreakPoints, setEnumNames];
|
||||
const allGetEnumMatBlankVals = [getBlankEnumBreakPointRow, getBlankEnumNameRow]
|
||||
|
||||
const enumBlankVals = [true, '1', 2, MODPARAMOPTIONS[0]];
|
||||
|
||||
const [render, rerender] = React.useState(false); // BAD. I SHOULDN'T BE DOING THIS
|
||||
|
||||
|
||||
|
||||
React.useEffect(() => {
|
||||
function handleLoad(event) {
|
||||
|
||||
window.max.getDict(event.detail, (dict) => {
|
||||
|
||||
for (let i = 0; i<allModArrays.length; i++) {
|
||||
allModSetters[i](dict.data.modArrays[i]);
|
||||
}
|
||||
|
||||
for (let i = 0; i<allEnumArrays.length; i++) {
|
||||
allEnumArrSetters[i](dict.data.enumArrays[i]);
|
||||
}
|
||||
|
||||
for (let i = 0; i<allEnumMats.length; i++) {
|
||||
allEnumMatSetters[i](dict.data.enumMats[i]);
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handleSave(event) {
|
||||
let data = {
|
||||
'modArrays' : allModArrays,
|
||||
'enumArrays' : allEnumArrays,
|
||||
'enumMats' : allEnumMats
|
||||
}
|
||||
window.max.setDict(event.detail, {"data" : data});
|
||||
window.max.outlet("saved");
|
||||
}
|
||||
|
||||
|
||||
// only called internally by 1. Handler after modulator processing 2. LFO outputs
|
||||
function handleEnum(event){
|
||||
let inst = event.detail[0];
|
||||
let name = event.detail[1];
|
||||
let val = event.detail[2];
|
||||
|
||||
// if none of the Enums use this param, then we output it
|
||||
let i = 0;
|
||||
while (i < MAXENUMS){
|
||||
if (enumVisibleArr[i] && enumDjParamArr[i] == name && enumInstanceNumArr[i] == inst)
|
||||
break;
|
||||
i++
|
||||
}
|
||||
if (i == MAXENUMS){
|
||||
window.max.outlet(inst + ' ' + name + ' ' + val);
|
||||
}
|
||||
else {
|
||||
enumerate(name, inst, val, enumItemCounts[i], enumBreakPoints[i], enumNames[i]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
function handleParam(event) {
|
||||
let inst = event.detail[0]; // djster instance
|
||||
let name = event.detail[1];
|
||||
let val = event.detail[2];
|
||||
// CHECK FOR INDEX OF THIS NAME IN ENUM MATRIX, AND IF IT IS THERE DENUMERATE
|
||||
let index = -1;
|
||||
for (let i = 0; i < MAXENUMS; i++){
|
||||
if (enumDjParamArr[i] == name && enumInstanceNumArr[i] == inst)
|
||||
index = i;
|
||||
}
|
||||
if (index != -1){
|
||||
val = denumerate(val, enumItemCounts[index], enumBreakPoints[index], enumNames[index]);
|
||||
}
|
||||
|
||||
|
||||
// if none of the LFOs use this param, then we send it straight to the enum
|
||||
let i = 0;
|
||||
while (i < MAXLFOS){
|
||||
if (modVisibleArr[i] && djParamArr[i] == name && modInstanceNumArr[i] == inst)
|
||||
break;
|
||||
i++;
|
||||
}
|
||||
if (i == MAXLFOS){
|
||||
|
||||
window.dispatchEvent(new CustomEvent('enum', {'detail' : [inst, name, val]}));
|
||||
}
|
||||
|
||||
modCenterVals[inst][name] = val;
|
||||
setModCenterVals(modCenterVals);
|
||||
rerender(!render); // BAD! SHOULD NOT BE DOING THIS!
|
||||
|
||||
|
||||
}
|
||||
|
||||
function handleTick(event) {
|
||||
let time = (Date.now() - firstUpdateTime) / 1000;
|
||||
|
||||
operateModulators(modVisibleArr, modInstanceNumArr, djParamArr, modCenterVals, freqArr, minArr, maxArr, shapeArr, phaseArr, userDefinedWave, time, beatsInMeasure, ticks);
|
||||
}
|
||||
|
||||
function handleTimeSig(event) {
|
||||
setBeatsInMeasure(parseFloat(event.detail[0]) * parseFloat(event.detail[1])/ 4);
|
||||
}
|
||||
|
||||
function handleChangeUserWave(event){
|
||||
setUserDefinedWave(event.detail);
|
||||
}
|
||||
|
||||
function handleMaxTicks(event){
|
||||
setTicks(event.detail);
|
||||
}
|
||||
|
||||
|
||||
window.addEventListener('loadDict', handleLoad);
|
||||
window.addEventListener('saveDict', handleSave);
|
||||
window.addEventListener('tick', handleTick);
|
||||
window.addEventListener('param', handleParam);
|
||||
window.addEventListener('enum', handleEnum);
|
||||
window.addEventListener('timesig', handleTimeSig);
|
||||
window.addEventListener('userWave', handleChangeUserWave);
|
||||
window.addEventListener('maxTicks', handleMaxTicks);
|
||||
|
||||
return () => {
|
||||
window.removeEventListener('loadDict', handleLoad);
|
||||
window.removeEventListener('saveDict', handleSave);
|
||||
window.removeEventListener('tick', handleTick);
|
||||
window.removeEventListener('param', handleParam);
|
||||
window.removeEventListener('enum', handleEnum);
|
||||
window.removeEventListener('timesig', handleTimeSig);
|
||||
window.removeEventListener('userWave', handleChangeUserWave);
|
||||
window.removeEventListener('maxTicks', handleMaxTicks);
|
||||
};
|
||||
}, [...allModArrays, ...allEnumArrays, ...allEnumMats, modCenterVals, render, beatsInMeasure, ticks]);
|
||||
|
||||
|
||||
function CheckLinked(inst, param, checkInstArr, checkParamArr){
|
||||
for (let i = 0; i < checkInstArr.length; i++){
|
||||
if (checkInstArr[i] == inst && checkParamArr[i] == param)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
///////
|
||||
// Generate Modulators
|
||||
///////
|
||||
let modContents = []
|
||||
for (var i = 0; i<MAXLFOS; i++){
|
||||
let id = i;
|
||||
|
||||
modContents.push(
|
||||
|
||||
e(LfoRow, {
|
||||
instanceNum : modInstanceNumArr[i],
|
||||
setInstanceNum: CreateParamChanger(modInstanceNumArr, setModInstanceNumArr, i),
|
||||
shape: shapeArr[i],
|
||||
setShape: CreateParamChanger(shapeArr, setShapeArr, i),
|
||||
djParam: djParamArr[i],
|
||||
setDjParam: CreateParamChanger(djParamArr, setDjParamArr, i),
|
||||
centerVals: modCenterVals,
|
||||
|
||||
freq: freqArr[i],
|
||||
setFreq: CreateParamChanger(freqArr, setFreqArr, i),
|
||||
|
||||
//amp: ampArr[i],
|
||||
//setAmp: CreateParamChanger(ampArr, setAmpArr, i),
|
||||
|
||||
min: minArr[i],
|
||||
setMin : CreateParamChanger(minArr, setMinArr, i),
|
||||
max: maxArr[i],
|
||||
setMax: CreateParamChanger(maxArr, setMaxArr, i),
|
||||
|
||||
phase: phaseArr[i],
|
||||
setPhase: CreateParamChanger(phaseArr, setPhaseArr, i),
|
||||
visible: modVisibleArr[i],
|
||||
|
||||
linked: CheckLinked(modInstanceNumArr[i], djParamArr[i], enumInstanceNumArr, enumDjParamArr),
|
||||
addLfo: () => {
|
||||
if (id < MAXLFOS - 1){
|
||||
if (modVisibleArr[id + 1]){
|
||||
|
||||
let emptyIndex = modVisibleArr.findIndex((item) => !item);
|
||||
if (emptyIndex != -1){
|
||||
for (var j = 0; j < allModArrays.length; j++){
|
||||
let array = allModArrays[j];
|
||||
// remove from all arrays
|
||||
array.splice(emptyIndex, 1);
|
||||
// add empty item at opened index
|
||||
array.splice(id + 1, 0, modBlankVals[j]);
|
||||
allModSetters[j](array);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var j = 0; j < allModArrays.length; j++){ // no space below, easy.
|
||||
let array = allModArrays[j];
|
||||
array[id + 1] = modBlankVals[j];
|
||||
allModSetters[j](array);
|
||||
}
|
||||
}
|
||||
rerender(!render);
|
||||
}
|
||||
},
|
||||
removeLfo: () => {
|
||||
if (modVisibleArr.filter(x=>x).length > 1){
|
||||
let newArr = modVisibleArr.slice();
|
||||
newArr[id] = false;
|
||||
setModVisibleArr(newArr);
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
null));
|
||||
}
|
||||
|
||||
|
||||
///////
|
||||
// Generate Enumerators
|
||||
///////
|
||||
let enumContents = []
|
||||
for (var i = 0; i<MAXLFOS; i++){
|
||||
let id = i;
|
||||
enumContents.push(
|
||||
e(EnumeratorRow, {
|
||||
index: i,
|
||||
|
||||
instanceNum : enumInstanceNumArr[i],
|
||||
setInstanceNum: CreateParamChanger(enumInstanceNumArr, setEnumInstanceNumArr, i),
|
||||
enumItems: enumItemCounts[i],
|
||||
setEnumItemCounts: CreateParamChanger(enumItemCounts, setEnumItemCounts, i),
|
||||
enumBreakPoints: enumBreakPoints,
|
||||
setEnumBreakPoints: setEnumBreakPoints,
|
||||
enumNames: enumNames,
|
||||
setEnumNames: setEnumNames,
|
||||
visible: enumVisibleArr[i],
|
||||
djParam: enumDjParamArr[i],
|
||||
setDjParam: CreateParamChanger(enumDjParamArr, setEnumDjParamArr, i),
|
||||
linked: CheckLinked(enumInstanceNumArr[i], enumDjParamArr[i], modInstanceNumArr, djParamArr),
|
||||
addEnum: () => {
|
||||
if (id < MAXLFOS - 1){
|
||||
if (enumVisibleArr[id + 1]){ // if we need to open up space
|
||||
let emptyIndex = enumVisibleArr.findIndex((item) => !item);
|
||||
if (emptyIndex != -1){
|
||||
for (var j = 0; j < allEnumArrays.length; j++){
|
||||
let array = allEnumArrays[j];
|
||||
// remove from all arrays
|
||||
array.splice(emptyIndex, 1);
|
||||
// add empty item at opened index
|
||||
array.splice(id + 1, 0, enumBlankVals[j]);
|
||||
allEnumArrSetters[j](array);
|
||||
}
|
||||
|
||||
// Now do the same with matrices
|
||||
|
||||
for (var j = 0; j < allEnumMats.length; j++){
|
||||
let mat = allEnumMats[j];
|
||||
mat.splice(emptyIndex, 1);
|
||||
mat.splice(id + 1, 0, 0);
|
||||
mat[id + 1] = allGetEnumMatBlankVals[j]();
|
||||
allEnumMatSetters[j](mat);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (var j = 0; j < allEnumArrays.length; j++){
|
||||
let array = allEnumArrays[j];
|
||||
array[id+1] = enumBlankVals[j];
|
||||
allEnumArrSetters[j](array);
|
||||
}
|
||||
|
||||
// Now do the same with matrices
|
||||
|
||||
for (var j = 0; j < allEnumMats.length; j++){
|
||||
let mat = allEnumMats[j];
|
||||
mat[id + 1] = allGetEnumMatBlankVals[j]();
|
||||
allEnumMatSetters[j](mat);
|
||||
}
|
||||
}
|
||||
rerender(!render);
|
||||
}
|
||||
},
|
||||
removeEnum: () => {
|
||||
if (enumVisibleArr.filter(x=>x).length > 1){
|
||||
let newArr = enumVisibleArr.slice();
|
||||
newArr[id] = false;
|
||||
setEnumVisibleArr(newArr);
|
||||
}
|
||||
}
|
||||
}, null)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
var grid;
|
||||
var title;
|
||||
var labels;
|
||||
if (viewMode === ViewModes.MOD){
|
||||
grid = modContents;
|
||||
title = "MODULATORS";
|
||||
labels = MODULATORLABELS;
|
||||
}
|
||||
else {
|
||||
grid = enumContents;
|
||||
title = "ENUMERATORS";
|
||||
labels = ENUMERATORLABELS;
|
||||
}
|
||||
|
||||
return e('div', null,
|
||||
e(Switch, {ontoggle: toggleViewMode}, null),
|
||||
e('h5', null, title),
|
||||
e('ul', null, ...labels.map(x => ListItem(Label(x)))),
|
||||
e('div', {id: 'grid'}, ...grid)
|
||||
);
|
||||
}
|
||||
|
||||
if (!DEBUG){
|
||||
window.max.bindInlet("load", (dictId) => {
|
||||
window.dispatchEvent(new CustomEvent('loadDict', {'detail' : dictId}));
|
||||
});
|
||||
|
||||
window.max.bindInlet("save", (dictId) => {
|
||||
window.dispatchEvent(new CustomEvent('saveDict', {'detail' : dictId}));
|
||||
});
|
||||
|
||||
window.max.bindInlet("param", (inst, paramName, val) => {
|
||||
|
||||
window.dispatchEvent(new CustomEvent('param', {'detail' : [inst, paramName, val]}));
|
||||
});
|
||||
|
||||
window.max.bindInlet("timesig", (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.dispatchEvent(new CustomEvent('userWave', {'detail' : points}));
|
||||
});
|
||||
|
||||
|
||||
/* window.max.binInlet("userWave", (...points) => {
|
||||
window.dispatchEvent(new CustomEvent('userWave', {'detail' : [points]}));
|
||||
log("received user points");
|
||||
}); */
|
||||
|
||||
setInterval(() => {
|
||||
window.dispatchEvent(new CustomEvent('tick'));
|
||||
}, 200);
|
||||
}
|
||||
|
||||
|
||||
const root = ReactDOM.createRoot(document.getElementById('lfo-container'));
|
||||
root.render(e(MasterLfoHandler, null, null));
|
134
modulators/modulators.js
Normal file
134
modulators/modulators.js
Normal file
@ -0,0 +1,134 @@
|
||||
/////////////////////////
|
||||
// MODULATORS
|
||||
/////////////////////////
|
||||
|
||||
var SHAPETYPES = ["Sine", "SawUp", "SawDown", "Tri", "Square", "Custom"];
|
||||
|
||||
var INSTANCEOPTIONS = ["1", "2", "3", "4"];
|
||||
|
||||
const MODPARAMOPTIONS = ["NONE", "stream", "pulse_length", "eventfulness", "event_length", "metriclarity",
|
||||
"harmoniclarity", "melodic_cohesion", "melody_scope", "tonic_pitch", "pitch_center", "pitch_range", "dynamics",
|
||||
"attenuation", "chordal_weight", "tonality-profile", "ostinato-buffer", "ostinato", "meter", "scale"];
|
||||
|
||||
const PhaseTypes = Object.freeze({
|
||||
MUSICAL: Symbol("musical"),
|
||||
TIME: Symbol("time")
|
||||
});
|
||||
|
||||
function ControlType(){
|
||||
return e('select', {className: 'control-type'}, Option("LFO"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
function LfoRow(props){
|
||||
|
||||
let linkedText = props.linked ? "-> enums" : "";
|
||||
let center = props.centerVals[props.instanceNum][props.djParam];
|
||||
if (!center)
|
||||
center = 0;
|
||||
|
||||
let content = e('ul', {className: 'lfo-item'},
|
||||
ListItem(DropDown({onChange: props.setInstanceNum, value:props.instanceNum, options: INSTANCEOPTIONS})),
|
||||
ListItem(ControlType()),
|
||||
ListItem(DropDown({onChange: props.setShape, value:props.shape, options: SHAPETYPES})),
|
||||
ListItem(DropDown({onChange: props.setDjParam, value: props.djParam, options: MODPARAMOPTIONS})),
|
||||
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.setMax, value:props.max, step:0.1}, null)),
|
||||
//ListItem(e(NumberBox, {onChange:props.setAmp, value:props.amp, 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("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.removeLfo}, null)),
|
||||
ListItem(e("div", {className:"linked"}, linkedText)),
|
||||
);
|
||||
if (props.visible){
|
||||
return content
|
||||
};
|
||||
}
|
||||
|
||||
function indexWave(type, phase, userDefinedWave){
|
||||
switch (type){
|
||||
case "Sine":
|
||||
return (Math.sin(phase * Math.PI * 2) / 2) + 0.5;
|
||||
case "SawUp":
|
||||
return phase;
|
||||
case "SawDown":
|
||||
return 1 - phase;
|
||||
case "Tri":
|
||||
return phase > 0.5? (1-phase) * 2 : phase * 2;
|
||||
case "Square":
|
||||
return +(phase > 0.5);
|
||||
case "Custom":
|
||||
return parseFloat(userDefinedWave[Math.floor(phase * 50)]) / 127
|
||||
}
|
||||
}
|
||||
|
||||
function operateModulators(visibleArr, instanceNumArr, paramNames, centers, freqs, mins, maxs, waveTypes, phaseArr, userDefinedWave, currTime, beatsInMeasure, ticks){
|
||||
for (let i=0; i<paramNames.length; i++){
|
||||
if (visibleArr[i]){
|
||||
|
||||
let name = paramNames[i];
|
||||
let inst = instanceNumArr[i];
|
||||
let center = 0;
|
||||
if (centers[inst].hasOwnProperty(name)){
|
||||
center = centers[inst][name];
|
||||
}
|
||||
let output = operateModulator(center, inst, freqs[i], mins[i], maxs[i], waveTypes[i], phaseArr, i, userDefinedWave, name, currTime, beatsInMeasure, ticks);
|
||||
if (name !== "NONE")
|
||||
window.dispatchEvent(new CustomEvent('enum', {'detail' : [inst, name, output]}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function operateModulator(center, inst, timeBaseStr, min, max, waveType, phaseArr, phaseI, userDefinedWave, name, currTime, beatsInMeasure, maxTicks){
|
||||
|
||||
let amp = parseFloat(max) - parseFloat(min);
|
||||
let phaseType;
|
||||
let timeBase;
|
||||
|
||||
[timeBase, phaseType] = parseLfoTime(timeBaseStr, beatsInMeasure);
|
||||
let phase;
|
||||
|
||||
if (phaseType === PhaseTypes.TIME)
|
||||
phase = (currTime * timeBase + parseFloat(phaseArr[phaseI])) % 1.00;
|
||||
else if (phaseType === PhaseTypes.MUSICAL)
|
||||
phase = (maxTicks % timeBase) / timeBase;
|
||||
let unscaled = indexWave(waveType, phase, userDefinedWave);
|
||||
let el = document.getElementById(`slider-${inst}-${name}`);
|
||||
|
||||
if (el)
|
||||
el.value = unscaled;
|
||||
|
||||
return unscaled * amp + center + parseFloat(min);
|
||||
}
|
||||
|
||||
// actual returns the period for musical timing, to avoid floating point errors
|
||||
function parseLfoTime(lfoTime, beatsInMeasure){
|
||||
if (lfoTime.slice(-2) == "hz"){
|
||||
return [parseFloat(lfoTime.slice(0, -2)), PhaseTypes.TIME];
|
||||
}
|
||||
else if (lfoTime.slice(-2) == "ms"){
|
||||
return [1000 / parseFloat(lfoTime.slice(0, -2)), PhaseTypes.TIME];
|
||||
}
|
||||
else if (lfoTime.slice(-1) == "s"){
|
||||
return [1 / parseFloat(lfoTime.slice(0, -1)), PhaseTypes.TIME];
|
||||
}
|
||||
else if ((lfoTime.match(/:/g) || []).length == 2){
|
||||
return [1 / moment.duration(lfoTime).asSeconds(), PhaseTypes.TIME];
|
||||
}
|
||||
else if ((lfoTime.match(/\./g) || []).length == 2){
|
||||
return [musicalTimingToFreq(...lfoTime.split('.'), beatsInMeasure), PhaseTypes.MUSICAL];
|
||||
}
|
||||
else {
|
||||
return [0, PhaseTypes.TIME];
|
||||
}
|
||||
}
|
||||
|
||||
function musicalTimingToFreq(bars, beats, ticks, beatsInMeasure){
|
||||
let totalTicks = (parseFloat(bars) * parseFloat(beatsInMeasure) + parseFloat(beats)) * 480 + parseFloat(ticks);
|
||||
return totalTicks;
|
||||
}
|
||||
|
2
modulators/moment.js
Normal file
2
modulators/moment.js
Normal file
File diff suppressed because one or more lines are too long
29924
modulators/react-dom.js
vendored
Normal file
29924
modulators/react-dom.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
3343
modulators/react.js
vendored
Normal file
3343
modulators/react.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user