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.

(feat) paste bounced audio

Egor Khindikaynen5dfa7f8af0fa
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1c0d0a21..2c3502eb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,9 +16,20 @@ created, and the build-and-publish run starts.
Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
+### Fixed
+- Right-clicking empty space on a track now always opens a menu. It used to show nothing
+ when there was no copied clip.
+
## [Unreleased]
### Added
+- **Paste Bounced Audio** (⌘⇧V, Ctrl+Shift+V on Windows/Linux; also in the Edit menu),
+ like in Ableton Live. Select a range on any audio or MIDI track with Shift+drag, click an
+ audio track, and press ⌘⇧V. The range is rendered through the track's instrument and all
+ its effects, then pasted there at the playhead as a new audio clip, replacing what was
+ under it. You can also right-click an audio track and choose **Paste bounced audio** to
+ paste at that spot. The render runs in the background with a progress bar, and one undo
+ removes the paste.
- **Input monitoring** on audio tracks: the headphones button right of the track's input
selector lets you hear the input live through the track's effects and fader, whether or
not the transport is playing, like Ableton's Monitor "In". The input can be your audio
diff --git a/src/managed/Nota.App/ArrangementView.LaneControl.cs b/src/managed/Nota.App/ArrangementView.LaneControl.cs
index ea3d63c6..bb913584 100644
--- a/src/managed/Nota.App/ArrangementView.LaneControl.cs
+++ b/src/managed/Nota.App/ArrangementView.LaneControl.cs
@@ -424,6 +424,8 @@ public sealed partial class ArrangementView
// (except during playback — scrub from the ruler, not the grid).
_o.Select(-1, -1);
_o.ClearTimeSelection();
+ int row = _o.RowAtY(_marqueePress.Y);
+ if (row >= 0 && row < _o._tracks.Count) _o.FocusTrackId = _o._tracks[row].Id;
if (_o._engine is not { IsPlaying: true })
_o.SeekTo(_o._scrollBeats + _marqueePress.X / _o._pixelsPerBeat);
}
@@ -844,27 +846,48 @@ public sealed partial class ArrangementView
private static readonly KeyGesture ConsolidateGesture =
new(Key.J, OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control);
- // Right-click on empty lane space: paste the clipboard clip here (type permitting), and
- // consolidate the time selection when the click lands inside it.
+ // ⌘⇧V / Ctrl+⇧V, shown next to the context-menu Paste bounced audio items.
+ private static readonly KeyGesture PasteBouncedGesture =
+ new(Key.V, (OperatingSystem.IsMacOS() ? KeyModifiers.Meta : KeyModifiers.Control) | KeyModifiers.Shift);
+
+ // "Paste bounced audio" onto this track at `at`, or null when there's nothing to paste
+ // or the track can't take it (only audio tracks can).
+ private MenuItem? PasteBouncedItem(int trackId, double at)
+ {
+ if (!_o.CanPasteBouncedOnto(trackId)) return null;
+ var mi = new MenuItem { Header = "Paste bounced audio", InputGesture = PasteBouncedGesture };
+ mi.Click += (_, _) => _o.RequestPasteBounced(trackId, at);
+ return mi;
+ }
+
+ // Right-click on empty lane space: paste the clipboard clip (or the bounced range) here,
+ // insert a MIDI clip on an instrument track, and consolidate the time selection when the
+ // click lands inside it. Always opens, so the menu never silently fails to appear.
private void ShowLaneMenu(Point pos, double beat)
{
int ti = _o.RowAtY(pos.Y);
if (ti < 0) return;
- int trackId = _o._tracks[ti].Id;
+ var track = _o._tracks[ti];
+ int trackId = track.Id;
bool inRange = _o.TimeSelectionCovers(trackId, beat);
- if (!_o.HasClipClipboard && !inRange) return;
double at = _o.Snap(beat);
var flyout = new MenuFlyout();
- if (_o.HasClipClipboard)
+ var paste = new MenuItem { Header = "Paste", IsEnabled = _o.HasClipClipboard };
+ paste.Click += (_, _) => _o.PasteClipboardAt(trackId, at);
+ flyout.Items.Add(paste);
+ if (PasteBouncedItem(trackId, at) is { } bounced) flyout.Items.Add(bounced);
+ if (track.IsInstrument)
{
- var paste = new MenuItem { Header = "Paste" };
- paste.Click += (_, _) => _o.PasteClipboardAt(trackId, at);
- flyout.Items.Add(paste);
+ var insert = new MenuItem { Header = "Insert MIDI clip" };
+ insert.Click += (_, _) => _o.AddMidiClipAt(trackId, beat);
+ flyout.Items.Add(new Separator());
+ flyout.Items.Add(insert);
}
if (inRange)
{
var consolidate = new MenuItem { Header = "Consolidate selection", InputGesture = ConsolidateGesture };
consolidate.Click += (_, _) => _o.ConsolidateSelection();
+ flyout.Items.Add(new Separator());
flyout.Items.Add(consolidate);
}
flyout.ShowAt(this, showAtPointer: true);
@@ -935,6 +958,7 @@ public sealed partial class ArrangementView
flyout.Items.Add(copy);
flyout.Items.Add(cut);
flyout.Items.Add(paste);
+ if (PasteBouncedItem(trackId, at) is { } bounced) flyout.Items.Add(bounced);
flyout.Items.Add(new Separator());
flyout.Items.Add(split);
flyout.Items.Add(dup);
diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.cs
index cc1c0862..202cf119 100644
--- a/src/managed/Nota.App/ArrangementView.cs
+++ b/src/managed/Nota.App/ArrangementView.cs
@@ -1016,6 +1016,7 @@ public sealed partial class ArrangementView : UserControl
int prev = SelTrackId;
SelTrackId = trackId;
SelClipIndex = clipIndex;
+ if (trackId > 0) FocusTrackId = trackId;
_sel.Clear();
if (trackId > 0 && clipIndex >= 0) _sel.Add((trackId, clipIndex));
// Selecting into or out of a group changes that row's height, so the rows below it
@@ -1072,7 +1073,7 @@ public sealed partial class ArrangementView : UserControl
else
{
_sel.Add((trackId, clipIndex));
- SelTrackId = trackId; SelClipIndex = clipIndex; // the just-clicked clip is the primary
+ SelTrackId = trackId; SelClipIndex = clipIndex; FocusTrackId = trackId; // the just-clicked clip is the primary
}
UpdateHeaderSelection();
Redraw();
@@ -1119,9 +1120,43 @@ public sealed partial class ArrangementView : UserControl
_timeSelRowLo = Math.Max(0, Math.Min(rowA, rowB));
_timeSelRowHi = Math.Min(Math.Max(0, _tracks.Count - 1), Math.Max(rowA, rowB));
if (_sel.Count > 0) { _sel.Clear(); SelClipIndex = -1; UpdateHeaderSelection(); }
+ if (HasTimeSelection) BounceSource = (TimeSelectionTrackIds(), _timeSelStart, _timeSelEnd);
Redraw();
}
+ /// <summary>Paste Bounced Audio (⌘⇧V) source: the most recent time selection's tracks and
+ /// range. Outlives the selection itself, so the user can click over to the target track.</summary>
+ public (int[] TrackIds, double Start, double End)? BounceSource { get; private set; }
+
+ /// <summary>The track the user last clicked (clip, header, or empty lane space) — the target
+ /// of Paste Bounced Audio. Unlike <see cref="SelectedTrackId"/>, a click on empty lane space
+ /// keeps it, since that click is how the paste position (the playhead) is placed.</summary>
+ public int FocusTrackId { get; internal set; } = -1;
+
+ /// <summary>Context-menu Paste Bounced Audio onto (track id, beat).</summary>
+ public event Action<int, double>? PasteBouncedRequested;
+ internal void RequestPasteBounced(int trackId, double beat) => PasteBouncedRequested?.Invoke(trackId, beat);
+
+ /// <summary>True when Paste Bounced Audio can land on <paramref name="trackId"/>: it's an audio
+ /// track and the remembered range covers exactly one audio/instrument track that still exists.</summary>
+ internal bool CanPasteBouncedOnto(int trackId)
+ {
+ if (BounceSource is not { } src) return false;
+ var target = _tracks.Find(t => t.Id == trackId);
+ if (target is null || target.IsInstrument || target.IsReturn || target.IsGroup) return false;
+ int sources = 0;
+ foreach (int id in src.TrackIds)
+ if (_tracks.Find(t => t.Id == id) is { IsReturn: false, IsGroup: false }) sources++;
+ return sources == 1;
+ }
+
+ /// <summary>Refreshes and selects the clips the engine placed last (e.g. a bounced paste).</summary>
+ public void RefreshAndSelectPlaced()
+ {
+ Refresh();
+ ReselectPlaced();
+ }
+
internal void ClearTimeSelection()
{
if (_timeSelRowLo < 0) return;
@@ -1240,7 +1275,7 @@ public sealed partial class ArrangementView : UserControl
foreach (var c in _tracks[r].Clips)
if (c.StartBeat < bhi - 1e-6 && c.StartBeat + c.LengthBeats > blo + 1e-6)
_sel.Add((_tracks[r].Id, c.ClipIndex));
- SelTrackId = trackId; SelClipIndex = clipIndex;
+ SelTrackId = trackId; SelClipIndex = clipIndex; FocusTrackId = trackId;
UpdateHeaderSelection();
Redraw();
}
@@ -1272,7 +1307,7 @@ public sealed partial class ArrangementView : UserControl
if (HasTimeSelection) ClearTimeSelection();
_sel.Clear();
foreach (var c in clips) _sel.Add(c);
- if (_sel.Count > 0) { var f = _sel.First(); SelTrackId = f.track; SelClipIndex = f.clip; }
+ if (_sel.Count > 0) { var f = _sel.First(); SelTrackId = f.track; SelClipIndex = f.clip; FocusTrackId = f.track; }
else { SelTrackId = -1; SelClipIndex = -1; }
UpdateHeaderSelection();
Redraw();
diff --git a/src/managed/Nota.App/MainWindow.Input.cs b/src/managed/Nota.App/MainWindow.Input.cs
index 932ec042..3dc3f789 100644
--- a/src/managed/Nota.App/MainWindow.Input.cs
+++ b/src/managed/Nota.App/MainWindow.Input.cs
@@ -147,6 +147,17 @@ public partial class MainWindow
return;
}
+ // ⌘⇧V / ⌃⇧V = Paste Bounced Audio: render the last time selection through its track's
+ // chain and paste it onto the focused audio track at the playhead (MainWindow.PasteBounced).
+ if (e.Key == Key.V && ArrangementView.IsPrimaryDown(e.KeyModifiers)
+ && (e.KeyModifiers & KeyModifiers.Shift) != 0 && (e.KeyModifiers & KeyModifiers.Alt) == 0
+ && _editorRoll is not { GridFocused: true })
+ {
+ _ = PasteBouncedAsync();
+ e.Handled = true;
+ return;
+ }
+
// ⌘/⌃ + C/X/V = copy/cut/paste the selected arrangement clip. Skipped while the
// piano-roll grid is focused (it copies/pastes notes) and when nothing is
// actionable, so the event falls through to other handlers.
diff --git a/src/managed/Nota.App/MainWindow.PasteBounced.cs b/src/managed/Nota.App/MainWindow.PasteBounced.cs
new file mode 100644
index 00000000..bee616ab
--- /dev/null
+++ b/src/managed/Nota.App/MainWindow.PasteBounced.cs
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Paste Bounced Audio (⌘⇧V / Ctrl+Shift+V), as in Ableton Live. The most recent time
+// selection (Shift+drag) on an audio or instrument track is rendered through that track's
+// whole chain — instrument, MIDI FX, devices; pre-fader, like Freeze — and pasted as a new
+// audio clip onto the focused audio track at the playhead, overwriting what it covers.
+// The render takes the engine offline (like Freeze / Export), so it runs off the UI thread
+// behind the modal progress dialog.
+
+using System;
+using System.Linq;
+using System.Threading.Tasks;
+using Nota.Application;
+
+namespace Nota.App;
+
+public partial class MainWindow
+{
+ private bool _bounceBusy; // the menu accelerator and the key handler can both fire
+
+ private void OnMenuPasteBounced(object? sender, EventArgs e) => _ = PasteBouncedAsync();
+
+ // Keyboard / Edit menu: onto the focused track at the playhead. The lane context menu passes
+ // the right-clicked track and beat instead.
+ private async Task PasteBouncedAsync(int targetId = -1, double? atBeat = null)
+ {
+ if (_vm is null || _bounceBusy) return;
+ if (Timeline.BounceSource is not { } src)
+ { _vm.StatusText = "Select a time range first (Shift+drag), then paste it bounced onto an audio track."; return; }
+
+ // Only clip tracks render content (groups/returns have no chain of their own to bounce).
+ var sources = src.TrackIds.Where(id => TrackTypeOf(id) is 0 or 1).ToArray();
+ if (sources.Length == 0) { _vm.StatusText = "The selected range has no audio or instrument track to bounce."; return; }
+ if (sources.Length > 1) { _vm.StatusText = "Paste Bounced Audio takes a range on a single track."; return; }
+ int sourceId = sources[0];
+
+ if (targetId <= 0) targetId = Timeline.FocusTrackId;
+ if (TrackTypeOf(targetId) != 0) { _vm.StatusText = "Click an audio track to paste the bounced audio onto."; return; }
+
+ double at = Math.Max(0.0, atBeat ?? Engine.PositionBeats); // read now: the render moves the playhead
+ string name = Engine.GetTrackName(sourceId);
+
+ _bounceBusy = true;
+ _vm.SuspendEnginePolling = true;
+ float[]? pcm = null;
+ try
+ {
+ await RunBlockingAsync("Paste Bounced Audio", "Rendering…", async prog =>
+ {
+ var frac = new Progress<double>(f => prog.Report(ProgressReport.At(f, $"Rendering… {f * 100:0} %")));
+ pcm = await Task.Run(() => _freezer.BounceRange(Engine, sourceId, src.Start, src.End,
+ _vm.Transport.LoopOn, _vm.Transport.MetronomeOn, frac));
+ });
+ }
+ catch (Exception ex) { _vm.StatusText = $"Paste Bounced Audio failed: {ex.Message}"; return; }
+ finally { _vm.SuspendEnginePolling = false; _bounceBusy = false; }
+
+ if (pcm is null) { _vm.StatusText = "Couldn't render this track."; return; }
+ if (Engine.PasteAudioFrames(targetId, pcm, pcm.Length / 2, at, name) < 0)
+ { _vm.StatusText = "Couldn't paste the bounced audio."; return; }
+
+ Timeline.RefreshAndSelectPlaced();
+ _session?.Refresh();
+ _vm.StatusText = "Pasted bounced audio";
+ }
+
+ // Engine track type (0 audio, 1 instrument, 2 return, 3 group), or -1 when the id is gone.
+ private int TrackTypeOf(int trackId)
+ => trackId > 0 && Engine.TryGetTrackInfo(TrackIndexOf(trackId), out var ti) ? ti.Type : -1;
+}
diff --git a/src/managed/Nota.App/MainWindow.axaml b/src/managed/Nota.App/MainWindow.axaml
index 43d798c4..efbb4f74 100644
--- a/src/managed/Nota.App/MainWindow.axaml
+++ b/src/managed/Nota.App/MainWindow.axaml
@@ -48,6 +48,7 @@
<NativeMenuItem Header="Cut" Click="OnMenuCut"/>
<NativeMenuItem Header="Copy" Click="OnMenuCopy"/>
<NativeMenuItem Header="Paste" Click="OnMenuPaste"/>
+ <NativeMenuItem Header="Paste Bounced Audio" Click="OnMenuPasteBounced" Gesture="Shift+Cmd+V"/>
<NativeMenuItem Header="Delete" Click="OnMenuDeleteSel"/>
</NativeMenu>
</NativeMenuItem.Menu>
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 56ce930d..18e28be7 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -173,6 +173,7 @@ public partial class MainWindow : Window
Timeline.MidiClipActivated += OpenClipEditor;
Timeline.AudioClipActivated += OpenAudioClipEditor;
Timeline.ItemDropped += OnArrangementDrop; // browser drag & drop (M7-5)
+ Timeline.PasteBouncedRequested += (track, beat) => _ = PasteBouncedAsync(track, beat);
Timeline.ConvertClipRequested += OnConvertClip; // audio clip → MIDI (Convert / Slice)
// Arrangement context menus add tracks through the toolbar's own handlers, so the two
// routes seed, refresh and report identically.
diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.cs
index d33ccad0..0b055acc 100644
--- a/src/managed/Nota.App/PreferencesWindow.cs
+++ b/src/managed/Nota.App/PreferencesWindow.cs
@@ -661,6 +661,7 @@ public sealed class PreferencesWindow : NotaWindow
("Esc", "Cancel the current gesture / clear the selection · close the patch-bay overlay"),
("⌘G ⌘⇧G", "Group / ungroup selected tracks"),
("⌘C ⌘X ⌘V", "Copy / cut / paste clip (or automation range)"),
+ ("⌘⇧V", "Paste the last range as audio rendered through its devices"),
("⌘D", "Duplicate the selected clip(s) / range"),
("⌘E", "Split at the playhead · at the range edges"),
("⌘J", "Consolidate the selection into one clip per track"),
diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.cs
index 90b83eb4..8cc27cd1 100644
--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs
+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs
@@ -239,6 +239,14 @@ public interface IAudioEngine : IDisposable
void EndFreeze(int trackId);
/// <summary>Aborts an armed freeze capture.</summary>
void CancelFreeze();
+ /// <summary>Arms a capture exactly <paramref name="lengthBeats"/> long (no ring-out tail); returns frames.</summary>
+ long BeginBounce(int trackId, double lengthBeats);
+ /// <summary>Paste Bounced Audio: copies the armed capture's frames into <paramref name="outFrames"/>
+ /// (interleaved stereo) and disarms it without freezing the track. Returns frames copied.</summary>
+ long TakeFreezeCapture(float[] outFrames);
+ /// <summary>Places device-rate interleaved-stereo PCM on an audio track as a new clip at
+ /// <paramref name="atBeat"/>, overwriting what it covers (one undo step). Clip index, or -1.</summary>
+ int PasteAudioFrames(int trackId, float[] interleaved, long frames, double atBeat, string? name);
/// <summary>Drops a track's freeze buffer (back to live processing).</summary>
void UnfreezeTrack(int trackId);
/// <summary>True when the track is frozen.</summary>
diff --git a/src/managed/Nota.Infrastructure/Audio/TrackFreezer.cs b/src/managed/Nota.Infrastructure/Audio/TrackFreezer.cs
index 83e26914..89165321 100644
--- a/src/managed/Nota.Infrastructure/Audio/TrackFreezer.cs
+++ b/src/managed/Nota.Infrastructure/Audio/TrackFreezer.cs
@@ -65,6 +65,58 @@ public sealed class TrackFreezer
return true;
}
+ /// <summary>Paste Bounced Audio (⌘⇧V): renders <paramref name="trackId"/>'s post-device,
+ /// pre-fader sound over [<paramref name="startBeat"/>, <paramref name="endBeat"/>) and returns
+ /// it as interleaved stereo at the device rate (exactly the range, no tail), without freezing
+ /// the track. Null when the engine can't capture the track (unsupported type).</summary>
+ public float[]? BounceRange(IAudioEngine engine, int trackId, double startBeat, double endBeat,
+ bool restoreLoop, bool restoreMetronome, IProgress<double>? progress = null)
+ {
+ if (endBeat <= startBeat) return null;
+ double restoreBeat = engine.PositionBeats;
+ double loopStart = engine.LoopStart, loopEnd = engine.LoopEnd;
+
+ engine.Stop();
+ engine.SetLoop(false, 0, 0);
+ engine.SetMetronome(false);
+ engine.StopTransport();
+
+ long total = engine.BeginBounce(trackId, endBeat - startBeat);
+ if (total <= 0) { Restore(engine, restoreLoop, restoreMetronome, loopStart, loopEnd, restoreBeat); return null; }
+
+ float[] pcm;
+ try
+ {
+ engine.Seek(startBeat); // capture starts at the range start; held notes are chased
+ engine.Play();
+
+ var buf = new float[Chunk * 2];
+ long remaining = total, done = 0;
+ int lastPct = -1;
+ while (remaining > 0)
+ {
+ int m = (int)Math.Min(Chunk, remaining);
+ engine.RenderOffline(buf, m);
+ remaining -= m; done += m;
+ int pct = (int)(100.0 * done / total);
+ if (progress is not null && pct != lastPct) { lastPct = pct; progress.Report((double)done / total); }
+ }
+ engine.StopTransport();
+ pcm = new float[total * 2];
+ engine.TakeFreezeCapture(pcm); // disarms without freezing the track (short = zero-padded)
+ }
+ catch
+ {
+ engine.CancelFreeze();
+ Restore(engine, restoreLoop, restoreMetronome, loopStart, loopEnd, restoreBeat);
+ throw;
+ }
+
+ Restore(engine, restoreLoop, restoreMetronome, loopStart, loopEnd, restoreBeat);
+ progress?.Report(1.0);
+ return pcm;
+ }
+
private static void Restore(IAudioEngine engine, bool loop, bool metronome,
double loopStart, double loopEnd, double beat)
{
diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
index 10227563..95b5d299 100644
--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Tracks.cs
@@ -262,6 +262,13 @@ internal static partial class NativeMethods
internal static partial void TrackFreezeEnd(IntPtr engine, int trackId);
[LibraryImport(Lib, EntryPoint = "nota_track_freeze_cancel")]
internal static partial void TrackFreezeCancel(IntPtr engine);
+ [LibraryImport(Lib, EntryPoint = "nota_track_bounce_begin")]
+ internal static partial long TrackBounceBegin(IntPtr engine, int trackId, double lengthBeats);
+ [LibraryImport(Lib, EntryPoint = "nota_track_freeze_take")]
+ internal static partial long TrackFreezeTake(IntPtr engine, [Out] float[] outFrames, long capFrames);
+ [LibraryImport(Lib, EntryPoint = "nota_track_paste_audio_frames", StringMarshalling = StringMarshalling.Utf8)]
+ internal static partial int TrackPasteAudioFrames(IntPtr engine, int trackId, [In] float[] interleaved,
+ long frames, double atBeat, string? name);
[LibraryImport(Lib, EntryPoint = "nota_track_unfreeze")]
internal static partial void TrackUnfreeze(IntPtr engine, int trackId);
[LibraryImport(Lib, EntryPoint = "nota_track_is_frozen")]
diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
index 5073f7e7..b7622b4f 100644
--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Tracks.cs
@@ -389,6 +389,25 @@ public sealed partial class NotaEngine
/// <summary>Aborts an armed freeze capture without freezing anything.</summary>
public void CancelFreeze() { ThrowIfDisposed(); NativeMethods.TrackFreezeCancel(_handle); }
+ /// <summary>Like <see cref="BeginFreeze"/> but sized to exactly <paramref name="lengthBeats"/> (no
+ /// ring-out tail) — a one-shot range bounce finished with <see cref="TakeFreezeCapture"/>.</summary>
+ public long BeginBounce(int trackId, double lengthBeats)
+ { ThrowIfDisposed(); return NativeMethods.TrackBounceBegin(_handle, trackId, lengthBeats); }
+
+ /// <summary>Copies the armed capture's rendered frames (interleaved stereo, device rate) into
+ /// <paramref name="outFrames"/> and disarms it without freezing the track. Returns frames copied.</summary>
+ public long TakeFreezeCapture(float[] outFrames)
+ { ThrowIfDisposed(); return NativeMethods.TrackFreezeTake(_handle, outFrames, outFrames.Length / 2); }
+
+ /// <summary>Places device-rate interleaved-stereo PCM on an audio track at <paramref name="atBeat"/>
+ /// as a new clip, overwriting what it covers (one undo step). Returns the clip index, or -1.</summary>
+ public int PasteAudioFrames(int trackId, float[] interleaved, long frames, double atBeat, string? name)
+ {
+ ThrowIfDisposed();
+ if (frames * 2 > interleaved.Length) throw new ArgumentOutOfRangeException(nameof(frames));
+ return NativeMethods.TrackPasteAudioFrames(_handle, trackId, interleaved, frames, atBeat, name);
+ }
+
/// <summary>Drops a track's freeze buffer and returns it to live processing.</summary>
public void UnfreezeTrack(int trackId) { ThrowIfDisposed(); NativeMethods.TrackUnfreeze(_handle, trackId); }
diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.h
index ff61628a..82add03c 100644
--- a/src/native/nota.engine/include/nota/nota_engine.h
+++ b/src/native/nota.engine/include/nota/nota_engine.h
@@ -823,6 +823,17 @@ NOTA_API int64_t nota_track_freeze_begin(NotaEngine* engine, int32_t track_id
NOTA_API void nota_track_freeze_end(NotaEngine* engine, int32_t track_id);
NOTA_API void nota_track_freeze_cancel(NotaEngine* engine);
NOTA_API void nota_track_unfreeze(NotaEngine* engine, int32_t track_id);
+/* Paste Bounced Audio (⌘⇧V). bounce_begin arms a capture exactly length_beats long (no
+ * ring-out tail) and returns its frame count; seek to the range start and pump
+ * render_offline for that many frames, then freeze_take copies the captured post-device, pre-fader PCM
+ * (interleaved stereo, device rate, up to cap_frames) into out and disarms the capture
+ * WITHOUT freezing the track; returns frames copied. paste_audio_frames places such PCM on
+ * an audio track at at_beat as a new clip, overwriting what it covers (one undo step);
+ * returns the clip index or -1. name_utf8 may be NULL. */
+NOTA_API int64_t nota_track_bounce_begin(NotaEngine* engine, int32_t track_id, double length_beats);
+NOTA_API int64_t nota_track_freeze_take(NotaEngine* engine, float* out, int64_t cap_frames);
+NOTA_API int32_t nota_track_paste_audio_frames(NotaEngine* engine, int32_t track_id, const float* interleaved,
+ int64_t frames, double at_beat, const char* name_utf8);
NOTA_API int32_t nota_track_is_frozen(const NotaEngine* engine, int32_t track_id);
/* Opaque frozen-audio blob for project save/restore (header + interleaved PCM). get
* copies up to `cap` bytes into out and returns the full size (out=NULL probes the
diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.h
index c931ce23..969f6ade 100644
--- a/src/native/nota.engine/src/Engine.h
+++ b/src/native/nota.engine/src/Engine.h
@@ -276,6 +276,11 @@ public:
int32_t addAudioClip(int32_t trackId, const std::string& path, double startBeat);
// Places an already-decoded buffer (background import) — no disk I/O on this thread.
int32_t addAudioClipBuffer(int32_t trackId, std::shared_ptr<SampleBuffer> sample, double startBeat);
+ // Paste Bounced Audio: places device-rate interleaved-stereo PCM on an audio track at
+ // startBeat as a new (unwarped) clip, overwriting whatever it covers. One undo step.
+ // Returns the clip index, or -1 (not an audio track / empty buffer).
+ int32_t pasteAudioFrames(int32_t trackId, const float* interleaved, int64_t frames, double startBeat,
+ const std::string& name);
void setTrackVolume(int32_t trackId, float v);
void setTrackPan(int32_t trackId, float p);
void setTrackMute(int32_t trackId, bool m);
@@ -298,9 +303,13 @@ public:
// have the backend stopped and then pump renderOffline() for the returned frame
// count (the capture is filled inside mixGraph). endFreeze publishes the frozen
// track; cancelFreeze aborts without freezing. Not undoable (a view toggle).
- int64_t beginFreeze(int32_t trackId, double lengthBeats); // capture frames, or 0 on failure
+ int64_t beginFreeze(int32_t trackId, double lengthBeats, double tailSec = 2.0); // capture frames, or 0 on failure
void endFreeze(int32_t trackId);
void cancelFreeze();
+ // Paste Bounced Audio (⌘⇧V): copies the armed capture's rendered frames into out (up to
+ // capFrames, interleaved stereo) and disarms it WITHOUT freezing the track — a one-shot
+ // bounce of the track's post-device, pre-fader sound. Returns the frames copied.
+ int64_t takeFreezeCapture(float* out, int64_t capFrames);
void unfreeze(int32_t trackId); // drop the buffer, go back to live
bool trackFrozen(int32_t trackId) const;
// Opaque frozen-audio blob for project save/restore (header + interleaved PCM).
diff --git a/src/native/nota.engine/src/Engine_Tracks.cpp b/src/native/nota.engine/src/Engine_Tracks.cpp
index 1cb25e74..ded36145 100644
--- a/src/native/nota.engine/src/Engine_Tracks.cpp
+++ b/src/native/nota.engine/src/Engine_Tracks.cpp
@@ -1056,6 +1056,35 @@ void Engine::overwriteAudioClipsInRange(std::vector<AudioClip>& clips, double ns
audioOverwriteRange(clips, ns, ne, transport_.samplesPerBeat(), transport_.sampleRate());
}
+int32_t Engine::pasteAudioFrames(int32_t trackId, const float* interleaved, int64_t frames, double startBeat,
+ const std::string& name) {
+ if (!interleaved || frames <= 0) return -1;
+ auto old = findTrackAuthoring(trackId);
+ if (!old || old->type() != TrackType::Audio) return -1;
+ const double spb = transport_.samplesPerBeat(), devSR = transport_.sampleRate();
+ if (spb <= 0.0 || devSR <= 0.0) return -1;
+ startBeat = std::max(0.0, startBeat);
+
+ auto sb = std::make_shared<SampleBuffer>();
+ sb->channels = 2;
+ sb->frames = frames;
+ sb->sourceSampleRate = devSR; // the capture ran at the device rate
+ sb->samples.assign(interleaved, interleaved + static_cast<size_t>(frames) * 2);
+
+ auto nt = cloneTrack(*old);
+ audioOverwriteRange(nt->clips, startBeat, startBeat + static_cast<double>(frames) / spb, spb, devSR);
+ AudioClip clip;
+ clip.sample = std::move(sb);
+ clip.startBeat = startBeat;
+ clip.lengthFrames = frames;
+ clip.name = name;
+ nt->clips.push_back(std::move(clip));
+ const int32_t idx = static_cast<int32_t>(nt->clips.size()) - 1;
+ republishWithTrack(trackId, nt);
+ lastPlaced_ = { { trackId, idx } };
+ return idx;
+}
+
bool Engine::moveClip(int32_t trackId, int32_t clipIndex, double newStartBeat) {
auto old = findTrackAuthoring(trackId);
if (!old) return false;
@@ -2439,15 +2468,15 @@ int32_t Engine::clipNoteCount(int32_t trackId, int32_t clipIndex) const {
// bumps the whole project format).
namespace { constexpr int kFreezeHeaderBytes = static_cast<int>(sizeof(double) + sizeof(int64_t)); }
-int64_t Engine::beginFreeze(int32_t trackId, double lengthBeats) {
+int64_t Engine::beginFreeze(int32_t trackId, double lengthBeats, double tailSec) {
auto t = findTrackAuthoring(trackId);
if (!t) return 0;
if (t->type() != TrackType::Instrument && t->type() != TrackType::Audio) return 0;
const double sr = transport_.sampleRate() > 0.0 ? transport_.sampleRate() : 44100.0;
const double spb = transport_.samplesPerBeat();
if (spb <= 0.0 || lengthBeats <= 0.0) return 0;
- const double tailSec = 2.0; // let reverb/delay tails ring past the last clip
- int64_t frames = static_cast<int64_t>(std::ceil(lengthBeats * spb)) + static_cast<int64_t>(tailSec * sr);
+ // tailSec lets reverb/delay tails ring past the last clip (0 for an exact-range bounce).
+ int64_t frames = static_cast<int64_t>(std::ceil(lengthBeats * spb)) + static_cast<int64_t>(std::max(0.0, tailSec) * sr);
if (frames <= 0) return 0;
freezeCaptureBuf_.assign(static_cast<size_t>(frames) * 2, 0.0f);
freezeCapFrames_ = frames;
@@ -2477,6 +2506,13 @@ void Engine::cancelFreeze() {
freezeCapFrames_ = 0; freezeCursor_ = 0;
}
+int64_t Engine::takeFreezeCapture(float* out, int64_t capFrames) {
+ const int64_t n = (out && capFrames > 0) ? std::min(capFrames, freezeCursor_) : 0;
+ if (n > 0) std::memcpy(out, freezeCaptureBuf_.data(), static_cast<size_t>(n) * 2 * sizeof(float));
+ cancelFreeze(); // disarm + free the capture; the track itself is untouched
+ return n;
+}
+
void Engine::unfreeze(int32_t trackId) {
auto old = findTrackAuthoring(trackId);
if (!old || !old->frozen()) return;
diff --git a/src/native/nota.engine/src/nota_engine_track.cpp b/src/native/nota.engine/src/nota_engine_track.cpp
index 9e19ccca..ce24f404 100644
--- a/src/native/nota.engine/src/nota_engine_track.cpp
+++ b/src/native/nota.engine/src/nota_engine_track.cpp
@@ -531,6 +531,16 @@ void nota_track_freeze_end(NotaEngine* e, int32_t track_id) {
void nota_track_freeze_cancel(NotaEngine* e) {
if (e) ENG(e)->cancelFreeze();
}
+int64_t nota_track_bounce_begin(NotaEngine* e, int32_t track_id, double length_beats) {
+ return e ? ENG(e)->beginFreeze(track_id, length_beats, 0.0) : 0;
+}
+int64_t nota_track_freeze_take(NotaEngine* e, float* out, int64_t cap_frames) {
+ return e ? ENG(e)->takeFreezeCapture(out, cap_frames) : 0;
+}
+int32_t nota_track_paste_audio_frames(NotaEngine* e, int32_t track_id, const float* interleaved,
+ int64_t frames, double at_beat, const char* name_utf8) {
+ return e ? ENG(e)->pasteAudioFrames(track_id, interleaved, frames, at_beat, name_utf8 ? name_utf8 : "") : -1;
+}
void nota_track_unfreeze(NotaEngine* e, int32_t track_id) {
if (e) ENG(e)->unfreeze(track_id);
}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index b8cff7f0..bb4caded 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -2140,6 +2140,45 @@ Console.WriteLine("-- Nota Pentad --");
Check(fe.IsTrackFrozen(ft) && Rms(live, N) > 1e-3f && md < 1e-5, $"Nota Pentad freeze == live render (maxdiff {md:G3})");
}
+ // Paste Bounced Audio (⌘⇧V): a range bounce captures exactly what the chain plays from the
+ // range start (held notes chased), leaves the source unfrozen, and pastes as one undo step
+ // that overwrites what it covers on the target audio track.
+ {
+ using var be = new NotaEngine();
+ be.SetBpm(120);
+ int bt = be.AddPentadTrack();
+ SetId(be, bt, "drift", 0.7f); SetId(be, bt, "mixnoise", 0.2f);
+ be.AddMidiClip(bt, 0.0, 4.0);
+ be.SetClipNotes(bt, 0, new[] { new NotaNote(57, 0.0, 3.0, 0.9f), new NotaNote(64, 0.5, 2.0, 0.8f) });
+ // Live reference first (as in the freeze test): a fresh engine's first render still
+ // carries the parameter smoothing from the SetId calls above.
+ long withTail = be.BeginFreeze(bt, 2.0); be.CancelFreeze();
+ long bFrames = be.BeginBounce(bt, 2.0); be.CancelFreeze();
+ Check(bFrames > 0 && bFrames < withTail, $"bounce arms exactly the range, no ring-out tail ({bFrames} < {withTail} frames)");
+ be.Seek(1.0); be.Play(); var live = new float[bFrames * 2]; be.RenderOffline(live, (int)bFrames); be.StopTransport();
+ be.Stop(); be.SetLoop(false, 0, 0); be.SetMetronome(false); be.StopTransport();
+ be.BeginBounce(bt, 2.0);
+ be.Seek(1.0); be.Play();
+ var chunk = new float[4096 * 2];
+ for (long rem = bFrames; rem > 0;) { int m = (int)Math.Min(4096, rem); be.RenderOffline(chunk, m); rem -= m; }
+ be.StopTransport();
+ var pcm = new float[bFrames * 2];
+ long got = be.TakeFreezeCapture(pcm);
+ // The bounce is pre-fader; the live mix went through the centred equal-power pan (cos π/4).
+ float panGain = (float)Math.Cos(Math.PI / 4);
+ double md = 0; for (int i = 0; i < pcm.Length; i++) md = Math.Max(md, Math.Abs(live[i] - pcm[i] * panGain));
+ Check(bFrames > 0 && got == bFrames && !be.IsTrackFrozen(bt) && Rms(pcm, (int)bFrames) > 1e-3f && md < 1e-5,
+ $"bounce range == live render from the range start, source not frozen (maxdiff {md:G3})");
+
+ int dst = be.AddAudioTrack();
+ int ClipsOn(int id)
+ { for (int i = 0; i < be.TrackCount; i++) if (be.TryGetTrackInfo(i, out var ti) && ti.Id == id) return ti.ClipCount; return -1; }
+ Check(be.PasteAudioFrames(dst, pcm, bFrames, 8.0, "Bounce") >= 0 && ClipsOn(dst) == 1, "paste bounced audio places a clip");
+ Check(be.PasteAudioFrames(dst, pcm, bFrames, 8.0, "Bounce") >= 0 && ClipsOn(dst) == 1, "paste bounced audio overwrites the covered range");
+ Check(be.Undo() && ClipsOn(dst) == 1 && be.Undo() && ClipsOn(dst) == 0, "each bounced paste is one undo step");
+ Check(be.PasteAudioFrames(bt, pcm, bFrames, 8.0, null) < 0, "paste bounced audio rejects an instrument track");
+ }
+
// Factory presets: 40 ship, every named param is a real Pentad id, each applies in place.
{
var cat = new FactoryPresetCatalog();