Publish the Media Explorer import into REAPER's Media Explorer action section as well as Main — custom_action + hookcommand2, second forever-stable id, one handler.

This commit is contained in:
2026-08-01 19:43:27 -04:00
parent 8bf6841f7b
commit 72b870459c
6 changed files with 118 additions and 15 deletions
+45 -10
View File
@@ -62,18 +62,22 @@ namespace {
// Not owned here (main.cpp owns g_session).
ReaSamplerSession* g_session = nullptr;
// FOREVER-STABLE suffix — NEVER change after ship. Only the Media-Explorer import
// registers here — the arrange capture+assign action lives in the capture family in
// main.cpp, and the drop path is a panel callback (ingestDroppedFiles), not a
// bindable action.
constexpr const char* kIdImportMediaExplorer = "INGEST_IMPORT_MEDIA_EXPLORER";
// Only the Media-Explorer import registers here — the arrange capture+assign action lives
// in the capture family in main.cpp, and the drop path is a panel callback
// (ingestDroppedFiles), not a bindable action. Its two FOREVER-STABLE suffixes are in
// ingest.h.
constexpr int kSectionMediaExplorer = 32063;
int g_cmdImportMediaExplorer = 0;
gaccel_register_t g_accelImportMediaExplorer{};
int g_cmdImportMediaExplorer = 0;
int g_cmdImportMediaExplorerMx = 0;
gaccel_register_t g_accelImportMediaExplorer{};
custom_action_register_t g_customImportMediaExplorer{};
// c_str() pointers are handed to REAPER at register and re-presented at unregister,
// so these strings must not be mutated after registration.
// so these strings must not be mutated after registration. The label backs BOTH the
// gaccel desc and the custom_action name.
std::string g_idImportStr;
std::string g_idImportMxStr;
std::string g_labelImportStr;
// Forward-slashed, no trailing slash. Empty for an unsaved/no-active project, which
@@ -457,14 +461,31 @@ void ingestDroppedFiles(const std::vector<std::string>& absolutePaths) {
void ingestRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* session) {
g_session = session;
g_idImportStr = channelCommandId(kIdImportMediaExplorer);
g_labelImportStr = channelActionName("import Media Explorer file into selected track");
g_idImportStr = channelCommandId(kIngestImportMediaExplorerId);
g_cmdImportMediaExplorer = rec->Register("command_id", (void*)g_idImportStr.c_str());
if (g_cmdImportMediaExplorer) {
g_labelImportStr = channelActionName("import Media Explorer file into selected track");
g_accelImportMediaExplorer.accel.cmd = g_cmdImportMediaExplorer;
g_accelImportMediaExplorer.desc = g_labelImportStr.c_str();
rec->Register("gaccel", (void*)&g_accelImportMediaExplorer);
}
// Second publication of the SAME action, into the Media Explorer section, so it can
// be put on that window's toolbar. gaccel cannot express this — it registers into the
// main keyboard section only — so custom_action is the one mechanism. It carries no
// ACCEL, hence no default keybinding for this entry; toolbar reach is the point.
g_idImportMxStr = channelCommandId(kIngestImportMediaExplorerMxId);
g_customImportMediaExplorer.uniqueSectionId = kSectionMediaExplorer;
g_customImportMediaExplorer.idStr = g_idImportMxStr.c_str();
g_customImportMediaExplorer.name = g_labelImportStr.c_str();
g_customImportMediaExplorer.extra = nullptr; // reserved
g_cmdImportMediaExplorerMx =
rec->Register("custom_action", (void*)&g_customImportMediaExplorer);
if (!g_cmdImportMediaExplorerMx)
ShowConsoleMsg("ReaSampler: could not publish the Media Explorer import action into "
"the Media Explorer action section -- it is still available in the "
"Main section.\n");
}
bool ingestHandleCommand(int command) {
@@ -473,10 +494,24 @@ bool ingestHandleCommand(int command) {
return false; // not ours — caller's hookcommand keeps looking
}
bool ingestHandleSectionCommand(int command) {
if (command == 0 || !g_session) return false;
// ONLY the Media Explorer id. The Main entry has its own distinct id and is claimed by
// ingestHandleCommand off "hookcommand"; claiming it here too would double-fire it.
if (command == g_cmdImportMediaExplorerMx) { doImportFromMediaExplorer(); return true; }
return false;
}
void ingestUnregisterActions(reaper_plugin_info_t* rec) {
// A 0 return from "custom_action" means REAPER holds no registration of ours (a dupe
// idStr is one documented cause) — mirroring it anyway could retire someone else's.
if (g_cmdImportMediaExplorerMx)
rec->Register("-custom_action", (void*)&g_customImportMediaExplorer);
// '-command_id' re-presents the SAME interned id used at register (g_idImportStr).
rec->Register("-gaccel", (void*)&g_accelImportMediaExplorer);
rec->Register("-command_id", (void*)g_idImportStr.c_str());
g_cmdImportMediaExplorer = 0;
g_cmdImportMediaExplorerMx = 0;
g_session = nullptr;
}