mirror of
https://github.com/isod89/sloop-fm1.git
synced 2026-12-06 12:54:21 +01:00
Editor: find the FM-1 by the installer's port names, not only Felucca (Windows and macOS keep the port name of the first firmware they saw, e.g. X0X FM-1), and keep the first port that answers as an FM-1; firmware unchanged (2.6)
This commit is contained in:
1 parent
8fad1a15ff
commit
d315ad88c5
5 files changed
+136
-44
No files matched your search
@@ -3711,6 +3711,22 @@ class SetGate {
|
||||
}
|
||||
clear() { this.m.clear(); }
|
||||
}
|
||||
/* the FM-1's MIDI ports. Every FM-1 firmware has the same USB IDs, so Windows and macOS often keep the port name of the
|
||||
* first firmware they saw ("X0X FM-1", "USB-MIDI"…): the names the installer accepts (fm1ota.js FM1_PORT, the same
|
||||
* list), as in/out pairs of one name, "Felucca" / "SLOOP" first, then FM-1, then the generic names. connect() keeps the
|
||||
* first pair that answers INFO, so a generic name of other gear is tried and left */
|
||||
const FM1_PORT = /fm-1|felucca|sloop|clipper|ota|composite|sinco|usb-midi/i;
|
||||
function fm1Ports(access) {
|
||||
const live = (p) => p.state !== "disconnected" && FM1_PORT.test(p.name || "");
|
||||
const ins = [...access.inputs.values()].filter(live), outs = [...access.outputs.values()].filter(live);
|
||||
const rank = (n) => (/felucca|sloop/i.test(n) ? 0 : /fm-1/i.test(n) ? 1 : 2);
|
||||
const pairs = [];
|
||||
for (const input of ins) {
|
||||
const output = outs.find((o) => o.name === input.name) || (outs.length === 1 ? outs[0] : null);
|
||||
if (output) pairs.push({ input, output });
|
||||
}
|
||||
return pairs.sort((a, b) => rank(a.input.name || "") - rank(b.input.name || ""));
|
||||
}
|
||||
/*PROTO-END*/
|
||||
|
||||
/* ===================================================================== UI === */
|
||||
@@ -4886,19 +4902,29 @@ async function connect() {
|
||||
}
|
||||
access.onstatechange = onState;
|
||||
}
|
||||
const isF = (p) => /felucca/i.test(p.name || "") && p.state !== "disconnected";
|
||||
const input = [...access.inputs.values()].find(isF);
|
||||
const output = [...access.outputs.values()].find(isF);
|
||||
if (!input || !output) { sayK("nodevice"); return; }
|
||||
const link = new Link((d) => output.send(d), {
|
||||
timeout: 300,
|
||||
onUnknown: (f) => console.debug("ignored reply", f),
|
||||
onTimeout: () => sayK("noreply"),
|
||||
onPush: (f) => onPush(f),
|
||||
onGap: () => { rewatch = true; },
|
||||
});
|
||||
input.onmidimessage = (e) => link.receive(e.data);
|
||||
if (input.open) await input.open().catch(() => {});
|
||||
const pairs = fm1Ports(access);
|
||||
if (!pairs.length) { sayK("nodevice"); return; }
|
||||
let link = null, input = null, output = null;
|
||||
for (const pr of pairs) { /* the first pair that answers (a generic name may be other gear) */
|
||||
const l = new Link((d) => pr.output.send(d), {
|
||||
timeout: 300,
|
||||
onUnknown: (f) => console.debug("ignored reply", f),
|
||||
onTimeout: () => sayK("noreply"),
|
||||
onPush: (f) => onPush(f),
|
||||
onGap: () => { rewatch = true; },
|
||||
});
|
||||
pr.input.onmidimessage = (e) => l.receive(e.data);
|
||||
if (pr.input.open) await pr.input.open().catch(() => {});
|
||||
try {
|
||||
await l.request(req.info(), { timeout: 500, retries: 3, quiet: true }); /* (the first frame can be lost) */
|
||||
link = l, input = pr.input, output = pr.output;
|
||||
break;
|
||||
} catch (e) {
|
||||
l.close();
|
||||
pr.input.onmidimessage = null;
|
||||
}
|
||||
}
|
||||
if (!link) { sayK(pairs.length ? "noreply" : "nodevice"); return; }
|
||||
dev = { link, input, output, info: null, pdesc: [], gdesc: [], names: [], dump: null, steps: [], slotUsed: [null, null, null, null],
|
||||
keys: null, watch: false, bank: null };
|
||||
sets.clear(); /* (another FM-1, maybe) */
|
||||
@@ -4939,7 +4965,7 @@ function disconnect(reasonKey = "disconnected") {
|
||||
|
||||
function onState(e) {
|
||||
const p = e.port;
|
||||
if (!p || !/felucca/i.test(p.name || "")) return;
|
||||
if (!p || !FM1_PORT.test(p.name || "")) return;
|
||||
if (dev && p.state === "disconnected" && (p.id === dev.input.id || p.id === dev.output.id)) {
|
||||
disconnect("lost");
|
||||
} else if (!dev && wantConnected && p.state === "connected" && p.type === "output") {
|
||||
|
||||
Reference in new issue
Block a user