Q-W6: registration table (OCP) in main.cpp; bank verbs -> shell/bank_ops(Session&); persist.h + wav_trim + namespaces.h shims deleted; 61/61
capture.h realtime seam split to capture_realtime_shell.h; GetProjExtState grow-loop rehomed to core/wire/ext_state_read; stale persist.cpp/bank_panel.cpp comment refs fixed; CLAUDE.md persist/bank_book/actions bullets updated. Command-id suffixes, display phrases, and undo labels byte-identical.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
// action_registry.cpp — shared registration plumbing (Q-W4 split of actions.cpp).
|
||||
// See action_registry.h. Needs no REAPER API pointers: rec->Register is a member
|
||||
// call on the dispatch struct REAPER hands the entry point.
|
||||
// action_registry.cpp — shared registration plumbing (Q-W4) + the registration
|
||||
// table (Q-W6). See action_registry.h. Needs no REAPER API pointers: rec->Register
|
||||
// is a member call on the dispatch struct REAPER hands the entry point.
|
||||
|
||||
#include "shell/actions/action_registry.h"
|
||||
|
||||
#include <cstring>
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
@@ -23,6 +24,18 @@ using version::channelCommandId;
|
||||
// pointer for a given action.
|
||||
std::deque<std::string> g_strStore;
|
||||
|
||||
// One registered table row: the row data plus the registry-owned registration
|
||||
// artifacts (interned id, minted cmd, gaccel storage REAPER holds a pointer to).
|
||||
// A std::deque so element addresses never move after push_back — REAPER keeps each
|
||||
// &accel until the mirror-unregister.
|
||||
struct TableEntry {
|
||||
ActionTableRow row;
|
||||
const char* id = nullptr; // interned channel-qualified command id
|
||||
int cmd = 0; // minted command id (0 = mint failed / inert row)
|
||||
gaccel_register_t accel{}; // Actions-list entry; address handed to REAPER
|
||||
};
|
||||
std::deque<TableEntry> g_table;
|
||||
|
||||
} // namespace
|
||||
|
||||
const char* channelIdFor(const char* suffix) {
|
||||
@@ -46,4 +59,39 @@ int registerAction(reaper_plugin_info_t* rec, const char* suffix,
|
||||
return cmd;
|
||||
}
|
||||
|
||||
void registerActionTable(reaper_plugin_info_t* rec, const ActionTableRow* rows,
|
||||
std::size_t count) {
|
||||
for (std::size_t i = 0; i < count; ++i) {
|
||||
g_table.push_back(TableEntry{rows[i]});
|
||||
TableEntry& e = g_table.back();
|
||||
e.id = channelIdFor(e.row.suffix);
|
||||
e.cmd = registerAction(rec, e.row.suffix, e.accel, e.row.phrase);
|
||||
}
|
||||
}
|
||||
|
||||
bool actionTableHandleCommand(int command) {
|
||||
if (command == 0) return false;
|
||||
for (const TableEntry& e : g_table)
|
||||
if (e.cmd != 0 && command == e.cmd) {
|
||||
e.row.run(e.row.arg);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int actionTableCommandId(const char* suffix) {
|
||||
for (const TableEntry& e : g_table)
|
||||
if (std::strcmp(e.row.suffix, suffix) == 0) return e.cmd;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void unregisterActionTable(reaper_plugin_info_t* rec) {
|
||||
// Reverse table order, mirroring the register loop. Each '-command_id'
|
||||
// re-presents the SAME interned pointer channelIdFor handed out at register.
|
||||
for (auto it = g_table.rbegin(); it != g_table.rend(); ++it) {
|
||||
rec->Register("-gaccel", (void*)&it->accel);
|
||||
rec->Register("-command_id", (void*)it->id);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
@@ -1,13 +1,30 @@
|
||||
#pragma once
|
||||
// action_registry — shared registration plumbing for the bindable action families
|
||||
// (Q-W4 split of actions.cpp). Owns the durable interned-string store both the
|
||||
// Design View and multi-bank families register through, so a composed command id
|
||||
// keeps ONE stable pointer from register to the mirror-unregister, and the
|
||||
// register-a-command_id-then-gaccel sequence has one implementation.
|
||||
// action_registry — shared registration plumbing + the Q-W6 registration TABLE.
|
||||
//
|
||||
// Two layers, one TU:
|
||||
//
|
||||
// * The Q-W4 plumbing (channelIdFor / registerAction): the durable interned-string
|
||||
// store the action families register through, so a composed command id keeps ONE
|
||||
// stable pointer from register to the mirror-unregister, and the
|
||||
// register-a-command_id-then-gaccel sequence has one implementation. The
|
||||
// design_view / bank / ingest families still register row-by-row through this.
|
||||
//
|
||||
// * The Q-W6 registration TABLE (ActionTableRow + registerActionTable /
|
||||
// actionTableHandleCommand / actionTableCommandId / unregisterActionTable): the
|
||||
// data-driven home of main.cpp's own action family (capture scopes, panel toggle,
|
||||
// insert, batch, realtime, recapture, version). One row = one action (FOREVER-
|
||||
// STABLE id suffix, display phrase, flat function-pointer handler); registration
|
||||
// iterates the rows, hookcommand dispatch walks the same rows, and unload
|
||||
// mirror-unregisters from them — adding an action touches the table only (OCP).
|
||||
// Handlers are plain function pointers (a static dispatch walk, no std::function,
|
||||
// no virtual — the §3 performance guardrail); gaccel + interned-id storage is
|
||||
// owned here for the module lifetime, so REAPER's held pointers stay valid and
|
||||
// the '-command_id' unregister re-presents the IDENTICAL pointer registered.
|
||||
//
|
||||
// Includes reaper_plugin.h (gaccel_register_t / reaper_plugin_info_t full defs);
|
||||
// only the action-family TUs include this header. Q-W6's registration table
|
||||
// subsumes this helper when the hand-written blocks become data.
|
||||
// only the action-family TUs and main.cpp include this header.
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
#include "reaper_plugin.h" // reaper_plugin_info_t, gaccel_register_t
|
||||
|
||||
@@ -26,4 +43,41 @@ const char* channelIdFor(const char* suffix);
|
||||
int registerAction(reaper_plugin_info_t* rec, const char* suffix,
|
||||
gaccel_register_t& accel, const char* phrase);
|
||||
|
||||
// --- The registration table (Q-W6) -------------------------------------------
|
||||
|
||||
// One bindable action. `suffix` and `phrase` are the channel-AGNOSTIC pieces (the
|
||||
// registry composes the full id/label via channelCommandId / channelActionName);
|
||||
// both must have static storage duration (string literals, or a pure static table
|
||||
// like captureActionTable()). `run` fires when the minted command does; `arg` is an
|
||||
// opaque per-row value passed through to it (e.g. a captureActionTable row index, or
|
||||
// a bool-like flag), so sibling actions can share one handler without captures.
|
||||
struct ActionTableRow {
|
||||
const char* suffix; // FOREVER-STABLE command-id suffix — never change shipped
|
||||
const char* phrase; // Actions-list display phrase (after the channel prefix)
|
||||
void (*run)(int arg); // handler — a flat function pointer, no state
|
||||
int arg = 0; // opaque per-row handler argument
|
||||
};
|
||||
|
||||
// Registers every row (command_id -> gaccel, via the same interning plumbing as
|
||||
// registerAction) in table order. Rows are COPIED into registry-owned storage whose
|
||||
// element addresses never move (REAPER holds each gaccel pointer until unload).
|
||||
// Call once at load; a failed command_id mint (cmd 0) leaves that row inert but
|
||||
// still mirror-unregistered on unload (harmless, matches the pre-table behavior).
|
||||
void registerActionTable(reaper_plugin_info_t* rec, const ActionTableRow* rows,
|
||||
std::size_t count);
|
||||
|
||||
// Dispatches one fired command: fires the matching row's handler and returns true;
|
||||
// false when the command belongs to no table row (caller's hookcommand keeps
|
||||
// looking, per the claim-only contract). A flat walk over the registered rows.
|
||||
bool actionTableHandleCommand(int command);
|
||||
|
||||
// The minted command id for `suffix` (0 when unregistered / mint failed). For the
|
||||
// callers that need a raw command id outside dispatch — e.g. the toggleaction
|
||||
// checked-state hook resolving TOGGLE_BANK_PANEL once at load.
|
||||
int actionTableCommandId(const char* suffix);
|
||||
|
||||
// Mirror-unregisters every table row (reverse table order): '-gaccel' with the same
|
||||
// held storage, '-command_id' with the SAME interned pointer used at register.
|
||||
void unregisterActionTable(reaper_plugin_info_t* rec);
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// bank_actions.cpp — the multi-bank bindable action family (Phase B3; Q-W4 split of
|
||||
// actions.cpp). See bank_actions.h.
|
||||
//
|
||||
// Q-W4 dedupe: each mutating handler is a THIN UX SKIN — text prompts (promptBankName),
|
||||
// name resolution, and console feedback — over the promptless bankOp* inner verbs
|
||||
// homed in panel_bank_ops (model op + persistBankOp, one bank op = one Ctrl-Z). The
|
||||
// book's rules (pool privileges, collapse-by-hash, active-fallback-to-pool) all live
|
||||
// in bank_book; these handlers only drive the verbs and react to the boolean.
|
||||
// Q-W4 dedupe / Q-W6 seam: each mutating handler is a THIN UX SKIN — text prompts
|
||||
// (promptBankName), name resolution, and console feedback — over the promptless
|
||||
// bankOp* inner verbs homed in shell/bank_ops (model op + persistBankOp, one bank op
|
||||
// = one Ctrl-Z), driven against this family's registered session. The book's rules
|
||||
// (pool privileges, collapse-by-hash, active-fallback-to-pool) all live in
|
||||
// bank_book; these handlers only drive the verbs and react to the boolean.
|
||||
//
|
||||
// REFERENCE-INVALIDATION GUARDRAIL (B2 review): book().activeIndex() / bank()->index
|
||||
// return a reference INTO the book's internal vector, which a create/delete can
|
||||
@@ -27,9 +28,10 @@
|
||||
#include "shell/actions/prune_action.h" // doBankPruneFolder — the guarded prune body
|
||||
|
||||
#include "core/model/bank_book.h" // BankBook, nextBankId, kPoolBankId (B1)
|
||||
#include "persist.h" // ReaSamplerSession (owns book())
|
||||
#include "shell/panel/panel_bank_ops.h" // bankOp* inner verbs + promptBankName + selection seam
|
||||
#include "shell/bank_ops/bank_ops.h" // bankOp* promptless verbs (Q-W6 non-UI seam)
|
||||
#include "shell/panel/panel_bank_ops.h" // promptBankName + the panel selection seam
|
||||
#include "shell/panel/panel_layout.h" // full-height toggles (B3)
|
||||
#include "shell/persist/session.h" // ReaSamplerSession (owns book())
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_ShowConsoleMsg
|
||||
@@ -61,9 +63,9 @@ constexpr const char* kIdBankBanksFull = "BANK_BANKS_FULLHEIGHT";
|
||||
// and R3 extends the confirm-and-delete step behind this SAME id — never a throwaway id.
|
||||
constexpr const char* kIdBankPruneFolder = "BANK_PRUNE_FOLDER";
|
||||
|
||||
// The live session the actions read (name resolution, member counts, prune). The
|
||||
// mutations themselves run through the bankOp* verbs, which resolve the same session
|
||||
// via the panel seam. Set once by bankRegisterActions; not owned here.
|
||||
// The live session the actions read (name resolution, member counts, prune) and
|
||||
// pass to the bankOp* verbs by reference (bankHandleCommand guards it non-null
|
||||
// before any handler runs). Set once by bankRegisterActions; not owned here.
|
||||
ReaSamplerSession* g_session = nullptr;
|
||||
|
||||
int g_cmdBankCreate = 0;
|
||||
@@ -116,7 +118,7 @@ std::string bankIdByDisplayName(const std::string& name) {
|
||||
void doBankCreate() {
|
||||
std::string name;
|
||||
if (!promptBankName("ReaSampler: create bank", "Bank name:", "", name)) return;
|
||||
if (bankOpCreate(name).empty()) {
|
||||
if (bankOpCreate(*g_session, name).empty()) {
|
||||
ShowConsoleMsg(
|
||||
("ReaSampler: could not create bank \"" + name +
|
||||
"\" (a bank with that name already exists).\n")
|
||||
@@ -139,7 +141,7 @@ void doBankRename() {
|
||||
}
|
||||
std::string newName;
|
||||
if (!promptBankName("ReaSampler: rename bank", "New name:", which, newName)) return;
|
||||
if (!bankOpRename(id, newName)) {
|
||||
if (!bankOpRename(*g_session, id, newName)) {
|
||||
// The verb rejects the pool (un-renamable) or a name already used by another
|
||||
// bank (unique display names, trimmed + case-insensitive).
|
||||
ShowConsoleMsg("ReaSampler: cannot rename that bank (the pool is un-renamable, "
|
||||
@@ -184,7 +186,7 @@ void doBankDelete() {
|
||||
}
|
||||
// S9: bump only when the deleted bank held samples — dropping them changes what a live
|
||||
// instance referencing one could play. Deleting an EMPTY bank is purely organizational.
|
||||
if (!bankOpDelete(id, /*bumpGeneration=*/members > 0)) {
|
||||
if (!bankOpDelete(*g_session, id, /*bumpGeneration=*/members > 0)) {
|
||||
ShowConsoleMsg("ReaSampler: cannot delete that bank (the pool is un-deletable).\n");
|
||||
}
|
||||
}
|
||||
@@ -202,7 +204,7 @@ void doBankEvacuate() {
|
||||
ShowConsoleMsg(("ReaSampler: no bank named \"" + which + "\".\n").c_str());
|
||||
return;
|
||||
}
|
||||
if (!bankOpEvacuate(id)) {
|
||||
if (!bankOpEvacuate(*g_session, id)) {
|
||||
ShowConsoleMsg("ReaSampler: cannot evacuate that bank (the pool is the "
|
||||
"destination, not a source).\n");
|
||||
}
|
||||
@@ -218,13 +220,13 @@ void doBankActivateNext() {
|
||||
for (const Bank& b : g_session->book().banks()) ids.push_back(b.id);
|
||||
const std::string target = nextBankId(ids, g_session->book().activeBankId());
|
||||
if (target.empty()) return; // degenerate (no banks) — cannot happen (pool seeded)
|
||||
bankOpActivate(target);
|
||||
bankOpActivate(*g_session, target);
|
||||
}
|
||||
|
||||
// Activate the pool directly (the common "back to the default target" jump). Bindable
|
||||
// direct-by-id form; a general activate-bank-by-name/menu is a panel affordance.
|
||||
void doBankActivatePool() {
|
||||
bankOpActivate(kPoolBankId);
|
||||
bankOpActivate(*g_session, kPoolBankId);
|
||||
}
|
||||
|
||||
// Move or copy the panel's selected samples into a named destination bank (prompted
|
||||
@@ -257,7 +259,7 @@ void doBankTransferSelected(bool copy) {
|
||||
ShowConsoleMsg("ReaSampler: source and destination are the same bank.\n");
|
||||
return;
|
||||
}
|
||||
bankOpTransfer(selected, srcId, destId, copy);
|
||||
bankOpTransfer(*g_session, selected, srcId, destId, copy);
|
||||
}
|
||||
|
||||
// Remove the panel's selected samples from the SOURCE bank (the focused region's
|
||||
@@ -275,7 +277,7 @@ void doBankRemoveSelected() {
|
||||
ShowConsoleMsg("ReaSampler: the selection's bank no longer exists.\n");
|
||||
return;
|
||||
}
|
||||
bankOpRemove(selected, srcId);
|
||||
bankOpRemove(*g_session, selected, srcId);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
#include "core/view/lane_keys.h" // view::isOnManualLane — the single managed/manual predicate
|
||||
#include "core/view/view_mode_model.h"
|
||||
#include "persist.h" // ReaSamplerSession (owns view() model)
|
||||
#include "shell/persist/session.h" // ReaSamplerSession (owns view() model)
|
||||
#include "shell/capture/item_read.h" // shared MediaItem* -> GUID + fixed-lane-name reads (D2 W3-B)
|
||||
#include "shell/capture/track_guid.h" // shared MediaTrack* -> canonical GUID key
|
||||
#include "shell/panel/panel_window.h" // bankPanelInvalidate — footer toggle repaint
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// drag_out_win — OS/COM initiation of native OS drag-out (M11). See drag_out_win.h.
|
||||
//
|
||||
// Windows path (primary): a hand-rolled minimal IDataObject exposing exactly one format,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// drag_out_win — the OS/COM initiation half of native OS drag-out (Milestone 11). The pure
|
||||
// gesture-boundary decision and path-list assembly live in drag_out.*; THIS is the platform
|
||||
// shell that hands a resolved, existing-file path list to the operating system's drag-drop
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// instrument_drop_win — the REAPER shell for S17 drop-and-load. See instrument_drop_win.h.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h WITHOUT
|
||||
@@ -30,6 +29,10 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the namespaces.h shim is retired).
|
||||
using version::vstPluginName;
|
||||
using wire::infoNamesFxHotspot;
|
||||
|
||||
namespace {
|
||||
|
||||
// Write `bytes` to a fresh uniquely-named .vstpreset in the OS temp dir and return its path;
|
||||
@@ -43,7 +46,7 @@ namespace {
|
||||
//
|
||||
// Non-throwing: every std::filesystem call uses the error_code overload. The whole body is
|
||||
// wrapped in try/catch to guarantee no exception crosses the REAPER C callback boundary
|
||||
// (the same discipline persist.cpp uses — see its non-throwing scanPruneOrphans comment).
|
||||
// (the same discipline the prune shell uses — see prune_fs.cpp's non-throwing scan comment).
|
||||
//
|
||||
// Returns the path object (not a narrow string) so the caller can:
|
||||
// (a) pass path.u8string() to TrackFX_SetPreset — UTF-8 on MSVC, not ACP-converted,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// instrument_drop_win — the REAPER-facing shell half of S17 drop-and-load. The pure gesture
|
||||
// decision lives in drag_out (DragGesture::InstrumentDrop) and the pure payload construction
|
||||
// in instrument_drop; THIS is the platform shell that (a) resolves a screen point to a track
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "persist.h" // ReaSamplerSession — pruneDryRun / pruneOrphanSet / pruneReclaim
|
||||
#include "shell/persist/session.h" // ReaSamplerSession — pruneDryRun / pruneOrphanSet / pruneReclaim
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_ShowConsoleMsg
|
||||
@@ -31,7 +31,7 @@ namespace reasampler {
|
||||
// is opened (file deletion is not REAPER-undoable and pruneReclaim mutates no project
|
||||
// state) — a Ctrl-Z after a prune correctly cannot claim to restore deleted files.
|
||||
void doBankPruneFolder(ReaSamplerSession& session) {
|
||||
const PruneReport report = session.pruneDryRun();
|
||||
const reclaim::PruneReport report = session.pruneDryRun();
|
||||
|
||||
// pS-usage FAIL-SAFE: a present instance-usage record could not be read — the
|
||||
// protected set is unknowable, so the prune HALTS outright (deletes nothing) rather
|
||||
@@ -85,7 +85,7 @@ void doBankPruneFolder(ReaSamplerSession& session) {
|
||||
}
|
||||
|
||||
// Confirmed -> delete exactly the confirmed set (recomputed fresh, stale entries skipped).
|
||||
const PruneDeletionResult del = session.pruneReclaim(orphanSet);
|
||||
const reclaim::PruneDeletionResult del = session.pruneReclaim(orphanSet);
|
||||
|
||||
std::string done = "ReaSampler prune: reclaimed " +
|
||||
std::to_string(del.reclaimedCount) + " file(s), " +
|
||||
|
||||
@@ -0,0 +1,183 @@
|
||||
// bank_ops.cpp — the promptless bank-verb seam (Q-W6 lift; see bank_ops.h for the
|
||||
// contract). The ONE implementation home of the bank verbs (create / rename /
|
||||
// delete / evacuate / activate / move / copy / remove): each mutates the given
|
||||
// session's book() then persists via persistBankOp() (one bank op = one Ctrl-Z; a
|
||||
// true index no-op opens NO undo point). It DOES mutate the bank BOOK — but only
|
||||
// the index/model + ext-state, never the arrange, never a sample file on disk
|
||||
// (bank ops are index-only; files stay put — CONTEXT.md §Multi-bank).
|
||||
// REFERENCE-INVALIDATION GUARDRAIL: after a STRUCTURAL mutation any
|
||||
// Bank*/BankModel& is invalid — verbs take ids and resolve fresh per model call.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
// WITHOUT REAPERAPI_IMPLEMENT — main.cpp owns the API pointers; here they are
|
||||
// extern (CLAUDE.md §contract). DAW-verified, not unit tested.
|
||||
|
||||
#include "shell/bank_ops/bank_ops.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "core/model/bank_book.h" // BankBook / TransferResult / RemoveScope
|
||||
#include "shell/persist/session.h" // ReaSamplerSession — the session the verbs mutate
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_genGuid
|
||||
#define REAPERAPI_WANT_guidToString
|
||||
#define REAPERAPI_WANT_Undo_BeginBlock2
|
||||
#define REAPERAPI_WANT_Undo_EndBlock2
|
||||
#include "reaper_plugin_functions.h"
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
namespace {
|
||||
|
||||
// Mints a fresh, genuine REAPER GUID string as a stable bank id (the B2/model
|
||||
// design: ids are caller-supplied and stable; the model stays pure and mints none).
|
||||
// Distinct from a track GUID by origin only — both are canonical guidToString output.
|
||||
std::string mintBankId() {
|
||||
GUID g{};
|
||||
genGuid(&g);
|
||||
char buf[64] = {0}; // guidToString needs >=64 chars (SDK contract)
|
||||
guidToString(&g, buf);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// Persists a completed bank-index verb as a SINGLE batched REAPER undo point (R-B) —
|
||||
// one bank op = one Ctrl-Z.
|
||||
//
|
||||
// WHY THIS WRAPS AND saveToActiveProject() DOES NOT: a bank verb mutates ONLY our
|
||||
// project ext-state (SetProjExtState under "reasampler"), which REAPER's undo system
|
||||
// captures iff UNDO_STATE_MISCCFG is set in the Undo_EndBlock2 flags — the SDK
|
||||
// documents MISCCFG as covering "extensions!" project ext-state (reaper_plugin.h
|
||||
// ~1544, ~1199). We pass exactly UNDO_STATE_MISCCFG (not -1 / UNDO_STATE_ALL as the
|
||||
// item-move family does): a bank verb touches no tracks, FX, items, or envelopes, so
|
||||
// snapshotting them would be both heavier and semantically wrong. The persist runs
|
||||
// INSIDE the block so the post-mutation ext-state is the block's "after" image.
|
||||
//
|
||||
// UNSAVED-PROJECT GUARDRAIL: on an unsaved / no-active project saveToActiveProject()
|
||||
// no-ops (nothing is written to ext state). We must still CLOSE the block we opened,
|
||||
// but with an EMPTY label and a zero flag so REAPER DISCARDS the point instead of
|
||||
// recording a no-effect undo entry — mirroring view.cpp's empty-plan close. The
|
||||
// in-session model change stands and persists on the user's next save; it just earns
|
||||
// no undo point until there is a project to persist into (undo of an unsaved bank op
|
||||
// has nothing to roll back to anyway). The Begin/End must still be balanced, hence
|
||||
// the close-either-way. (Quiet persist by design — mirrors the CAPTURE path, NOT the
|
||||
// Design-View path; deliberately NO Save-As prompt.)
|
||||
void persistBankOp(ReaSamplerSession& session, const char* label,
|
||||
bool bumpGeneration) {
|
||||
Undo_BeginBlock2(nullptr);
|
||||
// S9: bump the bank-generation counter INSIDE the block, before the persist, so the
|
||||
// fresh generation rides the same ext-state write (saveToActiveProject() stamps
|
||||
// bankGeneration()). Bumped only for content-changing verbs (the caller decides); a
|
||||
// pure-organizational verb passes false and leaves the counter be, so a
|
||||
// rename/activate does not needlessly refresh live instances.
|
||||
if (bumpGeneration) session.bumpBankGeneration();
|
||||
const bool persisted = session.saveToActiveProject();
|
||||
if (persisted)
|
||||
Undo_EndBlock2(nullptr, label, UNDO_STATE_MISCCFG);
|
||||
else
|
||||
Undo_EndBlock2(nullptr, "", 0); // no ext-state write -> discard the empty point
|
||||
}
|
||||
|
||||
// --- Promptless inner bank verbs (one home) ------------------------------------
|
||||
// Model op + persistBankOp only; NO UX. Callers own prompts/confirms/nudges and the
|
||||
// session-liveness question. Each verb persists ONLY after the model accepted — a
|
||||
// rejected op opens no undo point.
|
||||
|
||||
std::string bankOpCreate(ReaSamplerSession& session, const std::string& name) {
|
||||
const std::string id = mintBankId();
|
||||
if (!session.book().createBank(id, name)) return {}; // duplicate display name (model rule)
|
||||
persistBankOp(session, "ReaSampler: create bank");
|
||||
return id;
|
||||
}
|
||||
|
||||
bool bankOpRename(ReaSamplerSession& session, const std::string& bankId,
|
||||
const std::string& newName) {
|
||||
if (!session.book().renameBank(bankId, newName)) return false; // pool / name in use
|
||||
persistBankOp(session, "ReaSampler: rename bank");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bankOpDelete(ReaSamplerSession& session, const std::string& bankId,
|
||||
bool bumpGeneration) {
|
||||
if (!session.book().deleteBank(bankId)) return false; // pool un-deletable (model rule)
|
||||
persistBankOp(session, "ReaSampler: delete bank", bumpGeneration);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bankOpEvacuate(ReaSamplerSession& session, const std::string& bankId) {
|
||||
if (!session.book().evacuate(bankId)) return false; // pool is a destination, not a source
|
||||
// S9: evacuate moves members between banks (bank membership changes) -> bump.
|
||||
persistBankOp(session, "ReaSampler: evacuate bank", /*bumpGeneration=*/true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bankOpActivate(ReaSamplerSession& session, const std::string& bankId) {
|
||||
if (!session.book().setActiveBank(bankId)) return false; // rejects an unknown id
|
||||
persistBankOp(session, "ReaSampler: activate bank");
|
||||
return true;
|
||||
}
|
||||
|
||||
// NO-OP GUARDRAIL — VERB-AWARE (a collapse means different things per verb):
|
||||
// * MOVE collapse: the source entry WAS removed (bank_book moveSample removes
|
||||
// unconditionally before the dest add collapses on hash), so the index DID
|
||||
// mutate — it counts toward opening an undo point.
|
||||
// * COPY collapse: the source is left intact AND the dest already held the hash,
|
||||
// so NOTHING changed — a true index no-op. It must NOT open an undo point.
|
||||
// Hence: copy counts only real gains; move counts gains OR collapses. Ids pass
|
||||
// straight to the model op — no BankModel& cached across the loop's mutations.
|
||||
bool bankOpTransfer(ReaSamplerSession& session,
|
||||
const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId, const std::string& destBankId,
|
||||
bool copy) {
|
||||
BankBook& b = session.book();
|
||||
if (sampleIds.empty() || srcBankId == destBankId) return false;
|
||||
if (!b.bank(srcBankId) || !b.bank(destBankId)) return false;
|
||||
int ok = 0, collapsed = 0;
|
||||
for (const std::string& sid : sampleIds) {
|
||||
const TransferResult r =
|
||||
copy ? b.copySample(sid, srcBankId, destBankId)
|
||||
: b.moveSample(sid, srcBankId, destBankId);
|
||||
switch (r) {
|
||||
case TransferResult::Moved:
|
||||
case TransferResult::Copied: ++ok; break;
|
||||
case TransferResult::Collapsed: ++collapsed; break;
|
||||
case TransferResult::RejectedUnknownBank:
|
||||
case TransferResult::RejectedSampleAbsent:
|
||||
case TransferResult::RejectedSameBank: break;
|
||||
}
|
||||
}
|
||||
const bool mutated = copy ? (ok > 0) : (ok > 0 || collapsed > 0);
|
||||
if (!mutated) return false; // nothing changed — no persist, no undo point
|
||||
// S9: a move/copy changes bank membership (a sample arrives in / leaves a bank an
|
||||
// instance may reference) -> bump so assigned instances refresh hands-free.
|
||||
persistBankOp(session,
|
||||
copy ? "ReaSampler: copy sample(s)" : "ReaSampler: move sample(s)",
|
||||
/*bumpGeneration=*/true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Index-only, this-bank scope (fork R-A: the sole surfaced verb; RemoveScope::AllBanks
|
||||
// stays latent in the model). Non-destructive to the file: a last-reference remove
|
||||
// leaves the file on disk, orphaned until Phase R prune — remove NEVER deletes bytes
|
||||
// (the manifest is untouched). Silent: recoverability is the batched undo (R-B).
|
||||
bool bankOpRemove(ReaSamplerSession& session,
|
||||
const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId) {
|
||||
BankBook& b = session.book();
|
||||
if (sampleIds.empty() || !b.bank(srcBankId)) return false;
|
||||
int removed = 0;
|
||||
for (const std::string& sid : sampleIds)
|
||||
if (b.removeSample(sid, srcBankId, RemoveScope::ThisBank) ==
|
||||
RemoveResult::Removed)
|
||||
++removed;
|
||||
if (removed == 0) return false; // every id already absent — no undo point
|
||||
// S9: a remove drops a sample from a bank (an instance referencing it must refresh —
|
||||
// it will resolve to silence, per the stale-id policy) -> bump.
|
||||
persistBankOp(session, "ReaSampler: remove sample(s)", /*bumpGeneration=*/true);
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace reasampler
|
||||
@@ -0,0 +1,83 @@
|
||||
#pragma once
|
||||
// bank_ops — the promptless bank-verb seam (Q-W6 lift of the Q-W4 single-owner
|
||||
// verbs out of shell/panel/panel_bank_ops into a NON-UI home). Each verb is a model
|
||||
// op on the given session's BankBook + persistBankOp (undo-batched ext-state
|
||||
// persist) — NO prompts, NO message boxes, NO panel-state nudges, NO panel-global
|
||||
// reads. The two UX surfaces consume these as thin skins:
|
||||
//
|
||||
// * shell/panel/panel_bank_ops — the panel's menu handlers (prompts / confirms /
|
||||
// repaints), passing the panel's live session.
|
||||
// * shell/actions/bank_actions — the bindable family (text prompts / console
|
||||
// feedback), passing its registered session.
|
||||
//
|
||||
// The session arrives BY REFERENCE: there is exactly one session pointer question
|
||||
// per call site (the caller's), so a missing session can never be half-reported as
|
||||
// a model rejection from in here (the Q-W4 review's fail-safe-collapse concern).
|
||||
// Every verb returns whether the model accepted the mutation — a rejected op
|
||||
// persists nothing and opens no undo point.
|
||||
//
|
||||
// REAPER-facing (persist + undo blocks + GUID minting) but SDK-free in this header.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
class ReaSamplerSession;
|
||||
|
||||
// Mints a stable GUID bank id, creates `name` in the book. Returns the new bank id,
|
||||
// or "" when the model rejects the name (duplicate, trimmed + case-insensitive).
|
||||
// Create is purely organizational — no generation bump.
|
||||
std::string bankOpCreate(ReaSamplerSession& session, const std::string& name);
|
||||
|
||||
// Renames `bankId`. False when the model rejects (pool un-renamable / name in use).
|
||||
bool bankOpRename(ReaSamplerSession& session, const std::string& bankId,
|
||||
const std::string& newName);
|
||||
|
||||
// Deletes `bankId`. False when the model rejects (pool un-deletable). The caller
|
||||
// passes `bumpGeneration` from the member count it read BEFORE any evacuate/delete
|
||||
// (an evacuate-then-delete flow must still bump on the ORIGINAL membership).
|
||||
bool bankOpDelete(ReaSamplerSession& session, const std::string& bankId,
|
||||
bool bumpGeneration);
|
||||
|
||||
// Evacuates `bankId`'s members to the pool. False when the model rejects (the pool
|
||||
// itself). Bumps the generation (membership changed).
|
||||
bool bankOpEvacuate(ReaSamplerSession& session, const std::string& bankId);
|
||||
|
||||
// Activates `bankId` as the capture target. False on an unknown id. No bump.
|
||||
bool bankOpActivate(ReaSamplerSession& session, const std::string& bankId);
|
||||
|
||||
// Moves (copy=false) or copies (copy=true) `sampleIds` from `srcBankId` to
|
||||
// `destBankId` (index-only; files never relocate). Returns whether the index
|
||||
// actually mutated — the verb-aware no-op guardrail: a COPY collapse changes
|
||||
// nothing (no undo point); a MOVE collapse did remove the source entry (counts).
|
||||
// Persists ONE undo point ("move/copy sample(s)") only when mutated.
|
||||
bool bankOpTransfer(ReaSamplerSession& session,
|
||||
const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId, const std::string& destBankId,
|
||||
bool copy);
|
||||
|
||||
// Removes `sampleIds` from `srcBankId` (index-only, this-bank scope; never deletes
|
||||
// bytes). Returns whether anything was removed; persists one undo point when so.
|
||||
bool bankOpRemove(ReaSamplerSession& session,
|
||||
const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId);
|
||||
|
||||
// Persists a completed bank-index verb as a single REAPER undo point (R-B).
|
||||
// Wraps the session persist (SetProjExtState) in a Begin/End block with
|
||||
// UNDO_STATE_MISCCFG so the bank op is one Ctrl-Z. On an unsaved / no-active project
|
||||
// the persist no-ops and the block is closed with an empty label + zero flag (REAPER
|
||||
// discards it). Callers must invoke this ONLY after a successful/effective mutation —
|
||||
// rejected ops (duplicate name, un-deletable pool, etc.) must return before reaching
|
||||
// here so no empty undo point is ever opened for a no-op.
|
||||
//
|
||||
// S9 bank-generation bump: pass `bumpGeneration = true` for a verb that changes what a
|
||||
// live instance would PLAY — move / copy / remove / evacuate / delete-with-members. Leave
|
||||
// it false (the default) for a PURELY ORGANIZATIONAL verb — create / rename / activate /
|
||||
// reorder. The bump (when requested) happens INSIDE the block, BEFORE the persist, so
|
||||
// the stamped counter rides the same ext-state write and undo captures the pre/post
|
||||
// generation with the rest of the blob.
|
||||
void persistBankOp(ReaSamplerSession& session, const char* label,
|
||||
bool bumpGeneration = false);
|
||||
|
||||
} // namespace reasampler
|
||||
+5
-111
@@ -1,16 +1,16 @@
|
||||
#pragma once
|
||||
// capture — the REAPER-facing capture shell (CLAUDE.md §load-bearing split).
|
||||
//
|
||||
// This header declares the capture *seam* the later milestones fill:
|
||||
// * CaptureRequest — everything a capture needs, source-mode-agnostic.
|
||||
// This header declares the SHARED capture seam (Q-W6 split of the former fat
|
||||
// header — the realtime backend's async begin/tick/abort surface now lives in
|
||||
// capture_realtime_shell.h):
|
||||
// * CaptureRequest / CaptureResult — everything a capture needs and yields,
|
||||
// source-mode-agnostic; the types BOTH backends speak.
|
||||
// * OfflineRenderBackend — the deterministic default; a plain CONCRETE class
|
||||
// (the former ICaptureBackend interface was deleted in
|
||||
// Q-W3, T4-26 — it had one deriver and zero polymorphic
|
||||
// call sites; every construction site instantiates the
|
||||
// concrete type).
|
||||
// * RealtimeRecordBackend — the ASYNC realtime seam (begin/tick/abort), driven
|
||||
// across timer ticks; a genuinely different lifecycle
|
||||
// (see the SEAM CHOICE note at its declaration).
|
||||
// * makeUniqueTag / stampCaptureSample — the shared file-tag mint and the shared
|
||||
// finished-capture metadata stamp both backends call
|
||||
// (Q-W3 riders T1-11 / T2-09).
|
||||
@@ -20,7 +20,6 @@
|
||||
// REAPER-free lets callers (the capture orchestration TUs) depend on the seam
|
||||
// without dragging the SDK into every include site.
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
@@ -156,109 +155,4 @@ void stampCaptureSample(Sample& s, const CaptureRequest& req,
|
||||
ReaProject* rateProj, ReaProject* timeSigProj,
|
||||
const std::string& absolutePath);
|
||||
|
||||
// --- Realtime-record backend: the ASYNC seam ---------------------------------
|
||||
//
|
||||
// A realtime record is inherently asynchronous: CSurf_OnRecord starts the transport
|
||||
// on REAPER's audio thread and returns immediately — it does NOT block until the
|
||||
// range completes, which takes (end - start) wall-clock seconds. Blocking the main
|
||||
// thread for that duration freezes REAPER's UI, so the realtime backend is DRIVEN
|
||||
// ACROSS TIMER TICKS instead: begin() starts and returns at once; tick() (called
|
||||
// from the same OnTimer that runs session.poll()) advances the in-flight record and
|
||||
// reports when it is done.
|
||||
//
|
||||
// SEAM CHOICE (surfaced): the two backends deliberately share NO interface. The
|
||||
// lifecycles are genuinely different (offline is headless + immediate — one
|
||||
// synchronous capture() call returns a finished Sample; realtime is
|
||||
// transport-driven + async — begin/tick/abort across timer ticks), so a shared
|
||||
// interface would make offline fake a lifecycle it does not have (its tick()
|
||||
// would always be Done on the first call — dead code / an LSP smell). Offline
|
||||
// stays synchronous; the realtime backend owns this small bespoke async seam,
|
||||
// driven by exactly one caller (the timer-driven realtime_lifecycle). This is the
|
||||
// split-sync/async fork, chosen over a unified async interface for that reason.
|
||||
// (The old synchronous ICaptureBackend interface over OfflineRenderBackend was
|
||||
// deleted in Q-W3 — T4-26: one deriver, zero polymorphic call sites.)
|
||||
|
||||
// One tick's verdict from the in-flight record.
|
||||
enum class RealtimeTickStatus {
|
||||
InProgress, // still recording — call tick() again next timer tick
|
||||
Done, // finished (range end reached, or the user stopped) — `result` is set
|
||||
Failed, // an error tore the capture down — `result.message` explains
|
||||
};
|
||||
|
||||
struct RealtimeTickResult {
|
||||
RealtimeTickStatus status = RealtimeTickStatus::InProgress;
|
||||
CaptureResult result; // meaningful only when status == Done or Failed
|
||||
};
|
||||
|
||||
// The opaque in-flight capture state. Owns the snapshot of everything to restore
|
||||
// (temp track + its receive sends from the source tracks, other tracks' I_RECARM,
|
||||
// transport, edit cursor, time selection) and the record's own project handle.
|
||||
// Defined in capture_realtime_shell.cpp; the header stays REAPER-free (nothing is
|
||||
// dereferenced here) by holding it behind a forward-declared type + unique_ptr.
|
||||
//
|
||||
// restore()/teardown is idempotent and lives ON THIS OBJECT (not a function-scope
|
||||
// RAII guard) because the record spans ticks — no single stack frame outlives it.
|
||||
// Every terminal path (normal completion, user stop, error, project switch, unload)
|
||||
// funnels through the same single restore, safe to call once from whichever fires.
|
||||
class RealtimeCaptureState;
|
||||
|
||||
// Out-of-line deleter so callers (realtime_lifecycle) can own a unique_ptr to the
|
||||
// opaque RealtimeCaptureState WITHOUT its full (REAPER-typed) definition — the
|
||||
// delete is compiled in capture_realtime_shell.cpp where the type is complete,
|
||||
// keeping this header REAPER-free (load-bearing split).
|
||||
struct RealtimeCaptureStateDeleter {
|
||||
void operator()(RealtimeCaptureState* p) const noexcept;
|
||||
};
|
||||
using RealtimeCaptureHandle =
|
||||
std::unique_ptr<RealtimeCaptureState, RealtimeCaptureStateDeleter>;
|
||||
|
||||
// Realtime-record backend — captures by RECORDING in realtime (transport-driven)
|
||||
// into a hidden temp track, then moves the recorded file into the bank as a Sample.
|
||||
// For sources offline render cannot do (hardware, performed FX) and as the true
|
||||
// pre-FX-dry path (I_RECMODE_FLAGS &3==1 — the only pre-FX tap in the SDK; offline
|
||||
// render has none). Dialog-free: never invokes the offline-render progress window.
|
||||
//
|
||||
// Non-bit-identical by nature (it is realtime); offline stays the deterministic
|
||||
// default. Non-destructive across EVERY terminal path — the review gate — which is
|
||||
// harder here than offline because the record spans ticks: the snapshot + restore
|
||||
// live on RealtimeCaptureState, not a function-scope RAII destructor.
|
||||
//
|
||||
// SCOPE (this increment): TRACK scope only — records the selected track's OWN
|
||||
// output (item + that track's own FX + its own fader/pan, PRE-parent), matching
|
||||
// offline's track scope. This needs NO FxBypassGuard: a send tapping a track's
|
||||
// output is naturally PRE-parent (the parent has not summed it yet), so the tap is
|
||||
// chain-independent by construction. Item realtime is deferred (UnsupportedMode).
|
||||
class RealtimeRecordBackend {
|
||||
public:
|
||||
// Starts a realtime record: validates the request (track scope, non-empty range,
|
||||
// at least one source track, active + saved project, transport idle), snapshots
|
||||
// all state to restore, creates the hidden temp track, routes a send FROM each
|
||||
// source track INTO the temp track, arms, and CSurf_OnRecord — then returns
|
||||
// IMMEDIATELY (no wait, no UI block). `sourceTracks` are the selected tracks to
|
||||
// tap (resolved by the action layer — the CaptureRequest itself stays REAPER-free,
|
||||
// carrying only the provenance GUIDs). On success the returned unique_ptr owns the
|
||||
// in-flight state; drive it with tick(). On a validation/setup failure returns
|
||||
// nullptr and fills `outFailure` with the CaptureStatus + message (nothing was
|
||||
// left mutated — begin() restores on its own failure paths).
|
||||
RealtimeCaptureHandle begin(const CaptureRequest& request,
|
||||
const std::vector<MediaTrack*>& sourceTracks,
|
||||
CaptureResult& outFailure);
|
||||
|
||||
// Advances the in-flight record one tick. Reads the transport (bound to the
|
||||
// record's OWN project handle so a project switch cannot confuse it), and on a
|
||||
// terminal verdict stops the transport, finalizes the recorded file into the
|
||||
// bank Sample (Done) or reports the failure (Failed), then restores ALL
|
||||
// snapshotted state. Returns InProgress while the record is still running.
|
||||
// After Done/Failed the state is spent — the caller drops the unique_ptr.
|
||||
RealtimeTickResult tick(RealtimeCaptureState& state);
|
||||
|
||||
// Force-terminate an in-flight record NOW without waiting for the range end:
|
||||
// stops the transport, finalizes whatever was captured (best effort) or abandons
|
||||
// it, and restores ALL snapshotted state. For the shutdown / project-switch
|
||||
// paths (extension unload, a new project became active) where the record must
|
||||
// not leak a temp track / armed track / altered transport into the user's
|
||||
// project. Idempotent — safe even if a prior tick already tore the state down.
|
||||
RealtimeTickResult abort(RealtimeCaptureState& state);
|
||||
};
|
||||
|
||||
} // namespace reasampler::capture
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "core/capture/batch_capture.h" // planCaptureUnits / BatchOutcome
|
||||
#include "core/model/bank_book.h" // BankBook / Bank
|
||||
#include "core/model/provenance.h" // recipe parse/build, fingerprint
|
||||
#include "persist.h" // ReaSamplerSession
|
||||
#include "shell/persist/session.h" // ReaSamplerSession
|
||||
#include "shell/capture/capture_orchestrator.h" // captureAndIndexOne / renderOffline
|
||||
#include "shell/capture/provenance_shell.h" // fxChainIdentity* / trackByGuid
|
||||
#include "shell/capture/scope_resolve.h" // ResolvedSource
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#include "core/capture/tail_control.h" // TailSetting
|
||||
#include "core/model/provenance.h" // model::Provenance
|
||||
#include "ingest.h" // ingestAssignActiveInstance
|
||||
#include "persist.h" // ReaSamplerSession
|
||||
#include "shell/persist/session.h" // ReaSamplerSession
|
||||
#include "shell/capture/insert.h" // runInsert / InsertRequest
|
||||
#include "shell/capture/realtime_lifecycle.h" // the in-flight realtime state
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@
|
||||
// Item realtime is deferred (UnsupportedMode): item scope would need per-item take
|
||||
// isolation on top of the tap, which is a separate increment.
|
||||
|
||||
#include "shell/capture/capture.h"
|
||||
#include "shell/capture/capture_realtime_shell.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
#pragma once
|
||||
// capture_realtime_shell — the ASYNC realtime-record seam (Q-W6 split of the former
|
||||
// fat capture.h: this header owns the realtime backend's begin/tick/abort surface;
|
||||
// capture.h keeps the shared CaptureRequest/CaptureResult types, the offline
|
||||
// backend, and the shared backend helpers). Implemented by
|
||||
// capture_realtime_shell.cpp; driven by exactly one caller (realtime_lifecycle).
|
||||
//
|
||||
// A realtime record is inherently asynchronous: CSurf_OnRecord starts the transport
|
||||
// on REAPER's audio thread and returns immediately — it does NOT block until the
|
||||
// range completes, which takes (end - start) wall-clock seconds. Blocking the main
|
||||
// thread for that duration freezes REAPER's UI, so the realtime backend is DRIVEN
|
||||
// ACROSS TIMER TICKS instead: begin() starts and returns at once; tick() (called
|
||||
// from the same OnTimer that runs session.poll()) advances the in-flight record and
|
||||
// reports when it is done.
|
||||
//
|
||||
// SEAM CHOICE (surfaced): the two backends deliberately share NO interface. The
|
||||
// lifecycles are genuinely different (offline is headless + immediate — one
|
||||
// synchronous capture() call returns a finished Sample; realtime is
|
||||
// transport-driven + async — begin/tick/abort across timer ticks), so a shared
|
||||
// interface would make offline fake a lifecycle it does not have (its tick()
|
||||
// would always be Done on the first call — dead code / an LSP smell). Offline
|
||||
// stays synchronous; the realtime backend owns this small bespoke async seam.
|
||||
// This is the split-sync/async fork, chosen over a unified async interface for
|
||||
// that reason. (The old synchronous ICaptureBackend interface over
|
||||
// OfflineRenderBackend was deleted in Q-W3 — T4-26: one deriver, zero polymorphic
|
||||
// call sites.)
|
||||
//
|
||||
// REAPER-free like capture.h: MediaTrack is forward-declared there and never
|
||||
// dereferenced here; the REAPER-facing TU is capture_realtime_shell.cpp.
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "shell/capture/capture.h" // CaptureRequest / CaptureResult / MediaTrack fwd
|
||||
|
||||
namespace reasampler::capture {
|
||||
|
||||
// One tick's verdict from the in-flight record.
|
||||
enum class RealtimeTickStatus {
|
||||
InProgress, // still recording — call tick() again next timer tick
|
||||
Done, // finished (range end reached, or the user stopped) — `result` is set
|
||||
Failed, // an error tore the capture down — `result.message` explains
|
||||
};
|
||||
|
||||
struct RealtimeTickResult {
|
||||
RealtimeTickStatus status = RealtimeTickStatus::InProgress;
|
||||
CaptureResult result; // meaningful only when status == Done or Failed
|
||||
};
|
||||
|
||||
// The opaque in-flight capture state. Owns the snapshot of everything to restore
|
||||
// (temp track + its receive sends from the source tracks, other tracks' I_RECARM,
|
||||
// transport, edit cursor, time selection) and the record's own project handle.
|
||||
// Defined in capture_realtime_shell.cpp; the header stays REAPER-free (nothing is
|
||||
// dereferenced here) by holding it behind a forward-declared type + unique_ptr.
|
||||
//
|
||||
// restore()/teardown is idempotent and lives ON THIS OBJECT (not a function-scope
|
||||
// RAII guard) because the record spans ticks — no single stack frame outlives it.
|
||||
// Every terminal path (normal completion, user stop, error, project switch, unload)
|
||||
// funnels through the same single restore, safe to call once from whichever fires.
|
||||
class RealtimeCaptureState;
|
||||
|
||||
// Out-of-line deleter so callers (realtime_lifecycle) can own a unique_ptr to the
|
||||
// opaque RealtimeCaptureState WITHOUT its full (REAPER-typed) definition — the
|
||||
// delete is compiled in capture_realtime_shell.cpp where the type is complete,
|
||||
// keeping this header REAPER-free (load-bearing split).
|
||||
struct RealtimeCaptureStateDeleter {
|
||||
void operator()(RealtimeCaptureState* p) const noexcept;
|
||||
};
|
||||
using RealtimeCaptureHandle =
|
||||
std::unique_ptr<RealtimeCaptureState, RealtimeCaptureStateDeleter>;
|
||||
|
||||
// Realtime-record backend — captures by RECORDING in realtime (transport-driven)
|
||||
// into a hidden temp track, then moves the recorded file into the bank as a Sample.
|
||||
// For sources offline render cannot do (hardware, performed FX) and as the true
|
||||
// pre-FX-dry path (I_RECMODE_FLAGS &3==1 — the only pre-FX tap in the SDK; offline
|
||||
// render has none). Dialog-free: never invokes the offline-render progress window.
|
||||
//
|
||||
// Non-bit-identical by nature (it is realtime); offline stays the deterministic
|
||||
// default. Non-destructive across EVERY terminal path — the review gate — which is
|
||||
// harder here than offline because the record spans ticks: the snapshot + restore
|
||||
// live on RealtimeCaptureState, not a function-scope RAII destructor.
|
||||
//
|
||||
// SCOPE (this increment): TRACK scope only — records the selected track's OWN
|
||||
// output (item + that track's own FX + its own fader/pan, PRE-parent), matching
|
||||
// offline's track scope. This needs NO FxBypassGuard: a send tapping a track's
|
||||
// output is naturally PRE-parent (the parent has not summed it yet), so the tap is
|
||||
// chain-independent by construction. Item realtime is deferred (UnsupportedMode).
|
||||
class RealtimeRecordBackend {
|
||||
public:
|
||||
// Starts a realtime record: validates the request (track scope, non-empty range,
|
||||
// at least one source track, active + saved project, transport idle), snapshots
|
||||
// all state to restore, creates the hidden temp track, routes a send FROM each
|
||||
// source track INTO the temp track, arms, and CSurf_OnRecord — then returns
|
||||
// IMMEDIATELY (no wait, no UI block). `sourceTracks` are the selected tracks to
|
||||
// tap (resolved by the action layer — the CaptureRequest itself stays REAPER-free,
|
||||
// carrying only the provenance GUIDs). On success the returned unique_ptr owns the
|
||||
// in-flight state; drive it with tick(). On a validation/setup failure returns
|
||||
// nullptr and fills `outFailure` with the CaptureStatus + message (nothing was
|
||||
// left mutated — begin() restores on its own failure paths).
|
||||
RealtimeCaptureHandle begin(const CaptureRequest& request,
|
||||
const std::vector<MediaTrack*>& sourceTracks,
|
||||
CaptureResult& outFailure);
|
||||
|
||||
// Advances the in-flight record one tick. Reads the transport (bound to the
|
||||
// record's OWN project handle so a project switch cannot confuse it), and on a
|
||||
// terminal verdict stops the transport, finalizes the recorded file into the
|
||||
// bank Sample (Done) or reports the failure (Failed), then restores ALL
|
||||
// snapshotted state. Returns InProgress while the record is still running.
|
||||
// After Done/Failed the state is spent — the caller drops the unique_ptr.
|
||||
RealtimeTickResult tick(RealtimeCaptureState& state);
|
||||
|
||||
// Force-terminate an in-flight record NOW without waiting for the range end:
|
||||
// stops the transport, finalizes whatever was captured (best effort) or abandons
|
||||
// it, and restores ALL snapshotted state. For the shutdown / project-switch
|
||||
// paths (extension unload, a new project became active) where the record must
|
||||
// not leak a temp track / armed track / altered transport into the user's
|
||||
// project. Idempotent — safe even if a prior tick already tore the state down.
|
||||
RealtimeTickResult abort(RealtimeCaptureState& state);
|
||||
};
|
||||
|
||||
} // namespace reasampler::capture
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// insert.cpp — REAPER-facing placement shell (M6). See insert.h.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
@@ -40,7 +39,7 @@
|
||||
#include "core/model/bank_model.h"
|
||||
#include "shell/panel/panel_bank_ops.h" // bankPanelSelectedSampleIds / SourceBankId
|
||||
#include "core/capture/capture_paths.h"
|
||||
#include "persist.h"
|
||||
#include "shell/persist/session.h"
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_CountSelectedTracks
|
||||
@@ -58,13 +57,19 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the namespaces.h shim is retired).
|
||||
using capture::computeInsertMode;
|
||||
using capture::normalizeSlashes;
|
||||
using capture::resolveBankFile;
|
||||
using capture::TempoConform;
|
||||
|
||||
namespace {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// The current project's directory (mirrors bank_panel/capture/persist). The bank
|
||||
// index stores relative paths; resolving a bank file needs the current .rpp dir.
|
||||
// FOLLOW-UP (already noted in bank_panel.cpp): a shared "current project dir"
|
||||
// FOLLOW-UP (already noted in panel_bank_ops.cpp): a shared "current project dir"
|
||||
// REAPER helper is a clean small refactor now that a fourth consumer exists — out
|
||||
// of scope for M6.
|
||||
std::string currentProjectDir() {
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// insert — placement of bank samples into the arrange (M6). REAPER-facing shell:
|
||||
// it reads the bank_panel's current selection, resolves each selected sample's
|
||||
// file, and drops it into the arrange at the edit cursor via InsertMedia, wrapped
|
||||
@@ -28,7 +27,7 @@ class ReaSamplerSession;
|
||||
// tempo-conform choice) so the two action variants (native-length vs
|
||||
// conform-to-tempo) differ only by this struct — no divergent code paths.
|
||||
struct InsertRequest {
|
||||
InsertOptions options; // defaults: current track, no conform, native length
|
||||
capture::InsertOptions options; // defaults: current track, no conform, native length
|
||||
};
|
||||
|
||||
// The outcome of an insert action, for the caller to log to the console.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// item_read.cpp — the single MediaItem* read seam (GUID + fixed-lane name). See
|
||||
// item_read.h. Compiled into the reaper_reasampler MODULE; includes
|
||||
// reaper_plugin_functions.h WITHOUT REAPERAPI_IMPLEMENT (main.cpp is the one TU that
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// item_read — the ONE place a MediaItem* is read for its canonical GUID string and for
|
||||
// the durable P_LANENAME of the fixed lane it sits on. Before this seam, view.cpp and
|
||||
// bank_panel.cpp each carried a near-identical private itemGuid / itemLaneName pair
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// provenance_shell.cpp — the REAPER reads behind Milestone 10. See provenance_shell.h.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
@@ -52,6 +51,10 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the namespaces.h shim is retired).
|
||||
using capture::normalizeSlashes;
|
||||
using capture::resolveBankFile;
|
||||
|
||||
std::string fxChainIdentityForTrack(MediaTrack* tr) {
|
||||
if (!tr) return fxChainIdentity({});
|
||||
std::vector<FxIdentityEntry> rows;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// provenance_shell — the REAPER-facing reads Milestone 10 needs, in one place.
|
||||
//
|
||||
// The PURE provenance module (provenance.h) owns the fingerprint encoding, the
|
||||
@@ -29,6 +28,9 @@ namespace reasampler {
|
||||
|
||||
class BankBook;
|
||||
|
||||
// Real-namespace-home using-declaration (Q-W6: the namespaces.h shim is retired).
|
||||
using model::BankFileRef;
|
||||
|
||||
// The in-scope FX-chain identity of a source track (Track scope), folded to the
|
||||
// pure provenance string. Reads the track's own FX chain via TrackFX_GetCount /
|
||||
// TrackFX_GetFXName / TrackFX_GetFXGUID / TrackFX_GetEnabled in chain order.
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
#include "shell/capture/realtime_lifecycle.h"
|
||||
|
||||
#include "persist.h" // ReaSamplerSession
|
||||
#include "shell/persist/session.h" // ReaSamplerSession
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_EnumProjects
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
// REAPER-facing: the .cpp includes reaper_plugin_functions.h WITHOUT
|
||||
// REAPERAPI_IMPLEMENT (main.cpp owns the API pointers — CLAUDE.md §contract).
|
||||
|
||||
#include "shell/capture/capture.h" // RealtimeRecordBackend / RealtimeCaptureHandle
|
||||
#include "shell/capture/capture_realtime_shell.h" // RealtimeRecordBackend / RealtimeCaptureHandle
|
||||
|
||||
namespace reasampler {
|
||||
class ReaSamplerSession;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// track_guid.cpp — the single MediaTrack* -> canonical GUID key formatter. See
|
||||
// track_guid.h. Compiled into the reaper_reasampler MODULE; includes
|
||||
// reaper_plugin_functions.h WITHOUT REAPERAPI_IMPLEMENT (main.cpp is the one TU
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// track_guid — the ONE place a MediaTrack* is formatted into the canonical GUID
|
||||
// string used as a membership-index key. Both the Design View shell (view.cpp) and
|
||||
// the actions layer (design_view_actions.cpp) key membership on this exact string, so the key
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
namespace reasampler::vst {
|
||||
|
||||
using namespace reasampler::instrument::map; // ZonePlaySeconds vocabulary + trigger_seam converters
|
||||
using instrument::ui::EnvMode; // envelope_overlay's mode enum (Q-W6: shim retired)
|
||||
using instrument::engine::formatMasterGainLabel;
|
||||
using instrument::engine::masterGainLinearFromNorm;
|
||||
using instrument::engine::masterGainNormFromLinear;
|
||||
|
||||
@@ -209,7 +209,7 @@ LRESULT CALLBACK ReaSamplerEditor::wndProc(HWND hwnd, UINT msg, WPARAM wParam,
|
||||
// Capture stolen mid-drag (modal dialog, alt-tab, etc.) — restore map_ to its
|
||||
// pre-grab snapshot so the in-flight live-drag mutation is rolled back, then reset
|
||||
// the drag state machine so stale capture-less WM_MOUSEMOVEs don't keep editing.
|
||||
// Mirror of bank_panel.cpp's WM_CAPTURECHANGED handler.
|
||||
// Mirror of the panel shell's WM_CAPTURECHANGED handler (panel_window.cpp).
|
||||
if (self) {
|
||||
// A held preview note must be released here too (peer of WM_LBUTTONUP) — capture
|
||||
// loss otherwise leaves the momentary-key voice hung with no note-off.
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
|
||||
#include "core/audio/peaks.h" // computeEnvelope (the cached peak thumbnail)
|
||||
#include "core/capture/capture_paths.h" // resolveBankFile (shared M4 path resolution)
|
||||
#include "core/capture/wav_trim.h" // parseWavLayout, extractFloatFrames
|
||||
#include "core/capture/wav_codec.h" // parseWavLayout, extractFloatFrames
|
||||
#include "core/ui/bank_grid.h" // ThumbnailKey / thumbnailKeyString (T2-10: the pure key)
|
||||
#include "core/util/file_bytes.h" // shared whole-file loader (Q-W1, T2-03)
|
||||
#include "ext_keys.h"
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "core/capture/capture_paths.h" // resolveBankFile (shared M4 path resolution)
|
||||
#include "core/capture/wav_trim.h" // parseWavLayout, extractFloatFrames (shared WAV parse)
|
||||
#include "core/capture/wav_codec.h" // parseWavLayout, extractFloatFrames (shared WAV parse)
|
||||
#include "core/instrument/map/bank_sync.h" // S9/S8 pure decisions: parseBankGeneration, consumeDecision
|
||||
#include "core/instrument/map/sample_map.h" // refs resolve, buildZonedKeymap (pS self-contained)
|
||||
#include "core/util/file_bytes.h" // shared whole-file loader (Q-W1, T2-03)
|
||||
@@ -31,6 +31,12 @@ namespace reasampler::vst {
|
||||
|
||||
using namespace instrument::map; // resolution + bank-sync vocabulary this TU drives
|
||||
using namespace reasampler::wire; // assignment_request + sample_usage wire records
|
||||
// Q-W6 (shim retired): the shared WAV parse + file loader by their real homes.
|
||||
using capture::extractFloatFrames;
|
||||
using capture::parseWavLayout;
|
||||
using capture::resolveBankFile;
|
||||
using capture::WavLayout;
|
||||
using util::readFileBytes;
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ using namespace Steinberg::Vst;
|
||||
namespace reasampler::vst {
|
||||
|
||||
using namespace instrument::map; // the codec + resolution vocabulary this TU marshals
|
||||
using instrument::engine::masterGainMaxLinear; // FB1 taper ceiling (Q-W6: shim retired)
|
||||
|
||||
tresult PLUGIN_API ReaSamplerProcessor::setState(IBStream* state) {
|
||||
if (!state) return kResultFalse;
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// reaper_bridge.cpp — see reaper_bridge.h. The DAW-facing edge; keep it thin.
|
||||
|
||||
#include "shell/instrument/reaper_bridge.h"
|
||||
@@ -6,6 +5,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "core/instrument/map/bridge_marshal.h"
|
||||
#include "core/wire/ext_state_read.h" // readProjExtStateGrowing (T2-04 grow-loop policy)
|
||||
#include "core/capture/capture_paths.h" // projectDirOfRpp (shared M4 project-dir derivation)
|
||||
#include "ext_keys.h" // kProjExtNamespace (shared wire contract)
|
||||
|
||||
@@ -39,6 +39,10 @@ DEF_CLASS_IID(Steinberg::IReaperHostApplication)
|
||||
|
||||
namespace reasampler::vst {
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the namespaces.h shim is retired).
|
||||
using capture::projectDirOfRpp;
|
||||
using instrument::map::decodeGetProjExtState;
|
||||
|
||||
bool ReaperBridge::connect(Steinberg::FUnknown* context) {
|
||||
getProjExtState_ = nullptr;
|
||||
enumProjExtState_ = nullptr;
|
||||
@@ -63,7 +67,8 @@ bool ReaperBridge::connect(Steinberg::FUnknown* context) {
|
||||
enumProjExtState_ = reinterpret_cast<EnumProjExtStateFn>(
|
||||
reaper->getReaperApi("EnumProjExtState"));
|
||||
// EnumProjects(-1, ...) yields the active project AND its .rpp path — the same call
|
||||
// persist.cpp uses, so the instrument derives the project directory identically.
|
||||
// the persist shell (ext_state_io.cpp) uses, so the instrument derives the project
|
||||
// directory identically.
|
||||
enumProjects_ = reinterpret_cast<EnumProjectsFn>(
|
||||
reaper->getReaperApi("EnumProjects"));
|
||||
// pS-usage: the (prefix-guarded) usage publish write + the track-identity pair the
|
||||
@@ -93,17 +98,17 @@ std::optional<std::string> ReaperBridge::readReasamplerExtState(const std::strin
|
||||
|
||||
// GetProjExtState writes into a caller buffer; the bank blob can be large (many
|
||||
// samples), so grow the buffer until the value fits rather than risk a silent
|
||||
// truncation. The retry policy is the SHARED pure
|
||||
// instrument::map::readProjExtStateGrowing (Q-W5 rider T2-04 — one loop for the
|
||||
// truncation. The retry policy is the SHARED pure wire::readProjExtStateGrowing
|
||||
// (T2-04 — one loop for the
|
||||
// extension's persist/usage reads and this bridge read; the rules cannot drift):
|
||||
// absent (rv <= 0) and the >16 MB ceiling both fold to nullopt here, and a
|
||||
// complete value still runs through decodeGetProjExtState (the stale/empty-buffer
|
||||
// guard) exactly as before.
|
||||
const auto read = instrument::map::readProjExtStateGrowing(
|
||||
const auto read = wire::readProjExtStateGrowing(
|
||||
[&](char* buf, int cap) {
|
||||
return getProjExtState_(proj, kProjExtNamespace(), key.c_str(), buf, cap);
|
||||
});
|
||||
if (read.status != instrument::map::GrowingExtStateRead::Status::Complete)
|
||||
if (read.status != wire::GrowingExtStateRead::Status::Complete)
|
||||
return std::nullopt; // absent / empty key, or pathologically large (>16 MB)
|
||||
return decodeGetProjExtState(read.apiReturn, read.value);
|
||||
}
|
||||
@@ -147,7 +152,7 @@ std::string ReaperBridge::currentTrackGuid() {
|
||||
std::string ReaperBridge::activeProjectDir() {
|
||||
if (!enumProjects_) return {};
|
||||
// idx=-1 is the current project tab; the out-buffer receives the full .rpp path,
|
||||
// EMPTY for a never-saved project. Same call + convention as persist.cpp; the pure
|
||||
// EMPTY for a never-saved project. Same call + convention as the persist shell; the pure
|
||||
// projectDirOfRpp turns the .rpp path into the project directory (parent, forward-
|
||||
// slashed) and keeps an unsaved project's empty path empty (no default-location
|
||||
// fallback — the tool's invariant).
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
// reaper_vst3_interfaces.h + reaper_plugin_functions.h at the spike.
|
||||
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
@@ -87,7 +86,8 @@ private:
|
||||
int valOut_sz);
|
||||
// EnumProjects(-1, projfnOut, sz) -> active project + its .rpp path (SDK line
|
||||
// ~1264). The instrument uses idx=-1 (current tab) so it follows the active project,
|
||||
// and reads the .rpp path from the out-buffer exactly as persist.cpp does.
|
||||
// and reads the .rpp path from the out-buffer exactly as the persist shell
|
||||
// (ext_state_io.cpp) does.
|
||||
using EnumProjectsFn = void* (*)(int idx, char* projfnOut, int projfnOut_sz);
|
||||
// SetProjExtState(proj, extname, key, value) -> int (SDK line ~6290). Used ONLY by
|
||||
// writeUsageExtState (prefix-guarded) — see the read-only-bank note there.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// reasampler_embed.cpp — see reasampler_embed.h. The IReaperUIEmbedInterface shell.
|
||||
// Windows-only (D5); guarded so a non-Windows build degrades to a stub that reports
|
||||
// "not supported" and draws nothing.
|
||||
@@ -43,6 +42,14 @@ DEF_CLASS_IID(Steinberg::IReaperUIEmbedInterface)
|
||||
|
||||
namespace reasampler::vst {
|
||||
|
||||
// Real-namespace-home using-directives (Q-W6: the namespaces.h shim is retired):
|
||||
// the embed strip speaks the map vocabulary (listSamples / parseBankGeneration) and
|
||||
// the pure UI layout (embed_strip / editor_geometry Rect) wholesale.
|
||||
using namespace reasampler::instrument::map;
|
||||
using namespace reasampler::instrument::ui;
|
||||
using reasampler::ui::spectralColor;
|
||||
using version::vstPluginName;
|
||||
|
||||
namespace {
|
||||
#ifdef _WIN32
|
||||
// Kit adapter (Phase L, L3): the embed shell's Rect (editor_geometry) -> the kit's KitBox
|
||||
@@ -201,7 +208,7 @@ bool ReaSamplerEmbed::paint(TPtrInt bitmap, TPtrInt drawInfo) {
|
||||
// reads as "present, no zones" — the default single-capture face lives in the editor.
|
||||
LICE_FillRect(bmp, layout.keymap.x, layout.keymap.y, layout.keymap.width,
|
||||
layout.keymap.height, toLice(roleColor(Role::BgCell)), 0.5f, 0);
|
||||
const std::string label = reasampler::vstPluginName() + // channel-derived (S18)
|
||||
const std::string label = version::vstPluginName() + // channel-derived (S18)
|
||||
(samples_.empty() ? " (bank empty)" : " (no zones)");
|
||||
const Rect labelR = Rect::ltrb(layout.keymap.x + 4, layout.keymap.y, layout.keymap.right(),
|
||||
layout.keymap.bottom());
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
// REAPER's messages to/from it and draws with the same LICE idiom as reasampler_editor.
|
||||
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
@@ -52,6 +51,10 @@ namespace reasampler::vst {
|
||||
|
||||
class ReaSamplerProcessor;
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the namespaces.h shim is retired).
|
||||
using instrument::map::PerformanceMap;
|
||||
using instrument::map::SampleChoice;
|
||||
|
||||
// Implements IReaperUIEmbedInterface. Lifetime is OWNED by the processor (the processor
|
||||
// holds the sole unique_ptr and hands out AddRef'd references from queryInterface); the
|
||||
// back-pointer to the processor is therefore always valid while this lives.
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
// binary UID identity — the string identity lives in the pure module).
|
||||
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
|
||||
#include "pluginterfaces/base/funknown.h"
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// vst_entry.cpp — the VST3 module class factory (Phase S1). Enumerates the one class
|
||||
// this module offers (the ReaSampler instrument) via the SDK's factory macros. The
|
||||
// Windows module exports — GetPluginFactory (here, via BEGIN_FACTORY) and
|
||||
@@ -74,10 +73,10 @@ DEF_CLASS2(INLINE_UID(REASAMPLER_ACTIVE_UID_1, REASAMPLER_ACTIVE_UID_2,
|
||||
REASAMPLER_ACTIVE_UID_3, REASAMPLER_ACTIVE_UID_4),
|
||||
Steinberg::PClassInfo::kManyInstances, // cardinality
|
||||
kVstAudioEffectClass, // component category (fixed)
|
||||
reasampler::vstPluginName().c_str(), // plug-in display name (channel-derived)
|
||||
reasampler::version::vstPluginName().c_str(), // plug-in display name (channel-derived)
|
||||
0, // single-component => 0
|
||||
Steinberg::Vst::PlugType::kInstrumentSynthSampler, // subcategory
|
||||
reasampler::appVersion().c_str(), // plug-in version (channel: -beta render)
|
||||
reasampler::version::appVersion().c_str(), // plug-in version (channel: -beta render)
|
||||
kVstVersionString, // VST3 SDK version (fixed)
|
||||
reasampler::vst::ReaSamplerProcessor::createInstance)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// draw_kit — the LICE/SWELL shell half of the drawing kit. See draw_kit.h.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. SHELL layer: it is the only kit file that
|
||||
@@ -12,7 +11,7 @@
|
||||
#include "core/ui/bank_grid.h" // compressAmplitudeForDisplay — the shared dB display curve (pure)
|
||||
|
||||
// SWELL / LICE. On Windows use native Win32 (windows.h first); on mac/linux SWELL is
|
||||
// provided by the host. Mirrors bank_panel.cpp's include discipline.
|
||||
// provided by the host. Mirrors the panel TUs' (shell/panel/) include discipline.
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#else
|
||||
@@ -24,6 +23,15 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the namespaces.h shim is retired).
|
||||
using audio::ChannelEnvelope;
|
||||
using audio::columnMinMax;
|
||||
using audio::MinMax;
|
||||
using ui::compressAmplitudeForDisplay;
|
||||
using ui::roleColor;
|
||||
using ui::roleColorState;
|
||||
using ui::spectralColor;
|
||||
|
||||
// --- KitColor <-> LICE boundary ----------------------------------------------
|
||||
|
||||
// The one place a pure KitColor becomes a LICE_pixel. Verified packing: LICE_RGBA(r,g,b,a)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// draw_kit — the LICE-facing SHELL half of the shared drawing kit (Phase L, L1). This is
|
||||
// the ONE source of drawing for the whole system: every surface (bank_panel now; the VST
|
||||
// editor + embed strip at L3) fills, buttons, rows, sliders, waveforms, and — above all —
|
||||
@@ -41,6 +40,19 @@ class LICE_IBitmap;
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the interim core/namespaces.h shim
|
||||
// is retired; the kit's pure vocabulary names its Q-W1 homes explicitly). These are
|
||||
// deliberate re-exports: every draw_kit consumer speaks these types at the call
|
||||
// boundary, so they surface here exactly as panel_state.h surfaces the panel's.
|
||||
using audio::Envelope;
|
||||
using ui::InteractionState;
|
||||
using ui::KitBox;
|
||||
using ui::KitButtonBox;
|
||||
using ui::KitColor;
|
||||
using ui::ListRowBox;
|
||||
using ui::Role;
|
||||
using ui::SliderGeometry;
|
||||
|
||||
// The kit's four cached fonts (§3.1 type scale). Consumers pass a Font to text() to pick
|
||||
// the size/weight; the kit maps it to the matching LICE_CachedFont.
|
||||
enum class Font {
|
||||
|
||||
@@ -1,17 +1,10 @@
|
||||
// panel_bank_ops.cpp — the bank-CRUD + menus seam of the docked bank panel (Q-W2
|
||||
// split of bank_panel.cpp; Phase B4/B5). Since Q-W4 this TU is the ONE implementation
|
||||
// home of the bank verbs (create / rename / delete / evacuate / activate / move /
|
||||
// copy / remove): the promptless bankOp* inner verbs (model op + persistBankOp only)
|
||||
// serve BOTH thin UX skins — the panel's menu handlers here and the bindable
|
||||
// bank_actions family — plus the book/bank accessors, the popup menus that drive
|
||||
// them, and the selection-id / OS-drag path resolvers.
|
||||
//
|
||||
// Each verb mutates the session's book() then persists via persistBankOp() (one bank
|
||||
// op = one Ctrl-Z; a true index no-op opens NO undo point). It DOES mutate the bank
|
||||
// BOOK — that is the whole point of B4 — but only the index/model + ext-state, never
|
||||
// the arrange, never a sample file on disk (bank ops are index-only; files stay put —
|
||||
// CONTEXT.md §Multi-bank). REFERENCE-INVALIDATION GUARDRAIL: after a STRUCTURAL
|
||||
// mutation any Bank*/BankModel& is invalid — resolve fresh, pass ids.
|
||||
// panel_bank_ops.cpp — the bank-CRUD-UX + menus seam of the docked bank panel
|
||||
// (Q-W2 split of the former bank_panel god-module; Phase B4/B5). Since Q-W6 the
|
||||
// promptless bank verbs live in shell/bank_ops (model op + persistBankOp, taking
|
||||
// ReaSamplerSession&); this TU is the panel's THIN UX SKIN over them — the menu
|
||||
// handlers (prompts / confirms / message boxes / panel-state nudges / repaint),
|
||||
// the book/bank accessors, the popup menus that drive them, and the selection-id /
|
||||
// OS-drag path resolvers. The bindable bank_actions family is the sibling skin.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
// WITHOUT REAPERAPI_IMPLEMENT — main.cpp owns the API pointers; here they are
|
||||
@@ -25,24 +18,21 @@
|
||||
#include "shell/panel/panel_state.h"
|
||||
#include "shell/panel/panel_bank_ops.h"
|
||||
|
||||
#include "persist.h" // ReaSamplerSession — the live session the ops mutate
|
||||
#include "shell/bank_ops/bank_ops.h" // bankOp* promptless verbs (the Q-W6 non-UI seam)
|
||||
#include "shell/persist/session.h" // ReaSamplerSession — the live session the ops mutate
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_EnumProjects
|
||||
#define REAPERAPI_WANT_GetUserInputs
|
||||
#define REAPERAPI_WANT_ShowMessageBox
|
||||
#define REAPERAPI_WANT_Main_OnCommand
|
||||
#define REAPERAPI_WANT_genGuid
|
||||
#define REAPERAPI_WANT_guidToString
|
||||
#define REAPERAPI_WANT_Undo_BeginBlock2
|
||||
#define REAPERAPI_WANT_Undo_EndBlock2
|
||||
#include "reaper_plugin_functions.h"
|
||||
|
||||
namespace reasampler::panel {
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// --- Current-project directory (mirrors persist.cpp's derivation) -------------
|
||||
// --- Current-project directory (mirrors the persist shell's derivation, ext_state_io.cpp)
|
||||
std::string currentProjectDir() {
|
||||
std::vector<char> buf(4096, '\0');
|
||||
EnumProjects(-1, buf.data(), static_cast<int>(buf.size()));
|
||||
@@ -84,19 +74,21 @@ std::vector<const Bank*> namedBanks() {
|
||||
|
||||
// --- Bank management ops (id-keyed; THIN UX SKINS over the bankOp* verbs) ------
|
||||
//
|
||||
// Q-W4: each handler here owns only the panel's UX (prompts / confirms / message
|
||||
// boxes / panel-state nudges / repaint); the model op + persist is the shared
|
||||
// bankOp* inner verb (defined in the public section below). After a STRUCTURAL
|
||||
// mutation (create/delete/evacuate) any Bank*/BankModel& is invalid — we resolve
|
||||
// fresh, pass ids, and let the next refreshFingerprint repaint. On an unsaved
|
||||
// project the empty-close discard in persistBankOp ensures no stale state
|
||||
// survives (matches the capture/B3 quiet-persist idiom).
|
||||
// Q-W4/Q-W6: each handler here owns only the panel's UX (prompts / confirms /
|
||||
// message boxes / panel-state nudges / repaint); the model op + persist is the
|
||||
// shared bankOp* inner verb (shell/bank_ops), which takes the live session by
|
||||
// reference — the book() check answers the one session-liveness question per
|
||||
// handler. After a STRUCTURAL mutation (create/delete/evacuate) any
|
||||
// Bank*/BankModel& is invalid — we resolve fresh, pass ids, and let the next
|
||||
// refreshFingerprint repaint. On an unsaved project the empty-close discard in
|
||||
// persistBankOp ensures no stale state survives (matches the capture/B3
|
||||
// quiet-persist idiom).
|
||||
|
||||
void doCreateBank() {
|
||||
if (!book()) return;
|
||||
std::string name;
|
||||
if (!promptBankName("ReaSampler: create bank", "Bank name:", "", name)) return;
|
||||
const std::string id = bankOpCreate(name);
|
||||
const std::string id = bankOpCreate(*g_panel.session, name);
|
||||
if (id.empty()) {
|
||||
ShowMessageBox("A bank with that name already exists.",
|
||||
"ReaSampler: create bank", 0);
|
||||
@@ -116,7 +108,7 @@ void doRenameBank(const std::string& bankId) {
|
||||
const std::string current = bk->displayName; // copy before any mutation
|
||||
std::string newName;
|
||||
if (!promptBankName("ReaSampler: rename bank", "New name:", current, newName)) return;
|
||||
if (!bankOpRename(bankId, newName)) {
|
||||
if (!bankOpRename(*g_panel.session, bankId, newName)) {
|
||||
ShowMessageBox("Another bank already uses that name.",
|
||||
"ReaSampler: rename bank", 0);
|
||||
return;
|
||||
@@ -156,7 +148,7 @@ void doDeleteBank(const std::string& bankId) {
|
||||
// delete path moved/dropped members) — both change what a live instance could play. An
|
||||
// empty-bank delete is purely organizational, no bump. The ORIGINAL member count decides
|
||||
// (the No-path evacuated them moments ago, but the membership still changed).
|
||||
if (!bankOpDelete(bankId, /*bumpGeneration=*/members > 0)) return;
|
||||
if (!bankOpDelete(*g_panel.session, bankId, /*bumpGeneration=*/members > 0)) return;
|
||||
// shownBankId is reconciled by the next fingerprint pass. If no named banks remain,
|
||||
// nudge focus to the pool so the selection has a valid home.
|
||||
if (namedBanks().empty()) g_panel.focusedRegion = Region::Pool;
|
||||
@@ -167,12 +159,13 @@ void doEvacuateBank(const std::string& bankId) {
|
||||
if (!book()) return;
|
||||
const Bank* bk = book()->bank(bankId);
|
||||
if (!bk || bk->isPool()) return;
|
||||
if (!bankOpEvacuate(bankId)) return;
|
||||
if (!bankOpEvacuate(*g_panel.session, bankId)) return;
|
||||
invalidatePanel();
|
||||
}
|
||||
|
||||
void doActivateBank(const std::string& bankId) {
|
||||
if (!bankOpActivate(bankId)) return; // rejects an unknown id
|
||||
if (!book()) return; // no live session — nothing to activate against
|
||||
if (!bankOpActivate(*g_panel.session, bankId)) return; // rejects an unknown id
|
||||
invalidatePanel();
|
||||
}
|
||||
|
||||
@@ -185,7 +178,8 @@ void doActivateBank(const std::string& bankId) {
|
||||
void transferSamples(const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId, const std::string& destBankId,
|
||||
bool copy) {
|
||||
if (!bankOpTransfer(sampleIds, srcBankId, destBankId, copy))
|
||||
if (!book()) return; // no live session — nothing to transfer within
|
||||
if (!bankOpTransfer(*g_panel.session, sampleIds, srcBankId, destBankId, copy))
|
||||
return; // nothing changed — no persist, no undo point
|
||||
// The selection indexed into the source; after a move those indices are stale, so
|
||||
// clear it (the fingerprint pass will also clear, but do it now for immediacy).
|
||||
@@ -198,7 +192,8 @@ void transferSamples(const std::vector<std::string>& sampleIds,
|
||||
// one-Ctrl-Z contract. Clears the stale selection and repaints on an actual removal.
|
||||
void removeSamples(const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId) {
|
||||
if (!bankOpRemove(sampleIds, srcBankId))
|
||||
if (!book()) return; // no live session — nothing to remove from
|
||||
if (!bankOpRemove(*g_panel.session, sampleIds, srcBankId))
|
||||
return; // nothing changed — no persist, no undo point
|
||||
// The selection indexed into the source; after a remove those indices are stale, so
|
||||
// clear it (the fingerprint pass will also clear, but do it now for immediacy).
|
||||
@@ -410,35 +405,7 @@ void showSelectionMenu(int screenX, int screenY) {
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
namespace {
|
||||
|
||||
// Persists the book after a bank mutation. Mirrors the CAPTURE path, NOT the
|
||||
// Design-View path: quiet persist — saveToActiveProject no-ops on an unsaved project
|
||||
// (the change stays valid for the session and persists on the user's next save).
|
||||
// Deliberately NO Save-As prompt; do not "align" with persistViewState's prompt
|
||||
// idiom. Returns whether a persist actually happened, so persistBankOp can discard
|
||||
// its undo block when nothing was written. Guards a null session pointer (false,
|
||||
// no-op) — see persistBankOp's guard below for why this is defensive rather than
|
||||
// dead code.
|
||||
bool persistBook() {
|
||||
if (!panel::g_panel.session) return false; // no live session: nothing to persist
|
||||
return panel::g_panel.session->saveToActiveProject();
|
||||
}
|
||||
|
||||
// Mints a fresh, genuine REAPER GUID string as a stable bank id (the B2/model
|
||||
// design: ids are caller-supplied and stable; the model stays pure and mints none).
|
||||
// Distinct from a track GUID by origin only — both are canonical guidToString output.
|
||||
std::string mintBankId() {
|
||||
GUID g{};
|
||||
genGuid(&g);
|
||||
char buf[64] = {0}; // guidToString needs >=64 chars (SDK contract)
|
||||
guidToString(&g, buf);
|
||||
return std::string(buf);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
// One home (Q-W4) for the former actions.cpp/panel_bank_ops.cpp byte-identical twins.
|
||||
// One home (Q-W4) for the former actions/panel byte-identical twins.
|
||||
// COMMA GUARD: GetUserInputs splits returned values on a separator defaulting to ',',
|
||||
// so the return separator is overridden to \x1f (un-typeable) via the documented
|
||||
// `separator=X` trailing pseudo-caption (SDK ~3806) — any printable name round-trips.
|
||||
@@ -457,147 +424,6 @@ bool promptBankName(const char* title, const char* caption, const std::string& i
|
||||
return true;
|
||||
}
|
||||
|
||||
// Persists a completed bank-index verb as a SINGLE batched REAPER undo point (R-B) —
|
||||
// one bank op = one Ctrl-Z.
|
||||
//
|
||||
// WHY THIS WRAPS AND persistBook() DOES NOT: a bank verb mutates ONLY our project
|
||||
// ext-state (SetProjExtState under "reasampler"), which REAPER's undo system captures
|
||||
// iff UNDO_STATE_MISCCFG is set in the Undo_EndBlock2 flags — the SDK documents
|
||||
// MISCCFG as covering "extensions!" project ext-state (reaper_plugin.h ~1544, ~1199).
|
||||
// We pass exactly UNDO_STATE_MISCCFG (not -1 / UNDO_STATE_ALL as the item-move family
|
||||
// does): a bank verb touches no tracks, FX, items, or envelopes, so snapshotting them
|
||||
// would be both heavier and semantically wrong. persistBook() (= SetProjExtState) runs
|
||||
// INSIDE the block so the post-mutation ext-state is the block's "after" image.
|
||||
//
|
||||
// UNSAVED-PROJECT GUARDRAIL: on an unsaved / no-active project persistBook() no-ops
|
||||
// (nothing is written to ext state). We must still CLOSE the block we opened, but with
|
||||
// an EMPTY label and a zero flag so REAPER DISCARDS the point instead of recording a
|
||||
// no-effect undo entry — mirroring view.cpp's empty-plan close. The in-session model
|
||||
// change stands and persists on the user's next save; it just earns no undo point until
|
||||
// there is a project to persist into (undo of an unsaved bank op has nothing to roll
|
||||
// back to anyway). The Begin/End must still be balanced, hence the close-either-way.
|
||||
//
|
||||
// NULL-SESSION GUARD: this is a public API (panel_bank_ops.h) with callers outside
|
||||
// this TU (e.g. panel_drag.cpp), not all of which are guaranteed to have re-checked
|
||||
// the session pointer immediately beforehand. Bail out BEFORE Undo_BeginBlock2 — no
|
||||
// block is opened, so there is nothing to balance and no risk of an unbalanced
|
||||
// Begin/End pair.
|
||||
void persistBankOp(const char* label, bool bumpGeneration) {
|
||||
if (!panel::g_panel.session) return; // no live session: no-op, no undo point opened
|
||||
Undo_BeginBlock2(nullptr);
|
||||
// S9: bump the bank-generation counter INSIDE the block, before persistBook(), so the
|
||||
// fresh generation rides the same ext-state write the persist makes (persistBook() ->
|
||||
// saveToActiveProject() stamps bankGeneration()). Bumped only for content-changing verbs
|
||||
// (the caller decides); a pure-organizational verb passes false and leaves the counter be,
|
||||
// so a rename/activate does not needlessly refresh live instances.
|
||||
if (bumpGeneration) panel::g_panel.session->bumpBankGeneration();
|
||||
const bool persisted = persistBook();
|
||||
if (persisted)
|
||||
Undo_EndBlock2(nullptr, label, UNDO_STATE_MISCCFG);
|
||||
else
|
||||
Undo_EndBlock2(nullptr, "", 0); // no ext-state write -> discard the empty point
|
||||
}
|
||||
|
||||
// --- Promptless inner bank verbs (Q-W4 single home) ----------------------------
|
||||
// Model op + persistBankOp only; NO UX. Callers own prompts/confirms/nudges. Each
|
||||
// verb resolves the book fresh (panel::book(), null when no live session) and
|
||||
// persists ONLY after the model accepted — a rejected op opens no undo point.
|
||||
|
||||
std::string bankOpCreate(const std::string& name) {
|
||||
BankBook* b = panel::book();
|
||||
if (!b) return {};
|
||||
const std::string id = mintBankId();
|
||||
if (!b->createBank(id, name)) return {}; // duplicate display name (model rule)
|
||||
persistBankOp("ReaSampler: create bank");
|
||||
return id;
|
||||
}
|
||||
|
||||
bool bankOpRename(const std::string& bankId, const std::string& newName) {
|
||||
BankBook* b = panel::book();
|
||||
if (!b || !b->renameBank(bankId, newName)) return false; // pool / name in use
|
||||
persistBankOp("ReaSampler: rename bank");
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bankOpDelete(const std::string& bankId, bool bumpGeneration) {
|
||||
BankBook* b = panel::book();
|
||||
if (!b || !b->deleteBank(bankId)) return false; // pool un-deletable (model rule)
|
||||
persistBankOp("ReaSampler: delete bank", bumpGeneration);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bankOpEvacuate(const std::string& bankId) {
|
||||
BankBook* b = panel::book();
|
||||
if (!b || !b->evacuate(bankId)) return false; // pool is a destination, not a source
|
||||
// S9: evacuate moves members between banks (bank membership changes) -> bump.
|
||||
persistBankOp("ReaSampler: evacuate bank", /*bumpGeneration=*/true);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bankOpActivate(const std::string& bankId) {
|
||||
BankBook* b = panel::book();
|
||||
if (!b || !b->setActiveBank(bankId)) return false; // rejects an unknown id
|
||||
persistBankOp("ReaSampler: activate bank");
|
||||
return true;
|
||||
}
|
||||
|
||||
// NO-OP GUARDRAIL — VERB-AWARE (a collapse means different things per verb):
|
||||
// * MOVE collapse: the source entry WAS removed (bank_book moveSample removes
|
||||
// unconditionally before the dest add collapses on hash), so the index DID
|
||||
// mutate — it counts toward opening an undo point.
|
||||
// * COPY collapse: the source is left intact AND the dest already held the hash,
|
||||
// so NOTHING changed — a true index no-op. It must NOT open an undo point.
|
||||
// Hence: copy counts only real gains; move counts gains OR collapses. Ids pass
|
||||
// straight to the model op — no BankModel& cached across the loop's mutations.
|
||||
bool bankOpTransfer(const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId, const std::string& destBankId,
|
||||
bool copy) {
|
||||
BankBook* b = panel::book();
|
||||
if (!b || sampleIds.empty() || srcBankId == destBankId) return false;
|
||||
if (!b->bank(srcBankId) || !b->bank(destBankId)) return false;
|
||||
int ok = 0, collapsed = 0;
|
||||
for (const std::string& sid : sampleIds) {
|
||||
const TransferResult r =
|
||||
copy ? b->copySample(sid, srcBankId, destBankId)
|
||||
: b->moveSample(sid, srcBankId, destBankId);
|
||||
switch (r) {
|
||||
case TransferResult::Moved:
|
||||
case TransferResult::Copied: ++ok; break;
|
||||
case TransferResult::Collapsed: ++collapsed; break;
|
||||
case TransferResult::RejectedUnknownBank:
|
||||
case TransferResult::RejectedSampleAbsent:
|
||||
case TransferResult::RejectedSameBank: break;
|
||||
}
|
||||
}
|
||||
const bool mutated = copy ? (ok > 0) : (ok > 0 || collapsed > 0);
|
||||
if (!mutated) return false; // nothing changed — no persist, no undo point
|
||||
// S9: a move/copy changes bank membership (a sample arrives in / leaves a bank an
|
||||
// instance may reference) -> bump so assigned instances refresh hands-free.
|
||||
persistBankOp(copy ? "ReaSampler: copy sample(s)" : "ReaSampler: move sample(s)",
|
||||
/*bumpGeneration=*/true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Index-only, this-bank scope (fork R-A: the sole surfaced verb; RemoveScope::AllBanks
|
||||
// stays latent in the model). Non-destructive to the file: a last-reference remove
|
||||
// leaves the file on disk, orphaned until Phase R prune — remove NEVER deletes bytes
|
||||
// (the manifest is untouched). Silent: recoverability is the batched undo (R-B).
|
||||
bool bankOpRemove(const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId) {
|
||||
BankBook* b = panel::book();
|
||||
if (!b || sampleIds.empty() || !b->bank(srcBankId)) return false;
|
||||
int removed = 0;
|
||||
for (const std::string& sid : sampleIds)
|
||||
if (b->removeSample(sid, srcBankId, RemoveScope::ThisBank) ==
|
||||
RemoveResult::Removed)
|
||||
++removed;
|
||||
if (removed == 0) return false; // every id already absent — no undo point
|
||||
// S9: a remove drops a sample from a bank (an instance referencing it must refresh —
|
||||
// it will resolve to silence, per the stale-id policy) -> bump.
|
||||
persistBankOp("ReaSampler: remove sample(s)", /*bumpGeneration=*/true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// --- Selection read seam --------------------------------------------------------
|
||||
|
||||
std::vector<std::string> bankPanelSelectedSampleIds() {
|
||||
|
||||
@@ -1,97 +1,31 @@
|
||||
#pragma once
|
||||
// panel_bank_ops — the bank-CRUD + selection-read seam of the bank panel (Q-W2 split
|
||||
// of bank_panel.h; Phase B4/B5). The .cpp is the SINGLE implementation home of the
|
||||
// bank verbs (create / rename / delete / evacuate / activate / move / copy / remove):
|
||||
// each promptless inner verb below drives the B1 BankBook model on the session and
|
||||
// persists via persistBankOp (one bank op = one Ctrl-Z). Q-W4 dedupe: the panel's
|
||||
// menu handlers and the bank_actions bindable family are both thin UX skins
|
||||
// (prompts / confirms / console vs. message boxes / panel-state nudges) over these
|
||||
// one-home verbs. This header carries that verb surface, the shared prompt/persist
|
||||
// helpers, and the panel's public selection-read surface.
|
||||
// panel_bank_ops — the bank-CRUD-UX + selection-read seam of the bank panel (Q-W2
|
||||
// split of the former bank_panel god-module; Phase B4/B5). Since Q-W6 the
|
||||
// promptless bank verbs themselves live in the NON-UI shell/bank_ops seam
|
||||
// (bankOp* + persistBankOp, taking ReaSamplerSession&); this TU is the panel's
|
||||
// thin UX skin over them — prompts / confirms / message boxes / panel-state
|
||||
// nudges / repaints — plus the popup menus that drive them. The bank_actions
|
||||
// bindable family is the sibling skin over the same verbs. This header carries
|
||||
// the shared prompt helper and the panel's public selection-read surface.
|
||||
//
|
||||
// The selection reads are REAPER-free; the verbs and helpers are REAPER-facing
|
||||
// (persist + stock dialogs) but SDK-free in this header.
|
||||
// The selection reads are REAPER-free; the prompt helper is REAPER-facing (stock
|
||||
// dialogs) but SDK-free in this header.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// --- Promptless inner bank verbs (Q-W4 single home) --------------------------
|
||||
// Each verb: model op on the session's BankBook + persistBankOp (undo-batched
|
||||
// ext-state persist) — NO prompts, NO message boxes, NO panel-state nudges. The
|
||||
// caller owns all UX. Every verb returns whether the model accepted the mutation
|
||||
// (a rejected op persists nothing and opens no undo point). Verbs resolve the
|
||||
// session via the panel's live session pointer (set at load by bankPanelInit,
|
||||
// before any action can fire) and fail safe (false / "") when it is absent.
|
||||
|
||||
// Mints a stable GUID bank id, creates `name` in the book. Returns the new bank id,
|
||||
// or "" when the model rejects the name (duplicate, trimmed + case-insensitive).
|
||||
// Create is purely organizational — no generation bump.
|
||||
std::string bankOpCreate(const std::string& name);
|
||||
|
||||
// Renames `bankId`. False when the model rejects (pool un-renamable / name in use).
|
||||
bool bankOpRename(const std::string& bankId, const std::string& newName);
|
||||
|
||||
// Deletes `bankId`. False when the model rejects (pool un-deletable). The caller
|
||||
// passes `bumpGeneration` from the member count it read BEFORE any evacuate/delete
|
||||
// (an evacuate-then-delete flow must still bump on the ORIGINAL membership).
|
||||
bool bankOpDelete(const std::string& bankId, bool bumpGeneration);
|
||||
|
||||
// Evacuates `bankId`'s members to the pool. False when the model rejects (the pool
|
||||
// itself). Bumps the generation (membership changed).
|
||||
bool bankOpEvacuate(const std::string& bankId);
|
||||
|
||||
// Activates `bankId` as the capture target. False on an unknown id. No bump.
|
||||
bool bankOpActivate(const std::string& bankId);
|
||||
|
||||
// Moves (copy=false) or copies (copy=true) `sampleIds` from `srcBankId` to
|
||||
// `destBankId` (index-only; files never relocate). Returns whether the index
|
||||
// actually mutated — the verb-aware no-op guardrail: a COPY collapse changes
|
||||
// nothing (no undo point); a MOVE collapse did remove the source entry (counts).
|
||||
// Persists ONE undo point ("move/copy sample(s)") only when mutated.
|
||||
bool bankOpTransfer(const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId, const std::string& destBankId,
|
||||
bool copy);
|
||||
|
||||
// Removes `sampleIds` from `srcBankId` (index-only, this-bank scope; never deletes
|
||||
// bytes). Returns whether anything was removed; persists one undo point when so.
|
||||
bool bankOpRemove(const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId);
|
||||
|
||||
// --- Shared UX/persist helpers ------------------------------------------------
|
||||
|
||||
// Prompts the user for a single line of text via REAPER's stock input dialog
|
||||
// (GetUserInputs). `initial` pre-fills the field. Returns false (leaving `out`
|
||||
// untouched) on cancel or an empty entry. COMMA GUARD: the return separator is
|
||||
// overridden to \x1f (un-typeable) via the documented `separator=X` pseudo-caption,
|
||||
// so any printable name — commas included — round-trips whole (SDK ~3806/3808).
|
||||
// One home (Q-W4) for the former actions.cpp/panel_bank_ops.cpp twins.
|
||||
// One home (Q-W4) for the former actions/panel byte-identical twins; shared by the
|
||||
// panel menus and the bank_actions bindable family.
|
||||
bool promptBankName(const char* title, const char* caption, const std::string& initial,
|
||||
std::string& out);
|
||||
|
||||
// Persists a completed bank-index verb as a single REAPER undo point (R-B).
|
||||
// Wraps the session persist (SetProjExtState) in a Begin/End block with
|
||||
// UNDO_STATE_MISCCFG so the bank op is one Ctrl-Z. On an unsaved / no-active project
|
||||
// the persist no-ops and the block is closed with an empty label + zero flag (REAPER
|
||||
// discards it). Callers must invoke this ONLY after a successful/effective mutation —
|
||||
// rejected ops (duplicate name, un-deletable pool, etc.) must return before reaching
|
||||
// here so no empty undo point is ever opened for a no-op.
|
||||
//
|
||||
// NULL-SESSION GUARD: this is a public API with callers outside panel_bank_ops.cpp
|
||||
// (e.g. panel_drag.cpp). If the panel's session pointer is absent (no live session),
|
||||
// this is a no-op — no undo block is opened. Today every real caller only reaches
|
||||
// here via a prior session-backed check, so the guard is not yet reachable in
|
||||
// practice; it exists to make the function safe to call standalone.
|
||||
//
|
||||
// S9 bank-generation bump: pass `bumpGeneration = true` for a verb that changes what a
|
||||
// live instance would PLAY — move / copy / remove / evacuate / delete-with-members. Leave
|
||||
// it false (the default) for a PURELY ORGANIZATIONAL verb — create / rename / activate /
|
||||
// reorder. The bump (when requested) happens INSIDE the block, BEFORE the persist, so
|
||||
// the stamped counter rides the same ext-state write and undo captures the pre/post
|
||||
// generation with the rest of the blob.
|
||||
void persistBankOp(const char* label, bool bumpGeneration = false);
|
||||
|
||||
// The stable ids of the currently-selected samples, in bank (insertion) order.
|
||||
// Empty when nothing is selected or the panel has never opened. This is the clean
|
||||
// seam the `insert` action reads to know WHAT to place — it returns ids (not grid
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "shell/panel/panel_state.h"
|
||||
|
||||
#include "shell/panel/panel_bank_ops.h" // persistBankOp — shared undo-block wrapper (R-B)
|
||||
#include "shell/bank_ops/bank_ops.h" // persistBankOp — shared undo-block wrapper (R-B)
|
||||
#include "shell/actions/drag_out_win.h" // OLE / SWELL drag-out initiation seam (M11)
|
||||
#include "shell/actions/instrument_drop_win.h" // resolveFxDropTarget / performInstrumentDrop (S17)
|
||||
|
||||
@@ -374,7 +374,7 @@ namespace {
|
||||
void doReorderDrop(const std::string& id, const std::string& bankId, int targetSlot) {
|
||||
if (!book() || id.empty() || bankId.empty() || targetSlot < 0) return;
|
||||
if (!book()->reorderSample(id, bankId, targetSlot)) return; // rejected/no-op: no undo point
|
||||
persistBankOp("ReaSampler: reorder sample");
|
||||
persistBankOp(*g_panel.session, "ReaSampler: reorder sample");
|
||||
g_panel.selection = Selection{};
|
||||
invalidatePanel();
|
||||
}
|
||||
@@ -387,7 +387,7 @@ void doReplaceDrop(const std::string& newId, const std::string& oldId,
|
||||
const std::string& bankId) {
|
||||
if (!book() || newId.empty() || oldId.empty() || bankId.empty()) return;
|
||||
if (!book()->replaceSample(newId, oldId, bankId)) return; // pool-guard reject: NO-OP
|
||||
persistBankOp("ReaSampler: replace sample");
|
||||
persistBankOp(*g_panel.session, "ReaSampler: replace sample");
|
||||
g_panel.selection = Selection{};
|
||||
invalidatePanel();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "shell/panel/panel_input.h"
|
||||
|
||||
#include "shell/actions/bank_actions.h" // bankPruneCommandId — the footer Prune dispatch (R3)
|
||||
#include "persist.h" // ReaSamplerSession — view/tail reads + mutation
|
||||
#include "shell/persist/session.h" // ReaSamplerSession — view/tail reads + mutation
|
||||
#include "core/view/view_mode_model.h" // autoTagNewContent / NewItem / AutoTag (D2 Wave 2)
|
||||
#include "shell/capture/item_read.h" // itemGuid / itemLaneName — shared item-read seam (D2 W3-B)
|
||||
#include "shell/capture/track_guid.h" // guidString — canonical track GUID key (D2 Wave 2)
|
||||
@@ -157,7 +157,8 @@ void enumerateLiveGuids(ReaProject* proj, std::set<std::string>& allGuids,
|
||||
//
|
||||
// INTENTIONAL: membership mutation happens OUTSIDE any Undo block. Auto-tag is a
|
||||
// background metadata update (like setting a label), not a destructive project edit.
|
||||
// persist.cpp writes it on the next project save alongside the bank and view state, the
|
||||
// the persist shell (ext_state_io.cpp) writes it on the next project save alongside the
|
||||
// bank and view state, the
|
||||
// same way an action-driven tag is persisted. Wrapping this in an Undo block would flood
|
||||
// the REAPER undo history with a new entry for every timer tick that sees new content.
|
||||
// Returns true iff this tick tagged at least one new GUID into a mode — the signal the
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
#include "shell/panel/panel_state.h"
|
||||
#include "shell/panel/panel_layout.h"
|
||||
|
||||
#include "persist.h" // ReaSamplerSession — mode/view reads
|
||||
#include "shell/persist/session.h" // ReaSamplerSession — mode/view reads
|
||||
#include "core/view/view_mode_model.h" // ViewModeModel — modes()/activeModeId()
|
||||
|
||||
// Action-trigger buttons (M11): resolve each button's command id at runtime from the
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "shell/panel/panel_state.h"
|
||||
|
||||
#include "shell/panel/draw_kit.h" // kit text()/fillSurface/drawButton/drawWaveform (L1)
|
||||
#include "persist.h" // ReaSamplerSession — mode/view/tail reads
|
||||
#include "shell/persist/session.h" // ReaSamplerSession — mode/view/tail reads
|
||||
#include "core/view/view_mode_model.h" // ViewModeModel / Mode — the footer toggle's model
|
||||
|
||||
namespace reasampler::panel {
|
||||
|
||||
@@ -14,13 +14,9 @@
|
||||
// plain free function — direct call-through, no interface, no virtual dispatch
|
||||
// (T4-28: the audition path and the per-mouse-move path must stay direct calls).
|
||||
// * Explicit using-declarations pulling the pure modules' symbols into
|
||||
// reasampler::panel from their REAL namespace homes (Q-W1 sub-namespaces) — this
|
||||
// header itself does not directly include the interim core/namespaces.h shim
|
||||
// (Q-W2 retires that direct dependency for this module; Q-W4 retired the
|
||||
// actions.h carrier with the actions split). Several panel TUs still pull the
|
||||
// shim in TRANSITIVELY via persist.h/ingest.h/draw_kit.h/view.h; only
|
||||
// panel_thumbnails.cpp and panel_audition.cpp are shim-free end to end.
|
||||
// Nothing HERE depends on it either way.
|
||||
// reasampler::panel from their REAL namespace homes (Q-W1 sub-namespaces). The
|
||||
// interim core/namespaces.h shim is GONE (deleted in Q-W6 with the last split);
|
||||
// every symbol below names its true home.
|
||||
//
|
||||
// REFERENCE-INVALIDATION GUARDRAIL (CONTEXT.md §Multi-bank): a bank-structural
|
||||
// mutation (create/delete/evacuate/activate/move) can reallocate the book's vector,
|
||||
@@ -84,10 +80,10 @@ namespace reasampler::panel {
|
||||
// --- Real-namespace-home using-declarations -----------------------------------
|
||||
//
|
||||
// The panel's pre-split internals reference the pure modules' symbols unqualified;
|
||||
// these explicit per-symbol usings (NOT the core/namespaces.h shim) keep those
|
||||
// references valid while documenting each symbol's Q-W1 home. Flat-`reasampler`
|
||||
// symbols (BankBook / ViewModeModel / the draw_kit shell / persistBankOp / ...)
|
||||
// resolve via the enclosing namespace and need no using.
|
||||
// these explicit per-symbol usings keep those references valid while documenting
|
||||
// each symbol's Q-W1 home. Flat-`reasampler` symbols (BankBook / ViewModeModel /
|
||||
// the draw_kit shell / the shell/bank_ops verbs / ...) resolve via the enclosing
|
||||
// namespace and need no using.
|
||||
|
||||
// core/ui
|
||||
using ui::ActionBarRect;
|
||||
|
||||
@@ -36,7 +36,7 @@
|
||||
|
||||
#include "core/capture/capture_paths.h" // projectDirOfRpp (pure path arithmetic)
|
||||
#include "core/instrument/map/bank_sync.h" // parseBankGeneration / formatBankGeneration (SHARED with the instrument reader)
|
||||
#include "core/instrument/map/bridge_marshal.h" // readProjExtStateGrowing (T2-04: the ONE grow-loop policy)
|
||||
#include "core/wire/ext_state_read.h" // readProjExtStateGrowing (T2-04: the ONE grow-loop policy)
|
||||
#include "core/version/app_version.h"
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
@@ -77,15 +77,15 @@ std::string projectDirOf(const std::string& rppPath) {
|
||||
|
||||
// GetProjExtState needs a caller-supplied buffer; the index JSON can be large
|
||||
// (many samples). The grow-until-strict-fit retry policy is the SHARED pure
|
||||
// instrument::map::readProjExtStateGrowing (Q-W5 rider T2-04 — the same policy the
|
||||
// usage_scan and VST-bridge reads run); this wrapper binds the REAPER call and
|
||||
// wire::readProjExtStateGrowing (T2-04 — the same policy the usage_scan and
|
||||
// VST-bridge reads run); this wrapper binds the REAPER call and
|
||||
// folds the terminal cases persist's callers expect: "" for an absent key (a valid
|
||||
// empty bank, not an error) and a console warning + "" for a value exceeding the
|
||||
// 16 MB ceiling, so an over-large value reads as "too large to load", not silent
|
||||
// data loss (mirrors the malformed-JSON warning in loadFromProject).
|
||||
std::string getProjExtStateString(void* proj, const char* ns, const char* key) {
|
||||
using instrument::map::GrowingExtStateRead;
|
||||
const GrowingExtStateRead read = instrument::map::readProjExtStateGrowing(
|
||||
using wire::GrowingExtStateRead;
|
||||
const GrowingExtStateRead read = wire::readProjExtStateGrowing(
|
||||
[&](char* buf, int cap) {
|
||||
return GetProjExtState(static_cast<ReaProject*>(proj), ns, key, buf, cap);
|
||||
});
|
||||
|
||||
@@ -29,8 +29,8 @@ std::string projectDirOf(const std::string& rppPath);
|
||||
// Growing GetProjExtState read for `key` in namespace `ns` against `proj`. Returns
|
||||
// "" when the key is absent (a valid empty bank, not an error) and warns on the
|
||||
// console for a value exceeding the 16 MB read ceiling (unreadable whole, ignored).
|
||||
// The retry policy itself is the shared pure instrument::map::readProjExtStateGrowing
|
||||
// (Q-W5 rider, T2-04); this wrapper binds the REAPER call + persist's fold.
|
||||
// The retry policy itself is the shared pure wire::readProjExtStateGrowing
|
||||
// (T2-04; rehomed to core/wire in Q-W6); this wrapper binds the REAPER call + persist's fold.
|
||||
std::string getProjExtStateString(void* proj, const char* ns, const char* key);
|
||||
|
||||
// The GUID we mint per project, formatted "{XXXXXXXX-....}" by guidToString.
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// usage_scan.cpp — see usage_scan.h. The REAPER reads behind the pS-usage prune
|
||||
// protection; every decision is in the pure sample_usage module, this TU only reads.
|
||||
//
|
||||
@@ -27,7 +26,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include "core/version/app_version.h" // vstPluginName / vstOutputName (channel name needles)
|
||||
#include "core/instrument/map/bridge_marshal.h" // readProjExtStateGrowing (T2-04: the ONE grow-loop policy)
|
||||
#include "core/wire/ext_state_read.h" // readProjExtStateGrowing (T2-04: the ONE grow-loop policy)
|
||||
#include "ext_keys.h" // kProjExtNamespace / kProjExtUsageKeyPrefix
|
||||
#include "core/wire/instrument_drop.h" // vstClassIdHex — the frozen channel class-UID hex
|
||||
#include "core/wire/sample_usage.h" // identityMatches, foldUsageRecords (the pure decisions)
|
||||
@@ -53,6 +52,14 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Real-namespace-home using-directive (Q-W6: the namespaces.h shim is retired):
|
||||
// this TU speaks the sample_usage wire vocabulary wholesale (UsageRecord /
|
||||
// decodeUsageRecord / foldUsageRecords / identityMatches / toUpperAscii) plus the
|
||||
// channel-identity accessors + the preset class-id hex.
|
||||
using namespace reasampler::wire;
|
||||
using version::vstOutputName;
|
||||
using version::vstPluginName;
|
||||
|
||||
namespace {
|
||||
|
||||
// The three UPPERCASED channel needles identityMatches (pure, sample_usage) checks
|
||||
@@ -169,16 +176,15 @@ bool itemHasInstance(MediaItem* item, const FxIdentityNeedles& id) {
|
||||
|
||||
// Growing GetProjExtState read: the usage record scales with the hold count, so a
|
||||
// fixed buffer risks a truncated decode. The retry policy is the SHARED pure
|
||||
// instrument::map::readProjExtStateGrowing (Q-W5 rider T2-04 — one loop for persist,
|
||||
// this prune-safety-adjacent read, and the VST bridge; the rules cannot drift).
|
||||
// wire::readProjExtStateGrowing (T2-04 — one loop for persist, this
|
||||
// prune-safety-adjacent read, and the VST bridge; the rules cannot drift).
|
||||
// Returns nullopt when the key cannot be read WHOLE — absent-after-enumeration
|
||||
// (rv <= 0) or pathologically large (> 16 MB give-up). The caller only queries keys
|
||||
// the enumeration just listed, so a nullopt here is a PRESENT-BUT-UNREADABLE record:
|
||||
// it folds to abortPrune (fail-safe — silently reduced protection is the delete
|
||||
// direction).
|
||||
std::optional<std::string> readExtStateValue(ReaProject* proj, const char* key) {
|
||||
using instrument::map::GrowingExtStateRead;
|
||||
const GrowingExtStateRead read = instrument::map::readProjExtStateGrowing(
|
||||
const GrowingExtStateRead read = readProjExtStateGrowing(
|
||||
[&](char* buf, int cap) {
|
||||
return GetProjExtState(proj, kProjExtNamespace(), key, buf, cap);
|
||||
});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// usage_scan — the EXTENSION-side shell of the pS-usage seam (see sample_usage.h for
|
||||
// the pure core, the fail-safe folds, and the full design note). At prune-scan time it
|
||||
// answers ONE question: which project-relative bank paths are held by a LIVE ReaSampler
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
#include "core/namespaces.h"
|
||||
// view.cpp — REAPER-facing Design View shell (Phase D2). See view.h.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
@@ -48,6 +47,13 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Real-namespace-home using-declarations (Q-W6: the namespaces.h shim is retired).
|
||||
using view::buildFolderTree;
|
||||
using view::isOnManualLane;
|
||||
using view::managedLaneKey;
|
||||
using view::modeIdFromLaneName;
|
||||
using view::TrackFolderEntry;
|
||||
|
||||
namespace {
|
||||
|
||||
// Track fixed-lane mode value (I_FREEMODE=2). See SDK: 0=normal, 1=free item
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "core/namespaces.h"
|
||||
// view — the REAPER-facing shell of the Design View feature (Phase D2). It is the
|
||||
// mirror of the capture shell: the ViewModeModel (pure, D1) holds the mode/
|
||||
// membership/snapshot state and emits the toggle plan; this shell reads the live
|
||||
|
||||
Reference in New Issue
Block a user