Add the Max for Live device that reads Live's scale

Build step 2 of the brief: an M4L device that observes root_note /
scale_name / scale_intervals in the Live Object Model and prints the
QWERTY keys the scale maps to. No lighting yet — that is step 3.

LiveAPI only exists inside Max's js objects, so max/scale-observer.js
(plain ES5, the one uncompiled file here) observes the LOM and forwards
raw values as flat messages; src/max/device.ts resolves them, keeping
every decision in TypeScript and testable off the hardware.

Follows the Song's scale by default and the selected clip's on request,
since the brief left that decision open. scale_intervals only exists
from Live 12.1, so scale_name resolves against a table of Live's
built-ins as a fallback; reported intervals always win.

Ships a .maxpat rather than an .amxd because an .amxd has to be created
from inside Live — the README has the paste-into-a-new-device steps.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
khannurien
2026-08-15 08:48:05 +00:00
parent 3b02612461
commit 2f0d5841c6
8 changed files with 1454 additions and 9 deletions

30
max/scale-device.js Normal file
View File

@@ -0,0 +1,30 @@
'use strict';
/**
* Launcher for the `node.script` object — the same trick as bin/apex7-scale.js.
*
* The device logic is TypeScript (`src/max/device.ts`); this file stays plain
* CommonJS because Node for Max runs it on a Node version we do not control,
* with no loader and no build step of its own.
*
* `max-api` is required *here*, in the folder Node for Max resolves modules
* from, and handed to the compiled module — which keeps that module importable
* (and testable) outside of Max.
*/
const fs = require('fs');
const path = require('path');
const Max = require('max-api');
const compiled = path.join(__dirname, '..', 'dist', 'src', 'max', 'device.js');
if (!fs.existsSync(compiled)) {
Max.post(
'scale: not built yet — run `npm install` (or `npm run build`) in ' +
path.join(__dirname, '..'),
Max.POST_LEVELS.ERROR
);
} else {
require(compiled).start(Max);
}