87 lines
6.6 KiB
PHP
87 lines
6.6 KiB
PHP
{{-- PL0XION strudel-live 🎛️ — LIVE CODING MUSICAL (rs-4, spec MUSICION de RS-7, §3 prio 1, Voie A
|
|
D1 direct). Strudel = portage JS de TidalCycles, 100% navigateur (Web Audio). Éditeur + évaluer
|
|
(Ctrl+↵) + hush. Contrat bus/tsoin EXACT de la spec : music.pattern.eval (tsoin), music.pattern.active,
|
|
music.session.start/stop. Cœur chargé depuis unpkg (CSP déclaré) ; dégrade proprement si absent
|
|
(droit au silence §4.4 : l'AudioContext est coupé à l'unmount). Persistance jos:strudel-live:last-pattern. --}}
|
|
<style>
|
|
.sdl{display:flex;flex-direction:column;height:100%;background:#080a12;color:#e6ecff;font-family:var(--xr-font-ui,ui-sans-serif,system-ui);overflow:hidden}
|
|
.sdl__h{flex:0 0 auto;display:flex;gap:8px;align-items:center;padding:8px 11px;border-bottom:1px solid #1a2340}
|
|
.sdl__h b{color:#8f7bff;font-weight:800}
|
|
.sdl__btn{cursor:pointer;border:0;border-radius:8px;background:#8f7bff;color:#08040f;font:inherit;font-weight:800;font-size:.78rem;padding:7px 13px}
|
|
.sdl__btn.sec{background:rgba(40,40,70,.7);color:#cdd0f0;border:1px solid #33385c;font-weight:600}
|
|
.sdl__st{margin-left:auto;font-size:.68rem;color:#8b90c0}
|
|
.sdl__st.ok{color:#6affc0}.sdl__st.err{color:#ff8a6a}
|
|
.sdl__ed{flex:1;min-height:0;width:100%;background:#0a0d18;border:0;outline:0;color:#d8e0ff;font:14px/1.55 ui-monospace,SFMono-Regular,monospace;padding:12px 14px;resize:none;tab-size:2}
|
|
.sdl__log{flex:0 0 auto;padding:6px 12px;border-top:1px solid #1a2340;font:.68rem ui-monospace,monospace;color:#7f86b8;white-space:pre-wrap;max-height:70px;overflow:auto}
|
|
</style>
|
|
<script>
|
|
(function () {
|
|
'use strict';
|
|
var CDN = 'https://unpkg.com/@strudel/web@1.1.0';
|
|
var KEY = 'jos:strudel-live:last-pattern';
|
|
var DEFAULT = 'note("c3 eb3 g3 bb3".fast(2)).s("sawtooth").cutoff(sine.range(300,2000).slow(4)).room(.4)';
|
|
|
|
var LIVE = null; // posé au mount : { started, code }
|
|
function describe() {
|
|
var started = LIVE ? LIVE.started() : false;
|
|
var code = LIVE ? LIVE.code() : (function () { try { return localStorage.getItem(KEY) || DEFAULT; } catch (e) { return DEFAULT; } })();
|
|
return { v: 1, id: 'strudel-live', title: 'Strudel', icon: '🎛️', items: [
|
|
{ p: 1, kind: 'stat', label: started ? '▶ joue' : 'pattern', value: (code || '').slice(0, 60) }
|
|
] };
|
|
}
|
|
function mount(container, ctx) {
|
|
container.innerHTML = '<div class="sdl"><div class="sdl__h"><b>🎛️ Strudel</b>'
|
|
+ '<button class="sdl__btn" data-eval>▶ évaluer <small style="opacity:.7">Ctrl+↵</small></button>'
|
|
+ '<button class="sdl__btn sec" data-hush>■ hush</button>'
|
|
+ '<span class="sdl__st" data-st>chargement du moteur…</span></div>'
|
|
+ '<textarea class="sdl__ed" data-ed spellcheck="false"></textarea>'
|
|
+ '<div class="sdl__log" data-log>live coding musical — patterns cycliques. Ctrl+Entrée pour (ré)évaluer.</div></div>';
|
|
var ed = container.querySelector('[data-ed]'), st = container.querySelector('[data-st]'), log = container.querySelector('[data-log]');
|
|
ed.value = (function () { try { return localStorage.getItem(KEY) || DEFAULT; } catch (e) { return DEFAULT; } })();
|
|
var evaluate = null, hush = null, started = false, alive = true;
|
|
function setSt(t, cls) { st.textContent = t; st.className = 'sdl__st' + (cls ? ' ' + cls : ''); }
|
|
function emit(ev, o) { try { window.jOSPorts && jOSPorts.emit('music', ev, o || {}); } catch (e) {} }
|
|
function tmark(code) { try { (window.__tsoinMark || (window.jOSTsoin && window.jOSTsoin.mark))('music.pattern.eval', code.slice(0, 90)); } catch (e) {} }
|
|
|
|
// chargement du cœur Strudel (Voie A) — CSP déclare unpkg + unsafe-eval + blob
|
|
import(CDN).then(function (mod) {
|
|
if (!alive) return;
|
|
var init = mod.initStrudel || mod.default;
|
|
return Promise.resolve(init && init()).then(function () {
|
|
evaluate = mod.evaluate || window.evaluate; hush = mod.hush || window.hush;
|
|
if (!evaluate) throw new Error('API evaluate introuvable');
|
|
setSt('prêt · Web Audio', 'ok'); log.textContent = 'moteur prêt. Édite le pattern → Ctrl+Entrée.';
|
|
});
|
|
}).catch(function (e) {
|
|
if (!alive) return; setSt('moteur indisponible', 'err');
|
|
log.textContent = '⚠️ Strudel non chargé (' + (e && e.message || 'hors-ligne / CSP') + ').\nLe live coding a besoin du cœur @strudel/web. Réessaie connecté, ou utilise le ploxion `web-son` en attendant.';
|
|
});
|
|
|
|
function doEval() {
|
|
var code = ed.value; try { localStorage.setItem(KEY, code); } catch (e) {}
|
|
if (!evaluate) { log.textContent = '⏳ moteur pas encore prêt…'; return; }
|
|
try {
|
|
evaluate(code);
|
|
if (!started) { started = true; emit('session.start', { ploxion: 'strudel-live', ts: Date.now() }); }
|
|
tmark(code); // TSOIN : l'instant créatif
|
|
emit('pattern.eval', { ploxion: 'strudel-live', code: code, ts: Date.now() });
|
|
emit('pattern.active', { ploxion: 'strudel-live', code: code });
|
|
setSt('▶ joue', 'ok'); log.textContent = '▶ pattern évalué @ ' + new Date().toLocaleTimeString();
|
|
} catch (err) { setSt('erreur', 'err'); log.textContent = '✗ ' + (err && err.message || err); }
|
|
}
|
|
function doHush() { try { hush && hush(); } catch (e) {} setSt('■ silence'); emit('session.stop', { ploxion: 'strudel-live', ts: Date.now() }); }
|
|
|
|
container.querySelector('[data-eval]').addEventListener('click', doEval);
|
|
container.querySelector('[data-hush]').addEventListener('click', doHush);
|
|
ed.addEventListener('keydown', function (e) { if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') { e.preventDefault(); doEval(); }
|
|
if (e.key === 'Tab') { e.preventDefault(); var s = ed.selectionStart; ed.value = ed.value.slice(0, s) + ' ' + ed.value.slice(ed.selectionEnd); ed.selectionStart = ed.selectionEnd = s + 2; } });
|
|
|
|
LIVE = { started: function () { return started; }, code: function () { return ed.value; } };
|
|
return { unmount: function () { LIVE = null; alive = false; try { hush && hush(); } catch (e) {} // droit au silence : coupe l'audio
|
|
try { emit('session.stop', { ploxion: 'strudel-live', ts: Date.now() }); } catch (e) {} container.innerHTML = ''; } };
|
|
}
|
|
window.jOSApps = window.jOSApps || {};
|
|
window.jOSApps['strudel-live'] = { manifest: { id: 'strudel-live', name: 'Strudel', icon: '🎛️' }, mount: mount, describe: describe };
|
|
})();
|
|
</script>
|