Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
(fix) Take retry: restored automation follows devices moved or removed during the take
Egor Khindikaynen2e220fc571ff
diff --git a/src/native/nota.engine/src/engine/Engine_TakeRetry.cpp b/src/native/nota.engine/src/engine/Engine_TakeRetry.cppindex e95c0106..7f03e638 100644--- a/src/native/nota.engine/src/engine/Engine_TakeRetry.cpp+++ b/src/native/nota.engine/src/engine/Engine_TakeRetry.cpp@@ -9,6 +9,7 @@// queued behind the transport moves, so nothing from before the restart reaches it.#include "Engine.h"+#include "ParamPath.h"#include <algorithm>#include <cmath>@@ -61,6 +62,37 @@ void Engine::closeTakeAttempt() {retryStartBeat_ = std::numeric_limits<double>::quiet_NaN();}+// The pre-take lanes of `base`, aimed at the devices as `cur` has them: a device moved during+// the take keeps its lanes (devices are shared between track copies, so the object finds its+// new slot), one removed takes its lanes with it — as remapAutomationAfterDeviceChange does.+static std::vector<TrackLane> lanesOnto(const Track& base, const Track& cur) {+ auto slotIn = [](const auto& from, const auto& to, int32_t idx) -> int32_t {+ if (idx < 0 || idx >= static_cast<int32_t>(from.size())) return -1;+ auto it = std::find(to.begin(), to.end(), from[static_cast<size_t>(idx)]);+ return it == to.end() ? -1 : static_cast<int32_t>(it - to.begin());+ };+ std::vector<TrackLane> out;+ out.reserve(base.automation.size());+ for (TrackLane l : base.automation) {+ const bool midiRack = l.nested() && isMidiHost(l.deviceIndex);+ const bool midi = midiRack || (!l.nested() && l.target == AutomationTarget::MidiDeviceParam);+ const bool effect = !midi && (l.nested() ? l.deviceIndex >= 0+ : l.target == AutomationTarget::DeviceParam ||+ (l.target == AutomationTarget::PluginParam && l.deviceIndex >= 0));+ if (midi) {+ const int32_t ni = slotIn(base.midiEffects, cur.midiEffects, midiRack ? midiHostIndex(l.deviceIndex) : l.deviceIndex);+ if (ni < 0) continue;+ l.deviceIndex = midiRack ? midiHost(ni) : ni;+ } else if (effect) {+ const int32_t ni = slotIn(base.devices, cur.devices, l.deviceIndex);+ if (ni < 0) continue;+ l.deviceIndex = ni;+ }+ out.push_back(std::move(l));+ }+ return out;+}+void Engine::discardTake() {if (!takeAttempt_.active) return;TakeAttempt a = std::move(takeAttempt_);@@ -113,7 +145,7 @@ void Engine::discardTake() {nt->clips = base->clips;nt->takes = base->takes;nt->midiClips = base->midiClips;- nt->automation = base->automation;+ nt->automation = lanesOnto(*base, *cur);return nt;}const int32_t sc = a.sessionScene;diff --git a/tests/Nota.SmokeTest/RetryTakeTests.cs b/tests/Nota.SmokeTest/RetryTakeTests.csindex a7104eda..444ca79d 100644--- a/tests/Nota.SmokeTest/RetryTakeTests.cs+++ b/tests/Nota.SmokeTest/RetryTakeTests.cs@@ -34,6 +34,7 @@ internal static class RetryTakeTestsforeach (var r in AutomationOnAnotherTrack()) yield return r;foreach (var r in EditsMadeMeanwhile()) yield return r;foreach (var r in RecordingTrackEditedMeanwhile()) yield return r;+ foreach (var r in DeviceMovedMeanwhile()) yield return r;foreach (var r in DisarmedTakeIsKept()) yield return r;foreach (var r in SessionHeldIntoRelaunch()) yield return r;foreach (var r in SessionToggleSlot()) yield return r;@@ -208,6 +209,41 @@ internal static class RetryTakeTests$"retry keeps a rename of the recording track (name kept {named}, take dropped {dropped}, rename undoes to the old name without the take {renameUndone})");}+ // Moving an automated effect mid-take: the pre-take lane comes back aimed at the effect+ // where it now sits; removing one takes its lane with it.+ private static IEnumerable<(bool, string)> DeviceMovedMeanwhile()+ {+ const int Utility = 4, Delay = 3;+ using var e = Armed(out int t);+ e.AddBuiltinDevice(t, Utility);+ e.AddBuiltinDevice(t, Delay);+ int lane = e.AddAutomationLane(t, AutomationTarget.DeviceParam, 0, 0); // the Utility+ e.SetAutomationPoints(t, lane, new[] { new AutomationPoint(0, 0.2f), new AutomationPoint(4, 0.8f) });+ int lanes = e.AutomationLaneCount(t);+ e.SetCountIn(0);+ e.Seek(0.0);+ Beats(e, 0.01);+ e.SetRecording(true);+ Beats(e, 0.5);+ e.BeginAutomationWrite(t, AutomationTarget.Pan, -1, -1, "");+ Beats(e, 0.5);+ e.EndAutomationWrite(t, AutomationTarget.Pan, -1, -1, "");+ e.MoveDevice(t, 0, 1); // the Utility now sits second+ e.RetryTake();+ Beats(e, 0.01);+ var moved = Enumerable.Range(0, e.AutomationLaneCount(t)).Select(i => e.AutomationLaneInfo(t, i))+ .Where(i => i.Target == AutomationTarget.DeviceParam).ToArray();+ yield return (e.AutomationLaneCount(t) == lanes && moved.Length == 1 && moved[0].DeviceIndex == 1 && moved[0].PointCount == 2,+ $"retry after moving an automated effect: its lane follows it (lanes {lanes} → {e.AutomationLaneCount(t)}, device {(moved.Length == 1 ? moved[0].DeviceIndex : -9)})");+ e.RemoveDevice(t, 1); // the Utility goes, mid-take+ e.RetryTake();+ Beats(e, 0.01);+ bool gone = Enumerable.Range(0, e.AutomationLaneCount(t)).All(i => e.AutomationLaneInfo(t, i).Target != AutomationTarget.DeviceParam);+ yield return (gone, "retry after removing an automated effect: its lane goes with it");+ e.SetRecording(false);+ e.StopTransport();+ }+// Disarming the track ends (and keeps) its take: a retry afterwards has nothing to discard.private static IEnumerable<(bool, string)> DisarmedTakeIsKept(){