ableton-js
Advanced tools
Comparing version 1.7.2 to 1.8.0
console.warn( | ||
"🚨 Ableton.js changed the default ports from 9000 and 9001 to 9004 and 9005. Please update the Python plugin as well.", | ||
"\x1b[33m🚨 Ableton.js changed the default ports from 9000 and 9001 to 9004 and 9005. Please update the Python plugin as well.\x1b[0m", | ||
); |
@@ -26,2 +26,3 @@ /// <reference types="node" /> | ||
private cancelConnectionEvent; | ||
private buffer; | ||
song: Song; | ||
@@ -31,3 +32,4 @@ internal: Internal; | ||
close(): void; | ||
handleIncoming(msg: Buffer, info: dgram.RemoteInfo): any; | ||
handleIncoming(msg: Buffer, info: dgram.RemoteInfo): void; | ||
handleUncompressedMessage(msg: string): any; | ||
sendCommand(ns: string, nsid: number | undefined, name: string, args?: { | ||
@@ -34,0 +36,0 @@ [k: string]: any; |
76
index.js
@@ -60,2 +60,3 @@ "use strict"; | ||
var semver_1 = __importDefault(require("semver")); | ||
var zlib_1 = require("zlib"); | ||
var Ableton = /** @class */ (function (_super) { | ||
@@ -76,2 +77,3 @@ __extends(Ableton, _super); | ||
_this.cancelConnectionEvent = false; | ||
_this.buffer = []; | ||
_this.song = new song_1.Song(_this); | ||
@@ -125,36 +127,50 @@ _this.internal = new internal_1.Internal(_this); | ||
try { | ||
var data_1 = JSON.parse(msg.toString()); | ||
var functionCallback = this.msgMap.get(data_1.uuid); | ||
if (data_1.event === "result" && functionCallback) { | ||
this.msgMap["delete"](data_1.uuid); | ||
return functionCallback.res(data_1.data); | ||
var index = msg[0]; | ||
var message = msg.slice(1); | ||
this.buffer[index] = message; | ||
// 0xFF signals that the end of the buffer has been reached | ||
if (index === 255) { | ||
this.handleUncompressedMessage(zlib_1.unzipSync(Buffer.concat(this.buffer.filter(function (b) { return b; }))).toString()); | ||
this.buffer = []; | ||
} | ||
if (data_1.event === "error" && functionCallback) { | ||
this.msgMap["delete"](data_1.uuid); | ||
return functionCallback.rej(new Error(data_1.data)); | ||
} | ||
catch (e) { | ||
this.buffer = []; | ||
console.warn("Could not handle input:", e); | ||
} | ||
}; | ||
Ableton.prototype.handleUncompressedMessage = function (msg) { | ||
var data = JSON.parse(msg); | ||
var functionCallback = this.msgMap.get(data.uuid); | ||
if (data.event === "result" && functionCallback) { | ||
this.msgMap["delete"](data.uuid); | ||
return functionCallback.res(data.data); | ||
} | ||
if (data.event === "error" && functionCallback) { | ||
this.msgMap["delete"](data.uuid); | ||
return functionCallback.rej(new Error(data.data)); | ||
} | ||
if (data.event === "disconnect") { | ||
this.msgMap.clear(); | ||
this.eventListeners.clear(); | ||
if (this._isConnected === true) { | ||
this._isConnected = false; | ||
this.cancelConnectionEvent = true; | ||
this.emit("disconnect", "realtime"); | ||
} | ||
if (data_1.event === "disconnect") { | ||
this.msgMap.clear(); | ||
this.eventListeners.clear(); | ||
if (this._isConnected === true) { | ||
this._isConnected = false; | ||
this.cancelConnectionEvent = true; | ||
this.emit("disconnect", "realtime"); | ||
} | ||
return; | ||
return; | ||
} | ||
if (data.event === "connect") { | ||
if (this._isConnected === false) { | ||
this._isConnected = true; | ||
this.cancelConnectionEvent = true; | ||
this.emit("connect", "realtime"); | ||
} | ||
if (data_1.event === "connect") { | ||
if (this._isConnected === false) { | ||
this._isConnected = true; | ||
this.cancelConnectionEvent = true; | ||
this.emit("connect", "realtime"); | ||
} | ||
return; | ||
} | ||
var eventCallback = this.eventListeners.get(data_1.event); | ||
if (eventCallback) { | ||
return eventCallback.forEach(function (cb) { return cb(data_1.data); }); | ||
} | ||
return; | ||
} | ||
catch (e) { } | ||
var eventCallback = this.eventListeners.get(data.event); | ||
if (eventCallback) { | ||
return eventCallback.forEach(function (cb) { return cb(data.data); }); | ||
} | ||
throw new Error("Message could not be assigned to any request: " + msg); | ||
}; | ||
@@ -161,0 +177,0 @@ Ableton.prototype.sendCommand = function (ns, nsid, name, args, timeout) { |
import { Ableton } from ".."; | ||
import { Namespace } from "."; | ||
import { ClipSlot, RawClipSlot } from './clip-slot'; | ||
export interface GettableProperties { | ||
clip_slots: number; | ||
clip_slots: RawClipSlot[]; | ||
color: number; | ||
@@ -13,5 +14,6 @@ color_index: number; | ||
export interface TransformedProperties { | ||
clip_slots: ClipSlot[]; | ||
} | ||
export interface SettableProperties { | ||
clip_slots: number; | ||
clip_slots: RawClipSlot[]; | ||
color: number; | ||
@@ -23,3 +25,3 @@ color_index: number; | ||
export interface ObservableProperties { | ||
clip_slots: number; | ||
clip_slots: RawClipSlot[]; | ||
color: number; | ||
@@ -26,0 +28,0 @@ color_index: number; |
@@ -17,7 +17,11 @@ "use strict"; | ||
var _1 = require("."); | ||
var clip_slot_1 = require("./clip-slot"); | ||
var Scene = /** @class */ (function (_super) { | ||
__extends(Scene, _super); | ||
function Scene(ableton, raw) { | ||
var _this = _super.call(this, ableton, "scene") || this; | ||
var _this = _super.call(this, ableton, "scene", raw.id) || this; | ||
_this.raw = raw; | ||
_this.transformers = { | ||
clip_slots: function (clip_slots) { return clip_slots.map(function (c) { return new clip_slot_1.ClipSlot(_this.ableton, c); }); } | ||
}; | ||
return _this; | ||
@@ -24,0 +28,0 @@ } |
@@ -7,2 +7,3 @@ import { Ableton } from ".."; | ||
import { RawDeviceParameter, DeviceParameter } from "./device-parameter"; | ||
import { ClipSlot, RawClipSlot } from "./clip-slot"; | ||
export interface GettableProperties { | ||
@@ -12,3 +13,3 @@ detail_clip: any; | ||
follow_song: boolean; | ||
highlighted_clip_slot: any; | ||
highlighted_clip_slot: RawClipSlot; | ||
selected_chain: any; | ||
@@ -23,2 +24,3 @@ selected_parameter: RawDeviceParameter; | ||
selected_track: Track; | ||
highlighted_clip_slot: ClipSlot; | ||
} | ||
@@ -25,0 +27,0 @@ export interface SettableProperties { |
@@ -55,2 +55,3 @@ "use strict"; | ||
var device_parameter_1 = require("./device-parameter"); | ||
var clip_slot_1 = require("./clip-slot"); | ||
var SongView = /** @class */ (function (_super) { | ||
@@ -63,3 +64,4 @@ __extends(SongView, _super); | ||
selected_track: function (track) { return new track_1.Track(_this.ableton, track); }, | ||
selected_scene: function (scene) { return new scene_1.Scene(_this.ableton, scene); } | ||
selected_scene: function (scene) { return new scene_1.Scene(_this.ableton, scene); }, | ||
highlighted_clip_slot: function (clipSlot) { return new clip_slot_1.ClipSlot(_this.ableton, clipSlot); } | ||
}; | ||
@@ -66,0 +68,0 @@ return _this; |
@@ -50,13 +50,12 @@ "use strict"; | ||
]; | ||
describe("Song", function () { | ||
describe("Song View", function () { | ||
it("should be able to read all properties without erroring", function () { return __awaiter(_this, void 0, void 0, function () { | ||
var a, _a, _b; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
var a; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
a = new index_1.Ableton(); | ||
_b = (_a = console).log; | ||
return [4 /*yield*/, Promise.all(gettableProps.map(function (p) { return a.song.view.get(p); }))]; | ||
case 1: | ||
_b.apply(_a, [_c.sent()]); | ||
_a.sent(); | ||
a.close(); | ||
@@ -63,0 +62,0 @@ return [2 /*return*/]; |
@@ -6,2 +6,3 @@ import { Ableton } from ".."; | ||
import { SongView } from "./song-view"; | ||
import { Scene, RawScene } from "./scene"; | ||
export interface GettableProperties { | ||
@@ -41,3 +42,3 @@ arrangement_overdub: number; | ||
scale_name: number; | ||
scenes: number; | ||
scenes: RawScene[]; | ||
select_on_launch: number; | ||
@@ -53,3 +54,2 @@ session_automation_record: number; | ||
tracks: RawTrack[]; | ||
view: number; | ||
visible_tracks: RawTrack[]; | ||
@@ -63,3 +63,3 @@ } | ||
visible_tracks: Track[]; | ||
view: SongView; | ||
scenes: Scene[]; | ||
} | ||
@@ -94,3 +94,2 @@ export interface SettableProperties { | ||
scale_name: number; | ||
scenes: number; | ||
select_on_launch: number; | ||
@@ -133,3 +132,3 @@ session_automation_record: number; | ||
return_tracks: RawTrack[]; | ||
scenes: number; | ||
scenes: RawScene[]; | ||
session_automation_record: number; | ||
@@ -136,0 +135,0 @@ session_record: number; |
@@ -55,2 +55,3 @@ "use strict"; | ||
var song_view_1 = require("./song-view"); | ||
var scene_1 = require("./scene"); | ||
var Quantization; | ||
@@ -96,3 +97,3 @@ (function (Quantization) { | ||
visible_tracks: function (tracks) { return tracks.map(function (t) { return new track_1.Track(_this.ableton, t); }); }, | ||
view: function () { return new song_view_1.SongView(_this.ableton); } | ||
scenes: function (scenes) { return scenes.map(function (s) { return new scene_1.Scene(_this.ableton, s); }); } | ||
}; | ||
@@ -99,0 +100,0 @@ return _this; |
@@ -85,3 +85,2 @@ "use strict"; | ||
"tracks", | ||
"view", | ||
"visible_tracks", | ||
@@ -88,0 +87,0 @@ ]; |
import { Ableton } from ".."; | ||
import { Namespace } from "."; | ||
import { Device, RawDevice } from "./device"; | ||
import { ClipSlot, RawClipSlot } from './clip-slot'; | ||
export interface GettableProperties { | ||
@@ -13,3 +14,3 @@ arm: number; | ||
can_show_chains: number; | ||
clip_slots: number; | ||
clip_slots: RawClipSlot[]; | ||
color: number; | ||
@@ -61,2 +62,3 @@ color_index: number; | ||
devices: Device[]; | ||
clip_slots: ClipSlot[]; | ||
} | ||
@@ -73,3 +75,3 @@ export interface SettableProperties { | ||
canonical_parent: number; | ||
clip_slots: number; | ||
clip_slots: RawClipSlot[]; | ||
color: number; | ||
@@ -125,3 +127,3 @@ color_index: number; | ||
available_output_routing_types: number; | ||
clip_slots: number; | ||
clip_slots: RawClipSlot[]; | ||
color_index: number; | ||
@@ -128,0 +130,0 @@ color: number; |
@@ -18,2 +18,3 @@ "use strict"; | ||
var device_1 = require("./device"); | ||
var clip_slot_1 = require("./clip-slot"); | ||
var Track = /** @class */ (function (_super) { | ||
@@ -25,3 +26,4 @@ __extends(Track, _super); | ||
_this.transformers = { | ||
devices: function (devices) { return devices.map(function (d) { return new device_1.Device(_this.ableton, d); }); } | ||
devices: function (devices) { return devices.map(function (d) { return new device_1.Device(_this.ableton, d); }); }, | ||
clip_slots: function (clip_slots) { return clip_slots.map(function (c) { return new clip_slot_1.ClipSlot(_this.ableton, c); }); } | ||
}; | ||
@@ -28,0 +30,0 @@ return _this; |
{ | ||
"name": "ableton-js", | ||
"version": "1.7.2", | ||
"version": "1.8.0", | ||
"description": "Control Ableton Live from Node", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
85500
33
1919