Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ pedalboard of five pedals — Boost and Chorus before the amp, Flanger, Delay an
A settings page behind the "Captures, MIDI, Settings" button, top right, carrying the capture
loaders, a trim per channel, the MIDI-learn rows and the output section.

**A green lamp beside the Input dial** tells you whether the capture is hearing a level like the
one it was trained on. It lights while your playing peaks between −6 and 0 dBFS at the capture's
input, which is the top of NAM's training signal: turn Input up until your hardest playing lights it.
If it goes dark when you dig in, you are past full scale and the capture is hearing more than it
was ever shown. It reads after the Input dial and, with *Calibrate Input* on, after the
calibration, so it works the same for captures that state their recording level and captures that
do not. The Boost and Chorus pedals do not count towards it; in NAMp Rack, plug-ins you host before
the amp do.

**The knobs.** Drag up or down to turn one, or use the mouse wheel. Hold **Shift** or **Ctrl**
(**Command** on a Mac) for ten times finer control. **Double-click** a knob or a channel trim to
return it to its default. Click the number under Threshold, Bass, Middle, Treble, Input or Output
to **type a value**: Enter or Tab sets it, Escape leaves it alone, and either `2.5` or `2,5` works.
The same applies to the amp in NAMp Rack.

**You load your own captures.** Nothing ships in the bundle. Point each loader at a folder of
`.nam` files or at a single one; the folder's name becomes the channel's name, and you can type
over it.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.6.0
0.7.0
5 changes: 5 additions & 0 deletions core/channelrack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ double ChannelRack::activeIndexNorm() const
return mEngine[mFading ? mTo : mFrom].activeIndexNorm();
}

double ChannelRack::soundingInputGain() const
{
return mEngine[soundingChannel()].dominantInputGain();
}

bool ChannelRack::playable() const
{
return mEngine[mFrom].playable();
Expand Down
5 changes: 5 additions & 0 deletions core/channelrack.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ class ChannelRack : public NativeBlockProcessor
}
// Normalized index of the capture sounding in that channel.
double activeIndexNorm() const;
// The input calibration gain of that capture, for the input-level lamp: 1.0 unless Calibrate
// is on and the capture states its input level, and 0 when the sounding channel has no model
// bound. Read from the channel soundingChannel() names, so the lamp and the channel LEDs
// always describe the same capture. Audio thread only: both ends of a fade belong to it.
double soundingInputGain() const;
bool playable() const;
// Fraction of all four banks that is built and primed. One number rather than four, because
// what the editor shows is one progress line.
Expand Down
9 changes: 7 additions & 2 deletions core/crossfadeengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,14 @@ bool CrossfadeEngine::hasInputLevel() const
return mA.bound() && mBank && mBank->entries[mA.index].hasInputLevel;
}

double CrossfadeEngine::inputLevelDbu() const
// B is the upper neighbour of A and carries weight mPos - A, so it dominates once mPos rounds to
// it. std::round takes the half away from zero, as activeIndexNorm() does, so the two always agree
// on which capture is sounding.
double CrossfadeEngine::dominantInputGain() const
{
return hasInputLevel() ? mBank->entries[mA.index].inputLevelDbu : 0.0;
if (mB.bound() && std::round(mPos) >= static_cast<double>(mB.index))
return mB.inputGain;
return mA.bound() ? mA.inputGain : 0.0;
}

//------------------------------------------------------------------------
Expand Down
8 changes: 6 additions & 2 deletions core/crossfadeengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,13 @@ class CrossfadeEngine : public NativeBlockProcessor
// NativeBlockProcessor.
void processNative(NAM_SAMPLE **in, NAM_SAMPLE **out, int numFrames) override;

