ableton-js 3.1.2 → 3.1.3
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 +8 -0
- package/index.js +4 -4
- package/midi-script/Interface.py +2 -1
- package/midi-script/Internal.py +1 -1
- package/midi-script/Socket.py +57 -46
- package/package.json +2 -2
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.3](https://github.com/leolabs/ableton.js/compare/v3.1.2...v3.1.3)
|
|
8
|
+
|
|
9
|
+
- :bug: Fix opening a project file from within Finder closing all socket and file handles [`6cf2440`](https://github.com/leolabs/ableton.js/commit/6cf244057797dd45a7f5007af907947754449d5d)
|
|
10
|
+
- :loud_sound: Log data that couldn't be sent [`e39c6c6`](https://github.com/leolabs/ableton.js/commit/e39c6c6b0b68823268ca715c486dbc1ab6ce7dec)
|
|
11
|
+
- :loud_sound: Improve logging for event handlers [`a1fa33b`](https://github.com/leolabs/ableton.js/commit/a1fa33bb9c1c6b05352ea845c24b4637c7f80094)
|
|
12
|
+
|
|
7
13
|
#### [v3.1.2](https://github.com/leolabs/ableton.js/compare/v3.1.1...v3.1.2)
|
|
8
14
|
|
|
15
|
+
> 26 February 2023
|
|
16
|
+
|
|
9
17
|
- :sparkles: Keep a handle to the client port file open for faster read performance [`2a0295d`](https://github.com/leolabs/ableton.js/commit/2a0295dff3022e3812c2a0f6077ffb7bdcd00bf0)
|
|
10
18
|
- :sparkles: Try re-using the previous port for a quicker reconnect [`5c77760`](https://github.com/leolabs/ableton.js/commit/5c777606ce97295429dcac1a5685a34c8aa5abe3)
|
|
11
19
|
- :bug: Fix double disconnect/connect event [`2f960be`](https://github.com/leolabs/ableton.js/commit/2f960be4c6d18b2668d15258914cd3b763be0f4a)
|
package/index.js
CHANGED
|
@@ -384,7 +384,7 @@ var Ableton = /** @class */ (function (_super) {
|
|
|
384
384
|
}
|
|
385
385
|
};
|
|
386
386
|
Ableton.prototype.handleUncompressedMessage = function (msg) {
|
|
387
|
-
var _a, _b;
|
|
387
|
+
var _a, _b, _c, _d;
|
|
388
388
|
this.emit("raw_message", msg);
|
|
389
389
|
var data = JSON.parse(msg);
|
|
390
390
|
var functionCallback = this.msgMap.get(data.uuid);
|
|
@@ -404,8 +404,8 @@ var Ableton = /** @class */ (function (_super) {
|
|
|
404
404
|
// If some heartbeat ping from the old connection is still pending,
|
|
405
405
|
// cancel it to prevent a double disconnect/connect event.
|
|
406
406
|
this.cancelDisconnectEvent = true;
|
|
407
|
-
if (data.data.port && data.data.port !== this.serverPort) {
|
|
408
|
-
(
|
|
407
|
+
if (((_a = data.data) === null || _a === void 0 ? void 0 : _a.port) && ((_b = data.data) === null || _b === void 0 ? void 0 : _b.port) !== this.serverPort) {
|
|
408
|
+
(_c = this.logger) === null || _c === void 0 ? void 0 : _c.info("Got new server port via connect:", {
|
|
409
409
|
port: data.data.port,
|
|
410
410
|
});
|
|
411
411
|
this.serverPort = data.data.port;
|
|
@@ -418,7 +418,7 @@ var Ableton = /** @class */ (function (_super) {
|
|
|
418
418
|
}
|
|
419
419
|
if (data.uuid) {
|
|
420
420
|
this.emit("error", "Message could not be assigned to any request: " + msg);
|
|
421
|
-
(
|
|
421
|
+
(_d = this.logger) === null || _d === void 0 ? void 0 : _d.warn("Message could not be assigned to any request:", {
|
|
422
422
|
msg: msg,
|
|
423
423
|
});
|
|
424
424
|
}
|
package/midi-script/Interface.py
CHANGED
|
@@ -90,7 +90,8 @@ class Interface(object):
|
|
|
90
90
|
value = self.get_prop(ns, prop)
|
|
91
91
|
return self.socket.send(eventId, value)
|
|
92
92
|
|
|
93
|
-
self.log_message("Attaching listener"
|
|
93
|
+
self.log_message("Attaching listener: " +
|
|
94
|
+
key + ", event ID: " + eventId)
|
|
94
95
|
add_fn(fn)
|
|
95
96
|
self.listeners[key] = {"id": eventId, "fn": fn}
|
|
96
97
|
return eventId
|
package/midi-script/Internal.py
CHANGED
package/midi-script/Socket.py
CHANGED
|
@@ -35,11 +35,16 @@ class Socket(object):
|
|
|
35
35
|
|
|
36
36
|
def __init__(self, handler):
|
|
37
37
|
self.input_handler = handler
|
|
38
|
-
self._server_addr = (
|
|
39
|
-
self._client_addr = (
|
|
40
|
-
self.
|
|
38
|
+
self._server_addr = ("0.0.0.0", 0)
|
|
39
|
+
self._client_addr = ("127.0.0.1", 39031)
|
|
40
|
+
self._socket = None
|
|
41
|
+
|
|
41
42
|
self.read_remote_port()
|
|
42
|
-
self.init_socket()
|
|
43
|
+
self.init_socket(True)
|
|
44
|
+
|
|
45
|
+
self.file_timer = Live.Base.Timer(callback=self.read_remote_port,
|
|
46
|
+
interval=1000, repeat=True)
|
|
47
|
+
self.file_timer.start()
|
|
43
48
|
|
|
44
49
|
def read_last_server_port(self):
|
|
45
50
|
try:
|
|
@@ -56,61 +61,64 @@ class Socket(object):
|
|
|
56
61
|
def read_remote_port(self):
|
|
57
62
|
'''Reads the port our client is listening on'''
|
|
58
63
|
try:
|
|
59
|
-
|
|
60
|
-
self.log_message("Opening remote port file...")
|
|
61
|
-
self.remote_port_file = open(client_port_path)
|
|
64
|
+
old_port = self._client_addr[1]
|
|
62
65
|
|
|
63
|
-
|
|
64
|
-
|
|
66
|
+
with open(client_port_path) as file:
|
|
67
|
+
port = int(file.read())
|
|
65
68
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
if port != old_port:
|
|
70
|
+
self.log_message("[" + str(id(self)) + "] Client port changed from " +
|
|
71
|
+
str(old_port) + " to " + str(port))
|
|
72
|
+
self._client_addr = ("127.0.0.1", port)
|
|
69
73
|
|
|
70
|
-
|
|
71
|
-
|
|
74
|
+
if self._socket:
|
|
75
|
+
self.send("connect", {"port": self._server_addr[1]})
|
|
72
76
|
except Exception as e:
|
|
73
|
-
self.log_message("Couldn't read
|
|
74
|
-
if self.remote_port_file:
|
|
75
|
-
self.remote_port_file.close()
|
|
76
|
-
|
|
77
|
-
Timer(1, self.read_remote_port).start()
|
|
78
|
-
|
|
79
|
-
def init_socket(self):
|
|
80
|
-
self._socket = socket.socket(
|
|
81
|
-
socket.AF_INET, socket.SOCK_DGRAM)
|
|
82
|
-
self._socket.setblocking(0)
|
|
83
|
-
|
|
84
|
-
self.bind(True)
|
|
77
|
+
self.log_message("Couldn't read file: " + str(e.args))
|
|
85
78
|
|
|
86
79
|
def shutdown(self):
|
|
80
|
+
self.log_message("Shutting down...")
|
|
81
|
+
self.file_timer.stop()
|
|
87
82
|
self._socket.close()
|
|
88
|
-
if self.remote_port_file:
|
|
89
|
-
self.remote_port_file.close()
|
|
90
83
|
|
|
91
|
-
def
|
|
84
|
+
def init_socket(self, try_stored=False):
|
|
85
|
+
self.log_message(
|
|
86
|
+
"Initializing socket, from stored: " + str(try_stored))
|
|
87
|
+
|
|
92
88
|
try:
|
|
93
89
|
stored_port = self.read_last_server_port()
|
|
94
90
|
|
|
95
91
|
# Try the port we used last time first
|
|
96
92
|
if try_stored and stored_port:
|
|
97
|
-
self._server_addr = ("
|
|
93
|
+
self._server_addr = ("0.0.0.0", stored_port)
|
|
98
94
|
else:
|
|
99
|
-
self._server_addr = ("
|
|
95
|
+
self._server_addr = ("0.0.0.0", 0)
|
|
100
96
|
|
|
97
|
+
self._socket = socket.socket(
|
|
98
|
+
socket.AF_INET, socket.SOCK_DGRAM)
|
|
99
|
+
self._socket.setblocking(0)
|
|
101
100
|
self._socket.bind(self._server_addr)
|
|
102
101
|
port = self._socket.getsockname()[1]
|
|
103
102
|
|
|
104
103
|
# Write the chosen port to a file
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
104
|
+
try:
|
|
105
|
+
if stored_port != port:
|
|
106
|
+
with open(server_port_path, "w") as file:
|
|
107
|
+
file.write(str(port))
|
|
108
|
+
except Exception as e:
|
|
109
|
+
self.log_message("Couldn't save port in file: " + str(e.args))
|
|
110
|
+
raise e
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
self.send("connect", {"port": self._server_addr[1]})
|
|
114
|
+
except Exception as e:
|
|
115
|
+
self.log_message("Couldn't send connect to " +
|
|
116
|
+
str(self._client_addr) + ": " + str(e.args))
|
|
108
117
|
|
|
109
|
-
self.send("connect", {"port": port})
|
|
110
118
|
self.show_message("Started server on port " + str(port))
|
|
111
119
|
|
|
112
|
-
self.log_message('Started on: ' + str(self._socket.getsockname()) +
|
|
113
|
-
',
|
|
120
|
+
self.log_message('Started server on: ' + str(self._socket.getsockname()) +
|
|
121
|
+
', client addr: ' + str(self._client_addr))
|
|
114
122
|
except Exception as e:
|
|
115
123
|
msg = 'ERROR: Cannot bind to ' + \
|
|
116
124
|
str(self._server_addr) + ': ' + \
|
|
@@ -118,7 +126,8 @@ class Socket(object):
|
|
|
118
126
|
'If this keeps happening, try restarting your computer.'
|
|
119
127
|
self.show_message(msg)
|
|
120
128
|
self.log_message(msg)
|
|
121
|
-
|
|
129
|
+
self.log_message("Client address: " + str(self._client_addr))
|
|
130
|
+
t = Timer(5, self.init_socket)
|
|
122
131
|
t.start()
|
|
123
132
|
|
|
124
133
|
def _sendto(self, msg):
|
|
@@ -143,16 +152,16 @@ class Socket(object):
|
|
|
143
152
|
return list(o)
|
|
144
153
|
return str(o)
|
|
145
154
|
|
|
155
|
+
data = None
|
|
156
|
+
|
|
146
157
|
try:
|
|
147
|
-
|
|
148
|
-
{"event": name, "data": obj, "uuid": uuid}, default=jsonReplace, ensure_ascii=False)
|
|
158
|
+
data = json.dumps(
|
|
159
|
+
{"event": name, "data": obj, "uuid": uuid}, default=jsonReplace, ensure_ascii=False)
|
|
160
|
+
self._sendto(data)
|
|
149
161
|
except socket.error as e:
|
|
150
|
-
self.log_message("Socket error: " + str(e.args))
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
self.log_message("Restarting socket...")
|
|
154
|
-
self._socket.close()
|
|
155
|
-
self.init_socket()
|
|
162
|
+
self.log_message("Socket error: " + str(e.args) + ", server: " + str(self._server_addr) +
|
|
163
|
+
", client: " + str(self._client_addr) + ", socket: " + str(self._socket))
|
|
164
|
+
self.log_message("Data:" + data)
|
|
156
165
|
except Exception as e:
|
|
157
166
|
error = str(type(e).__name__) + ': ' + str(e.args)
|
|
158
167
|
self.log_message("Error " + name + "(" + str(uuid) + "): " + error)
|
|
@@ -175,6 +184,8 @@ class Socket(object):
|
|
|
175
184
|
buffer = bytes()
|
|
176
185
|
num_messages = 0
|
|
177
186
|
except socket.error as e:
|
|
187
|
+
if (e.errno != 35):
|
|
188
|
+
self.log_message("Socket error: " + str(e.args))
|
|
178
189
|
return
|
|
179
190
|
except Exception as e:
|
|
180
191
|
self.log_message("Error while processing: " + str(e.args))
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "ableton-js",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.3",
|
|
4
4
|
"description": "Control Ableton Live from Node",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"author": "Leo Bernard <admin@leolabs.org>",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"ableton10:launch": "set -- /Applications/Ableton*10* && open \"$1\"",
|
|
21
21
|
"ableton11:copy-script": "set -- /Applications/Ableton*11*/Contents/App-Resources/MIDI\\ Remote\\ Scripts && rm -rf \"$1/AbletonJS\" && cp -r \"$(pwd)/midi-script\" \"$1/AbletonJS\" && rm -rf \"$1/AbletonJS/_Framework\"",
|
|
22
22
|
"ableton11:launch": "set -- /Applications/Ableton*11* && open \"$1\"",
|
|
23
|
-
"ableton:logs": "tail -f ~/Library/Preferences/Ableton/*/Log.txt | grep -i -e RemoteScriptError -e RemoteScriptMessage",
|
|
23
|
+
"ableton:logs": "tail -n 50 -f ~/Library/Preferences/Ableton/*/Log.txt | grep -i -e RemoteScriptError -e RemoteScriptMessage",
|
|
24
24
|
"ableton:kill": "pkill -KILL -f \"Ableton Live\"",
|
|
25
25
|
"ableton10:start": "yarn ableton:kill; yarn ableton:clean && yarn ableton10:copy-script && yarn ableton10:launch && yarn ableton:logs",
|
|
26
26
|
"ableton11:start": "yarn ableton:kill; yarn ableton:clean && yarn ableton11:copy-script && yarn ableton11:launch && yarn ableton:logs",
|