-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheyes_in_the_sky.js
More file actions
57 lines (48 loc) · 1.54 KB
/
Copy patheyes_in_the_sky.js
File metadata and controls
57 lines (48 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
const Max = require('max-api');
const http = require('http');
// We use lightweight HTTP to ping the Python backend
let aiListening = false;
let currentBpm = 120.0;
let isPlaying = false;
// 1. Listen for the ON/OFF toggle from your Ableton panel
Max.addHandler('toggle_listen', (state) => {
aiListening = (state === 1);
Max.post(`AI Listening Mode: ${aiListening ? 'ON' : 'OFF'}`);
});
// 2. The Watchtower: Receives live BPM and Transport data from Ableton
Max.addHandler('telemetry', (bpm, playing_state) => {
currentBpm = bpm;
isPlaying = (playing_state === 1);
// Only send data to the Swarm if the AI is told to listen
if (aiListening) {
sendToSwarm({
event: "status_update",
bpm: currentBpm,
playing: isPlaying,
timestamp: Date.now()
});
}
});
// 3. The Transmission Engine: Shoots data to your local Python hub
function sendToSwarm(payload) {
const data = JSON.stringify(payload);
const options = {
hostname: 'localhost',
port: 8000, // FastAPI gateway port
path: '/ableton-telemetry',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = http.request(options, (res) => {
// AI received it silently
});
req.on('error', (error) => {
Max.post(`Swarm disconnected: ${error.message}`);
});
req.write(data);
req.end();
}
Max.post("Eyes in the Sky: ONLINE. Awaiting Swarm Link.");