ableton-js 3.1.9 → 3.2.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/ns/song.spec.js CHANGED
@@ -1,44 +1,8 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
- var tests_1 = require("../util/tests");
3
+ const tests_1 = require("../util/tests");
40
4
  require("jest-extended");
41
- var gettableProps = [
5
+ const gettableProps = [
42
6
  "arrangement_overdub",
43
7
  "back_to_arranger",
44
8
  "can_capture_midi",
@@ -85,82 +49,31 @@ var gettableProps = [
85
49
  "tracks",
86
50
  "visible_tracks",
87
51
  ];
88
- describe("Song", function () {
89
- it("should be able to read all properties without erroring", function () { return __awaiter(void 0, void 0, void 0, function () {
90
- return __generator(this, function (_a) {
91
- switch (_a.label) {
92
- case 0: return [4 /*yield*/, tests_1.withAbleton(function (ab) { return __awaiter(void 0, void 0, void 0, function () {
93
- return __generator(this, function (_a) {
94
- switch (_a.label) {
95
- case 0: return [4 /*yield*/, Promise.all(gettableProps.map(function (p) { return ab.song.get(p); }))];
96
- case 1:
97
- _a.sent();
98
- return [2 /*return*/];
99
- }
100
- });
101
- }); })];
102
- case 1:
103
- _a.sent();
104
- return [2 /*return*/];
105
- }
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)));
106
56
  });
107
- }); });
108
- it("should return the proper types for properties", function () { return __awaiter(void 0, void 0, void 0, function () {
109
- return __generator(this, function (_a) {
110
- switch (_a.label) {
111
- case 0: return [4 /*yield*/, tests_1.withAbleton(function (ab) { return __awaiter(void 0, void 0, void 0, function () {
112
- var songTime, clipTriggerQuantization, isPlaying;
113
- return __generator(this, function (_a) {
114
- switch (_a.label) {
115
- case 0: return [4 /*yield*/, ab.song.get("current_song_time")];
116
- case 1:
117
- songTime = _a.sent();
118
- expect(songTime).toBeNumber();
119
- return [4 /*yield*/, ab.song.get("clip_trigger_quantization")];
120
- case 2:
121
- clipTriggerQuantization = _a.sent();
122
- expect(clipTriggerQuantization).toBeString();
123
- return [4 /*yield*/, ab.song.get("is_playing")];
124
- case 3:
125
- isPlaying = _a.sent();
126
- expect(isPlaying).toBeBoolean();
127
- return [2 /*return*/];
128
- }
129
- });
130
- }); })];
131
- case 1:
132
- _a.sent();
133
- return [2 /*return*/];
134
- }
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();
135
66
  });
136
- }); });
137
- it("should be able to write and read large objects from the project", function () { return __awaiter(void 0, void 0, void 0, function () {
138
- return __generator(this, function (_a) {
139
- switch (_a.label) {
140
- case 0: return [4 /*yield*/, tests_1.withAbleton(function (ab) { return __awaiter(void 0, void 0, void 0, function () {
141
- var largeArray, i, received;
142
- return __generator(this, function (_a) {
143
- switch (_a.label) {
144
- case 0:
145
- largeArray = [];
146
- for (i = 0; i < 100000; i++) {
147
- largeArray.push(i);
148
- }
149
- return [4 /*yield*/, ab.song.setData("abletonjs_test", largeArray)];
150
- case 1:
151
- _a.sent();
152
- return [4 /*yield*/, ab.song.getData("abletonjs_test")];
153
- case 2:
154
- received = _a.sent();
155
- expect(received).toEqual(largeArray);
156
- return [2 /*return*/];
157
- }
158
- });
159
- }); })];
160
- case 1:
161
- _a.sent();
162
- return [2 /*return*/];
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);
163
73
  }
74
+ await ab.song.setData("abletonjs_test", largeArray);
75
+ const received = await ab.song.getData("abletonjs_test");
76
+ expect(received).toEqual(largeArray);
164
77
  });
165
- }); });
78
+ });
166
79
  });
