ableton-js 3.1.4 → 3.1.5

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,16 @@ 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.1.5](https://github.com/leolabs/ableton.js/compare/v3.1.4...v3.1.5)
8
+
9
+ - :zap: Try binding to the last used port first to speed up the connection to Live [`b86bc5d`](https://github.com/leolabs/ableton.js/commit/b86bc5d2b2872b030978a87cc3b001e2e997722d)
10
+ - :memo: Add logging to the example code [`7b5dfbf`](https://github.com/leolabs/ableton.js/commit/7b5dfbf5beb8140588211a4b54c970e48f9980c9)
11
+ - :bug: Don't emit an error when a received message can't be assigned to any request [`3186bdb`](https://github.com/leolabs/ableton.js/commit/3186bdbdc6cb1190d9d2de1f29905fed6e5030dd)
12
+
7
13
  #### [v3.1.4](https://github.com/leolabs/ableton.js/compare/v3.1.3...v3.1.4)
8
14
 
15
+ > 27 February 2023
16
+
9
17
  - :loud_sound: Log the version of AbletonJS when it's loaded [`fae9799`](https://github.com/leolabs/ableton.js/commit/fae9799dc4650286ed0b9ebdce9a18b607643271)
10
18
  - :wrench: Bind server to 127.0.0.1 only [`bb73239`](https://github.com/leolabs/ableton.js/commit/bb73239c70ddcb881d6fd9b909bc7f74a49b81fb)
11
19
 
package/README.md CHANGED
@@ -48,7 +48,8 @@ Example:
48
48
  ```typescript
49
49
  import { Ableton } from "ableton-js";
50
50
 
51
- const ableton = new Ableton();
51
+ // Log all messages to the console
52
+ const ableton = new Ableton({ logger: console });
52
53
 
53
54
  const test = async () => {
54
55
  // Establishes a connection with Live
@@ -60,7 +61,7 @@ const test = async () => {
60
61
 
61
62
  // Get the current tempo
62
63
  const tempo = await ableton.song.get("tempo");
63
- console.log(tempo);
64
+ console.log("Current tempo:", tempo);
64
65
 
65
66
  // Set the tempo
66
67
  await ableton.song.set("tempo", 85);
package/index.js CHANGED
@@ -187,103 +187,122 @@ var Ableton = /** @class */ (function (_super) {
187
187
  * in the given time. Should be higher than 2000ms to avoid false positives.
188
188
  */
189
189
  Ableton.prototype.start = function (timeoutMs) {
190
- var _a, _b, _c, _d, _e;
190
+ var _a, _b, _c, _d, _e, _f, _g, _h;
191
191
  return __awaiter(this, void 0, void 0, function () {
192
- var connection, timeout, heartbeat;
192
+ var clientPort, port, error_1, connection, timeout, heartbeat;
193
193
  var _this = this;
194
- return __generator(this, function (_f) {
195
- switch (_f.label) {
194
+ return __generator(this, function (_j) {
195
+ switch (_j.label) {
196
196
  case 0:
197
197
  if (this.clientState !== "closed") {
198
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn("Tried call start, but client is already " + this.clientState);
198
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.warn("Tried calling start, but client is already " + this.clientState);
199
199
  return [2 /*return*/];
200
200
  }
201
201
  this.clientState = "starting";
202
202
  this.client = dgram_1.default.createSocket({ type: "udp4" });
203
203
  this.client.addListener("message", this.handleIncoming.bind(this));
204
204
  this.client.addListener("listening", function () { return __awaiter(_this, void 0, void 0, function () {
205
- var clientPort;
205
+ var port;
206
206
  var _a, _b;
207
207
  return __generator(this, function (_c) {
208
208
  switch (_c.label) {
209
209
  case 0:
210
- clientPort = (_a = this.client) === null || _a === void 0 ? void 0 : _a.address().port;
211
- (_b = this.logger) === null || _b === void 0 ? void 0 : _b.info("Bound client to port:", { clientPort: clientPort });
212
- // Write used port to a file to Live can read from it
213
- return [4 /*yield*/, promises_1.writeFile(this.clientPortFile, String(clientPort))];
210
+ port = (_a = this.client) === null || _a === void 0 ? void 0 : _a.address().port;
211
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.info("Client is bound and listening", { port: port });
212
+ // Write used port to a file so Live can read from it
213
+ return [4 /*yield*/, promises_1.writeFile(this.clientPortFile, String(port))];
214
214
  case 1:
215
- // Write used port to a file to Live can read from it
215
+ // Write used port to a file so Live can read from it
216
216
  _c.sent();
217
217
  return [2 /*return*/];
218
218
  }
219
219
  });
220
220
  }); });
221
- this.client.bind(undefined, "127.0.0.1");
222
- // Wait for the server port file to exist
223
- return [4 /*yield*/, new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
224
- var serverPort, e_1;
225
- var _this = this;
226
- var _a;
227
- return __generator(this, function (_b) {
228
- switch (_b.label) {
229
- case 0:
230
- _b.trys.push([0, 2, , 3]);
231
- return [4 /*yield*/, promises_1.readFile(this.serverPortFile)];
232
- case 1:
233
- serverPort = _b.sent();
234
- this.serverPort = Number(serverPort.toString());
235
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("Server port:", { port: this.serverPort });
236
- res();
237
- return [3 /*break*/, 3];
238
- case 2:
239
- e_1 = _b.sent();
240
- return [3 /*break*/, 3];
241
- case 3:
242
- // Set up a watcher in case the server port changes
243
- fs_1.watchFile(this.serverPortFile, function (curr) { return __awaiter(_this, void 0, void 0, function () {
244
- var serverPort, newPort;
245
- var _a;
246
- return __generator(this, function (_b) {
247
- switch (_b.label) {
248
- case 0:
249
- if (!curr.isFile()) return [3 /*break*/, 2];
250
- return [4 /*yield*/, promises_1.readFile(this.serverPortFile)];
251
- case 1:
252
- serverPort = _b.sent();
253
- newPort = Number(serverPort.toString());
254
- if (!isNaN(newPort) && newPort !== this.serverPort) {
255
- (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("Server port changed:", { port: newPort });
256
- this.serverPort = Number(serverPort.toString());
257
- }
258
- res();
259
- _b.label = 2;
260
- case 2: return [2 /*return*/];
261
- }
262
- });
263
- }); });
264
- return [2 /*return*/];
265
- }
266
- });
267
- }); })];
221
+ _j.label = 1;
268
222
  case 1:
223
+ _j.trys.push([1, 3, , 4]);
224
+ // Try binding to the port that was used last for better start performance
225
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.info("Checking if a stored port exists", {
226
+ file: this.clientPortFile,
227
+ });
228
+ return [4 /*yield*/, promises_1.readFile(this.clientPortFile)];
229
+ case 2:
230
+ clientPort = _j.sent();
231
+ port = Number(clientPort.toString());
232
+ (_c = this.logger) === null || _c === void 0 ? void 0 : _c.info("Trying to bind to the most recent port", { port: port });
233
+ this.client.bind(port, "127.0.0.1");
234
+ return [3 /*break*/, 4];
235
+ case 3:
236
+ error_1 = _j.sent();
237
+ (_d = this.logger) === null || _d === void 0 ? void 0 : _d.info("Couldn't bind to last port, binding to any free port instead", { error: error_1 });
238
+ this.client.bind(undefined, "127.0.0.1");
239
+ return [3 /*break*/, 4];
240
+ case 4:
241
+ // Wait for the server port file to exist
242
+ return [4 /*yield*/, new Promise(function (res) { return __awaiter(_this, void 0, void 0, function () {
243
+ var serverPort, e_1;
244
+ var _this = this;
245
+ var _a;
246
+ return __generator(this, function (_b) {
247
+ switch (_b.label) {
248
+ case 0:
249
+ _b.trys.push([0, 2, , 3]);
250
+ return [4 /*yield*/, promises_1.readFile(this.serverPortFile)];
251
+ case 1:
252
+ serverPort = _b.sent();
253
+ this.serverPort = Number(serverPort.toString());
254
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("Server port:", { port: this.serverPort });
255
+ res();
256
+ return [3 /*break*/, 3];
257
+ case 2:
258
+ e_1 = _b.sent();
259
+ return [3 /*break*/, 3];
260
+ case 3:
261
+ // Set up a watcher in case the server port changes
262
+ fs_1.watchFile(this.serverPortFile, function (curr) { return __awaiter(_this, void 0, void 0, function () {
263
+ var serverPort, newPort;
264
+ var _a;
265
+ return __generator(this, function (_b) {
266
+ switch (_b.label) {
267
+ case 0:
268
+ if (!curr.isFile()) return [3 /*break*/, 2];
269
+ return [4 /*yield*/, promises_1.readFile(this.serverPortFile)];
270
+ case 1:
271
+ serverPort = _b.sent();
272
+ newPort = Number(serverPort.toString());
273
+ if (!isNaN(newPort) && newPort !== this.serverPort) {
274
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("Server port changed:", { port: newPort });
275
+ this.serverPort = Number(serverPort.toString());
276
+ }
277
+ res();
278
+ _b.label = 2;
279
+ case 2: return [2 /*return*/];
280
+ }
281
+ });
282
+ }); });
283
+ return [2 /*return*/];
284
+ }
285
+ });
286
+ }); })];
287
+ case 5:
269
288
  // Wait for the server port file to exist
270
- _f.sent();
271
- (_b = this.logger) === null || _b === void 0 ? void 0 : _b.info("Checking connection...");
289
+ _j.sent();
290
+ (_e = this.logger) === null || _e === void 0 ? void 0 : _e.info("Checking connection...");
272
291
  connection = this.waitForConnection();
273
- if (!timeoutMs) return [3 /*break*/, 3];
292
+ if (!timeoutMs) return [3 /*break*/, 7];
274
293
  timeout = new Promise(function (_, rej) {
275
294
  return setTimeout(function () { return rej("Connection timed out."); }, timeoutMs);
276
295
  });
277
296
  return [4 /*yield*/, Promise.race([connection, timeout])];
278
- case 2:
279
- _f.sent();
280
- return [3 /*break*/, 5];
281
- case 3: return [4 /*yield*/, connection];
282
- case 4:
283
- _f.sent();
284
- _f.label = 5;
285
- case 5:
286
- (_c = this.logger) === null || _c === void 0 ? void 0 : _c.info("Got connection!");
297
+ case 6:
298
+ _j.sent();
299
+ return [3 /*break*/, 9];
300
+ case 7: return [4 /*yield*/, connection];
301
+ case 8:
302
+ _j.sent();
303
+ _j.label = 9;
304
+ case 9:
305
+ (_f = this.logger) === null || _f === void 0 ? void 0 : _f.info("Got connection!");
287
306
  this.clientState = "started";
288
307
  this.handleConnect("start");
289
308
  heartbeat = function () { return __awaiter(_this, void 0, void 0, function () {
@@ -310,7 +329,7 @@ var Ableton = /** @class */ (function (_super) {
310
329
  }
311
330
  });
312
331
  }); };
313
- this.heartbeatInterval = setInterval(heartbeat, (_e = (_d = this.options) === null || _d === void 0 ? void 0 : _d.heartbeatInterval) !== null && _e !== void 0 ? _e : 2000);
332
+ this.heartbeatInterval = setInterval(heartbeat, (_h = (_g = this.options) === null || _g === void 0 ? void 0 : _g.heartbeatInterval) !== null && _h !== void 0 ? _h : 2000);
314
333
  heartbeat();
315
334
  this.internal
316
335
  .get("version")
@@ -329,12 +348,14 @@ var Ableton = /** @class */ (function (_super) {
329
348
  };
330
349
  /** Closes the client */
331
350
  Ableton.prototype.close = function () {
351
+ var _a, _b;
332
352
  return __awaiter(this, void 0, void 0, function () {
333
353
  var closePromise;
334
354
  var _this = this;
335
- return __generator(this, function (_a) {
336
- switch (_a.label) {
355
+ return __generator(this, function (_c) {
356
+ switch (_c.label) {
337
357
  case 0:
358
+ (_a = this.logger) === null || _a === void 0 ? void 0 : _a.info("Closing the client");
338
359
  fs_1.unwatchFile(this.serverPortFile);
339
360
  if (this.heartbeatInterval) {
340
361
  clearInterval(this.heartbeatInterval);
@@ -344,11 +365,12 @@ var Ableton = /** @class */ (function (_super) {
344
365
  this.client.close();
345
366
  return [4 /*yield*/, closePromise];
346
367
  case 1:
347
- _a.sent();
348
- _a.label = 2;
368
+ _c.sent();
369
+ _c.label = 2;
349
370
  case 2:
350
371
  this.clientState = "closed";
351
372
  this._isConnected = false;
373
+ (_b = this.logger) === null || _b === void 0 ? void 0 : _b.info("Client closed");
352
374
  return [2 /*return*/];
353
375
  }
354
376
  });
@@ -417,7 +439,6 @@ var Ableton = /** @class */ (function (_super) {
417
439
  return eventCallback.forEach(function (cb) { return cb(data.data); });
418
440
  }
419
441
  if (data.uuid) {
420
- this.emit("error", "Message could not be assigned to any request: " + msg);
421
442
  (_d = this.logger) === null || _d === void 0 ? void 0 : _d.warn("Message could not be assigned to any request:", {
422
443
  msg: msg,
423
444
  });
@@ -1 +1 @@
1
- version = "3.1.4"
1
+ version = "3.1.5"
package/ns/track.d.ts CHANGED
@@ -89,7 +89,7 @@ export interface SettableProperties {
89
89
  current_input_sub_routing: string;
90
90
  current_monitoring_state: number;
91
91
  current_output_routing: string;
92
- current_output_sub_routing: number;
92
+ current_output_sub_routing: string;
93
93
  fired_slot_index: number;
94
94
  fold_state: number;
95
95
  implicit_arm: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ableton-js",
3
- "version": "3.1.4",
3
+ "version": "3.1.5",
4
4
  "description": "Control Ableton Live from Node",
5
5
  "main": "index.js",
6
6
  "author": "Leo Bernard <admin@leolabs.org>",
package/util/tests.js CHANGED
@@ -50,15 +50,16 @@ var withAbleton = function (callback) { return __awaiter(void 0, void 0, void 0,
50
50
  _a.sent();
51
51
  _a.label = 2;
52
52
  case 2:
53
- _a.trys.push([2, , 4, 5]);
53
+ _a.trys.push([2, , 4, 6]);
54
54
  return [4 /*yield*/, callback(ab)];
55
55
  case 3:
56
56
  _a.sent();
57
- return [3 /*break*/, 5];
58
- case 4:
59
- ab.close();
57
+ return [3 /*break*/, 6];
58
+ case 4: return [4 /*yield*/, ab.close()];
59
+ case 5:
60
+ _a.sent();
60
61
  return [7 /*endfinally*/];
61
- case 5: return [2 /*return*/];
62
+ case 6: return [2 /*return*/];
62
63
  }
63
64
  });
64
65
  }); };