4
0
Эх сурвалжийг харах

Sampler: FL's native sampler voice (velocity and pan laws, channel levels inside the voice, articulators on the song's tick grid, gain ramps, channel filter, end fade); renderwav maps Windows paths

Ka1-S 1 сар өмнө
parent
commit
423a4889a5

+ 19 - 0
src/core/FlpImport.cpp

@@ -1,5 +1,6 @@
 #include "core/FlpImport.h"
 #include "core/FlPluginDb.h"
+#include "core/FlVoiceProcessor.h"
 #include "core/HardcoreFx.h"
 #include "core/GrossBeat.h"
 #include "core/LovePhilter.h"
@@ -694,6 +695,24 @@ Song importFlp (const flp::Project& input, const FlpImportOptions& options)
             }
         }
 
+        // FL's whole native sampler voice (REA_rodada76): the five articulator records as stored (a missing one keeps
+        // the plugins' default record), Mod X/Y, filter type, PPQ
+        if (c.type == flp::ChannelType::sampler && def.instrument == InstrumentKind::sampler)
+        {
+            const auto defaults = flvp::defaultSnapshot();
+            def.sampler.flChannel.assign (89, 0);
+            for (int k = 0; k < 5; ++k)
+            {
+                const auto& env = c.envelopes[(std::size_t) k];
+                const auto* src = env.rawSize >= 68 ? env.raw.data() : defaults.data() + 0x44 * k;
+                std::memcpy (def.sampler.flChannel.data() + 17 * k, src, 68);
+            }
+            def.sampler.flChannel[85] = c.modX;
+            def.sampler.flChannel[86] = c.modY;
+            def.sampler.flChannel[87] = c.filterType;
+            def.sampler.flChannel[88] = project.header.ppq > 0 ? project.header.ppq : 96;
+        }
+
         // channel filter (Mod X/Y + type from 0xDB) applies to the sampler too
         synthFilterFromChannel (c.modX, c.modY, c.filterType, def.sampler.cutoff, def.sampler.resonance, def.sampler.filterType);
 

+ 280 - 4
src/core/Instruments.cpp

@@ -1381,8 +1381,29 @@ struct SamplerVoice
     SvfCoefficients filter;         // this voice's (only with a cutoff envelope)
     double pitchMul = 1.0;
     int controlCountdown = 0;
+    // FL's native sampler voice (REA_rodada76): the channel's articulators and filter (flvp), the note's initial
+    // volume and pan, the stereo gains ramping between ticks, the fast LP's running coefficient, the song tick index
+    bool flVoice = false;
+    flvp::Proc flProc;
+    float initVol = 1.0f, notePan = 0.0f;
+    float gL = 0.0f, gR = 0.0f, sL = 0.0f, sR = 0.0f;
+    float fcRun = 0.0f, fcSlope = 0.0f;
+    std::int64_t tickIndex = 0;
+    int endFade = -1;                 // ≥ 0: past the sample's end, the last frame fading out (FL's 10 ms end fade)
+    float holdL = 0.0f, holdR = 0.0f; // the last frame read
 };
 
