Răsfoiți Sursa

VFX Level Scaler: FL's curves, presets, editor

Ka1-S 1 lună în urmă
părinte
comite
1dce2ac0cf
4 a modificat fișierele cu 442 adăugiri și 1 ștergeri
  1. 193 0
      src/core/Vfx.cpp
  2. 20 0
      src/core/Vfx.h
  3. 185 1
      src/ui/VfxEditors.cpp
  4. 44 0
      tests/Vfx164Tests.inc

+ 193 - 0
src/core/Vfx.cpp

@@ -4,6 +4,7 @@
 #include <atomic>
 #include <cmath>
 #include <cstring>
+#include <functional>
 
 #include "core/Song.h"
 #include "flp/Flp.h"
@@ -235,6 +236,110 @@ std::vector<std::uint8_t> writeColorMapper (const ColorMapperSettings& s)
     return out;
 }
 
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Level Scaler (REA_rodada164b §Level Scaler)
+
+bool LevelScalerSettings::identity (int tab) const noexcept
+{
+    return at (tab, multiply) == 8192 && at (tab, offset) == 0 && at (tab, tension) == 0 && at (tab, humanize) == 0;
+}
+
+void resetLevelScalerTab (LevelScalerSettings& s, int tab)
+{
+    // the editor's Reset: bipolar properties are centred
+    s.at (tab, LevelScalerSettings::center) = tab >= LevelScalerSettings::finePitch ? 4096 : 0;
+    s.at (tab, LevelScalerSettings::multiply) = 8192;
+    s.at (tab, LevelScalerSettings::offset) = 0;
+    s.at (tab, LevelScalerSettings::tension) = 0;
+    s.at (tab, LevelScalerSettings::humanize) = 0;
+    s.at (tab, LevelScalerSettings::humanizeMode) = 1;
+}
+
+LevelScalerSettings defaultLevelScaler()
+{
+    LevelScalerSettings s;
+    for (int t = 0; t < LevelScalerSettings::tabCount; ++t)
+        resetLevelScalerTab (s, t);
+    return s;
+}
+
+std::optional<LevelScalerSettings> parseLevelScaler (const std::vector<std::uint8_t>& fl)
+{
+    Reader r { fl.data(), fl.size() };
+    auto s = defaultLevelScaler();
+    s.version = r.u32();
+    if (r.failed)
+        return std::nullopt;
+    if (s.version >= 2)
+        return defaultLevelScaler(); // (FL ignores a state it does not know)
+    // chunks: id, 64-bit size, data (unknown ids skipped)
+    while (r.left() >= 12)
+    {
+        const auto id = r.u32();
+        const auto size = r.get<std::uint64_t>();
+        if (size > r.left())
+            return std::nullopt;
+        const auto end = r.pos + (std::size_t) size;
+        if (id == 0x3ea && size >= 1)
+            s.selectedTab = std::clamp ((int) r.get<std::uint8_t>(), 0, 5);
+        else if (id == 0x3e9 && size >= 144)
+        {
+            static constexpr std::array<std::pair<int, int>, 6> range { { { 0, 8192 }, { -16384, 16384 }, { -8192, 8192 }, { -8192, 8192 }, { 0, 16384 }, { 0, 2 } } };
+            for (int i = 0; i < 36; ++i)
+                s.p[(std::size_t) i] = std::clamp (r.i32(), range[(std::size_t) (i % 6)].first, range[(std::size_t) (i % 6)].second);
+        }
+        r.pos = end;
+    }
+    if (r.failed)
+        return std::nullopt;
+    return s;
+}
+
+std::vector<std::uint8_t> writeLevelScaler (const LevelScalerSettings& s)
+{
+    std::vector<std::uint8_t> out;
+    put<std::uint32_t> (out, 1);
+    put<std::uint32_t> (out, 0x3ea);
+    put<std::uint64_t> (out, 1);
+    put<std::uint8_t> (out, (std::uint8_t) std::clamp (s.selectedTab, 0, 5));
+    put<std::uint32_t> (out, 0x3e9);
+    put<std::uint64_t> (out, 144);
+    for (const auto v : s.p)
+        put<std::int32_t> (out, v);
+    return out;
+}
+
+double levelScale (const LevelScalerSettings& s, int tab, double x, double lo, double hi, double random) noexcept
+{
+    using L = LevelScalerSettings;
+    if (s.identity (tab) || ! (hi > lo))
+        return x;
+    const auto c = s.at (tab, L::center) / 8192.0;
+    const auto scale = 1.0 / std::max (c, 1.0 - c);
+    const auto tension = s.at (tab, L::tension);
+    const auto g = std::pow (8193.0, std::abs (tension) / 8192.0) - 1.0;
+    const auto mul = s.at (tab, L::multiply) / (8192.0 * scale);
+    const auto off = s.at (tab, L::offset) / 8192.0 + c;
+    const auto u = (x - lo) / (hi - lo);
+    const auto d = u - c;
+    const auto m = std::min (1.0, std::abs (d) * scale);
+    auto shape = m;
+    if (tension > 0 && g > 0.0)
+        shape = 1.0 - (std::pow (g + 1.0, 1.0 - m) - 1.0) / g;
+    else if (tension < 0 && g > 0.0)
+        shape = (std::pow (g + 1.0, m) - 1.0) / g;
+    const auto y = std::clamp ((d < 0.0 ? -shape : shape) * mul + off, 0.0, 1.0);
+    auto out = std::clamp (lo + y * (hi - lo), lo, hi);
+    if (const auto h = s.at (tab, L::humanize) / 16384.0; h > 0.0)
+    {
+        const auto mode = s.at (tab, L::humanizeMode);
+        const auto a = mode == 2 ? out : out - (out - lo) * h;
+        const auto b = mode == 0 ? out : out + (hi - out) * h;
+        out = a + std::clamp (random, 0.0, 1.0) * (b - a);
+    }
+    return out;
+}
+
 // ---------------------------------------------------------------------------------------------------------------
 // Presets
 
