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
+34 -21
View File
@@ -1,13 +1,14 @@
// keyboard_strip.h — layout + hit-test + drag math for the editor's keyboard strip.
// Mirror of embed_strip/mode_switch; the shell draws and marshals mouse events into these
// functions.
// keyboard_strip.h — piano-keyboard geometry for the editor's root strip: per-class key
// rects, hit-test, the root marker, and the note name a hovered key reports.
//
// The strip maps the full 128-key MIDI span across a horizontal band (the same idiom
// embed_strip uses). The loaded capture responds across that whole span, so the strip's
// job is the root marker: click a key, or drag the marker, to set the root.
// Same-class keys are one integer width by construction. An arbitrary band width is not
// divisible by the 75 white keys, so the residue lands in symmetric end margins — uniform
// key widths and gap-free edge-to-edge tiling cannot both hold, and uniformity wins.
#pragma once
#include <string>
#include "core/instrument/ui/editor_geometry.h" // Rect, contains
namespace reasampler::instrument::ui {
@@ -16,35 +17,47 @@ namespace reasampler::instrument::ui {
// stay independent.
inline constexpr int kStripKeyCount = 128;
// The keys band takes the whole strip area today; clamped so a degenerate size never
// yields an inverted rect.
// Naturals in MIDI 0..127 (C-1 .. G9): ten full octaves of seven, plus C D E F G.
inline constexpr int kStripWhiteKeyCount = 75;
struct StripLayout {
Rect keys;
Rect band; // the surface handed in, edge to edge
Rect keys; // the tiled key area, kStripWhiteKeyCount * whiteWidth, centred in band
int whiteWidth = 0;
int blackWidth = 0;
int blackHeight = 0; // black keys are short; below them the white key answers
};
// Divide a (w x h) strip area into its regions. Pure.
// Divide a (w x h) strip area into its key geometry. Pure. A band too narrow for one pixel
// per white key yields empty `keys` — nothing draws and nothing hit-tests.
StripLayout layoutStrip(int w, int h);
// x pixel of the LEFT edge of key `note` (0..127) under the linear 128-key map; key N
// occupies [keyLeftX(N), keyLeftX(N+1)). note==128 maps to the band's right edge.
int keyLeftX(const StripLayout& layout, int note);
// True when `note` (clamped to [0,127]) is a natural (white) key in 12-tone equal
// temperament; false for an accidental (black) key.
bool isNaturalKey(int note);
// Half-open rect of a single key `note`, clamped to [0,127].
// Naturals strictly below `note`. For a white key that is its own ordinal; for a black key
// it is the white-key boundary the accidental straddles.
int whiteIndexOf(int note);
// Rect of a single key, clamped to [0,127]. Whites are full band height and whiteWidth
// wide; blacks are blackHeight tall and blackWidth wide, centred on their boundary.
Rect keyRect(const StripLayout& layout, int note);
// Root-marker rect; equivalent to keyRect(layout, rootNote) but named so the intent reads
// at the call site.
Rect rootMarkerRect(const StripLayout& layout, int rootNote);
// MIDI note a point (x, y) lands on, or -1 outside the keys band.
// MIDI note a point (x, y) lands on, or -1 outside the tiled keys. A black key wins inside
// its own short zone; anywhere else the white key beneath answers.
int keyAtPoint(const StripLayout& layout, int x, int y);
// Resolves a drag to a new MIDI note: `startNote` shifted by round(dxPixels / keyWidth),
// clamped to [0,127]. The one arithmetic behind the root-marker drag.
int resolveDragNote(const StripLayout& layout, int startNote, int dxPixels);
// The note a live drag resolves to: keyAtPoint with the point clamped into the key area, so
// a drag that wanders off the strip keeps tracking rather than dropping the edit. -1 only
// when there is no key area at all.
int resolveDragNote(const StripLayout& layout, int x, int y);
// True when `note` (clamped to [0,127]) is a natural (white) key in 12-tone equal
// temperament; false for an accidental (black) key.
bool isNaturalKey(int note);
// DAW convention (the one REAPER uses): MIDI 60 is C4, so MIDI 0 is C-1.
std::string noteName(int note);
} // namespace reasampler::instrument::ui