-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconstruct.js
More file actions
111 lines (84 loc) · 3.01 KB
/
Copy pathconstruct.js
File metadata and controls
111 lines (84 loc) · 3.01 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const maxApi = require('max-api');
const { makeMelody } = require('./makeMelody');
const { noteNamesFromLiveFormat } = require('./noteNamesFromLiveFormat');
const { getNotes } = require('./getNotes');
const { getClip } = require('./getClip');
const { rhythmAlgos } = require('./rhythmAlgos');
const { pitchAlgos } = require('./pitchAlgos');
const { bothAlgos } = require('./bothAlgos');
const getPattern = async () => {
const parsed = await getNotes('stepsLive');
const clipData = getClip(parsed);
if (clipData) {
const { pattern, subdiv } = clipData;
maxApi.outlet(`pattern ${pattern}`);
maxApi.outlet(`subdiv ${subdiv}`);
}
};
const getPitches = async () => {
const parsed = await getNotes('stepsLive');
const clipData = getClip(parsed);
if (clipData) {
const { noteNames } = clipData;
maxApi.outlet(`noteNames ${noteNames}`);
}
};
const makeClip = async () => {
const full = await maxApi.getDict('full');
const midiSteps = makeMelody(full);
const { liveFormat, totalDuration } = midiSteps;
const names = noteNamesFromLiveFormat(liveFormat);
await Promise.all([
maxApi.setDict('noteNames', {
notes: names,
}),
maxApi.setDict('stepsClip', {
notes: liveFormat,
totalDuration,
}),
]);
maxApi.outlet('make');
};
const generateRhythm = async () => {
const full = await maxApi.getDict('full');
const { rhythmAlgoInt } = full;
maxApi.outlet(`pattern ${rhythmAlgos[rhythmAlgoInt].algo(full)}`);
maxApi.outlet(`gatedBang`);
};
const patternDescription = async () => {
const full = await maxApi.getDict('full');
const { rhythmAlgoInt } = full;
maxApi.outlet(`description ${rhythmAlgos[rhythmAlgoInt].description}`);
};
const generatePitch = async () => {
const full = await maxApi.getDict('full');
const { pitchAlgoInt } = full;
maxApi.outlet(`noteNames ${pitchAlgos[pitchAlgoInt].algo(full)}`);
maxApi.outlet(`gatedBang`);
};
const pitchDescription = async () => {
const full = await maxApi.getDict('full');
const { pitchAlgoInt } = full;
maxApi.outlet(`description ${pitchAlgos[pitchAlgoInt].description}`);
};
const generateBoth = async () => {
const full = await maxApi.getDict('full');
const { bothAlgoInt } = full;
maxApi.outlet(`noteNames ${bothAlgos[bothAlgoInt].algo(full).notes}`);
maxApi.outlet(`pattern ${bothAlgos[bothAlgoInt].algo(full).pattern}`);
maxApi.outlet(`gatedBang`);
};
const bothDescription = async () => {
const full = await maxApi.getDict('full');
const { bothAlgoInt } = full;
maxApi.outlet(`description ${bothAlgos[bothAlgoInt].description}`);
};
maxApi.addHandler('makeClip', makeClip);
maxApi.addHandler('getPattern', getPattern);
maxApi.addHandler('getPitches', getPitches);
maxApi.addHandler('generateRhythm', generateRhythm);
maxApi.addHandler('generatePitch', generatePitch);
maxApi.addHandler('patternDescription', patternDescription);
maxApi.addHandler('pitchDescription', pitchDescription);
maxApi.addHandler('generateBoth', generateBoth);
maxApi.addHandler('bothDescription', bothDescription);