refactor(ingest): ME-import adds RS9k to selected track, not a new track
No track is created; no routing changes. No selected track -> bank import proceeds, instrument placement is refused with a console message explaining why. createTrackWithInstrument removed (was sole caller).
This commit is contained in:
+57
-32
@@ -23,7 +23,7 @@
|
||||
#include "bank_panel.h" // bankPanelRefresh
|
||||
#include "capture_paths.h" // deriveBankPaths / projectDirOfRpp / hashWavContent
|
||||
#include "instrument_drop.h" // pure buildInstrumentDropChunk (vst_chunk blob for a sampleId)
|
||||
#include "instrument_drop_win.h" // shell createTrackWithInstrument (new track + pre-loaded RS9k)
|
||||
#include "instrument_drop_win.h" // shell loadInstrumentOntoTrack (FX add+inject, no own undo block)
|
||||
#include "persist.h" // ReaSamplerSession
|
||||
|
||||
#include "wav_trim.h" // parseWavLayout — 32f-float WAV validator for the fast path
|
||||
@@ -41,6 +41,7 @@
|
||||
#define REAPERAPI_WANT_GetMediaSourceLength
|
||||
#define REAPERAPI_WANT_Undo_BeginBlock2
|
||||
#define REAPERAPI_WANT_Undo_EndBlock2
|
||||
#define REAPERAPI_WANT_GetSelectedTrack
|
||||
#include "reaper_plugin_functions.h"
|
||||
|
||||
namespace reasampler {
|
||||
@@ -419,20 +420,25 @@ ImportResult importFileIntoActiveBank(const std::string& absoluteSourcePath) {
|
||||
// --- Media-Explorer import action --------------------------------------------
|
||||
|
||||
// Import the Media Explorer's current last-played/selected file into the active bank, then
|
||||
// stand up a NEW ReaSampler 9000 instrument on a NEW track pre-loaded with JUST that sound
|
||||
// (S8 surface 2, RS5k "load into a new sampler" parity). This is the ADD-a-new-sound workflow:
|
||||
// it NEVER touches (nor force-selects on) an existing live instance — no assignment_request is
|
||||
// written on this path. Single-file, pull-on-action: MediaExplorerGetLastPlayedFileInfo returns
|
||||
// the ONE last-played file (the whole ME contract — no enumerate-selected API). The selection
|
||||
// RANGE it reports is deliberately IGNORED here: an import brings the whole file into the bank
|
||||
// (the range is a preview hint, and the fields are [0,1] fractions, not seconds — see the
|
||||
// DAW-verify note); a user wanting a sub-range captures it via the arrange path instead.
|
||||
// add a ReaSampler 9000 instrument to the FIRST SELECTED TRACK pre-loaded with that sound.
|
||||
// No new track is created; no routing changes are made — "new sound, existing track."
|
||||
// No assignment_request is written on this path.
|
||||
//
|
||||
// LOAD-BEARING (CLAUDE.md): this creates a track + one FX instance ONLY. It NEVER inserts a
|
||||
// timeline item. Persist ordering is critical — the fresh instance's setState -> reloadFromBank
|
||||
// reads the bank from project ext-state, so the sample MUST be persisted (generation bumped when
|
||||
// something new landed) BEFORE createTrackWithInstrument adds the FX, or the instance cannot
|
||||
// resolve the sampleId. Undo-wrapped: track-create + persist + FX-add + inject = one Ctrl-Z.
|
||||
// Single-file, pull-on-action: MediaExplorerGetLastPlayedFileInfo returns the ONE last-played
|
||||
// file (the whole ME contract — no enumerate-selected API). The selection RANGE it reports is
|
||||
// deliberately IGNORED here: an import brings the whole file into the bank (the range is a
|
||||
// preview hint, and the fields are [0,1] fractions, not seconds — see the DAW-verify note);
|
||||
// a user wanting a sub-range captures it via the arrange path instead.
|
||||
//
|
||||
// LOAD-BEARING (CLAUDE.md): this adds ONE FX instance to the user's existing selected track.
|
||||
// It NEVER inserts a timeline item and NEVER creates a track. Persist ordering is critical —
|
||||
// the fresh instance's setState -> reloadFromBank reads the bank from project ext-state, so
|
||||
// the sample MUST be persisted (generation bumped when something new landed) BEFORE
|
||||
// loadInstrumentOntoTrack adds the FX, or the instance cannot resolve the sampleId.
|
||||
// Undo-wrapped: persist + FX-add + inject = one Ctrl-Z.
|
||||
//
|
||||
// No selected track: the bank import still proceeds (sound is now in the bank), but no
|
||||
// instrument is placed and a clear console message explains why.
|
||||
void doImportFromMediaExplorer() {
|
||||
// filemode/sel/pitch/vol/rate/bpm/extrainfo are read but only the filename is used for
|
||||
// the import. selstart/selend are [0,1] fractions (SDK header) — a preview hint, not a
|
||||
@@ -456,18 +462,37 @@ void doImportFromMediaExplorer() {
|
||||
const ImportResult r = importFileIntoActiveBank(path);
|
||||
if (r.sampleId.empty()) {
|
||||
// Import refused (unsaved project / undecodable / write failure). Report and stop —
|
||||
// no track is created, so there is no orphan to clean up (createTrackWithInstrument was
|
||||
// never reached).
|
||||
// no instrument is placed.
|
||||
ShowConsoleMsg(("ReaSampler ingest: Media Explorer import failed -- " + r.message +
|
||||
".\n").c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// The new track's name follows the imported sound (RS5k parity). The source file stem is
|
||||
// what importFileIntoActiveBank uses for the Sample's displayName, so it names the track
|
||||
// consistently for both a fresh import and a dedup hit.
|
||||
const std::string trackName =
|
||||
std::filesystem::path(path).stem().string();
|
||||
// Resolve the first selected track. GetSelectedTrack(nullptr, 0): proj=nullptr=active
|
||||
// project, seltrackidx=0=first selected (ignores master). Returns null when nothing is
|
||||
// selected — directive: existing track only, never alter the graph.
|
||||
MediaTrack* target = GetSelectedTrack(nullptr, 0);
|
||||
if (!target) {
|
||||
// Sound landed in the bank; no instrument placed because there is no selected track.
|
||||
// The bank import is kept (sound is available in the bank browser) and generation is
|
||||
// bumped so any open VST3 browser instances refresh to show the new sound.
|
||||
if (r.added) {
|
||||
Undo_BeginBlock2(nullptr);
|
||||
g_session->bumpBankGeneration();
|
||||
const bool persisted = g_session->saveToActiveProject();
|
||||
if (persisted)
|
||||
Undo_EndBlock2(nullptr, "ReaSampler: import Media Explorer file into bank",
|
||||
UNDO_STATE_MISCCFG);
|
||||
else
|
||||
Undo_EndBlock2(nullptr, "", 0);
|
||||
bankPanelRefresh();
|
||||
}
|
||||
ShowConsoleMsg(("ReaSampler ingest: " + r.message +
|
||||
" -- select a track first, then import into it "
|
||||
"(sound is in the bank but no instrument was placed because "
|
||||
"no track was selected).\n").c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
// Build the pre-loaded instrument blob for the resolved sampleId. Valid for BOTH the fresh
|
||||
// import and the dedup case (added == false but a real sampleId) — the user asked for a
|
||||
@@ -475,7 +500,7 @@ void doImportFromMediaExplorer() {
|
||||
const std::string chunk = buildInstrumentDropChunk(r.sampleId);
|
||||
|
||||
// One undo point for the whole gesture. Persist happens INSIDE the block and BEFORE the
|
||||
// track/FX so the new instance's setState -> reloadFromBank sees the just-persisted sample.
|
||||
// FX add so the new instance's setState -> reloadFromBank sees the just-persisted sample.
|
||||
// The generation is bumped only when something NEW landed (a dedup collapse mutated nothing,
|
||||
// so it needs neither a bump nor a persist to resolve — the sample is already in ext-state).
|
||||
// If saveToActiveProject() no-ops (unsaved project), close with an empty label + zero flag so
|
||||
@@ -490,23 +515,23 @@ void doImportFromMediaExplorer() {
|
||||
g_session->bumpBankGeneration();
|
||||
persisted = g_session->saveToActiveProject();
|
||||
}
|
||||
MediaTrack* newTrack = createTrackWithInstrument(trackName, chunk);
|
||||
if (newTrack && persisted)
|
||||
Undo_EndBlock2(nullptr, "ReaSampler: import from Media Explorer into new instrument",
|
||||
const bool placed = loadInstrumentOntoTrack(target, chunk);
|
||||
if (placed && persisted)
|
||||
Undo_EndBlock2(nullptr, "ReaSampler: import from Media Explorer into selected track",
|
||||
UNDO_STATE_MISCCFG);
|
||||
else
|
||||
// Either the instrument-side add/inject failed (createTrackWithInstrument already rolled
|
||||
// its own track back — no orphan) or the project was unsaved (persist no-op): discard the
|
||||
// undo entry so no empty point is recorded.
|
||||
// Either the FX add/inject failed (loadInstrumentOntoTrack already rolled the FX back —
|
||||
// no orphan) or the project was unsaved (persist no-op): discard the undo entry so no
|
||||
// empty point is recorded.
|
||||
Undo_EndBlock2(nullptr, "", 0);
|
||||
|
||||
bankPanelRefresh();
|
||||
if (newTrack)
|
||||
if (placed)
|
||||
ShowConsoleMsg(("ReaSampler ingest: " + r.message +
|
||||
" (loaded into a new instrument on a new track).\n").c_str());
|
||||
" (loaded into a new instrument on the selected track).\n").c_str());
|
||||
else
|
||||
ShowConsoleMsg(("ReaSampler ingest: imported to the bank (" + r.message +
|
||||
") but could not create the new instrument track.\n").c_str());
|
||||
") but could not add the instrument to the selected track.\n").c_str());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -587,7 +612,7 @@ void ingestRegisterActions(reaper_plugin_info_t* rec, ReaSamplerSession* session
|
||||
g_idImportStr = channelCommandId(kIdImportMediaExplorer);
|
||||
g_cmdImportMediaExplorer = rec->Register("command_id", (void*)g_idImportStr.c_str());
|
||||
if (g_cmdImportMediaExplorer) {
|
||||
g_labelImportStr = channelActionName("import Media Explorer file into new instrument");
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user