@@ -300,6 +405,37 @@ std::vector<Preset> builtInPresets (Kind kind)
             inverted.rows[(std::size_t) pc] = { 11 - pc };
         out.push_back ({ "Special", "Inverted", writeKeyMapper (inverted) });
     }
+    if (kind == Kind::levelScaler)
+    {
+        using L = LevelScalerSettings;
+        auto make = [&] (const char* folder, const char* name, std::function<void (L&)> f) {
+            auto s = defaultLevelScaler();
+            f (s);
+            out.push_back ({ folder, name, writeLevelScaler (s) });
+        };
+        make ("Velocity", "Humanize (subtle)", [] (L& s) { s.at (L::velocity, L::humanize) = 2400; });
+        make ("Velocity", "Humanize (strong)", [] (L& s) { s.at (L::velocity, L::humanize) = 6000; });
+        make ("Velocity", "Softer", [] (L& s) { s.at (L::velocity, L::multiply) = 6144; });
+        make ("Velocity", "Compress", [] (L& s) {
+            s.at (L::velocity, L::center) = 6400;
+            s.at (L::velocity, L::multiply) = 4096;
+        });
+        make ("Velocity", "Expand", [] (L& s) {
+            s.at (L::velocity, L::center) = 6400;
+            s.at (L::velocity, L::multiply) = 12288;
+        });
+        make ("Velocity", "Fixed", [] (L& s) {
+            s.at (L::velocity, L::multiply) = 0;
+            s.at (L::velocity, L::offset) = 6400;
+        });
+        make ("Velocity", "Inverted", [] (L& s) {
+            s.at (L::velocity, L::center) = 4096;
+            s.at (L::velocity, L::multiply) = -8192;
+        });
+        make ("Other", "Random pan", [] (L& s) { s.at (L::pan, L::humanize) = 8192; });
+        make ("Other", "Detune (random fine pitch)", [] (L& s) { s.at (L::finePitch, L::humanize) = 300; });
+        make ("Other", "Short releases", [] (L& s) { s.at (L::release, L::offset) = -4096; });
+    }
     return out;
 }
 
