Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

(fix) Copies keep their links, rack chains keep built-in state, Session feeds rack keys

Egor Khindikaynend57b93f4c906
diff --git a/src/managed/Nota.Application/Editing/PresetEdit.cs b/src/managed/Nota.Application/Editing/PresetEdit.cs
index 6771ed69..24c5654a 100644
--- a/src/managed/Nota.Application/Editing/PresetEdit.cs
+++ b/src/managed/Nota.Application/Editing/PresetEdit.cs
@@ -33,11 +33,18 @@ public static class PresetEdit
};
targets[^1] = MixTarget.PresetTag(trackId, surface, index);
string warn = "";
- MixEdit.Step(engine, () =>
+ // A group around the gesture: what apply() changes beside the parameters (an EQ-8's band
+ // labels, each its own undo entry) undoes with them however few parameters there are.
+ engine.BeginUndoGroup();
+ try
{
- warn = apply();
- if (warn.Length == 0) engine.SetDevicePresetTag(trackId, surface, index, presetId, name);
- }, targets);
+ MixEdit.Step(engine, () =>
+ {
+ warn = apply();
+ if (warn.Length == 0) engine.SetDevicePresetTag(trackId, surface, index, presetId, name);
+ }, targets);
+ }
+ finally { engine.EndUndoGroup(); }
return warn;
}
diff --git a/src/native/nota.engine/src/devices/racks/RackCore.cpp b/src/native/nota.engine/src/devices/racks/RackCore.cpp
index d7d3fd44..f960a070 100644
--- a/src/native/nota.engine/src/devices/racks/RackCore.cpp
+++ b/src/native/nota.engine/src/devices/racks/RackCore.cpp
@@ -180,6 +180,37 @@ bool RackCore::removeChain(int32_t chain) {
return true;
}
+// What the blob leaves out because it points outside the rack: the children's sidechain keys
+// and the Arps' CC targets. A target in the source chain itself moves to the copy.
+void RackCore::copyExternalLinks(const RackChain& src, RackChain& dst) {
+ if (src.devices.size() == dst.devices.size())
+ for (size_t i = 0; i < src.devices.size(); ++i) {
+ const Device* s = src.devices[i].get();
+ Device* d = dst.devices[i].get();
+ if (!s || !d) continue;
+ d->setSidechainSourceTrackId(s->sidechainSourceTrackId());
+ d->setSidechainPart(s->sidechainPart());
+ d->setSidechainTapPre(s->sidechainTapPre());
+ d->setSidechainGainDb(s->sidechainGainDb());
+ d->setSidechainMix(s->sidechainMix());
+ }
+ if (src.instrument && dst.instrument) {
+ dst.instrument->setSidechainSourceTrackId(src.instrument->sidechainSourceTrackId());
+ dst.instrument->setSidechainPart(src.instrument->sidechainPart());
+ }
+ if (src.midiDevices.size() == dst.midiDevices.size())
+ for (size_t i = 0; i < src.midiDevices.size(); ++i) {
+ const MidiDevice* s = src.midiDevices[i].get();
+ MidiDevice* d = dst.midiDevices[i].get();
+ if (!s || !d) continue;
+ d->setCcDepth(s->ccDepth());
+ if (s->ccDestDevice() < 0 && s->ccDestChainUid() == 0) continue;
+ d->setCcDest(s->ccDestDevice(), s->ccDestParam());
+ if (const uint64_t uid = s->ccDestChainUid())
+ d->setCcDestNested(uid == src.uid ? dst.uid : uid, s->ccDestSlot());
+ }
+}
+
int32_t RackCore::duplicateChain(int32_t chain) {
if (chain < 0 || chain >= chainCount()) return -1;
// Rebuild the chain from this rack's own blob in a scratch rack: the blob already knows
@@ -191,7 +222,9 @@ int32_t RackCore::duplicateChain(int32_t chain) {
if (!tmp.authoring_ || chain >= static_cast<int32_t>(tmp.authoring_->chains.size())) return -1;
auto ns = copyState();
const int32_t at = chain + 1;
- ns->chains.insert(ns->chains.begin() + at, std::move(tmp.authoring_->chains[chain]));
+ RackChain& copy = tmp.authoring_->chains[chain];
+ copyExternalLinks(ns->chains[chain], copy);
+ ns->chains.insert(ns->chains.begin() + at, std::move(copy));
std::vector<MacroMapping> copies;
for (auto& m : ns->mappings) {
if (m.chainIndex == chain) {
@@ -714,6 +747,13 @@ std::vector<uint8_t> RackCore::serialize() const {
};
putPreview(c.instrument ? c.instrument->editorPreview : EditorPreview{});
for (auto& d : c.devices) putPreview(d ? d->editorPreview() : EditorPreview{});
+ // v11: each built-in device's state blob (an EQ-8's band labels, a looper's take, a
+ // nested rack); a hosted plug-in's went in above. 0 = none.
+ for (auto& d : c.devices) {
+ std::vector<uint8_t> ds = d && d->builtinKind() >= 0 ? d->getState() : std::vector<uint8_t>{};
+ putU32(b, static_cast<uint32_t>(ds.size()));
+ b.insert(b.end(), ds.begin(), ds.end());
+ }
}
return b;
}
@@ -882,6 +922,12 @@ void RackCore::deserialize(const uint8_t* data, int32_t size) {
if (d) d->setEditorPreview(std::move(dp));
}
}
+ if (ver >= 11)
+ for (auto* d : devAt) {
+ const uint32_t n = getU32(cur);
+ const uint8_t* p = cur.take(n);
+ if (d && p && n > 0 && d->builtinKind() >= 0) d->setState(p, static_cast<int32_t>(n));
+ }
ns->chains.push_back(std::move(c));
}
commit(ns);
diff --git a/src/native/nota.engine/src/devices/racks/RackCore.h b/src/native/nota.engine/src/devices/racks/RackCore.h
index 85b4ff6e..2d681a05 100644
--- a/src/native/nota.engine/src/devices/racks/RackCore.h
+++ b/src/native/nota.engine/src/devices/racks/RackCore.h
@@ -527,6 +527,8 @@ class RackCore {
int32_t maxBlock_ = kMaxBlock;
private:
+ // duplicateChain: the keys and Arp targets the blob doesn't carry, from src to its copy.
+ static void copyExternalLinks(const RackChain& src, RackChain& dst);
std::shared_ptr<RackState> copyState() const {
return authoring_ ? std::make_shared<RackState>(*authoring_) : std::make_shared<RackState>();
}
@@ -637,7 +639,7 @@ class RackCore {
static constexpr uint32_t kMagic = 0x314B524E; // 'NRK1'
static constexpr uint32_t kBlobVersion =
- 10; // v2 triggerNote; v3 Sampler; v4 plugins; v5 zones/names/rack-out/curve; v6 drum pad shaping + swing/humanize; v7 effect-rack mode/dry-wet/pdc/select; v8 chain name; v9 chain MIDI effects + select range/transpose/vel scale, mono/merge/thru (specs/040); v10 chain children's editor previews (specs/046)
+ 11; // v2 triggerNote; v3 Sampler; v4 plugins; v5 zones/names/rack-out/curve; v6 drum pad shaping + swing/humanize; v7 effect-rack mode/dry-wet/pdc/select; v8 chain name; v9 chain MIDI effects + select range/transpose/vel scale, mono/merge/thru (specs/040); v10 chain children's editor previews (specs/046); v11 built-in chain devices' state
std::shared_ptr<RackState> authoring_;
SnapshotHistory<RackState> states_;
diff --git a/src/native/nota.engine/src/engine/Engine.h b/src/native/nota.engine/src/engine/Engine.h
index 37944938..2e5e1250 100644
--- a/src/native/nota.engine/src/engine/Engine.h
+++ b/src/native/nota.engine/src/engine/Engine.h
@@ -1392,6 +1392,7 @@ class Engine {
void feedMidiKey(Graph* g, Device& d, int32_t srcTrackId);
// Sidechain / MIDI key for a device and, for a rack, its chain children (specs/044).
void feedDeviceKey(Graph* g, Device& d, int32_t ownTrackId, int32_t frames);
+ void feedInstrumentKeys(Graph* g, Track& t, int32_t frames);
void feedRackChildKeys(Graph* g, const RackCore& r, int32_t ownTrackId, int32_t frames);
void renderSessionSlotRaw(Track& t, float* dst, int32_t frames, double spb);
// Session P0 (audio thread): queue a follow action / Repeat retrigger before the launch
diff --git a/src/native/nota.engine/src/engine/Engine_Devices.cpp b/src/native/nota.engine/src/engine/Engine_Devices.cpp
index e57e8d2e..fe34da9d 100644
--- a/src/native/nota.engine/src/engine/Engine_Devices.cpp
+++ b/src/native/nota.engine/src/engine/Engine_Devices.cpp
@@ -1143,10 +1143,10 @@ int32_t Engine::insertDeviceClone(int32_t trackId, std::shared_ptr<Device> dev,
const int32_t end = static_cast<int32_t>(nt->devices.size());
const int32_t at = (atIndex < 0 || atIndex > end) ? end : atIndex;
nt->devices.insert(nt->devices.begin() + at, dev);
- // An insert is a move from just past the end: the lanes and CV links after it shift up.
- if (at != end) remapAutomationAfterDeviceChange(*nt, false, -1, end, at);
- republishWithTrack(trackId, nt);
- if (at != end) remapCvLinksAfterDeviceChange(trackId, -1, end, at);
+ // The lanes, CV links and Arp CC targets on the devices after it shift up; the copy has none.
+ publishWithRefMap(trackId, nt, [at](const DeviceRef& r) -> DeviceRef {
+ return r.fam == 0 && r.idx >= at ? DeviceRef{0, r.idx + 1, r.uid, r.slot} : r;
+ });
recomputePdc();
return at;
}
@@ -1167,8 +1167,10 @@ int32_t Engine::insertMidiEffectClone(int32_t trackId, std::shared_ptr<MidiDevic
const int32_t end = static_cast<int32_t>(nt->midiEffects.size());
const int32_t at = (atIndex < 0 || atIndex > end) ? end : atIndex;
nt->midiEffects.insert(nt->midiEffects.begin() + at, md);
- if (at != end) remapAutomationAfterDeviceChange(*nt, true, -1, end, at);
- republishWithTrack(trackId, nt);
+ // As for an audio effect; a duplicated Arp's own target is rewritten with the rest.
+ publishWithRefMap(trackId, nt, [at](const DeviceRef& r) -> DeviceRef {
+ return r.fam == 1 && r.idx >= at ? DeviceRef{1, r.idx + 1, r.uid, r.slot} : r;
+ });
return at;
}
diff --git a/src/native/nota.engine/src/engine/Engine_Rack.cpp b/src/native/nota.engine/src/engine/Engine_Rack.cpp
index 25c16aef..457f84a5 100644
--- a/src/native/nota.engine/src/engine/Engine_Rack.cpp
+++ b/src/native/nota.engine/src/engine/Engine_Rack.cpp
@@ -947,7 +947,13 @@ int32_t Engine::rackDuplicateChain(int32_t t, int32_t di, int32_t c) {
for (int32_t j = c; j < n; ++j)
if (r->chainMidiDeviceCount(j) > 0 && j + 1 >= RackInstrument::kMaxMidiChains) return -1;
}
- return rackForEdit(t, di)->duplicateChain(c);
+ auto* fork = rackForEdit(t, di);
+ const int32_t at = fork ? fork->duplicateChain(c) : -1;
+ if (at < 0) return at;
+ // The copy keeps its children's keys and Arp targets: give them their routes.
+ recomputeRouting();
+ if (ccDestsSet_) republishCcRoutes(t);
+ return at;
}
bool Engine::rackCheckpoint(int32_t t, int32_t di) { return rackForEdit(t, di) != nullptr; }
int64_t Engine::rackChainId(int32_t t, int32_t di, int32_t c) const {
diff --git a/src/native/nota.engine/src/engine/Engine_Render.cpp b/src/native/nota.engine/src/engine/Engine_Render.cpp
index 6a7030e5..fbb17207 100644
--- a/src/native/nota.engine/src/engine/Engine_Render.cpp
+++ b/src/native/nota.engine/src/engine/Engine_Render.cpp
@@ -1963,6 +1963,7 @@ void Engine::renderLeafDry(Track& t, float* dst, const LeafWork& w, Graph* g, in
case LeafPath::Frozen: fillFrozen(t, dst, frames, blockStart, spb); break;
case LeafPath::Monitor: renderMonitorInput(g, t, dst, frames); break;
case LeafPath::SessionInst:
+ feedInstrumentKeys(g, t, frames); // a Session clip plays the same instrument: its keys too
feedPartTaps(t); // a Session clip plays the same pads: their keys too (specs/050)
renderSessionSlotRaw(t, dst, frames, spb);
if (t.instrument) t.instrument->setPartTaps(nullptr, 0);
@@ -1975,14 +1976,7 @@ void Engine::renderLeafDry(Track& t, float* dst, const LeafWork& w, Graph* g, in
case LeafPath::Instrument:
if (t.instrument) {
t.instrument->setTransportInfo(ti); // hosted-plugin sync
- // React (Nota Flux): hand a listening instrument its source track's
- // previous-block, post-fader signal just before it renders.
- const int32_t iSc = t.instrument->sidechainSourceTrackId();
- if (iSc >= 0) {
- t.instrument->setSidechain(keyBuffer(iSc, t.instrument->sidechainPart(), false), frames);
- }
- // Keyed devices and instruments inside an Instrument Rack's chains (specs/044).
- if (auto* r = t.instrument->asRack()) feedRackChildKeys(g, *r, t.id(), frames);
+ feedInstrumentKeys(g, t, frames);
}
feedPartTaps(t);
renderInstrumentRaw(g, t, dst, frames, blockStart, spb, playing);
@@ -2030,6 +2024,16 @@ void Engine::feedDeviceKey(Graph* g, Device& d, int32_t ownTrackId, int32_t fram
if (auto* r = d.asRack()) feedRackChildKeys(g, *r, ownTrackId, frames);
}
+// React (Nota Flux): hand a listening instrument its source track's previous-block, post-fader
+// signal just before it renders; and the keyed devices and instruments inside an Instrument
+// Rack's chains theirs (specs/044). Audio thread.
+void Engine::feedInstrumentKeys(Graph* g, Track& t, int32_t frames) {
+ if (!t.instrument) return;
+ const int32_t iSc = t.instrument->sidechainSourceTrackId();
+ if (iSc >= 0) t.instrument->setSidechain(keyBuffer(iSc, t.instrument->sidechainPart(), false), frames);
+ if (auto* r = t.instrument->asRack()) feedRackChildKeys(g, *r, t.id(), frames);
+}
+
void Engine::feedRackChildKeys(Graph* g, const RackCore& r, int32_t ownTrackId, int32_t frames) {
r.forEachChildDevice([&](Device& c) {
if (!c.bypassed() && !c.asRack()) feedDeviceKey(g, c, ownTrackId, frames);
diff --git a/tests/Nota.SmokeTest/DeviceCopyTests.cs b/tests/Nota.SmokeTest/DeviceCopyTests.cs
index d238c1e7..c1079d3a 100644
--- a/tests/Nota.SmokeTest/DeviceCopyTests.cs
+++ b/tests/Nota.SmokeTest/DeviceCopyTests.cs
@@ -32,6 +32,54 @@ internal static class DeviceCopyTests
foreach (var r in DrumRackUndo()) yield return r;
foreach (var r in InstrumentRackUndo()) yield return r;
foreach (var r in WrapInRack()) yield return r;
+ foreach (var r in CopiesKeepLinks()) yield return r;
+ }
+
+ // What points at or out of a copy follows it: a duplicate shifts the Arp CC targets behind
+ // it, and a duplicated rack chain keeps its children's keys, Arp targets and built-in state.
+ private static IEnumerable<(bool, string)> CopiesKeepLinks()
+ {
+ using var e = new NotaEngine();
+ int t = e.AddInstrumentTrack();
+ e.SetTrackBuiltinInstrument(t, 6); // Volt
+ int arp = e.AddMidiEffect(t, Arp);
+ int a = e.AddBuiltinDevice(t, 0);
+ int b = e.AddBuiltinDevice(t, 3);
+ e.SetMidiEffectCcDest(t, arp, b, 1);
+ int dup = e.DuplicateDevice(t, a);
+ yield return (dup == a + 1 && e.MidiEffectCcDestDevice(t, arp) == b + 1,
+ $"copies keep links: duplicating an effect before an Arp's target moves the target with it ({e.MidiEffectCcDestDevice(t, arp)})");
+ int arp2 = e.DuplicateMidiEffect(t, arp);
+ yield return (arp2 == arp + 1 && e.MidiEffectCcDestDevice(t, arp) == b + 1 && e.MidiEffectCcDestDevice(t, arp2) == b + 1,
+ "copies keep links: a duplicated Arp drives the same effect");
+ e.Undo();
+ yield return (e.Undo() && e.MidiEffectCcDestDevice(t, arp) == b, "copies keep links: undo puts the target back");
+
+ // An Arp inside an Instrument Rack chain driving a device of the same chain: the copied
+ // chain's Arp drives the copied device.
+ e.GroupDevices(t, 0, 1, true, 0, 2); // Arp, Volt, EQ-8, Delay in one chain
+ var d0 = e.RackChainMidiCcDest(t, -1, 0, 0);
+ int c1 = e.RackDuplicateChain(t, 0);
+ var d1 = e.RackChainMidiCcDest(t, -1, c1, 0);
+ yield return (d0 is { Chain: 0, Slot: 1, Param: 1 } && c1 == 1 && d1 is { Chain: 1, Slot: 1, Param: 1 }
+ && e.RackChainMidiCcDest(t, -1, 0, 0) == d0,
+ $"copies keep links: a duplicated chain's Arp drives its own chain's device ({d0} → {d1})");
+
+ // A keyed Compressor and a labelled EQ-8 in an Audio Effect Rack chain.
+ int src = e.AddAudioTrack();
+ int at = e.AddAudioTrack();
+ int eq = e.AddBuiltinDevice(at, 0);
+ e.EqSetBandText(at, eq, 2, "Mud", "200 Hz build-up");
+ int r = e.WrapDeviceInRack(at, eq);
+ e.RackDevAddChainDevice(at, r, 0, 1);
+ e.RackChainSetSidechain(at, r, 0, 1, new NestedSidechain(src, false, 3f, 0.5f));
+ int rc = e.RackDevDuplicateChain(at, r, 0);
+ yield return (rc == 1 && e.RackChainSidechain(at, r, 1, 1) is { SourceTrack: var k, GainDb: 3f, Mix: 0.5f } && k == src,
+ $"copies keep links: a duplicated chain's Compressor keeps its key ({e.RackChainSidechain(at, r, 1, 1)})");
+ e.RackDevRemoveChain(at, r, 0);
+ int n = e.UnwrapRack(at, r);
+ yield return (n == 2 && e.EqBandText(at, 0, 2, 0) == "Mud" && e.EqBandText(at, 0, 2, 1) == "200 Hz build-up",
+ $"copies keep links: an EQ-8 in a duplicated chain keeps its band labels (\"{e.EqBandText(at, 0, 2, 0)}\")");
}
private static string Chain(NotaEngine e, int t)
diff --git a/tests/Nota.SmokeTest/EqLabelTests.cs b/tests/Nota.SmokeTest/EqLabelTests.cs
index 7f9d79e4..fe4d822c 100644
--- a/tests/Nota.SmokeTest/EqLabelTests.cs
+++ b/tests/Nota.SmokeTest/EqLabelTests.cs
@@ -98,6 +98,15 @@ internal static class EqLabelTests
e.Undo();
yield return (L(e, t, d, 2) == "Mud" && e.DeviceGetParam(t, d, 2 * 5 + 2) == 250f,
"undoing a label leaves the band's params as they are");
+
+ // A preset applied in place is one step, its labels with its params (63 params: one gesture).
+ var preset = new PresetDocument { Type = "builtin-effect", BuiltinKind = Eq8Kind, NamedParams = new() { ["Labels"] = 1f },
+ BandText = [new PresetBandText { Band = 1, Label = "Low", Note = "" }] };
+ Nota.Application.Editing.PresetEdit.Apply(e, t, PresetSurface.Effect, d, "", "",
+ () => PresetService.ApplyInPlace(preset, e, t, d));
+ bool applied = L(e, t, d, 0) == "Low" && L(e, t, d, 2) == "" && e.DeviceGetParam(t, d, 2 * 5 + 2) != 250f;
+ yield return (applied && e.Undo() && L(e, t, d, 2) == "Mud" && L(e, t, d, 0) == "" && e.DeviceGetParam(t, d, 2 * 5 + 2) == 250f,
+ $"one undo takes back a preset's labels with its params (\"{L(e, t, d, 2)}\")");
}
private static IEnumerable<(bool, string)> Copies()