package/ns/track.js CHANGED
@@ -1,32 +1,17 @@
1
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
18
3
  exports.Track = exports.RoutingCategory = exports.RoutingLayout = void 0;
19
- var _1 = require(".");
20
- var device_1 = require("./device");
21
- var clip_slot_1 = require("./clip-slot");
22
- var mixer_device_1 = require("./mixer-device");
23
- var clip_1 = require("./clip");
24
- var color_1 = require("../util/color");
4
+ const _1 = require(".");
5
+ const device_1 = require("./device");
6
+ const clip_slot_1 = require("./clip-slot");
7
+ const mixer_device_1 = require("./mixer-device");
8
+ const clip_1 = require("./clip");
9
+ const color_1 = require("../util/color");
25
10
  var RoutingLayout;
26
11
  (function (RoutingLayout) {
27
12
  RoutingLayout[RoutingLayout["Mono"] = 1] = "Mono";
28
13
  RoutingLayout[RoutingLayout["Stereo"] = 2] = "Stereo";
29
- })(RoutingLayout = exports.RoutingLayout || (exports.RoutingLayout = {}));
14
+ })(RoutingLayout || (exports.RoutingLayout = RoutingLayout = {}));
30
15
  var RoutingCategory;
31
16
  (function (RoutingCategory) {
32
17
  RoutingCategory[RoutingCategory["External"] = 0] = "External";
@@ -37,40 +22,34 @@ var RoutingCategory;
37
22
  RoutingCategory[RoutingCategory["ParentGroupTrack"] = 5] = "ParentGroupTrack";
38
23
  RoutingCategory[RoutingCategory["None"] = 6] = "None";
39
24
  RoutingCategory[RoutingCategory["Invalid"] = 7] = "Invalid";
40
- })(RoutingCategory = exports.RoutingCategory || (exports.RoutingCategory = {}));
41
- var Track = /** @class */ (function (_super) {
42
- __extends(Track, _super);
43
- function Track(ableton, raw) {
44
- var _this = _super.call(this, ableton, "track", raw.id) || this;
45
- _this.raw = raw;
46
- _this.transformers = {
47
- arrangement_clips: function (clips) {
48
- return clips.map(function (clip) { return new clip_1.Clip(ableton, clip); });
49
- },
50
- color: function (c) { return new color_1.Color(c); },
51
- devices: function (devices) { return devices.map(function (d) { return new device_1.Device(ableton, d); }); },
52
- clip_slots: function (clip_slots) {
53
- return clip_slots.map(function (c) { return new clip_slot_1.ClipSlot(ableton, c); });
54
- },
55
- mixer_device: function (mixer_device) { return new mixer_device_1.MixerDevice(ableton, mixer_device); },
25
+ })(RoutingCategory || (exports.RoutingCategory = RoutingCategory = {}));
26
+ class Track extends _1.Namespace {
27
+ raw;
28
+ constructor(ableton, raw) {
29
+ super(ableton, "track", raw.id);
30
+ this.raw = raw;
31
+ this.transformers = {
32
+ arrangement_clips: (clips) => clips.map((clip) => new clip_1.Clip(ableton, clip)),
33
+ color: (c) => new color_1.Color(c),
34
+ devices: (devices) => devices.map((d) => new device_1.Device(ableton, d)),
35
+ clip_slots: (clip_slots) => clip_slots.map((c) => new clip_slot_1.ClipSlot(ableton, c)),
36
+ mixer_device: (mixer_device) => new mixer_device_1.MixerDevice(ableton, mixer_device),
56
37
  };
57
- _this.cachedProps = {
38
+ this.cachedProps = {
58
39
  arrangement_clips: true,
59
40
  devices: true,
60
41
  clip_slots: true,
61
42
  };
62
- return _this;
63
43
  }
64
44
  /**
65
45
  * Duplicates the given clip into the arrangement of this track at the provided destination time and returns it.
66
46
  * When the type of the clip and the type of the track are incompatible, a runtime error is raised.
67
47
  */
68
- Track.prototype.duplicateClipToArrangement = function (clipOrId, time) {
48
+ duplicateClipToArrangement(clipOrId, time) {
69
49
  return this.sendCommand("duplicate_clip_to_arrangement", {
70
50
  clip_id: typeof clipOrId === "string" ? clipOrId : clipOrId.raw.id,
71
51
  time: time,
72
52
  });
73
- };
74
- return Track;
75
- }(_1.Namespace));
53
+ }
54
+ }
76
55
  exports.Track = Track;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ableton-js",
3
- "version": "3.1.9",
3
+ "version": "3.2.0",
4
4
  "description": "Control Ableton Live from Node",
5
5
  "main": "index.js",
6
6
  "author": "Leo Bernard <admin@leolabs.org>",
@@ -32,7 +32,7 @@
32
32
  "devDependencies": {
33
33
  "@types/jest": "^26.0.23",
34
34
  "@types/lodash": "^4.14.194",
35
- "@types/node": "^15.6.1",
35
+ "@types/node": "^20.3.0",
36
36
  "@types/node-uuid": "^0.0.28",
37
37
  "@types/semver": "^7.3.6",
38
38
  "@types/uuid": "^8.3.0",
@@ -41,9 +41,9 @@
41
41
  "jest-extended": "^0.11.5",
42
42
  "lodash": "^4.17.21",
43
43
  "p-all": "^3",
44
- "ts-jest": "^27.0.1",
45
- "ts-node": "^10.0.0",
46
- "typescript": "^4.3.2"
44
+ "ts-jest": "^29.1.0",
45
+ "ts-node": "^10.9.1",
46
+ "typescript": "^5.1.3"
47
47
  },
48
48
  "dependencies": {
49
49
  "lru-cache": "^7.14.0",
package/util/cache.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type LruCache from "lru-cache";
2
- export declare type CachedResponse = {
2
+ export type CachedResponse = {
3
3
  __cached: true;
4
4
  };
5
- export declare type CacheResponse = CachedResponse | {
5
+ export type CacheResponse = CachedResponse | {
6
6
  data: any;
7
7
  etag: string;
8
8
  };
@@ -11,4 +11,4 @@ export interface CacheObject {
11
11
  etag: string;
12
12
  data: any;
13
13
  }
14
- export declare type Cache = LruCache<string, CacheObject>;
14
+ export type Cache = LruCache<string, CacheObject>;
package/util/cache.js CHANGED
@@ -1,7 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isCached = void 0;
4
- var isCached = function (obj) {
5
- return obj && "__cached" in obj;
6
- };
4
+ const isCached = (obj) => obj && "__cached" in obj;
7
5
  exports.isCached = isCached;
package/util/color.js CHANGED
@@ -2,8 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Color = void 0;
4
4
  /** Represents a color in Ableton */
5
- var Color = /** @class */ (function () {
6
- function Color(color) {
5
+ class Color {
6
+ color;
7
+ constructor(color) {
7
8
  if (typeof color === "number") {
8
9
  this.color = color.toString(16).padStart(6, "0");
9
10
  }
@@ -14,37 +15,24 @@ var Color = /** @class */ (function () {
14
15
  throw new Error("Color " + color + " is not in a valid format");
15
16
  }
16
17
  }
17
- Object.defineProperty(Color.prototype, "hex", {
18
- get: function () {
19
- return "#" + this.color;
20
- },
21
- enumerable: false,
22
- configurable: true
23
- });
24
- Object.defineProperty(Color.prototype, "rgb", {
25
- get: function () {
26
- return {
27
- r: parseInt(this.color.substr(0, 2), 16),
28
- g: parseInt(this.color.substr(2, 2), 16),
29
- b: parseInt(this.color.substr(4, 2), 16),
30
- };
31
- },
32
- enumerable: false,
33
- configurable: true
34
- });
35
- Object.defineProperty(Color.prototype, "numberRepresentation", {
36
- get: function () {
37
- return parseInt(this.color, 16);
38
- },
39
- enumerable: false,
40
- configurable: true
41
- });
42
- Color.prototype.toString = function () {
18
+ get hex() {
19
+ return `#${this.color}`;
20
+ }
21
+ get rgb() {
22
+ return {
23
+ r: parseInt(this.color.substr(0, 2), 16),
24
+ g: parseInt(this.color.substr(2, 2), 16),
25
+ b: parseInt(this.color.substr(4, 2), 16),
26
+ };
27
+ }
28
+ get numberRepresentation() {
29
+ return parseInt(this.color, 16);
30
+ }
31
+ toString() {
43
32
  return this.hex;
44
- };
45
- Color.prototype.toJSON = function () {
33
+ }
34
+ toJSON() {
46
35
  return this.numberRepresentation;
47
- };
48
- return Color;
49
- }());
36
+ }
37
+ }
50
38
  exports.Color = Color;
package/util/note.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export declare type NoteTuple = [
1
+ export type NoteTuple = [
2
2
  pitch: number,
3
3
  time: number,
4
4
  duration: number,
package/util/note.js CHANGED
@@ -1,19 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.noteToTuple = exports.tupleToNote = void 0;
4
- var tupleToNote = function (tuple) { return ({
4
+ const tupleToNote = (tuple) => ({
5
5
  pitch: tuple[0],
6
6
  time: tuple[1],
7
7
  duration: tuple[2],
8
8
  velocity: tuple[3],
9
9
  muted: tuple[4],
10
- }); };
10
+ });
11
11
  exports.tupleToNote = tupleToNote;
12
- var noteToTuple = function (note) { return [
12
+ const noteToTuple = (note) => [
13
13
  note.pitch,
14
14
  note.time,
15
15
  note.duration,
16
16
  note.velocity,
17
17
  note.muted,
18
- ]; };
18
+ ];
19
19
  exports.noteToTuple = noteToTuple;
@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.getPackageVersion = void 0;
7
- var fs_1 = __importDefault(require("fs"));
8
- var path_1 = __importDefault(require("path"));
9
- var getPackageVersion = function () {
10
- var parentPath = path_1.default.join(__dirname, "..", "package.json");
11
- var parent2Path = path_1.default.join(__dirname, "..", "..", "package.json");
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const getPackageVersion = () => {
10
+ const parentPath = path_1.default.join(__dirname, "..", "package.json");
11
+ const parent2Path = path_1.default.join(__dirname, "..", "..", "package.json");
12
12
  if (fs_1.default.existsSync(parentPath)) {
13
13
  return require(parentPath).version;
14
14
  }
@@ -1,10 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var package_version_1 = require("./package-version");
4
- var semver_1 = require("semver");
5
- describe("Package Version", function () {
6
- it("should get a valid package version without erroring", function () {
7
- var version = package_version_1.getPackageVersion();
8
- expect(semver_1.valid(version)).toBeTruthy();
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
9
  });
10
10
  });
package/util/tests.js CHANGED
@@ -1,66 +1,16 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
2
  Object.defineProperty(exports, "__esModule", { value: true });
39
3
  exports.withAbleton = void 0;
40
- var __1 = require("..");
41
- var withAbleton = function (callback) { return __awaiter(void 0, void 0, void 0, function () {
42
- var ab;
43
- return __generator(this, function (_a) {
44
- switch (_a.label) {
45
- case 0:
46
- ab = new __1.Ableton();
47
- ab.on("error", console.error);
48
- return [4 /*yield*/, ab.start(2000)];
49
- case 1:
50
- _a.sent();
51
- _a.label = 2;
52
- case 2:
53
- _a.trys.push([2, , 4, 6]);
54
- return [4 /*yield*/, callback(ab)];
55
- case 3:
56
- _a.sent();
57
- return [3 /*break*/, 6];
58
- case 4: return [4 /*yield*/, ab.close()];
59
- case 5:
60
- _a.sent();
61
- return [7 /*endfinally*/];
62
- case 6: return [2 /*return*/];
63
- }
64
- });
65
- }); };
4
+ const __1 = require("..");
5
+ const withAbleton = async (callback) => {
6
+ const ab = new __1.Ableton();
7
+ ab.on("error", console.error);
8
+ await ab.start(2000);
9
+ try {
10
+ await callback(ab);
11
+ }
12
+ finally {
13
+ await ab.close();
14
+ }
15
+ };
66
16
  exports.withAbleton = withAbleton;