@m4l-jweb/build 0.1.0 → 0.2.0
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/LICENSE +21 -0
- package/package.json +6 -4
- package/src/amxd.mjs +93 -93
- package/src/chains.mjs +338 -119
- package/src/index.mjs +246 -228
- package/src/init.mjs +38 -33
- package/templates/starter/.prettierrc +5 -0
- package/templates/starter/README.md +38 -12
- package/templates/starter/index.html +1 -1
- package/templates/starter/package.json +40 -34
- package/templates/starter/patcher/devices.mjs +33 -24
- package/templates/starter/scripts/build-ui.mjs +19 -0
- package/templates/starter/scripts/dev.mjs +24 -0
- package/templates/starter/scripts/devices.d.mts +24 -0
- package/templates/starter/scripts/devices.mjs +35 -0
- package/templates/starter/src/app/shared/Frame.tsx +51 -0
- package/templates/starter/src/app/shared/device.ts +79 -0
- package/templates/starter/src/app/{worker.ts → shared/worker.ts} +8 -8
- package/templates/starter/src/app/{{name}}/App.tsx +62 -0
- package/templates/starter/src/app/{{name}}/protocol.ts +32 -0
- package/templates/starter/src/app/{{name}}/surface.ts +26 -0
- package/templates/starter/src/index.css +117 -56
- package/templates/starter/src/main.tsx +35 -4
- package/templates/starter/src/vite-env.d.ts +2 -2
- package/templates/starter/tsconfig.app.json +26 -22
- package/templates/starter/tsconfig.node.json +1 -1
- package/templates/starter/vite.config.ts +61 -28
- package/templates/starter/vitest.config.ts +1 -1
- package/templates/starter/src/app/App.tsx +0 -87
- package/templates/starter/src/app/protocol.ts +0 -32
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jaime Lopez (alienmind)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@m4l-jweb/build",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "m4l-jweb: the CLI that builds and packages a device repo into installable Max for Live devices.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -18,17 +18,19 @@
|
|
|
18
18
|
"exports": {
|
|
19
19
|
".": "./src/index.mjs",
|
|
20
20
|
"./chains": "./src/chains.mjs",
|
|
21
|
-
"./amxd": "./src/amxd.mjs"
|
|
21
|
+
"./amxd": "./src/amxd.mjs",
|
|
22
|
+
"./init": "./src/init.mjs"
|
|
22
23
|
},
|
|
23
24
|
"files": [
|
|
24
25
|
"bin",
|
|
25
26
|
"src",
|
|
26
|
-
"templates"
|
|
27
|
+
"templates",
|
|
28
|
+
"LICENSE"
|
|
27
29
|
],
|
|
28
30
|
"dependencies": {
|
|
29
31
|
"acorn": "^8.17.0",
|
|
30
32
|
"archiver": "^7.0.1",
|
|
31
33
|
"typescript": "^5.7.0",
|
|
32
|
-
"@m4l-jweb/wrapper": "0.
|
|
34
|
+
"@m4l-jweb/wrapper": "0.2.0"
|
|
33
35
|
}
|
|
34
36
|
}
|
package/src/amxd.mjs
CHANGED
|
@@ -21,9 +21,9 @@ import { parse } from "acorn";
|
|
|
21
21
|
|
|
22
22
|
/** 'aaaa' audio effect / 'mmmm' MIDI effect / 'iiii' instrument. */
|
|
23
23
|
export const AMXD_TYPES = {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
midi: 0x6d6d6d6d,
|
|
25
|
+
audio: 0x61616161,
|
|
26
|
+
instrument: 0x69696969,
|
|
27
27
|
};
|
|
28
28
|
|
|
29
29
|
const TAG_BY_CODE = { 0x61616161: "aaaa", 0x6d6d6d6d: "mmmm", 0x69696969: "iiii" };
|
|
@@ -35,11 +35,11 @@ const TAG_BY_CODE = { 0x61616161: "aaaa", 0x6d6d6d6d: "mmmm", 0x69696969: "iiii"
|
|
|
35
35
|
* preference. Call this on the exact bytes that will ship.
|
|
36
36
|
*/
|
|
37
37
|
export function assertES5(js, label = "wrapper") {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
try {
|
|
39
|
+
parse(js, { ecmaVersion: 5 });
|
|
40
|
+
} catch (e) {
|
|
41
|
+
throw new Error(`${label} is not valid ES5: ${e.message}`);
|
|
42
|
+
}
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
@@ -51,17 +51,17 @@ export function assertES5(js, label = "wrapper") {
|
|
|
51
51
|
* so it carries the payload and writes it to a real file on first load.
|
|
52
52
|
*/
|
|
53
53
|
export function payloadJs(prefix, name, buf) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
54
|
+
const CHUNK = 30000; // multiple of 3 -> each chunk is padding-free base64
|
|
55
|
+
const chunks = [];
|
|
56
|
+
for (let i = 0; i < buf.length; i += CHUNK) {
|
|
57
|
+
chunks.push(JSON.stringify(buf.subarray(i, i + CHUNK).toString("base64")));
|
|
58
|
+
}
|
|
59
|
+
return (
|
|
60
|
+
`\n// ---- generated: embedded ${prefix} payload ----\n` +
|
|
61
|
+
`var ${prefix}_NAME = ${JSON.stringify(name)};\n` +
|
|
62
|
+
`var ${prefix}_BYTES = ${buf.length};\n` +
|
|
63
|
+
`var ${prefix}_B64 = [\n${chunks.join(",\n")}\n];\n`
|
|
64
|
+
);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -74,38 +74,38 @@ export function payloadJs(prefix, name, buf) {
|
|
|
74
74
|
* the wrapper's core.ts.
|
|
75
75
|
*/
|
|
76
76
|
export function extraPayloadsJs(payloads) {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
77
|
+
const names = payloads.map((p) => JSON.stringify(p.name));
|
|
78
|
+
const bytes = payloads.map((p) => p.data.length);
|
|
79
|
+
const blobs = payloads.map((p) => {
|
|
80
|
+
const CHUNK = 30000;
|
|
81
|
+
const chunks = [];
|
|
82
|
+
for (let i = 0; i < p.data.length; i += CHUNK) {
|
|
83
|
+
chunks.push(JSON.stringify(p.data.subarray(i, i + CHUNK).toString("base64")));
|
|
84
|
+
}
|
|
85
|
+
return `[\n${chunks.join(",\n")}\n]`;
|
|
86
|
+
});
|
|
87
|
+
return (
|
|
88
|
+
`\n// ---- generated: ${payloads.length} extra payload(s) ----\n` +
|
|
89
|
+
`var EXTRA_PAYLOAD_NAMES = [${names.join(", ")}];\n` +
|
|
90
|
+
`var EXTRA_PAYLOAD_BYTES = [${bytes.join(", ")}];\n` +
|
|
91
|
+
`var EXTRA_PAYLOAD_B64 = [\n${blobs.join(",\n")}\n];\n`
|
|
92
|
+
);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
const u32be = (n) => {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
96
|
+
const b = Buffer.alloc(4);
|
|
97
|
+
b.writeUInt32BE(n >>> 0);
|
|
98
|
+
return b;
|
|
99
99
|
};
|
|
100
100
|
const u32le = (n) => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
const b = Buffer.alloc(4);
|
|
102
|
+
b.writeUInt32LE(n >>> 0);
|
|
103
|
+
return b;
|
|
104
104
|
};
|
|
105
105
|
const field = (tag, payload) => Buffer.concat([Buffer.from(tag, "latin1"), u32be(8 + payload.length), payload]);
|
|
106
106
|
const paddedName = (name) => {
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
const raw = Buffer.from(name + "\0", "latin1");
|
|
108
|
+
return Buffer.concat([raw, Buffer.alloc((4 - (raw.length % 4)) % 4)]);
|
|
109
109
|
};
|
|
110
110
|
|
|
111
111
|
/**
|
|
@@ -119,60 +119,60 @@ const paddedName = (name) => {
|
|
|
119
119
|
* @returns {Buffer}
|
|
120
120
|
*/
|
|
121
121
|
export function buildAmxd({ patcherJson, wrapperJs, deviceName, extras = [] }) {
|
|
122
|
-
|
|
122
|
+
assertES5(wrapperJs, "wrapper.js");
|
|
123
123
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
124
|
+
const amxdtype = JSON.parse(patcherJson).patcher?.project?.amxdtype;
|
|
125
|
+
const deviceTag = TAG_BY_CODE[amxdtype];
|
|
126
|
+
if (!deviceTag) throw new Error(`unknown project.amxdtype ${amxdtype}`);
|
|
127
127
|
|
|
128
|
-
|
|
128
|
+
const macDate = Math.floor(Date.now() / 1000) + 2082844800; // secs since 1904-01-01
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
130
|
+
const files = [
|
|
131
|
+
{ type: "JSON", name: deviceName, data: Buffer.from(patcherJson, "utf8"), flag: 0x11 },
|
|
132
|
+
{ type: "TEXT", name: "wrapper.js", data: Buffer.from(wrapperJs, "utf8"), flag: 0 },
|
|
133
|
+
...extras.map((e) => ({
|
|
134
|
+
type: e.type ?? (/\.(maxpat|json)$/.test(e.name) ? "JSON" : "TEXT"),
|
|
135
|
+
name: e.name,
|
|
136
|
+
data: e.data,
|
|
137
|
+
flag: 0,
|
|
138
|
+
})),
|
|
139
|
+
];
|
|
140
140
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
141
|
+
// Payload region: the patcher JSON first, at offset 16 (right after mx@c).
|
|
142
|
+
let offset = 16;
|
|
143
|
+
const entries = [];
|
|
144
|
+
for (const f of files) {
|
|
145
|
+
const at = offset;
|
|
146
|
+
offset += f.data.length;
|
|
147
|
+
entries.push(
|
|
148
|
+
field(
|
|
149
|
+
"dire",
|
|
150
|
+
Buffer.concat([
|
|
151
|
+
field("type", Buffer.from(f.type, "latin1")),
|
|
152
|
+
field("fnam", paddedName(f.name)),
|
|
153
|
+
field("sz32", u32be(f.data.length)),
|
|
154
|
+
field("of32", u32be(at)),
|
|
155
|
+
field("vers", u32be(0)),
|
|
156
|
+
field("flag", u32be(f.flag)),
|
|
157
|
+
field("mdat", u32be(macDate)),
|
|
158
|
+
]),
|
|
159
|
+
),
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
162
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
163
|
+
const payload = Buffer.concat(files.map((f) => f.data));
|
|
164
|
+
const mxc = Buffer.concat([Buffer.from("mx@c", "latin1"), u32be(16), u32be(0), u32be(16 + payload.length)]);
|
|
165
|
+
const ptchBody = Buffer.concat([mxc, payload, field("dlst", Buffer.concat(entries))]);
|
|
166
166
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
167
|
+
return Buffer.concat([
|
|
168
|
+
Buffer.from("ampf", "latin1"),
|
|
169
|
+
u32le(4),
|
|
170
|
+
Buffer.from(deviceTag, "latin1"),
|
|
171
|
+
Buffer.from("meta", "latin1"),
|
|
172
|
+
u32le(4),
|
|
173
|
+
u32le(7),
|
|
174
|
+
Buffer.from("ptch", "latin1"),
|
|
175
|
+
u32le(ptchBody.length),
|
|
176
|
+
ptchBody,
|
|
177
|
+
]);
|
|
178
178
|
}
|