C++ API. Load/Save button state on presets

  • Hi @Christoph-Hart
    Having troubles making a button to load state from presets.
    Saving state is done. But don't know how to load it

    // This saves it ok
    addToUserPreset<raw::GenericStorage::Bypassed<true>>("extendedRange", "KeyRangeScriptProcessor1");
    // Don't know how to load it since Bypassed is not a parameter
    #define raw_parameter(x, name)raw::PluginParameter<raw::Data<float>::Attribute<x>>(getMainController(), name);
       auto p1 = new raw_parameter(SimpleReverbEffect::WetLevel, "SimpleReverbSlider 1");
        p1->setup(raw::IDs::UIWidgets::Slider, "SimpleReverb1", { 0.0f, 1.0f, 0.5f}, 0.1f); // {min, max, stepsize}, middlePos

    Any quick tip???
    Thanks in advance

  • Just use the Bypassed class from the raw::Data namespace. instead of the raw::Data::Attribute class:

    #define raw_bypass(x, name) raw::PluginParameter<raw::Data<bool>::Bypassed<true>>(getMainController(), name);

    The bool template argument can be used to invert the state (so basically making it an "Enabled" property).

    BTW a better coding style is to use using aliases instead of preprocessor definitions (#define). Unlike the preprocessor, the using aliases are scoped, so you don't mess up the global namespace:

    // definition
    template <int Index> using MyAttributeParameter = raw::PluginParameter<raw::Data<float>::Attribute<Index>>;
    // without template argument it gets a bit easier to read:
    using MyEnabledParameter = raw::PluginParameter<raw::Data<bool>::Bypassed<true>>;
    // usage
    auto p1 = new MyAttributeParameter<SimpleReverbEffect::WetLevel>(mc, "SimpleReverbSlider");
    auto b1 = new MyEnabledParameter(mc, "EnabledButton");

  • @Christoph-Hart thanks mate!!!!!!

    Implemented that!
    Still having a weird behaviour loading a button state from preset at the "First time I create it"
    I mean, when I create a preset and the button is "Enabled" or "1" in the preset file, it flips apparently the behaviour of the other presets doing that button to not load the correct state. If I quit or restart de plugin, it loads correctly. I guess the toggle thing makes it not to work properly.
    I just want to save if that module is Enabled or Bypassed.

    This is what I have at Raw.cpp

    addToUserPreset<raw::Data<bool>::Bypassed<true>>("VibratoOnButton", "LfoGain");

    this is the preset

    <?xml version="1.0" encoding="UTF-8"?>
    <Preset Version="1.0.0">
      <Control id="VibratoOnButton" value="1"/>

Log in to reply