// RT, for the processor's input-calibration stage and its editor feedback.
// Whether the capture on branch A states the level it was made at. For the tools' reports.
bool hasInputLevel() const;
double inputLevelDbu() const;
// RT. The input calibration gain of the branch carrying the larger weight: A, or B once the
// dial crossfade has reached the halfway point, the same choice activeIndexNorm() makes. What
// the input-level lamp multiplies the model input by. 0 when no model is bound, so an empty
// or still-building channel never lights it.
double dominantInputGain() const;
int entryCount() const
{
return mBank ? mBank->count : 0;
Expand Down
109 changes: 109 additions & 0 deletions core/inputlevellamp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
// InputLevelLamp — whether the level the sounding capture hears is the level it was trained on.
//
// The green lamp beside the Input knob. It answers one question, and it is a question about the
// MODEL INPUT, not about the interface: the signal after the Input knob and after the sounding
// capture's own input calibration. That gain is exactly 1.0 when Calibrate is off or when the
// capture states no input_level_dbu, so a capture without metadata is judged by the same rule as
// one with it, and nothing is guessed on its behalf. With Calibrate on, it is still the model
// input that is judged: calibration is a gain on that input, so the lamp follows it rather than
// having a second rule for that mode.
//
// The rule is a window on the block's sample peak:
//
// * LIT when the peak is above -6.0 dBFS and at most 0.0 dBFS. The bottom edge is the one
// measured on ML Sound Lab's Amped, whose input LED is off for a -6.0 dBFS peak and on for a
// -5.9 dBFS one, and which reads peak rather than RMS (a burst with the same peak and 10 dB
// less RMS still lights it). It agrees within 2 dB with the NAM training signal itself, the
// same material in the trainer's v2 and v3 inputs: over 300 ms windows, 90% of its peaks are
// at or below -7.8 dBFS. The top edge is that signal's loudest sample, -0.3 dBFS, rounded to
// full scale: above it the capture is hearing a level it was never shown.
// * OFF below the window, once the hold has run out, so a played phrase reads as a steady light
// rather than flickering between notes.
// * OFF above the window at once, and held off for the same hold. The second half is not
// decoration: a hot pick attack decays back through the window within milliseconds, and
// without the hold the lamp would relight before any editor repaint could show it was ever
// dark. Too hot would then be indistinguishable from just right, which is the one thing the
// lamp exists to tell apart. Amped never does this; its LED stays lit to +12 dBFS.
// * OFF at once when no capture is hearing anything (gain 0), so an empty channel, or one still
// building, never shows a light left over from the capture before it.
//
// The hold is a choice, not a measurement. Amped holds full brightness for about 0.2 s and then
// fades over about 2 s; this lamp has two states, so one hold stands in for both.
//
// Real-time contract: process() allocates nothing, takes no lock and calls nothing; the state is
// plain members owned by the audio thread. reset() is called from setupProcessing(), when the
// audio thread is not running.

#pragma once

#include <algorithm>
#include <cmath>

namespace Rations
{

//------------------------------------------------------------------------
class InputLevelLamp
{
public:
// The window, as sample peaks in dBFS at the model input. Lit means kLitAboveDb < peak <=
// kLitAtMostDb. See the top of this file for where each number comes from.
static constexpr double kLitAboveDb = -6.0;
static constexpr double kLitAtMostDb = 0.0;
// How long a peak in the window keeps the lamp lit, and a peak above it keeps the lamp dark.
static constexpr double kHoldSeconds = 1.0;

// Non-RT. The hold is counted in samples, so it has to know the rate it is counting at.
void reset(double sampleRate)
{
mHoldSamples = static_cast<long long>(std::llround(kHoldSeconds * sampleRate));
mLitLeft = 0;
mHotLeft = 0;
}

// RT. One block of the signal the sounding capture is fed, before its input calibration, and
// that calibration's gain. A gain of 0 means no capture is hearing it.
void process(const double *x, int numFrames, double gain)
{
if (!(gain > 0.0)) {
mLitLeft = 0;
mHotLeft = 0;
return;
}
// A NaN sample loses every comparison and so is ignored rather than propagated; an
// infinite one reads as hot, which is the right answer for it.
double peak = 0.0;
for (int i = 0; i < numFrames; ++i)
peak = std::max(peak, std::fabs(x[i]));
peak *= gain;

// Count down by this block first, then let this block restart whichever hold it earned,
// so a peak at the end of a block holds for the full time from there.
const long long elapsed = numFrames > 0 ? numFrames : 0;
mLitLeft = std::max(0LL, mLitLeft - elapsed);
mHotLeft = std::max(0LL, mHotLeft - elapsed);
if (peak > mHotAbove) {
mHotLeft = mHoldSamples;
mLitLeft = 0;
} else if (peak > mLitAbove && mHotLeft == 0) {
mLitLeft = mHoldSamples;
}
}

bool lit() const
{
return mLitLeft > 0 && mHotLeft == 0;
}

private:
// The window's edges as linear peaks. std::pow is not constexpr, so they are worked out once,
// at construction, from the dB constants above rather than written out as bare numbers.
double mLitAbove = std::pow(10.0, kLitAboveDb / 20.0);
double mHotAbove = std::pow(10.0, kLitAtMostDb / 20.0);

long long mHoldSamples = 0;
long long mLitLeft = 0;
long long mHotLeft = 0;
};

} // namespace Rations
7 changes: 4 additions & 3 deletions core/platform/plugview.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// The platform seam: which IPlugView base the editor is built on.
//
// RationsEditorView is written against ONE protected hook set — onAttached,
// onRemoved, onDraw(cairo_t*), onMouseDown/Up/Move/Leave/Wheel, onTick,
// isResizable, constrainSize, onResized, invalidate, isWindowOpen — and knows
// nothing about the windowing system underneath it. Each platform base
// onRemoved, onDraw(cairo_t*), onMouseDown/Up/Move/Leave/Wheel (carrying a
// PointerMod mask from platform/pointermods.h and, on a press, a double-click
// flag), onTick, isResizable, constrainSize, onResized, invalidate,
// isWindowOpen — and knows nothing about the windowing system underneath it. Each platform base
// implements that hook set over its own native window, and this header picks
// one. Nothing else in the plug-in includes a platform header.
//
Expand Down
24 changes: 24 additions & 0 deletions core/platform/pointermods.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Modifier keys held during a pointer event, as the editor sees them on every platform.
//
// Each window class translates its own platform's state into this mask — X's ShiftMask and
// ControlMask, Win32's MK_SHIFT and MK_CONTROL, AppKit's Shift and Command — so the editor's
// gestures are written once and cannot learn which platform they are on. Only the two keys a
// fine-adjust gesture needs are carried: the original plug-in's knobs treat either as "fine"
// (iPlug2's IKnobControlBase::IsFineControl, `mod.C || mod.S`).
//
// kPointerControl is the COMMAND key on macOS, not Control, and that is upstream's mapping rather
// than a choice made here: iPlug2's IGraphicsMac_view.mm builds its IMouseMod with `C` taken from
// NSCommandKeyMask. It is also the only mapping that works there, because a Control-click is a
// right-click on that platform (see macplugview.mm) and so cannot also be a fine left-drag.

#pragma once

namespace Steinberg
{

enum PointerMod : unsigned {
kPointerShift = 1u << 0,
kPointerControl = 1u << 1,
};

} // namespace Steinberg
61 changes: 51 additions & 10 deletions core/platform/win32plugview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ constexpr int kButtonLeft = 1;
constexpr int kButtonMiddle = 2;
constexpr int kButtonRight = 3;

// The X11 view's double-click rule and its two numbers, repeated rather than read from
// GetDoubleClickTime: that is the desktop's preference on this platform and has no counterpart on
// the other, and one gesture behaving two ways is the thing CS_DBLCLKS is left off to avoid.
constexpr DWORD kDoubleClickMs = 400;
constexpr int kDoubleClickSlop = 4;

// MK_SHIFT / MK_CONTROL, the key state every mouse message carries (in the whole of wParam, or in
// its low word for WM_MOUSEWHEEL), as the editor's PointerMod mask.
unsigned pointerMods(WPARAM keys)
{
unsigned mods = 0;
if (keys & MK_SHIFT)
mods |= kPointerShift;
if (keys & MK_CONTROL)
mods |= kPointerControl;
return mods;
}

// One trace summary line per ~1 s, and the threshold above which a repaint is
// interesting enough to log on its own (i.e. the editor was quiet and then
// something woke it up).
Expand Down Expand Up @@ -76,8 +94,11 @@ HINSTANCE thisModule()
//
// CS_DBLCLKS is deliberately NOT set. With it, the second click of a pair
// arrives as WM_LBUTTONDBLCLK instead of WM_LBUTTONDOWN, and the editor would
// simply lose that click. X11 delivers two ordinary presses; this keeps the two
// platforms behaving the same. CS_HREDRAW | CS_VREDRAW invalidate the whole
// simply lose that click. X11 delivers two ordinary presses, and both views
// derive the double-click themselves from those presses by one rule and two
// shared numbers (see pressButton), so the gesture is the same on both
// platforms rather than one rule here and another there. CS_HREDRAW |
// CS_VREDRAW invalidate the whole
// window on a size change, so a resize can never leave a stale edge.
// `proc` is passed in rather than named here because the window procedure is a
// private member of Win32PlugView; openWindow() supplies it.
Expand Down Expand Up @@ -393,13 +414,13 @@ LRESULT Win32PlugView::wndProc(UINT msg, WPARAM wParam, LPARAM lParam)
return 0;

case WM_LBUTTONDOWN:
pressButton(kButtonLeft, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
pressButton(kButtonLeft, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam);
return 0;
case WM_MBUTTONDOWN:
pressButton(kButtonMiddle, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
pressButton(kButtonMiddle, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam);
return 0;
case WM_RBUTTONDOWN:
pressButton(kButtonRight, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
pressButton(kButtonRight, GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), wParam);
return 0;

case WM_LBUTTONUP:
Expand All @@ -422,7 +443,7 @@ LRESULT Win32PlugView::wndProc(UINT msg, WPARAM wParam, LPARAM lParam)
// Already coalesced by the system — a WM_MOUSEMOVE is only
// generated when the queue has none pending, so the X11 side's
// explicit motion compression has no counterpart here.
onMouseMove(mLastMouseX, mLastMouseY);
onMouseMove(mLastMouseX, mLastMouseY, pointerMods(wParam));
return 0;

case WM_MOUSELEAVE:
Expand All @@ -436,14 +457,17 @@ LRESULT Win32PlugView::wndProc(UINT msg, WPARAM wParam, LPARAM lParam)
POINT pt{GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)};
ScreenToClient(mWindow, &pt);

// The key state is the low word here, where every other mouse message carries it as
// the whole of wParam: the high word is the wheel delta.
const unsigned mods = pointerMods(GET_KEYSTATE_WPARAM(wParam));
mWheelRemainder += GET_WHEEL_DELTA_WPARAM(wParam);
while (mWheelRemainder >= WHEEL_DELTA) {
mWheelRemainder -= WHEEL_DELTA;
onMouseWheel(pt.x, pt.y, 1);
onMouseWheel(pt.x, pt.y, 1, mods);
}
while (mWheelRemainder <= -WHEEL_DELTA) {
mWheelRemainder += WHEEL_DELTA;
onMouseWheel(pt.x, pt.y, -1);
onMouseWheel(pt.x, pt.y, -1, mods);
}
return 0;
}
Expand Down Expand Up @@ -518,14 +542,31 @@ LRESULT Win32PlugView::wndProc(UINT msg, WPARAM wParam, LPARAM lParam)
// pointer crosses our window's edge the drag stops receiving WM_MOUSEMOVE and
// the knob freezes. Capture is taken on the first button down and released only
// when the last one comes up.
void Win32PlugView::pressButton(int button, int x, int y)
//
// The double-click is the X11 view's rule, derived from two ordinary presses: the same button
// within kDoubleClickMs and kDoubleClickSlop pixels of the first, and a pair consumed so a third
// press starts a new one. GetMessageTime is that message's own timestamp in milliseconds since the
// system started, and Microsoft's documentation for it says to take the difference of two such
// times ignoring overflow, as unsigned integers — which is what the DWORD subtraction does across
// the 49-day wrap.
void Win32PlugView::pressButton(int button, int x, int y, WPARAM keys)
{
mLastMouseX = x;
mLastMouseY = y;
if (mButtonsDown == 0)
SetCapture(mWindow);
mButtonsDown |= 1u << button;
onMouseDown(x, y, button);

const DWORD now = static_cast<DWORD>(GetMessageTime());
const bool doubleClick = button == mLastPressButton &&
static_cast<DWORD>(now - mLastPressTime) <= kDoubleClickMs &&
std::abs(x - mLastPressX) <= kDoubleClickSlop &&
std::abs(y - mLastPressY) <= kDoubleClickSlop;
mLastPressButton = doubleClick ? 0 : button;
mLastPressTime = now;
mLastPressX = x;
mLastPressY = y;
onMouseDown(x, y, button, pointerMods(keys), doubleClick);
}

void Win32PlugView::releaseButton(int button, int x, int y)
Expand Down
Loading
Loading