diff --git a/midi-script/AbletonJS.py b/midi-script/AbletonJS.py index 3fdd226..7498358 100755 --- a/midi-script/AbletonJS.py +++ b/midi-script/AbletonJS.py @@ -3,6 +3,7 @@ from .Socket import Socket from .Interface import Interface +from .Application import Application from .CuePoint import CuePoint from .Device import Device from .DeviceParameter import DeviceParameter @@ -26,6 +27,7 @@ def __init__(self, c_instance): self.socket = Socket(self.command_handler) self.handlers = { + "application": Application(c_instance, self.socket, self.application()), "internal": Internal(c_instance, self.socket), "cue-point": CuePoint(c_instance, self.socket), "device": Device(c_instance, self.socket), diff --git a/midi-script/Application.py b/midi-script/Application.py new file mode 100755 index 0000000..78c632b --- /dev/null +++ b/midi-script/Application.py @@ -0,0 +1,26 @@ +from __future__ import absolute_import +from .Interface import Interface + +import Live + + +class Application(Interface): + def __init__(self, c_instance, socket, application): + super(Application, self).__init__(c_instance, socket) + self.application = application + self.log_message("Version: " + self.get_version(self.get_ns())) + + def get_ns(self, nsid=None): + return self.application + + def get_major_version(self, ns): + return ns.get_major_version() + + def get_minor_version(self, ns): + return ns.get_minor_version() + + def get_bugfix_version(self, ns): + return ns.get_bugfix_version() + + def get_version(self, ns): + return str(ns.get_major_version()) + "." + str(ns.get_minor_version()) + "." + str(ns.get_bugfix_version()) diff --git a/midi-script/Socket.py b/midi-script/Socket.py index 68a5364..867de04 100755 --- a/midi-script/Socket.py +++ b/midi-script/Socket.py @@ -82,19 +82,23 @@ def shutdown(self): def process(self): try: buffer = bytes() + num_messages = 0 while 1: - data = self._socket.recv(65536) + data = self._socket.recv(8192) if len(data) and self.input_handler: buffer += data[1:] + num_messages += 1 # \xFF for Live 10 (Python2) and 255 for Live 11 (Python3) if(data[0] == b'\xFF' or data[0] == 255): unzipped = zlib.decompress(buffer) payload = json.loads(unzipped) - self.log_message("Receiving: " + str(payload)) + self.log_message( + "Receiving from " + str(num_messages) + " messages, " + str(len(buffer)) + " bytes: " + str(payload)) self.input_handler(payload) buffer = bytes() + num_messages = 0 except socket.error as e: return except Exception as e: diff --git a/src/index.ts b/src/index.ts index 0f1defb..56d52ae 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,10 @@ import { EventEmitter } from "events"; import { v4 } from "uuid"; import semver from "semver"; import { unzipSync, deflateSync } from "zlib"; + import { Song } from "./ns/song"; import { Internal } from "./ns/internal"; +import { Application } from "./ns/application"; import { getPackageVersion } from "./util/package-version"; interface Command { @@ -61,6 +63,7 @@ export class Ableton extends EventEmitter implements ConnectionEventEmitter { private latency: number = 0; public song = new Song(this); + public application = new Application(this); public internal = new Internal(this); constructor( diff --git a/src/ns/application.spec.ts b/src/ns/application.spec.ts new file mode 100644 index 0000000..2c4c1a1 --- /dev/null +++ b/src/ns/application.spec.ts @@ -0,0 +1,21 @@ +import { withAbleton } from "../util/tests"; +import { GettableProperties } from "./application"; +import "jest-extended"; + +const gettableProps: (keyof GettableProperties)[] = [ + "major_version", + "minor_version", + "bugfix_version", + "version", + "open_dialog_count", + "current_dialog_message", + "current_dialog_button_count", +]; + +describe("Application", () => { + it("should be able to read all properties without erroring", async () => { + await withAbleton(async (ab) => { + await Promise.all(gettableProps.map((p) => ab.application.get(p))); + }); + }); +}); diff --git a/src/ns/application.ts b/src/ns/application.ts new file mode 100644 index 0000000..60cc051 --- /dev/null +++ b/src/ns/application.ts @@ -0,0 +1,36 @@ +import { Ableton } from ".."; +import { Namespace } from "."; + +export interface GettableProperties { + bugfix_version: number; + major_version: number; + minor_version: number; + version: string; + current_dialog_button_count: number; + current_dialog_message: string; + open_dialog_count: number; + // More properties are available +} + +export interface TransformedProperties {} + +export interface SettableProperties {} + +export interface ObservableProperties { + open_dialog_count: number; +} + +export class Application extends Namespace< + GettableProperties, + TransformedProperties, + SettableProperties, + ObservableProperties +> { + constructor(ableton: Ableton) { + super(ableton, "application"); + } + + public async pressCurrentDialogButton(index: number) { + return this.sendCommand("press_current_dialog_button", [index]); + } +} diff --git a/src/ns/song.spec.ts b/src/ns/song.spec.ts index 959b881..443d2e8 100644 --- a/src/ns/song.spec.ts +++ b/src/ns/song.spec.ts @@ -76,7 +76,7 @@ describe("Song", () => { await withAbleton(async (ab) => { const largeArray: number[] = []; - for (let i = 0; i < 10000; i++) { + for (let i = 0; i < 100000; i++) { largeArray.push(i); }