20  halp_meta(name, 
"LFO")
 
   21  halp_meta(c_name, 
"LFO")
 
   22  halp_meta(category, 
"Control/Generators")
 
   23  halp_meta(author, 
"ossia score")
 
   24  halp_meta(manual_url, 
"https://ossia.io/score-docs/processes/lfo.html#lfo")
 
   25  halp_meta(description, 
"Low-frequency oscillator")
 
   26  halp_meta(recommended_height, 130.)
 
   27  halp_meta(uuid, 
"1e17e479-3513-44c8-a8a7-017be9f6ac8a");
 
   31    halp::log_hslider_f32<
"Freq.", halp::range{0.01f, 100.f, 1.f}> freq;
 
   32    halp::knob_f32<
"Ampl.", halp::range{0., 2., 0.5}> ampl;
 
   33    halp::knob_f32<
"Offset", halp::range{-1., 1., 0.5}> offset;
 
   34    halp::knob_f32<
"Jitter", halp::range{0., 1., 0}> jitter;
 
   35    halp::knob_f32<
"Phase", halp::range{-1., 1., 0.}> phase;
 
   36    struct : halp::enum_t<Control::Widgets::Waveform, 
"Waveform">
 
   38      static constexpr auto pixmaps()
 
   40        return std::array<const char*, 16>{
 
   41            ":/icons/wave_sin_off.png",
 
   42            ":/icons/wave_sin_on.png",
 
   43            ":/icons/wave_triangle_off.png",
 
   44            ":/icons/wave_triangle_on.png",
 
   45            ":/icons/wave_saw_off.png",
 
   46            ":/icons/wave_saw_on.png",
 
   47            ":/icons/wave_square_off.png",
 
   48            ":/icons/wave_square_on.png",
 
   49            ":/icons/wave_sample_and_hold_off.png",
 
   50            ":/icons/wave_sample_and_hold_on.png",
 
   51            ":/icons/wave_noise1_off.png",
 
   52            ":/icons/wave_noise1_on.png",
 
   53            ":/icons/wave_noise2_off.png",
 
   54            ":/icons/wave_noise2_on.png",
 
   55            ":/icons/wave_noise3_off.png",
 
   56            ":/icons/wave_noise3_on.png"};
 
 
   65    struct : halp::val_port<
"Out", std::optional<float>>
 
   76  rnd::pcg rd{random_source()};
 
   78  using tick = halp::tick_flicks;
 
   79  void operator()(
const halp::tick_flicks& tk)
 
   81    constexpr const double sine_ratio = ossia::two_pi / ossia::flicks_per_second<double>;
 
   82    const auto elapsed = tk.model_read_duration();
 
   84    const auto quantif = inputs.quant.value;
 
   85    auto freq = inputs.freq.value;
 
   86    auto ampl = inputs.ampl.value;
 
   87    auto offset = inputs.offset.value;
 
   88    const auto jitter = inputs.jitter.value;
 
   89    auto custom_phase = inputs.phase.value;
 
   90    const auto type = inputs.waveform.value;
 
   94      if(tk.unexpected_bar_change())
 
  105      freq = 1. / (2. * quantif);
 
  108    const auto ph_delta = elapsed * freq * sine_ratio;
 
  111      auto ph = this->phase;
 
  114        ph += std::normal_distribution<float>(0., 0.25)(this->rd) * jitter;
 
  117      using namespace Control::Widgets;
 
  120          = [&](
auto new_val) { outputs.out.value = ampl * new_val + offset; };
 
  124          add_val(std::sin(custom_phase + ph));
 
  127          add_val(std::asin(std::sin(custom_phase + ph)) / ossia::half_pi);
 
  130          add_val(std::atan(std::tan(custom_phase + ph)) / ossia::half_pi);
 
  133          add_val((std::sin(custom_phase + ph) > 0.f) ? 1.f : -1.f);
 
  135        case SampleAndHold: {
 
  136          const auto start_s = std::sin(custom_phase + ph);
 
  137          const auto end_s = std::sin(custom_phase + ph + ph_delta);
 
  138          if((start_s > 0 && end_s <= 0) || (start_s <= 0 && end_s > 0))
 
  140            add_val(std::uniform_real_distribution<float>(-1.f, 1.f)(this->rd));
 
  145          add_val(std::uniform_real_distribution<float>(-1.f, 1.f)(this->rd));
 
  148          add_val(std::normal_distribution<float>(0.f, 1.f)(this->rd));
 
  152              std::clamp(std::cauchy_distribution<float>(0.f, 1.f)(this->rd), 0.f, 1.f));
 
  157    this->phase += ph_delta;
 
  162    halp_meta(layout, halp::layouts::hbox)
 
  165      halp_meta(layout, halp::layouts::vbox)
 
  166      halp_meta(background, halp::colors::background_mid)
 
  169        halp_meta(layout, halp::layouts::hbox)
 
  171        halp::control<&ins::freq> f;
 
  172        halp::control<&ins::quant> q;
 
  174      halp::control<&ins::waveform> w;
 
  179      halp_meta(layout, halp::layouts::vbox)
 
  180      halp_meta(background, halp::colors::background_mid)
 
  181      halp::control<&ins::ampl> a;
 
  182      halp::control<&ins::offset> o;
 
  186      halp_meta(layout, halp::layouts::vbox)
 
  187      halp_meta(background, halp::colors::background_mid)
 
  188      halp::control<&ins::jitter> j;
 
  189      halp::control<&ins::phase> p;