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) Fold a device into a narrow strip (#153)

Chris Laupamacdf20e76ceab
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 182c594e..8b43daa1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -23,6 +23,13 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
### Added
+- **Fold a device into a narrow strip** (nota-daw/nota#147): double-click a device's header
+ (or choose Fold in its right-click menu) and the card collapses into a 28 px strip with its
+ name, rotated, and its on/off switch, so a long chain fits the Devices panel. Double-click
+ the strip to open it again. A folded device still selects, drags to a new slot and opens its
+ menu; it works for audio effects, MIDI effects, plug-ins and the instrument. The fold is
+ saved with the project (format v23) and follows the device when it is moved or its
+ deletion is undone.
- **An on/off switch on instrument cards** (nota-daw/nota#148): every instrument in the
Devices panel (built-in synths and samplers, Instrument and Drum Racks, hosted plug-ins)
now has the same switch as the effects. Off silences the instrument without muting the
diff --git a/FEATURES.md b/FEATURES.md
index 38c8b0d3..87b3efc8 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -210,6 +210,8 @@ track count and closes with Escape.
- **Send/Return** buses (sends to returns) with a return list.
- **Level meters** (peak/RMS) on every channel and on the master, plus true peak.
- **Device chain** per track: instrument + effects + MIDI effects, laid out in a row.
+ - Double-click a device's header (or Fold in its menu) to fold it into a narrow strip with
+ its rotated name and on/off switch; double-click the strip to unfold. Saved with the project.
---
diff --git a/specs/022-device-fold/contracts/c-abi.md b/specs/022-device-fold/contracts/c-abi.md
new file mode 100644
index 00000000..244798cc
--- /dev/null
+++ b/specs/022-device-fold/contracts/c-abi.md
@@ -0,0 +1,13 @@
+# C ABI: device fold
+
+```c
+/* Device fold (specs/022): a view flag the Devices panel draws as a narrow strip. Saved with
+ * the project, never read by the audio thread. Kept on the device, so it follows moves and
+ * undo/redo. device_index -1 = the track's instrument. Message thread. */
+NOTA_API void nota_track_set_device_folded(NotaEngine* engine, int32_t track_id, int32_t device_index, int32_t folded);
+NOTA_API int32_t nota_track_device_folded(const NotaEngine* engine, int32_t track_id, int32_t device_index);
+NOTA_API void nota_midi_effect_set_folded(NotaEngine* engine, int32_t track_id, int32_t index, int32_t folded);
+NOTA_API int32_t nota_midi_effect_folded(const NotaEngine* engine, int32_t track_id, int32_t index);
+```
+
+Out-of-range / null engine: setters are no-ops, getters return 0.
diff --git a/specs/022-device-fold/plan.md b/specs/022-device-fold/plan.md
new file mode 100644
index 00000000..dd09b962
--- /dev/null
+++ b/specs/022-device-fold/plan.md
@@ -0,0 +1,53 @@
+# Implementation Plan: Fold a device into a narrow strip
+
+**Branch**: `022-device-fold` | **Date**: 2026-10-17 | **Spec**: [spec.md](spec.md)
+
+## Summary
+
+The fold is a per-device flag kept **on the engine's device object** (beside bypass), so it
+follows the device through every structural edit the engine already handles — move, remove,
+undo/redo of a removed device (the retained graph snapshot holds the same object) — with no
+managed-side index bookkeeping. The Devices panel reads it while rebuilding the chain and,
+for a folded device, builds a 28 px strip instead of the card (the body is not built). The
+project format stores it as `folded` on each device, MIDI-effect and instrument DTO (v23).
+
+## Technical Context
+
+- Engine: `Device` / `MidiDevice` / `Instrument` get a `folded` flag. Message thread only
+ (written by the UI, read by the UI and by project save); the audio thread never touches it,
+ so it is a plain `bool` — no atomics, no command queue (AR-4/AR-6 unaffected).
+- C ABI (`nota_engine.h`): two pairs — `nota_track_set_device_folded` /
+ `nota_track_device_folded` (device index -1 = the instrument, as in the device-name and
+ plugin-param calls) and `nota_midi_effect_set_folded` / `nota_midi_effect_folded`. See
+ [contracts/c-abi.md](contracts/c-abi.md).
+- Managed: `NativeMethods` + `NotaEngine` + `IAudioEngine` (`SetDeviceFolded`,
+ `DeviceFolded`, `SetMidiEffectFolded`, `MidiEffectFolded`).
+- Persistence: `DeviceDto.Folded`, `MidiDeviceDto.Folded`, `InstrumentDto.Folded`; format
+ v22 → v23 with a no-op migration (absent = false = unfolded).
+- UI: `DeviceChainView.Shell.cs` — a double-click (`ClickCount == 2`) on the header, outside
+ its controls, toggles the fold; a `FoldedStrip` builder; "Fold" / "Unfold" in the header
+ menu. The four card builders (effect, MIDI effect, instrument, plug-in) return the strip
+ early when the device is folded. `ClickCount` is used rather than `DoubleTapped` because the
+ first click selects the card and rebuilds the row, so the second click lands on a new control.
+
+## Constitution Check
+
+- I Real-time safety: the flag is never read on the audio thread. ✓
+- II Boundary: new surface is pure C (`int32_t` in/out). ✓
+- III Licensing: no new files outside specs except a test file with the SPDX header; no dependencies. ✓
+- IV Verification: smoke test covers the ABI, move/undo following and save/load. ✓
+- V One change: fold only. ✓
+- VI Docs: CHANGELOG, FEATURES.md, nota-docs devices page (EN + RU). ✓
+
+## Project Structure (touched)
+
+```
+src/native/nota.engine/include/nota/nota_engine.h
+src/native/nota.engine/src/{Device.h,MidiDevice.h,Instrument.h,Engine.h,Engine_Devices.cpp,nota_engine_device.cpp}
+src/managed/Nota.Infrastructure/Interop/{NativeMethods.Devices.cs,NotaEngine.Devices.cs}
+src/managed/Nota.Application/Engine/IAudioEngine.cs
+src/managed/Nota.Infrastructure/Persistence/{ProjectModel.cs,ProjectService.cs,ProjectMigrations.cs}
+src/managed/Nota.App/DeviceChainView*.cs
+tests/Nota.SmokeTest/{DeviceFoldTests.cs,Program.cs}
+CHANGELOG.md, FEATURES.md
+```
diff --git a/specs/022-device-fold/quickstart.md b/specs/022-device-fold/quickstart.md
new file mode 100644
index 00000000..21967fa8
--- /dev/null
+++ b/specs/022-device-fold/quickstart.md
@@ -0,0 +1,8 @@
+# Quickstart: verify device fold
+
+1. `CI=true dotnet run --project tests/Nota.SmokeTest -c Release -- --fold` → `FOLD PASSED`.
+2. Run the app, add three effects to a track. Double-click the first card's header (on the
+ name, not the switch or the preset picker): it folds into a strip; the others move left.
+3. Click the strip's switch: the device bypasses, the strip stays folded.
+4. Drag the strip to the end of the chain; right-click it → Unfold.
+5. Fold an effect and the instrument, save, reopen: both are still folded.
diff --git a/specs/022-device-fold/spec.md b/specs/022-device-fold/spec.md
new file mode 100644
index 00000000..68dbd60b
--- /dev/null
+++ b/specs/022-device-fold/spec.md
@@ -0,0 +1,101 @@
+# Feature Specification: Fold a device into a narrow strip
+
+**Feature Branch**: `022-device-fold`
+
+**Created**: 2026-10-17
+
+**Status**: Clarified
+
+**Input**: User description: "Devices panel: double-click a device header to fold it into a narrow strip (GitHub issue nota-daw/nota#147). Long device chains don't fit the panel; you scroll sideways to reach the device you need. Double-click a device's header to collapse the card into a narrow vertical strip (name rotated, bypass switch still there), like Ableton Live. Double-click again to expand. The folded state is saved with the project."
+
+## Nota Context *(fill in — drives plan and tasks)*
+
+**Feature area** *(pick the main one)*:
+
+- [ ] Engine (C++, `src/native/nota.engine`) — real-time audio rules apply, see `ARCHITECTURE.md` AR table
+- [ ] Managed app (C#, `src/managed/*`) — domain, application, infrastructure, presentation
+- [x] UI (Avalonia, `src/managed/Nota.Presentation`) — follow `DESIGN.md` (Studio)
+- [ ] Plugin hosting (`pluginhost/`) — the only place JUCE is allowed
+- [ ] Build / packaging / CI (`scripts/`, `.github/`) — see `BUILD.md`
+- [ ] Docs only
+
+Also touches the engine (a message-thread flag on each device, never read by the audio
+thread) and the project format (one boolean per device).
+
+**Nota docs to keep in mind** *(links relative to `specs/<slug>/`, where this file lands)*:
+[`ARCHITECTURE.md`](../../ARCHITECTURE.md) (AR rules),
+[`CONTRIBUTING.md`](../../CONTRIBUTING.md) (licensing, dependency policy, PR
+expectations), [`BUILD.md`](../../BUILD.md), [`DESIGN.md`](../../DESIGN.md),
+[`FEATURES.md`](../../FEATURES.md).
+
+## Clarifications
+
+### Session 2026-10-17
+
+Defaults chosen for the open points (the request was clear on the gesture and on saving):
+
+- Q: Which cards fold? → A: Every device card in the chain: MIDI effects, the instrument, and audio effects (built-in and hosted plug-ins). The Sends card and the "+" key are not devices and don't fold.
+- Q: Which double-clicks count? → A: A double-click anywhere on the header except its controls (the bypass switch, the preset picker and any header accessory such as a plug-in's size toggle). On a folded strip, a double-click anywhere except its bypass switch unfolds it.
+- Q: What does the strip keep? → A: The bypass switch at the top (same switch, same behaviour), the device name rotated to read top to bottom, selection, the right-click menu and drag-to-reorder. The body is not built while folded.
+- Q: Is folding an undo step? → A: No. Like bypass, it is a view state, not an edit; but the fold follows its device through move, delete + undo and redo, and it is saved.
+- Q: Is there a way besides the double-click? → A: Yes, "Fold" / "Unfold" in the header's right-click menu, for discoverability.
+- Q: Does copy/paste carry the fold? → A: No; a pasted device opens unfolded.
+
+## User Scenarios & Testing *(mandatory)*
+
+### User Story 1 - Fold and unfold with a double-click (Priority: P1)
+
+A user with a long chain double-clicks the header of a device they are not editing. The card
+collapses into a narrow strip showing its name and its on/off switch, so the rest of the chain
+moves into view. Double-clicking the strip opens the card again, exactly as it was.
+
+**Why this priority**: The core of the request.
+
+**Independent Test**: Put four effects on a track, double-click the first one's header: it
+becomes a ~28 px strip, the others shift left; double-click the strip: the full card returns
+with its parameters unchanged.
+
+**Acceptance Scenarios**:
+
+1. **Given** an unfolded card, **When** the user double-clicks its header (not on a control), **Then** it becomes a narrow strip with the rotated name and the bypass switch.
+2. **Given** a folded strip, **When** the user double-clicks it (not on the switch), **Then** the full card returns.
+3. **Given** an unfolded card, **When** the user double-clicks the bypass switch or the preset picker, **Then** the card does not fold (the control behaves as it does today).
+4. **Given** a folded strip, **When** the user clicks its switch, **Then** the device bypasses / un-bypasses and stays folded.
+5. **Given** a folded strip, **When** the user clicks, right-clicks or drags it, **Then** it selects, opens the device menu, or moves within its chain like a full card.
+
+---
+
+### User Story 2 - The fold is saved with the project (Priority: P1)
+
+A user folds a few devices, saves, and reopens the project later: the same devices are folded.
+
+**Independent Test**: Fold an effect, a MIDI effect and the instrument; save; reopen: all three are folded, the rest unfolded.
+
+**Acceptance Scenarios**:
+
+1. **Given** folded devices, **When** the project is saved and reopened, **Then** exactly those devices are folded.
+2. **Given** a project saved before this feature, **When** it is opened, **Then** every device is unfolded.
+3. **Given** a folded device, **When** it is moved, or deleted and the delete is undone, **Then** it is still folded.
+
+### Edge Cases
+
+- Folding the selected device keeps it selected (the selection ring wraps the strip).
+- An instrument replaced in place (a new instrument dropped on the track) opens unfolded.
+- Folding marks the project as changed (it is part of what gets saved).
+
+## Requirements *(mandatory)*
+
+### Functional Requirements
+
+- **FR-001**: A double-click on a device card's header, outside its controls, MUST fold the card into a narrow vertical strip; a double-click on the strip, outside its switch, MUST unfold it.
+- **FR-002**: The strip MUST show the device name rotated to read top to bottom and, for a bypassable device, the same bypass switch as the full card.
+- **FR-003**: The strip MUST keep selection, the right-click device menu and drag-to-reorder.
+- **FR-004**: The header's right-click menu MUST offer Fold (on a card) / Unfold (on a strip).
+- **FR-005**: The fold MUST belong to the device: it follows moves, delete + undo, and redo, and resets for a new device.
+- **FR-006**: The fold MUST be saved with the project for audio effects, MIDI effects and the instrument; older projects open unfolded.
+- **FR-007**: Folding MUST NOT affect audio (it is never read on the audio thread).
+
+## Success Criteria *(mandatory)*
+
+- **SC-001**: A folded card takes ≤ 28 px of chain width (plus the 6 px gap).
+- **SC-002**: Fold state round-trips through save/load for all three chain kinds (smoke test).
diff --git a/specs/022-device-fold/tasks.md b/specs/022-device-fold/tasks.md
new file mode 100644
index 00000000..adda3af8
--- /dev/null
+++ b/specs/022-device-fold/tasks.md
@@ -0,0 +1,26 @@
+# Tasks: Fold a device into a narrow strip
+
+**Input**: [spec.md](spec.md), [plan.md](plan.md), [contracts/c-abi.md](contracts/c-abi.md)
+
+## Phase 1 — Engine + ABI
+
+- [x] T001 Add a message-thread `folded` flag to `Device`, `MidiDevice` and `Instrument` (src/native/nota.engine/src/{Device.h,MidiDevice.h,Instrument.h})
+- [x] T002 `Engine::setTrackDeviceFolded/trackDeviceFolded` (index -1 = instrument) and `setMidiEffectFolded/midiEffectFolded` (src/native/nota.engine/src/{Engine.h,Engine_Devices.cpp})
+- [x] T003 Export the four C functions and document them (include/nota/nota_engine.h, src/nota_engine_device.cpp)
+
+## Phase 2 — Managed + persistence
+
+- [x] T004 P/Invoke + `NotaEngine` + `IAudioEngine` members (Nota.Infrastructure/Interop, Nota.Application/Engine/IAudioEngine.cs)
+- [x] T005 `Folded` on `DeviceDto`, `MidiDeviceDto`, `InstrumentDto`; capture + apply in `ProjectService`; format v23 + no-op migration
+
+## Phase 3 — Devices panel (US1)
+
+- [x] T006 Double-click on a card header outside its controls toggles the fold; Fold / Unfold in the header menu (DeviceChainView.Shell.cs)
+- [x] T007 `FoldedStrip`: 28 px strip, bypass switch on top, rotated name, selection ring, menu, drag (DeviceChainView.Shell.cs)
+- [x] T008 Effect, MIDI-effect, instrument and plug-in builders return the strip when folded, without building the body (DeviceChainView*.cs)
+
+## Phase 4 — Verification + docs
+
+- [x] T009 Smoke test: ABI round-trip, out-of-range safety, fold follows move and delete + undo, save/load for all three kinds, v22 file opens unfolded (tests/Nota.SmokeTest/DeviceFoldTests.cs, Program.cs `--fold`)
+- [x] T010 CHANGELOG `[Unreleased]`, FEATURES.md, nota-docs devices page EN + RU
+- [ ] T011 `scripts/build-linux.sh` green; screenshots of the real app for the PR
diff --git a/src/managed/Nota.App/DeviceChainView.Fold.cs b/src/managed/Nota.App/DeviceChainView.Fold.cs
new file mode 100644
index 00000000..6bd79a76
--- /dev/null
+++ b/src/managed/Nota.App/DeviceChainView.Fold.cs
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Detail · Devices — folding a card into a narrow strip (specs/022), so a long chain fits
+// the panel. A double-click on a card's header (or "Fold" in its menu) folds it; the strip
+// keeps the bypass switch on top and the name, rotated to read top to bottom, and still
+// selects, opens the device menu and drags like the card. A double-click on it unfolds.
+// The fold lives on the engine's device (beside bypass), so it follows moves and undo, and
+// it is saved with the project. A folded card's body is not built.
+
+using System.Linq;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Input;
+using Avalonia.Layout;
+using Avalonia.Media;
+using Avalonia.VisualTree;
+using static Nota.App.DeviceCardKit;
+
+namespace Nota.App;
+
+public sealed partial class DeviceChainView
+{
+ // The strip's width: the "+" key's, just room for the bypass switch and a rotated name.
+ internal const double FoldedW = 28;
+
+ private bool IsFolded(ChainKind k, int di)
+ => k == ChainKind.Midi ? _engine.MidiEffectFolded(_trackId, di) : _engine.DeviceFolded(_trackId, di);
+
+ private void SetFolded(ChainKind k, int di, bool folded)
+ {
+ if (k == ChainKind.Midi) _engine.SetMidiEffectFolded(_trackId, di, folded);
+ else _engine.SetDeviceFolded(_trackId, di, folded);
+ Rebuild();
+ }
+
+ // True when the pointer event started on `control` or inside it (a header control the
+ // fold double-click must leave alone).
+ private static bool Within(object? source, Control? control)
+ => control is not null && source is Visual v && (ReferenceEquals(v, control) || v.GetVisualAncestors().Contains<Visual>(control));
+
+ private Control FoldedStrip(ChainKind k, int di, string name, bool bypassable, bool bypassed)
+ {
+ bool movable = k != ChainKind.Instrument; // the instrument is the track's, not a chain slot
+ var power = new Border { Height = SwitchTrack.H, HorizontalAlignment = HorizontalAlignment.Center, Margin = new Thickness(0, 8, 0, 6) };
+ if (bypassable)
+ {
+ var bypass = new SwitchTrack { IsOn = !bypassed, Cursor = new Cursor(StandardCursorType.Hand) };
+ ToolTip.SetTip(bypass, bypassed ? "Bypassed — click to enable" : "Active — click to bypass");
+ bypass.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(bypass).Properties.IsLeftButtonPressed) return;
+ e.Handled = true; // not a drag, not a selection click, not a fold toggle
+ if (k == ChainKind.Midi) _engine.SetMidiEffectBypassed(_trackId, di, !bypassed);
+ else _engine.SetDeviceBypassed(_trackId, di, !bypassed);
+ Rebuild(); Changed?.Invoke();
+ };
+ power.Child = bypass;
+ }
+ var label = new TextBlock
+ {
+ Text = name, FontSize = NotaType.DeviceName, FontWeight = FontWeight.SemiBold,
+ Foreground = bypassed ? TextTertiary : TextPrimary, TextTrimming = TextTrimming.CharacterEllipsis,
+ VerticalAlignment = VerticalAlignment.Center,
+ };
+ // Rotated a quarter turn clockwise, so the name reads top to bottom down the strip.
+ var rotated = new LayoutTransformControl
+ {
+ LayoutTransform = new RotateTransform(90), Child = label,
+ HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top,
+ };
+ DockPanel.SetDock(power, Dock.Top);
+ var strip = new Border
+ {
+ Background = ShellHdr, BorderBrush = BorderDef, BorderThickness = new Thickness(1),
+ CornerRadius = NotaRadius.Body, ClipToBounds = true,
+ Padding = new Thickness(0, 0, 0, 8),
+ Child = new DockPanel { LastChildFill = true, Children = { power, rotated } },
+ Cursor = movable ? new Cursor(StandardCursorType.SizeAll) : null,
+ };
+ strip.BindResource(Border.BoxShadowProperty, "Shadow.Raised");
+ ToolTip.SetTip(strip, $"{name} — double-click to unfold");
+
+ const double RingGap = 3; // the same focus ring as the full card (BuildCardShell)
+ var selRing = new Border
+ {
+ BorderBrush = Brass, BorderThickness = new Thickness(1.5),
+ CornerRadius = new CornerRadius(NotaRadius.BodyValue + RingGap), Margin = new Thickness(-RingGap),
+ IsHitTestVisible = false, IsVisible = IsSelected(k, di),
+ };
+ var card = new Border { Width = FoldedW, Height = CardH, Child = new Panel { Children = { strip, selRing } } };
+
+ void Menu(MenuFlyout flyout)
+ {
+ var unfold = new MenuItem { Header = "Unfold" };
+ unfold.Click += (_, _) => SetFolded(k, di, false);
+ flyout.Items.Add(unfold);
+ flyout.Items.Add(new Separator());
+ }
+ strip.PointerPressed += (_, e) =>
+ {
+ var pt = e.GetCurrentPoint(strip).Properties;
+ if (pt.IsRightButtonPressed) { ShowDeviceContextMenu(strip, k, di, Menu); return; }
+ if (!pt.IsLeftButtonPressed) return;
+ if (e.ClickCount == 2) { e.Handled = true; SetFolded(k, di, false); return; }
+ SelectDevice(k, di);
+ };
+ if (movable) HookDeviceDrag(strip, card, k, di);
+ return card;
+ }
+}
diff --git a/src/managed/Nota.App/DeviceChainView.Instruments.cs b/src/managed/Nota.App/DeviceChainView.Instruments.cs
index dfd5a6a6..5d3e43f9 100644
--- a/src/managed/Nota.App/DeviceChainView.Instruments.cs
+++ b/src/managed/Nota.App/DeviceChainView.Instruments.cs
@@ -16,6 +16,9 @@ public sealed partial class DeviceChainView
private Control InstrumentCard()
{
int kind = _engine.TrackInstrumentKind(_trackId);
+ // Folded: just the strip, whatever the instrument (no body is built), with the
+ // instrument's on/off switch on top like any other device's.
+ if (_engine.DeviceFolded(_trackId, -1)) return FoldedStrip(ChainKind.Instrument, -1, _engine.DeviceName(_trackId, -1), bypassable: true, _engine.DeviceBypassed(_trackId, -1));
if (kind == 3) return InstrumentRackCard();
if (kind == 4) return DrumRackCard();
if (kind == -1) return PluginCardFor(ChainKind.Instrument, -1, 1); // hosted VST3 / AU
diff --git a/src/managed/Nota.App/DeviceChainView.Midi.cs b/src/managed/Nota.App/DeviceChainView.Midi.cs
index d33fd078..11fed16d 100644
--- a/src/managed/Nota.App/DeviceChainView.Midi.cs
+++ b/src/managed/Nota.App/DeviceChainView.Midi.cs
@@ -18,6 +18,7 @@ public sealed partial class DeviceChainView
bool bypassed = _engine.MidiEffectBypassed(_trackId, index);
string name = _engine.MidiEffectName(_trackId, index);
int kind = _engine.MidiEffectKind(_trackId, index);
+ if (_engine.MidiEffectFolded(_trackId, index)) return FoldedStrip(ChainKind.Midi, index, name, bypassable: true, bypassed);
var body = _midiFactory.Resolve(kind);
var ctx = NewCardContext();
double width = body.WidthFor(_engine, _trackId, index);
diff --git a/src/managed/Nota.App/DeviceChainView.Shell.cs b/src/managed/Nota.App/DeviceChainView.Shell.cs
index b6351cac..b3890ce3 100644
--- a/src/managed/Nota.App/DeviceChainView.Shell.cs
+++ b/src/managed/Nota.App/DeviceChainView.Shell.cs
@@ -197,7 +197,7 @@ public sealed partial class DeviceChainView
Cursor = s.CanMove && SelectableKind(s.Kind) ? new Cursor(StandardCursorType.SizeAll) : null,
};
headerBar.BindResource(Border.BoxShadowProperty, "Shadow.Raised"); // the raised strip's top bevel
- if (!s.Utility) ToolTip.SetTip(headerBar, s.CanMove ? "Drag to reorder · right-click for A/B, move and delete" : "Right-click for more");
+ if (!s.Utility) ToolTip.SetTip(headerBar, s.CanMove ? "Drag to reorder · double-click to fold · right-click for A/B, move and delete" : "Double-click to fold · right-click for more");
// Factory presets for this device (or the card's own list), and applying one in place.
List<(string Id, string Name)> presets;
@@ -236,9 +236,10 @@ public sealed partial class DeviceChainView
// the preset belongs to the device, not to the card size.
// The picker has its own centre slot: the badges' live voice count changes width
// (Consort's "Duo 1/2" → "Poly 12/16") without moving it.
+ Control? picker = null;
if (presets.Count > 0)
{
- var picker = PresetPicker(presets.Select(p => p.Name).ToList(), curPreset, extra.Preset, ApplyPreset, StepPreset,
+ picker = PresetPicker(presets.Select(p => p.Name).ToList(), curPreset, extra.Preset, ApplyPreset, StepPreset,
nameWidth: s.Compact ? 74 : 132);
Grid.SetColumn(picker, 1); headerGrid.Children.Add(picker);
}
@@ -300,6 +301,9 @@ public sealed partial class DeviceChainView
NotaDocs.Open(headerBar, NotaDocs.DevicePage(s.Kind, kind));
};
flyout.Items.Add(docs);
+ var fold = new MenuItem { Header = "Fold" }; // the header's double-click, findable
+ fold.Click += (_, _) => SetFolded(s.Kind, di, true);
+ flyout.Items.Add(fold);
flyout.Items.Add(new Separator());
}
@@ -308,7 +312,13 @@ public sealed partial class DeviceChainView
{
var pt = e.GetCurrentPoint(headerBar).Properties;
if (pt.IsRightButtonPressed) { ShowDeviceContextMenu(headerBar, s.Kind, di, HeaderMenu); return; }
- if (pt.IsLeftButtonPressed) SelectDevice(s.Kind, di);
+ if (!pt.IsLeftButtonPressed) return;
+ // A double-click on the header itself (not its picker, switch or accessories) folds
+ // the card into a strip (specs/022). ClickCount, not DoubleTapped: the first click
+ // selects and rebuilds the row, so the second lands on a new header.
+ if (e.ClickCount == 2 && !Within(e.Source, picker) && !Within(e.Source, power) && !Within(e.Source, s.HeaderExtra))
+ { e.Handled = true; SetFolded(s.Kind, di, true); return; }
+ SelectDevice(s.Kind, di);
};
DockPanel.SetDock(headerBar, Dock.Top);
diff --git a/src/managed/Nota.App/DeviceChainView.cs b/src/managed/Nota.App/DeviceChainView.cs
index 19d8ccef..22c0c2ef 100644
--- a/src/managed/Nota.App/DeviceChainView.cs
+++ b/src/managed/Nota.App/DeviceChainView.cs
@@ -177,6 +177,7 @@ public sealed partial class DeviceChainView : UserControl
int kind = _engine.TrackDeviceBuiltinKind(_trackId, index);
bool bypassed = _engine.DeviceBypassed(_trackId, index);
string name = _engine.DeviceName(_trackId, index);
+ if (_engine.DeviceFolded(_trackId, index)) return FoldedStrip(ChainKind.Effect, index, name, bypassable: true, bypassed); // built-in or plug-in
Control body;
double width;
diff --git a/src/managed/Nota.Application/Engine/IAudioEngine.cs b/src/managed/Nota.Application/Engine/IAudioEngine.cs
index 7ac37213..70cbf6cb 100644
--- a/src/managed/Nota.Application/Engine/IAudioEngine.cs
+++ b/src/managed/Nota.Application/Engine/IAudioEngine.cs
@@ -539,6 +539,10 @@ public interface IAudioEngine : IDisposable
void MidiEffectSetParam(int trackId, int index, int paramIndex, float value);
void SetMidiEffectBypassed(int trackId, int index, bool bypassed);
bool MidiEffectBypassed(int trackId, int index);
+ /// <summary>Fold (specs/022): the Devices panel draws the MIDI effect as a narrow strip.
+ /// A view flag kept on the device (follows moves and undo) and saved with the project.</summary>
+ void SetMidiEffectFolded(int trackId, int index, bool folded);
+ bool MidiEffectFolded(int trackId, int index);
void SetMidiEffectCcDest(int trackId, int index, int destDevice, int destParam);
void SetMidiEffectCcDepth(int trackId, int index, float depth);
int MidiEffectCcDestDevice(int trackId, int index);
@@ -592,6 +596,10 @@ public interface IAudioEngine : IDisposable
void SetPluginState(int trackId, int deviceIndex, byte[] data);
void SetDeviceBypassed(int trackId, int deviceIndex, bool bypassed);
bool DeviceBypassed(int trackId, int deviceIndex);
+ /// <summary>Fold (specs/022): the Devices panel draws the device as a narrow strip.
+ /// deviceIndex -1 = the instrument. Kept on the device; saved with the project.</summary>
+ void SetDeviceFolded(int trackId, int deviceIndex, bool folded);
+ bool DeviceFolded(int trackId, int deviceIndex);
int TrackLatencySamples(int trackId);
// --- Instrument Rack (parallel chains + 8 macros) ----------------------
diff --git a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.cs b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.cs
index cd6db64b..413092eb 100644
--- a/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NativeMethods.Devices.cs
@@ -127,6 +127,10 @@ internal static partial class NativeMethods
internal static partial void MidiEffectSetBypassed(IntPtr engine, int trackId, int index, int bypassed);
[LibraryImport(Lib, EntryPoint = "nota_midi_effect_bypassed")]
internal static partial int MidiEffectBypassed(IntPtr engine, int trackId, int index);
+ [LibraryImport(Lib, EntryPoint = "nota_midi_effect_set_folded")]
+ internal static partial void MidiEffectSetFolded(IntPtr engine, int trackId, int index, int folded);
+ [LibraryImport(Lib, EntryPoint = "nota_midi_effect_folded")]
+ internal static partial int MidiEffectFolded(IntPtr engine, int trackId, int index);
[LibraryImport(Lib, EntryPoint = "nota_midi_effect_set_cc_dest")]
internal static partial void MidiEffectSetCcDest(IntPtr engine, int trackId, int index, int destDevice, int destParam);
[LibraryImport(Lib, EntryPoint = "nota_midi_effect_set_cc_depth")]
@@ -197,6 +201,12 @@ internal static partial class NativeMethods
[LibraryImport(Lib, EntryPoint = "nota_track_device_bypassed")]
internal static partial int DeviceBypassed(IntPtr engine, int trackId, int deviceIndex);
+ [LibraryImport(Lib, EntryPoint = "nota_track_set_device_folded")]
+ internal static partial void SetDeviceFolded(IntPtr engine, int trackId, int deviceIndex, int folded);
+
+ [LibraryImport(Lib, EntryPoint = "nota_track_device_folded")]
+ internal static partial int DeviceFolded(IntPtr engine, int trackId, int deviceIndex);
+
[LibraryImport(Lib, EntryPoint = "nota_track_latency_samples")]
internal static partial int TrackLatencySamples(IntPtr engine, int trackId);
diff --git a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.cs b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.cs
index 3d026b92..028f33a2 100644
--- a/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.cs
+++ b/src/managed/Nota.Infrastructure/Interop/NotaEngine.Devices.cs
@@ -157,6 +157,8 @@ public sealed partial class NotaEngine
public void MidiEffectSetParam(int trackId, int index, int paramIndex, float value) { ThrowIfDisposed(); NativeMethods.MidiEffectSetParam(_handle, trackId, index, paramIndex, value); }
public void SetMidiEffectBypassed(int trackId, int index, bool bypassed) { ThrowIfDisposed(); NativeMethods.MidiEffectSetBypassed(_handle, trackId, index, bypassed ? 1 : 0); }
public bool MidiEffectBypassed(int trackId, int index) { ThrowIfDisposed(); return NativeMethods.MidiEffectBypassed(_handle, trackId, index) != 0; }
+ public void SetMidiEffectFolded(int trackId, int index, bool folded) { ThrowIfDisposed(); NativeMethods.MidiEffectSetFolded(_handle, trackId, index, folded ? 1 : 0); }
+ public bool MidiEffectFolded(int trackId, int index) { ThrowIfDisposed(); return NativeMethods.MidiEffectFolded(_handle, trackId, index) != 0; }
public void SetMidiEffectCcDest(int trackId, int index, int destDevice, int destParam) { ThrowIfDisposed(); NativeMethods.MidiEffectSetCcDest(_handle, trackId, index, destDevice, destParam); }
public void SetMidiEffectCcDepth(int trackId, int index, float depth) { ThrowIfDisposed(); NativeMethods.MidiEffectSetCcDepth(_handle, trackId, index, depth); }
public int MidiEffectCcDestDevice(int trackId, int index) { ThrowIfDisposed(); return NativeMethods.MidiEffectCcDestDevice(_handle, trackId, index); }
@@ -243,6 +245,21 @@ public sealed partial class NotaEngine
return NativeMethods.DeviceBypassed(_handle, trackId, deviceIndex) != 0;
}
+ /// <summary>Folds (or unfolds) the device at deviceIndex in the Devices panel (specs/022);
+ /// -1 = the instrument. A view flag, saved with the project.</summary>
+ public void SetDeviceFolded(int trackId, int deviceIndex, bool folded)
+ {
+ ThrowIfDisposed();
+ NativeMethods.SetDeviceFolded(_handle, trackId, deviceIndex, folded ? 1 : 0);
+ }
+
+ /// <summary>Whether the device at deviceIndex (-1 = the instrument) is folded.</summary>
+ public bool DeviceFolded(int trackId, int deviceIndex)
+ {
+ ThrowIfDisposed();
+ return NativeMethods.DeviceFolded(_handle, trackId, deviceIndex) != 0;
+ }
+
/// <summary>Total reported latency (samples) of a track's plugin chain (M3-7).</summary>
public int TrackLatencySamples(int trackId)
{
diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectMigrations.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectMigrations.cs
index 19fb9908..31721858 100644
--- a/src/managed/Nota.Infrastructure/Persistence/ProjectMigrations.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectMigrations.cs
@@ -94,6 +94,9 @@ public static class ProjectMigrations
// v21 -> v22: MIDI clips and Session slot clips gain controller curves (Controllers,
// specs/020). Absent in v21 documents; null = none matches old behaviour — no-op.
new Migration(21, _ => { }),
+ // v22 -> v23: devices, MIDI effects and instruments gain Folded (drawn as a strip in
+ // the Devices panel, specs/022). Absent in v22 documents; false = unfolded — no-op.
+ new Migration(22, _ => { }),
};
/// <summary>Migrates <paramref name="root"/> up to <see cref="ProjectService.CurrentFormatVersion"/>
diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectModel.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectModel.cs
index f547b1c7..3a8af9ab 100644
--- a/src/managed/Nota.Infrastructure/Persistence/ProjectModel.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectModel.cs
@@ -257,6 +257,8 @@ public sealed class InstrumentDto
/// <summary>Sidechain source ("React", Nota Flux) as a track INDEX in this document
/// (-1 = none). Resolved to a live track id on load, since ids are reassigned.</summary>
public int SidechainSource { get; set; } = -1;
+ /// <summary>Drawn as a narrow strip in the Devices panel (format v23, specs/022).</summary>
+ public bool Folded { get; set; }
/// <summary>Nota Rhythm (Kind == 12) per-voice one-shots (only sample-source voices).</summary>
public List<VoiceSampleDto>? VoiceSamples { get; set; }
/// <summary>The card's on/off switch is off: the instrument makes no sound (#148).</summary>
@@ -342,6 +344,7 @@ public sealed class MidiDeviceDto
{
public int Kind { get; set; } // 0 = Arpeggiator
public bool Bypassed { get; set; }
+ public bool Folded { get; set; } // drawn as a strip in the Devices panel (v23, specs/022)
public float[] Params { get; set; } = System.Array.Empty<float>();
// Map/CC routing (arp): CC lane → an audio-device param on the same track.
public int CcDestDevice { get; set; } = -2; // -2 = no routing
@@ -356,6 +359,8 @@ public sealed class DeviceDto
/// <summary>Built-in kind: 0=EQ, 1=Compressor, 2=Reverb, 3=Delay, 4=Utility; -1 = hosted plugin.</summary>
public int BuiltinKind { get; set; }
public bool Bypassed { get; set; }
+ /// <summary>Drawn as a narrow strip in the Devices panel (format v23, specs/022).</summary>
+ public bool Folded { get; set; }
public float[] Params { get; set; } = System.Array.Empty<float>();
/// <summary>Stable plugin identifier when BuiltinKind == -1 (M7-6c).</summary>
public string? PluginId { get; set; }
diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs
index 847cddfa..f3f7e50b 100644
--- a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs
+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs
@@ -32,7 +32,8 @@ public sealed class ProjectService
/// (pitchSemitones / warpEnabled / warpMode / warpBeats). v6 adds warp markers.</summary>
/// v18 (Phase 3) adds CV modulation: per-track LFO modulators + CV links to device params.
/// v22 (specs/020) adds MIDI controller curves on MIDI clips and Session slot clips.
- public const int CurrentFormatVersion = 22;
+ /// v23 (specs/022) adds the Devices-panel fold on devices, MIDI effects and instruments.
+ public const int CurrentFormatVersion = 23;
/// <summary>Manifest file name inside the bundle folder.</summary>
public const string ManifestName = "project.json";
@@ -162,6 +163,7 @@ public sealed class ProjectService
// React source (Nota Flux): store as a doc index, resolved on load.
int instScSrc = engine.InstrumentSidechainSource(ti.Id);
instDto.SidechainSource = instScSrc >= 0 && idToIndex.TryGetValue(instScSrc, out var isi) ? isi : -1;
+ instDto.Folded = engine.DeviceFolded(ti.Id, -1);
instDto.Bypassed = engine.DeviceBypassed(ti.Id, -1);
t.Instrument = instDto;
}
@@ -170,7 +172,7 @@ public sealed class ProjectService
int midiCount = engine.TrackMidiEffectCount(ti.Id);
for (int m = 0; m < midiCount; m++)
{
- var mdev = new MidiDeviceDto { Kind = engine.MidiEffectKind(ti.Id, m), Bypassed = engine.MidiEffectBypassed(ti.Id, m) };
+ var mdev = new MidiDeviceDto { Kind = engine.MidiEffectKind(ti.Id, m), Bypassed = engine.MidiEffectBypassed(ti.Id, m), Folded = engine.MidiEffectFolded(ti.Id, m) };
int pc = engine.MidiEffectParamCount(ti.Id, m);
mdev.Params = new float[pc];
for (int p = 0; p < pc; p++) mdev.Params[p] = engine.MidiEffectGetParam(ti.Id, m, p);
@@ -349,7 +351,7 @@ public sealed class ProjectService
for (int d = 0; d < deviceCount; d++)
{
int bk = engine.TrackDeviceBuiltinKind(trackId, d);
- var dev = new DeviceDto { BuiltinKind = bk, Bypassed = engine.DeviceBypassed(trackId, d) };
+ var dev = new DeviceDto { BuiltinKind = bk, Bypassed = engine.DeviceBypassed(trackId, d), Folded = engine.DeviceFolded(trackId, d) };
int scSrc = engine.DeviceSidechainSource(trackId, d);
dev.SidechainSource = scSrc >= 0 && idToIndex.TryGetValue(scSrc, out var si) ? si : -1;
dev.SidechainGain = engine.DeviceSidechainGain(trackId, d);
@@ -428,6 +430,7 @@ public sealed class ProjectService
}
}
if (d.Bypassed) engine.SetDeviceBypassed(trackId, di, true);
+ if (d.Folded) engine.SetDeviceFolded(trackId, di, true);
if (d.SidechainSource >= 0) scDeferred.Add((trackId, di, d.SidechainSource));
engine.SetDeviceSidechainGain(trackId, di, d.SidechainGain);
engine.SetDeviceSidechainMix(trackId, di, d.SidechainMix);
@@ -590,6 +593,7 @@ public sealed class ProjectService
id = engine.AddAudioTrack();
}
+ if (id > 0 && t.Instrument is { Folded: true }) engine.SetDeviceFolded(id, -1, true);
if (id > 0 && t.Instrument is { Bypassed: true })
engine.SetDeviceBypassed(id, -1, true); // the instrument card's switch is off (#148)
if (id > 0 && t.Instrument is { SidechainSource: >= 0 } insc)
@@ -625,6 +629,7 @@ public sealed class ProjectService
if (m.Kind == 3 && m.Params.Length <= 11) PresetService.LengthLegacy(engine, id, mi); // pre-Division Nota Length
if (m.Kind == 4 && m.Params.Length <= 7) PresetService.VelocityLegacy(engine, id, mi); // pre-switch Nota Velocity
if (m.Bypassed) engine.SetMidiEffectBypassed(id, mi, true);
+ if (m.Folded) engine.SetMidiEffectFolded(id, mi, true);
if (m.CcDestDevice >= 0 && m.CcDestParam >= 0)
{
engine.SetMidiEffectCcDest(id, mi, m.CcDestDevice, m.CcDestParam);
diff --git a/src/native/nota.engine/include/nota/nota_engine.h b/src/native/nota.engine/include/nota/nota_engine.h
index eeacf0e0..0c8a6e8c 100644
--- a/src/native/nota.engine/include/nota/nota_engine.h
+++ b/src/native/nota.engine/include/nota/nota_engine.h
@@ -1384,6 +1384,9 @@ NOTA_API float nota_midi_effect_get_param(const NotaEngine* engine, int32_
NOTA_API NotaResult nota_midi_effect_set_param(NotaEngine* engine, int32_t track_id, int32_t index, int32_t param_index, float value);
NOTA_API void nota_midi_effect_set_bypassed(NotaEngine* engine, int32_t track_id, int32_t index, int32_t bypassed);
NOTA_API int32_t nota_midi_effect_bypassed(const NotaEngine* engine, int32_t track_id, int32_t index);
+/* Fold (specs/022): as nota_track_set_device_folded, for a MIDI effect. */
+NOTA_API void nota_midi_effect_set_folded(NotaEngine* engine, int32_t track_id, int32_t index, int32_t folded);
+NOTA_API int32_t nota_midi_effect_folded(const NotaEngine* engine, int32_t track_id, int32_t index);
/* Live IN/OUT of the last note-on a MIDI effect remapped (Nota Scale readout); -1 = none. */
NOTA_API int32_t nota_midi_effect_last_in(const NotaEngine* engine, int32_t track_id, int32_t index);
NOTA_API int32_t nota_midi_effect_last_out(const NotaEngine* engine, int32_t track_id, int32_t index);
@@ -1697,6 +1700,13 @@ NOTA_API NotaResult nota_plugin_set_state(NotaEngine* engine, int32_t track_id,
NOTA_API NotaResult nota_track_set_device_bypassed(NotaEngine* engine, int32_t track_id, int32_t device_index, int32_t bypassed);
NOTA_API int32_t nota_track_device_bypassed(const NotaEngine* engine, int32_t track_id, int32_t device_index);
+/* Device fold (specs/022): a view flag the Devices panel draws as a narrow strip. Saved with
+ * the project, never read by the audio thread. Kept on the device, so it follows moves and
+ * undo/redo. device_index -1 = the track's instrument. Out of range: set is a no-op, get
+ * returns 0. Message thread. */
+NOTA_API void nota_track_set_device_folded(NotaEngine* engine, int32_t track_id, int32_t device_index, int32_t folded);
+NOTA_API int32_t nota_track_device_folded(const NotaEngine* engine, int32_t track_id, int32_t device_index);
+
/* Plugin delay compensation (M3-7, FR-38). Total reported latency of a track's
* chain (instrument + effects), in samples; the engine delays other tracks to
* match the highest so they stay aligned. */
diff --git a/src/native/nota.engine/src/Device.h b/src/native/nota.engine/src/Device.h
index 577ec85d..062bfcf4 100644
--- a/src/native/nota.engine/src/Device.h
+++ b/src/native/nota.engine/src/Device.h
@@ -180,8 +180,15 @@ public:
bool bypassed() const { return bypassed_.load(std::memory_order_relaxed); }
void setBypassed(bool b) { bypassed_.store(b, std::memory_order_relaxed); }
+ // Fold (specs/022): the Devices panel draws this device as a narrow strip. A view flag
+ // saved with the project; message thread only — the audio thread never reads it. Kept on
+ // the device so it follows moves and undo/redo.
+ bool folded() const { return folded_; }
+ void setFolded(bool f) { folded_ = f; }
+
private:
std::atomic<bool> bypassed_{false};
+ bool folded_ = false;
std::atomic<float> scGainDb_{0.0f};
std::atomic<float> scMix_{1.0f};
std::atomic<int32_t> scTapPre_{0};
diff --git a/src/native/nota.engine/src/Engine.h b/src/native/nota.engine/src/Engine.h
index 90611de3..49beca92 100644
--- a/src/native/nota.engine/src/Engine.h
+++ b/src/native/nota.engine/src/Engine.h
@@ -797,6 +797,9 @@ public:
// deviceIndex -1 is the instrument's on/off switch (#148).
void setTrackDeviceBypassed(int32_t trackId, int32_t deviceIndex, bool bypassed);
bool trackDeviceBypassed(int32_t trackId, int32_t deviceIndex) const;
+ // Device fold (specs/022): a view flag on the device; deviceIndex -1 = the instrument.
+ void setTrackDeviceFolded(int32_t trackId, int32_t deviceIndex, bool folded);
+ bool trackDeviceFolded(int32_t trackId, int32_t deviceIndex) const;
// Plugin delay compensation (M3-7).
int32_t trackLatencySamples(int32_t trackId) const;
@@ -819,6 +822,8 @@ public:
void midiEffectSetParam(int32_t trackId, int32_t index, int32_t paramIndex, float value);
void setMidiEffectBypassed(int32_t trackId, int32_t index, bool bypassed);
bool midiEffectBypassed(int32_t trackId, int32_t index) const;
+ void setMidiEffectFolded(int32_t trackId, int32_t index, bool folded);
+ bool midiEffectFolded(int32_t trackId, int32_t index) const;
// Map/CC routing: the effect's CC lane modulates an audio-device param on the track.
void setMidiEffectCcDest(int32_t trackId, int32_t index, int32_t destDevice, int32_t destParam);
void setMidiEffectCcDepth(int32_t trackId, int32_t index, float depth);
diff --git a/src/native/nota.engine/src/Engine_Devices.cpp b/src/native/nota.engine/src/Engine_Devices.cpp
index 6d49a085..9907d206 100644
--- a/src/native/nota.engine/src/Engine_Devices.cpp
+++ b/src/native/nota.engine/src/Engine_Devices.cpp
@@ -810,6 +810,8 @@ float Engine::midiEffectGetParam(int32_t t, int32_t i, int32_t p) const {
void Engine::midiEffectSetParam(int32_t t, int32_t i, int32_t p, float v) { routeCvBaseEdit(2, t, i, p, v); if (auto* m = midiDeviceAt(t, i)) m->setParam(p, v); }
void Engine::setMidiEffectBypassed(int32_t t, int32_t i, bool b) { if (auto* m = midiDeviceAt(t, i)) m->setBypassed(b); }
bool Engine::midiEffectBypassed(int32_t t, int32_t i) const { auto* m = midiDeviceAt(t, i); return m ? m->bypassed() : false; }
+void Engine::setMidiEffectFolded(int32_t t, int32_t i, bool f) { if (auto* m = midiDeviceAt(t, i)) m->setFolded(f); }
+bool Engine::midiEffectFolded(int32_t t, int32_t i) const { auto* m = midiDeviceAt(t, i); return m ? m->folded() : false; }
int32_t Engine::midiEffectLastIn(int32_t t, int32_t i) const { auto* m = midiDeviceAt(t, i); return m ? m->midiLastIn() : -1; }
int32_t Engine::midiEffectLastOut(int32_t t, int32_t i) const { auto* m = midiDeviceAt(t, i); return m ? m->midiLastOut() : -1; }
int32_t Engine::midiEffectScope(int32_t t, int32_t i, float* out, int32_t maxN) const { auto* m = midiDeviceAt(t, i); return m ? m->midiScope(out, maxN) : 0; }
@@ -1067,6 +1069,22 @@ bool Engine::trackDeviceBypassed(int32_t trackId, int32_t deviceIndex) const {
return t->devices[deviceIndex] && t->devices[deviceIndex]->bypassed();
}
+void Engine::setTrackDeviceFolded(int32_t trackId, int32_t deviceIndex, bool folded) {
+ auto t = findTrackAuthoring(trackId);
+ if (!t) return;
+ if (deviceIndex < 0) { if (t->instrument) t->instrument->folded = folded; return; }
+ if (deviceIndex < static_cast<int32_t>(t->devices.size()) && t->devices[deviceIndex])
+ t->devices[deviceIndex]->setFolded(folded);
+}
+
+bool Engine::trackDeviceFolded(int32_t trackId, int32_t deviceIndex) const {
+ auto t = findTrackAuthoring(trackId);
+ if (!t) return false;
+ if (deviceIndex < 0) return t->instrument && t->instrument->folded;
+ return deviceIndex < static_cast<int32_t>(t->devices.size()) && t->devices[deviceIndex]
+ && t->devices[deviceIndex]->folded();
+}
+
// --- plugin delay compensation (M3-7) --------------------------------------
int32_t Engine::trackLatency(const Track& t) {
diff --git a/src/native/nota.engine/src/Instrument.h b/src/native/nota.engine/src/Instrument.h
index 2401e0a9..99a75aa3 100644
--- a/src/native/nota.engine/src/Instrument.h
+++ b/src/native/nota.engine/src/Instrument.h
@@ -54,6 +54,9 @@ public:
// and "send on change" read it.
// Relaxed atomics so a test / meter can read them from the message thread.
std::atomic<float> deliveredCtl[kCtlCount];
+ // Fold (specs/022): the Devices panel draws the instrument as a narrow strip. A view flag
+ // saved with the project; message thread only.
+ bool folded = false;
Instrument() { for (auto& v : deliveredCtl) v.store(std::numeric_limits<float>::quiet_NaN(), std::memory_order_relaxed); }
virtual void controller(int32_t ctl, float value) {
switch (ctl) {
diff --git a/src/native/nota.engine/src/MidiDevice.h b/src/native/nota.engine/src/MidiDevice.h
index d450b5d1..2863e1c4 100644
--- a/src/native/nota.engine/src/MidiDevice.h
+++ b/src/native/nota.engine/src/MidiDevice.h
@@ -94,6 +94,10 @@ public:
bool bypassed() const { return bypassed_.load(std::memory_order_relaxed); }
void setBypassed(bool b) { bypassed_.store(b, std::memory_order_relaxed); }
+ // Fold (specs/022): drawn as a narrow strip in the Devices panel. Message thread only.
+ bool folded() const { return folded_; }
+ void setFolded(bool f) { folded_ = f; }
+
// Map/CC routing: a device (the arpeggiator) can drive a target audio-device param
// on the same track from its per-step CC lane. destDevice = the track's audio-device
// chain index (-2 = no routing), destParam = that device's param index, depth 0..1
@@ -108,6 +112,7 @@ public:
private:
std::atomic<bool> bypassed_{false};
+ bool folded_ = false;
};
} // namespace nota
diff --git a/src/native/nota.engine/src/nota_engine_device.cpp b/src/native/nota.engine/src/nota_engine_device.cpp
index e990f0ce..791ff8b2 100644
--- a/src/native/nota.engine/src/nota_engine_device.cpp
+++ b/src/native/nota.engine/src/nota_engine_device.cpp
@@ -148,6 +148,8 @@ NotaResult nota_midi_effect_set_param(NotaEngine* e, int32_t t, int32_t i, int3
}
void nota_midi_effect_set_bypassed(NotaEngine* e, int32_t t, int32_t i, int32_t b) { if (e) ENG(e)->setMidiEffectBypassed(t, i, b != 0); }
int32_t nota_midi_effect_bypassed(const NotaEngine* e, int32_t t, int32_t i) { return (e && CENG(e)->midiEffectBypassed(t, i)) ? 1 : 0; }
+void nota_midi_effect_set_folded(NotaEngine* e, int32_t t, int32_t i, int32_t f) { if (e) ENG(e)->setMidiEffectFolded(t, i, f != 0); }
+int32_t nota_midi_effect_folded(const NotaEngine* e, int32_t t, int32_t i) { return (e && CENG(e)->midiEffectFolded(t, i)) ? 1 : 0; }
void nota_midi_effect_set_cc_dest(NotaEngine* e, int32_t t, int32_t i, int32_t dev, int32_t param) { if (e) ENG(e)->setMidiEffectCcDest(t, i, dev, param); }
void nota_midi_effect_set_cc_depth(NotaEngine* e, int32_t t, int32_t i, float d) { if (e) ENG(e)->setMidiEffectCcDepth(t, i, d); }
int32_t nota_midi_effect_cc_dest_device(const NotaEngine* e, int32_t t, int32_t i) { return e ? CENG(e)->midiEffectCcDestDevice(t, i) : -2; }
@@ -313,6 +315,12 @@ NotaResult nota_track_set_device_bypassed(NotaEngine* e, int32_t track_id, int32
int32_t nota_track_device_bypassed(const NotaEngine* e, int32_t track_id, int32_t device_index) {
return (e && CENG(e)->trackDeviceBypassed(track_id, device_index)) ? 1 : 0;
}
+void nota_track_set_device_folded(NotaEngine* e, int32_t track_id, int32_t device_index, int32_t folded) {
+ if (e) ENG(e)->setTrackDeviceFolded(track_id, device_index, folded != 0);
+}
+int32_t nota_track_device_folded(const NotaEngine* e, int32_t track_id, int32_t device_index) {
+ return (e && CENG(e)->trackDeviceFolded(track_id, device_index)) ? 1 : 0;
+}
int32_t nota_track_latency_samples(const NotaEngine* e, int32_t track_id) {
return e ? CENG(e)->trackLatencySamples(track_id) : 0;
}
diff --git a/tests/Nota.SmokeTest/DeviceFoldTests.cs b/tests/Nota.SmokeTest/DeviceFoldTests.cs
new file mode 100644
index 00000000..43a99a83
--- /dev/null
+++ b/tests/Nota.SmokeTest/DeviceFoldTests.cs
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Device fold (specs/022): the Devices panel's "folded into a strip" flag lives on the engine
+// device. It round-trips through the C ABI for audio effects, MIDI effects and the instrument,
+// is safe out of range, follows a move and a delete + undo, and survives save/load; a v22
+// project opens unfolded. Also runnable alone: `dotnet run --project tests/Nota.SmokeTest -- --fold`.
+
+using System.Text.Json.Nodes;
+using Nota.Application;
+using Nota.Infrastructure;
+
+namespace Nota.SmokeTest;
+
+internal static class DeviceFoldTests
+{
+ private const int Eq = 0, Utility = 4, Arp = 0;
+
+ public static IEnumerable<(bool ok, string label)> Run()
+ {
+ using var eng = new NotaEngine();
+ int t = eng.AddInstrumentTrack();
+ int eq = eng.AddBuiltinDevice(t, Eq), ut = eng.AddBuiltinDevice(t, Utility);
+ int arp = eng.AddMidiEffect(t, Arp);
+ yield return (eq == 0 && ut == 1 && arp == 0, "fold: a track with an instrument, two effects and a MIDI effect");
+ yield return (!eng.DeviceFolded(t, -1) && !eng.DeviceFolded(t, eq) && !eng.DeviceFolded(t, ut) && !eng.MidiEffectFolded(t, arp),
+ "fold: new devices start unfolded");
+
+ eng.SetDeviceFolded(t, eq, true);
+ eng.SetDeviceFolded(t, -1, true);
+ eng.SetMidiEffectFolded(t, arp, true);
+ yield return (eng.DeviceFolded(t, eq) && !eng.DeviceFolded(t, ut) && eng.DeviceFolded(t, -1) && eng.MidiEffectFolded(t, arp),
+ "fold: set/get round-trips for an effect, the instrument and a MIDI effect");
+ yield return (!eng.DeviceBypassed(t, eq) && !eng.DeviceBypassed(t, -1) && !eng.MidiEffectBypassed(t, arp), "fold: folding doesn't bypass");
+ // The folded instrument strip's switch is the instrument's bypass (#148): it toggles while folded.
+ eng.SetDeviceBypassed(t, -1, true);
+ bool offFolded = eng.DeviceBypassed(t, -1) && eng.DeviceFolded(t, -1);
+ eng.SetDeviceBypassed(t, -1, false);
+ yield return (offFolded && !eng.DeviceBypassed(t, -1) && eng.DeviceFolded(t, -1),
+ "fold: a folded instrument switches off and on and stays folded");
+
+ eng.SetDeviceFolded(t, 99, true); eng.SetMidiEffectFolded(t, 99, true); eng.SetDeviceFolded(9999, 0, true);
+ yield return (!eng.DeviceFolded(t, 99) && !eng.MidiEffectFolded(t, 99) && !eng.DeviceFolded(9999, 0),
+ "fold: out of range is a no-op and reads unfolded");
+
+ // The flag is on the device, so it travels with it.
+ eng.MoveDevice(t, 0, 1);
+ yield return (!eng.DeviceFolded(t, 0) && eng.DeviceFolded(t, 1) && eng.TrackDeviceBuiltinKind(t, 1) == Eq,
+ "fold: a moved device keeps its fold");
+ eng.RemoveDevice(t, 1);
+ yield return (eng.TrackDeviceCount(t) == 1 && !eng.DeviceFolded(t, 0), "fold: delete the folded device");
+ yield return (eng.Undo() && eng.TrackDeviceCount(t) == 2 && eng.DeviceFolded(t, 1) && !eng.DeviceFolded(t, 0),
+ "fold: undoing the delete brings the device back folded");
+
+ // Save/load keeps exactly the folded devices folded.
+ string dir = Path.Combine(Path.GetTempPath(), "nota-fold-" + Guid.NewGuid().ToString("N"));
+ try
+ {
+ var doc = ProjectService.Capture(eng, new TransportState(120, 1, false, false), new List<string>());
+ ProjectService.Save(doc, dir, eng);
+ using var eng2 = new NotaEngine();
+ ProjectService.Apply(ProjectService.Load(dir), eng2, dir);
+ int t2 = -1;
+ for (int i = 0; i < eng2.TrackCount; i++)
+ if (eng2.TryGetTrackInfo(i, out var ti) && ti.IsInstrument) t2 = ti.Id;
+ yield return (t2 > 0 && eng2.TrackDeviceCount(t2) == 2 && eng2.TrackMidiEffectCount(t2) == 1,
+ "fold: the project reopens with its chain");
+ yield return (t2 > 0 && !eng2.DeviceFolded(t2, 0) && eng2.DeviceFolded(t2, 1)
+ && eng2.DeviceFolded(t2, -1) && eng2.MidiEffectFolded(t2, 0),
+ "fold: save/load keeps the effect, instrument and MIDI-effect folds");
+ }
+ finally
+ {
+ try { if (Directory.Exists(dir)) Directory.Delete(dir, recursive: true); } catch (IOException) { }
+ }
+
+ // A v22 document has no folds: it migrates to v23 and every device opens unfolded.
+ var old = ProjectMigrations.Migrate(new JsonObject { ["formatVersion"] = 22 });
+ yield return (ProjectService.CurrentFormatVersion == 23 && old["formatVersion"]?.GetValue<int>() == 23,
+ "fold: a v22 project migrates to v23");
+ yield return (!new DeviceDto().Folded && !new MidiDeviceDto().Folded && !new InstrumentDto().Folded,
+ "fold: absent means unfolded");
+ }
+}
diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.cs
index 53f02834..71b3ad8e 100644
--- a/tests/Nota.SmokeTest/Program.cs
+++ b/tests/Nota.SmokeTest/Program.cs
@@ -309,6 +309,14 @@ if (args.Length >= 1 && args[0] == "--paramundo")
Console.WriteLine(failures == 0 ? "PARAMUNDO PASSED" : $"PARAMUNDO FAILED ({failures})");
return failures == 0 ? 0 : 1;
}
+// Device fold alone: `--fold`. Also part of the full run.
+if (args.Length >= 1 && args[0] == "--fold")
+{
+ Console.WriteLine("-- device fold --");
+ foreach (var (ok, label) in DeviceFoldTests.Run()) Check(ok, label);
+ Console.WriteLine(failures == 0 ? "FOLD PASSED" : $"FOLD FAILED ({failures})");
+ return failures == 0 ? 0 : 1;
+}
// The project pan law alone: `--panlaw`. Also part of the full run.
if (args.Length >= 1 && args[0] == "--panlaw")
{
@@ -14794,6 +14802,9 @@ foreach (var (ok, label) in ReturnDeleteTests.Run()) Check(ok, label);
Console.WriteLine("-- pan law --");
foreach (var (ok, label) in PanLawTests.Run()) Check(ok, label);
+Console.WriteLine("-- device fold --");
+foreach (var (ok, label) in DeviceFoldTests.Run()) Check(ok, label);
+
// The Linux JUCE message pump (.specify/bugs/linux-plugin-black-window): exported on every
// platform and a safe no-op before any hosted plugin exists (the app ticks it on Linux).
Console.WriteLine("-- plugin host pump --");