-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmidiStepsToApi.js
More file actions
64 lines (55 loc) · 1.63 KB
/
Copy pathmidiStepsToApi.js
File metadata and controls
64 lines (55 loc) · 1.63 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
//gets dict whit the clip to pass
function getDict(dictName) {
var d = new Dict(dictName);
var notesObject = JSON.parse(d.stringify());
return notesObject;
}
//clears a clip passes the dict using Ableton Live 10 methods
function liveTen(clip, dict) {
var inner = dict.notes;
var end_time = clip.get('end_time');
clip.call('remove_notes', 0, 1, end_time, 127);
clip.call('set_notes');
clip.call('notes', inner.length);
for (var step = 0; step < inner.length; step++) {
clip.call(
'note',
inner[step].pitch,
inner[step].start_time.toFixed(6).toString(),
inner[step].duration.toFixed(6).toString(),
inner[step].velocity,
0
);
}
clip.call('done');
}
//clears a clip passes the dict using Ableton Live 11 methods
function liveEleven(clip, dict) {
var end_time = clip.get('end_time');
clip.call('remove_notes_extended', 1, 127, 0, end_time);
clip.call('add_new_notes', dict);
}
var clipToSelect = new LiveAPI();
//returns whats selected
function clipOrSlot() {
clipToSelect.path = 'live_set view detail_clip';
if (clipToSelect) {
return clipToSelect;
} else {
clipToSelect.path = 'live_set view highlighted_clip_slot clip';
return clipToSelect;
}
}
var liveVersion = new LiveAPI();
//passes notes down to the Live API based on the received name of a dict and active Live version
function setNotes(dictName) {
var clip = clipOrSlot();
var dict = getDict(dictName);
clip.set('loop_end', dict.totalDuration);
liveVersion.path = 'live_app';
if (liveVersion.call('get_major_version') === 10) {
liveTen(clip, dict);
} else {
liveEleven(clip, dict);
}
}