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,49 @@
|
||||
// action_registry.cpp — shared registration plumbing (Q-W4 split of actions.cpp).
|
||||
// See action_registry.h. Needs no REAPER API pointers: rec->Register is a member
|
||||
// call on the dispatch struct REAPER hands the entry point.
|
||||
|
||||
#include "shell/actions/action_registry.h"
|
||||
|
||||
#include <deque>
|
||||
#include <string>
|
||||
|
||||
#include "core/version/app_version.h" // channelCommandId / channelActionName
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
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<std::string> g_strStore;
|
||||
|
||||
} // namespace
|
||||
|
||||
const char* channelIdFor(const char* suffix) {
|
||||
const std::string composed = channelCommandId(suffix);
|
||||
for (const std::string& s : g_strStore)
|
||||
if (s == composed) return s.c_str();
|
||||
g_strStore.push_back(composed);
|
||||
return g_strStore.back().c_str();
|
||||
}
|
||||
|
||||
int registerAction(reaper_plugin_info_t* rec, const char* suffix,
|
||||
gaccel_register_t& accel, const char* phrase) {
|
||||
const char* id = channelIdFor(suffix);
|
||||
const int cmd = rec->Register("command_id", (void*)id);
|
||||
if (cmd) {
|
||||
g_strStore.push_back(channelActionName(phrase));
|
||||
accel.accel.cmd = cmd;
|
||||
accel.desc = g_strStore.back().c_str();
|
||||
rec->Register("gaccel", (void*)&accel);
|
||||
}
|
||||
return cmd;
|
||||
}
|
||||
|
||||
} // namespace reasampler
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
// action_registry — shared registration plumbing for the bindable action families
|
||||
// (Q-W4 split of actions.cpp). Owns the durable interned-string store both the
|
||||
// Design View and multi-bank families register through, so a composed command id
|
||||
// keeps ONE stable pointer from register to the mirror-unregister, and the
|
||||
// register-a-command_id-then-gaccel sequence has one implementation.
|
||||
//
|
||||
// Includes reaper_plugin.h (gaccel_register_t / reaper_plugin_info_t full defs);
|
||||
// only the action-family TUs include this header. Q-W6's registration table
|
||||
// subsumes this helper when the hand-written blocks become data.
|
||||
|
||||
#include "reaper_plugin.h" // reaper_plugin_info_t, gaccel_register_t
|
||||
|
||||
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.
|
||||
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).
|
||||
int registerAction(reaper_plugin_info_t* rec, const char* suffix,
|
||||
gaccel_register_t& accel, const char* phrase);
|
||||
|
||||
} // namespace reasampler
|
||||
@@ -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
|
||||
@@ -0,0 +1,45 @@
|
||||
#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).
|
||||
//
|
||||
// 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.
|
||||
|
||||
// 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 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.
|
||||
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.
|
||||
int bankPruneCommandId();
|
||||
|
||||
} // namespace reasampler
|
||||
@@ -0,0 +1,383 @@
|
||||
// design_view_actions.cpp — the Design View action family (Phase D4; Q-W4 split of
|
||||
// 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.
|
||||
//
|
||||
// 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).
|
||||
//
|
||||
// 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).
|
||||
|
||||
#include "shell/actions/design_view_actions.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "shell/actions/action_registry.h" // channelIdFor / registerAction (shared plumbing)
|
||||
|
||||
#include "core/view/lane_keys.h" // view::isOnManualLane — the single managed/manual predicate
|
||||
#include "core/view/view_mode_model.h"
|
||||
#include "persist.h" // ReaSamplerSession (owns view() model)
|
||||
#include "shell/capture/item_read.h" // shared MediaItem* -> GUID + fixed-lane-name reads (D2 W3-B)
|
||||
#include "shell/capture/track_guid.h" // shared MediaTrack* -> canonical GUID key
|
||||
#include "shell/panel/panel_window.h" // bankPanelInvalidate — footer toggle repaint
|
||||
#include "shell/view/view.h" // applyMode + mintManagedLanes (D2 shell)
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_CountSelectedTracks
|
||||
#define REAPERAPI_WANT_GetSelectedTrack
|
||||
#define REAPERAPI_WANT_CountSelectedMediaItems
|
||||
#define REAPERAPI_WANT_GetSelectedMediaItem
|
||||
#define REAPERAPI_WANT_GetMediaItemTrack
|
||||
#define REAPERAPI_WANT_GetMediaTrackInfo_Value
|
||||
#define REAPERAPI_WANT_EnumProjects
|
||||
#define REAPERAPI_WANT_Main_SaveProject
|
||||
#define REAPERAPI_WANT_ShowConsoleMsg
|
||||
#define REAPERAPI_WANT_Undo_BeginBlock2
|
||||
#define REAPERAPI_WANT_Undo_EndBlock2
|
||||
#include "reaper_plugin_functions.h"
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
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.
|
||||
constexpr const char* kIdToggleMode = "VIEW_TOGGLE_MODE";
|
||||
constexpr const char* kIdActivateArrange = "VIEW_ACTIVATE_ARRANGE";
|
||||
constexpr const char* kIdActivateDesign = "VIEW_ACTIVATE_DESIGN";
|
||||
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.
|
||||
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).
|
||||
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;
|
||||
int g_cmdTagDesign = 0;
|
||||
int g_cmdTagArrange = 0;
|
||||
int g_cmdUntag = 0;
|
||||
int g_cmdShowBoth = 0;
|
||||
int g_cmdMoveItemsDesign = 0;
|
||||
int g_cmdMoveItemsArrange = 0;
|
||||
int g_cmdUntagItems = 0;
|
||||
|
||||
// gaccel storage must outlive registration — REAPER holds each pointer until we
|
||||
// mirror-unregister it. One per action.
|
||||
gaccel_register_t g_accelToggleMode{};
|
||||
gaccel_register_t g_accelActivateArrange{};
|
||||
gaccel_register_t g_accelActivateDesign{};
|
||||
gaccel_register_t g_accelTagDesign{};
|
||||
gaccel_register_t g_accelTagArrange{};
|
||||
gaccel_register_t g_accelUntag{};
|
||||
gaccel_register_t g_accelShowBoth{};
|
||||
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
|
||||
guids.reserve(static_cast<std::size_t>(n < 0 ? 0 : n));
|
||||
for (int i = 0; i < n; ++i) {
|
||||
MediaTrack* tr = GetSelectedTrack(nullptr, i);
|
||||
if (!tr) continue;
|
||||
std::string g = guidString(tr);
|
||||
if (!g.empty()) guids.push_back(std::move(g));
|
||||
}
|
||||
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.
|
||||
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;
|
||||
|
||||
// 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.
|
||||
// Items whose GUID cannot be read are dropped (an empty GUID must never be retagged).
|
||||
std::vector<RetagItem> selectedRetagItems() {
|
||||
std::vector<RetagItem> items;
|
||||
const int n = CountSelectedMediaItems(nullptr); // nullptr = active project
|
||||
items.reserve(static_cast<std::size_t>(n < 0 ? 0 : n));
|
||||
for (int i = 0; i < n; ++i) {
|
||||
MediaItem* it = GetSelectedMediaItem(nullptr, i);
|
||||
if (!it) continue;
|
||||
std::string g = itemGuid(it);
|
||||
if (g.empty()) continue;
|
||||
|
||||
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).
|
||||
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 {
|
||||
std::vector<char> buf(4096, '\0');
|
||||
EnumProjects(-1, buf.data(), static_cast<int>(buf.size()));
|
||||
return std::string(buf.data());
|
||||
};
|
||||
|
||||
if (readRppPath().empty()) {
|
||||
// Project is unsaved — prompt Save-As.
|
||||
Main_SaveProject(proj, true);
|
||||
// Re-read: still empty means the user cancelled.
|
||||
if (readRppPath().empty()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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.
|
||||
void doToggleMode() {
|
||||
const std::string target =
|
||||
nextModeId(g_session->view().modes(), g_session->view().activeModeId());
|
||||
if (target.empty()) return; // no modes to cycle to (degenerate)
|
||||
applyMode(g_session->view(), target, nullptr);
|
||||
persistViewState();
|
||||
bankPanelInvalidate(); // repaint the footer [Arrange|Design] toggle immediately
|
||||
}
|
||||
|
||||
// Direct jump to a named mode. applyMode is a no-op (returns false, no mutation) if
|
||||
// the id is unregistered, so an absent mode fails safe.
|
||||
void doActivateMode(const std::string& modeId) {
|
||||
applyMode(g_session->view(), modeId, nullptr);
|
||||
persistViewState();
|
||||
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.
|
||||
void doTag(const std::string& modeId) {
|
||||
for (const std::string& g : selectedTrackGuids())
|
||||
g_session->view().membership().tag(g, modeId);
|
||||
reapplyActiveMode();
|
||||
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.
|
||||
void doUntag() {
|
||||
for (const std::string& g : selectedTrackGuids())
|
||||
g_session->view().membership().untag(g);
|
||||
reapplyActiveMode();
|
||||
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.
|
||||
void doShowBoth() {
|
||||
MembershipIndex& m = g_session->view().membership();
|
||||
for (const std::string& g : selectedTrackGuids())
|
||||
m.setShowBoth(g, !m.isShowBoth(g));
|
||||
reapplyActiveMode();
|
||||
persistViewState();
|
||||
}
|
||||
|
||||
// -- Item-level mode moves (D2 Wave 3-B) -----------------------------------
|
||||
//
|
||||
// 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).
|
||||
void doMoveItems(const std::string& targetMode) {
|
||||
const std::vector<RetagItem> selected = selectedRetagItems();
|
||||
const std::vector<ItemRetagOp> ops = planItemRetag(selected, targetMode);
|
||||
if (ops.empty()) return; // nothing selected, or every selected item was exempt/empty
|
||||
|
||||
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).
|
||||
mintManagedLanes(g_session->view(), nullptr);
|
||||
reapplyActiveMode();
|
||||
|
||||
const std::string label =
|
||||
targetMode.empty()
|
||||
? std::string("ReaSampler: untag selected items")
|
||||
: std::string("ReaSampler: move selected items -> ") + targetMode;
|
||||
Undo_EndBlock2(nullptr, label.c_str(), -1);
|
||||
|
||||
persistViewState();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
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,
|
||||
"activate mode Arrange");
|
||||
g_cmdActivateDesign = registerAction(rec, kIdActivateDesign, g_accelActivateDesign,
|
||||
"activate mode Design");
|
||||
g_cmdTagDesign = registerAction(rec, kIdTagDesign, g_accelTagDesign,
|
||||
"tag selected tracks -> Design");
|
||||
g_cmdTagArrange = registerAction(rec, kIdTagArrange, g_accelTagArrange,
|
||||
"tag selected tracks -> Arrange");
|
||||
g_cmdUntag = registerAction(rec, kIdUntag, g_accelUntag,
|
||||
"untag selected tracks");
|
||||
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,
|
||||
"move selected items -> Arrange");
|
||||
g_cmdUntagItems = registerAction(rec, kIdUntagItems, g_accelUntagItems,
|
||||
"untag selected items");
|
||||
}
|
||||
|
||||
bool designViewHandleCommand(int command) {
|
||||
if (command == 0 || !g_session) return false;
|
||||
|
||||
if (command == g_cmdToggleMode) { doToggleMode(); return true; }
|
||||
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; }
|
||||
|
||||
return false; // not ours — caller's hookcommand keeps looking
|
||||
}
|
||||
|
||||
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.
|
||||
rec->Register("-gaccel", (void*)&g_accelUntagItems);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdUntagItems));
|
||||
rec->Register("-gaccel", (void*)&g_accelMoveItemsArrange);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdMoveItemsArrange));
|
||||
rec->Register("-gaccel", (void*)&g_accelMoveItemsDesign);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdMoveItemsDesign));
|
||||
rec->Register("-gaccel", (void*)&g_accelShowBoth);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdShowBoth));
|
||||
rec->Register("-gaccel", (void*)&g_accelUntag);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdUntag));
|
||||
rec->Register("-gaccel", (void*)&g_accelTagArrange);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdTagArrange));
|
||||
rec->Register("-gaccel", (void*)&g_accelTagDesign);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdTagDesign));
|
||||
rec->Register("-gaccel", (void*)&g_accelActivateDesign);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdActivateDesign));
|
||||
rec->Register("-gaccel", (void*)&g_accelActivateArrange);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdActivateArrange));
|
||||
rec->Register("-gaccel", (void*)&g_accelToggleMode);
|
||||
rec->Register("-command_id", (void*)channelIdFor(kIdToggleMode));
|
||||
|
||||
g_session = nullptr;
|
||||
}
|
||||
|
||||
} // namespace reasampler
|
||||
@@ -0,0 +1,38 @@
|
||||
#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.
|
||||
|
||||
// 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.
|
||||
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.
|
||||
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.
|
||||
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
|
||||
@@ -0,0 +1,102 @@
|
||||
// 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).
|
||||
|
||||
#include "shell/actions/prune_action.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "persist.h" // ReaSamplerSession — pruneDryRun / pruneOrphanSet / pruneReclaim
|
||||
|
||||
#define REAPERAPI_MINIMAL
|
||||
#define REAPERAPI_WANT_ShowConsoleMsg
|
||||
#define REAPERAPI_WANT_ShowMessageBox
|
||||
#include "reaper_plugin_functions.h"
|
||||
|
||||
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.
|
||||
void doBankPruneFolder(ReaSamplerSession& session) {
|
||||
const 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.
|
||||
if (report.abortedUnreadableUsage) {
|
||||
std::string msg =
|
||||
"ReaSampler prune: ABORTED -- one or more instance usage records could not "
|
||||
"be read or decoded. Nothing was deleted.\n"
|
||||
"If the owning instance is still loaded it will republish its record on the "
|
||||
"next poll tick, clearing the abort. If the instance no longer exists (the "
|
||||
"key is an orphaned corrupt record), clear it manually via ReaScript:\n"
|
||||
" reaper.SetProjExtState(0, \"reasampler\", \"<key>\", \"\")\n"
|
||||
"Offending key(s):\n";
|
||||
for (const std::string& key : report.offendingUsageKeys) {
|
||||
msg += " " + key + "\n";
|
||||
}
|
||||
ShowConsoleMsg(msg.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
if (report.count == 0) {
|
||||
ShowConsoleMsg("ReaSampler prune: no orphaned files to reclaim.\n");
|
||||
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.
|
||||
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"
|
||||
"These files are no longer referenced by any bank and were created by ReaSampler.\n"
|
||||
"They will be moved to the Recycle Bin on Windows (recoverable), or deleted on "
|
||||
"other platforms.\n\n";
|
||||
for (const std::string& rel : report.orphans) msg += " " + rel + "\n";
|
||||
if (report.truncated) {
|
||||
msg += " ... (" + std::to_string(report.count - report.orphans.size()) +
|
||||
" more not shown)\n";
|
||||
}
|
||||
msg += "\nReclaim these files now?";
|
||||
|
||||
const int r = ShowMessageBox(msg.c_str(), "ReaSampler: prune bank folder", 4);
|
||||
if (r != 6) { // 6 == YES; anything else cancels -> delete NOTHING (SDK ~6544)
|
||||
ShowConsoleMsg("ReaSampler prune: cancelled -- nothing deleted.\n");
|
||||
return;
|
||||
}
|
||||
|
||||
// Confirmed -> delete exactly the confirmed set (recomputed fresh, stale entries skipped).
|
||||
const PruneDeletionResult del = session.pruneReclaim(orphanSet);
|
||||
|
||||
std::string done = "ReaSampler prune: reclaimed " +
|
||||
std::to_string(del.reclaimedCount) + " file(s), " +
|
||||
std::to_string(del.reclaimedBytes) + " bytes" +
|
||||
(del.usedTrash ? " (to Recycle Bin)" : " (deleted)") + ".";
|
||||
if (del.skippedCount > 0) {
|
||||
done += " " + std::to_string(del.skippedCount) +
|
||||
" file(s) skipped (locked, or changed since the report).";
|
||||
}
|
||||
done += "\n";
|
||||
ShowConsoleMsg(done.c_str());
|
||||
}
|
||||
|
||||
} // namespace reasampler
|
||||
@@ -0,0 +1,22 @@
|
||||
#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.
|
||||
//
|
||||
// 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).
|
||||
|
||||
namespace reasampler {
|
||||
|
||||
class ReaSamplerSession;
|
||||
|
||||
// Runs the guarded prune flow against `session`. Called by the bank family's
|
||||
// hookcommand handler when the BANK_PRUNE_FOLDER action fires.
|
||||
void doBankPruneFolder(ReaSamplerSession& session);
|
||||
|
||||
} // namespace reasampler
|
||||
Reference in New Issue
Block a user