@joplo-app/plugin-alda 0.0.0-stage → 0.4.1

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.
@@ -0,0 +1,30 @@
1
+ import type { LocalResourceInfo } from '@joplo-app/kit/plugin';
2
+ export declare const installSoundfont: () => Promise<void>;
3
+ export declare function inspectScore(score: string, directory: string): Promise<LocalResourceInfo>;
4
+ declare const _default: {
5
+ compilers: {
6
+ audio: {
7
+ requiresAttribution: true;
8
+ version: string;
9
+ mime: string;
10
+ timeoutMs: number;
11
+ inspect(input: string, ctx: {
12
+ directory: string;
13
+ }): Promise<LocalResourceInfo>;
14
+ compile(input: string, ctx: {
15
+ directory: string;
16
+ projectDir?: string;
17
+ keys: Readonly<Record<string, string>>;
18
+ cacheDir: string;
19
+ allowSpend?: boolean;
20
+ maxBytes: number;
21
+ }): Promise<{
22
+ bytes: Uint8Array<ArrayBufferLike>;
23
+ audio: import("@joplo-app/kit/plugin").AudioRegion;
24
+ credit: string;
25
+ license: string;
26
+ }>;
27
+ };
28
+ };
29
+ };
30
+ export default _default;
package/dist/local.js ADDED
@@ -0,0 +1,62 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import { execFile } from 'node:child_process';
4
+ import { soundfont, SOUNDFONT, credit } from "./soundfont.js";
5
+ import { createHash, randomUUID } from 'node:crypto';
6
+ import { encodeMusic, MP3_VERSION } from "./mp3.js";
7
+ import license from "./soundfont-license.js";
8
+ import { encodeFlac, renderPCM, RENDER_VERSION } from "./render.js";
9
+ export const installSoundfont = async () => { await soundfont(); console.log(`Installed ${SOUNDFONT.name}; SHA-256 ${SOUNDFONT.sha256}`); };
10
+ function request(input) {
11
+ const value = JSON.parse(input);
12
+ if (typeof value.score !== 'string' || typeof value.loop !== 'boolean')
13
+ throw new Error('Invalid music resource');
14
+ return value;
15
+ }
16
+ async function run(args, directory) {
17
+ return new Promise((resolve, reject) => execFile('alda', args, { cwd: directory, timeout: 25000, maxBuffer: 16 * 1024 * 1024 }, (error, stdout, stderr) => {
18
+ if (error)
19
+ reject(Object.assign(new Error(error.code === 'ENOENT' ? 'Alda is not installed or not on PATH. Install Alda 2.4.8, then run joplo check again; other checks continue.' : `Alda failed: ${(stderr || stdout || error.message).replaceAll(directory, '<temporary>').slice(0, 1500)}`), { code: error.killed ? 'LOCAL_RESOURCE_TIMEOUT' : 'LOCAL_RESOURCE_FAILED' }));
20
+ else
21
+ resolve(stdout);
22
+ }));
23
+ }
24
+ export async function inspectScore(score, directory) {
25
+ const source = path.join(directory, 'score.alda');
26
+ await fs.writeFile(source, score);
27
+ const parsed = JSON.parse(await run(['parse', '-f', source, '-o', 'data'], directory));
28
+ const parts = {};
29
+ let durationMs = 0;
30
+ for (const [id, p] of Object.entries(parsed.parts)) {
31
+ parts[`${p.name} (${id})`] = parsed.events.filter((e) => e.part === id && typeof e['midi-note'] === 'number').length;
32
+ durationMs = Math.max(durationMs, p['current-offset']);
33
+ }
34
+ if (!Number.isFinite(durationMs) || durationMs <= 0)
35
+ throw new Error('Score contains no timed music');
36
+ return { durationMs, parts, markers: parsed.markers, credit };
37
+ }
38
+ export default { compilers: { audio: {
39
+ requiresAttribution: true, version: `alda-2.4.8-${RENDER_VERSION}-${SOUNDFONT.sha256}-${MP3_VERSION}`, mime: 'audio/mpeg', timeoutMs: 180000,
40
+ async inspect(input, ctx) { return inspectScore(request(input).score, ctx.directory); },
41
+ async compile(input, ctx) {
42
+ const { score, loop } = request(input);
43
+ const version = (await run(['version'], ctx.directory)).trim();
44
+ if (version !== 'alda 2.4.8')
45
+ throw new Error(`Expected Alda 2.4.8; found ${version}`);
46
+ const info = await inspectScore(score, ctx.directory);
47
+ const output = path.join(ctx.directory, 'score.mid');
48
+ await run(['export', '-f', path.join(ctx.directory, 'score.alda'), '-o', output], ctx.directory);
49
+ const pcm = await renderPCM(await fs.readFile(output), await soundfont(ctx.cacheDir), info.durationMs, loop);
50
+ const master = await encodeFlac(pcm);
51
+ const masters = path.join(ctx.projectDir ?? ctx.directory, '.joplo', 'music-masters');
52
+ await fs.mkdir(masters, { recursive: true });
53
+ const key = createHash('sha256').update(JSON.stringify([score, loop, RENDER_VERSION, SOUNDFONT.sha256])).digest('hex');
54
+ const tmp = path.join(masters, `${key}.${randomUUID()}.tmp`);
55
+ await fs.writeFile(tmp, master);
56
+ await fs.rename(tmp, path.join(masters, `${key}.flac`));
57
+ const { bytes, audio } = await encodeMusic(pcm, Math.round(info.durationMs * 44100 / 1000), loop);
58
+ if (bytes.length > ctx.maxBytes)
59
+ throw Object.assign(new Error('Rendered audio exceeds resource size limit'), { code: 'LOCAL_RESOURCE_TOO_LARGE' });
60
+ return { bytes, audio, credit, license };
61
+ },
62
+ } } };
package/dist/mp3.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ import type { AudioRegion } from '@joplo-app/kit/plugin';
2
+ export declare const MP3_VERSION = "breezystack-lamejs-1.2.7-mpg123-decoder-1.0.3-stereo96-32000-sinc24-phase256-probe1600-silence640-guard3840-correlation-v1-runtime-seam3ms";
3
+ /** A deterministic out-of-band probe measures the decoder's delay; it is excluded from the public playback region. */
4
+ export declare function measureDelay(reference: Float32Array, decoded: Float32Array): number;
5
+ export declare function encodeMusic(pcm: Float32Array[], cycleFrames: number, loop: boolean): Promise<{
6
+ bytes: Uint8Array;
7
+ audio: AudioRegion;
8
+ }>;
package/dist/mp3.js ADDED
@@ -0,0 +1,78 @@
1
+ import { Mp3Encoder } from '@breezystack/lamejs';
2
+ import { MPEGDecoder } from 'mpg123-decoder';
3
+ const SAMPLE_RATE = 32000;
4
+ export const MP3_VERSION = 'breezystack-lamejs-1.2.7-mpg123-decoder-1.0.3-stereo96-32000-sinc24-phase256-probe1600-silence640-guard3840-correlation-v1-runtime-seam3ms';
5
+ /** Fixed anti-aliasing resampler, 24 taps and 256 fractional phases. */
6
+ function resample(input) {
7
+ const ratio = 32000 / 44100, cutoff = ratio * .92;
8
+ const weights = Array.from({ length: 256 }, (_, phase) => Float64Array.from({ length: 24 }, (_, j) => { const x = j - 11 - phase / 256; return (Math.abs(x) < 1e-9 ? cutoff : Math.sin(Math.PI * x * cutoff) / (Math.PI * x)) * (.5 + .5 * Math.cos(Math.PI * x / 12)); }));
9
+ return Float32Array.from({ length: Math.round(input.length * ratio) }, (_, i) => {
10
+ const position = i / ratio, base = Math.floor(position), w = weights[Math.min(255, Math.round((position - base) * 256))];
11
+ let sum = 0, norm = 0;
12
+ for (let j = 0; j < 24; j++) {
13
+ sum += input[Math.max(0, Math.min(input.length - 1, base + j - 11))] * w[j];
14
+ norm += w[j];
15
+ }
16
+ return sum / norm;
17
+ });
18
+ }
19
+ /** A deterministic out-of-band probe measures the decoder's delay; it is excluded from the public playback region. */
20
+ export function measureDelay(reference, decoded) {
21
+ let best = -Infinity, lag = 0;
22
+ for (let shift = 0; shift <= 4096; shift++) {
23
+ let dot = 0, energy = 0;
24
+ for (let i = 0; i < reference.length; i++) {
25
+ const x = decoded[i + shift] ?? 0;
26
+ dot += reference[i] * x;
27
+ energy += x * x;
28
+ }
29
+ const score = dot / Math.sqrt(energy || 1);
30
+ if (score > best) {
31
+ best = score;
32
+ lag = shift;
33
+ }
34
+ }
35
+ if (best < .5)
36
+ throw new Error('MP3 delay calibration failed');
37
+ return lag;
38
+ }
39
+ export async function encodeMusic(pcm, cycleFrames, loop) {
40
+ pcm = pcm.map(resample);
41
+ cycleFrames = Math.round(cycleFrames * 32000 / 44100);
42
+ const probeLength = 1600, gap = 640, guard = 3840, head = probeLength + gap + guard, tail = guard;
43
+ let seed = 13919;
44
+ const probe = Float32Array.from({ length: probeLength }, () => { seed = (Math.imul(seed, 1664525) + 1013904223) >>> 0; return (seed / 4294967296 - .5) * .3; });
45
+ const frames = pcm[0].length;
46
+ const input = pcm.map(ch => {
47
+ const out = new Float32Array(head + frames + tail);
48
+ out.set(probe);
49
+ if (loop)
50
+ for (let i = 0; i < guard; i++)
51
+ out[probeLength + gap + i] = ch[((frames - guard + i) % frames + frames) % frames];
52
+ out.set(ch, head);
53
+ if (loop)
54
+ for (let i = 0; i < tail; i++)
55
+ out[head + frames + i] = ch[i % frames];
56
+ return Int16Array.from(out, x => Math.round(Math.max(-1, Math.min(1, x)) * 32767));
57
+ });
58
+ const encoder = new Mp3Encoder(2, SAMPLE_RATE, 96), chunks = [];
59
+ for (let i = 0; i < input[0].length; i += 1152)
60
+ chunks.push(Uint8Array.from(encoder.encodeBuffer(input[0].subarray(i, i + 1152), input[1].subarray(i, i + 1152))));
61
+ chunks.push(Uint8Array.from(encoder.flush()));
62
+ const bytes = new Uint8Array(Buffer.concat(chunks));
63
+ const decoder = new MPEGDecoder();
64
+ await decoder.ready;
65
+ try {
66
+ const decoded = decoder.decode(bytes);
67
+ if (decoded.sampleRate !== SAMPLE_RATE || decoded.errors.length)
68
+ throw new Error('MP3 verification decode failed: ' + JSON.stringify({ sampleRate: decoded.sampleRate, errors: decoded.errors, samples: decoded.samplesDecoded }));
69
+ const delay = measureDelay(probe, decoded.channelData[0]);
70
+ const audio = { sourceSampleRate: SAMPLE_RATE, cycleFrames, contentStartFrame: head + delay, contentFrames: frames, decodedFrames: decoded.samplesDecoded, encoderDelayFrames: delay, paddingFrames: decoded.samplesDecoded - input[0].length - delay, channels: 2 };
71
+ if (audio.paddingFrames < 0 || audio.contentStartFrame + frames > audio.decodedFrames)
72
+ throw new Error('MP3 region exceeds decoded samples');
73
+ return { bytes, audio };
74
+ }
75
+ finally {
76
+ decoder.free();
77
+ }
78
+ }
@@ -0,0 +1,6 @@
1
+ export declare const SAMPLE_RATE = 44100;
2
+ export declare const RENDER_VERSION = "spessasynth_core-4.4.9-stb-vorbis-0.0.7-libflacjs-5.6.0-flac16-44100-v2";
3
+ /** Add every release/reverb sample into the following cycle, never append a silent tail to a loop. */
4
+ export declare function wrapTail(pcm: Float32Array, cycle: number): Float32Array;
5
+ export declare function renderPCM(midiBytes: Uint8Array, bankBytes: Uint8Array, durationMs: number, loop: boolean): Promise<Float32Array<ArrayBufferLike>[]>;
6
+ export declare function encodeFlac(channels: Float32Array[]): Promise<Uint8Array<ArrayBuffer>>;
package/dist/render.js ADDED
@@ -0,0 +1,120 @@
1
+ import { StbVorbis } from 'stb-vorbis';
2
+ import { BasicSoundBank, BasicMIDI, SoundBankLoader, SpessaLog, SpessaSynthProcessor, SpessaSynthSequencer } from 'spessasynth_core';
3
+ import * as FlacModule from 'libflacjs/dist/libflac.js';
4
+ export const SAMPLE_RATE = 44100;
5
+ // Also embedded in the host bundle/cache key. Bump for ANY signal processing change.
6
+ export const RENDER_VERSION = 'spessasynth_core-4.4.9-stb-vorbis-0.0.7-libflacjs-5.6.0-flac16-44100-v2';
7
+ /** Add every release/reverb sample into the following cycle, never append a silent tail to a loop. */
8
+ export function wrapTail(pcm, cycle) {
9
+ const out = pcm.slice(0, cycle);
10
+ for (let i = cycle; i < pcm.length; i++)
11
+ out[i % cycle] += pcm[i];
12
+ // A 3ms endpoint correction removes the jump without a silence-producing crossfade.
13
+ const window = Math.min(128, Math.floor(cycle / 2));
14
+ const first = out[0], last = out[cycle - 1], mid = (first + last) / 2;
15
+ for (let i = 0; i < window; i++) {
16
+ const weight = .5 + .5 * Math.cos(Math.PI * i / window);
17
+ out[i] += (mid - first) * weight;
18
+ out[cycle - 1 - i] += (mid - last) * weight;
19
+ }
20
+ return out;
21
+ }
22
+ export async function renderPCM(midiBytes, bankBytes, durationMs, loop) {
23
+ SpessaLog.setLogLevel(false, false, false);
24
+ // Upstream declares a floating decoder range. Refuse a second decoder instance/version instead of changing bytes silently.
25
+ if (BasicSoundBank.ready !== StbVorbis.ready)
26
+ throw new Error('SpessaSynth resolved a different SF3 decoder. Pin its stb-vorbis dependency to 0.0.7 using your package manager overrides, reinstall, and retry.');
27
+ await BasicSoundBank.ready;
28
+ const midi = BasicMIDI.fromArrayBuffer(Uint8Array.from(midiBytes).buffer);
29
+ const bank = SoundBankLoader.fromArrayBuffer(Uint8Array.from(bankBytes).buffer);
30
+ const synth = new SpessaSynthProcessor(SAMPLE_RATE, { eventsEnabled: false, effectsEnabled: true });
31
+ synth.soundBankManager.addSoundBank(bank, 'gm');
32
+ await synth.ready;
33
+ synth.setSystemParameter('autoAllocateVoices', true);
34
+ const seq = new SpessaSynthSequencer(synth);
35
+ seq.loadNewSongList([midi]);
36
+ seq.loopCount = 0;
37
+ seq.play();
38
+ const cycle = Math.max(1, Math.round(durationMs * SAMPLE_RATE / 1000));
39
+ if (cycle > SAMPLE_RATE * 600)
40
+ throw new Error('Music exceeds 10 minutes; split the score into named pieces');
41
+ const count = cycle + SAMPLE_RATE * 12;
42
+ const left = new Float32Array(count), right = new Float32Array(count);
43
+ let silent = 0, end = count;
44
+ for (let i = 0; i < count; i += 128) {
45
+ seq.processTick();
46
+ const size = Math.min(128, count - i);
47
+ synth.process(left, right, i, size);
48
+ if (i >= cycle) {
49
+ let peak = 0;
50
+ for (let j = i; j < i + size; j++)
51
+ peak = Math.max(peak, Math.abs(left[j]), Math.abs(right[j]));
52
+ silent = peak < .0001 ? silent + size : 0;
53
+ if (silent >= SAMPLE_RATE / 4) {
54
+ end = i + size;
55
+ break;
56
+ }
57
+ }
58
+ }
59
+ const channels = [left.slice(0, end), right.slice(0, end)];
60
+ for (let c = 0; c < channels.length; c++) {
61
+ let pcm = channels[c];
62
+ if (loop)
63
+ pcm = wrapTail(pcm, cycle);
64
+ else {
65
+ // Includes all release/reverb down to -80dB, with a 20ms guard fade (also bounds pathological sustained presets).
66
+ const fade = Math.min(882, pcm.length);
67
+ for (let i = 0; i < fade; i++)
68
+ pcm[pcm.length - 1 - i] *= i / fade;
69
+ }
70
+ for (let i = 0; i < pcm.length; i++)
71
+ pcm[i] = Math.tanh(pcm[i] * .7) * .95;
72
+ channels[c] = pcm;
73
+ }
74
+ // Normalize musical energy once per piece, preserving its internal dynamics and stereo balance.
75
+ // Sparse GM presets otherwise land around -40 LUFS before track gain/ducking.
76
+ let energy = 0, peak = 0;
77
+ for (const ch of channels)
78
+ for (let i = 0; i < ch.length; i++) {
79
+ peak = Math.max(peak, Math.abs(ch[i]));
80
+ if (i < cycle)
81
+ energy += ch[i] * ch[i];
82
+ }
83
+ const rms = Math.sqrt(energy / (cycle * channels.length));
84
+ const gain = rms > .000001 ? Math.min(.1 / rms, .891 / peak) : 1;
85
+ for (const ch of channels)
86
+ for (let i = 0; i < ch.length; i++)
87
+ ch[i] *= gain;
88
+ return channels;
89
+ }
90
+ export async function encodeFlac(channels) {
91
+ // Standalone asm.js variant has no WASM/mem sidecar to relocate into disposable resource jobs.
92
+ const Flac = ('default' in FlacModule ? FlacModule.default : FlacModule);
93
+ if (!Flac.isReady())
94
+ await new Promise(resolve => Flac.on('ready', () => resolve()));
95
+ const samples = channels[0].length, chunks = [];
96
+ const encoder = Flac.create_libflac_encoder(SAMPLE_RATE, channels.length, 16, 5, samples, true);
97
+ if (!encoder)
98
+ throw new Error('FLAC encoder allocation failed');
99
+ let md5 = '';
100
+ try {
101
+ if (Flac.init_encoder_stream(encoder, bytes => { chunks.push(Uint8Array.from(bytes)); }, meta => { md5 = meta?.md5sum ?? ''; }) !== 0)
102
+ throw new Error('FLAC encoder initialization failed');
103
+ for (let start = 0; start < samples; start += 16384) {
104
+ const chunk = channels.map(ch => Int32Array.from(ch.subarray(start, start + 16384), x => Math.round(Math.max(-1, Math.min(1, x)) * 32767)));
105
+ if (!Flac.FLAC__stream_encoder_process(encoder, chunk, chunk[0].length))
106
+ throw new Error('FLAC PCM encoding failed');
107
+ }
108
+ if (!Flac.FLAC__stream_encoder_finish(encoder))
109
+ throw new Error('FLAC finalization failed');
110
+ const bytes = Buffer.concat(chunks);
111
+ // A streaming sink cannot seek back: finalize native FLAC STREAMINFO length and PCM MD5.
112
+ bytes.writeBigUInt64BE((bytes.readBigUInt64BE(18) & ~0xfffffffffn) | BigInt(samples), 18);
113
+ if (md5.length === 32)
114
+ bytes.set(Buffer.from(md5, 'hex'), 26);
115
+ return new Uint8Array(bytes);
116
+ }
117
+ finally {
118
+ Flac.FLAC__stream_encoder_delete(encoder);
119
+ }
120
+ }
@@ -0,0 +1,3 @@
1
+ /** Audio decoding/playback belongs to the host's generic media layer. */
2
+ declare const _default: import("@joplo-app/kit/plugin").PluginRuntime;
3
+ export default _default;
@@ -0,0 +1,3 @@
1
+ import { defineRuntime } from '@joplo-app/kit/plugin';
2
+ /** Audio decoding/playback belongs to the host's generic media layer. */
3
+ export default defineRuntime({ id: 'alda', components: {} });
@@ -0,0 +1,2 @@
1
+ declare const _default: "FluidR3Mono_GM.sf3\r\n---\r\n\r\nCurrent version: 2.312 5th December 2016\r\n\r\nOriginal Stereo version by Frank Wen Copyright \u00A9 2000-2002\r\n\r\nMono version by Michael Cowgill Copyright \u00A9 2014-16\r\n\r\nTemple Blocks instrument provided by Ethan Winer Copyright \u00A9 2002\r\n\r\nDrumline Percussion provided by Michael Schorsch Copyright \u00A9 2016\r\n\r\nThis Mono version of FluidR3 GM is released under the MIT license as described in COPYING\r\n\r\nThe COPYING and README files from the original FluidR3GM file are now displayed here for reference.\r\n\r\nThe acknowledgements and copyright notices above should be included in any derivative work.\r\n\r\n\r\nREADME\r\n---\r\n\r\nFluid (R3) SoundFont\r\n\r\nCopyright (c) 2000-2002, 2008 Frank Wen <getfrank@gmail.com>\r\n\r\nI hereby release Fluid under the MIT license, as described in COPYING.\r\n\r\n\r\nThanks to Toby Smithe for helping to get Fluid included in Ubuntu.\r\n\r\nThis package, of course, is the original Release 3 of Fluid. \r\n\r\n\r\nFluid was constructed in part from samples found in the public domain that I\r\nedited/cleaned/remixed/programmed and largely from recordings of my own and\r\nin conjunction with the people below who helped along the way:\r\n\r\nSuren M. Seron\r\nScott Hanan\r\nSteve Aupperle\r\nChris Gillman\r\nAlex Taubr\r\nChris Prola\r\nAndrew Klenk\r\nWinfried Hubbe \r\nDylan\r\nTim\r\nGort\r\nUros Katic \r\nEthan Winer (http://www.ethanwiner.com) \r\n\r\n\r\nIt's obviously been a few years since the project, but its nice to see that\r\npeople are still enjoying my work and getting good use out of it. As always,\r\nI'd like to hear some work done with Fluid so email me, or just email me to\r\nsay hello and tell me what is going on in the computer musician world.\r\nWho knows, maybe I'll kick start this project again? ;)\r\n\r\n\r\nCOPYING\r\n---\r\n\r\nMono version: Copyright (c) 2014-16 Michael Cowgill \r\nCopyright (c) 2000-2002, 2008 Frank Wen <getfrank@gmail.com>\r\n\r\nPermission is hereby granted, free of charge, to any person\r\nobtaining a copy of this software and associated documentation\r\nfiles (the \"Software\"), to deal in the Software without\r\nrestriction, including without limitation the rights to use,\r\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the\r\nSoftware is furnished to do so, subject to the following\r\nconditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\r\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\r\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r\nOTHER DEALINGS IN THE SOFTWARE.\r\n\r\n";
2
+ export default _default;
@@ -0,0 +1 @@
1
+ export default "FluidR3Mono_GM.sf3\r\n---\r\n\r\nCurrent version: 2.312 5th December 2016\r\n\r\nOriginal Stereo version by Frank Wen Copyright \u00a9 2000-2002\r\n\r\nMono version by Michael Cowgill Copyright \u00a9 2014-16\r\n\r\nTemple Blocks instrument provided by Ethan Winer Copyright \u00a9 2002\r\n\r\nDrumline Percussion provided by Michael Schorsch Copyright \u00a9 2016\r\n\r\nThis Mono version of FluidR3 GM is released under the MIT license as described in COPYING\r\n\r\nThe COPYING and README files from the original FluidR3GM file are now displayed here for reference.\r\n\r\nThe acknowledgements and copyright notices above should be included in any derivative work.\r\n\r\n\r\nREADME\r\n---\r\n\r\nFluid (R3) SoundFont\r\n\r\nCopyright (c) 2000-2002, 2008 Frank Wen <getfrank@gmail.com>\r\n\r\nI hereby release Fluid under the MIT license, as described in COPYING.\r\n\r\n\r\nThanks to Toby Smithe for helping to get Fluid included in Ubuntu.\r\n\r\nThis package, of course, is the original Release 3 of Fluid. \r\n\r\n\r\nFluid was constructed in part from samples found in the public domain that I\r\nedited/cleaned/remixed/programmed and largely from recordings of my own and\r\nin conjunction with the people below who helped along the way:\r\n\r\nSuren M. Seron\r\nScott Hanan\r\nSteve Aupperle\r\nChris Gillman\r\nAlex Taubr\r\nChris Prola\r\nAndrew Klenk\r\nWinfried Hubbe \r\nDylan\r\nTim\r\nGort\r\nUros Katic \r\nEthan Winer (http://www.ethanwiner.com) \r\n\r\n\r\nIt's obviously been a few years since the project, but its nice to see that\r\npeople are still enjoying my work and getting good use out of it. As always,\r\nI'd like to hear some work done with Fluid so email me, or just email me to\r\nsay hello and tell me what is going on in the computer musician world.\r\nWho knows, maybe I'll kick start this project again? ;)\r\n\r\n\r\nCOPYING\r\n---\r\n\r\nMono version: Copyright (c) 2014-16 Michael Cowgill \r\nCopyright (c) 2000-2002, 2008 Frank Wen <getfrank@gmail.com>\r\n\r\nPermission is hereby granted, free of charge, to any person\r\nobtaining a copy of this software and associated documentation\r\nfiles (the \"Software\"), to deal in the Software without\r\nrestriction, including without limitation the rights to use,\r\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\r\ncopies of the Software, and to permit persons to whom the\r\nSoftware is furnished to do so, subject to the following\r\nconditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\r\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\r\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\r\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\r\nOTHER DEALINGS IN THE SOFTWARE.\r\n\r\n";
@@ -0,0 +1,88 @@
1
+ FluidR3Mono_GM.sf3
2
+ ---
3
+
4
+ Current version: 2.312 5th December 2016
5
+
6
+ Original Stereo version by Frank Wen Copyright © 2000-2002
7
+
8
+ Mono version by Michael Cowgill Copyright © 2014-16
9
+
10
+ Temple Blocks instrument provided by Ethan Winer Copyright © 2002
11
+
12
+ Drumline Percussion provided by Michael Schorsch Copyright © 2016
13
+
14
+ This Mono version of FluidR3 GM is released under the MIT license as described in COPYING
15
+
16
+ The COPYING and README files from the original FluidR3GM file are now displayed here for reference.
17
+
18
+ The acknowledgements and copyright notices above should be included in any derivative work.
19
+
20
+
21
+ README
22
+ ---
23
+
24
+ Fluid (R3) SoundFont
25
+
26
+ Copyright (c) 2000-2002, 2008 Frank Wen <getfrank@gmail.com>
27
+
28
+ I hereby release Fluid under the MIT license, as described in COPYING.
29
+
30
+
31
+ Thanks to Toby Smithe for helping to get Fluid included in Ubuntu.
32
+
33
+ This package, of course, is the original Release 3 of Fluid.
34
+
35
+
36
+ Fluid was constructed in part from samples found in the public domain that I
37
+ edited/cleaned/remixed/programmed and largely from recordings of my own and
38
+ in conjunction with the people below who helped along the way:
39
+
40
+ Suren M. Seron
41
+ Scott Hanan
42
+ Steve Aupperle
43
+ Chris Gillman
44
+ Alex Taubr
45
+ Chris Prola
46
+ Andrew Klenk
47
+ Winfried Hubbe
48
+ Dylan
49
+ Tim
50
+ Gort
51
+ Uros Katic
52
+ Ethan Winer (http://www.ethanwiner.com)
53
+
54
+
55
+ It's obviously been a few years since the project, but its nice to see that
56
+ people are still enjoying my work and getting good use out of it. As always,
57
+ I'd like to hear some work done with Fluid so email me, or just email me to
58
+ say hello and tell me what is going on in the computer musician world.
59
+ Who knows, maybe I'll kick start this project again? ;)
60
+
61
+
62
+ COPYING
63
+ ---
64
+
65
+ Mono version: Copyright (c) 2014-16 Michael Cowgill
66
+ Copyright (c) 2000-2002, 2008 Frank Wen <getfrank@gmail.com>
67
+
68
+ Permission is hereby granted, free of charge, to any person
69
+ obtaining a copy of this software and associated documentation
70
+ files (the "Software"), to deal in the Software without
71
+ restriction, including without limitation the rights to use,
72
+ copy, modify, merge, publish, distribute, sublicense, and/or sell
73
+ copies of the Software, and to permit persons to whom the
74
+ Software is furnished to do so, subject to the following
75
+ conditions:
76
+
77
+ The above copyright notice and this permission notice shall be
78
+ included in all copies or substantial portions of the Software.
79
+
80
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
81
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
82
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
83
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
84
+ HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
85
+ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
86
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
87
+ OTHER DEALINGS IN THE SOFTWARE.
88
+
@@ -0,0 +1,12 @@
1
+ export declare const SOUNDFONT: {
2
+ name: string;
3
+ url: string;
4
+ sha256: string;
5
+ licenseUrl: string;
6
+ licenseSha256: string;
7
+ };
8
+ export declare const credit: string;
9
+ export declare const sha256: (data: Uint8Array | string) => string;
10
+ /** cacheDir is the alda plugin's private cache (JOPLO_HOME/plugins/alda/cache), not JOPLO_HOME itself. */
11
+ export declare const defaultCacheDir: () => string;
12
+ export declare function soundfont(cacheDir?: string): Promise<NonSharedBuffer>;
@@ -0,0 +1,55 @@
1
+ import fs from 'node:fs/promises';
2
+ import path from 'node:path';
3
+ import os from 'node:os';
4
+ import { createHash, randomUUID } from 'node:crypto';
5
+ const BASE = 'https://raw.githubusercontent.com/LibreScore/sf3/3a6eda823dac2ec3e134d38544ca839217358f08';
6
+ export const SOUNDFONT = {
7
+ name: 'FluidR3Mono GM 2.312',
8
+ url: `${BASE}/FluidR3Mono_GM.sf3.wasm`,
9
+ sha256: 'cfcd66d89e8386823400eca64934b14fbea7bf48ba1f00d21189af1262794ec2',
10
+ licenseUrl: `${BASE}/FluidR3Mono_License.md`,
11
+ licenseSha256: 'c21ed6be2fea862673953977c616befc28d1b20dfa60349e4461b97c759db6ca',
12
+ };
13
+ export const credit = `${SOUNDFONT.name} (MIT). Original SoundFont © 2000–2002, 2008 Frank Wen; mono version © 2014–2016 Michael Cowgill; Temple Blocks © 2002 Ethan Winer; Drumline Percussion © 2016 Michael Schorsch. Source and license: ${SOUNDFONT.licenseUrl}`;
14
+ export const sha256 = (data) => createHash('sha256').update(data).digest('hex');
15
+ /** cacheDir is the alda plugin's private cache (JOPLO_HOME/plugins/alda/cache), not JOPLO_HOME itself. */
16
+ export const defaultCacheDir = () => path.join(process.env.JOPLO_HOME || path.join(os.homedir(), '.joplo'), 'plugins', 'alda', 'cache');
17
+ export async function soundfont(cacheDir = defaultCacheDir()) {
18
+ const directory = path.join(cacheDir, 'soundfonts', SOUNDFONT.sha256);
19
+ await fs.mkdir(directory, { recursive: true });
20
+ const load = async (name, url, hash, maxBytes) => {
21
+ const file = path.join(directory, name);
22
+ try {
23
+ const data = await fs.readFile(file);
24
+ if (sha256(data) === hash)
25
+ return data;
26
+ }
27
+ catch { /* first use */ }
28
+ try {
29
+ const response = await fetch(url, { signal: AbortSignal.timeout(120000) });
30
+ if (!response.ok || Number(response.headers.get('content-length')) > maxBytes)
31
+ throw new Error(`HTTP ${response.status}`);
32
+ const chunks = [];
33
+ let length = 0;
34
+ for await (const chunk of response.body) {
35
+ length += chunk.length;
36
+ if (length > maxBytes)
37
+ throw new Error('Download exceeds size limit');
38
+ chunks.push(chunk);
39
+ }
40
+ const data = Buffer.concat(chunks);
41
+ if (sha256(data) !== hash)
42
+ throw new Error('SHA-256 mismatch');
43
+ const tmp = `${file}.${randomUUID()}.tmp`;
44
+ await fs.writeFile(tmp, data);
45
+ await fs.rename(tmp, file);
46
+ return data;
47
+ }
48
+ catch (e) {
49
+ throw new Error(`SoundFont cache missing or invalid; download failed (${e.message}). Connect to the internet and run: node --input-type=module -e "import('@joplo-app/plugin-alda/local').then(m=>m.installSoundfont())". For offline use, copy the verified soundfonts/${SOUNDFONT.sha256}/ directory into JOPLO_HOME/plugins/alda/cache/ on this machine.`);
50
+ }
51
+ };
52
+ // Keep the exact license beside the bank; no bank is usable without its verified license.
53
+ await load('LICENSE.md', SOUNDFONT.licenseUrl, SOUNDFONT.licenseSha256, 64 * 1024);
54
+ return load('FluidR3Mono_GM.sf3', SOUNDFONT.url, SOUNDFONT.sha256, 16 * 1024 * 1024);
55
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "version": "0.4.1"
3
+ }
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@joplo-app/plugin-alda",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.4.1",
4
+ "type": "module",
5
+ "joplo": {
6
+ "api": 2
7
+ },
8
+ "exports": {
9
+ ".": {
10
+ "types": "./dist/index.d.ts",
11
+ "default": "./dist/index.js"
12
+ },
13
+ "./local": {
14
+ "types": "./dist/local.d.ts",
15
+ "default": "./dist/local.js"
16
+ },
17
+ "./runtime": {
18
+ "types": "./dist/runtime.d.ts",
19
+ "default": "./dist/runtime.js"
20
+ },
21
+ "./guide": {
22
+ "types": "./dist/guide.d.ts",
23
+ "default": "./dist/guide.js"
24
+ },
25
+ "./package.json": "./package.json"
26
+ },
27
+ "dependencies": {
28
+ "@breezystack/lamejs": "1.2.7",
29
+ "@joplo-app/kit": "0.4.1",
30
+ "libflacjs": "5.6.0",
31
+ "mpg123-decoder": "1.0.3",
32
+ "spessasynth_core": "4.4.9",
33
+ "stb-vorbis": "0.0.7"
34
+ },
35
+ "description": "Joplo optional text-authored background music and offline SoundFont audio rendering",
36
+ "license": "PolyForm-Shield-1.0.0",
37
+ "repository": {
38
+ "type": "git",
39
+ "url": "git+https://github.com/Joplo-app/Joplo.git",
40
+ "directory": "plugins/alda"
41
+ },
42
+ "engines": {
43
+ "node": ">=22"
44
+ },
45
+ "files": [
46
+ "dist"
47
+ ],
48
+ "publishConfig": {
49
+ "access": "public"
50
+ },
51
+ "scripts": {
52
+ "build": "node ../../scripts/build-package.mjs"
53
+ }
6
54
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.