Created
October 7, 2018 08:24
-
-
Save zeffii/a6d535d6497015fbb64eb4a991b14ead to your computer and use it in GitHub Desktop.
max msp node.script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const maxApi = require("max-api"); | |
let x = 0; | |
let y = 0; | |
maxApi.addHandler("input", (dir) => { | |
switch (dir) { | |
case "UP": | |
y += 1; | |
break; | |
case "DOWN": | |
y -= 1; | |
break; | |
case "LEFT": | |
x += 1; | |
break; | |
case "RIGHT": | |
x -= 1; | |
} | |
maxApi.post(`x: ${x}, y: ${y}`); | |
maxApi.outlet(x, y); | |
}); |
further.. for later
const maxApi = require("max-api");
const fs = require('fs');
var filePath = "C:\\Users\\zeffi\\Desktop\\maxmsp_patches_SC\\drum_patterns.ptx";
// C:\\Users\\zeffi\\Desktop\\maxmsp_patches_SC\\noddemo_ptxreader.js
let mat = [];
let xdata = "";
let xmat = [];
function parse_ptx_data(xdata){
var xmat = [];
mat = xdata.split('\n');
for (matrix in mat) {
var items = mat[matrix].split(' ');
var item_list = [];
for (item in items) {
item_list.push(parseInt(items[item]));
}
if (mat[matrix]) {
xmat.push(item_list);
}
}
return xmat;
}
maxApi.post("happened");
maxApi.addHandler("input", (msg_type) => {
maxApi.post(msg_type);
if (msg_type === "LOAD_MATRIX") {
fs.readFile(filePath, {encoding: 'utf-8'}, (err, data) => {
if (!err) {
maxApi.post('received data: ' + data);
xdata = data;
maxApi.outlet(data);
} else {
maxApi.post(err);
}
});
} else if (msg_type === "PARSE") {
xmat = parse_ptx_data(xdata);
maxApi.post(xmat);
maxApi.outlet(xmat[0]);
}
});
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
reading/loading a file from disk using node's fs