Cut shell/actions, bank_ops, app comment bloat ~48% (comments only, zero code change)
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
// 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.
|
||||
// action_registry.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.
|
||||
|
||||
#include "shell/actions/action_registry.h"
|
||||
|
||||
@@ -17,16 +16,12 @@ namespace {
|
||||
using version::channelActionName;
|
||||
using version::channelCommandId;
|
||||
|
||||
// Durable store of composed, channel-qualified strings (ids + labels). A std::deque
|
||||
// never invalidates references on push_back, so a c_str() handed to REAPER (a
|
||||
// command_id at register, a gaccel desc for its lifetime) stays valid until process
|
||||
// exit. Memoized by suffix so register and the mirror-unregister get the SAME id
|
||||
// pointer for a given action.
|
||||
// std::deque never invalidates references on push_back, so a c_str() handed to
|
||||
// REAPER stays valid until process exit. Memoized by suffix so register and
|
||||
// mirror-unregister get the SAME id pointer.
|
||||
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
|
||||
// std::deque so element addresses never move after push_back — REAPER keeps each
|
||||
// &accel until the mirror-unregister.
|
||||
struct TableEntry {
|
||||
ActionTableRow row;
|
||||
|
||||
@@ -1,28 +1,10 @@
|
||||
#pragma once
|
||||
// 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 and main.cpp include this header.
|
||||
// action_registry — shared REAPER registration plumbing, plus a data-driven action
|
||||
// table (ActionTableRow) so adding an action means adding one row, not touching
|
||||
// register/dispatch/unregister separately (OCP). Interned command-id/label strings
|
||||
// persist for the module lifetime: REAPER holds those pointers, and an unregister
|
||||
// must re-present the SAME one. Handlers are flat function pointers, never
|
||||
// std::function/virtual (hot-path-adjacent dispatch discipline).
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
@@ -30,27 +12,19 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Returns the channel-qualified command id for `suffix`, interning it once for the
|
||||
// process lifetime. Called by BOTH registerAction and each family's unregister path,
|
||||
// so a '-command_id' presents the IDENTICAL string pointer registered earlier.
|
||||
// Interns the channel-qualified command id for `suffix` once per process, so a
|
||||
// '-command_id' unregister presents the IDENTICAL pointer registered earlier.
|
||||
const char* channelIdFor(const char* suffix);
|
||||
|
||||
// Mints a command id from a channel-qualified SUFFIX and registers its gaccel
|
||||
// (Actions-list entry with a channel-qualified label PHRASE). Returns the command id
|
||||
// (0 on failure). Both the composed id and label are interned durably — REAPER holds
|
||||
// the desc pointer, and the id must survive to the mirror-unregister. The gaccel
|
||||
// storage itself is caller-owned (file-scope in the family TU).
|
||||
// Mints a command id from `suffix`, registers its gaccel with label `phrase`.
|
||||
// Returns the id (0 on failure); gaccel storage is caller-owned.
|
||||
int registerAction(reaper_plugin_info_t* rec, const char* suffix,
|
||||
gaccel_register_t& accel, const char* phrase);
|
||||
|
||||
// --- The registration table (Q-W6) -------------------------------------------
|
||||
// --- The registration table ---------------------------------------------------
|
||||
|
||||
// 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.
|
||||
// `suffix`/`phrase` are channel-agnostic and must have static storage duration.
|
||||
// `arg` is an opaque per-row value so sibling actions can share one handler.
|
||||
struct ActionTableRow {
|
||||
const char* suffix; // FOREVER-STABLE command-id suffix — never change shipped
|
||||
const char* phrase; // Actions-list display phrase (after the channel prefix)
|
||||
@@ -58,26 +32,19 @@ struct ActionTableRow {
|
||||
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).
|
||||
// Rows are copied into registry-owned storage whose addresses never move (REAPER
|
||||
// holds each gaccel pointer until unload).
|
||||
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.
|
||||
// 0 when unregistered / mint failed — for callers needing a raw id outside dispatch
|
||||
// (e.g. the toggleaction checked-state hook).
|
||||
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.
|
||||
// Mirror-unregisters every table row (reverse order): '-gaccel' with the held
|
||||
// storage, '-command_id' with the SAME interned pointer used at register.
|
||||
void unregisterActionTable(reaper_plugin_info_t* rec);
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
// bank_actions.cpp — the multi-bank bindable action family (Phase B3; Q-W4 split of
|
||||
// actions.cpp). See bank_actions.h.
|
||||
// bank_actions.cpp — see bank_actions.h.
|
||||
//
|
||||
// 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.
|
||||
// Each mutating handler is a thin UX skin — text prompts, name resolution, console
|
||||
// feedback — over the promptless bankOp* verbs in shell/bank_ops (model op +
|
||||
// persistBankOp, one bank op = one Ctrl-Z). Pool privileges / collapse-by-hash /
|
||||
// active-fallback-to-pool live in bank_book; handlers only drive the verbs.
|
||||
//
|
||||
// REFERENCE-INVALIDATION GUARDRAIL (B2 review): book().activeIndex() / bank()->index
|
||||
// return a reference INTO the book's internal vector, which a create/delete can
|
||||
// reallocate. No handler here caches a BankModel& (or a Bank*) across a structural
|
||||
// mutation — each resolves ids to strings up front and re-resolves after any
|
||||
// create/delete. Move/copy pass ids (not references) straight to the verbs.
|
||||
// REFERENCE-INVALIDATION GUARDRAIL: book().activeIndex() / bank()->index return a
|
||||
// reference INTO the book's internal vector, which a create/delete can reallocate.
|
||||
// No handler caches a BankModel&/Bank* across a structural mutation — ids are
|
||||
// resolved to strings up front and re-resolved after any create/delete.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
// WITHOUT REAPERAPI_IMPLEMENT — main.cpp owns the API pointers (CLAUDE.md §contract).
|
||||
// The action ids are minted from FOREVER-STABLE strings; user keybindings key off
|
||||
// them, so they must never change after ship.
|
||||
// main.cpp owns the API pointers; this TU gets them extern. Action ids are minted
|
||||
// from FOREVER-STABLE strings — never change one after ship.
|
||||
|
||||
#include "shell/actions/bank_actions.h"
|
||||
|
||||
@@ -42,11 +36,9 @@ namespace reasampler {
|
||||
|
||||
namespace {
|
||||
|
||||
// FOREVER-STABLE multi-bank action-id SUFFIXES (Phase V, V4). The channel family prefix is
|
||||
// prepended at register via channelCommandId (as with the Design View family) — stable
|
||||
// rebuilds the shipped id, beta the isolated one. NEVER change a shipped suffix.
|
||||
// Each suffix + the stable prefix must byte-match the pre-V4 shipped literal exactly
|
||||
// (e.g. "BANK_REMOVE_SELECTED" -> "CEREBELLUM_REASAMPLER_BANK_REMOVE_SELECTED").
|
||||
// FOREVER-STABLE action-id SUFFIXES: the channel prefix is prepended at register
|
||||
// (channelCommandId); NEVER change a shipped suffix — user keybindings key off the
|
||||
// composed id.
|
||||
constexpr const char* kIdBankCreate = "BANK_CREATE";
|
||||
constexpr const char* kIdBankRename = "BANK_RENAME";
|
||||
constexpr const char* kIdBankDelete = "BANK_DELETE";
|
||||
@@ -58,14 +50,10 @@ constexpr const char* kIdBankCopySel = "BANK_COPY_SELECTED";
|
||||
constexpr const char* kIdBankRemoveSel = "BANK_REMOVE_SELECTED";
|
||||
constexpr const char* kIdBankPoolFull = "BANK_POOL_FULLHEIGHT";
|
||||
constexpr const char* kIdBankBanksFull = "BANK_BANKS_FULLHEIGHT";
|
||||
// Phase R (Reclaim), R2: the FOREVER-STABLE "Prune bank folder" id. Registered NOW so
|
||||
// in-DAW dry-run verification is possible; R2 behaviour is REPORT-ONLY (no deletion),
|
||||
// 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) and
|
||||
// pass to the bankOp* verbs by reference (bankHandleCommand guards it non-null
|
||||
// before any handler runs). Set once by bankRegisterActions; not owned here.
|
||||
// Not owned here; set once by bankRegisterActions. bankHandleCommand guards it
|
||||
// non-null before any handler runs.
|
||||
ReaSamplerSession* g_session = nullptr;
|
||||
|
||||
int g_cmdBankCreate = 0;
|
||||
@@ -96,25 +84,17 @@ gaccel_register_t g_accelBankPoolFull{};
|
||||
gaccel_register_t g_accelBankBanksFull{};
|
||||
gaccel_register_t g_accelBankPruneFolder{};
|
||||
|
||||
// Resolves a user-typed bank reference (a display name) to a bank id, scanning the
|
||||
// book's banks in ordinal order. Exact match on displayName; "Pool" resolves the pool.
|
||||
// Returns "" when no bank carries that name. Kept in the action layer (not the model)
|
||||
// — it is UI name-resolution, not a model rule. First-match is unambiguous BY
|
||||
// CONSTRUCTION: the model enforces unique display names (trimmed + case-insensitive),
|
||||
// so at most one bank can carry a given name — no duplicate can shadow another here.
|
||||
// Resolves a user-typed display name to a bank id ("" if none matches). UI name
|
||||
// resolution, not a model rule — kept here rather than the model. Unambiguous by
|
||||
// construction: the model enforces unique display names.
|
||||
std::string bankIdByDisplayName(const std::string& name) {
|
||||
for (const Bank& b : g_session->book().banks())
|
||||
if (b.displayName == name) return b.id;
|
||||
return {};
|
||||
}
|
||||
|
||||
// -- Action bodies (thin UX skins over the bankOp* verbs) -------------------
|
||||
|
||||
// Create a named bank: prompt for a display name; the verb mints a stable GUID id,
|
||||
// creates it in the model, persists. The new bank is NOT auto-activated (create and
|
||||
// activate are distinct acts — mirrors capture/placement separation). The model
|
||||
// rejects a duplicate display name (trimmed + case-insensitive, incl. "Pool"); the
|
||||
// create then fails and the user is told the name is taken.
|
||||
// The new bank is NOT auto-activated (create and activate are distinct acts,
|
||||
// mirroring capture/placement separation).
|
||||
void doBankCreate() {
|
||||
std::string name;
|
||||
if (!promptBankName("ReaSampler: create bank", "Bank name:", "", name)) return;
|
||||
@@ -126,9 +106,8 @@ void doBankCreate() {
|
||||
}
|
||||
}
|
||||
|
||||
// Rename a bank: prompt for which bank (by current display name) and the new name.
|
||||
// The pool is un-renamable (the model rejects it). Two prompts keep the bindable form
|
||||
// self-contained; the panel renames in place on a tab.
|
||||
// Two prompts (which bank, then the new name) keep this bindable form
|
||||
// self-contained; the panel renames in place on a tab instead.
|
||||
void doBankRename() {
|
||||
std::string which;
|
||||
if (!promptBankName("ReaSampler: rename bank", "Bank to rename (current name):", "",
|
||||
@@ -142,18 +121,13 @@ void doBankRename() {
|
||||
std::string newName;
|
||||
if (!promptBankName("ReaSampler: rename bank", "New name:", which, newName)) return;
|
||||
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, "
|
||||
"or another bank already uses that name).\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Delete a named bank. Bindable safe-form of the confirm-on-non-empty guardrail:
|
||||
// prompt for the bank; if it holds members, a YESNO ShowMessageBox names evacuate as
|
||||
// the alternative before dropping them (a plain delete orphans those members' files
|
||||
// until prune — CONTEXT.md §delete). An empty bank deletes with no prompt. The richer
|
||||
// panel confirm (naming evacuate inline, with a one-click evacuate) lives in the panel.
|
||||
// If the bank holds members, confirm first (a plain delete orphans those members'
|
||||
// files until prune); an empty bank deletes with no prompt.
|
||||
void doBankDelete() {
|
||||
std::string which;
|
||||
if (!promptBankName("ReaSampler: delete bank", "Bank to delete:", "", which)) return;
|
||||
@@ -162,15 +136,13 @@ void doBankDelete() {
|
||||
ShowConsoleMsg(("ReaSampler: no bank named \"" + which + "\".\n").c_str());
|
||||
return;
|
||||
}
|
||||
// Pool early-out: the pool is un-deletable (the model rejects it). Catch it here,
|
||||
// BEFORE the non-empty confirm, so typing "Pool" never shows a misleading
|
||||
// "delete anyway?" prompt for an operation the model will refuse regardless.
|
||||
// Catch the pool BEFORE the non-empty confirm, so typing "Pool" never shows a
|
||||
// misleading "delete anyway?" for an operation the model will refuse regardless.
|
||||
if (id == kPoolBankId) {
|
||||
ShowConsoleMsg("ReaSampler: the pool cannot be deleted.\n");
|
||||
return;
|
||||
}
|
||||
// Read member count BEFORE deleting (the Bank* is invalidated by the delete; we do
|
||||
// not cache it — resolve size to an int up front).
|
||||
// Read member count before deleting — the Bank* is invalidated by the delete.
|
||||
const Bank* b = g_session->book().bank(id);
|
||||
if (!b) return; // race-safe: id resolved above but re-check
|
||||
const std::size_t members = b->index.size();
|
||||
@@ -184,16 +156,14 @@ void doBankDelete() {
|
||||
const int r = ShowMessageBox(msg.c_str(), "ReaSampler: delete non-empty bank", 4);
|
||||
if (r != 6) return; // 6 == YES; anything else cancels (SDK ~6544)
|
||||
}
|
||||
// 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.
|
||||
// Bump only when the deleted bank held samples — dropping them changes what a
|
||||
// live instance referencing one could play.
|
||||
if (!bankOpDelete(*g_session, id, /*bumpGeneration=*/members > 0)) {
|
||||
ShowConsoleMsg("ReaSampler: cannot delete that bank (the pool is un-deletable).\n");
|
||||
}
|
||||
}
|
||||
|
||||
// Evacuate a named bank: move every member back to the pool (index-only, collapse by
|
||||
// hash), leaving the bank empty. The pool is un-evacuable (the verb rejects it). The
|
||||
// intended "keep the samples" companion to delete.
|
||||
// The "keep the samples" companion to delete: moves every member back to the pool.
|
||||
void doBankEvacuate() {
|
||||
std::string which;
|
||||
if (!promptBankName("ReaSampler: evacuate bank", "Bank to evacuate to the pool:", "",
|
||||
@@ -210,10 +180,8 @@ void doBankEvacuate() {
|
||||
}
|
||||
}
|
||||
|
||||
// Cycle the active bank forward in ordinal order (pool -> named -> ... -> pool),
|
||||
// via the pure nextBankId helper. Activating a bank changes the CAPTURE TARGET (the
|
||||
// next capture lands in the newly-active bank — B2's book().activeIndex() seam) and
|
||||
// never touches the timeline. The verb persists so the active id travels with the .rpp.
|
||||
// Cycles the active bank (pool -> named -> ... -> pool). Activating changes the
|
||||
// CAPTURE TARGET only — never touches the timeline.
|
||||
void doBankActivateNext() {
|
||||
std::vector<std::string> ids;
|
||||
ids.reserve(g_session->book().size());
|
||||
@@ -223,20 +191,13 @@ void doBankActivateNext() {
|
||||
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(*g_session, kPoolBankId);
|
||||
}
|
||||
|
||||
// Move or copy the panel's selected samples into a named destination bank (prompted
|
||||
// by display name). The SOURCE is the bank the selection lives in — the focused
|
||||
// region's displayed bank (bankPanelSelectedSourceBankId), which under B4's vertical
|
||||
// split is NOT necessarily the active/capture-target bank (active ≠ shown). Both are
|
||||
// index-only (files never relocate); the verb owns the verb-aware no-op guardrail and
|
||||
// destination collapse-by-hash. The panel's "move to bank" menu drives the same verb
|
||||
// with a menu-chosen destination — this bindable form is the same operation with a
|
||||
// text-prompt destination.
|
||||
// SOURCE is the bank the selection lives in (bankPanelSelectedSourceBankId), which is
|
||||
// NOT necessarily the active/capture-target bank — the vertical split can show a
|
||||
// different bank than the one active for capture.
|
||||
void doBankTransferSelected(bool copy) {
|
||||
const std::vector<std::string> selected = bankPanelSelectedSampleIds();
|
||||
if (selected.empty()) {
|
||||
@@ -253,7 +214,6 @@ void doBankTransferSelected(bool copy) {
|
||||
ShowConsoleMsg(("ReaSampler: no bank named \"" + destName + "\".\n").c_str());
|
||||
return;
|
||||
}
|
||||
// Source = the bank the selection lives in (the focused region's displayed bank).
|
||||
const std::string srcId = bankPanelSelectedSourceBankId();
|
||||
if (srcId == destId) {
|
||||
ShowConsoleMsg("ReaSampler: source and destination are the same bank.\n");
|
||||
@@ -262,10 +222,8 @@ void doBankTransferSelected(bool copy) {
|
||||
bankOpTransfer(*g_session, selected, srcId, destId, copy);
|
||||
}
|
||||
|
||||
// Remove the panel's selected samples from the SOURCE bank (the focused region's
|
||||
// displayed bank — same source as move/copy). Index-only and non-destructive to the
|
||||
// file (orphaned until Phase R prune); silent, with the batched undo as recovery —
|
||||
// see bankOpRemove for the full contract.
|
||||
// Index-only and non-destructive to the file (orphaned until prune); silent, with
|
||||
// the batched undo as recovery.
|
||||
void doBankRemoveSelected() {
|
||||
const std::vector<std::string> selected = bankPanelSelectedSampleIds();
|
||||
if (selected.empty()) {
|
||||
@@ -307,8 +265,6 @@ void bankRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* session)
|
||||
"toggle pool full-height");
|
||||
g_cmdBankBanksFull = registerAction(rec, kIdBankBanksFull, g_accelBankBanksFull,
|
||||
"toggle banks full-height");
|
||||
// Phase R, R2: the "Prune bank folder" action (report-only in this wave; R3 extends
|
||||
// the confirm-and-delete step behind this SAME forever-stable id).
|
||||
g_cmdBankPruneFolder = registerAction(rec, kIdBankPruneFolder, g_accelBankPruneFolder,
|
||||
"prune bank folder");
|
||||
}
|
||||
@@ -335,8 +291,8 @@ bool bankHandleCommand(int command) {
|
||||
int bankPruneCommandId() { return g_cmdBankPruneFolder; }
|
||||
|
||||
void bankUnregisterActions(reaper_plugin_info_t* rec) {
|
||||
// Mirror-unregister with '-'-prefixed strings, reverse of registration order. Each
|
||||
// '-command_id' re-presents the same interned channel-qualified id (channelIdFor).
|
||||
// Reverse of registration order; each '-command_id' re-presents the same
|
||||
// interned id (channelIdFor).
|
||||
rec->Register("-gaccel", (void*)&g_accelBankPruneFolder);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankPruneFolder));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankBanksFull);
|
||||
|
||||
@@ -1,45 +1,29 @@
|
||||
#pragma once
|
||||
// bank_actions — the multi-bank bindable action family (Phase B3; Q-W4 split of
|
||||
// actions.h). The bindable action set that drives the multi-bank workflow: create /
|
||||
// rename / delete / evacuate a bank, activate a bank (direct pool + cycle), move /
|
||||
// copy / remove the panel's selected samples, the two vertical-split full-height
|
||||
// toggles, and the Phase R prune action's registration + dispatch (its guarded body
|
||||
// lives in prune_action). Q-W4 dedupe: every mutating handler here is a THIN UX skin
|
||||
// (text prompts + console messages) over the promptless bankOp* verbs homed in
|
||||
// panel_bank_ops — one implementation home for each mutation, two UX skins (this
|
||||
// family prompts for which bank; the panel acts on a clicked tab).
|
||||
// bank_actions — the multi-bank bindable action family: create/rename/delete/
|
||||
// evacuate a bank, activate (direct pool + cycle), move/copy/remove the panel's
|
||||
// selected samples, the two vertical-split full-height toggles, and the prune
|
||||
// action's registration + dispatch (guarded body in prune_action). Every mutating
|
||||
// handler is a thin UX skin over the promptless bankOp* verbs in bank_ops (this
|
||||
// family prompts for a bank name; the panel acts on a clicked tab).
|
||||
//
|
||||
// Same registration/routing/unload contract as the Design View family
|
||||
// (design_view_actions); both share main.cpp's single hookcommand, and each family's
|
||||
// Handle claims only its own ids. This header is SDK-free.
|
||||
// Same registration/routing/unload contract as design_view_actions. SDK-free header.
|
||||
|
||||
// Forward-declared at GLOBAL scope (matches reaper_plugin.h's typedef) so this
|
||||
// header stays SDK-free; the .cpp includes the real definition.
|
||||
struct reaper_plugin_info_t;
|
||||
struct reaper_plugin_info_t; // global scope, matches reaper_plugin.h's typedef
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
class ReaSamplerSession;
|
||||
|
||||
// Registers the multi-bank family against `rec`. `session` is the live session (must
|
||||
// outlive registration). Call exactly once at load — pass the SAME session pointer
|
||||
// the Design View family receives.
|
||||
// `session` must outlive registration — pass the SAME pointer the Design View
|
||||
// family receives.
|
||||
void bankRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* session);
|
||||
|
||||
// Services one fired command for the multi-bank family. True iff it was one of this
|
||||
// family's ids (and handled); false otherwise so the caller's hookcommand keeps
|
||||
// looking. Safe for any command.
|
||||
bool bankHandleCommand(int command);
|
||||
|
||||
// Mirror-unregisters the multi-bank family with '-'-prefixed strings. Call once on
|
||||
// rec==nullptr (before the session is torn down).
|
||||
void bankUnregisterActions(reaper_plugin_info_t* rec);
|
||||
|
||||
// The registered command id for the "Prune bank folder" action (Phase R, R3), or 0
|
||||
// before registration. The bank_panel prune button fires the action THROUGH this id
|
||||
// via Main_OnCommand (fork R-E: the button dispatches the command, it does not call
|
||||
// the session directly) so the panel affordance and the bindable action share one
|
||||
// guarded code path.
|
||||
// The bank_panel prune button fires THROUGH this id (Main_OnCommand) rather than
|
||||
// calling the session directly, so button and bindable action share one guarded path.
|
||||
int bankPruneCommandId();
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
@@ -1,24 +1,16 @@
|
||||
// design_view_actions.cpp — the Design View action family (Phase D4; Q-W4 split of
|
||||
// actions.cpp). See design_view_actions.h.
|
||||
// design_view_actions.cpp — see design_view_actions.h.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
// WITHOUT REAPERAPI_IMPLEMENT — main.cpp is the one TU that defines the API pointers
|
||||
// (CLAUDE.md §contract). The action ids are minted from FOREVER-STABLE strings (the
|
||||
// same CEREBELLUM_REASAMPLER_ family prefix main.cpp uses); user keybindings key off
|
||||
// them, so they must never change after ship.
|
||||
// main.cpp owns the API pointers; this TU gets them extern. Action ids are minted
|
||||
// from FOREVER-STABLE strings — never change one after ship.
|
||||
//
|
||||
// Each action:
|
||||
// 1. mutates the session's ViewModeModel (membership tag/untag/show-both, or the
|
||||
// active mode via toggle/activate) — the pure D1 state,
|
||||
// 2. reapplies the active mode through the D2 view shell (applyMode) so the change
|
||||
// takes visible effect immediately (tagging a track into Design while in Arrange
|
||||
// parks it right away; a mode change re-partitions and re-parks in one step).
|
||||
// Each action mutates the session's ViewModeModel (membership tag/untag/show-both, or
|
||||
// the active mode via toggle/activate), then reapplies the active mode through the
|
||||
// view shell (applyMode) so the change takes visible effect immediately.
|
||||
//
|
||||
// Selection-driven mutations iterate the CURRENT REAPER track selection
|
||||
// (CountSelectedTracks/GetSelectedTrack — both ignore the master, which is correct:
|
||||
// the master is never tagged) and resolve each track to its canonical GUID key via
|
||||
// the shared guidString helper, so the keys match exactly what the D2 shell / view
|
||||
// tree key on (the cross-module key contract).
|
||||
// (CountSelectedTracks/GetSelectedTrack ignore the master, which is correct — the
|
||||
// master is never tagged) and resolve each track to its canonical GUID key so the
|
||||
// keys match what the view shell / view tree key on.
|
||||
|
||||
#include "shell/actions/design_view_actions.h"
|
||||
|
||||
@@ -55,11 +47,8 @@ using view::isOnManualLane;
|
||||
|
||||
namespace {
|
||||
|
||||
// FOREVER-STABLE action-id SUFFIXES (Phase V, V4). The channel family prefix is prepended
|
||||
// at register time via channelCommandId (app_version), so stable rebuilds the exact shipped
|
||||
// id ("CEREBELLUM_REASAMPLER_VIEW_TOGGLE_MODE") and beta yields the isolated forever-family
|
||||
// id ("CEREBELLUM_REASAMPLER_BETA_VIEW_TOGGLE_MODE"). Each composed id is minted into a
|
||||
// persistent command id user keybindings key off — NEVER change a shipped suffix after ship.
|
||||
// FOREVER-STABLE action-id SUFFIXES: the channel prefix is prepended at register
|
||||
// (channelCommandId) — NEVER change a shipped suffix.
|
||||
constexpr const char* kIdToggleMode = "VIEW_TOGGLE_MODE";
|
||||
constexpr const char* kIdActivateArrange = "VIEW_ACTIVATE_ARRANGE";
|
||||
constexpr const char* kIdActivateDesign = "VIEW_ACTIVATE_DESIGN";
|
||||
@@ -67,17 +56,14 @@ constexpr const char* kIdTagDesign = "VIEW_TAG_DESIGN";
|
||||
constexpr const char* kIdTagArrange = "VIEW_TAG_ARRANGE";
|
||||
constexpr const char* kIdUntag = "VIEW_UNTAG";
|
||||
constexpr const char* kIdShowBoth = "VIEW_SHOW_BOTH";
|
||||
// D2 Wave 3-B item-level mode moves — the item analog of the track tag family. Same
|
||||
// FOREVER-STABLE contract (suffix composed with the channel prefix) — NEVER change these.
|
||||
// Item-level mode moves — the item analog of the track tag family above.
|
||||
constexpr const char* kIdMoveItemsDesign = "VIEW_MOVE_ITEMS_DESIGN";
|
||||
constexpr const char* kIdMoveItemsArrange = "VIEW_MOVE_ITEMS_ARRANGE";
|
||||
constexpr const char* kIdUntagItems = "VIEW_UNTAG_ITEMS";
|
||||
|
||||
// The live session the actions mutate. Set once by designViewRegisterActions and
|
||||
// read by the hookcommand handler. Not owned here (main.cpp owns g_session).
|
||||
// Not owned here (main.cpp owns g_session).
|
||||
ReaSamplerSession* g_session = nullptr;
|
||||
|
||||
// Minted command ids (0 until registration succeeds). Compared in the handler.
|
||||
int g_cmdToggleMode = 0;
|
||||
int g_cmdActivateArrange = 0;
|
||||
int g_cmdActivateDesign = 0;
|
||||
@@ -102,9 +88,6 @@ gaccel_register_t g_accelMoveItemsDesign{};
|
||||
gaccel_register_t g_accelMoveItemsArrange{};
|
||||
gaccel_register_t g_accelUntagItems{};
|
||||
|
||||
// Collects the canonical GUID keys of the current track selection. Empty if nothing
|
||||
// is selected. CountSelectedTracks/GetSelectedTrack ignore the master (SDK), which is
|
||||
// exactly right — the master is never a tagged leaf.
|
||||
std::vector<std::string> selectedTrackGuids() {
|
||||
std::vector<std::string> guids;
|
||||
const int n = CountSelectedTracks(nullptr); // nullptr = active project
|
||||
@@ -118,22 +101,17 @@ std::vector<std::string> selectedTrackGuids() {
|
||||
return guids;
|
||||
}
|
||||
|
||||
// Reapplies the model's CURRENT active mode to the active project so a membership
|
||||
// mutation takes visible effect immediately (park/unpark/re-derive parents). Called
|
||||
// after every tag/untag/show-both. `proj = nullptr` -> REAPER's active project.
|
||||
// Reapplies the CURRENT active mode so a membership mutation takes visible effect
|
||||
// immediately (park/unpark/re-derive parents).
|
||||
void reapplyActiveMode() {
|
||||
applyMode(g_session->view(), g_session->view().activeModeId(), nullptr);
|
||||
}
|
||||
|
||||
// Track fixed-lane mode value (I_FREEMODE=2). Mirrors the shell's constant; used only to
|
||||
// decide whether an item's lane name is meaningful for the manual-lane read.
|
||||
constexpr int kFreeModeFixedLanes = 2;
|
||||
constexpr int kFreeModeFixedLanes = 2; // I_FREEMODE value; mirrors the shell's constant
|
||||
|
||||
// Collects the current media-item selection as the pure decision's input: each selected
|
||||
// item's GUID plus whether it sits on a MANUAL lane (⇒ EXEMPT — never retagged/re-laned).
|
||||
// The manual-lane read follows the shared pure predicate exactly as the shell's readers
|
||||
// do: only on a fixed-lane track (I_FREEMODE==2) is the item's lane name read; on a normal
|
||||
// track isOnManualLane returns false for the empty name, so the P_LANENAME read is skipped.
|
||||
// Each selected item's GUID plus whether it sits on a MANUAL lane (EXEMPT — never
|
||||
// retagged/re-laned). The lane name is read only on a fixed-lane track; on a normal
|
||||
// track the shared predicate returns false for an empty name, so the read is skipped.
|
||||
// Items whose GUID cannot be read are dropped (an empty GUID must never be retagged).
|
||||
std::vector<RetagItem> selectedRetagItems() {
|
||||
std::vector<RetagItem> items;
|
||||
@@ -148,33 +126,18 @@ std::vector<RetagItem> selectedRetagItems() {
|
||||
MediaTrack* tr = GetMediaItemTrack(it);
|
||||
const bool fixedLane =
|
||||
tr && static_cast<int>(GetMediaTrackInfo_Value(tr, "I_FREEMODE")) == kFreeModeFixedLanes;
|
||||
// Only read the lane name on a fixed-lane track; the pure predicate handles the
|
||||
// normal-track case (returns false) so we pass an empty name and skip the read.
|
||||
const std::string laneNm = fixedLane ? itemLaneName(tr, it) : std::string{};
|
||||
items.push_back(RetagItem{std::move(g), isOnManualLane(fixedLane, laneNm)});
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
// Persists both the bank and the Design-View model to the active project's ext
|
||||
// state. Called after every state-changing Design View action so the view model
|
||||
// is not lost across save/close/reopen. Marking the project dirty is correct —
|
||||
// a Design View mutation is a project-level change the user should be prompted
|
||||
// to save.
|
||||
//
|
||||
// When the membership index is non-empty AND the project is unsaved, we prompt
|
||||
// the user to Save-As before persisting — mirroring the flow capture uses.
|
||||
// Gate: if membership is empty (no tracks tagged), skip the prompt entirely;
|
||||
// saveToActiveProject will no-op for an unsaved project, which is correct.
|
||||
//
|
||||
// DAW-ONLY ASSUMPTION: Main_SaveProject(proj, true) opens a Save-As dialog and
|
||||
// blocks until the user dismisses it. The blocking behaviour and dialog
|
||||
// appearance can only be confirmed in a running REAPER (same caveat as capture).
|
||||
// Persists the bank + Design-View model after every state-changing action so the
|
||||
// view model is not lost across save/close/reopen. If membership is non-empty and
|
||||
// the project is unsaved, prompts Save-As first (mirrors the flow capture uses) —
|
||||
// DAW-ONLY: Main_SaveProject(proj, true) blocks until the dialog is dismissed.
|
||||
void persistViewState() {
|
||||
if (!g_session->view().membership().empty()) {
|
||||
// At least one track is tagged — worth persisting. Check whether the
|
||||
// project is saved and, if not, prompt Save-As so saveToActiveProject
|
||||
// can write ext state. Mirrors capture's readRppPath idiom exactly.
|
||||
ReaProject* proj = EnumProjects(-1, nullptr, 0);
|
||||
if (proj) {
|
||||
auto readRppPath = [&]() -> std::string {
|
||||
@@ -184,15 +147,11 @@ void persistViewState() {
|
||||
};
|
||||
|
||||
if (readRppPath().empty()) {
|
||||
// Project is unsaved — prompt Save-As.
|
||||
Main_SaveProject(proj, true);
|
||||
// Re-read: still empty means the user cancelled.
|
||||
if (readRppPath().empty()) {
|
||||
if (readRppPath().empty()) { // still empty -> user cancelled
|
||||
ShowConsoleMsg(
|
||||
"ReaSampler: Design View state will not persist until "
|
||||
"the project is saved.\n");
|
||||
// The in-session tag state is left as-is — the mode change
|
||||
// already applied and remains valid for this session.
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -201,11 +160,8 @@ void persistViewState() {
|
||||
g_session->saveToActiveProject();
|
||||
}
|
||||
|
||||
// -- Action bodies ---------------------------------------------------------
|
||||
|
||||
// Toggle: cycle to the next mode in ordinal order (Arrange <-> Design with two
|
||||
// seeds; scales to cycle-through-all for >2 modes with no change here). applyMode
|
||||
// itself sets the model's active mode, so we only compute the target and apply.
|
||||
// Cycle to the next mode in ordinal order. applyMode itself sets the model's active
|
||||
// mode, so we only compute the target and apply.
|
||||
void doToggleMode() {
|
||||
const std::string target =
|
||||
nextModeId(g_session->view().modes(), g_session->view().activeModeId());
|
||||
@@ -223,9 +179,8 @@ void doActivateMode(const std::string& modeId) {
|
||||
bankPanelInvalidate(); // repaint the footer [Arrange|Design] toggle immediately
|
||||
}
|
||||
|
||||
// Tag the selection's leaves into `modeId`, then reapply so the change is immediate.
|
||||
// tag() replaces any prior single-mode membership (a leaf lives in one mode; the
|
||||
// cross-mode case is show-both), matching the D1 contract.
|
||||
// cross-mode case is show-both).
|
||||
void doTag(const std::string& modeId) {
|
||||
for (const std::string& g : selectedTrackGuids())
|
||||
g_session->view().membership().tag(g, modeId);
|
||||
@@ -233,9 +188,8 @@ void doTag(const std::string& modeId) {
|
||||
persistViewState();
|
||||
}
|
||||
|
||||
// Untag the selection entirely (return each to the Arrange default). This is the
|
||||
// shared body behind both "Untag selected" and "Tag -> Arrange" (Arrange = the
|
||||
// absence of a tag), so the two actions are the same act by definition.
|
||||
// Shared body behind "Untag selected" and "Tag -> Arrange" — Arrange is the absence
|
||||
// of a tag, so the two actions are the same act.
|
||||
void doUntag() {
|
||||
for (const std::string& g : selectedTrackGuids())
|
||||
g_session->view().membership().untag(g);
|
||||
@@ -243,11 +197,8 @@ void doUntag() {
|
||||
persistViewState();
|
||||
}
|
||||
|
||||
// Toggle the per-track show-both pin for the selection. Read the CURRENT pin of each
|
||||
// track and flip it independently (a mixed selection converges toward "all on" then
|
||||
// "all off" only if uniform; per-track flip is the honest semantics of a toggle on a
|
||||
// multi-selection). show-both leaves are never parked (D1), so reapply reflects the
|
||||
// change immediately.
|
||||
// Flips each track's pin independently — the honest semantics of a toggle on a
|
||||
// multi-selection (a mixed selection converges toward uniform only if it already was).
|
||||
void doShowBoth() {
|
||||
MembershipIndex& m = g_session->view().membership();
|
||||
for (const std::string& g : selectedTrackGuids())
|
||||
@@ -256,19 +207,12 @@ void doShowBoth() {
|
||||
persistViewState();
|
||||
}
|
||||
|
||||
// -- Item-level mode moves (D2 Wave 3-B) -----------------------------------
|
||||
// Retag the current ITEM selection to `targetMode` (empty => untag -> Arrange
|
||||
// default). planItemRetag decides which items to retag (manual-lane items are
|
||||
// EXEMPT), upholding the managed-lanes-only invariant. Wrapped in ONE Undo block.
|
||||
//
|
||||
// Retag the current ITEM selection to `targetMode` (empty ⇒ untag → Arrange default),
|
||||
// then re-drive the minting + apply path so each moved item lands on its target mode's
|
||||
// managed lane and the active-mode lane visibility is reasserted. The pure planItemRetag
|
||||
// decides which selected items to retag (manual-lane items are EXEMPT — never retagged,
|
||||
// never re-laned), upholding the managed-lanes-only invariant even under this explicit
|
||||
// user action. The whole structural act is wrapped in ONE Undo block with a descriptive
|
||||
// label (the inner blocks mintManagedLanes / applyMode open nest harmlessly under it).
|
||||
//
|
||||
// UNDO/SAVE ordering: persistViewState may pop a Save-As dialog (Main_SaveProject) which
|
||||
// must NOT sit inside the Undo block, so we close the block first, then persist — the same
|
||||
// separation the track actions rely on (they persist outside applyMode's own block).
|
||||
// UNDO/SAVE ordering: persistViewState may pop a Save-As dialog, which must NOT sit
|
||||
// inside the Undo block, so we close the block first, then persist.
|
||||
void doMoveItems(const std::string& targetMode) {
|
||||
const std::vector<RetagItem> selected = selectedRetagItems();
|
||||
const std::vector<ItemRetagOp> ops = planItemRetag(selected, targetMode);
|
||||
@@ -277,15 +221,12 @@ void doMoveItems(const std::string& targetMode) {
|
||||
MembershipIndex& membership = g_session->view().membership();
|
||||
|
||||
Undo_BeginBlock2(nullptr);
|
||||
// Apply the pure decision's membership writes: tag into targetMode, or untag.
|
||||
for (const ItemRetagOp& op : ops) {
|
||||
if (op.untag) membership.untag(op.guid);
|
||||
else membership.tag(op.guid, op.modeId);
|
||||
}
|
||||
// Re-drive the SAME minting/apply path auto-tag uses: mint/split lanes for any track
|
||||
// whose items now span modes and assign each moved item to its mode's managed lane,
|
||||
// then reassert the active mode's lane visibility. Manual lanes stay untouched
|
||||
// (mintManagedLanes reports their items exempt and never mints over them).
|
||||
// Re-drive the same minting/apply path auto-tag uses: mint/split lanes for any
|
||||
// track whose items now span modes, then reassert active-mode lane visibility.
|
||||
mintManagedLanes(g_session->view(), nullptr);
|
||||
reapplyActiveMode();
|
||||
|
||||
@@ -303,8 +244,6 @@ void doMoveItems(const std::string& targetMode) {
|
||||
void designViewRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* session) {
|
||||
g_session = session;
|
||||
|
||||
// command_id -> gaccel for each. The single hookcommand that routes these lives
|
||||
// in main.cpp (one hook per extension); designViewHandleCommand services them.
|
||||
g_cmdToggleMode = registerAction(rec, kIdToggleMode, g_accelToggleMode,
|
||||
"toggle Design View mode");
|
||||
g_cmdActivateArrange = registerAction(rec, kIdActivateArrange, g_accelActivateArrange,
|
||||
@@ -320,7 +259,6 @@ void designViewRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* ses
|
||||
g_cmdShowBoth = registerAction(rec, kIdShowBoth, g_accelShowBoth,
|
||||
"show both for selected tracks");
|
||||
|
||||
// Item-level mode moves (D2 W3-B): the item analog of the track tag family.
|
||||
g_cmdMoveItemsDesign = registerAction(rec, kIdMoveItemsDesign, g_accelMoveItemsDesign,
|
||||
"move selected items -> Design");
|
||||
g_cmdMoveItemsArrange = registerAction(rec, kIdMoveItemsArrange, g_accelMoveItemsArrange,
|
||||
@@ -336,13 +274,10 @@ bool designViewHandleCommand(int command) {
|
||||
if (command == g_cmdActivateArrange) { doActivateMode(kArrangeModeId); return true; }
|
||||
if (command == g_cmdActivateDesign) { doActivateMode(kDesignModeId); return true; }
|
||||
if (command == g_cmdTagDesign) { doTag(kDesignModeId); return true; }
|
||||
// Tag -> Arrange and Untag are the same act (Arrange = the absence of a tag).
|
||||
if (command == g_cmdTagArrange) { doUntag(); return true; }
|
||||
if (command == g_cmdUntag) { doUntag(); return true; }
|
||||
if (command == g_cmdShowBoth) { doShowBoth(); return true; }
|
||||
|
||||
// Item-level moves. Move -> Arrange and Untag items collapse to the same act (an
|
||||
// empty target ⇒ untag ⇒ Arrange default), mirroring the track-level pairing above.
|
||||
if (command == g_cmdMoveItemsDesign) { doMoveItems(kDesignModeId); return true; }
|
||||
if (command == g_cmdMoveItemsArrange) { doMoveItems(std::string{}); return true; }
|
||||
if (command == g_cmdUntagItems) { doMoveItems(std::string{}); return true; }
|
||||
@@ -351,11 +286,8 @@ bool designViewHandleCommand(int command) {
|
||||
}
|
||||
|
||||
void designViewUnregisterActions(reaper_plugin_info_t* rec) {
|
||||
// Mirror-unregister with '-'-prefixed strings, per the contract's unload rule.
|
||||
// gaccel first, then the command_id string (reverse of registration order — the item
|
||||
// moves registered last, so they tear down first).
|
||||
// Each '-command_id' re-presents the SAME interned, channel-qualified id (channelIdFor
|
||||
// returns the memoized pointer registered above), so the unregister matches exactly.
|
||||
// Reverse registration order; each '-command_id' re-presents the SAME interned
|
||||
// pointer channelIdFor returned above.
|
||||
rec->Register("-gaccel", (void*)&g_accelUntagItems);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdUntagItems));
|
||||
rec->Register("-gaccel", (void*)&g_accelMoveItemsArrange);
|
||||
|
||||
@@ -1,38 +1,26 @@
|
||||
#pragma once
|
||||
// design_view_actions — the Design View action family (Phase D4; Q-W4 split of
|
||||
// actions.h). Registers the bindable actions that drive the mode workflow and wires
|
||||
// them end-to-end: toggle/activate a mode, tag/untag/show-both the current track
|
||||
// selection, and the item-level mode moves (D2 W3-B). Each action mutates the
|
||||
// session's ViewModeModel (D1, via persist's ReaSamplerSession) and then reapplies
|
||||
// the active mode through the view shell (D2) so the change takes effect immediately.
|
||||
//
|
||||
// REAPER-facing shell: the .cpp includes reaper_plugin_functions.h WITHOUT
|
||||
// REAPERAPI_IMPLEMENT (main.cpp owns the API pointers — CLAUDE.md §contract). This
|
||||
// header is SDK-free; main.cpp calls register/handle/unregister and nothing else.
|
||||
// design_view_actions — the Design View bindable action family: toggle/activate a
|
||||
// mode, tag/untag/show-both the current track selection, and the item-level mode
|
||||
// moves. Each action mutates the session's ViewModeModel then reapplies the active
|
||||
// mode through the view shell so the change takes effect immediately. SDK-free
|
||||
// header; main.cpp calls register/handle/unregister and nothing else.
|
||||
|
||||
// Forward-declared at GLOBAL scope (matches reaper_plugin.h's typedef struct
|
||||
// reaper_plugin_info_t) so this header stays SDK-free; the .cpp includes the real
|
||||
// definition. Declared before the namespace so it is the global type, not a
|
||||
// namespace-local shadow.
|
||||
// Forward-declared at GLOBAL scope (matches reaper_plugin.h's typedef) so this
|
||||
// header stays SDK-free; the .cpp includes the real definition.
|
||||
struct reaper_plugin_info_t;
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
class ReaSamplerSession;
|
||||
|
||||
// Registers the Design View action family against `rec` (command_id + gaccel +
|
||||
// hookcommand-routing is owned by the caller's single hookcommand). `session` is the
|
||||
// live session the actions mutate; it must outlive the registration. Idempotent is
|
||||
// NOT promised — call exactly once at load, mirror-unregister once at unload.
|
||||
// `session` must outlive registration. Not idempotent — call exactly once at load,
|
||||
// mirror-unregister once at unload.
|
||||
void designViewRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* session);
|
||||
|
||||
// Services one fired command. Returns true iff `command` is one of this module's
|
||||
// action ids (and it was handled); false otherwise so the caller's hookcommand keeps
|
||||
// looking (per the contract: claim only our own ids). Safe to call for any command.
|
||||
// True iff `command` is one of this module's ids (and handled); false otherwise so
|
||||
// the caller's hookcommand keeps looking.
|
||||
bool designViewHandleCommand(int command);
|
||||
|
||||
// Mirror-unregisters everything designViewRegisterActions registered, with the
|
||||
// '-'-prefixed strings (per the contract's unload rule). Call once on rec==nullptr.
|
||||
void designViewUnregisterActions(reaper_plugin_info_t* rec);
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
// 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,
|
||||
// CF_HDROP, plus a minimal IDropSource, handed to OLE DoDragDrop with a COPY-ONLY effect
|
||||
// mask. We roll our own rather than pull in a helper because the object is tiny (one
|
||||
// format, one medium) and the copy-only guarantee must be structural and auditable in one
|
||||
// place. mac/linux route to SWELL's file-list drag behind the same seam.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. No REAPER API is used here (pure OS/COM); it
|
||||
// is a leaf the bank_panel calls.
|
||||
// drag_out_win.cpp — see drag_out_win.h. Hand-rolled IDataObject/IDropSource rather
|
||||
// than a helper library: the object is tiny (one format, one medium) and the
|
||||
// copy-only guarantee must be structural and auditable in one place. No REAPER API
|
||||
// used here (pure OS/COM).
|
||||
|
||||
#include "shell/actions/drag_out_win.h"
|
||||
|
||||
@@ -29,8 +23,8 @@ namespace {
|
||||
HGLOBAL buildHDrop(const std::vector<std::string>& paths) {
|
||||
if (paths.empty()) return nullptr;
|
||||
|
||||
// 1) Convert each UTF-8 path to wide, normalizing '/' -> '\\' (the panel stores paths
|
||||
// slash-normalized for its own resolution; CF_HDROP wants native backslashes).
|
||||
// Convert each UTF-8 path to wide, normalizing '/' -> '\\' (the panel stores paths
|
||||
// slash-normalized; CF_HDROP wants native backslashes).
|
||||
std::vector<std::wstring> wide;
|
||||
wide.reserve(paths.size());
|
||||
std::size_t totalChars = 0; // characters incl. each path's terminating NUL
|
||||
@@ -40,8 +34,7 @@ HGLOBAL buildHDrop(const std::vector<std::string>& paths) {
|
||||
if (need <= 0) continue; // unconvertible path — skip rather than emit garbage
|
||||
std::wstring w(static_cast<std::size_t>(need), L'\0');
|
||||
MultiByteToWideChar(CP_UTF8, 0, p.c_str(), -1, &w[0], need);
|
||||
// `need` includes the NUL; drop it from the string length, we re-add it in the buffer.
|
||||
if (!w.empty() && w.back() == L'\0') w.pop_back();
|
||||
if (!w.empty() && w.back() == L'\0') w.pop_back(); // re-added below
|
||||
for (wchar_t& c : w) if (c == L'/') c = L'\\';
|
||||
totalChars += w.size() + 1; // + the per-path NUL
|
||||
wide.push_back(std::move(w));
|
||||
@@ -200,10 +193,9 @@ private:
|
||||
bool initiateDragOut(HWND__* /*panelHwnd*/, const std::vector<std::string>& absolutePaths) {
|
||||
if (absolutePaths.empty()) return false;
|
||||
|
||||
// REAPER's main thread is already OLE-initialized (it hosts OLE drag targets), so we do
|
||||
// NOT call OleInitialize here — a nested OleInitialize on an already-initialized STA is
|
||||
// harmless-but-unnecessary, and OleUninitialize pairing across a REAPER-owned apartment
|
||||
// is the kind of thing that bites. DoDragDrop works on the already-initialized STA.
|
||||
// REAPER's main thread is already OLE-initialized (it hosts OLE drag targets); we
|
||||
// deliberately do NOT call OleInitialize — pairing OleUninitialize across a
|
||||
// REAPER-owned apartment is the kind of thing that bites.
|
||||
HGLOBAL hdrop = buildHDrop(absolutePaths);
|
||||
if (!hdrop) return false;
|
||||
|
||||
@@ -211,9 +203,8 @@ bool initiateDragOut(HWND__* /*panelHwnd*/, const std::vector<std::string>& abso
|
||||
auto* source = new DropSource();
|
||||
|
||||
DWORD effect = 0;
|
||||
// COPY-ONLY (invariant #1): the allowed-effects mask is DROPEFFECT_COPY alone. MOVE is
|
||||
// NEVER offered, so no drop target can relocate (delete) the bank file — only prune
|
||||
// deletes bank bytes (Phase R boundary).
|
||||
// COPY-ONLY: the allowed-effects mask is DROPEFFECT_COPY alone. MOVE is never
|
||||
// offered, so no drop target can relocate (delete) the bank file.
|
||||
const HRESULT hr = DoDragDrop(data, source, DROPEFFECT_COPY, &effect);
|
||||
|
||||
source->Release();
|
||||
@@ -232,12 +223,9 @@ bool initiateDragOut(HWND__* /*panelHwnd*/, const std::vector<std::string>& abso
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// SWELL provides a file-list drag surface (SWELL_InitiateDragDropOfFileList, verified in
|
||||
// vendor/WDL/WDL/swell/swell-functions.h). It takes a C-string array + count and initiates
|
||||
// a copy-style file drag from the given window. Unlike OLE it exposes no per-source effect
|
||||
// mask, so the copy-only guarantee rests on SWELL's copy semantics rather than an explicit
|
||||
// DROPEFFECT_COPY mask — an honest platform difference, not a faked equivalence. Windows is
|
||||
// the exact-control path (D5: Windows is the shipping target).
|
||||
// SWELL_InitiateDragDropOfFileList initiates a copy-style file drag from the given
|
||||
// window. Unlike OLE it exposes no per-source effect mask, so the copy-only
|
||||
// guarantee here rests on SWELL's copy semantics rather than an explicit mask.
|
||||
bool initiateDragOut(HWND__* panelHwnd, const std::vector<std::string>& absolutePaths) {
|
||||
if (absolutePaths.empty() || !panelHwnd) return false;
|
||||
|
||||
|
||||
@@ -1,25 +1,17 @@
|
||||
#pragma once
|
||||
// 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
|
||||
// machinery so the user can drop bank samples into Explorer / another app / another DAW.
|
||||
// drag_out_win — the OS/COM initiation half of native OS drag-out: hands a resolved
|
||||
// existing-file path list to the OS's drag-drop machinery so the user can drop bank
|
||||
// samples into Explorer / another app / another DAW. The pure gesture-boundary
|
||||
// decision + path-list assembly live in drag_out.*.
|
||||
//
|
||||
// ONE seam, platform-forked inside the .cpp:
|
||||
// * Windows (primary — Daniel's target): OLE DoDragDrop with a minimal IDataObject
|
||||
// carrying CF_HDROP (absolute paths, double-null-terminated wide list) and a minimal
|
||||
// IDropSource. COPY-ONLY is STRUCTURAL: the IDataObject offers DROPEFFECT_COPY and the
|
||||
// effect mask passed to DoDragDrop is DROPEFFECT_COPY alone — MOVE is never offered, so
|
||||
// no target can pull the bank file out of the bank folder (invariant #1: a move would
|
||||
// delete bank bytes, and per the Phase R boundary ONLY prune deletes files).
|
||||
// * macOS/Linux (SWELL): SWELL_InitiateDragDropOfFileList (verified present in
|
||||
// vendor/WDL/WDL/swell/swell-functions.h) behind the same seam. SWELL's file-list drag
|
||||
// is a copy-style file drag; it exposes no per-source effect mask the way OLE does, so
|
||||
// the copy-only guarantee there rests on SWELL's copy semantics rather than an explicit
|
||||
// mask — noted honestly, not faked. Windows is where the mask control is exact.
|
||||
// COPY-ONLY is STRUCTURAL on Windows: DoDragDrop's effect mask is DROPEFFECT_COPY
|
||||
// alone — MOVE is never offered, so no target can pull a file out of the bank folder
|
||||
// (only prune deletes bank bytes). macOS/Linux route through SWELL's file-list drag,
|
||||
// which exposes no per-source effect mask, so there the copy-only guarantee rests on
|
||||
// SWELL's copy semantics rather than an explicit mask.
|
||||
//
|
||||
// NON-DESTRUCTIVE (invariant #2): initiating a drag reads nothing but the path list and
|
||||
// mutates no sample / index / selection. A cancelled or failed drag changes nothing — the
|
||||
// OS layer here neither writes ext-state nor touches the book.
|
||||
// NON-DESTRUCTIVE: initiating a drag reads nothing but the path list; a cancelled or
|
||||
// failed drag mutates no sample/index/selection.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -28,16 +20,10 @@ struct HWND__; // avoid dragging windows.h into every includer; the shell casts
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Initiates a native OS drag-out of `absolutePaths` (already resolved, existing, de-duped —
|
||||
// the pure drag_out::assemblePathList output) from the panel window `panelHwnd`. COPY-ONLY;
|
||||
// see the header note. A no-op when the path list is empty (nothing draggable — the caller
|
||||
// checks this too, but the guard is repeated here so a direct call is safe).
|
||||
//
|
||||
// BLOCKING on Windows: OLE DoDragDrop runs its own modal message loop until the drop or
|
||||
// cancel, then returns — the caller's gesture state should be reset AFTER this returns.
|
||||
// Returns true if a drop was accepted (DROPEFFECT_COPY), false on cancel / failure /
|
||||
// empty input. The return is advisory (a failed drag is visible by nothing happening —
|
||||
// the caller does not surface an error, per the brief's no-console-output constraint).
|
||||
// `absolutePaths` must already be resolved/existing/de-duped (drag_out::assemblePathList
|
||||
// output). No-op when empty. BLOCKING on Windows: OLE DoDragDrop runs its own modal
|
||||
// message loop until drop/cancel. Returns true iff the drop was accepted
|
||||
// (DROPEFFECT_COPY); the return is advisory — a failed drag surfaces no error.
|
||||
bool initiateDragOut(HWND__* panelHwnd, const std::vector<std::string>& absolutePaths);
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
// 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
|
||||
// REAPERAPI_IMPLEMENT (main.cpp owns the pointers; here they are extern via the WANT list).
|
||||
// instrument_drop_win.cpp — see instrument_drop_win.h. main.cpp owns the API
|
||||
// pointers; this TU gets them extern via the WANT list.
|
||||
|
||||
#include "shell/actions/instrument_drop_win.h"
|
||||
|
||||
@@ -35,32 +33,24 @@ using wire::infoNamesFxHotspot;
|
||||
|
||||
namespace {
|
||||
|
||||
// Write `bytes` to a fresh uniquely-named .vstpreset in the OS temp dir and return its path;
|
||||
// returns an empty path on any failure. The .vstpreset extension is load-bearing —
|
||||
// TrackFX_SetPreset's full-path form is documented for .vstpreset files (VST3). The file is
|
||||
// transient: the caller deletes it right after the SetPreset call.
|
||||
// Writes `bytes` to a fresh uniquely-named .vstpreset in the OS temp dir; empty path
|
||||
// on any failure. The .vstpreset extension is load-bearing — TrackFX_SetPreset's
|
||||
// full-path form is documented for .vstpreset files (VST3). Transient: the caller
|
||||
// deletes it right after the SetPreset call.
|
||||
//
|
||||
// The temp filename embeds the process ID so two concurrent REAPER instances (e.g. stable +
|
||||
// beta) cannot collide in the shared OS temp dir, and one instance's cleanup cannot
|
||||
// accidentally delete another's in-flight file.
|
||||
//
|
||||
// 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 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,
|
||||
// so a temp dir with accented or CJK user-name bytes is handled correctly;
|
||||
// (b) delete via the retained path object — not via re-parsing the narrow string —
|
||||
// so the cleanup cannot leak if the conversion above were to round-trip incorrectly.
|
||||
// Non-throwing: every std::filesystem call uses the error_code overload, and the
|
||||
// whole body is try/catch-wrapped so no exception crosses the REAPER callback
|
||||
// boundary. Returns the path object (not a narrow string) so the caller can pass
|
||||
// path.u8string() to TrackFX_SetPreset (UTF-8, not ACP-converted) and delete via the
|
||||
// same retained path — never a re-parsed narrow string.
|
||||
std::filesystem::path writeTempPreset(const std::vector<std::uint8_t>& bytes) {
|
||||
try {
|
||||
static std::atomic<unsigned> counter{0};
|
||||
std::error_code ec;
|
||||
const std::filesystem::path dir = std::filesystem::temp_directory_path(ec);
|
||||
if (ec) return {};
|
||||
// PID in the name keeps files from distinct REAPER instances distinct in the shared
|
||||
// temp dir — prevents cross-instance collisions and spurious post-apply deletions.
|
||||
// PID in the name: two concurrent REAPER instances (stable + beta) cannot
|
||||
// collide in the shared temp dir.
|
||||
const std::string name =
|
||||
"reasampler_drop_" + std::to_string(GetCurrentProcessId()) +
|
||||
"_" + std::to_string(counter.fetch_add(1)) + ".vstpreset";
|
||||
@@ -85,10 +75,8 @@ std::filesystem::path writeTempPreset(const std::vector<std::uint8_t>& bytes) {
|
||||
FxDropTarget resolveFxDropTarget(int screenX, int screenY) {
|
||||
FxDropTarget out;
|
||||
char info[256] = {0};
|
||||
// GetThingFromPoint returns the track under the point (may be null for a non-track thing)
|
||||
// and fills `info` with what was hit. A non-empty info OR a non-null track means the point
|
||||
// is over REAPER's own UI; a null track with an empty info means the pointer has left
|
||||
// REAPER entirely (over another app / the desktop) — the OsDrag boundary.
|
||||
// A non-empty info OR a non-null track means the point is over REAPER's own UI;
|
||||
// a null track with empty info means the pointer has left REAPER entirely.
|
||||
MediaTrack* track = GetThingFromPoint(screenX, screenY, info, sizeof(info));
|
||||
out.track = track;
|
||||
out.overReaperUi = (track != nullptr) || (info[0] != '\0');
|
||||
@@ -101,46 +89,32 @@ FxDropTarget resolveFxDropTarget(int screenX, int screenY) {
|
||||
bool loadInstrumentOntoTrack(MediaTrack* track, const std::vector<std::uint8_t>& presetBytes) {
|
||||
if (!track || presetBytes.empty()) return false;
|
||||
|
||||
// Materialize the .vstpreset FIRST so an I/O failure leaves the track untouched (no FX
|
||||
// added yet — nothing to roll back).
|
||||
// Materialize the .vstpreset FIRST so an I/O failure leaves the track untouched
|
||||
// (no FX added yet — nothing to roll back).
|
||||
const std::filesystem::path presetPath = writeTempPreset(presetBytes);
|
||||
if (presetPath.empty()) return false;
|
||||
|
||||
// The CHANNEL-correct FX name: "VST3:ReaSampler 9000" on stable, "VST3:ReaSampler 9000
|
||||
// beta" on beta. Sourcing it from app_version::vstPluginName() (the same accessor the VST
|
||||
// factory display name derives from) keeps the pairing invariant intact — a beta extension
|
||||
// drops the beta VST, a stable extension the stable VST — with no literal to drift. (The
|
||||
// preset's class ID forks by the same channel bit inside buildInstrumentDropPreset.)
|
||||
// Channel-correct FX name ("VST3:ReaSampler 9000[ beta]") sourced from the same
|
||||
// accessor the VST factory display name derives from, so the pairing invariant
|
||||
// (beta extension <-> beta VST) has no literal to drift.
|
||||
const std::string fxName = "VST3:" + vstPluginName();
|
||||
|
||||
// Negative `instantiate` => always create a NEW instance (verified in the header). recFX
|
||||
// = false: a normal track FX chain instance, not a record/monitoring FX.
|
||||
// Negative `instantiate` => always create a NEW instance. recFX = false: a
|
||||
// normal track FX chain instance, not a record/monitoring FX.
|
||||
const int fxIndex = TrackFX_AddByName(track, fxName.c_str(), /*recFX=*/false,
|
||||
/*instantiate=*/-1);
|
||||
bool ok = fxIndex >= 0;
|
||||
|
||||
// Apply the dragged capture's component state through the DOCUMENTED channel: a full
|
||||
// .vstpreset path handed to TrackFX_SetPreset (SDK: "Full paths to .vstpreset files are
|
||||
// also supported for VST3 plug-ins"). REAPER parses the Steinberg container and feeds the
|
||||
// 'Comp' chunk to the instance's setState — the same bytes the instrument's own
|
||||
// serializer produced (instrument_drop::buildInstrumentDropPreset ->
|
||||
// sample_map::serializeComponentState). Unlike the former "vst_chunk" named-config-parm
|
||||
// write, a failure here is REPORTED (false), not silently ignored.
|
||||
//
|
||||
// u8string() gives UTF-8 bytes on MSVC (not ACP-converted), so a temp dir under an
|
||||
// accented or CJK user-name is handled correctly by REAPER's path APIs.
|
||||
// u8string() gives UTF-8 bytes on MSVC (not ACP-converted), so a temp dir under
|
||||
// an accented or CJK user-name is handled correctly by REAPER's path APIs.
|
||||
if (ok) ok = TrackFX_SetPreset(track, fxIndex, presetPath.u8string().c_str());
|
||||
|
||||
// The preset file is transient regardless of outcome; delete via the retained path object
|
||||
// (not a re-parsed narrow string) so cleanup cannot leak even if the UTF-8 conversion
|
||||
// round-trip were incorrect.
|
||||
std::error_code ec;
|
||||
std::filesystem::remove(presetPath, ec);
|
||||
std::filesystem::remove(presetPath, ec); // transient regardless of outcome
|
||||
|
||||
// All-or-nothing: if the preset apply fails, remove the FX instance we just
|
||||
// added so the track is left exactly as it was.
|
||||
if (!ok && fxIndex >= 0) {
|
||||
// All-or-nothing: if the preset apply fails, remove the empty FX instance we just
|
||||
// added so the track is left exactly as it was. TrackFX_Delete signature (verified
|
||||
// in reaper_plugin_functions.h:7236): bool TrackFX_Delete(MediaTrack*, int fx).
|
||||
TrackFX_Delete(track, fxIndex);
|
||||
}
|
||||
return ok;
|
||||
@@ -149,11 +123,8 @@ bool loadInstrumentOntoTrack(MediaTrack* track, const std::vector<std::uint8_t>&
|
||||
bool performInstrumentDrop(MediaTrack* track, const std::vector<std::uint8_t>& presetBytes) {
|
||||
if (!track || presetBytes.empty()) return false;
|
||||
|
||||
// One undo point for the whole gesture (mirrors the bank-verb undo discipline). Both the
|
||||
// FX add and the state apply are REAPER-undoable, so Ctrl-Z removes the instance cleanly.
|
||||
Undo_BeginBlock2(nullptr);
|
||||
const bool ok = loadInstrumentOntoTrack(track, presetBytes);
|
||||
// The undo label reflects the placement-of-the-player framing (not a capture, not an insert).
|
||||
Undo_EndBlock2(nullptr, "ReaSampler: drop capture onto FX chain", -1);
|
||||
return ok;
|
||||
}
|
||||
|
||||
@@ -1,69 +1,51 @@
|
||||
#pragma once
|
||||
// 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
|
||||
// + its FX-surface hotspot via REAPER's hit-test API, and (b) on release adds a ReaSampler
|
||||
// 9000 instance to that track and applies the dragged capture as its component state via a
|
||||
// temp .vstpreset + TrackFX_SetPreset (S-GA-DropFX: the earlier "vst_chunk" named-config-parm
|
||||
// write was silently unappliable — see instrument_drop.h for the diagnosis).
|
||||
// instrument_drop_win — the REAPER-facing shell half of drop-and-load: (a) resolves
|
||||
// a screen point to a track + its FX-surface hotspot via REAPER's hit-test API, and
|
||||
// (b) on release adds a ReaSampler 9000 instance and applies the dragged capture as
|
||||
// its component state via a temp .vstpreset + TrackFX_SetPreset (the earlier
|
||||
// "vst_chunk" named-config-parm write was silently unappliable for VST3 — don't
|
||||
// revert to it). The pure gesture decision lives in drag_out; the pure payload
|
||||
// construction in instrument_drop.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. REAPER-facing (GetThingFromPoint, TrackFX_*,
|
||||
// Undo_*), so DAW-verified, not unit-tested; the pure decision + preset it drives are CTest'd.
|
||||
//
|
||||
// LOAD-BEARING (CONTEXT.md §Drop-and-load): this is an EXPLICIT user placement-of-the-player
|
||||
// gesture — it adds a READER of the bank on a track and points it at one already-captured
|
||||
// sample. It NEVER captures, NEVER writes the bank, and NEVER inserts a timeline item. The
|
||||
// only writes are: a new FX instance on the target track + that instance's own component
|
||||
// state — both REAPER-undoable, wrapped in one undo block so the whole gesture is one Ctrl-Z
|
||||
// — plus a transient .vstpreset in the OS temp dir, deleted before returning.
|
||||
// LOAD-BEARING: an EXPLICIT user placement-of-the-player gesture — adds a READER of
|
||||
// the bank on a track, pointed at an already-captured sample. NEVER captures, NEVER
|
||||
// writes the bank, NEVER inserts a timeline item. The only writes are a new FX
|
||||
// instance + its component state, both wrapped in one undo block (one Ctrl-Z), plus
|
||||
// a transient .vstpreset deleted before returning.
|
||||
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
// Opaque REAPER track handle at the boundary so includers don't need the SDK. The SDK
|
||||
// declares it as a class (reaper_plugin.h) — match that spelling so the mangled name agrees.
|
||||
// Declared as a class (matching reaper_plugin.h) so the mangled name agrees, without
|
||||
// pulling in the SDK.
|
||||
class MediaTrack;
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// The result of hit-testing a screen point during a live InstrumentDrop drag.
|
||||
struct FxDropTarget {
|
||||
MediaTrack* track = nullptr; // the track under the pointer (null if none / not a track)
|
||||
bool overReaperUi = false; // the point is over REAPER's own window/UI at all
|
||||
bool overFxHotspot = false; // specifically over this track's FX button/chain surface
|
||||
|
||||
// A valid drop target: a resolved track whose FX hotspot is under the pointer.
|
||||
bool valid() const { return track != nullptr && overFxHotspot; }
|
||||
};
|
||||
|
||||
// Hit-test a screen point (REAPER screen coords) to an FX drop target. Wraps
|
||||
// GetThingFromPoint, whose info string tells us what was hit ("tcp.fx*"/"mcp.fx*" for the
|
||||
// TCP/MCP FX button family; "fx_chain"/"fx_N" for the FX-chain and floating-FX windows; bare
|
||||
// "tcp"/"mcp" or other sub-element tokens for non-FX track-panel regions). `overReaperUi` is
|
||||
// the shell-supplied predicate the pure drag_out::decideGesture consumes (true when the point
|
||||
// is over REAPER's own UI — i.e. GetThingFromPoint returned a track OR a recognizable
|
||||
// non-track thing, false when the pointer has left REAPER entirely). `overFxHotspot` is true
|
||||
// only when the info string names a genuine FX-bearing surface — decided by the pure
|
||||
// instrument_drop::infoNamesFxHotspot from the SDK's own hit-test string.
|
||||
// Wraps GetThingFromPoint, whose info string tells us what was hit ("tcp.fx*"/
|
||||
// "mcp.fx*" for the TCP/MCP FX button family; "fx_chain"/"fx_N" for the FX-chain and
|
||||
// floating windows). `overReaperUi` is true when the point is over REAPER's own UI
|
||||
// at all; `overFxHotspot` is true only for a genuine FX-bearing surface (decided by
|
||||
// the pure instrument_drop::infoNamesFxHotspot).
|
||||
FxDropTarget resolveFxDropTarget(int screenX, int screenY);
|
||||
|
||||
// Perform the drop on `track`: add a fresh ReaSampler 9000 instance and apply `presetBytes`
|
||||
// (the instrument_drop::buildInstrumentDropPreset output — a .vstpreset image) as its
|
||||
// component state so it plays the dragged capture. Wraps the add + apply in one REAPER undo
|
||||
// block (mirrors the bank-verb undo discipline). Returns true on success (the FX was added
|
||||
// and the preset applied), false on any failure. All-or-nothing: if the preset apply fails
|
||||
// after a successful add, the freshly-added FX instance is removed via TrackFX_Delete before
|
||||
// returning false, leaving the track exactly as it was (no orphaned empty-state FX).
|
||||
// NEVER inserts a timeline item; the ONLY persistent mutations are the FX instance + its
|
||||
// state, both undoable.
|
||||
// Adds a fresh ReaSampler 9000 instance to `track` and applies `presetBytes` as its
|
||||
// component state. Wraps add + apply in one REAPER undo block. All-or-nothing: if
|
||||
// the preset apply fails after a successful add, the FX instance is removed via
|
||||
// TrackFX_Delete before returning false, leaving the track exactly as it was.
|
||||
bool performInstrumentDrop(MediaTrack* track, const std::vector<std::uint8_t>& presetBytes);
|
||||
|
||||
// Add a fresh ReaSampler 9000 instance to `track` and apply `presetBytes` as its component
|
||||
// state. Same all-or-nothing add+apply contract as performInstrumentDrop (rolls the FX back
|
||||
// via TrackFX_Delete on apply failure), but does NOT open its own undo block — the caller owns
|
||||
// the undo grouping so the whole gesture (persist + FX-add + apply) collapses to
|
||||
// one Ctrl-Z. This is the shared inner half performInstrumentDrop wraps in its own block.
|
||||
// Returns true on success, false on any failure. NEVER inserts a timeline item.
|
||||
// Same all-or-nothing add+apply contract as performInstrumentDrop but does NOT open
|
||||
// its own undo block — the caller owns the undo grouping so persist + FX-add + apply
|
||||
// collapses to one Ctrl-Z. The shared inner half performInstrumentDrop wraps.
|
||||
bool loadInstrumentOntoTrack(MediaTrack* track, const std::vector<std::uint8_t>& presetBytes);
|
||||
|
||||
} // namespace reasampler
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
// prune_action.cpp — the "Prune bank folder" action body (Phase R3; Q-W4 split of
|
||||
// actions.cpp). See prune_action.h for the contract this TU preserves.
|
||||
//
|
||||
// Compiled into the reaper_reasampler MODULE. Includes reaper_plugin_functions.h
|
||||
// WITHOUT REAPERAPI_IMPLEMENT (main.cpp owns the API pointers — CLAUDE.md §contract).
|
||||
// prune_action.cpp — see prune_action.h for the contract this TU preserves.
|
||||
// main.cpp owns the API pointers; this TU gets them extern.
|
||||
|
||||
#include "shell/actions/prune_action.h"
|
||||
|
||||
@@ -18,25 +15,17 @@
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
// Prune bank folder — Phase R (Reclaim), R3: the guarded DESTRUCTIVE step, and the SOLE
|
||||
// file-deletion entry in ReaSampler. Dry-run FIRST (compute the orphan set, read-only),
|
||||
// then — only when orphans exist — a blocking CONFIRM showing the SPECIFIC manifest
|
||||
// (count + reclaimable bytes + the file list, truncated consistent with the 64-cap), then
|
||||
// on explicit Yes delete EXACTLY that set (session.pruneReclaim, which recomputes the
|
||||
// pure core fresh and deletes confirmed ∩ freshOrphans — trash-preferred, unlink fallback).
|
||||
// Zero orphans => informational only, NO confirm ever shown. Cancel deletes nothing.
|
||||
//
|
||||
// The full (untruncated) orphan set is captured here for the delete; the dry-run's
|
||||
// truncated list is only the confirm's readout. No ext-state is written and no undo point
|
||||
// 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.
|
||||
// The guarded DESTRUCTIVE step and the SOLE file-deletion entry in ReaSampler.
|
||||
// Dry-run FIRST (read-only); only when orphans exist, a blocking CONFIRM with the
|
||||
// manifest; on explicit Yes, delete EXACTLY that set (recomputed fresh — confirmed ∩
|
||||
// freshOrphans). Zero orphans => informational only, no confirm shown. No ext-state
|
||||
// write, no undo point (file deletion is not REAPER-undoable).
|
||||
void doBankPruneFolder(ReaSamplerSession& session) {
|
||||
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
|
||||
// than proceed with degraded protection. Distinct from "no orphans": the user must
|
||||
// know the prune refused to run and why.
|
||||
// FAIL-SAFE: an unreadable instance-usage record makes the protected set
|
||||
// unknowable, so the prune HALTS outright rather than proceed with degraded
|
||||
// protection.
|
||||
if (report.abortedUnreadableUsage) {
|
||||
std::string msg =
|
||||
"ReaSampler prune: ABORTED -- one or more instance usage records could not "
|
||||
@@ -58,13 +47,10 @@ void doBankPruneFolder(ReaSamplerSession& session) {
|
||||
return;
|
||||
}
|
||||
|
||||
// The EXACT set the delete will target — full, untruncated, so what the confirm
|
||||
// summarises (count + bytes) matches what pruneReclaim reclaims. Captured before the
|
||||
// confirm so the confirm and the delete reason about the same enumeration.
|
||||
// The EXACT (untruncated) set the delete will target, captured before the confirm
|
||||
// so confirm and delete reason about the same enumeration.
|
||||
const std::vector<std::string> orphanSet = session.pruneOrphanSet();
|
||||
|
||||
// Confirm-with-manifest: count + bytes exact; the file list is the dry-run's 64-capped
|
||||
// list (the same clip the R2 readout used), with a "N more not shown" tail when clipped.
|
||||
std::string msg =
|
||||
"ReaSampler prune will PERMANENTLY reclaim " + std::to_string(report.count) +
|
||||
" orphaned file(s), freeing " + std::to_string(report.totalBytes) + " bytes.\n\n"
|
||||
@@ -84,7 +70,6 @@ void doBankPruneFolder(ReaSamplerSession& session) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirmed -> delete exactly the confirmed set (recomputed fresh, stale entries skipped).
|
||||
const reclaim::PruneDeletionResult del = session.pruneReclaim(orphanSet);
|
||||
|
||||
std::string done = "ReaSampler prune: reclaimed " +
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
#pragma once
|
||||
// prune_action — the "Prune bank folder" action body (Phase R3; Q-W4 split of
|
||||
// actions.cpp). This is the SOLE file-deletion action in ReaSampler, isolated in its
|
||||
// own TU so the deletion authority is one obvious module on the actions side (its
|
||||
// persist-side counterpart concentrates into prune_fs in Q-W5). Registration and
|
||||
// hookcommand routing for its FOREVER-STABLE id (BANK_PRUNE_FOLDER) stay with the
|
||||
// bank family (bank_actions) — one registration flow, one guarded body here.
|
||||
// prune_action — the "Prune bank folder" action body: the SOLE file-deletion action
|
||||
// in ReaSampler, isolated in its own TU so the deletion authority is one obvious
|
||||
// module. Registration/dispatch for its FOREVER-STABLE id (BANK_PRUNE_FOLDER) stay
|
||||
// with bank_actions; one guarded body here.
|
||||
//
|
||||
// Contract (preserve exactly): dry-run first; abort outright on unreadable usage
|
||||
// records (pS-usage fail-safe); confirm-with-manifest before any deletion; opens NO
|
||||
// undo point and writes NO ext state (file deletion is not REAPER-undoable). Routes
|
||||
// to persist's public session API only (pruneDryRun / pruneOrphanSet / pruneReclaim).
|
||||
// records (fail-safe); confirm-with-manifest before any deletion; opens NO undo
|
||||
// point and writes NO ext state (file deletion is not REAPER-undoable).
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
|
||||
@@ -1,16 +1,11 @@
|
||||
// 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.
|
||||
// bank_ops.cpp — see bank_ops.h for the contract. The ONE implementation home of the
|
||||
// bank verbs: 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). Index/model + ext-state only — never the arrange, never a file on disk.
|
||||
// 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.
|
||||
// main.cpp owns the API pointers; this TU gets them extern. DAW-verified, not unit tested.
|
||||
|
||||
#include "shell/bank_ops/bank_ops.h"
|
||||
|
||||
@@ -31,9 +26,7 @@ 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.
|
||||
// Ids are caller-supplied and stable; the model stays pure and mints none.
|
||||
std::string mintBankId() {
|
||||
GUID g{};
|
||||
genGuid(&g);
|
||||
@@ -44,35 +37,20 @@ std::string mintBankId() {
|
||||
|
||||
} // 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: a bank verb mutates ONLY our project ext-state, which REAPER's
|
||||
// undo system captures iff UNDO_STATE_MISCCFG is set (the SDK documents MISCCFG as
|
||||
// covering extensions' project ext-state). We pass exactly UNDO_STATE_MISCCFG, not
|
||||
// -1/UNDO_STATE_ALL — a bank verb touches no tracks/FX/items, so snapshotting them
|
||||
// would be both heavier and wrong. Persist runs INSIDE the block so the post-mutation
|
||||
// ext-state is the block's "after" image.
|
||||
//
|
||||
// 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.)
|
||||
// UNSAVED-PROJECT GUARDRAIL: on an unsaved/no-active project saveToActiveProject()
|
||||
// no-ops; we still CLOSE the block, but with an empty label + zero flag so REAPER
|
||||
// discards the point instead of recording a no-effect undo entry. Quiet persist by
|
||||
// design (mirrors capture, not Design-View) — 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)
|
||||
@@ -109,7 +87,6 @@ bool bankOpDelete(ReaSamplerSession& session, const std::string& bankId,
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -120,14 +97,10 @@ bool bankOpActivate(ReaSamplerSession& session, const std::string& bankId) {
|
||||
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.
|
||||
// NO-OP GUARDRAIL, verb-aware: a MOVE collapse still removed the source entry (the
|
||||
// index DID mutate), but a COPY collapse left the source intact AND the dest already
|
||||
// held the hash (a true no-op) — so copy counts only real gains, move counts gains
|
||||
// OR collapses.
|
||||
bool bankOpTransfer(ReaSamplerSession& session,
|
||||
const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId, const std::string& destBankId,
|
||||
@@ -151,18 +124,14 @@ bool bankOpTransfer(ReaSamplerSession& session,
|
||||
}
|
||||
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).
|
||||
// Index-only, this-bank scope; non-destructive to the file (a last-reference remove
|
||||
// leaves the file orphaned until prune). Silent: recoverability is the batched undo.
|
||||
bool bankOpRemove(ReaSamplerSession& session,
|
||||
const std::vector<std::string>& sampleIds,
|
||||
const std::string& srcBankId) {
|
||||
@@ -174,8 +143,6 @@ bool bankOpRemove(ReaSamplerSession& session,
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
#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:
|
||||
// bank_ops — the promptless bank-verb seam. 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. Two UX surfaces consume these as thin
|
||||
// skins: shell/panel/panel_bank_ops (menu prompts/confirms/repaints) and
|
||||
// shell/actions/bank_actions (bindable family, text prompts/console feedback).
|
||||
//
|
||||
// * 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.
|
||||
// The session arrives BY REFERENCE, so a missing session can never be
|
||||
// half-reported as a model rejection from in here. 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 header.
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@@ -25,58 +17,47 @@ 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.
|
||||
// Returns "" when the model rejects the name (duplicate, trimmed + case-insensitive).
|
||||
// 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).
|
||||
// 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).
|
||||
// False when the model rejects (pool un-deletable). `bumpGeneration` should be the
|
||||
// member count 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).
|
||||
// False when the model rejects (the pool itself). Bumps the generation.
|
||||
bool bankOpEvacuate(ReaSamplerSession& session, const std::string& bankId);
|
||||
|
||||
// Activates `bankId` as the capture target. False on an unknown id. No bump.
|
||||
// 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.
|
||||
// Index-only; files never relocate. Returns whether the index actually mutated — a
|
||||
// COPY collapse changes nothing (no undo point), a MOVE collapse did remove the
|
||||
// source entry (counts). Persists one undo point 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.
|
||||
// Index-only, this-bank scope; never deletes bytes. Persists one undo point when
|
||||
// anything was removed.
|
||||
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.
|
||||
// Wraps the session persist in a Begin/End undo block (UNDO_STATE_MISCCFG) so the
|
||||
// bank op is one Ctrl-Z; on an unsaved/no-active project the block closes empty
|
||||
// (REAPER discards it). Call ONLY after an effective mutation.
|
||||
//
|
||||
// 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.
|
||||
// `bumpGeneration = true` for a verb that changes what a live instance would PLAY;
|
||||
// leave false for a purely organizational verb. The bump happens INSIDE the block,
|
||||
// before the persist, so the stamped counter rides the same ext-state write.
|
||||
void persistBankOp(ReaSamplerSession& session, const char* label,
|
||||
bool bumpGeneration = false);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user