Rebuild the chrome band: full-width piano strip with uniform key widths, note tooltips, one toolbar font

This commit is contained in:
2026-07-30 09:14:07 -04:00
parent ea52b14f2a
commit ae23ee0882
14 changed files with 656 additions and 386 deletions
+123 -20
View File
@@ -1,7 +1,7 @@
// editor_paint_chrome.cpp — the CHROME band's painter: the toolbar row (product title +
// live readout + Browse) and the control row (root/piano strip with its root marker, the
// preview trigger, the preview-velocity knob cell, the curve-preview button, and the
// Mono|Stereo toggle). Windows-only; all rects come from the pure sample_chrome interior.
// live readout, then the control run — preview, preview-velocity knob, curve button,
// Mono|Stereo, Browse) over the strip row, which the piano strip has to itself. Windows-only;
// all rects come from the pure sample_chrome interior and the pure keyboard_strip geometry.
#include "shell/instrument/reasampler_editor.h"
@@ -10,9 +10,11 @@
#include <cstdio>
#include <string>
#include "core/instrument/ui/keyboard_strip.h" // StripLayout / keyRect / noteName
#include "core/instrument/ui/knob_deck.h" // kDeckKnobSize (the shared knob square)
#include "core/ui/tooltip.h" // computeTooltip (shared placement math)
#include "core/version/app_version.h" // vstPluginName (channel-derived title band)
#include "shell/instrument/editor_internal.h" // kit adapters + knob face / spectral strip / root marker
#include "shell/instrument/editor_internal.h" // kit adapters + knob face
#include "shell/instrument/reasampler_processor.h"
namespace reasampler::vst {
@@ -21,9 +23,81 @@ using namespace reasampler::ui; // kit vocabulary
using namespace reasampler::instrument::ui; // chrome geometry + keyboard strip
using namespace reasampler::instrument::map; // SampleRefs / findRef (title readout fallback)
namespace {
// Every text element on the toolbar row draws at this one size/weight — including the
// product title, which used to be the row's odd one out.
constexpr Font kToolbarFont = Font::Label;
// Kit font is proportional, so the char width is a generous estimate (pads, never clips).
constexpr int kTooltipCharPx = 7;
constexpr int kTooltipTextH = 14;
constexpr int kRootBadgeW = 38;
constexpr int kRootBadgeH = 13;
// The piano strip: white keys tiled at one width, black keys overlaid at one width, each
// tinted with its spectral hue so pitch position reads at a glance. `hoverNote` is outlined
// (-1 for none). All rects are strip-local; `area` supplies the origin.
void drawKeyboard(LICE_IBitmap* bmp, const Rect& area, const StripLayout& sl, int hoverNote) {
fillSurface(bmp, toKitBox(area), Role::BgBase, InteractionState::Rest);
if (sl.keys.empty()) return;
const LICE_pixel hairline = toLice(roleColor(Role::LineHairline));
const LICE_pixel shadow = toLice(roleColor(Role::BgBase));
const auto hueOf = [](int n) {
return toLice(spectralColor(static_cast<double>(n) / (kStripKeyCount - 1)));
};
for (int n = 0; n < kStripKeyCount; ++n) {
if (!isNaturalKey(n)) continue;
const Rect k = keyRect(sl, n);
LICE_FillRect(bmp, area.x + k.x, area.y + k.y, k.width, k.height, hueOf(n), 0.55f, 0);
LICE_Line(bmp, area.x + k.right() - 1, area.y + k.y, area.x + k.right() - 1,
area.y + k.bottom() - 1, hairline, 0.6f, 0, false);
}
// Blacks last: they overlap the whites they straddle.
for (int n = 0; n < kStripKeyCount; ++n) {
if (isNaturalKey(n)) continue;
const Rect k = keyRect(sl, n);
LICE_FillRect(bmp, area.x + k.x, area.y + k.y, k.width, k.height, shadow, 1.0f, 0);
LICE_FillRect(bmp, area.x + k.x, area.y + k.y, k.width, k.height, hueOf(n), 0.35f, 0);
}
if (hoverNote >= 0) {
const Rect k = keyRect(sl, hoverNote);
LICE_DrawRect(bmp, area.x + k.x, area.y + k.y, k.width - 1, k.height - 1,
toLice(roleColor(Role::TextPrimary)), 0.8f, 0);
}
}
// The root affordance: the root key lit accent-primary with a static glow, plus a name badge
// (a key is far too narrow to carry text itself). The badge is clamped inside the strip.
void drawRootKey(LICE_IBitmap* bmp, const Rect& area, const StripLayout& sl, int root) {
if (sl.keys.empty()) return;
const Rect k = rootMarkerRect(sl, root);
const int kx = area.x + k.x;
const LICE_pixel accent = toLice(roleColor(Role::AccentPrimary));
const LICE_pixel glow = toLice(roleColor(Role::AccentHot));
// Static glow: a wider low-alpha halo behind the lit key (a drawn state, not a pulse).
LICE_FillRect(bmp, kx - 3, area.y + k.y, k.width + 6, k.height, glow, 0.30f, 0);
LICE_FillRect(bmp, kx, area.y + k.y, k.width, k.height, accent, 1.0f, 0);
const int badgeH = (std::min)(kRootBadgeH, area.height);
const int badgeW = (std::min)(kRootBadgeW, area.width);
int bx = kx + (k.width - badgeW) / 2;
bx = (std::max)(area.x, (std::min)(bx, area.right() - badgeW));
const Rect badge = Rect::ltrb(bx, area.bottom() - badgeH, bx + badgeW, area.bottom());
LICE_FillRect(bmp, badge.x, badge.y, badge.width, badge.height, accent, 0.92f, 0);
kitTextCentered(bmp, badge, noteName(root).c_str(), Font::Micro, Role::BgBase);
}
} // namespace
void ReaSamplerEditor::paintChrome(LICE_IBitmap* bmp, const FaceLayout& fl, bool empty) {
const ChromeRects& cr = fl.chrome;
fillSurface(bmp, toKitBox(cr.toolbar), Role::BgPanel, InteractionState::Rest);
// Toolbar: product name + live readout. The beta channel gets no distinct accent; the
// channel-derived vstPluginName is the only beta-vs-stable signal.
std::string title = version::vstPluginName();
@@ -38,7 +112,7 @@ void ReaSamplerEditor::paintChrome(LICE_IBitmap* bmp, const FaceLayout& fl, bool
} else {
title += " [host: no bridge]";
}
drawTitleBand(bmp, cr.toolbar, title);
kitText(bmp, cr.title, title.c_str(), kToolbarFont, Role::TextPrimary);
// Browse: the picker. When nothing is loaded it is the empty state's dominant
// call-to-action — draw it Active (accent-primary) so it reads as "start here".
@@ -50,19 +124,9 @@ void ReaSamplerEditor::paintChrome(LICE_IBitmap* bmp, const FaceLayout& fl, bool
drawButton(bmp, box, "Browse", st, /*warn=*/false);
}
// The control row draws only once a capture is loaded — with nothing picked there is no
// root, no preview and no channel decision to make.
if (empty || cr.controls.empty()) return;
fillSurface(bmp, toKitBox(cr.controls), Role::BgPanel, InteractionState::Rest);
// Root strip: the full 128-key spectral band with the root marked. The loaded capture
// responds across the whole strip, repitched from that root.
if (cr.rootStrip.width > 0) {
drawSpectralStrip(bmp, cr.rootStrip);
const StripLayout sl = layoutStrip(cr.rootStrip.width, cr.rootStrip.height);
drawRootMarker(bmp, cr.rootStrip, sl, effectiveRoot());
}
// The rest of the run and the strip row draw only once a capture is loaded — with
// nothing picked there is no root, no preview and no channel decision to make.
if (empty) return;
// Preview-trigger button (fires the loaded capture at root through the live voice engine).
{
@@ -106,11 +170,50 @@ void ReaSamplerEditor::paintChrome(LICE_IBitmap* bmp, const FaceLayout& fl, bool
: InteractionState::Rest);
fillSurface(bmp, toKitBox(cr.chanMono), Role::BgCell, monoState);
fillSurface(bmp, toKitBox(cr.chanStereo), Role::BgCell, stereoState);
kitTextCentered(bmp, cr.chanMono, "Mono", Font::Label,
kitTextCentered(bmp, cr.chanMono, "Mono", kToolbarFont,
!isStereo ? Role::BgBase : Role::TextPrimary);
kitTextCentered(bmp, cr.chanStereo, "Stereo", Font::Label,
kitTextCentered(bmp, cr.chanStereo, "Stereo", kToolbarFont,
isStereo ? Role::BgBase : Role::TextPrimary);
}
// The strip row: the full 128-key piano with the root lit. The loaded capture responds
// across the whole strip, repitched from that root.
if (cr.controls.empty() || cr.rootStrip.empty()) return;
fillSurface(bmp, toKitBox(cr.controls), Role::BgPanel, InteractionState::Rest);
const StripLayout sl = layoutStrip(cr.rootStrip.width, cr.rootStrip.height);
// Same staleness guard as the tooltip: a latched hover note outlives a drag it started.
const int hoverNote = (drag_ == DragKind::kNone && hover_.kind == HoverKind::kStripKey)
? hover_.index : -1;
drawKeyboard(bmp, cr.rootStrip, sl, hoverNote);
drawRootKey(bmp, cr.rootStrip, sl, effectiveRoot());
}
// Drawn after every band so the chip is never painted over. No hover delay: the strip is a
// continuous readout you sweep, and a delay there reads as a dead surface — unlike the bank
// panel's buttons, where the delay stops tooltips firing on every traverse.
void ReaSamplerEditor::paintChromeTooltip(LICE_IBitmap* bmp, const FaceLayout& fl, int w,
int h) {
if (hover_.kind != HoverKind::kStripKey || hover_.index < 0) return;
// Hover is deliberately not re-resolved mid-drag, so the latched note would go stale
// under a root drag — the root badge is the live readout there.
if (drag_ != DragKind::kNone) return;
const Rect& area = fl.chrome.rootStrip;
if (area.empty()) return;
const StripLayout sl = layoutStrip(area.width, area.height);
const Rect key = keyRect(sl, hover_.index);
if (key.empty()) return;
const std::string label = noteName(hover_.index);
const int textW = static_cast<int>(label.size()) * kTooltipCharPx;
const TooltipBox tb = computeTooltip(area.x + key.x, area.y + key.y, key.width, key.height,
textW, kTooltipTextH, w, h, TooltipSpec{});
if (tb.empty()) return;
const Rect box = Rect::ltrb(tb.x, tb.y, tb.x + tb.width, tb.y + tb.height);
fillSurface(bmp, toKitBox(box), Role::BgCell, InteractionState::Hover);
LICE_DrawRect(bmp, box.x, box.y, box.width, box.height,
toLice(roleColor(Role::LineHairline)), 1.0f, 0);
kitTextCentered(bmp, box, label.c_str(), Font::Label, Role::TextPrimary);
}
} // namespace reasampler::vst