-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_python_model.js
51 lines (35 loc) · 1.32 KB
/
run_python_model.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const maxApi = require('max-api');
const {spawn} = require('child_process');
maxApi.addHandler('run_model', (...input) => {
maxApi.post("Received this "+input);
var scriptPath = 'melody_harmonizer.py';
const pythonExec = '/opt/homebrew/opt/[email protected]/bin/python3.11';
// var scriptPath = 'testing.py';
// const pyProg = spawn(pythonExec, [scriptPath,inputString]);
maxApi.post(typeof input);
var modelIn = input[0]; //"[[60,4],[60,4],[60,4]]";
var temperature = input[1];
var k_value = input[2];
maxApi.post("temp: "+temperature);
maxApi.post("k value: "+k_value);
maxApi.post(modelIn);
const pyProg = spawn(pythonExec, [scriptPath,"--daw",temperature, k_value, modelIn]);
// const pyProg = spawn(pythonExec, ['--version']);
// maxApi.post("val for slider ", tempSlider.getvalueof());
pyProg.stdout.on('data', function(data) {
// convert output back to javascript dictionary
maxApi.post("executed "+data);
data = JSON.parse(data)
data = JSON.stringify(data);
maxApi.post("output from python: \n"+data);
maxApi.outlet(data);
});
// maxApi.post("donez "+harmony);
//maxApi.oulet(harmony);
// maxApi.post("done "+data);
// from here: get output chords in form useful for creating new clips
// create new clips
pyProg.stderr.on('data', (data) => {
maxApi.post("error on script call "+data);
});
});