|
@@ -17,15 +17,16 @@
|
|
|
|
|
|
|
|
async function save() {
|
|
async function save() {
|
|
|
if (!seq) return;
|
|
if (!seq) return;
|
|
|
- const s = seq.slot;
|
|
|
|
|
- const n = name;
|
|
|
|
|
- const b = Number(bpm);
|
|
|
|
|
- const l = Number(bars);
|
|
|
|
|
- if (n === seq.name && b === seq.bpm && l === seq.bars) return;
|
|
|
|
|
- if (seq.hasNotes && l < seq.bars) {
|
|
|
|
|
|
|
+ // Copied before any await: props are live and may change meanwhile.
|
|
|
|
|
+ const slot = seq.slot;
|
|
|
|
|
+ const newName = name;
|
|
|
|
|
+ const newBpm = Number(bpm);
|
|
|
|
|
+ const newBars = Number(bars);
|
|
|
|
|
+ if (newName === seq.name && newBpm === seq.bpm && newBars === seq.bars) return;
|
|
|
|
|
+ if (seq.hasNotes && newBars < seq.bars) {
|
|
|
const ok = await confirm({
|
|
const ok = await confirm({
|
|
|
title: "Shorten a sequence with notes?",
|
|
title: "Shorten a sequence with notes?",
|
|
|
- message: `${seq.name} has recorded notes. Notes after bar ${l} will not play, but they are kept: lengthening the sequence again brings them back.`,
|
|
|
|
|
|
|
+ message: `${seq.name} has recorded notes. Notes after bar ${newBars} will not play, but they are kept: lengthening the sequence again brings them back.`,
|
|
|
items: [],
|
|
items: [],
|
|
|
action: "Shorten",
|
|
action: "Shorten",
|
|
|
});
|
|
});
|
|
@@ -34,10 +35,10 @@
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
- await run(() => Service.SetSequence(s, n, b, l));
|
|
|
|
|
|
|
+ await run(() => Service.SetSequence(slot, newName, newBpm, newBars));
|
|
|
// run() replaced the state; if Go refused, the fields still hold the
|
|
// run() replaced the state; if Go refused, the fields still hold the
|
|
|
// typed values, so put the stored ones back.
|
|
// typed values, so put the stored ones back.
|
|
|
- const now = app.state?.sequences?.find((q) => q.slot === s);
|
|
|
|
|
|
|
+ const now = app.state?.sequences?.find((q) => q.slot === slot);
|
|
|
if (now) {
|
|
if (now) {
|
|
|
name = now.name;
|
|
name = now.name;
|
|
|
bpm = now.bpm;
|
|
bpm = now.bpm;
|
|
@@ -47,14 +48,14 @@
|
|
|
|
|
|
|
|
async function remove() {
|
|
async function remove() {
|
|
|
if (!seq) return;
|
|
if (!seq) return;
|
|
|
- const s = seq.slot;
|
|
|
|
|
|
|
+ const slot = seq.slot; // copied before the await, as in save()
|
|
|
const ok = await confirm({
|
|
const ok = await confirm({
|
|
|
title: `Remove ${seq.name}?`,
|
|
title: `Remove ${seq.name}?`,
|
|
|
message: seq.hasNotes ? "Its recorded notes will be deleted too." : "The sequence has no recorded notes.",
|
|
message: seq.hasNotes ? "Its recorded notes will be deleted too." : "The sequence has no recorded notes.",
|
|
|
items: [],
|
|
items: [],
|
|
|
action: "Remove",
|
|
action: "Remove",
|
|
|
});
|
|
});
|
|
|
- if (ok) await run(() => Service.RemoveSequence(s));
|
|
|
|
|
|
|
+ if (ok) await run(() => Service.RemoveSequence(slot));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
function enter(e: KeyboardEvent) {
|
|
function enter(e: KeyboardEvent) {
|