ableton-js 2.3.3 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,8 +4,30 @@ All notable changes to this project will be documented in this file. Dates are d
4
4
 
5
5
  Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
6
6
 
7
+ #### [v2.5.0](https://github.com/leolabs/ableton.js/compare/v2.4.0...v2.5.0)
8
+
9
+ - adds support for getting the group_track property from a Track object [`#46`](https://github.com/leolabs/ableton.js/pull/46)
10
+ - Forward requested midi cc and note messages [`#48`](https://github.com/leolabs/ableton.js/pull/48)
11
+ - add Track's `duplicate_clip_to_arrangement` method [`#49`](https://github.com/leolabs/ableton.js/pull/49)
12
+ - Create LICENSE [`3f42141`](https://github.com/leolabs/ableton.js/commit/3f42141f33fc5b13eea2c46675c72182ec691bfb)
13
+
14
+ #### [v2.4.0](https://github.com/leolabs/ableton.js/compare/v2.3.4...v2.4.0)
15
+
16
+ > 21 May 2022
17
+
18
+ - :wrench: Use ports 39031 and 39041 to avoid collisions with other applications [`e3bd84c`](https://github.com/leolabs/ableton.js/commit/e3bd84cadf92af5d648533fd656c90722f5d8ab2)
19
+ - :sparkles: Run the heartbeat check once after initializing the class [`8db0bd6`](https://github.com/leolabs/ableton.js/commit/8db0bd66f5dec534f38c1319cacd2cc91da89f6a)
20
+
21
+ #### [v2.3.4](https://github.com/leolabs/ableton.js/compare/v2.3.3...v2.3.4)
22
+
23
+ > 1 May 2022
24
+
25
+ - :sparkles: Return the start and end time of clips in the raw clip [`1862efe`](https://github.com/leolabs/ableton.js/commit/1862efe6c6e8bc4d894cdce9b376e1fde93c8c7b)
26
+
7
27
  #### [v2.3.3](https://github.com/leolabs/ableton.js/compare/v2.3.2...v2.3.3)
8
28
 
29
+ > 30 April 2022
30
+
9
31
  - :sparkles: Add set_or_delete_cue, undo, and redo commands [`41d5ef7`](https://github.com/leolabs/ableton.js/commit/41d5ef7a2461fea95b125de13e18285beb47a2d6)
10
32
 
11
33
  #### [v2.3.2](https://github.com/leolabs/ableton.js/compare/v2.3.1...v2.3.2)
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Leo Bernard
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.d.ts CHANGED
@@ -3,6 +3,7 @@ import { EventEmitter } from "events";
3
3
  import { Song } from "./ns/song";
4
4
  import { Internal } from "./ns/internal";
5
5
  import { Application } from "./ns/application";
6
+ import { Midi } from "./ns/midi";
6
7
  interface Command {
7
8
  uuid: string;
8
9
  ns: string;
@@ -45,6 +46,7 @@ export declare class Ableton extends EventEmitter implements ConnectionEventEmit
45
46
  song: Song;
46
47
  application: Application;
47
48
  internal: Internal;
49
+ midi: Midi;
48
50
  constructor(host?: string, sendPort?: number, listenPort?: number, heartbeatInterval?: number);
49
51
  close(): void;
50
52
  /**
package/index.js CHANGED
@@ -68,6 +68,7 @@ var zlib_1 = require("zlib");
68
68
  var song_1 = require("./ns/song");
69
69
  var internal_1 = require("./ns/internal");
70
70
  var application_1 = require("./ns/application");
71
+ var midi_1 = require("./ns/midi");
71
72
  var package_version_1 = require("./util/package-version");
72
73
  var TimeoutError = /** @class */ (function (_super) {
73
74
  __extends(TimeoutError, _super);
@@ -84,8 +85,8 @@ var Ableton = /** @class */ (function (_super) {
84
85
  __extends(Ableton, _super);
85
86
  function Ableton(host, sendPort, listenPort, heartbeatInterval) {
86
87
  if (host === void 0) { host = "127.0.0.1"; }
87
- if (sendPort === void 0) { sendPort = 9041; }
88
- if (listenPort === void 0) { listenPort = 9031; }
88
+ if (sendPort === void 0) { sendPort = 39041; }
89
+ if (listenPort === void 0) { listenPort = 39031; }
89
90
  if (heartbeatInterval === void 0) { heartbeatInterval = 2000; }
90
91
  var _this = _super.call(this) || this;
91
92
  _this.host = host;
@@ -100,10 +101,11 @@ var Ableton = /** @class */ (function (_super) {
100
101
  _this.song = new song_1.Song(_this);
101
102
  _this.application = new application_1.Application(_this);
102
103
  _this.internal = new internal_1.Internal(_this);
103
- _this.client = dgram_1.default.createSocket({ type: "udp4", reuseAddr: true });
104
+ _this.midi = new midi_1.Midi(_this);
105
+ _this.client = dgram_1.default.createSocket({ type: "udp4" });
104
106
  _this.client.bind(_this.listenPort, host);
105
107
  _this.client.addListener("message", _this.handleIncoming.bind(_this));
106
- _this.heartbeatInterval = setInterval(function () { return __awaiter(_this, void 0, void 0, function () {
108
+ var heartbeat = function () { return __awaiter(_this, void 0, void 0, function () {
107
109
  var e_1;
108
110
  return __generator(this, function (_a) {
109
111
  switch (_a.label) {
@@ -133,7 +135,9 @@ var Ableton = /** @class */ (function (_super) {
133
135
  case 4: return [2 /*return*/];
134
136
  }
135
137
  });
136
- }); }, heartbeatInterval);
138
+ }); };
139
+ _this.heartbeatInterval = setInterval(heartbeat, heartbeatInterval);
140
+ heartbeat();
137
141
  _this.internal
138
142
  .get("version")
139
143
  .then(function (v) {
@@ -14,6 +14,7 @@ from .Track import Track
14
14
  from .Internal import Internal
15
15
  from .ClipSlot import ClipSlot
16
16
  from .Clip import Clip
17
+ from .Midi import Midi
17
18
  from _Framework.ControlSurface import ControlSurface
18
19
  import Live
19
20
 
@@ -21,6 +22,7 @@ import Live
21
22
  class AbletonJS(ControlSurface):
22
23
  def __init__(self, c_instance):
23
24
  super(AbletonJS, self).__init__(c_instance)
25
+ self.tracked_midi = set()
24
26
 
25
27
  Socket.set_log(self.log_message)
26
28
  Socket.set_message(self.show_message)
@@ -37,7 +39,8 @@ class AbletonJS(ControlSurface):
37
39
  "song-view": SongView(c_instance, self.socket),
38
40
  "track": Track(c_instance, self.socket),
39
41
  "clip_slot": ClipSlot(c_instance, self.socket),
40
- "clip": Clip(c_instance, self.socket)
42
+ "clip": Clip(c_instance, self.socket),
43
+ "midi": Midi(c_instance, self.socket, self.tracked_midi, self.request_rebuild_midi_map)
41
44
  }
42
45
 
43
46
  self.recv_loop = Live.Base.Timer(
@@ -47,6 +50,17 @@ class AbletonJS(ControlSurface):
47
50
 
48
51
  self.socket.send("connect")
49
52
 
53
+ def build_midi_map(self, midi_map_handle):
54
+ script_handle = self._c_instance.handle()
55
+ for midi in self.tracked_midi:
56
+ if midi[0] == "cc":
57
+ Live.MidiMap.forward_midi_cc(script_handle, midi_map_handle, midi[1], midi[2])
58
+ elif midi[0] == "note":
59
+ Live.MidiMap.forward_midi_note(script_handle, midi_map_handle, midi[1], midi[2])
60
+
61
+ def receive_midi(self, midi_bytes):
62
+ self.handlers["midi"].send_midi(midi_bytes)
63
+
50
64
  def disconnect(self):
51
65
  self.log_message("Disconnecting")
52
66
  self.recv_loop.stop()
@@ -15,6 +15,8 @@ class Clip(Interface):
15
15
  "color": clip.color,
16
16
  "is_audio_clip": clip.is_audio_clip,
17
17
  "is_midi_clip": clip.is_midi_clip,
18
+ "start_time": clip.start_time,
19
+ "end_time": clip.end_time,
18
20
  }
19
21
 
20
22
  def __init__(self, c_instance, socket):
@@ -10,4 +10,4 @@ class Internal(Interface):
10
10
  return self
11
11
 
12
12
  def get_version(self, ns):
13
- return "2.3.3"
13
+ return "2.5.0"
@@ -0,0 +1,55 @@
1
+ from __future__ import absolute_import
2
+
3
+ from .Interface import Interface
4
+
5
+
6
+ class Midi(Interface):
7
+ event_id = None
8
+
9
+ def __init__(self, c_instance, socket, tracked_midi, update_midi_callback):
10
+ super(Midi, self).__init__(c_instance, socket)
11
+ self.outputs = set()
12
+ self.tracked_midi = tracked_midi
13
+ self.update_midi = update_midi_callback
14
+
15
+ def get_ns(self, nsid):
16
+ return self
17
+
18
+ def set_midi_outputs(self, ns, outputs):
19
+ self.outputs.clear()
20
+ for output in outputs:
21
+ try:
22
+ midi_type = output.get("type")
23
+ if midi_type != "cc" and midi_type != "note":
24
+ raise ValueError("invalid midi type " + str(midi_type))
25
+ self.outputs.add((midi_type, output.get("channel"), output.get("target")))
26
+ except ValueError as e:
27
+ self.log_message(e)
28
+ except:
29
+ self.log_message("invalid midi output requested: " + str(output))
30
+
31
+ def remove_midi_listener(self, fn):
32
+ self.event_id = None
33
+ self.tracked_midi.clear()
34
+ self.update_midi()
35
+
36
+ def add_listener(self, ns, prop, eventId, nsid="Default"):
37
+ if prop != "midi":
38
+ raise Exception("Listener " + str(prop) + " does not exist.")
39
+
40
+ if self.event_id is not None:
41
+ self.log_message("midi listener already exists")
42
+ return self.event_id
43
+
44
+ self.log_message("Attaching midi listener")
45
+
46
+ self.tracked_midi.clear()
47
+ self.tracked_midi.update(self.outputs)
48
+ self.update_midi()
49
+ self.event_id = eventId
50
+
51
+ return eventId
52
+
53
+ def send_midi(self, midi_bytes):
54
+ if self.event_id is not None:
55
+ self.socket.send(self.event_id, {"bytes": midi_bytes})
@@ -22,10 +22,11 @@ class Socket(object):
22
22
  def set_message(func):
23
23
  Socket.show_message = func
24
24
 
25
- def __init__(self, handler, remotehost='127.0.0.1', remoteport=9031, localhost='127.0.0.1', localport=9041):
25
+ def __init__(self, handler, remotehost='127.0.0.1', remoteport=39031, localhost='127.0.0.1', localport=39041):
26
26
  self.input_handler = handler
27
27
 
28
- self._socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
28
+ self._socket = socket.socket(
29
+ socket.AF_INET, socket.SOCK_DGRAM)
29
30
  self._socket.setblocking(0)
30
31
 
31
32
  self._local_addr = (localhost, localport)
@@ -25,3 +25,10 @@ class Track(Interface):
25
25
 
26
26
  def get_clip_slots(self, ns):
27
27
  return list(map(ClipSlot.serialize_clip_slot, ns.clip_slots))
28
+
29
+
30
+ def get_group_track(self, ns):
31
+ return Track.serialize_track(ns.group_track)
32
+
33
+ def duplicate_clip_to_arrangement(self, ns, clip_id, time):
34
+ return ns.duplicate_clip_to_arrangement(self.get_obj(clip_id), time)
package/ns/clip.d.ts CHANGED
@@ -132,6 +132,8 @@ export interface RawClip {
132
132
  color: number;
133
133
  is_audio_clip: boolean;
134
134
  is_midi_clip: boolean;
135
+ start_time: number;
136
+ end_time: number;
135
137
  }
136
138
  /**
137
139
  * This class represents an entry in Live's Session view matrix.
package/ns/midi.d.ts ADDED
@@ -0,0 +1,63 @@
1
+ import { Namespace } from "./index";
2
+ import { Ableton } from "../index";
3
+ export declare enum MidiCommand {
4
+ NoteOn = 128,
5
+ NoteOff = 144,
6
+ AfterTouch = 160,
7
+ ControlChange = 176,
8
+ PatchChange = 192,
9
+ ChannelPressure = 208,
10
+ PitchBend = 224,
11
+ SysExStart = 240,
12
+ MidiTimeCodeQuarterFrame = 241,
13
+ SongPositionPointer = 242,
14
+ SongSelect = 243,
15
+ TuneRequest = 246,
16
+ SysExEnd = 247,
17
+ TimingClock = 248,
18
+ Start = 250,
19
+ Continue = 251,
20
+ Stop = 252,
21
+ ActiveSensing = 254,
22
+ SystemReset = 255
23
+ }
24
+ export interface MidiMapping {
25
+ type: "cc" | "note";
26
+ channel: number;
27
+ target: number;
28
+ }
29
+ export interface MidiNote {
30
+ command: MidiCommand.NoteOn | MidiCommand.NoteOff;
31
+ key: number;
32
+ velocity: number;
33
+ }
34
+ export interface MidiCC {
35
+ command: MidiCommand.ControlChange;
36
+ controller: number;
37
+ value: number;
38
+ }
39
+ export declare class MidiMessage {
40
+ command: MidiCommand;
41
+ parameter1: number | null;
42
+ parameter2: number | null;
43
+ constructor(raw: RawMidiMessage);
44
+ toCC(): MidiCC;
45
+ toNote(): MidiNote;
46
+ }
47
+ export interface RawMidiMessage {
48
+ bytes: number[];
49
+ }
50
+ export interface GettableProperties {
51
+ }
52
+ export interface TransformedProperties {
53
+ midi: MidiMessage;
54
+ }
55
+ export interface SettableProperties {
56
+ midi_outputs: MidiMapping[];
57
+ }
58
+ export interface ObservableProperties {
59
+ midi: RawMidiMessage;
60
+ }
61
+ export declare class Midi extends Namespace<GettableProperties, TransformedProperties, SettableProperties, ObservableProperties> {
62
+ constructor(ableton: Ableton);
63
+ }
package/ns/midi.js ADDED
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Midi = exports.MidiMessage = exports.MidiCommand = void 0;
19
+ var index_1 = require("./index");
20
+ var MidiCommand;
21
+ (function (MidiCommand) {
22
+ MidiCommand[MidiCommand["NoteOn"] = 128] = "NoteOn";
23
+ MidiCommand[MidiCommand["NoteOff"] = 144] = "NoteOff";
24
+ MidiCommand[MidiCommand["AfterTouch"] = 160] = "AfterTouch";
25
+ MidiCommand[MidiCommand["ControlChange"] = 176] = "ControlChange";
26
+ MidiCommand[MidiCommand["PatchChange"] = 192] = "PatchChange";
27
+ MidiCommand[MidiCommand["ChannelPressure"] = 208] = "ChannelPressure";
28
+ MidiCommand[MidiCommand["PitchBend"] = 224] = "PitchBend";
29
+ MidiCommand[MidiCommand["SysExStart"] = 240] = "SysExStart";
30
+ MidiCommand[MidiCommand["MidiTimeCodeQuarterFrame"] = 241] = "MidiTimeCodeQuarterFrame";
31
+ MidiCommand[MidiCommand["SongPositionPointer"] = 242] = "SongPositionPointer";
32
+ MidiCommand[MidiCommand["SongSelect"] = 243] = "SongSelect";
33
+ MidiCommand[MidiCommand["TuneRequest"] = 246] = "TuneRequest";
34
+ MidiCommand[MidiCommand["SysExEnd"] = 247] = "SysExEnd";
35
+ MidiCommand[MidiCommand["TimingClock"] = 248] = "TimingClock";
36
+ MidiCommand[MidiCommand["Start"] = 250] = "Start";
37
+ MidiCommand[MidiCommand["Continue"] = 251] = "Continue";
38
+ MidiCommand[MidiCommand["Stop"] = 252] = "Stop";
39
+ MidiCommand[MidiCommand["ActiveSensing"] = 254] = "ActiveSensing";
40
+ MidiCommand[MidiCommand["SystemReset"] = 255] = "SystemReset";
41
+ })(MidiCommand = exports.MidiCommand || (exports.MidiCommand = {}));
42
+ var MidiMessage = /** @class */ (function () {
43
+ function MidiMessage(raw) {
44
+ this.parameter1 = null;
45
+ this.parameter2 = null;
46
+ switch (raw.bytes.length) {
47
+ case 0:
48
+ throw "bytes missing from midi message";
49
+ case 3:
50
+ this.parameter1 = raw.bytes[1];
51
+ this.parameter2 = raw.bytes[2];
52
+ break;
53
+ case 2:
54
+ this.parameter1 = raw.bytes[1];
55
+ break;
56
+ case 1:
57
+ break;
58
+ default:
59
+ throw "invalid midi message length: " + raw.bytes.length;
60
+ }
61
+ if (!(raw.bytes[0] in MidiCommand)) {
62
+ throw "invalid midi command: " + raw.bytes[0];
63
+ }
64
+ this.command = raw.bytes[0];
65
+ }
66
+ MidiMessage.prototype.toCC = function () {
67
+ if (this.command !== MidiCommand.ControlChange) {
68
+ throw "not a midi CC message";
69
+ }
70
+ return {
71
+ command: this.command,
72
+ controller: this.parameter1,
73
+ value: this.parameter2
74
+ };
75
+ };
76
+ MidiMessage.prototype.toNote = function () {
77
+ if (this.command !== MidiCommand.NoteOn && this.command !== MidiCommand.NoteOff) {
78
+ throw "not a midi note message";
79
+ }
80
+ return {
81
+ command: this.command,
82
+ key: this.parameter1,
83
+ velocity: this.parameter2
84
+ };
85
+ };
86
+ return MidiMessage;
87
+ }());
88
+ exports.MidiMessage = MidiMessage;
89
+ var Midi = /** @class */ (function (_super) {
90
+ __extends(Midi, _super);
91
+ function Midi(ableton) {
92
+ var _this = _super.call(this, ableton, "midi") || this;
93
+ _this.transformers = {
94
+ midi: function (msg) { return new MidiMessage(msg); }
95
+ };
96
+ return _this;
97
+ }
98
+ return Midi;
99
+ }(index_1.Namespace));
100
+ exports.Midi = Midi;
package/ns/track.d.ts CHANGED
@@ -120,4 +120,5 @@ export interface RawTrack {
120
120
  export declare class Track extends Namespace<GettableProperties, TransformedProperties, SettableProperties, ObservableProperties> {
121
121
  raw: RawTrack;
122
122
  constructor(ableton: Ableton, raw: RawTrack);
123
+ duplicateClipToArrangement(clipID: number, time: number): Promise<any>;
123
124
  }
package/ns/track.js CHANGED
@@ -38,6 +38,12 @@ var Track = /** @class */ (function (_super) {
38
38
  };
39
39
  return _this;
40
40
  }
41
+ Track.prototype.duplicateClipToArrangement = function (clipID, time) {
42
+ return this.sendCommand("duplicate_clip_to_arrangement", {
43
+ clip_id: clipID,
44
+ time: time
45
+ });
46
+ };
41
47
  return Track;
42
48
  }(_1.Namespace));
43
49
  exports.Track = Track;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ableton-js",
3
- "version": "2.3.3",
3
+ "version": "2.5.0",
4
4
  "description": "Control Ableton Live from Node",
5
5
  "main": "index.js",
6
6
  "author": "Leo Bernard <admin@leolabs.org>",