ableton-js 2.5.3 → 2.6.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,23 @@ 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.6.0](https://github.com/leolabs/ableton.js/compare/v2.5.4...v2.6.0)
8
+
9
+ - :sparkles: Make IDs stable over the lifespan of Live [`0bfcf90`](https://github.com/leolabs/ableton.js/commit/0bfcf904b54d42377877a2e9fab0796986f6aa1a)
10
+ - :sparkles: Add create_track methods [`a7dd6bc`](https://github.com/leolabs/ableton.js/commit/a7dd6bc53e2f49fb133b2eea2a1fe6eb1ff0aac6)
11
+
12
+ #### [v2.5.4](https://github.com/leolabs/ableton.js/compare/v2.5.3...v2.5.4)
13
+
14
+ > 19 October 2022
15
+
16
+ - :sparkles: Restart the socket when a message can't be sent due to a socket error [`91294c3`](https://github.com/leolabs/ableton.js/commit/91294c3cf195afacd22cbf1863e244bc231c9a33)
17
+ - :sparkles: Send the UUID back with the error if a requested namespace handler doesn't exist [`8a96a99`](https://github.com/leolabs/ableton.js/commit/8a96a996b8b65c8485d90ac98293ccd605497784)
18
+ - :memo: Add an example for setting a value [`f334983`](https://github.com/leolabs/ableton.js/commit/f334983a8755eab8415383aae7aff1ecff6e23e2)
19
+
7
20
  #### [v2.5.3](https://github.com/leolabs/ableton.js/compare/v2.5.2...v2.5.3)
8
21
 
22
+ > 30 August 2022
23
+
9
24
  - :memo: Fix some typos in the readme [`10c8566`](https://github.com/leolabs/ableton.js/commit/10c8566758bc1a7e7ab6bc20fa269d38474e1d96)
10
25
  - :sparkles: Add support for observing the `muted` prop of clips [`ecb604a`](https://github.com/leolabs/ableton.js/commit/ecb604a2b25aa3a064ffe5d199d44cfca0c12144)
11
26
 
package/README.md CHANGED
@@ -51,11 +51,16 @@ import { Ableton } from "ableton-js";
51
51
  const ableton = new Ableton();
52
52
 
53
53
  const test = async () => {
54
+ // Observe the current playback state and tempo
54
55
  ableton.song.addListener("is_playing", (p) => console.log("Playing:", p));
55
56
  ableton.song.addListener("tempo", (t) => console.log("Tempo:", t));
56
57
 
58
+ // Get the current tempo
57
59
  const tempo = await ableton.song.get("tempo");
58
60
  console.log(tempo);
61
+
62
+ // Set the tempo
63
+ await ableton.song.set("tempo", 85);
59
64
  };
60
65
 
61
66
  test();
package/index.d.ts CHANGED
@@ -7,7 +7,7 @@ import { Midi } from "./ns/midi";
7
7
  interface Command {
8
8
  uuid: string;
9
9
  ns: string;
10
- nsid?: number;
10
+ nsid?: string;
11
11
  name: string;
12
12
  args?: {
13
13
  [k: string]: any;
@@ -61,11 +61,11 @@ export declare class Ableton extends EventEmitter implements ConnectionEventEmit
61
61
  * Sends a raw command to Ableton. Usually, you won't need this.
62
62
  * A good starting point in general is the `song` prop.
63
63
  */
64
- sendCommand(ns: string, nsid: number | undefined, name: string, args?: Record<string, any> | any[], timeout?: number): Promise<any>;
65
- getProp(ns: string, nsid: number | undefined, prop: string): Promise<any>;
66
- setProp(ns: string, nsid: number | undefined, prop: string, value: any): Promise<any>;
67
- addPropListener(ns: string, nsid: number | undefined, prop: string, listener: (data: any) => any): Promise<() => Promise<boolean | undefined>>;
68
- removePropListener(ns: string, nsid: number | undefined, prop: string, eventId: string, listener: (data: any) => any): Promise<boolean | undefined>;
64
+ sendCommand(ns: string, nsid: string | undefined, name: string, args?: Record<string, any> | any[], timeout?: number): Promise<any>;
65
+ getProp(ns: string, nsid: string | undefined, prop: string): Promise<any>;
66
+ setProp(ns: string, nsid: string | undefined, prop: string, value: any): Promise<any>;
67
+ addPropListener(ns: string, nsid: string | undefined, prop: string, listener: (data: any) => any): Promise<() => Promise<boolean | undefined>>;
68
+ removePropListener(ns: string, nsid: string | undefined, prop: string, eventId: string, listener: (data: any) => any): Promise<boolean | undefined>;
69
69
  /**
70
70
  * Removes all event listeners that were attached to properties.
71
71
  * This is useful for clearing all listeners when Live
@@ -54,9 +54,11 @@ class AbletonJS(ControlSurface):
54
54
  script_handle = self._c_instance.handle()
55
55
  for midi in self.tracked_midi:
56
56
  if midi[0] == "cc":
57
- Live.MidiMap.forward_midi_cc(script_handle, midi_map_handle, midi[1], midi[2])
57
+ Live.MidiMap.forward_midi_cc(
58
+ script_handle, midi_map_handle, midi[1], midi[2])
58
59
  elif midi[0] == "note":
59
- Live.MidiMap.forward_midi_note(script_handle, midi_map_handle, midi[1], midi[2])
60
+ Live.MidiMap.forward_midi_note(
61
+ script_handle, midi_map_handle, midi[1], midi[2])
60
62
 
61
63
  def receive_midi(self, midi_bytes):
62
64
  self.handlers["midi"].send_midi(midi_bytes)
@@ -77,4 +79,5 @@ class AbletonJS(ControlSurface):
77
79
  handler = self.handlers[namespace]
78
80
  handler.handle(payload)
79
81
  else:
80
- self.socket.send("error", "No handler for NS " + str(namespace))
82
+ self.socket.send("error", "No handler for namespace " +
83
+ str(namespace), payload["uuid"])
@@ -4,7 +4,11 @@ class Interface(object):
4
4
 
5
5
  @staticmethod
6
6
  def save_obj(obj):
7
- obj_id = id(obj)
7
+ try:
8
+ obj_id = "live_" + str(obj._live_ptr)
9
+ except:
10
+ obj_id = "id_" + str(id(obj))
11
+
8
12
  Interface.obj_ids[obj_id] = obj
9
13
  return obj_id
10
14
 
@@ -10,4 +10,4 @@ class Internal(Interface):
10
10
  return self
11
11
 
12
12
  def get_version(self, ns):
13
- return "2.5.3"
13
+ return "2.6.0"
@@ -24,16 +24,20 @@ class Socket(object):
24
24
 
25
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
+ self._local_addr = (localhost, localport)
28
+ self._remote_addr = (remotehost, remoteport)
29
+ self.init_socket()
27
30
 
31
+ def init_socket(self):
28
32
  self._socket = socket.socket(
29
33
  socket.AF_INET, socket.SOCK_DGRAM)
30
34
  self._socket.setblocking(0)
31
35
 
32
- self._local_addr = (localhost, localport)
33
- self._remote_addr = (remotehost, remoteport)
34
-
35
36
  self.bind()
36
37
 
38
+ def shutdown(self):
39
+ self._socket.close()
40
+
37
41
  def bind(self):
38
42
  try:
39
43
  self._socket.bind(self._local_addr)
@@ -70,15 +74,14 @@ class Socket(object):
70
74
  try:
71
75
  self._sendto(json.dumps(
72
76
  {"event": name, "data": obj, "uuid": uuid}, default=jsonReplace, ensure_ascii=False))
77
+ except socket.error as e:
78
+ self.log_message("Socket error: " + str(e.args))
79
+ self.log_message("Restarting socket...")
80
+ self.shutdown()
81
+ self.init_socket()
73
82
  except Exception as e:
74
83
  error = str(type(e).__name__) + ': ' + str(e.args)
75
- self._sendto(json.dumps(
76
- {"event": "error", "data": error, "uuid": uuid}, default=jsonReplace, ensure_ascii=False))
77
- self.log_message("Socket Error " + name +
78
- "(" + str(uuid) + "): " + str(e))
79
-
80
- def shutdown(self):
81
- self._socket.close()
84
+ self.log_message("Error " + name + "(" + str(uuid) + "): " + error)
82
85
 
83
86
  def process(self):
84
87
  try:
@@ -91,12 +94,9 @@ class Socket(object):
91
94
  num_messages += 1
92
95
 
93
96
  # \xFF for Live 10 (Python2) and 255 for Live 11 (Python3)
94
- if(data[0] == b'\xFF' or data[0] == 255):
97
+ if (data[0] == b'\xFF' or data[0] == 255):
95
98
  unzipped = zlib.decompress(buffer)
96
99
  payload = json.loads(unzipped)
97
-
98
- self.log_message(
99
- "Receiving from " + str(num_messages) + " messages, " + str(len(buffer)) + " bytes: " + str(payload))
100
100
  self.input_handler(payload)
101
101
  buffer = bytes()
102
102
  num_messages = 0
@@ -8,9 +8,19 @@ from .Track import Track
8
8
  class Song(Interface):
9
9
  def __init__(self, c_instance, socket):
10
10
  super(Song, self).__init__(c_instance, socket)
11
+ self.song = self.ableton.song()
11
12
 
12
13
  def get_ns(self, nsid):
13
- return self.ableton.song()
14
+ return self.song
15
+
16
+ def create_audio_track(self, ns, index):
17
+ return Track.serialize_track(ns.create_audio_track(index))
18
+
19
+ def create_midi_track(self, ns, index):
20
+ return Track.serialize_track(ns.create_midi_track(index))
21
+
22
+ def create_return_track(self, ns):
23
+ return Track.serialize_track(ns.create_return_track())
14
24
 
15
25
  def get_clip_trigger_quantization(self, ns):
16
26
  return str(ns.clip_trigger_quantization)
@@ -26,7 +26,6 @@ class Track(Interface):
26
26
  def get_clip_slots(self, ns):
27
27
  return list(map(ClipSlot.serialize_clip_slot, ns.clip_slots))
28
28
 
29
-
30
29
  def get_group_track(self, ns):
31
30
  return Track.serialize_track(ns.group_track)
32
31
 
package/ns/clip-slot.d.ts CHANGED
@@ -39,7 +39,7 @@ export interface ObservableProperties {
39
39
  playing_status: PlayingStatus;
40
40
  }
41
41
  export interface RawClipSlot {
42
- id: number;
42
+ id: string;
43
43
  color: number;
44
44
  has_clip: boolean;
45
45
  is_playing: boolean;
package/ns/clip.d.ts CHANGED
@@ -128,7 +128,7 @@ export interface ObservableProperties {
128
128
  warping: boolean;
129
129
  }
130
130
  export interface RawClip {
131
- id: number;
131
+ id: string;
132
132
  name: string;
133
133
  color: number;
134
134
  is_audio_clip: boolean;
package/ns/cue-point.d.ts CHANGED
@@ -13,7 +13,7 @@ export interface ObservableProperties {
13
13
  time: number;
14
14
  }
15
15
  export interface RawCuePoint {
16
- id: number;
16
+ id: string;
17
17
  name: string;
18
18
  time: number;
19
19
  }
@@ -25,7 +25,7 @@ export interface ObservableProperties {
25
25
  value: number;
26
26
  }
27
27
  export interface RawDeviceParameter {
28
- id: number;
28
+ id: string;
29
29
  name: string;
30
30
  value: number;
31
31
  is_quantized: boolean;
package/ns/device.d.ts CHANGED
@@ -24,7 +24,7 @@ export interface ObservableProperties {
24
24
  parameters: string;
25
25
  }
26
26
  export interface RawDevice {
27
- id: number;
27
+ id: string;
28
28
  name: string;
29
29
  type: DeviceType;
30
30
  class_name: string;
package/ns/index.d.ts CHANGED
@@ -2,8 +2,8 @@ import { Ableton } from "..";
2
2
  export declare class Namespace<GP, TP, SP, OP> {
3
3
  protected ableton: Ableton;
4
4
  protected ns: string;
5
- protected nsid?: number | undefined;
6
- constructor(ableton: Ableton, ns: string, nsid?: number | undefined);
5
+ protected nsid?: string | undefined;
6
+ constructor(ableton: Ableton, ns: string, nsid?: string | undefined);
7
7
  protected transformers: Partial<{
8
8
  [T in Extract<keyof GP, keyof TP>]: (val: GP[T]) => TP[T];
9
9
  }>;
package/ns/scene.d.ts CHANGED
@@ -29,7 +29,7 @@ export interface ObservableProperties {
29
29
  }
30
30
  export interface RawScene {
31
31
  color: number;
32
- id: number;
32
+ id: string;
33
33
  name: string;
34
34
  }
35
35
  export declare class Scene extends Namespace<GettableProperties, TransformedProperties, SettableProperties, ObservableProperties> {
package/ns/track.d.ts CHANGED
@@ -111,7 +111,7 @@ export interface ObservableProperties {
111
111
  solo: boolean;
112
112
  }
113
113
  export interface RawTrack {
114
- id: number;
114
+ id: string;
115
115
  name: string;
116
116
  color: number;
117
117
  is_foldable: boolean;
package/ns/track.js CHANGED
@@ -41,7 +41,7 @@ var Track = /** @class */ (function (_super) {
41
41
  Track.prototype.duplicateClipToArrangement = function (clipID, time) {
42
42
  return this.sendCommand("duplicate_clip_to_arrangement", {
43
43
  clip_id: clipID,
44
- time: time
44
+ time: time,
45
45
  });
46
46
  };
47
47
  return Track;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ableton-js",
3
- "version": "2.5.3",
3
+ "version": "2.6.0",
4
4
  "description": "Control Ableton Live from Node",
5
5
  "main": "index.js",
6
6
  "author": "Leo Bernard <admin@leolabs.org>",