Cut shell/panel comment bloat ~47% (comments only, zero code change)

This commit is contained in:
2026-07-29 20:48:56 -04:00
parent 1f24c4b095
commit cc36dd59c7
15 changed files with 627 additions and 1320 deletions
+31 -66
View File
@@ -1,16 +1,11 @@
// panel_window.cpp — the window-lifecycle seam of the docked bank panel (Q-W2 split
// of bank_panel.cpp; M5 Wave A). Owns the SWELL dialog (IDD_BANK_PANEL) docked via
// DockWindowAddEx / undocked via DockWindowRemove, the dialog proc that routes
// messages to the input/drag/render/audition seams, the S8 OS drop-target opt-in
// (WM_DROPFILES -> ingest), and the shared PanelState blob's definition.
// panel_window.cpp — window-lifecycle seam of the docked bank panel. Owns the SWELL
// dialog (docked via DockWindowAddEx / undocked via DockWindowRemove), the dialog
// proc routing to the input/drag/render/audition seams, the OS drop-target opt-in
// (WM_DROPFILES -> ingest), and the shared PanelState blob's definition. The panel
// never inserts into the arrange. Dock title + persisted-position identstr both
// come from app_version (channel-qualified).
//
// READ-ONLY of the TIMELINE (load-bearing principle): the panel never inserts into
// the arrange. Channel-qualified dock identity (Phase V, V4): title + persisted-
// position identstr both come from app_version.
//
// 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; here they are extern. DAW-verified, not unit tested.
#include <string>
#include <vector>
@@ -18,12 +13,12 @@
#include "shell/panel/panel_state.h"
#include "shell/panel/panel_window.h"
#include "shell/panel/draw_kit.h" // kitFontsInit/Shutdown — the kit's cached AA fonts (L1)
#include "ingest.h" // ingestDroppedFiles — S8 drop-onto-panel ingest
#include "shell/panel/draw_kit.h"
#include "ingest.h"
#ifdef _WIN32
#include <windowsx.h> // GET_X_LPARAM / GET_Y_LPARAM (SWELL supplies them on mac/linux)
#include <shellapi.h> // DragAcceptFiles / DragQueryFile / DragFinish — S8 drop ingest
#include <shellapi.h> // DragAcceptFiles / DragQueryFile / DragFinish
#endif
#include "resource.h"
@@ -40,26 +35,20 @@ extern REAPER_PLUGIN_HINSTANCE g_hInst;
namespace reasampler::panel {
// The one shared panel state blob (declared extern in panel_state.h). Defined here —
// the lifecycle seam owns the state's lifetime, mirroring the old single-TU global.
// Defined here — the lifecycle seam owns the state's lifetime.
PanelState g_panel;
// --- Dialog proc + docking ----------------------------------------------------
namespace {
// Decodes a WM_DROPFILES HDROP into the dropped file paths (absolute, OS-native) and hands
// them to the S8 ingest path. Multi-file drop: ingestDroppedFiles imports all into the active
// bank (bank-fill only — no assignment to any live instance). Always DragFinish's the HDROP
// (frees the shell-allocated drop buffer) on every path. DragQueryFile(hDrop, 0xFFFFFFFF, ...)
// returns the file count; then each path is queried by index. Both Win32 and SWELL expose
// DragQueryFile/DragFinish with this contract.
// DragQueryFile(hDrop, 0xFFFFFFFF, ...) returns the file count; each path is then
// queried by index (length first, excludes NUL, then a sized buffer). DragFinish
// always frees the shell-allocated drop buffer. Multi-file drop imports all into
// the active bank (bank-fill only — no assignment to any live instance).
void handleDropFiles(HDROP hDrop) {
std::vector<std::string> paths;
const UINT count = DragQueryFile(hDrop, 0xFFFFFFFF, nullptr, 0);
paths.reserve(count);
for (UINT i = 0; i < count; ++i) {
// Query the required length first (excludes the NUL), then read into a sized buffer.
const UINT len = DragQueryFile(hDrop, i, nullptr, 0);
if (len == 0) continue;
std::vector<char> buf(static_cast<std::size_t>(len) + 1, '\0');
@@ -74,8 +63,6 @@ void handleDropFiles(HDROP hDrop) {
WDL_DLGRET dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
switch (msg) {
case WM_DROPFILES:
// S8 drop-onto-panel ingest: OS file drop on the docked panel HWND -> import
// into the active bank (bank-fill only). wParam is the HDROP.
handleDropFiles(reinterpret_cast<HDROP>(wParam));
return 0;
case WM_PAINT: {
@@ -101,10 +88,8 @@ WDL_DLGRET dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
handleRightClick(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
return 0;
case WM_CAPTURECHANGED:
// Capture lost (pointer left window pre-threshold and released outside, or another
// window stole capture mid-drag) — cancel the whole drag as a NO-OP so no stale
// state lingers, mirroring onLBtnUp's reset (peer-path symmetry). Nothing is
// mutated on a cancel; the cursor is restored to the arrow.
// Capture lost (pointer left pre-threshold, or another window stole it
// mid-drag) — cancel the drag as a no-op, mirroring onLBtnUp's reset.
if (g_panel.dragArmed || g_panel.dragging) {
resetDragState();
SetCursor(LoadCursor(nullptr, IDC_ARROW));
@@ -112,13 +97,9 @@ WDL_DLGRET dlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
}
return 0;
case WM_MOUSEWHEEL: {
// Fine-adjust the Manual tail length when the wheel is over the footer.
// UNLIKE the button messages, WM_MOUSEWHEEL carries SCREEN coordinates in
// lParam (Win32 and SWELL agree — swell-generic-gdk.cpp §WM_MOUSEWHEEL), so
// convert to client space before hit-testing the footer. The signed wheel
// delta is the HIWORD of wParam (SWELL packs it as (delta<<16), delta=+/-120,
// matching GET_WHEEL_DELTA_WPARAM). Consume (return 1) only when the footer
// handler acts, so scrolling elsewhere in the dock still behaves normally.
// Unlike button messages, WM_MOUSEWHEEL carries SCREEN coords in lParam
// (Win32 and SWELL agree), so convert to client space first. Wheel delta
// is the HIWORD of wParam. Consume (return 1) only when the footer acts.
POINT pt{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
ScreenToClient(hwnd, &pt);
const int delta = static_cast<short>(HIWORD(wParam));
@@ -147,30 +128,23 @@ void openPanel() {
}
initPreview();
// Create the kit's cached AA fonts before the first paint (Phase L, L1). Idempotent, so
// a reopen after closePanel (which leaves the fonts alive) is a cheap no-op; the fonts
// are torn down once at bankPanelShutdown. All panel text draws through these.
// Idempotent — a reopen after closePanel (fonts left alive) is a cheap no-op;
// torn down once at bankPanelShutdown.
kitFontsInit();
g_panel.hwnd = CreateDialogParam(g_hInst, MAKEINTRESOURCE(IDD_BANK_PANEL),
GetMainHwnd(), dlgProc, 0);
if (!g_panel.hwnd) return;
// Channel-qualified dock identity (Phase V, V4). The title and the persisted-position
// identstr both come from app_version, so a beta panel is distinguishable ("ReaSampler
// Bank beta") and does not fight over stable's saved dock slot (the identstr is a
// REAPER-global collision surface — it keys the persisted dock position).
// identstr is a REAPER-global collision surface keying the persisted dock
// position — channel-qualified so beta doesn't fight over stable's slot.
DockWindowAddEx(g_panel.hwnd, dockTitle().c_str(), dockIdent().c_str(), true);
DockWindowActivate(g_panel.hwnd);
g_panel.open = true;
// S8: accept OS file drops on the panel HWND (WM_DROPFILES routes to handleDropFiles).
// DragAcceptFiles is a native Win32 shell call (shellapi.h); SWELL does NOT expose it,
// so the opt-in is Windows-only here. The primary/shipped platform is Windows (the VST3
// instrument the drop assigns to is Windows-only, D5); a mac/linux drop-registration
// surface is out of scope for this dispatch. WM_DROPFILES handling itself uses
// DragQueryFile/DragFinish, which SWELL DOES provide, so a drop delivered by other means
// would still ingest — only the accept opt-in is gated.
// DragAcceptFiles is native Win32 (shellapi.h); SWELL doesn't expose it, so the
// accept opt-in is Windows-only. DragQueryFile/DragFinish ARE SWELL-provided,
// so a drop delivered by other means would still ingest.
#ifdef _WIN32
DragAcceptFiles(g_panel.hwnd, TRUE);
#endif
@@ -199,27 +173,20 @@ void closePanel() {
} // namespace reasampler::panel
// --- Public API (the lifecycle seam — panel_window.h) --------------------------
namespace reasampler {
void bankPanelInit(ReaSamplerSession* session) {
panel::g_panel.session = session;
}
// Returns true only when the panel window is actually visible to the user right now.
// IsWindowVisible() returns false when the docker is hidden via Alt+D even though the
// HWND and g_panel.open are still live — the live query is the source of truth for
// toggle decisions and the Actions-list checkmark (OnToggleAction in main.cpp).
// Alt+D hides the docker without destroying the window, leaving HWND/g_panel.open
// live but IsWindowVisible false the live query is the source of truth for
// toggle decisions and the Actions-list checkmark.
static bool panelEffectivelyVisible() {
return panel::g_panel.hwnd && IsWindowVisible(panel::g_panel.hwnd);
}
void bankPanelToggle() {
// Decide from live visibility, not the cached g_panel.open flag.
// Alt+D hides the docker without destroying the window, leaving g_panel.open
// stale (true) while the panel is gone. Using IsWindowVisible avoids the
// double-fire needed to re-show the panel after a docker hide.
if (panelEffectivelyVisible())
panel::closePanel();
else
@@ -227,8 +194,6 @@ void bankPanelToggle() {
}
bool bankPanelIsOpen() {
// Derive from live window state so the Actions-list checkmark stays honest
// even after Alt+D hides the docker without notifying the extension.
return panelEffectivelyVisible();
}
@@ -239,7 +204,7 @@ void bankPanelInvalidate() {
void bankPanelShutdown() {
panel::closePanel();
panel::deinitPreview();
kitFontsShutdown(); // free the kit's cached AA fonts + their owned HFONTs (L1)
kitFontsShutdown();
panel::g_panel.cache.clear();
panel::g_panel.session = nullptr;
}