+// FL's note velocity → initial volume (FLEngine FUN_00d29aa0, REA_rodada76 §1): x = byte·0.01; 1 at x = 1, else
+// (exp(x·ln 11) − 1)·0.1 — velocity 100 is unity, 128 ≈ 2.05
+inline float flInitVolume (float velocity) noexcept
+{
+    static const float ln11 = (float) std::log (11.0);
+    const auto x = (float) std::nearbyint (std::clamp (velocity, 0.0f, 1.0f) * 128.0f) * 0.01f;
+    if (x == 1.0f)
+        return 1.0f;
+    return (float) ((std::exp ((double) (x * ln11)) - 1.0) * (double) 0.1f);
+}
+
 class SamplerInstrument final : public Instrument
 {
 public:
@@ -1466,7 +1487,20 @@ public:
         bpm.store (std::max (1.0, songBpm)); // before the mailbox: the synced LFO reads it when updating
         {
             Modulation m { { s.filterEnv, s.pitchEnv }, s.lfo };
-            if (s.flVolumeEnvelope.size() == 18)
+            if (s.flChannel.size() == 89)
+            {
+                // FL's channel articulators and filter in the plugins' 364-byte snapshot layout (REA_rodada76 §4)
+                std::array<std::uint8_t, flvp::snapshotSize> snap {};
+                std::memcpy (snap.data(), s.flChannel.data(), 85 * 4);
+                std::memcpy (snap.data() + 0x15c, &s.flChannel[85], 4);
+                std::memcpy (snap.data() + 0x160, &s.flChannel[86], 4);
+                std::memcpy (snap.data() + 0x168, &s.flChannel[87], 4);
+                const auto ppq = std::clamp ((int) s.flChannel[88], 24, 3840);
+                m.flNative = true;
+                m.fl.build (snap.data(), ppq, std::max (1.0, songBpm));
+                m.ticksPerSecond = (double) ppq * std::max (1.0, songBpm) / 60.0;
+            }
+            else if (s.flVolumeEnvelope.size() == 18)
             {
                 const auto ppq = std::clamp ((int) s.flVolumeEnvelope[17], 24, 3840);
                 m.flVolume = true;
@@ -1627,6 +1661,22 @@ public:
             target->flStep = 0.0f;
             target->tickLeft = 0.0;
         }
+        // FL's native sampler voice (REA_rodada76): the articulators start, the first render block steps them at once,
+        // the following steps fall on the song's tick grid (the tick this note starts on, then round(k · spt))
+        target->flVoice = ! clipMode && modulation.flNative && modulation.ticksPerSecond > 0.0;
+        if (target->flVoice)
+        {
+            target->flEnvelope = false;
+            target->env = 1.0f;
+            target->envStep = 0.0f;
+            target->stage = 1;
+            target->flProc.init (modulation.fl);
+            target->initVol = flInitVolume (velocity);
+            target->notePan = nextPan;
+            const auto spt = sampleRate / modulation.ticksPerSecond;
+            target->tickIndex = (std::int64_t) std::nearbyint (songSample / spt);
+            target->tickLeft = 0.0;
+        }
         voicePan (clipMode ? 0.0f : nextPan, target->panL, target->panR);
         target->basePan = clipMode ? 0.0f : nextPan;
 
@@ -1680,6 +1730,16 @@ public:
                 for (std::size_t e = 0; e < 2; ++e)
                     modEnv[e].release (v.mod[e]);
 
+        // FL's voice: the volume, cutoff, resonance and pitch articulators release (FLEngine FUN_00d241e0); without a
+        // volume envelope the sample plays on (one-shot)
+        for (auto& v : voices)
+            if (v.active && v.key == key && v.flVoice && v.stage < 3)
+            {
+                for (int k = 1; k < 5; ++k)
+                    v.flProc.arts[(std::size_t) k].release (modulation.fl.recs[(std::size_t) k]);
+                v.stage = 3;
+            }
+
         // FL's volume articulator enters its release stage from the current level
         for (auto& v : voices)
             if (v.active && v.key == key && v.flEnvelope && v.stage < 3)
@@ -1696,7 +1756,7 @@ public:
 
         // linear release from the current level (like FL)
         for (auto& v : voices)
-            if (v.active && v.key == key && v.stage < 3 && ! v.flEnvelope)
+            if (v.active && v.key == key && v.stage < 3 && ! v.flEnvelope && ! v.flVoice)
             {
                 v.stage = 3;
                 v.envStep = -(float) (std::max (v.env, 0.001f) / (seconds * sampleRate));
@@ -1712,12 +1772,33 @@ public:
 
     void render (float* left, float* right, int n, float gl, float gr) noexcept override
     {
+        const struct Advance
+        {
+            double& at;
+            int n;
+            ~Advance() { at += n; }
+        } advance { songSample, n };
+
         if (sample == nullptr && zones.empty())
             return;
 
         if (envelopeMailbox.read (modulation))
             updateModulation();
 
+        // FL's native sampler voices: the channel's volume and pan act inside each voice (REA_rodada76 §3), so they are
+        // recovered from the rack's gains (panGains: gain·√2·cos/sin of (1 + pan)·π/4)
+        if (modulation.flNative)
+        {
+            const auto chanVol = (float) std::sqrt (((double) gl * gl + (double) gr * gr) * 0.5);
+            auto chanPan = chanVol > 0.0f ? (float) (std::atan2 ((double) gr, (double) gl) * (4.0 / 3.141592653589793) - 1.0) : 0.0f;
+            if (std::fabs (chanPan) < 1.0e-6f)
+                chanPan = 0.0f;
+            const flvp::X87Extended precision;
+            for (auto& v : voices)
+                if (v.active && v.data != nullptr && v.flVoice)
+                    renderFl (v, left, right, n, chanVol, chanPan);
+        }
+
         // channel filter (TPT SVF, same as the synth); off when open, without resonance and without modulation
         const auto fc = cutoff.load(), res = resonance.load();
         const auto type = filterType.load();
@@ -1736,7 +1817,7 @@ public:
 
         for (auto& v : voices)
         {
-            if (! v.active || v.data == nullptr)
+            if (! v.active || v.data == nullptr || v.flVoice)
                 continue;
 
             const auto* l = v.data->leftData();
@@ -1898,6 +1979,187 @@ public:
         }
     }
 
+    // One sequencer tick of FL's sampler voice (FLEngine FUN_00d24ae0 / FUN_00d24500 / FUN_00d24650, REA_rodada76
+    // §3–§4): the articulators step; the target gains are the pan law of (note pan + channel pan + pan articulator,
+    // initial volume · channel volume · volume articulator); the filter coefficients follow Final.FCut/FRes plus the
+    // cutoff/resonance articulators; gains and the fast LP's coefficient ramp towards their targets over round(spt)
+    // samples, at most 0.001·44100/fs per sample.
+    void flTick (SamplerVoice& v, float chanVol, float chanPan, int perTick) noexcept
+    {
+        const auto& S = modulation.fl;
+        auto& pr = v.flProc;
+        pr.control (S);
+        const auto finalVol = v.initVol * chanVol, finalPan = v.notePan + chanPan;
+        float tL, tR;
+        flvp::panLaw (finalPan + pr.pan, finalVol * pr.vol, tL, tR);
+        v.pitchMul = pr.pitch != 0.0f ? std::exp2 ((double) pr.pitch / 1200.0) : 1.0;
+
+        const auto first = pr.first;
+        const auto cx = ((float) S.modX * 0.00390625f + 0.0f) + pr.cut;
+        const auto cy = ((float) S.modY * 0.00390625f + 0.0f) + pr.res;
+        if (pr.kind == 0)
+        {
+            flvp::coefFast (cx, cy, pr.fc, pr.fq, S.rateRatio);
+            if (flvp::bitsOf (pr.fc) != 0x3f800000 || flvp::bitsOf (pr.fq) != 0)
+                pr.active = true;
+            if (! pr.active || first > 0)
+                v.fcRun = pr.fc, v.fcSlope = 0.0f;
+            else
+                v.fcSlope = flvp::rampStep (pr.fc, v.fcRun, perTick, S.rampLimit);
+        }
+        else if (pr.kind >= 1 && pr.kind <= 4)
+            flvp::coefBiquad (pr.kind, cx, cy, pr.fc, pr.fq, pr.b, S.rateRatio);
+        else if (pr.kind == 6)
+            flvp::coefSvf (cx, cy, pr.fc, pr.fq, S.rateRatio);
+
+        // the first block: with the volume articulator past its attack the gains start at their (unscaled) target,
+        // else they ramp up from 0
+        auto prevL = v.gL, prevR = v.gR;
+        if (first > 1)
+            prevL = tL, prevR = tR;
+        pr.first = 0;
+        if (pr.active && pr.kind >= 1 && pr.kind <= 4 && pr.stage2 != 0)
+        {
+            const auto g = (float) (1.0 - (double) pr.fq * (3.2 - (double) pr.fc) * 0.046875);
+            tL = tL * g, tR = tR * g;
+        }
+        v.sL = flvp::rampStep (tL, prevL, perTick, S.rampLimit);
+        v.sR = flvp::rampStep (tR, prevR, perTick, S.rampLimit);
+        v.gL = prevL, v.gR = prevR;
+
+        // the volume envelope has ended and the level is down: the voice is done
+        if (pr.arts[1].state == 9 && tL == 0.0f && tR == 0.0f && std::fabs (prevL) < 1.0e-7f && std::fabs (prevR) < 1.0e-7f)
+            v.active = false;
+    }
+
+    // FL's sampler voice over n samples: split at the song's ticks, the sample read through FL's interpolators, the
+    // channel filter on the stereo block, the gains ramped per sample (the channel's volume and pan are inside)
+    void renderFl (SamplerVoice& v, float* left, float* right, int n, float chanVol, float chanPan) noexcept
+    {
+        const auto spt = sampleRate / modulation.ticksPerSecond;
+        const auto perTick = (int) std::max<std::int64_t> (1, flvp::roundEven (spt));
+        const auto* l = v.data->leftData();
+        const auto* r = v.data->rightData();
+        const auto lastFrame = std::min ((double) (v.data->frames() - 1), v.last);
+        auto& pr = v.flProc;
+
+        for (int pos = 0; pos < n && v.active;)
+        {
+            if (v.tickLeft <= 0.0)
+            {
+                flTick (v, chanVol, chanPan, perTick);
+                const auto next = v.tickIndex + 1;
+                v.tickLeft += (double) (flvp::roundEven ((double) next * spt) - flvp::roundEven ((double) v.tickIndex * spt));
+                v.tickIndex = next;
+                if (! v.active)
+                    break;
+            }
+            auto seg = std::min ({ n - pos, (int) std::ceil (v.tickLeft), flBlock });
+
+            // read the segment (loop wrap, region end, declick of stolen voices, clip fades)
+            auto ended = false;
+            int m = 0;
+            for (; m < seg; ++m)
+            {
+                const auto looping = v.loopEnd > v.loopStart && (! v.loopWhileHeld || v.stage < 3);
+                if (looping && v.position >= v.loopEnd)
+                {
+                    while (v.position >= v.loopEnd)
+                        v.position = (v.position - v.loopEnd) + v.loopStart;
+                    ++v.loops;
+                }
+                if (v.stolen && v.fade <= 0.0f)
+                {
+                    ended = true;
+                    break;
+                }
+                // past the region's end FL holds the last frame and fades it out with the 441-entry end table (EXEC:
+                // FL's render, REA_rodada76 §6)
+                if (v.endFade < 0 && ((double) flrs::wholeFrames (v.position) > lastFrame || v.position < v.first))
+                    v.endFade = 0;
+                float sl, sr;
+                if (v.endFade >= 0)
+                {
+                    const auto& table = flvp::endTable();
+                    if (v.endFade >= (int) table.size())
+                    {
+                        ended = true;
+                        break;
+                    }
+                    const auto t = table[(std::size_t) v.endFade++];
+                    sl = v.holdL * t, sr = v.holdR * t;
+                }
+                else
+                {
+                    readFrame (v, l, r, lastFrame, looping, sl, sr);
+                    v.holdL = sl, v.holdR = sr;
+                }
+                auto gain = v.fade * v.zoneGain;
+                if (v.fadeIn > 0.0f || v.fadeOut > 0.0f)
+                {
+                    if (v.fadeIn > 0.0f && v.clipElapsed < v.fadeIn)
+                        gain *= v.clipElapsed / v.fadeIn;
+                    if (v.fadeOut > 0.0f && v.clipRemaining < v.fadeOut)
+                        gain *= std::max (0.0f, v.clipRemaining) / v.fadeOut;
+                    v.clipElapsed += 1.0f;
+                    v.clipRemaining -= 1.0f;
+                }
+                flX[(std::size_t) (2 * m)] = sl;
+                flX[(std::size_t) (2 * m + 1)] = sr;
+                flG[(std::size_t) m] = gain;
+                v.position += v.rate * v.pitchMul;
+                ++v.age;
+                if (v.glideLeft > 0)
+                {
+                    v.rate *= v.glideRatio;
+                    --v.glideLeft;
+                }
+                if (v.stolen)
+                    v.fade -= fadeStep;
+            }
+            seg = m;
+
+            // the channel filter (FLEngine FUN_00d247a0)
+            const float* y = flX.data();
+            if (pr.active && seg > 0)
+            {
+                if (pr.kind == 0)
+                {
+                    flvp::renderFast (pr.fst, pr.fq, flX.data(), flY.data(), seg, v.fcRun, v.fcSlope);
+                    v.fcRun = v.fcRun + (float) seg * v.fcSlope;
+                    y = flY.data();
+                }
+                else if (pr.kind >= 1 && pr.kind <= 4)
+                {
+                    flvp::renderBiquad (pr.st1, pr.b, flX.data(), flY.data(), seg);
+                    if (pr.stage2 != 0)
+                        flvp::renderBiquad (pr.st2, pr.b, flY.data(), flY.data(), seg);
+                    y = flY.data();
+                }
+                else if (pr.kind == 6)
+                {
+                    flvp::renderSvf (pr.st1, pr.fc, pr.fq, flX.data(), flY.data(), seg);
+                    if (pr.stage2 != 0)
+                        flvp::renderSvf (pr.st2, pr.fc, pr.fq + (1.0f - pr.fq) * 0.25f, flY.data(), flY.data(), seg);
+                    y = flY.data();
+                }
+            }
+
+            for (int i = 0; i < seg; ++i)
+            {
+                const auto g = flG[(std::size_t) i];
+                left[pos + i] += y[2 * i] * ((v.gL + (float) i * v.sL) * g);
+                right[pos + i] += y[2 * i + 1] * ((v.gR + (float) i * v.sR) * g);
+            }
+            v.gL = v.gL + v.sL * (float) seg;
+            v.gR = v.gR + v.sR * (float) seg;
+            v.tickLeft -= seg;
+            pos += seg;
+            if (ended)
+                v.active = false;
+        }
+    }
+
     // FL's sampler read (REA_rodada69 §1): the kernel's taps around the read position, frames outside the region
     // repeating its first/last frame, taps past the loop end wrapping to the loop start (and, once the voice has
     // looped, taps before the loop start wrapping to its end), a reversed voice reading the region backwards
@@ -1958,6 +2220,9 @@ private:
     std::array<SamplerVoice, 16> voices {};
     int quality = flrs::liveQuality;        // FL's interpolation index (prepare)
     std::array<float, 1024> tapL {}, tapR {}; // kernel taps gathered near the region edges and loops
+    static constexpr int flBlock = 512;       // FL voices: longest segment rendered at once
+    std::array<float, 2 * flBlock> flX {}, flY {};
+    std::array<float, flBlock> flG {};
     std::atomic<float> pitch { 0.0f }, attack { 0.0f }, decay { 0.0f }, sustain { 1.0f }, release { 0.0f }, stretchBeats { 0.0f };
     std::atomic<double> bpm { 120.0 };
     std::atomic<float> regionStart { 0.0f }, regionEnd { 1.0f };
@@ -1968,9 +2233,16 @@ private:
     double songTicks = 0.0;         // song position in the block (global LFO)
 
 public:
-    void setSongPosition (double ticks) noexcept override { songTicks = ticks; }
+    void setSongPosition (double ticks) noexcept override
+    {
+        songTicks = ticks;
+        // the song's sample position (FL's ticks fall at round(k · samples per tick) from the song start)
+        const auto tps = (double) ppq * bpm.load() / (60.0 * sampleRate);
+        songSample = tps > 0.0 ? std::nearbyint (ticks / tps) : 0.0;
+    }
 
 private:
+    double songSample = 0.0;        // sample position of the next render call in the song
     int lastZone = -1;              // the zone the last note chose (overlapping layers cycle from it)
     double lastRate = 0.0; // read speed of the last note (where porta starts from)
     std::atomic<int> filterType { 0 };
@@ -1983,6 +2255,8 @@ private:
         bool flVolume = false;     // FL's volume articulator replaces the ADSR
         flvp::Rec volume {};       // its settings (FLEngine FUN_009ce9e0 = the plugins' FUN_0071ff00, REA_rodada69 §3)
         double ticksPerSecond = 0; // FL steps it once per sequencer tick
+        bool flNative = false;     // FL's whole sampler voice (SamplerSettings::flChannel)
+        flvp::Settings fl {};
     };
     SettingsMailbox<Modulation> envelopeMailbox;
     Modulation modulation;
@@ -1992,6 +2266,8 @@ private:
     void updateModulation() noexcept
     {
         anyLfo = false;
+        if (modulation.flNative)
+            modulation.fl.setRate (sampleRate); // FLEngine FUN_006a0230: ratio 44100/fs, ramp limit ratio·0.001
 
         for (std::size_t e = 0; e < 2; ++e)
             modEnv[e] = ModCoefficients::make (modulation.envelopes[e], sampleRate);

+ 7 - 0
src/core/Song.h

@@ -158,6 +158,13 @@ struct SamplerSettings
     // by the project's PPQ. When present it replaces attack/decay/sustain/release (delay, hold, tensions, FL's tick
     // stepping); editing the ADSR by hand clears it.
     std::vector<std::int32_t> flVolumeEnvelope;
+    // FL's native sampler channel as the project stored it (REA_rodada76): the five 0xDA articulator records (pan,
+    // volume, cutoff, resonance, pitch; 17 values each), Mod X, Mod Y and the filter type (0xDB), then the project's
+    // PPQ — 89 values. When present the sampler runs FL's voice: the velocity and pan laws with the channel's volume and
+    // pan inside the voice, the articulators stepped on the song's tick grid with FL's gain ramps, and the channel filter
+    // (core/FlVoiceProcessor.h); ADSR, cutoff/resonance/type, the modulation envelopes and LFOs above are then unused.
+    // Editing the envelope or the filter by hand clears it.
+    std::vector<std::int32_t> flChannel;
 
     bool operator== (const SamplerSettings&) const = default;
 };

+ 11 - 0
src/engine/ProjectFile.cpp

@@ -629,6 +629,13 @@ juce::String toJson (const Song& song)
                     env.add ((int) v);
                 sampler->setProperty ("flVolumeEnvelope", env);
             }
+            if (! c.sampler.flChannel.empty())
+            {
+                juce::Array<juce::var> fl;
+                for (auto v : c.sampler.flChannel)
+                    fl.add ((int) v);
+                sampler->setProperty ("flChannel", fl);
+            }
             writeEnvelopes (*sampler, c.sampler.filterEnv, c.sampler.pitchEnv);
             writeLfos (*sampler, c.sampler.lfo);
             o->setProperty ("samplerSettings", juce::var (sampler.release()));
@@ -1037,6 +1044,10 @@ std::optional<Song> fromJson (const juce::String& json, juce::String& error)
                     for (const auto& v : *env)
                         def.sampler.flVolumeEnvelope.push_back ((std::int32_t) (int) v);
 
+                if (auto* fl = s["flChannel"].getArray(); fl != nullptr && fl->size() == 89)
+                    for (const auto& v : *fl)
+                        def.sampler.flChannel.push_back ((std::int32_t) (int) v);
+
                 if (const auto& filter = s["filter"]; filter.isArray() && filter.size() >= 2)
                 {
                     def.sampler.cutoff = juce::jlimit (20.0f, 20000.0f, (float) (double) filter[0]);

+ 5 - 1
src/ui/ChannelSettings.cpp

@@ -1327,8 +1327,12 @@ private:
             // an ADSR edited by hand replaces FL's imported volume envelope
             const auto& old = current()->sampler;
             auto moved = [] (float a, float b) { return std::abs (a - b) > 1.0e-4f; };
-            if (moved (s.attack, old.attack) || moved (s.decay, old.decay) || moved (s.sustain, old.sustain) || moved (s.release, old.release))
+            const auto adsr = moved (s.attack, old.attack) || moved (s.decay, old.decay) || moved (s.sustain, old.sustain) || moved (s.release, old.release);
+            if (adsr)
                 s.flVolumeEnvelope.clear();
+            // so does an edited envelope or filter for FL's whole sampler voice (REA_rodada76)
+            if (adsr || moved (s.cutoff, old.cutoff) || moved (s.resonance, old.resonance) || s.filterType != old.filterType)
+                s.flChannel.clear();
         }
         if (s == current()->sampler)
             return;

+ 4 - 0
tools/renderwav.cpp

@@ -2,6 +2,7 @@
 // Usage: renderwav project.flp output.wav [pattern-index] [loops]
 // Without an index, picks the pattern with the most notes.
 
+#include <cctype>
 #include <cstdio>
 #include <cstdlib>
 #include <fstream>
@@ -69,6 +70,9 @@ int main (int argc, char** argv)
                                                        : "/mnt/c/Program Files/Image-Line/FL Studio 2026";
     auto toLocal = [] (std::string p) {
         std::replace (p.begin(), p.end(), '\\', '/');
+        // absolute Windows paths ("C:/...") → the WSL mount ("/mnt/c/...")
+        if (p.size() > 2 && p[1] == ':' && p[2] == '/' && std::isalpha ((unsigned char) p[0]))
+            p = "/mnt/" + std::string (1, (char) std::tolower ((unsigned char) p[0])) + p.substr (2);
         return p;
     };