mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 04:44:33 +01:00
Studio: the emulator as a recording input: its stems (8 channels) and its MIDI OUT
- web/emu: the emulator gives its stems live as MENU > USB STEMS sends them (fx.c stem_buf: T1..T6 mono, the FX return L R, before the master), each sample at its place beside the stereo (felucca_web.c web_stems, web_stem_out), and what MIDI OUT sends (web_midi_tap, web_midi_take: usb.c queues it without a USB host). worklet.js posts them about every 93 ms (tap-chunk: the first sample's number, the planes, the MIDI packets each at its sample); index.html jiantEmu.tap(f) for JIANT Studio. - firmware: two hooks for the browser build only, nothing in the device's: audio.c calls WEB_STEM_TAP when it is defined; usb.c's midi_out_event queues with USB_MIDI_TAP (0 unless defined). - Studio, Record: Input lists "JIANT emulator · stems (8 channels)" and "· master (stereo)"; MIDI input lists "JIANT emulator · MIDI OUT". The stems come in as STEMS' lanes (named by the tracks' engines), the take exports a WAV per track, FX, the ZIP and the mix; the MIDI lines up with the audio by sample. An emulator without the tap (the published one until it is rebuilt) says so. Tests: the browser test records the emulator's stems and three notes of its MIDI OUT; emu_test, devices, the host tests as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UVqsRnhKjiABTzc6Ety3dd
This commit is contained in:
7 files changed
+179
-23
No files matched your search
@@ -80,6 +80,10 @@ static void audio_block(int32_t *out, uint32_t n) /* mix (fx.c), then Q15
|
||||
#endif
|
||||
t1 = PRF_T();
|
||||
mix_block(out, n);
|
||||
#ifdef WEB_STEM_TAP
|
||||
if (fx_stems) /* (studio) the browser build: the stems as USB STEMS sends them */
|
||||
WEB_STEM_TAP(n);
|
||||
#endif
|
||||
#if FELUCCA_HOST_POWER
|
||||
smp_audio_block(out, n); /* (ports/) the input, the LIVE buffers, the recorder */
|
||||
#endif
|
||||
|
||||
+4
-1
@@ -266,9 +266,12 @@ static int midi_enqueue(uint32_t pkt, uint32_t source)
|
||||
return 1;
|
||||
}
|
||||
|
||||
#ifndef USB_MIDI_TAP
|
||||
#define USB_MIDI_TAP 0 /* (studio) the browser build reads what MIDI OUT sends (felucca_web.c) */
|
||||
#endif
|
||||
static void midi_out_event(uint32_t pkt) /* from the audio ISR */
|
||||
{
|
||||
if (usb.config && mo_w - mo_r < MQ) {
|
||||
if ((usb.config || USB_MIDI_TAP) && mo_w - mo_r < MQ) {
|
||||
midi_out_q[mo_w % MQ] = pkt;
|
||||
RING_PUBLISH();
|
||||
mo_w++;
|
||||
|
||||
+53
-1
@@ -34,6 +34,9 @@
|
||||
#endif
|
||||
|
||||
static uint8_t nor[0x100000]; /* the SPI NOR (erased: 0xFF) */
|
||||
/* (studio) JIANT Studio records the emulator's MIDI OUT (usb.c midi_out_event queues it without a USB host) */
|
||||
static unsigned char web_mo_tap;
|
||||
#define USB_MIDI_TAP web_mo_tap
|
||||
#define main hostsim_main
|
||||
#include "../../tests/hostsim.c"
|
||||
#undef main
|
||||
@@ -71,6 +74,27 @@ static void fm1_audio_init(int32_t *buf, uint32_t words, void (*isr)(void), uint
|
||||
{ (void)buf; (void)words; (void)isr; (void)prio; }
|
||||
static void fm1_audio_stop(void) {}
|
||||
void isr_alnk0(void) {}
|
||||
/* (studio) the stems live, as MENU > USB STEMS sends them (fx.c stem_buf: the six parts mono, before the master;
|
||||
* stem_fx: the FX return L R), each sample at its place in the output (stem_ring by the sample's number), for JIANT
|
||||
* Studio's recorder: web_stems(1) on, web_render puts them in web_stem_out() beside the stereo */
|
||||
#define STEM_CH 8u
|
||||
#define STEM_RING 4096u
|
||||
static float stem_ring[STEM_RING][STEM_CH], stem_out[STEM_CH][1024];
|
||||
static uint32_t stem_w, stem_from;
|
||||
static uint8_t web_stems_on;
|
||||
static void web_stem_tap(uint32_t n)
|
||||
{
|
||||
uint32_t i, k;
|
||||
for (i = 0; i < n; i++) {
|
||||
float *s = stem_ring[(stem_w + i) % STEM_RING];
|
||||
for (k = 0; k < 6u; k++)
|
||||
s[k] = (float)stem_buf[k][i] / 32768.0f;
|
||||
s[6] = (float)stem_fx[0][i] / 32768.0f;
|
||||
s[7] = (float)stem_fx[1][i] / 32768.0f;
|
||||
}
|
||||
stem_w += n;
|
||||
}
|
||||
#define WEB_STEM_TAP(n) web_stem_tap(n)
|
||||
#include "../../firmware/src/audio.c"
|
||||
|
||||
/* ------------------------------------------------------------ the panel --- */
|
||||
@@ -321,6 +345,8 @@ static void web_ms(void)
|
||||
web_real_at = jiant_host_us();
|
||||
#endif
|
||||
web_samples_due += FS;
|
||||
if (web_stems_on && !fx_stems) /* (studio) the stems on while Studio records them (the menu's */
|
||||
fx_stems = 1; /* USB setting sets it back each frame) */
|
||||
while (web_samples_due >= 1000u * HALF_FRAMES) { /* an I2S half: the audio ISR renders it */
|
||||
uint32_t k;
|
||||
const int32_t *o = &abuf[web_half * HALF_WORDS];
|
||||
@@ -366,11 +392,37 @@ EXPORT void web_render(uint32_t n)
|
||||
while (ring_w - ring_r < n)
|
||||
web_ms();
|
||||
for (k = 0; k < n; k++) {
|
||||
uint32_t i = (ring_r++ % RING) * 2u;
|
||||
uint32_t c, at = ring_r, i = (ring_r++ % RING) * 2u;
|
||||
out_l[k] = ring[i];
|
||||
out_r[k] = ring[i + 1];
|
||||
if (web_stems_on) /* (studio) its stems: silent before they were on */
|
||||
for (c = 0; c < STEM_CH; c++)
|
||||
stem_out[c][k] = (int32_t)(at - stem_from) >= 0 ? stem_ring[at % STEM_RING][c] : 0.0f;
|
||||
}
|
||||
}
|
||||
/* (studio) the stems: on (their samples from the next one rendered) or off; web_stem_out(c) a channel's n samples */
|
||||
EXPORT void web_stems(uint32_t on)
|
||||
{
|
||||
web_stems_on = (uint8_t)(on != 0u);
|
||||
if (web_stems_on) {
|
||||
stem_w = stem_from = ring_w; /* (between halves: the next half's first sample) */
|
||||
if (!fx_stems)
|
||||
fx_stems = 1;
|
||||
}
|
||||
}
|
||||
EXPORT float *web_stem_out(uint32_t c) { return stem_out[c < STEM_CH ? c : 0]; }
|
||||
/* (studio) MIDI OUT as the FM-1 sends it over USB (MENU > CONTROL > MIDI OUT: KEYS, CLOCK, ALL), read by Studio:
|
||||
* web_midi_tap(1) on; web_midi_take() the next USB-MIDI packet (0: none) */
|
||||
EXPORT void web_midi_tap(uint32_t on) { web_mo_tap = (unsigned char)(on != 0u); mo_r = mo_w; }
|
||||
EXPORT uint32_t web_midi_take(void)
|
||||
{
|
||||
uint32_t p;
|
||||
if (mo_r == mo_w)
|
||||
return 0;
|
||||
p = midi_out_q[mo_r % MQ];
|
||||
mo_r++;
|
||||
return p;
|
||||
}
|
||||
|
||||
/* the flash: erased, then the page's saved sectors (web_nor), then boot */
|
||||
EXPORT uint8_t *web_nor(void) { return nor; }
|
||||
|
||||
+10
-1
@@ -493,7 +493,7 @@ async function midiOn() {
|
||||
|
||||
/* (studio) JIANT Studio's editor talks to this emulator as to an FM-1 (web/emu/editor-api.h): a frame in (sysex), the
|
||||
* replies and the live pushes out to each listener; on() says whether the emulator runs */
|
||||
const sysexListeners = new Set();
|
||||
const sysexListeners = new Set(), tapListeners = new Set();
|
||||
window.jiantEmu = {
|
||||
on: () => !!node,
|
||||
midiInputs: () => midiAccess ? [...midiAccess.inputs.values()].filter((p) => p.state !== "disconnected").map((p) => ({ id: p.id, name: p.name || p.id })) : [],
|
||||
@@ -503,6 +503,14 @@ window.jiantEmu = {
|
||||
},
|
||||
sysex: (bytes) => { if (node) node.port.postMessage({ type: "sysex", data: Array.from(bytes) }); },
|
||||
listen: (f) => { sysexListeners.add(f); return () => sysexListeners.delete(f); },
|
||||
/* (studio) the recorder: f gets { at, planes: [T1..T6, FX L, FX R] (44.1 kHz), midi: [{ at, data }] } about every
|
||||
93 ms while tapped; returns stop. The stems as MENU > USB STEMS sends them, MIDI as MIDI OUT does */
|
||||
tap: (f) => {
|
||||
if (!node) return null;
|
||||
tapListeners.add(f);
|
||||
if (tapListeners.size === 1) node.port.postMessage({ type: "tap", on: true });
|
||||
return () => { tapListeners.delete(f); if (!tapListeners.size && node) node.port.postMessage({ type: "tap", on: false }); };
|
||||
},
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------ switching on
|
||||
@@ -535,6 +543,7 @@ async function switchOn() {
|
||||
rej(new Error(m.message));
|
||||
}
|
||||
else if (m.type === "sysex") sysexListeners.forEach((f) => m.msgs.forEach(f));
|
||||
else if (m.type === "tap-chunk") tapListeners.forEach((f) => f(m));
|
||||
else if (m.type === "frame") {
|
||||
if (m.sysex) sysexListeners.forEach((f) => m.sysex.forEach(f));
|
||||
if (m.fb) drawScreen(m.fb);
|
||||
|
||||
@@ -151,6 +151,13 @@ if (typeof registerProcessor === "function") {
|
||||
else if (m.type === "enc") ex.web_enc(m.role, m.n | 0);
|
||||
else if (m.type === "master") ex.web_master(m.value | 0);
|
||||
else if (m.type === "midi") ex.web_midi(m.data[0] | 0, m.data[1] | 0, m.data[2] | 0);
|
||||
else if (m.type === "tap") { // (studio) the stems and MIDI OUT to JIANT Studio's recorder
|
||||
const on = !!m.on && !!ex.web_stems;
|
||||
if (ex.web_stems) ex.web_stems(on ? 1 : 0);
|
||||
if (ex.web_midi_tap) ex.web_midi_tap(on ? 1 : 0);
|
||||
this.tap = on ? { planes: Array.from({ length: 8 }, () => new Float32Array(4096)), n: 0, at: this.pos, midi: [] } : null;
|
||||
this.port.postMessage({ type: "tap", on, stems: !!ex.web_stems });
|
||||
}
|
||||
else if (m.type === "sysex") { // (studio) the web editor's frame (editor-api.h): its replies at once
|
||||
if (!ex.web_sysex || !Array.isArray(m.data) || m.data.length > 640) return;
|
||||
new Uint8Array(ex.memory.buffer, ex.web_sysex_buf(), m.data.length).set(m.data.map((v) => v & 255));
|
||||
@@ -257,6 +264,23 @@ if (typeof registerProcessor === "function") {
|
||||
}
|
||||
}
|
||||
|
||||
/* (studio) a block's stems (web_stem_out: T1..T6, FX L, FX R) and the MIDI OUT packets it sent (each at its sample),
|
||||
posted about every 93 ms: { at: the first sample's number, planes, midi: [{ at, data }] } */
|
||||
tapBlock(ex, n) {
|
||||
const T = this.tap;
|
||||
for (let c = 0; c < 8; c++) T.planes[c].set(new Float32Array(ex.memory.buffer, ex.web_stem_out(c), n), T.n);
|
||||
for (let p; ex.web_midi_take && (p = ex.web_midi_take()) !== 0;) {
|
||||
const cin = p & 15, len = cin === 0xC || cin === 0xD ? 2 : cin >= 0x8 && cin <= 0xE ? 3 : cin === 0xF ? 1 : 0;
|
||||
if (len) T.midi.push({ at: this.pos, data: [(p >>> 8) & 255, (p >>> 16) & 255, (p >>> 24) & 255].slice(0, len) });
|
||||
}
|
||||
T.n += n;
|
||||
if (T.n + 128 > 4096) {
|
||||
const planes = T.planes.map((pl) => pl.slice(0, T.n));
|
||||
this.port.postMessage({ type: "tap-chunk", at: T.at, planes, midi: T.midi }, planes.map((pl) => pl.buffer));
|
||||
T.n = 0; T.at = this.pos + n; T.midi = [];
|
||||
}
|
||||
}
|
||||
|
||||
process(inputs, outputs) {
|
||||
try { return this.renderBlock(inputs, outputs); }
|
||||
catch (error) {
|
||||
@@ -280,6 +304,8 @@ if (typeof registerProcessor === "function") {
|
||||
}
|
||||
const t0 = clock();
|
||||
ex.web_render(n);
|
||||
if (this.tap) this.tapBlock(ex, n);
|
||||
this.pos = (this.pos || 0) + n;
|
||||
this.busy += clock() - t0;
|
||||
this.frames += n;
|
||||
out[0].set(new Float32Array(ex.memory.buffer, ex.web_out_l(), n));
|
||||
|
||||
@@ -164,6 +164,19 @@ try {
|
||||
await e.click('nav.views [data-go="rec"]'); await e.click("#recgo"); await e.waitForTimeout(2000); await e.click("#recgo"); await e.waitForTimeout(800);
|
||||
const takes = await e.evaluate(() => jiantStudio.rec.takes.map((t) => ({ s: t.secs, f: t.files.map((x) => x.blob.size) })));
|
||||
ok(takes.length === 1 && takes[0].s > 1.5 && takes[0].f[0] > 44 + 44100 * 4, `the emulator's output recorded: ${takes[0] ? takes[0].s.toFixed(2) : 0} s, a stereo WAV`);
|
||||
/* the emulator as an input: its stems (8 channels, as USB STEMS) and its MIDI OUT, keys played on it */
|
||||
if (readFileSync(wasm).includes(Buffer.from("web_stems"))) {
|
||||
await e.selectOption("#recdev", "emu-stems"); await e.selectOption("#midisrc", "emu-midi");
|
||||
await e.click("#recgo"); await e.waitForTimeout(500);
|
||||
await e.evaluate(() => document.getElementById("f-emu").contentWindow.focus());
|
||||
for (const k of ["KeyZ", "KeyC", "KeyB"]) { await e.keyboard.down(k); await e.waitForTimeout(300); await e.keyboard.up(k); await e.waitForTimeout(150); }
|
||||
await e.waitForTimeout(800); await e.click("#recgo"); await e.waitForTimeout(1000);
|
||||
const st = await e.evaluate(() => { const tk = jiantStudio.rec.takes[0];
|
||||
return { ch: tk.planes.length, peak: tk.planes.map((p) => { let m = 0; for (const v of p) m = Math.max(m, Math.abs(v)); return m; }),
|
||||
files: tk.files.map((f) => f.label), notes: jiantStudio.rec.midi.filter((m) => (m.data[0] & 0xF0) === 0x90 && m.data[2]).length }; });
|
||||
ok(st.ch === 8 && st.peak.some((v) => v > 0.05) && st.files.length >= 9 && st.notes === 3,
|
||||
`the emulator as an input: ${st.ch} stems (${st.peak.filter((v) => v > 0.05).length} with sound), ${st.files.length} files, ${st.notes} notes from its MIDI OUT`);
|
||||
}
|
||||
} else console.log("studio browser: (no emulator with the editor in build/emu: web/emu/build.sh; the target Emulator checks skipped)");
|
||||
ok(!errs.length, `no page errors${errs.length ? ": " + errs.slice(0, 3).join(" | ") : ""}`);
|
||||
} finally {
|
||||
|
||||
+69
-20
@@ -96,6 +96,9 @@ const TEXT = {
|
||||
recSaved: "Toma guardada: está abajo, en Tomas.",
|
||||
recSrcFm1: "La FM-1 por USB es una entrada de audio: estéreo (USB > AUDIO), u 8 canales en USB > STEMS (las 6 pistas y los efectos por separado). Elegila acá.",
|
||||
recSrcEmu: "Graba la salida del emulador (prendelo en la pestaña Emulador).",
|
||||
recEmuStems: "Emulador JIANT · stems (8 canales)", recEmuMaster: "Emulador JIANT · master (estéreo)", recEmuMidi: "Emulador JIANT · MIDI OUT",
|
||||
recEmuOff: "Prendé el emulador en la pestaña Emulador (Prender) y volvé.", recEmuOld: "El emulador publicado todavía no entrega stems ni MIDI: llegan con su próxima versión. Mientras tanto: «master (estéreo)».", recEmuStemsHelp: "Del emulador, como USB STEMS: cada pista sola (T1–T6) y la vuelta de efectos (FX L R), antes del master; se graban juntas y se exportan como WAV por pista, el ZIP y la mezcla.",
|
||||
recEmuMidiHelp: "Las notas que manda MIDI OUT del emulador (MENU › CONTROL › MIDI OUT: KEYS las teclas, ALL también el secuenciador y el arpegiador).",
|
||||
recNoDev: "No hay entradas de audio (dale permiso al micrófono para verlas).", recAsk: "Pedir permiso de audio",
|
||||
recMidi: "MIDI", recMidiHelp: "Mientras grabás, también se guarda lo que entra por MIDI: lo que tocás en la FM-1 (MENU > MIDI OUT) o en un teclado.",
|
||||
recMidiIn: "Entrada MIDI", recMidiNone: "(ninguna)",
|
||||
@@ -200,6 +203,9 @@ const TEXT = {
|
||||
recSaved: "Take saved: it is below, under Takes.",
|
||||
recSrcFm1: "The FM-1 over USB is an audio input: stereo (USB > AUDIO), or 8 channels in USB > STEMS (the 6 tracks and the effects apart). Pick it here.",
|
||||
recSrcEmu: "Records the emulator's output (switch it on in the Emulator tab).",
|
||||
recEmuStems: "JIANT emulator · stems (8 channels)", recEmuMaster: "JIANT emulator · master (stereo)", recEmuMidi: "JIANT emulator · MIDI OUT",
|
||||
recEmuOff: "Switch the emulator on in the Emulator tab (Switch on) and come back.", recEmuOld: "The published emulator does not give stems or MIDI yet: they come with its next version. Meanwhile: “master (stereo)”.", recEmuStemsHelp: "From the emulator, as USB STEMS: each track alone (T1–T6) and the effects' return (FX L R), before the master; recorded together, exported as a WAV per track, the ZIP and the mix.",
|
||||
recEmuMidiHelp: "The notes the emulator's MIDI OUT sends (MENU › CONTROL › MIDI OUT: KEYS the keys, ALL the sequencer and the arpeggiator too).",
|
||||
recNoDev: "No audio inputs (allow the microphone to list them).", recAsk: "Ask for audio permission",
|
||||
recMidi: "MIDI", recMidiHelp: "While recording, what comes in over MIDI is kept too: what you play on the FM-1 (MENU > MIDI OUT) or on a keyboard.",
|
||||
recMidiIn: "MIDI input", recMidiNone: "(none)",
|
||||
@@ -607,12 +613,13 @@ const daw = new Daw($("daw"), { get mute() { return t("recMute"); }, get solo()
|
||||
const profileOf = (ch) => { const p = $("recprof").value; return p !== "auto" ? p : ch >= 10 ? "stemsin" : ch >= 8 ? "stems" : "master"; };
|
||||
/* the six tracks' engines, for the lanes' names (27 TRACK: selected, NTRK, then per track engine, preset, level v14,
|
||||
mute, armed) */
|
||||
async function trackNames() {
|
||||
const d = state.dev;
|
||||
if (!d || state.target !== "fm1") return [];
|
||||
async function trackNames(emu = false) {
|
||||
const d = state.dev, L = emu ? projLink() : d && state.target === "fm1" ? { link: d.link } : null;
|
||||
if (!L) return [];
|
||||
try {
|
||||
const a = await d.link.request(27, [], 600), n = a[1] | 0;
|
||||
return Array.from({ length: n }, (_, k) => d.engines[a[2 + k * 6]] || "");
|
||||
const engines = emu ? parseInfo(await L.link.request(CMD.INFO, [], 900)).engines : d.engines;
|
||||
const a = await L.link.request(27, [], 600), n = a[1] | 0;
|
||||
return Array.from({ length: n }, (_, k) => engines[a[2 + k * 6]] || "");
|
||||
} catch (_) { return []; }
|
||||
}
|
||||
function lanesFor(profile, ch) {
|
||||
@@ -625,17 +632,48 @@ function lanesFor(profile, ch) {
|
||||
return lanes;
|
||||
}
|
||||
function profileHelp() {
|
||||
const p = $("recprof").value;
|
||||
$("profhelp").textContent = state.target === "emu" ? t("recSrcEmu") : t("profHelp_" + p);
|
||||
const p = $("recprof").value, d = $("recdev").value;
|
||||
$("profhelp").textContent = d === "emu-stems" ? t("recEmuStemsHelp") + ($("midisrc").value === "emu-midi" ? " " + t("recEmuMidiHelp") : "") :
|
||||
d === "emu" ? t("recSrcEmu") : t("profHelp_" + p);
|
||||
}
|
||||
$("recprof").addEventListener("change", () => { profileHelp(); if (rec.mon && !rec.on) monitorStop(); });
|
||||
/* the input open and shown in the lanes (levels only) until Record, which keeps what comes in */
|
||||
/* the emulator's tap (emu/index.html jiantEmu.tap): its stems as the input (8 channels, STEMS' lanes) and/or its MIDI
|
||||
OUT, each at its sample (rec.at0: the take's first sample) */
|
||||
const emuApi = () => { try { const e = frames.emu.el.contentWindow.jiantEmu; return e && e.on() && e.tap ? e : null; } catch (_) { return null; } };
|
||||
const emuWhyNot = () => t(emuOn() ? "recEmuOld" : "recEmuOff");
|
||||
function onTap(m) {
|
||||
if (rec.src === "emu-stems") {
|
||||
if (rec.on) { if (rec.at0 == null) rec.at0 = m.at; rec.chunks.push(m.planes); daw.live(m.planes, rec.rate); }
|
||||
else daw.meters(m.planes.map((p) => { let v = 0; for (let i = 0; i < p.length; i += 8) { const a = Math.abs(p[i]); if (a > v) v = a; } return v; }));
|
||||
}
|
||||
if (rec.on && rec.emuMidi) for (const e of m.midi) {
|
||||
if (e.data[0] < 0x80 || e.data[0] >= 0xF0) continue;
|
||||
const t0 = rec.at0 != null ? (e.at - rec.at0) / 44.1 : performance.now() - rec.t0;
|
||||
if (t0 >= 0) rec.midi.push({ t: t0, data: e.data });
|
||||
}
|
||||
}
|
||||
async function monitorStart() {
|
||||
if (rec.mon || state.busy) return true;
|
||||
let stream;
|
||||
if ($("recdev").value === "emu-stems") {
|
||||
loadFrame("emu");
|
||||
const e = emuApi();
|
||||
if (!e) { $("recstat").textContent = emuWhyNot(); return false; }
|
||||
rec.tapStop = e.tap(onTap);
|
||||
rec.engines = state.target === "emu" ? await trackNames(true) : [];
|
||||
Object.assign(rec, { mon: true, src: "emu-stems", stream: null, ac: null, node: null, ch: 8, rate: 44100, profile: "stems" });
|
||||
daw.setLanes(lanesFor("stems", 8));
|
||||
$("recstat").textContent = `8${t("recChannels")} · 44100 Hz`;
|
||||
$("recwarn").hidden = true;
|
||||
render();
|
||||
return true;
|
||||
}
|
||||
rec.src = $("recdev").value;
|
||||
const want = PROFILES[$("recprof").value === "auto" ? "stemsin" : $("recprof").value].ch;
|
||||
try {
|
||||
if (state.target === "emu") {
|
||||
if (rec.src === "emu") {
|
||||
loadFrame("emu");
|
||||
const w = frames.emu.el.contentWindow;
|
||||
stream = w && w.jiantEmu && w.jiantEmu.stream && w.jiantEmu.stream();
|
||||
if (!stream) { $("recstat").textContent = t("recSrcEmu"); return false; }
|
||||
@@ -657,7 +695,7 @@ async function monitorStart() {
|
||||
const node = new AudioWorkletNode(ac, "studio-recorder", { numberOfInputs: 1, numberOfOutputs: 0, channelCount: ch, channelCountMode: "explicit", channelInterpretation: "discrete" });
|
||||
src.connect(node);
|
||||
rec.engines = await trackNames();
|
||||
const profile = state.target === "emu" ? "master" : profileOf(ch);
|
||||
const profile = rec.src === "emu" ? "master" : profileOf(ch);
|
||||
Object.assign(rec, { mon: true, stream, ac, node, ch, rate: ac.sampleRate, profile });
|
||||
daw.setLanes(lanesFor(profile, ch));
|
||||
node.port.onmessage = (e) => {
|
||||
@@ -669,7 +707,7 @@ async function monitorStart() {
|
||||
const need = PROFILES[profile].ch, got = ch;
|
||||
$("recstat").textContent = `${got}${t("recChannels")} · ${rec.rate} Hz`;
|
||||
const warn = $("recwarn");
|
||||
warn.hidden = !(state.target !== "emu" && (got < need || ($("recprof").value !== "auto" && got < PROFILES[$("recprof").value].ch)));
|
||||
warn.hidden = !(rec.src !== "emu" && (got < need || ($("recprof").value !== "auto" && got < PROFILES[$("recprof").value].ch)));
|
||||
warn.textContent = t("recFewerLong").replace("%got", got).replace("%need", PROFILES[$("recprof").value === "auto" ? profile : $("recprof").value].ch);
|
||||
render();
|
||||
return true;
|
||||
@@ -678,8 +716,9 @@ function monitorStop() {
|
||||
if (!rec.mon) return;
|
||||
if (rec.on) recStop();
|
||||
rec.mon = false;
|
||||
if (state.target !== "emu" && rec.stream !== "mock") rec.stream.getTracks().forEach((x) => x.stop());
|
||||
rec.ac.close().catch(() => {});
|
||||
if (rec.tapStop) { rec.tapStop(); rec.tapStop = null; }
|
||||
if (rec.stream && rec.src !== "emu" && rec.stream !== "mock") rec.stream.getTracks().forEach((x) => x.stop());
|
||||
if (rec.ac) rec.ac.close().catch(() => {});
|
||||
render();
|
||||
}
|
||||
$("recmon").addEventListener("click", () => (rec.mon ? monitorStop() : monitorStart()));
|
||||
@@ -688,9 +727,12 @@ async function recStart() {
|
||||
if (!rec.mon && !(await monitorStart())) return;
|
||||
daw.stop();
|
||||
daw.setLanes(lanesFor(rec.profile, rec.ch));
|
||||
Object.assign(rec, { on: true, chunks: [], t0: performance.now(), midi: [] });
|
||||
Object.assign(rec, { on: true, chunks: [], t0: performance.now(), midi: [], at0: null, emuMidi: false });
|
||||
const mid = $("midisrc").value;
|
||||
if (mid && access) {
|
||||
if (mid === "emu-midi") { // the emulator's MIDI OUT: by its tap (the stems' own, or one of its own)
|
||||
rec.emuMidi = true;
|
||||
if (!rec.tapStop) { const e = emuApi(); if (e) rec.tapStop = e.tap(onTap); else $("recstat").textContent = emuWhyNot(); }
|
||||
} else if (mid && access) {
|
||||
const inp = access.inputs.get(mid);
|
||||
if (inp) {
|
||||
midiTapInput = inp;
|
||||
@@ -711,6 +753,7 @@ function recStop() {
|
||||
try { rec.node.port.postMessage("flush"); } catch (_) {}
|
||||
setTimeout(() => {
|
||||
if (midiTapInput) { midiTapInput.removeEventListener("midimessage", midiTap); midiTapInput = null; }
|
||||
if (rec.tapStop && rec.src !== "emu-stems") { rec.tapStop(); rec.tapStop = null; } // (a tap for its MIDI only)
|
||||
const take = makeTake();
|
||||
if (take) daw.show(take.planes, rec.rate);
|
||||
$("recclock").textContent = "00:00";
|
||||
@@ -826,27 +869,33 @@ function midiTap(e) {
|
||||
}
|
||||
async function renderAudioInputs(ask = false) {
|
||||
const sel = $("recdev"), was = sel.value;
|
||||
if (state.target === "emu") { sel.replaceChildren(new Option(t("tEmu"), "emu")); sel.disabled = true; return; }
|
||||
if (rec.mon) return; // (the input in use stays as it is)
|
||||
sel.disabled = false;
|
||||
const emuOpts = () => [new Option(t("recEmuStems"), "emu-stems"), new Option(t("recEmuMaster"), "emu")];
|
||||
if (state.target === "emu") {
|
||||
sel.replaceChildren(...emuOpts());
|
||||
sel.value = was === "emu" ? "emu" : "emu-stems";
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (ask) (await navigator.mediaDevices.getUserMedia({ audio: true })).getTracks().forEach((x) => x.stop());
|
||||
const ins = (await navigator.mediaDevices.enumerateDevices()).filter((d) => d.kind === "audioinput");
|
||||
const opts = ins.map((d, i) => new Option(d.label || `${t("recInput")} ${i + 1}`, d.deviceId));
|
||||
if (!opts.length || !ins.some((d) => d.label)) opts.push(new Option(t("recAsk"), "ask"));
|
||||
if (MOCK) opts.unshift(new Option("JIANT FM (simulated: STEMS+IN, 10 ch)", "mock-stems"));
|
||||
sel.replaceChildren(...opts);
|
||||
sel.replaceChildren(...opts, ...emuOpts());
|
||||
const fm1 = MOCK ? { deviceId: "mock-stems" } : ins.find((d) => /fm-?1|jiant|felucca|m-?vave/i.test(d.label));
|
||||
sel.value = [...sel.options].some((o) => o.value === was) ? was : fm1 ? fm1.deviceId : sel.options[0].value;
|
||||
} catch (_) { sel.replaceChildren(new Option(t("recNoDev"), "")); }
|
||||
}
|
||||
$("recdev").addEventListener("change", () => { if ($("recdev").value === "ask") renderAudioInputs(true); });
|
||||
$("recdev").addEventListener("change", () => { if ($("recdev").value === "ask") renderAudioInputs(true); profileHelp(); });
|
||||
$("midisrc").addEventListener("change", profileHelp);
|
||||
function renderMidiInputs() {
|
||||
const sel = $("midisrc"), was = sel.value;
|
||||
const ins = access ? [...access.inputs.values()].filter((p) => p.state !== "disconnected") : [];
|
||||
sel.replaceChildren(new Option(t("recMidiNone"), ""), ...ins.map((p) => new Option(p.name || p.id, p.id)));
|
||||
sel.replaceChildren(new Option(t("recMidiNone"), ""), new Option(t("recEmuMidi"), "emu-midi"), ...ins.map((p) => new Option(p.name || p.id, p.id)));
|
||||
const fm1 = ins.find((p) => PORT_RE.test(p.name || ""));
|
||||
sel.value = [...sel.options].some((o) => o.value === was) ? was : fm1 ? fm1.id : "";
|
||||
sel.value = was && [...sel.options].some((o) => o.value === was) ? was : state.target === "emu" ? "emu-midi" : fm1 ? fm1.id : "";
|
||||
}
|
||||
$("midisrc").addEventListener("focus", async () => { if (!access && !MOCK) { try { await midiAccess(); } catch (_) {} renderMidiInputs(); } });
|
||||
function renderTakes() {
|
||||
@@ -1254,7 +1303,7 @@ function render() {
|
||||
$("recmon").disabled = rec.on || state.busy;
|
||||
$("recplay").textContent = t(daw.playing ? "recPlayStop" : "recPlay");
|
||||
$("recplay").disabled = rec.on || !daw.planes;
|
||||
$("recprof").disabled = rec.mon || state.target === "emu";
|
||||
$("recprof").disabled = rec.mon || /^emu/.test($("recdev").value);
|
||||
if (state.view === "rec") profileHelp();
|
||||
if (state.view === "rec" && !rec.on) { renderAudioInputs(); renderMidiInputs(); }
|
||||
renderTakes();
|
||||
|
||||
Reference in new issue
Block a user