ableton-js 3.2.5 → 3.2.7

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,24 @@ 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
+ #### [v3.2.7](https://github.com/leolabs/ableton.js/compare/v3.2.6...v3.2.7)
8
+
9
+ - :white_check_mark: Switch from Jest to Vitest for faster testing [`d2af8b7`](https://github.com/leolabs/ableton.js/commit/d2af8b756ff9dfe2d76927d2695fba55226ab480)
10
+ - :mute: Don't log the result of setting the client port [`2206ab7`](https://github.com/leolabs/ableton.js/commit/2206ab74afc9d2388059d88a863dc8e5eed5a32f)
11
+ - :sparkles: When client is already starting or started, return a promise that waits for a connection [`97c2e1a`](https://github.com/leolabs/ableton.js/commit/97c2e1a81cbe3e8e7ee2f8ef7d349903b728e67e)
12
+
13
+ #### [v3.2.6](https://github.com/leolabs/ableton.js/compare/v3.2.5...v3.2.6)
14
+
15
+ > 5 July 2023
16
+
17
+ - :bug: Fix Live 11.3.3 hanging in some scenarios [`f3933b1`](https://github.com/leolabs/ableton.js/commit/f3933b1b714d1d87a1e4952bc142d017d513242b)
18
+ - :mute: Make logging less noisy when the heartbeat to Live fails [`2f46968`](https://github.com/leolabs/ableton.js/commit/2f46968db10ce82288fb221d5c6e22e5fb0c6972)
19
+ - :loud_sound: Truncate arguments in the error message when a command times out [`8bd0a9c`](https://github.com/leolabs/ableton.js/commit/8bd0a9cd7f1b4864e163fd22d87997f0d1c3dc30)
20
+
7
21
  #### [v3.2.5](https://github.com/leolabs/ableton.js/compare/v3.2.4...v3.2.5)
8
22
 
23
+ > 27 June 2023
24
+
9
25
  - :label: Add missing types for color_index props [`23e0edb`](https://github.com/leolabs/ableton.js/commit/23e0edb13e2972264b8748afa2bcb31a94d47348)
10
26
 
11
27
  #### [v3.2.4](https://github.com/leolabs/ableton.js/compare/v3.2.3...v3.2.4)
package/index.d.ts CHANGED
@@ -118,7 +118,7 @@ export declare class Ableton extends EventEmitter implements ConnectionEventEmit
118
118
  * If set, the function will throw an error if it can't establish a connection
119
119
  * in the given time. Should be higher than 2000ms to avoid false positives.
120
120
  */
121
- start(timeoutMs?: number): Promise<void>;
121
+ start(timeoutMs?: number): Promise<unknown>;
122
122
  /** Closes the client */
123
123
  close(): Promise<void>;
124
124
  /**
package/index.js CHANGED
@@ -7,6 +7,7 @@ exports.getPackageVersion = exports.Ableton = exports.TimeoutError = void 0;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const dgram_1 = __importDefault(require("dgram"));
10
+ const lodash_1 = require("lodash");
10
11
  const events_1 = require("events");
11
12
  const uuid_1 = require("uuid");
12
13
  const semver_1 = __importDefault(require("semver"));
@@ -106,7 +107,7 @@ class Ableton extends events_1.EventEmitter {
106
107
  async start(timeoutMs) {
107
108
  if (this.clientState !== "closed") {
108
109
  this.logger?.warn("Tried calling start, but client is already " + this.clientState);
109
- return;
110
+ return this.waitForConnection();
110
111
  }
111
112
  this.clientState = "starting";
112
113
  this.client = dgram_1.default.createSocket({ type: "udp4" });
@@ -114,23 +115,10 @@ class Ableton extends events_1.EventEmitter {
114
115
  this.client.addListener("listening", async () => {
115
116
  const port = this.client?.address().port;
116
117
  this.logger?.info("Client is bound and listening", { port });
117
- // Write used port to a file so Live can read from it
118
+ // Write used port to a file so Live can read from it on startup
118
119
  await (0, promises_1.writeFile)(this.clientPortFile, String(port));
119
120
  });
120
- try {
121
- // Try binding to the port that was used last for better start performance
122
- this.logger?.info("Checking if a stored port exists", {
123
- file: this.clientPortFile,
124
- });
125
- const clientPort = await (0, promises_1.readFile)(this.clientPortFile);
126
- const port = Number(clientPort.toString());
127
- this.logger?.info("Trying to bind to the most recent port", { port });
128
- this.client.bind(port, "127.0.0.1");
129
- }
130
- catch (error) {
131
- this.logger?.info("Couldn't bind to last port, binding to any free port instead", { error });
132
- this.client.bind(undefined, "127.0.0.1");
133
- }
121
+ this.client.bind(undefined, "127.0.0.1");
134
122
  // Wait for the server port file to exist
135
123
  await new Promise(async (res) => {
136
124
  try {
@@ -139,7 +127,9 @@ class Ableton extends events_1.EventEmitter {
139
127
  this.logger?.info("Server port:", { port: this.serverPort });
140
128
  res();
141
129
  }
142
- catch (e) { }
130
+ catch (e) {
131
+ this.logger?.info("Server doesn't seem to be online yet, waiting for it to go online...");
132
+ }
143
133
  // Set up a watcher in case the server port changes
144
134
  (0, fs_1.watchFile)(this.serverPortFile, async (curr) => {
145
135
  if (curr.isFile()) {
@@ -153,6 +143,15 @@ class Ableton extends events_1.EventEmitter {
153
143
  }
154
144
  });
155
145
  });
146
+ // Send used port to Live in case the plugin is already started
147
+ try {
148
+ const port = this.client.address().port;
149
+ this.logger?.info("Sending port to Live:", { port });
150
+ await this.setProp("internal", "", "client_port", port);
151
+ }
152
+ catch (e) {
153
+ this.logger?.info("Live doesn't seem to be loaded yet, waiting...");
154
+ }
156
155
  this.logger?.info("Checking connection...");
157
156
  const connection = this.waitForConnection();
158
157
  if (timeoutMs) {
@@ -178,9 +177,9 @@ class Ableton extends events_1.EventEmitter {
178
177
  this.handleConnect("heartbeat");
179
178
  }
180
179
  catch (e) {
181
- this.logger?.warn("Heartbeat failed:", { error: e, canceled });
182
180
  // If the heartbeat has been canceled, don't emit a disconnect event
183
- if (!canceled) {
181
+ if (!canceled && this._isConnected) {
182
+ this.logger?.warn("Heartbeat failed:", { error: e, canceled });
184
183
  this.handleDisconnect("heartbeat");
185
184
  }
186
185
  }
@@ -296,7 +295,7 @@ class Ableton extends events_1.EventEmitter {
296
295
  const msg = JSON.stringify(payload);
297
296
  const timeout = this.options?.commandTimeoutMs ?? 2000;
298
297
  const timeoutId = setTimeout(() => {
299
- const arg = JSON.stringify(command.args);
298
+ const arg = (0, lodash_1.truncate)(JSON.stringify(command.args), { length: 100 });
300
299
  const cls = command.nsid
301
300
  ? `${command.ns}(${command.nsid})`
302
301
  : command.ns;
@@ -15,3 +15,7 @@ class Internal(Interface):
15
15
 
16
16
  def get_version(self, ns):
17
17
  return version
18
+
19
+ def set_client_port(self, nsid, port):
20
+ self.socket.set_client_port(port)
21
+ return True
@@ -19,8 +19,8 @@ def split_by_n(seq, n):
19
19
  server_port_file = "ableton-js-server.port"
20
20
  client_port_file = "ableton-js-client.port"
21
21
 
22
- client_port_path = os.path.join(tempfile.gettempdir(), client_port_file)
23
22
  server_port_path = os.path.join(tempfile.gettempdir(), server_port_file)
23
+ client_port_path = os.path.join(tempfile.gettempdir(), client_port_file)
24
24
 
25
25
 
26
26
  class Socket(object):
@@ -37,22 +37,22 @@ class Socket(object):
37
37
  self.input_handler = handler
38
38
  self._server_addr = ("127.0.0.1", 0)
39
39
  self._client_addr = ("127.0.0.1", 39031)
40
- self._port_file_last_modified = 0
41
40
  self._last_error = ""
42
41
  self._socket = None
43
42
 
44
43
  self.read_remote_port()
45
44
  self.init_socket(True)
46
45
 
47
- self.file_timer = Live.Base.Timer(callback=self.read_remote_port,
48
- interval=1000, repeat=True)
49
- self.file_timer.start()
50
-
51
46
  def log_once(self, msg):
52
47
  if self._last_error != msg:
53
48
  self._last_error = msg
54
49
  self.log_message(msg)
55
50
 
51
+ def set_client_port(self, port):
52
+ self.log_message("Setting client port: ", str(port))
53
+ self.show_message("Client connected on port " + str(port))
54
+ self._client_addr = ("127.0.0.1", int(port))
55
+
56
56
  def read_last_server_port(self):
57
57
  try:
58
58
  with open(server_port_path) as file:
@@ -69,16 +69,7 @@ class Socket(object):
69
69
  '''Reads the port our client is listening on'''
70
70
 
71
71
  try:
72
- file = os.stat(client_port_path)
73
-
74
- print("Client port file modified: " + str(file.st_mtime) +
75
- " – last: " + str(self._port_file_last_modified))
76
-
77
- if file.st_mtime > self._port_file_last_modified:
78
- self._port_file_last_modified = file.st_mtime
79
- else:
80
- # If the file hasn't changed, don't try to open it
81
- return
72
+ os.stat(client_port_path)
82
73
  except Exception as e:
83
74
  self.log_once("Couldn't stat remote port file: " + str(e.args))
84
75
  return
@@ -101,7 +92,6 @@ class Socket(object):
101
92
 
102
93
  def shutdown(self):
103
94
  self.log_message("Shutting down...")
104
- self.file_timer.stop()
105
95
  self._socket.close()
106
96
 
107
97
  def init_socket(self, try_stored=False):
@@ -1 +1 @@
1
- version = "3.2.5"
1
+ version = "3.2.7"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ableton-js",
3
- "version": "3.2.5",
3
+ "version": "3.2.7",
4
4
  "description": "Control Ableton Live from Node",
5
5
  "main": "index.js",
6
6
  "author": "Leo Bernard <admin@leolabs.org>",
@@ -27,23 +27,20 @@
27
27
  "build:doc": "jsdoc2md --files src/**/*.ts --configure ./jsdoc2md.json > ./API.md",
28
28
  "version": "node hooks/prepublish.js && git add midi-script/version.py && auto-changelog -p -l 100 && git add CHANGELOG.md",
29
29
  "build": "tsc",
30
- "test": "jest --runInBand"
30
+ "test": "vitest --run --no-threads"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/jest": "^26.0.23",
34
33
  "@types/lodash": "^4.14.194",
35
34
  "@types/node": "^20.3.0",
36
35
  "@types/node-uuid": "^0.0.28",
37
36
  "@types/semver": "^7.3.6",
38
37
  "@types/uuid": "^8.3.0",
39
38
  "auto-changelog": "^2.3.0",
40
- "jest": "^27.0.3",
41
- "jest-extended": "^0.11.5",
42
39
  "lodash": "^4.17.21",
43
40
  "p-all": "^3",
44
- "ts-jest": "^29.1.0",
45
- "ts-node": "^10.9.1",
46
- "typescript": "^5.1.3"
41
+ "tsx": "^3.12.7",
42
+ "typescript": "^5.1.3",
43
+ "vitest": "^0.32.4"
47
44
  },
48
45
  "dependencies": {
49
46
  "lru-cache": "^7.14.0",
package/jest.config.js DELETED
@@ -1,7 +0,0 @@
1
- module.exports = {
2
- roots: ["<rootDir>/src"],
3
- transform: {
4
- "^.+\\.tsx?$": "ts-jest",
5
- },
6
- setupFilesAfterEnv: ["jest-extended"],
7
- };
@@ -1 +0,0 @@
1
- import "jest-extended";
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tests_1 = require("../util/tests");
4
- require("jest-extended");
5
- const gettableProps = [
6
- "browse_mode",
7
- "focused_document_view",
8
- ];
9
- describe("Application", () => {
10
- it("should be able to read all properties without erroring", async () => {
11
- await (0, tests_1.withAbleton)(async (ab) => {
12
- await Promise.all(gettableProps.map((p) => ab.application.view.get(p)));
13
- });
14
- });
15
- });
@@ -1 +0,0 @@
1
- import "jest-extended";
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tests_1 = require("../util/tests");
4
- require("jest-extended");
5
- const gettableProps = [
6
- "major_version",
7
- "minor_version",
8
- "bugfix_version",
9
- "version",
10
- "open_dialog_count",
11
- "current_dialog_message",
12
- "current_dialog_button_count",
13
- ];
14
- describe("Application", () => {
15
- it("should be able to read all properties without erroring", async () => {
16
- await (0, tests_1.withAbleton)(async (ab) => {
17
- await Promise.all(gettableProps.map((p) => ab.application.get(p)));
18
- });
19
- });
20
- });
@@ -1 +0,0 @@
1
- import "jest-extended";
@@ -1,26 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tests_1 = require("../util/tests");
4
- require("jest-extended");
5
- const gettableProps = [
6
- //"crossfade_assign", (not applicable to the master track)
7
- "crossfader",
8
- "cue_volume",
9
- "left_split_stereo",
10
- "panning",
11
- "panning_mode",
12
- "right_split_stereo",
13
- "sends",
14
- "song_tempo",
15
- "track_activator",
16
- "volume",
17
- ];
18
- describe("Mixer Device", () => {
19
- it("should be able to read all properties without erroring", async () => {
20
- await (0, tests_1.withAbleton)(async (ab) => {
21
- const masterTrack = await ab.song.get("master_track");
22
- const mixerDevice = await masterTrack.get("mixer_device");
23
- await Promise.all(gettableProps.map((p) => mixerDevice.get(p)));
24
- });
25
- });
26
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,20 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tests_1 = require("../util/tests");
4
- const gettableProps = [
5
- "detail_clip",
6
- "draw_mode",
7
- "follow_song",
8
- "highlighted_clip_slot",
9
- "selected_chain",
10
- "selected_parameter",
11
- "selected_scene",
12
- "selected_track",
13
- ];
14
- describe("Song View", () => {
15
- it("should be able to read all properties without erroring", async () => {
16
- await (0, tests_1.withAbleton)(async (ab) => {
17
- await Promise.all(gettableProps.map((p) => ab.song.view.get(p)));
18
- });
19
- });
20
- });
package/ns/song.spec.d.ts DELETED
@@ -1 +0,0 @@
1
- import "jest-extended";
package/ns/song.spec.js DELETED
@@ -1,79 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tests_1 = require("../util/tests");
4
- require("jest-extended");
5
- const gettableProps = [
6
- "arrangement_overdub",
7
- "back_to_arranger",
8
- "can_capture_midi",
9
- "can_jump_to_next_cue",
10
- "can_jump_to_prev_cue",
11
- "can_redo",
12
- "can_undo",
13
- "clip_trigger_quantization",
14
- "count_in_duration",
15
- "cue_points",
16
- "current_song_time",
17
- "exclusive_arm",
18
- "exclusive_solo",
19
- "groove_amount",
20
- "is_counting_in",
21
- "is_playing",
22
- "last_event_time",
23
- "loop",
24
- "loop_length",
25
- "loop_start",
26
- "master_track",
27
- "metronome",
28
- "midi_recording_quantization",
29
- "nudge_down",
30
- "nudge_up",
31
- "overdub",
32
- "punch_in",
33
- "punch_out",
34
- "re_enable_automation_enabled",
35
- "record_mode",
36
- "return_tracks",
37
- "root_note",
38
- "scale_name",
39
- "scenes",
40
- "select_on_launch",
41
- "session_automation_record",
42
- "session_record",
43
- "session_record_status",
44
- "signature_denominator",
45
- "signature_numerator",
46
- "song_length",
47
- "swing_amount",
48
- "tempo",
49
- "tracks",
50
- "visible_tracks",
51
- ];
52
- describe("Song", () => {
53
- it("should be able to read all properties without erroring", async () => {
54
- await (0, tests_1.withAbleton)(async (ab) => {
55
- await Promise.all(gettableProps.map((p) => ab.song.get(p)));
56
- });
57
- });
58
- it("should return the proper types for properties", async () => {
59
- await (0, tests_1.withAbleton)(async (ab) => {
60
- const songTime = await ab.song.get("current_song_time");
61
- expect(songTime).toBeNumber();
62
- const clipTriggerQuantization = await ab.song.get("clip_trigger_quantization");
63
- expect(clipTriggerQuantization).toBeString();
64
- const isPlaying = await ab.song.get("is_playing");
65
- expect(isPlaying).toBeBoolean();
66
- });
67
- });
68
- it("should be able to write and read large objects from the project", async () => {
69
- await (0, tests_1.withAbleton)(async (ab) => {
70
- const largeArray = [];
71
- for (let i = 0; i < 100000; i++) {
72
- largeArray.push(i);
73
- }
74
- await ab.song.setData("abletonjs_test", largeArray);
75
- const received = await ab.song.getData("abletonjs_test");
76
- expect(received).toEqual(largeArray);
77
- });
78
- });
79
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const package_version_1 = require("./package-version");
4
- const semver_1 = require("semver");
5
- describe("Package Version", () => {
6
- it("should get a valid package version without erroring", () => {
7
- const version = (0, package_version_1.getPackageVersion)();
8
- expect((0, semver_1.valid)(version)).toBeTruthy();
9
- });
10
- });