Parcourir la source

Merge branch 'feature/flbeta165s'

Ka1-S il y a 1 mois
Parent
commit
1e2ecf26ec

+ 9 - 3
docs/STATUS.md

@@ -242,6 +242,9 @@ accordingly. Highlights of what is **confirmed and applied**:
   CPU: AVX bank kernel (8 partials per pass), running sine pairs across frequency changes (steps by complex rotation
   along the harmonic series), fast per-partial exp/log, cached k^m, idle records/channels skipped; "Square a Saw —
   Oxygen" (23 Harmor channels, 260 s) exports in 50 s, "JuiceBass — Menagerie" (8, 474 s) in 78 s.
+  **REA round 165g (flbeta165s):** the 88 old (version 11…15) factory presets, Default.fst included, are upgraded
+  the way FL's loader does (byte-identical to the DLL's own re-save; a new Harmor starts from Default.fst), filter
+  shapes 8, 10…13, 15 and 16, images of any size (Labyrinth's 16 × 12), portamento time following the velocity.
   **REA round 75:** image synthesis (the part's gain and frequency planes from the project: time position with speed,
   offset and smoothing, one-shot / loop / ping-pong / crossfade, the seven interpolation curves, gain pixel scale and
   mix, frequency modes Oct / Hz / Wide Hz / Unison with the local mask, formant shift with FL's per-column pitch track
@@ -610,9 +613,12 @@ accordingly. Highlights of what is **confirmed and applied**:
   MIDI; the hidden parameter 8 (time offset, 65536 in every state) is ignored; curve type 10 (spline) runs as a line
   (in no selected slot); FL's "playing" and position-jump messages are inferred from LYNX's transport.
 - Harmor (`harmorFallbacks()` lists what a state uses): resynthesis-mode images (a sample analysed at load time) and
-  images with a per-column gain table are ignored (the part plays its timbres; none in the demos), filter shapes
-  8/10–13/15/16 and unknown resonance/phaser types switch that stage off, clip modes > 4 switch the clip off, blend
-  modes > 5 play as mode 0. At precision "Average" FL computes `exp`/`expm1`/division with IPP's 11-bit routines
+  images with a per-column gain table are ignored (the part plays its timbres; none in the demos), unknown
+  resonance/phaser types switch that stage off, clip modes > 4 switch the clip off, blend modes > 5 play as mode 0;
+  the part's note start delay (parameter 2: Rotochip, Resynthesis/Harmony) and the part filter set by its misc
+  field +4 (Morning) are not modelled (REA_rodada165g-flbeta165s §3). Against the DLL on all 325 installation
+  presets: 264 null below −60 dB, 304 with the same spectrum (STFT magnitude below −40 dB); the frequency phaser
+  (type 209) at a high mix drifts in phase at precision "Average" for the IPP reason below. At precision "Average" FL computes `exp`/`expm1`/division with IPP's 11-bit routines
   (`*_A11`); LYNX computes them exactly — demos 74 and 78 (per-partial unison curve) stay at −57/−55 dB for that reason
   (−77.5/−84.5 dB at precision 1, REA_rodada75 §5). In the
   rack, the distortion's shapers are exact functions where FL uses IPP's 11-bit `Tanh/Exp/Ln/Sqrt/Cbrt` at precision 0

+ 1 - 1
docs/analise/REA_rodada142.md

@@ -41,7 +41,7 @@ the same contract as an imported project.
 | Engine | New instance on this PC | Sound of a note / signal | Notes |
 |---|---|---|---|
 | 3x Osc, Sytrus, Harmless, PoiZone, SimSynth, Fruity DX10, Plucked!, Fruit Kick, Drumpad | Default.fst | ✅ | |
-| Harmor (beta), Ogun | first preset the engine reads | ✅ | Default.fst not readable by the engine |
+| Harmor (beta), Ogun | Harmor: Default.fst (old states upgraded, REA_rodada165g-flbeta165s); Ogun: first preset the engine reads | ✅ | |
 | GMS, Morphine | first `.gmsynth` / `.mrp` | ✅ | no Default preset in FL |
 | Toxic Biohazard | `Default.tbio` + the DLL's spectra | ✅ | |
 | Kepler (beta), Transistor Bass, Sawer, MiniSynth, FL Slayer, BassDrum, BooBass | Default + the FL data file | ✅ | |

+ 86 - 0
docs/analise/REA_rodada165g-flbeta165s.md

@@ -0,0 +1,86 @@
+# REA round 165g — sub-round flbeta165s: Harmor out of "(beta)"?
+
+Goal: drop Harmor's "(beta)" only if LYNX's engine really matches FL (null / spectra / listening on FL's presets and
+demo projects). Data: `/mnt/d/lynx-work/flbeta165s` (survey tsv, `st/` old states, `up/` DLL re-saves, `run/hm.exe`
+EXEC harness around the unmodified `Harmor_x64.dll`, `py/` batteries, `tools/harmorrender`).
+
+## Where I stopped
+- 2026-10-27 19:40 — fixes verified against the DLL (`bat_all1.log`, `bat_all1_spec.tsv`): all 325 installation
+  presets now play on the exact engine (88 old ones were refused before), 264 null < −60 dB (was 248), 304 same
+  spectrum (was 291). Harmor stays **"(beta)"**: 21 presets still differ audibly (§5). Next: build-local, land.
+
+## 1. Old states (version 11…15) [DECOMP FUN_0086ed30][EXEC]
+The 88 presets saved by Harmor's first releases (Default.fst among them) were refused by LYNX ("state not usable").
+FL's loader brings them into the current layout: a part stores 385 integers (the articulator-33 smoothing, index 376,
+is missing — a 0 is inserted); version 11 stores the 43 smoothing times (343…385) on an older scale, converted as
+`round(log2(1 + (41^(v/1000) − 1)·37.5·0.0511)·1000/9)`; articulator 33 is absent and gets the default articulator
+(off, amounts 1, envelope 0.5, LFO 0.75, flat maps). The global text becomes an empty string + option byte 1.
+`harmorUpgradeState()` writes exactly what the DLL re-saves (`up/up*.bin` = the DLL's own re-save through the EXEC
+harness, `py/hup.py` = our upgrade): all 88 identical except shaping-curve point positions the DLL renormalises at
+load (sub-ulp of the curve length). Rendering the DLL with the old bytes vs its own re-save vs our upgrade:
+−141…−629 dB on the deterministic ones (`py/dll_up.py`) **[EXEC]**. The importer stores the upgraded bytes so the
+settings panel's parameter offsets apply. A new Harmor instance now starts from FL's Default.fst.
+
+## 2. Portamento following the velocity [DECOMP FUN_00883ae0]
+Global 6 on: the note's glide factor is `(1 − 0.85·velocity)²` (float) — a harder note glides faster.
+
+## 3. Battery: all 325 installation presets, DLL vs LYNX [EXEC]
+`py/bat_all.py` (3 notes: 60/1.0, 67/0.6, 55/0.95 over 1 s at 44.1 kHz, effects rack off, the DLL's Mersenne-Twister
+state handed to LYNX), `py/spec.py` (STFT magnitude error, 4096/2048 Hann). Results `bat_all0.log`, `bat_all0_spec.tsv`:
+
+| | presets |
+|---|---|
+| null < −60 dB (sample-exact within float noise) | 248 / 325 (median −74.8 dB) |
+| null ≥ −60 dB but STFT magnitude < −40 dB (same sound, phase drift) | 43 |
+| audibly different (STFT ≥ −40 dB) | 34 — 18 use a filter shape LYNX lacks (8, 10, 11, 12, 13, 15, 16) |
+
+Audibly different without a fallback: Dub steppy 1, Ice bells, Labyrinth, Shield hit, Magic swamp, Rotochip,
+Morning, Sunroom, Metal thingy, Pomona, Image synthesis/Interpolation, Resynthesis/Harmony, Olbaid Plato Cerrado,
+FX Subida, FX White Noise Caida, Lead Hoover. (Olbaid Bajo Acustico: the DLL itself blows up to 3.7·10¹⁹.)
+
+- **Labyrinth / Interpolation**: their images are small (16 × 12 → an 829-byte object; Interpolation 317 bytes) and
+  LYNX only built images from a part tail > 1024 bytes, so it played them without the image. Fixed: any image object
+  is read (FL's DLL plays it: the DLL's partials are inharmonic, LYNX's were harmonic) **[EXEC]**.
+- **Pomona**: no single parameter explains it (`sweep_pomona.log`: every parameter/global that differs from
+  Default.fst reset one at a time; best −8 dB) — several interacting causes, not found yet.
+- **Frequency phaser (type 209) at a high mix** (Ice bells, Magic swamp, Metal thingy, Church bell, Steam starship;
+  `py/` probes): the error starts at 10⁻⁴ relative and grows — a frequency drift. With the precision patched to 1
+  ("High") the same presets go from −13…−18 dB to −47…−56 dB **[EXEC]**: at precision 0 FL computes the phaser's
+  `2^x` frequency factor with IPP's 11-bit `Exp_32f_A11` (REA_rodada75 §5), which LYNX does not copy. The spectra
+  match (−35…−45 dB STFT); the residue is phase drift.
+- **Part parameter 2 = note start delay** [DECOMP FUN_00879540 case 2, FUN_0088ab10 0x88b150]: `p < 0`:
+  `(2^(−p/48) − 1)/255` s, `p ≥ 0`: `p·0.3125/tempo`; times the sample rate and the voice's articulator-8 output
+  (voice +0x3214), the voice's output starts that many samples later (its control-block grid shifts with it).
+  LYNX ignores it. Used by Rotochip (part B, −100) and Resynthesis/Harmony (−135) only: −47 dB on Rotochip with the
+  delay zeroed in both. Not implemented this round (LYNX's records share one control-block grid).
+
+## 4. Filter shapes 8, 10…13, 15, 16 [DECOMP FUN_00874ed0 + DLL constants]
+Used by 24 presets (18 of the audible outliers); LYNX switched that filter off. Tables (s = 1/(N−1), cos in double,
+`dB(x) = exp(float(x·−72)·float(ln10/20))`, `p16(x) = (x⁴)⁴`):
+- 8 (N 682): `−cos((1 − i·s/2)·π)`; 10 (N 1365): u = the same expression + 1 … `dB(u)·(1 − p16(u))`;
+- 11 (N 1024): `(1 − (cos(3π·(1 − i·s)) + 1)/2)·(1 − (cos(π·(1 − i·s)) + 1)/2)`;
+- 12 (N 4096, origin ½): first half `(1 − (cos(2π(1 − i·s)) + 1)/4)²`, second half `dB(x)·(1 − p16(x))`, x = 2·(i − N/2)·s;
+- 13 (N 1024): `exp(float((1 − (cos(π(1 − i·s)) + 1)/2)·18 − 18)·ln10/20)`;
+- 15 (N 4096, origin ½, ends 1/1): `a²·b² + b/8`, a = (cos(12π(1 − i·s)) + 1)/2, b = 1 − (cos(2π(1 − i·s)) + 1)/2;
+- 16 (N 2048, filled with 1.0, origin ½): the first and last N/3 entries `(1 − (cos(2π(1 − i·0.5/(N/3))) + 1)/2)²`.
+
+## 5. Result and what still differs [EXEC]
+After §1–4 (`bat_all1*`; repeated runs of the same preset vary by a few dB where a state uses randomness, the DLL's
+Mersenne-Twister seed differing per run):
+
+| | before | after |
+|---|---|---|
+| presets the exact engine plays | 237 / 325 | 325 / 325 |
+| null < −60 dB | 248 | 264 |
+| STFT magnitude < −40 dB | 291 | 304 |
+
+Shape presets now at −70…−84 dB (Machine wriggle, Blue screen 2, Wall, Equinox, Above the treeline, Bajo Deep/
+Future/Growl 2, Lead Borracho/Mono/Supersaw 2, Pluck Analogo/Clasico); Interpolation −84.4 dB, Labyrinth −19.9 dB
+(spectrum −38.8: the image now plays; the rest not found).
+
+Why Harmor keeps "(beta)": still audibly different (STFT ≥ −40 dB): Dub steppy 1, Labyrinth, Shield hit, Rotochip
+(note start delay, §3), Morning (part misc +4 → part +0x668: an audio filter object set up by FUN_008781f0 /
+FUN_00863450, not modelled; −81.8 dB with it zeroed in both), Sunroom, Metal thingy / Magic swamp / Ice bells (IPP
+`Exp_32f_A11` in the frequency phaser, §3), Pomona (several causes), Resynthesis/Harmony (delay + resynthesis),
+Oldschool / Tronic 3 / Blue screen / Lead Arcade (shapes now on; a second difference remains), Olbaid noise drums/FX
+(Plato Cerrado/Abierto, FX Subida, White Noise Caida: noise-driven, near the threshold), Lead Hoover.

+ 2 - 1
src/core/FlpImport.cpp

@@ -1481,7 +1481,8 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
                 if (harmorStateUsable (c.pluginState))
                 {
                     def.instrument = InstrumentKind::harmor;
-                    def.pluginState = c.pluginState;
+                    // an old (version 11…15) state is stored in the current layout, as FL re-saves it (REA_rodada165g-flbeta165s §1)
+                    def.pluginState = harmorUpgradeState (c.pluginState).value_or (c.pluginState);
                     adoptedFromPlugin = true;
                     // rack compressor: Harmor's own preset System\Compression\<n>.fst from the user's installation
                     // (REA_rodada38); its Maximus state goes into modelParams (size, bytes…)

+ 232 - 4
src/core/Harmor.cpp

@@ -318,7 +318,131 @@ bool readArt (Reader& r, ArtData& a)
     return r.ok;
 }
 
+// ---------------------------------------------------------------------------------------------------------------
+// Old states (version 11…15, the factory presets of Harmor's first releases, Default.fst included) as the DLL's loader
+// brings them into the current layout (REA_rodada165g-flbeta165s §1, [DECOMP FUN_0086ed30] + [EXEC] DLL re-saves): a part
+// stores 385 integers — the articulator-33 smoothing (index 376) is missing, so a 0 is inserted there; version 11 also
+// stores the 43 smoothing times (343…385) on an older scale, converted as round(log2(1 + (41^(v/1000) − 1)·37.5·0.0511)·
+// 1000/9); articulator 33 is not stored and gets its defaults. The global block's text becomes an empty string plus
+// the option byte 1 (what the DLL writes for these states). Bytes = the DLL's own re-save of the 88 old factory
+// presets, except shaping-curve point positions the DLL renormalises at load (sub-ulp of the curve length).
+
+std::optional<std::vector<std::uint8_t>> upgradeOldState (const std::vector<std::uint8_t>& d)
+{
+    if (d.size() < 8)
+        return std::nullopt;
+    std::uint32_t v = 0, mask = 0;
+    std::memcpy (&v, d.data(), 4);
+    std::memcpy (&mask, d.data() + 4, 4);
+    if (v > 0xffff)
+        v >>= 16;
+    if (v < 11 || v >= 16 || (mask & 3u) == 0 || (mask & 4u) == 0)
+        return std::nullopt;
+    std::vector<std::uint8_t> out;
+    auto put = [&out] (std::int32_t x) {
+        std::uint8_t b[4];
+        std::memcpy (b, &x, 4);
+        out.insert (out.end(), b, b + 4);
+    };
+    auto putD = [&out] (double x) {
+        std::uint8_t b[8];
+        std::memcpy (b, &x, 8);
+        out.insert (out.end(), b, b + 8);
+    };
+    put (0x130003);
+    put ((std::int32_t) mask);
+    std::size_t o = 8;
+    for (int part = 0; part < 2; ++part)
+    {
+        if (((mask >> part) & 1u) == 0)
+            continue;
+        if (o + 4 > d.size())
+            return std::nullopt;
+        std::uint32_t sz = 0;
+        std::memcpy (&sz, d.data() + o, 4);
+        const auto end = o + 4 + (std::size_t) sz;
+        if (end > d.size() || sz < 4 * 385 + 0x30 + 0x4b)
+            return std::nullopt;
+        std::vector<std::int32_t> p (385);
+        std::memcpy (p.data(), d.data() + o + 4, 4 * 385);
+        p.insert (p.begin() + 376, 0);
+        if (v < 12)
+            for (std::size_t i = 343; i < 386; ++i)
+            {
+                const auto x = (double) (float) ((float) p[i] * 0.001f);
+                const auto t = std::exp (x * std::log (41.0));
+                const auto y = std::log ((double) (float) (t - 1.0) * 37.5 * 0.0511 + 1.0);
+                p[i] = (std::int32_t) std::nearbyint (y * (1.0 / std::log (2.0)) * 111.11111111111111);
+            }
+        const auto sizeAt = out.size();
+        put (0);
+        for (const auto x : p)
+            put (x);
+        Reader r { d.data(), end, o + 4 + 4 * 385 };
+        r.i += 0x30 + 0x4b;
+        out.insert (out.end(), d.begin() + (std::ptrdiff_t) (o + 4 + 4 * 385), d.begin() + (std::ptrdiff_t) r.i);
+        for (int k = 0; k < 43; ++k)
+        {
+            if (k == 33)
+            {
+                // the defaults of an articulator: off, amounts 1, envelope at 0.5, LFO at 0.75, flat maps at 0.5
+                auto curve = [&] (int kind, std::initializer_list<std::pair<double, double>> pts, std::array<std::int32_t, 5> hdr) {
+                    put (kind);
+                    put (3);
+                    put ((std::int32_t) pts.size());
+                    for (const auto& [x, y] : pts)
+                    {
+                        putD (x);
+                        putD (y);
+                        put (0);
+                        put (0);
+                    }
+                    for (const auto h : hdr)
+                        put (h);
+                };
+                put (3);
+                put (0);
+                put (0x3f800000);
+                put (0x3f800000);
+                curve (1, { { 0.0, 0.5 } }, { 0, 0, -1, -1, -1 });
+                for (const auto a : { 128, 128, 0, 128 })
+                    put (a);
+                curve (2, { { 0.0, 0.75 } }, { 0, 0, -1, -1, -1 });
+                for (const auto a : { 40898, 0, 0, 0, 0 })
+                    put (a);
+                for (int m = 0; m < 9; ++m)
+                    curve (3, { { 0.0, 0.5 }, { 1.0, 0.5 } }, { 0, -1, -1, -1, -1 });
+                continue;
+            }
+            const auto from = r.i;
+            ArtData a;
+            if (! readArt (r, a))
+                return std::nullopt;
+            out.insert (out.end(), d.begin() + (std::ptrdiff_t) from, d.begin() + (std::ptrdiff_t) r.i);
+        }
+        out.insert (out.end(), d.begin() + (std::ptrdiff_t) r.i, d.begin() + (std::ptrdiff_t) end);
+        const auto blockSize = (std::int32_t) (out.size() - sizeAt - 4);
+        std::memcpy (out.data() + sizeAt, &blockSize, 4);
+        o = end;
+    }
+    if (o + 0xd4 + 0x18 + 0x3d > d.size())
+        return std::nullopt;
+    out.insert (out.end(), d.begin() + (std::ptrdiff_t) o, d.begin() + (std::ptrdiff_t) (o + 0xd4 + 0x18 + 0x3d));
+    out.push_back (0); // the preset text (empty)
+    out.push_back (1); // option byte
+    return out;
+}
+
+std::optional<StateData> parseCurrent (const std::vector<std::uint8_t>& d);
+
 std::optional<StateData> parseState (const std::vector<std::uint8_t>& d)
+{
+    if (auto up = upgradeOldState (d))
+        return parseCurrent (*up);
+    return parseCurrent (d);
+}
+
+std::optional<StateData> parseCurrent (const std::vector<std::uint8_t>& d)
 {
     if (d.size() < 8)
         return std::nullopt;
@@ -1454,6 +1578,86 @@ std::optional<Table> shapeTable (int code, const Curve* curve)
         }
         T = Table (std::move (t), 0.5 * 4095, 1, 1);
     }
+    // the filter shapes 8, 10…13, 15, 16 (REA_rodada165g-flbeta165s §4, [DECOMP FUN_00874ed0] + DLL constants)
+    else if (code == 8 || code == 10)
+    {
+        const int N = code == 8 ? 682 : 1365;
+        auto t = mk (N, s);
+        for (int i = 0; i < N; ++i)
+        {
+            const auto c = std::cos ((1.0 - i * s * 0.5) * pi);
+            if (code == 8)
+                t[(std::size_t) i] = (float) (1.0 - (c + 1.0));
+            else
+            {
+                const auto u = 1.0 - (1.0 - (c + 1.0));
+                t[(std::size_t) i] = (float) (dbOf2 (u) * (1.0 - p16 (u)));
+            }
+        }
+        T = Table (std::move (t), 0, 1, 0);
+    }
+    else if (code == 11)
+    {
+        auto t = mk (1024, s);
+        for (int i = 0; i < 1024; ++i)
+        {
+            const auto a = 1.0 - (std::cos ((1.0 - i * s) * 9.42477796076938) + 1.0) * 0.5;
+            t[(std::size_t) i] = (float) (a * (1.0 - (std::cos ((1.0 - i * s) * pi) + 1.0) * 0.5));
+        }
+        T = Table (std::move (t), 0, 1, 0);
+    }
+    else if (code == 12)
+    {
+        const int N = 4096, half = N / 2;
+        auto t = mk (N, s);
+        for (int i = 0; i < N; ++i)
+            if (i < half)
+            {
+                const auto v = 1.0 - (std::cos ((1.0 - i * s) * twoPi) + 1.0) * 0.25;
+                t[(std::size_t) i] = (float) (v * v);
+            }
+            else
+            {
+                const auto x = (double) (i - half) * s * 2.0;
+                t[(std::size_t) i] = (float) (dbOf2 (x) * (1.0 - p16 (x)));
+            }
+        T = Table (std::move (t), 0.5 * (N - 1), 1, 0);
+    }
+    else if (code == 13)
+    {
+        auto t = mk (1024, s);
+        for (int i = 0; i < 1024; ++i)
+        {
+            const auto c = std::cos ((1.0 - i * s) * pi);
+            const auto a = (float) ((1.0 - (c + 1.0) * 0.5) * 18.0 + -18.0);
+            t[(std::size_t) i] = (float) std::exp ((double) (a * (float) ln10over20));
+        }
+        T = Table (std::move (t), 0, 1, 0);
+    }
+    else if (code == 15)
+    {
+        auto t = mk (4096, s);
+        for (int i = 0; i < 4096; ++i)
+        {
+            const auto a = (std::cos ((1.0 - i * s) * 37.69911184307752) + 1.0) * 0.5;
+            const auto b = 1.0 - (std::cos ((1.0 - i * s) * twoPi) + 1.0) * 0.5;
+            t[(std::size_t) i] = (float) (a * a * b * b + b * 0.125);
+        }
+        T = Table (std::move (t), 0.5 * 4095, 1, 1);
+    }
+    else if (code == 16)
+    {
+        const int N = 2048, M = N / 3;
+        std::vector<float> t ((std::size_t) N, 1.0f);
+        s = 0.5 / M;
+        for (int i = 0; i < M; ++i)
+        {
+            auto v = 1.0 - (std::cos ((1.0 - i * s) * twoPi) + 1.0) * 0.5;
+            v = v * v;
+            t[(std::size_t) i] = t[(std::size_t) (N - 1 - i)] = (float) v;
+        }
+        T = Table (std::move (t), 0.5 * (N - 1), 1, 1);
+    }
     else if (code == 100 || code == 108)
     {
         auto t = mk (1024, s);
@@ -1896,7 +2100,9 @@ ImageData parseImage (const std::vector<std::uint8_t>& t)
         im.why = "resynthesis-mode image (not modelled: the part plays its timbres)";
         return im;
     }
-    if (! r.ok || im.cols <= 0 || im.rows <= 0 || im.rows > 4096 || (long long) im.cols * im.rows > 64LL * 1024 * 1024)
+    if (r.ok && (im.cols == 0 || im.rows == 0))
+        return im; // (an empty image object: every part without an image stores one)
+    if (! r.ok || im.cols < 0 || im.rows < 0 || im.rows > 4096 || (long long) im.cols * im.rows > 64LL * 1024 * 1024)
     {
         im.why = "image data unreadable";
         return im;
@@ -2934,7 +3140,7 @@ struct Part
         }
         if (blend > 5)
             fallbacks.push_back ("timbre blend mode " + std::to_string (blend) + " (played as mode 0)");
-        if (pd.tail > 1024)
+        if (pd.tail >= 4 + 0x2c) // (any image object: Labyrinth's 16 × 12 one is 829 bytes)
             buildImage (pd);
     }
 
@@ -3299,7 +3505,7 @@ struct Patch
 {
     double fs = 44100.0, bpm = 120.0, fclamp = 0.0, coef = 0.0, masterTarget = 1.0;
     int B = 88, prec = 0, monoMode = 0, vrmode = 0, maxrk = 0, e8 = 0;
-    bool legato = false, porta = false;
+    bool legato = false, porta = false, portaVel = false; // portaVel: global 6, the glide time follows the velocity
     bool arpAny = false, arpDesc = false; // some envelope has arpeggio markers; chord order (global 16: descending)
     double legLim = 2147483647.0;
     float kfade = 0.0f;
@@ -3384,6 +3590,7 @@ std::shared_ptr<Patch> buildPatch (const StateData& S, double fs, double bpm, co
     P->kfade = (float) (1.0 / (P->e8 + 1));
     P->legato = S.g[4] > 0;
     P->porta = S.g[5] > 0;
+    P->portaVel = S.g[6] >= 1;
     P->monoMode = S.GI (8);
     P->vrmode = S.GI (12);
     P->legLim = S.g[3] > 0 ? (double) S.g[3] : 2147483647.0;
@@ -4339,6 +4546,13 @@ private:
     void glideTo (Record& v, const Levels& L, bool porta) noexcept
     {
         const auto& p = P->parts[(std::size_t) v.part];
+        // the note's glide factor ([DECOMP FUN_00883ae0, note set-up], REA_rodada165g-flbeta165s §2): 1, or (1 − 0.85·velocity)² in
+        // float when global 6 is on (a harder note glides faster)
+        if (P->portaVel && v.note >= 0 && v.note < maxNotes)
+        {
+            const auto x = (float) (1.0 - (double) (float) notes[(std::size_t) v.note].vel * 0.85);
+            v.vfac = x * x;
+        }
         auto lc = f32 (p.portaT * v.vfac);
         bool toX = false;
         if (lc > 0.0)
@@ -6152,9 +6366,23 @@ std::vector<std::string> harmorFallbacks (const std::vector<std::uint8_t>& state
     return buildPatch (*S, 44100.0, 120.0)->fallbacks;
 }
 
+std::optional<std::vector<std::uint8_t>> harmorUpgradeState (const std::vector<std::uint8_t>& state)
+{
+    try
+    {
+        auto up = upgradeOldState (state);
+        if (up && parseCurrent (*up))
+            return up;
+    }
+    catch (...)
+    {
+    }
+    return std::nullopt;
+}
+
 int harmorParamOffset (const std::vector<std::uint8_t>& state, int part, int index)
 {
-    const auto S = parseState (state);
+    const auto S = parseCurrent (state); // (offsets into this very state: an old layout has to be upgraded first)
     if (! S)
         return -1;
     if (part < 0)

+ 6 - 0
src/core/Harmor.h

@@ -34,6 +34,7 @@
 
 #include <cstdint>
 #include <memory>
+#include <optional>
 #include <string>
 #include <vector>
 
@@ -44,6 +45,11 @@ namespace lynx
 // true when the exact engine can play this Harmor state (version ≥ 16 with articulators and curves, parsed fully)
 bool harmorStateUsable (const std::vector<std::uint8_t>& state);
 
+// An old state (version 11…15: the first releases' presets, FL's Default.fst included) in the current layout, as
+// FL's Harmor re-saves it after loading (REA_rodada165g-flbeta165s §1); nullopt when the state is not an old one (or unreadable).
+// The engine plays old states directly; the importer stores the upgraded bytes so the settings panel can edit them.
+std::optional<std::vector<std::uint8_t>> harmorUpgradeState (const std::vector<std::uint8_t>& state);
+
 // the round-34 fallbacks this state relies on (empty: everything it uses is modelled), for logs and reports
 std::vector<std::string> harmorFallbacks (const std::vector<std::uint8_t>& state);
 

+ 63 - 0
tests/tests.cpp

@@ -11822,6 +11822,69 @@ TEST (sytrus_instrument)
     CHECK (tail.back() == 0.0f);
 }
 
+TEST (harmor_installation_presets)
+{
+    // REA_rodada165g-flbeta165s: every Harmor preset of the installation plays on the exact engine — the 88 old
+    // (version 11…15) ones through the upgrade to the current layout, which renders exactly like the old bytes and
+    // keeps the parameter offsets editable; small images (Labyrinth's 16 × 12) are played, not skipped
+    if (realFlpDir.empty())
+        return;
+    const auto folder = std::filesystem::path (realFlpDir) / "Patches" / "Plugin presets" / "Generators" / "Harmor";
+    if (! std::filesystem::exists (folder))
+        return;
+    int files = 0, usable = 0, old = 0, upgraded = 0, same = 0;
+    const std::vector<lynx::harmor::RefNote> notes { { 0, 60, 0.8, 1.0, 0.0, 3000 } };
+    for (const auto& entry : std::filesystem::recursive_directory_iterator (folder))
+    {
+        if (entry.path().extension() != ".fst")
+            continue;
+        std::ifstream in (entry.path(), std::ios::binary);
+        const std::vector<std::uint8_t> file ((std::istreambuf_iterator<char> (in)), {});
+        std::vector<std::uint8_t> st;
+        try
+        {
+            for (const auto& c : flp::parseProject (file, true).channels)
+                if (! c.pluginState.empty())
+                    st = c.pluginState;
+        }
+        catch (const flp::Error&)
+        {
+        }
+        ++files;
+        usable += lynx::harmorStateUsable (st);
+        std::uint32_t v = 0;
+        if (st.size() >= 4)
+            std::memcpy (&v, st.data(), 4);
+        if ((v > 0xffff ? v >> 16 : v) >= 16)
+            continue;
+        ++old;
+        const auto up = lynx::harmorUpgradeState (st);
+        if (! up)
+            continue;
+        std::uint32_t uv = 0;
+        std::memcpy (&uv, up->data(), 4);
+        upgraded += uv == 0x130003u && lynx::harmorParamOffset (*up, 0, 34) > 0 && lynx::harmorStateUsable (*up);
+        if (old <= 6) // (a few: rendering is the slow part)
+            same += lynx::harmor::renderReference (st, notes, 44100.0, 4096) == lynx::harmor::renderReference (*up, notes, 44100.0, 4096);
+        else
+            ++same;
+    }
+    std::printf ("  Harmor installation presets: %d files, %d usable, %d old, %d upgraded\n", files, usable, old, upgraded);
+    CHECK (files >= 300 && usable == files && old >= 80 && upgraded == old && same == old);
+
+    std::ifstream in (folder / "Bell" / "Labyrinth.fst", std::ios::binary);
+    const std::vector<std::uint8_t> file ((std::istreambuf_iterator<char> (in)), {});
+    if (file.empty())
+        return;
+    auto st = flp::parseProject (file, true).channels.at (0).pluginState;
+    const auto a = lynx::harmor::renderReference (st, notes, 44100.0, 4096);
+    const std::int32_t zero = 0;
+    for (int part = 0; part < 2; ++part)
+        std::memcpy (st.data() + lynx::harmorParamOffset (st, part, 92), &zero, 4); // image frequency scale 0
+    const auto b = lynx::harmor::renderReference (st, notes, 44100.0, 4096);
+    CHECK (a.size() == b.size() && a != b);
+}
+
 TEST (harmor_image)
 {
     // REA_rodada75: image synthesis — a looping 6-column image (gain + frequency planes) read at a speed, cubic gain and