@@ -326,6 +462,7 @@ std::vector<std::uint8_t> defaultState (Kind kind)
     {
         case Kind::keyMapper: return writeKeyMapper (defaultKeyMapper());
         case Kind::colorMapper: return writeColorMapper (defaultColorMapper());
+        case Kind::levelScaler: return writeLevelScaler (defaultLevelScaler());
         default: break;
     }
     return {};
@@ -699,6 +836,60 @@ public:
 };
 } // namespace
 
+namespace
+{
+// One voice in, one voice out, its velocity, fine pitch, pan, Mod X / Y and release velocity through the curves.
+// (FL re-evaluates the curves every tick from the parent's live levels; LYNX applies them when the note starts and
+// to its release velocity when it ends: the voices' levels do not change on their way here.)
+class LevelScaler final : public Base<LevelScalerSettings>
+{
+public:
+    explicit LevelScaler (LevelScalerSettings s) : Base (std::move (s)) {}
+    Kind kind() const noexcept override { return Kind::levelScaler; }
+    bool configure (const std::vector<std::uint8_t>& fl) override
+    {
+        auto s = parseLevelScaler (fl);
+        if (! s)
+            return false;
+        publish (std::move (*s));
+        return true;
+    }
+    void process (const Event* in, int count, int, const Transport&, EventList& out) noexcept override
+    {
+        using L = LevelScalerSettings;
+        const auto& s = current();
+        for (int i = 0; i < count; ++i)
+        {
+            const auto& e = in[i];
+            if (e.type == Event::Type::on)
+            {
+                auto v = e.voice;
+                // (FL's order: pan, Mod X, Mod Y, fine pitch, velocity; each with its own random, fixed for the note)
+                v.pan = (float) levelScale (s, L::pan, v.pan, -1.0, 1.0, random());
+                v.modX = (float) (levelScale (s, L::modX, v.modX * 2.0 - 1.0, -1.0, 1.0, random()) * 0.5 + 0.5);
+                v.modY = (float) (levelScale (s, L::modY, v.modY * 2.0 - 1.0, -1.0, 1.0, random()) * 0.5 + 0.5);
+                v.cents = (float) (levelScale (s, L::finePitch, v.cents / 1200.0, -1.0, 1.0, random()) * 1200.0);
+                v.velocity = (float) levelScale (s, L::velocity, v.velocity, 0.0, 1.0, random());
+                if (const auto id = voices.add (e.id, 0, v); id >= 0)
+                    out.add (onEvent (e.offset, 0, id, v));
+            }
+            else if (e.type == Event::Type::off)
+                voices.release (e.id, e.offset, (float) levelScale (s, L::release, e.voice.release, 0.0, 1.0, random()), out);
+        }
+    }
+
+private:
+    double random() noexcept
+    {
+        seed ^= seed << 13;
+        seed ^= seed >> 17;
+        seed ^= seed << 5;
+        return (double) (seed >> 8) / 16777216.0;
+    }
+    std::uint32_t seed = 0x2545f491u;
+};
+} // namespace
+
 std::unique_ptr<Processor> makeProcessor (Kind kind, const std::vector<std::uint8_t>& fl)
 {
     switch (kind)
@@ -707,6 +898,8 @@ std::unique_ptr<Processor> makeProcessor (Kind kind, const std::vector<std::uint
             return std::make_unique<KeyMapper> (parseKeyMapper (fl).value_or (defaultKeyMapper()));
         case Kind::colorMapper:
             return std::make_unique<ColorMapper> (parseColorMapper (fl).value_or (defaultColorMapper()));
+        case Kind::levelScaler:
+            return std::make_unique<LevelScaler> (parseLevelScaler (fl).value_or (defaultLevelScaler()));
         default: break;
     }
     return std::make_unique<ThroughProcessor> (kind);

+ 20 - 0
src/core/Vfx.h

@@ -144,6 +144,26 @@ ColorMapperSettings defaultColorMapper();
 std::optional<ColorMapperSettings> parseColorMapper (const std::vector<std::uint8_t>& fl);
 std::vector<std::uint8_t> writeColorMapper (const ColorMapperSettings& s);
 
+// VFX Level Scaler: per voice property (tab) a transfer curve: Center, Multiply, Offset, Tension, Humanize (+ mode)
+struct LevelScalerSettings
+{
+    enum Tab { velocity, release, finePitch, pan, modX, modY, tabCount };
+    enum Field { center, multiply, offset, tension, humanize, humanizeMode, fieldCount };
+    std::uint32_t version = 1;
+    int selectedTab = 0;                 // (the editor's)
+    std::array<std::int32_t, 36> p {};   // p[6 · tab + field], FL's units (Center 0…8192, Multiply ±16384 = ×±2, …)
+    int& at (int tab, int field) noexcept { return p[(std::size_t) (tab * 6 + field)]; }
+    int at (int tab, int field) const noexcept { return p[(std::size_t) (tab * 6 + field)]; }
+    bool identity (int tab) const noexcept; // (passes the value untouched)
+    bool operator== (const LevelScalerSettings&) const = default;
+};
+LevelScalerSettings defaultLevelScaler();
+void resetLevelScalerTab (LevelScalerSettings& s, int tab);
+std::optional<LevelScalerSettings> parseLevelScaler (const std::vector<std::uint8_t>& fl);
+std::vector<std::uint8_t> writeLevelScaler (const LevelScalerSettings& s);
+// The curve: x in lo…hi → out in lo…hi; `random` 0…1 places it in the humanize range (FL's T(tab, x, lo, hi, rnd))
+double levelScale (const LevelScalerSettings& s, int tab, double x, double lo, double hi, double random) noexcept;
+
 // ---------------------------------------------------------------------------------------------------------------
 // Presets
 

+ 185 - 1
src/ui/VfxEditors.cpp

@@ -124,7 +124,7 @@ ui::ValueSpec intSpec (const juce::String& name, int lo, int hi, int def, std::f
     s.maximum = hi;
     s.defaultValue = def;
     s.interval = 1.0;
-    s.pixelsForRange = std::max (120.0, (double) (hi - lo) * 6.0);
+    s.pixelsForRange = std::clamp ((double) (hi - lo) * 6.0, 120.0, 300.0);
     if (text)
     {
         s.toText = text;
@@ -471,6 +471,189 @@ private:
     std::array<juce::ComboBox, 16> ports, colours;
 };
 
+// ---------------------------------------------------------------------------------------------------------------
+// VFX Level Scaler: a tab per voice property, its curve's controls on the left, the curve on the right
+
+class LevelScalerBody final : public Body
+{
+public:
+    using L = vfx::LevelScalerSettings;
+
+    LevelScalerBody()
+    {
+        static const char* names[] = { TR_NOOP ("Velocity"), TR_NOOP ("Release"), TR_NOOP ("Fine pitch"), TR_NOOP ("Pan"), TR_NOOP ("Mod X"), TR_NOOP ("Mod Y") };
+        for (int t = 0; t < L::tabCount; ++t)
+        {
+            auto& b = tabs[(std::size_t) t];
+            b.setButtonText (tr (names[t]));
+            b.setClickingTogglesState (false);
+            b.setColour (juce::TextButton::buttonOnColourId, theme::colour::accentMuted);
+            b.onClick = [this, t] { change ([t] (L& st) { st.selectedTab = t; }); };
+            addAndMakeVisible (b);
+        }
+        auto knob = [this] (Knob& k, const juce::String& caption) {
+            k.caption = caption;
+            addAndMakeVisible (k);
+        };
+        knob (center, tr ("Center"));
+        knob (multiply, tr ("Multiply"));
+        knob (offset, tr ("Offset"));
+        knob (tension, tr ("Tension"));
+        knob (humanize, tr ("Humanize"));
+        mode.addItem (tr ("Subtract"), 1);
+        mode.addItem (tr ("Spread"), 2);
+        mode.addItem (tr ("Add"), 3);
+        mode.onChange = [this] { set (L::humanizeMode, mode.getSelectedId() - 1); };
+        ui::setHint (mode, tr ("Humanize mode: the random part goes below the value, around it or above it"));
+        addAndMakeVisible (mode);
+        reset.setButtonText (tr ("Reset"));
+        ui::setHint (reset, tr ("Reset all controls of this property"));
+        reset.onClick = [this] { change ([] (L& st) { vfx::resetLevelScalerTab (st, st.selectedTab); }); };
+        addAndMakeVisible (reset);
+    }
+
+    void refresh (const std::vector<std::uint8_t>& fl) override
+    {
+        settings = vfx::parseLevelScaler (fl).value_or (vfx::defaultLevelScaler());
+        for (int t = 0; t < L::tabCount; ++t)
+            tabs[(std::size_t) t].setToggleState (t == settings.selectedTab, juce::dontSendNotification);
+        mode.setSelectedId (std::clamp (settings.at (settings.selectedTab, L::humanizeMode), 0, 2) + 1, juce::dontSendNotification);
+        for (auto* k : { &center, &multiply, &offset, &tension, &humanize })
+            k->repaint();
+        repaint();
+    }
+
+    int preferredHeight() const override { return 360; }
+    int preferredWidth() const override { return 700; }
+
+    void resized() override
+    {
+        auto area = getLocalBounds().reduced (12, 6);
+        auto top = area.removeFromTop (28);
+        for (auto& b : tabs)
+            b.setBounds (top.removeFromLeft (92).reduced (2, 0));
+        area.removeFromTop (8);
+        auto left = area.removeFromLeft (230);
+        auto row1 = left.removeFromTop (92);
+        for (auto* k : { &center, &multiply, &offset })
+            k->setBounds (row1.removeFromLeft (76));
+        auto row2 = left.removeFromTop (92);
+        for (auto* k : { &tension, &humanize })
+            k->setBounds (row2.removeFromLeft (76));
+        auto side = row2.reduced (2, 14);
+        mode.setBounds (side.removeFromTop (26));
+        left.removeFromTop (8);
+        reset.setBounds (left.removeFromTop (26).withWidth (100));
+        graph = area.reduced (10, 0).toFloat();
+    }
+
+    void paint (juce::Graphics& g) override
+    {
+        if (graph.isEmpty())
+            return;
+        const auto tab = settings.selectedTab;
+        const auto bipolar = tab >= L::finePitch;
+        const auto lo = bipolar ? -1.0 : 0.0, hi = 1.0;
+        g.setColour (theme::colour::bg0);
+        g.fillRoundedRectangle (graph, 4.0f);
+        g.setColour (theme::colour::border);
+        for (int k = 1; k < 8; ++k)
+        {
+            g.drawVerticalLine ((int) (graph.getX() + graph.getWidth() * (float) k / 8.0f), graph.getY(), graph.getBottom());
+            g.drawHorizontalLine ((int) (graph.getY() + graph.getHeight() * (float) k / 8.0f), graph.getX(), graph.getRight());
+        }
+        g.setColour (theme::colour::textDisabled);
+        g.setFont (theme::font (theme::type::title, true));
+        g.drawText (tabs[(std::size_t) tab].getButtonText(), graph.reduced (12.0f, 8.0f), juce::Justification::topLeft);
+        auto point = [&] (double u, double y) {
+            return juce::Point<float> (graph.getX() + (float) u * graph.getWidth(), graph.getBottom() - (float) ((y - lo) / (hi - lo)) * graph.getHeight());
+        };
+        g.setColour (theme::colour::borderStrong);
+        g.drawLine (juce::Line<float> (point (0.0, lo), point (1.0, hi)), 1.0f);
+        juce::Path curve, upper, lower;
+        constexpr int steps = 160;
+        for (int k = 0; k <= steps; ++k)
+        {
+            const auto u = (double) k / steps;
+            const auto x = lo + u * (hi - lo);
+            const auto p = point (u, vfx::levelScale (settings, tab, x, lo, hi, 0.5));
+            const auto a = point (u, vfx::levelScale (settings, tab, x, lo, hi, 0.0));
+            const auto b = point (u, vfx::levelScale (settings, tab, x, lo, hi, 1.0));
+            if (k == 0)
+            {
+                curve.startNewSubPath (p);
+                lower.startNewSubPath (a);
+                upper.startNewSubPath (b);
+            }
+            else
+            {
+                curve.lineTo (p);
+                lower.lineTo (a);
+                upper.lineTo (b);
+            }
+        }
+        if (settings.at (tab, L::humanize) > 0)
+        {
+            juce::Path band (upper);
+            for (int k = steps; k >= 0; --k)
+            {
+                const auto u = (double) k / steps;
+                band.lineTo (point (u, vfx::levelScale (settings, tab, lo + u * (hi - lo), lo, hi, 0.0)));
+            }
+            band.closeSubPath();
+            g.setColour (theme::colour::accent.withAlpha (0.16f));
+            g.fillPath (band);
+            g.setColour (theme::colour::accent.withAlpha (0.45f));
+            g.strokePath (upper, juce::PathStrokeType (1.0f));
+            g.strokePath (lower, juce::PathStrokeType (1.0f));
+        }
+        g.setColour (theme::colour::accent);
+        g.strokePath (curve, juce::PathStrokeType (2.2f));
+        g.setColour (theme::colour::borderStrong);
+        g.drawRoundedRectangle (graph, 4.0f, 1.0f);
+        g.setColour (theme::colour::textSecondary);
+        g.setFont (theme::font (theme::type::caption));
+        g.drawText (tr ("in"), graph.withTrimmedTop (graph.getHeight() - 16.0f).reduced (6.0f, 0.0f), juce::Justification::centredRight);
+        g.drawText (tr ("out"), graph.reduced (6.0f, 4.0f).withHeight (14.0f), juce::Justification::centredRight);
+    }
+
+private:
+    void change (std::function<void (L&)> f)
+    {
+        if (edit)
+            edit ([f] (std::vector<std::uint8_t>& fl) {
+                auto s = vfx::parseLevelScaler (fl).value_or (vfx::defaultLevelScaler());
+                f (s);
+                fl = vfx::writeLevelScaler (s);
+            });
+    }
+    void set (int field, double v)
+    {
+        change ([field, v] (L& st) { st.at (st.selectedTab, field) = (int) std::lround (v); });
+    }
+    double get (int field) const { return settings.at (settings.selectedTab, field); }
+    static juce::String percent (double v) { return juce::String (v * 100.0, 0) + "%"; }
+
+    L settings = vfx::defaultLevelScaler();
+    std::array<juce::TextButton, L::tabCount> tabs;
+    Knob center { intSpec (tr ("Center: the input level the curve turns around"), 0, 8192, 0, [] (double v) { return percent (v / 8192.0); }),
+                  [this] { return get (L::center); }, [this] (double v) { set (L::center, v); } };
+    Knob multiply { intSpec (tr ("Multiply: the slope around the center (negative inverts)"), -16384, 16384, 8192,
+                             [] (double v) { return juce::String::charToString (0xd7) + juce::String (v / 8192.0, 2); }),
+                    [this] { return get (L::multiply); }, [this] (double v) { set (L::multiply, v); } };
+    Knob offset { intSpec (tr ("Offset: moves every value up or down"), -8192, 8192, 0,
+                           [] (double v) { return (v > 0 ? "+" : "") + percent (v / 8192.0); }),
+                  [this] { return get (L::offset); }, [this] (double v) { set (L::offset, v); } };
+    Knob tension { intSpec (tr ("Tension: bends the curve (positive rises fast, negative starts slow)"), -8192, 8192, 0,
+                            [] (double v) { return (v > 0 ? "+" : "") + percent (v / 8192.0); }),
+                   [this] { return get (L::tension); }, [this] (double v) { set (L::tension, v); } };
+    Knob humanize { intSpec (tr ("Humanize: a random amount for each note"), 0, 16384, 0, [] (double v) { return percent (v / 16384.0); }),
+                    [this] { return get (L::humanize); }, [this] (double v) { set (L::humanize, v); } };
+    juce::ComboBox mode;
+    juce::TextButton reset;
+    juce::Rectangle<float> graph;
+};
+
 // A kind LYNX does not edit yet: says so (its notes pass through)
 class PendingBody final : public Body
 {
@@ -492,6 +675,7 @@ std::unique_ptr<Body> makeBody (vfx::Kind kind)
     {
         case vfx::Kind::keyMapper: return std::make_unique<KeyMapperBody>();
         case vfx::Kind::colorMapper: return std::make_unique<ColorMapperBody>();
+        case vfx::Kind::levelScaler: return std::make_unique<LevelScalerBody>();
         default: break;
     }
     return std::make_unique<PendingBody>();

+ 44 - 0
tests/Vfx164Tests.inc

@@ -316,3 +316,47 @@ TEST (vfx_key_mapper_pitch_slide_glides_to_the_new_note)
     }
     CHECK (steps == 18 && last < 1200.0f * 0.02f); // ~99 % of the way after 3 steps
 }
+
+TEST (vfx_level_scaler_curves_match_fl)
+{
+    using L = lynx::vfx::LevelScalerSettings;
+    auto s = lynx::vfx::defaultLevelScaler();
+    const auto fl = lynx::vfx::writeLevelScaler (s);
+    CHECK (fl.size() == 173);
+    CHECK (lynx::vfx::parseLevelScaler (fl) == s);
+    CHECK (lynx::vfx::levelScale (s, L::velocity, 0.3, 0.0, 1.0, 0.5) == 0.3); // identity
+    auto near = [] (double a, double b, double eps = 1e-4) { return std::abs (a - b) < eps; };
+    s.at (L::velocity, L::multiply) = 6842; // AutoBeat Lite
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.78125, 0.0, 1.0, 0.0), 0.652504));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::velocity, L::tension) = 8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.989073));
+    s.at (L::velocity, L::tension) = -8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.010927));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::finePitch, L::multiply) = 4096;
+    CHECK (near (lynx::vfx::levelScale (s, L::finePitch, 0.5, -1.0, 1.0, 0.0) * 1200.0, 300.0, 0.01));
+    CHECK (near (lynx::vfx::levelScale (s, L::finePitch, -1.0, -1.0, 1.0, 0.0) * 1200.0, -600.0, 0.01));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::pan, L::offset) = 4096;
+    CHECK (near (lynx::vfx::levelScale (s, L::pan, 0.0, -1.0, 1.0, 0.0), 1.0));
+    CHECK (near (lynx::vfx::levelScale (s, L::pan, -1.0, -1.0, 1.0, 0.0), 0.0));
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::modX, L::multiply) = -8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::modX, 0.4, -1.0, 1.0, 0.0), -0.4));
+    // humanize: spread around the value, subtract below, add above
+    s = lynx::vfx::defaultLevelScaler();
+    s.at (L::velocity, L::humanize) = 8192;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.25) && near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 1.0), 0.75));
+    s.at (L::velocity, L::humanizeMode) = 0;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 1.0), 0.5));
+    s.at (L::velocity, L::humanizeMode) = 2;
+    CHECK (near (lynx::vfx::levelScale (s, L::velocity, 0.5, 0.0, 1.0, 0.0), 0.5));
+    // the processor: a fixed velocity
+    auto fixed = lynx::vfx::defaultLevelScaler();
+    fixed.at (L::velocity, L::multiply) = 0;
+    fixed.at (L::velocity, L::offset) = 4096;
+    auto p = lynx::vfx::makeProcessor (lynx::vfx::Kind::levelScaler, lynx::vfx::writeLevelScaler (fixed));
+    const auto out = vfx164::run (*p, { vfx164::on (60, 0, 0, 0.9f), vfx164::on (64, 0, 0, 0.2f) });
+    CHECK (out.size() == 2 && near (out[0].voice.velocity, 0.5) && near (out[1].voice.velocity, 0.5) && out[0].voice.key == 60);
+}