Q-W4: split actions.cpp into design_view_actions/bank_actions/prune_action + shared action_registry; bank verbs deduped into promptless bankOp* inner verbs in panel_bank_ops (one mutation home, two UX skins); command-id strings byte-identical; actions.h shim carrier retired
This commit is contained in:
@@ -0,0 +1,366 @@
|
||||
// bank_actions.cpp — the multi-bank bindable action family (Phase B3; Q-W4 split of
|
||||
// actions.cpp). See bank_actions.h.
|
||||
//
|
||||
// Q-W4 dedupe: each mutating handler is a THIN UX SKIN — text prompts (promptText),
|
||||
// name resolution, and console feedback — over the promptless bankOp* inner verbs
|
||||
// homed in panel_bank_ops (model op + persistBankOp, one bank op = one Ctrl-Z). The
|
||||
// book's rules (pool privileges, collapse-by-hash, active-fallback-to-pool) all live
|
||||
// in bank_book; these handlers only drive the verbs and react to the boolean.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
|
||||
#include "shell/actions/bank_actions.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "shell/actions/action_registry.h" // channelIdFor / registerAction (shared plumbing)
|
||||
#include "shell/actions/prune_action.h" // doBankPruneFolder — the guarded prune body
|
||||
|
||||
#include "core/model/bank_book.h" // BankBook, nextBankId, kPoolBankId (B1)
|
||||
#include "persist.h" // ReaSamplerSession (owns book())
|
||||
#include "shell/panel/panel_bank_ops.h" // bankOp* inner verbs + promptText + selection seam
|
||||
#include "shell/panel/panel_layout.h" // full-height toggles (B3)
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_ShowConsoleMsg
|
||||
#define REAPERAPI_WANT_ShowMessageBox
|
||||
#include "reaper_plugin_functions.h"
|
||||
|
||||
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").
|
||||
constexpr const char* kIdBankCreate = "BANK_CREATE";
|
||||
constexpr const char* kIdBankRename = "BANK_RENAME";
|
||||
constexpr const char* kIdBankDelete = "BANK_DELETE";
|
||||
constexpr const char* kIdBankEvacuate = "BANK_EVACUATE";
|
||||
constexpr const char* kIdBankActivateNext = "BANK_ACTIVATE_NEXT";
|
||||
constexpr const char* kIdBankActivatePool = "BANK_ACTIVATE_POOL";
|
||||
constexpr const char* kIdBankMoveSel = "BANK_MOVE_SELECTED";
|
||||
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). The
|
||||
// mutations themselves run through the bankOp* verbs, which resolve the same session
|
||||
// via the panel seam. Set once by bankRegisterActions; not owned here.
|
||||
ReaSamplerSession* g_session = nullptr;
|
||||
|
||||
int g_cmdBankCreate = 0;
|
||||
int g_cmdBankRename = 0;
|
||||
int g_cmdBankDelete = 0;
|
||||
int g_cmdBankEvacuate = 0;
|
||||
int g_cmdBankActivateNext = 0;
|
||||
int g_cmdBankActivatePool = 0;
|
||||
int g_cmdBankMoveSel = 0;
|
||||
int g_cmdBankCopySel = 0;
|
||||
int g_cmdBankRemoveSel = 0;
|
||||
int g_cmdBankPoolFull = 0;
|
||||
int g_cmdBankBanksFull = 0;
|
||||
int g_cmdBankPruneFolder = 0;
|
||||
|
||||
// gaccel storage must outlive registration — REAPER holds each pointer until we
|
||||
// mirror-unregister it. One per action.
|
||||
gaccel_register_t g_accelBankCreate{};
|
||||
gaccel_register_t g_accelBankRename{};
|
||||
gaccel_register_t g_accelBankDelete{};
|
||||
gaccel_register_t g_accelBankEvacuate{};
|
||||
gaccel_register_t g_accelBankActivateNext{};
|
||||
gaccel_register_t g_accelBankActivatePool{};
|
||||
gaccel_register_t g_accelBankMoveSel{};
|
||||
gaccel_register_t g_accelBankCopySel{};
|
||||
gaccel_register_t g_accelBankRemoveSel{};
|
||||
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.
|
||||
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.
|
||||
void doBankCreate() {
|
||||
std::string name;
|
||||
if (!promptText("ReaSampler: create bank", "Bank name:", "", name)) return;
|
||||
if (bankOpCreate(name).empty()) {
|
||||
ShowConsoleMsg(
|
||||
("ReaSampler: could not create bank \"" + name +
|
||||
"\" (a bank with that name already exists).\n")
|
||||
.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
void doBankRename() {
|
||||
std::string which;
|
||||
if (!promptText("ReaSampler: rename bank", "Bank to rename (current name):", "",
|
||||
which))
|
||||
return;
|
||||
const std::string id = bankIdByDisplayName(which);
|
||||
if (id.empty()) {
|
||||
ShowConsoleMsg(("ReaSampler: no bank named \"" + which + "\".\n").c_str());
|
||||
return;
|
||||
}
|
||||
std::string newName;
|
||||
if (!promptText("ReaSampler: rename bank", "New name:", which, newName)) return;
|
||||
if (!bankOpRename(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.
|
||||
void doBankDelete() {
|
||||
std::string which;
|
||||
if (!promptText("ReaSampler: delete bank", "Bank to delete:", "", which)) return;
|
||||
const std::string id = bankIdByDisplayName(which);
|
||||
if (id.empty()) {
|
||||
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.
|
||||
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).
|
||||
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();
|
||||
if (members > 0) {
|
||||
const std::string msg =
|
||||
"\"" + which + "\" holds " + std::to_string(members) +
|
||||
(members == 1 ? " sample" : " samples") +
|
||||
".\n\nDeleting drops them from every bank (their files are NOT deleted, "
|
||||
"but no bank will reference them until prune).\n\nTo keep the samples, "
|
||||
"cancel and Evacuate the bank to the pool first.\n\nDelete anyway?";
|
||||
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.
|
||||
if (!bankOpDelete(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.
|
||||
void doBankEvacuate() {
|
||||
std::string which;
|
||||
if (!promptText("ReaSampler: evacuate bank", "Bank to evacuate to the pool:", "",
|
||||
which))
|
||||
return;
|
||||
const std::string id = bankIdByDisplayName(which);
|
||||
if (id.empty()) {
|
||||
ShowConsoleMsg(("ReaSampler: no bank named \"" + which + "\".\n").c_str());
|
||||
return;
|
||||
}
|
||||
if (!bankOpEvacuate(id)) {
|
||||
ShowConsoleMsg("ReaSampler: cannot evacuate that bank (the pool is the "
|
||||
"destination, not a source).\n");
|
||||
}
|
||||
}
|
||||
|
||||
// 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.
|
||||
void doBankActivateNext() {
|
||||
std::vector<std::string> ids;
|
||||
ids.reserve(g_session->book().size());
|
||||
for (const Bank& b : g_session->book().banks()) ids.push_back(b.id);
|
||||
const std::string target = nextBankId(ids, g_session->book().activeBankId());
|
||||
if (target.empty()) return; // degenerate (no banks) — cannot happen (pool seeded)
|
||||
bankOpActivate(target);
|
||||
}
|
||||
|
||||
// Activate the pool directly (the common "back to the default target" jump). Bindable
|
||||
// direct-by-id form; a general activate-bank-by-name/menu is a panel affordance.
|
||||
void doBankActivatePool() {
|
||||
bankOpActivate(kPoolBankId);
|
||||
}
|
||||
|
||||
// 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.
|
||||
void doBankTransferSelected(bool copy) {
|
||||
const std::vector<std::string> selected = bankPanelSelectedSampleIds();
|
||||
if (selected.empty()) {
|
||||
ShowConsoleMsg("ReaSampler: nothing selected in the bank panel to "
|
||||
"move/copy.\n");
|
||||
return;
|
||||
}
|
||||
const char* verb = copy ? "copy" : "move";
|
||||
const std::string title = std::string("ReaSampler: ") + verb + " selected samples";
|
||||
std::string destName;
|
||||
if (!promptText(title.c_str(), "Destination bank:", "", destName)) return;
|
||||
const std::string destId = bankIdByDisplayName(destName);
|
||||
if (destId.empty()) {
|
||||
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");
|
||||
return;
|
||||
}
|
||||
bankOpTransfer(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.
|
||||
void doBankRemoveSelected() {
|
||||
const std::vector<std::string> selected = bankPanelSelectedSampleIds();
|
||||
if (selected.empty()) {
|
||||
ShowConsoleMsg("ReaSampler: nothing selected in the bank panel to remove.\n");
|
||||
return;
|
||||
}
|
||||
const std::string srcId = bankPanelSelectedSourceBankId();
|
||||
if (g_session->book().bank(srcId) == nullptr) {
|
||||
ShowConsoleMsg("ReaSampler: the selection's bank no longer exists.\n");
|
||||
return;
|
||||
}
|
||||
bankOpRemove(selected, srcId);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
void bankRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* session) {
|
||||
g_session = session; // same live session as the Design View family
|
||||
|
||||
g_cmdBankCreate = registerAction(rec, kIdBankCreate, g_accelBankCreate,
|
||||
"create bank");
|
||||
g_cmdBankRename = registerAction(rec, kIdBankRename, g_accelBankRename,
|
||||
"rename bank");
|
||||
g_cmdBankDelete = registerAction(rec, kIdBankDelete, g_accelBankDelete,
|
||||
"delete bank");
|
||||
g_cmdBankEvacuate = registerAction(rec, kIdBankEvacuate, g_accelBankEvacuate,
|
||||
"evacuate bank to pool");
|
||||
g_cmdBankActivateNext = registerAction(rec, kIdBankActivateNext, g_accelBankActivateNext,
|
||||
"activate next bank (cycle)");
|
||||
g_cmdBankActivatePool = registerAction(rec, kIdBankActivatePool, g_accelBankActivatePool,
|
||||
"activate pool");
|
||||
g_cmdBankMoveSel = registerAction(rec, kIdBankMoveSel, g_accelBankMoveSel,
|
||||
"move selected samples to bank");
|
||||
g_cmdBankCopySel = registerAction(rec, kIdBankCopySel, g_accelBankCopySel,
|
||||
"copy selected samples to bank");
|
||||
g_cmdBankRemoveSel = registerAction(rec, kIdBankRemoveSel, g_accelBankRemoveSel,
|
||||
"remove selected samples");
|
||||
g_cmdBankPoolFull = registerAction(rec, kIdBankPoolFull, g_accelBankPoolFull,
|
||||
"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");
|
||||
}
|
||||
|
||||
bool bankHandleCommand(int command) {
|
||||
if (command == 0 || !g_session) return false;
|
||||
|
||||
if (command == g_cmdBankCreate) { doBankCreate(); return true; }
|
||||
if (command == g_cmdBankRename) { doBankRename(); return true; }
|
||||
if (command == g_cmdBankDelete) { doBankDelete(); return true; }
|
||||
if (command == g_cmdBankEvacuate) { doBankEvacuate(); return true; }
|
||||
if (command == g_cmdBankActivateNext) { doBankActivateNext(); return true; }
|
||||
if (command == g_cmdBankActivatePool) { doBankActivatePool(); return true; }
|
||||
if (command == g_cmdBankMoveSel) { doBankTransferSelected(false); return true; }
|
||||
if (command == g_cmdBankCopySel) { doBankTransferSelected(true); return true; }
|
||||
if (command == g_cmdBankRemoveSel) { doBankRemoveSelected(); return true; }
|
||||
if (command == g_cmdBankPoolFull) { bankPanelToggledPoolFullHeight(); return true; }
|
||||
if (command == g_cmdBankBanksFull) { bankPanelToggledBanksFullHeight(); return true; }
|
||||
if (command == g_cmdBankPruneFolder) { doBankPruneFolder(*g_session); return true; }
|
||||
|
||||
return false; // not ours — caller's hookcommand keeps looking
|
||||
}
|
||||
|
||||
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).
|
||||
rec->Register("-gaccel", (void*)&g_accelBankPruneFolder);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankPruneFolder));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankBanksFull);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankBanksFull));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankPoolFull);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankPoolFull));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankRemoveSel);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankRemoveSel));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankCopySel);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankCopySel));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankMoveSel);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankMoveSel));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankActivatePool);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankActivatePool));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankActivateNext);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankActivateNext));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankEvacuate);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankEvacuate));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankDelete);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankDelete));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankRename);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankRename));
|
||||
rec->Register("-gaccel", (void*)&g_accelBankCreate);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdBankCreate));
|
||||
|
||||
g_session = nullptr;
|
||||
}
|
||||
|
||||
} // namespace reasampler
|
||||
Reference in New Issue
Block a user