Stack L/R waveform lanes in stereo mode, with overlays drawn once at full band height

This commit is contained in:
2026-07-30 09:04:57 -04:00
parent 81f5861ba4
commit 2a0d10fab5
9 changed files with 341 additions and 77 deletions
+37 -22
View File
@@ -2,20 +2,20 @@
// span + start/loop markers, and the amp-envelope overlay. Windows-only.
//
// Overlays that ride the waveform (the envelope trace, its node handles, the markers) draw
// ONCE across the full band height, never per lane — the landed contract the stacked-lane
// work consumes.
// ONCE into WaveformSurface::overlay — the full band, spanning both stacked lanes in
// stereo. Never per lane; see waveform_view.h's overlay contract.
#include "shell/instrument/reasampler_editor.h"
#ifdef _WIN32
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <vector>
#include "core/audio/peaks.h" // computeEnvelope (waveform binning)
#include "core/instrument/ui/sample_bands.h" // waveformLanes (the band's lane inventory)
#include "core/instrument/ui/waveform_view.h" // frameToX (waveform markers)
#include "core/instrument/ui/waveform_view.h" // waveformSurface / laneEnvelope / frameToX
#include "shell/instrument/editor_internal.h" // kit adapters
#include "shell/instrument/reasampler_processor.h"
@@ -36,52 +36,67 @@ void ReaSamplerEditor::paintWaveform(LICE_IBitmap* bmp, const Rect& band) {
fillSurface(bmp, toKitBox(band), Role::BgBase, InteractionState::Rest);
if (band.empty()) return;
const std::vector<AudioSample>& pcm = monoPcmFor(selectedId_);
const std::int64_t frames = static_cast<std::int64_t>(pcm.size());
const std::vector<AudioSample>& mono = monoPcmFor(selectedId_);
const std::int64_t frames = static_cast<std::int64_t>(mono.size());
if (frames <= 0) {
kitTextCentered(bmp, band, "(decoding...)", Font::Label, Role::TextDim);
return;
}
// One lane today: the cached PCM is a mono downmix, so there is no second channel to
// draw. The band is already sized for two, and the second lane lights up when the
// per-channel decode lands.
const WaveformLanes lanes = waveformLanes(band, /*stereo=*/false);
const Rect& lane = lanes.upper;
if (lane.width > 0) {
const ChannelPcm& src = channelPcmFor(selectedId_);
const WaveformSurface surface = waveformSurface(
band, channelMode_ == ChannelMode::Stereo, src.channelCount);
if (!surface.upper.empty()) {
// Gap-free: one bin per drawn pixel column (kWaveformOversample == 1, so this
// multiplies by 1). The gap-free draw comes from peaks::columnMinMax's exact
// partition — extra bins produce no visible change. Clamped to frame count below.
// Both lanes share a width, so one bin count serves both.
const std::int64_t wantBins =
static_cast<std::int64_t>((std::max)(1, waveformColumnCount(toKitBox(lane)))) *
static_cast<std::int64_t>(
(std::max)(1, waveformColumnCount(toKitBox(surface.upper)))) *
kWaveformOversample;
const std::size_t bins =
static_cast<std::size_t>(wantBins < frames ? wantBins : frames);
drawEnvelope(bmp, lane, computeEnvelope(pcm, 1, pcm.size(), bins));
if (surface.laneCount == 2) {
// ONE pass over the interleaved source: computeEnvelope already envelopes each
// channel independently, so the second lane costs no second scan of the PCM.
const Envelope env =
computeEnvelope(src.interleaved, static_cast<std::size_t>(src.channelCount),
static_cast<std::size_t>(src.frameCount()), bins);
drawEnvelope(bmp, surface.upper, laneEnvelope(env, 0));
drawEnvelope(bmp, surface.lower, laneEnvelope(env, 1));
} else {
// One lane draws what one lane plays: the downmix, not channel 0 of a stereo
// source.
drawEnvelope(bmp, surface.upper, computeEnvelope(mono, 1, mono.size(), bins));
}
}
// Markers and the loop span run the FULL band height (both lanes), so a stacked view
// reads one loop region rather than two.
// Markers and the loop span are overlays: ONE draw across the full stacked height, so a
// stereo view reads one loop region rather than two.
const Rect& overlay = surface.overlay;
const SetupMarkers m = pickedMarkers(frames);
if (m.hasLoop && m.loopEnd > m.loopStart) {
const int lx = frameToX(band, frames, m.loopStart);
const int rx = frameToX(band, frames, m.loopEnd);
const int lx = frameToX(overlay, frames, m.loopStart);
const int rx = frameToX(overlay, frames, m.loopEnd);
if (rx > lx) {
LICE_FillRect(bmp, lx, band.y, rx - lx, band.height,
LICE_FillRect(bmp, lx, overlay.y, rx - lx, overlay.height,
toLice(roleColor(kRoleLoopMarker)), 0.20f, 0);
}
}
const std::int64_t markerFrames[3] = {m.start, m.loopStart, m.loopEnd};
const Role markerRoles[3] = {kRoleStartMarker, kRoleLoopMarker, kRoleLoopMarker};
for (int i = 0; i < 3; ++i) {
const int mx = frameToX(band, frames, markerFrames[i]);
const int mx = frameToX(overlay, frames, markerFrames[i]);
const bool loopMarker = (i != 0);
const float alpha = (loopMarker && !m.hasLoop) ? 0.4f : 1.0f;
LICE_FillRect(bmp, mx - 1, band.y, 2, band.height,
LICE_FillRect(bmp, mx - 1, overlay.y, 2, overlay.height,
toLice(roleColor(markerRoles[i])), alpha, 0);
}
paintEnvelopeOverlay(bmp, band, frames);
paintEnvelopeOverlay(bmp, overlay, frames);
}
void ReaSamplerEditor::paintEnvelopeOverlay(LICE_IBitmap* bmp, const Rect& waveArea,