Skip to content

Commit

Permalink
Merge branch 'master' into feat/lower-latency-with-timer
Browse files Browse the repository at this point in the history
  • Loading branch information
leolabs committed Mar 26, 2022
2 parents 71ceef5 + 502ef2f commit efcfef2
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 3 deletions.
2 changes: 2 additions & 0 deletions midi-script/AbletonJS.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
26 changes: 26 additions & 0 deletions midi-script/Application.py
Original file line number Diff line number Diff line change
@@ -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())
8 changes: 6 additions & 2 deletions midi-script/Socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 21 additions & 0 deletions src/ns/application.spec.ts
Original file line number Diff line number Diff line change
@@ -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)));
});
});
});
36 changes: 36 additions & 0 deletions src/ns/application.ts
Original file line number Diff line number Diff line change
@@ -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]);
}
}
2 changes: 1 addition & 1 deletion src/ns/song.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down

0 comments on commit efcfef2

Please sign in to comment.