Subversion Repositories DIN Is Noise

Rev

Rev 1806 | Rev 1858 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

/*
* modulator.h
* DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath
* DIN Is Noise is released under GNU Public License 2.0
* For more information, please visit https://dinisnoise.org/
*/

#ifndef __modulator__
#define __modulator__

#include "beat2value.h"
#include "chrono.h"

#include <fstream>
#include <string>

struct multi_curve;
struct drone;

struct mod_params {

  float depth;
  beat2value bv; // rate

  float result;

  // drone modulation direction
  //
  enum {VERTICAL, HORIZONTAL, VELOCITY, ACCELERATION}; // possible modulation directions
  int id;
  static point<float> vertical, horizontal; // constant directions
  float *dirx, *diry; // current modulation direction

  void setdir (int i, float* x, float* y) {
    id = i;
    dirx = x;
    diry = y;
  }

  void calcdir (drone& d);

  float initial; // for microtonal range modulation

  mod_params (multi_curve* c, int d, point<float>& p, const std::string& n = "noname");
  void calc (double dt);
  void clear ();

};

struct modulator {

  enum {AM, FM};

  mod_params am, fm;
 
  enum {FROZEN=-1, NOT_ACTIVE, ACTIVE};
  int active;

  int scrubbed; // used by point_modulator

  double t, dt;

  modulator (multi_curve* fmc, multi_curve* amc) :
    am (amc, mod_params::VERTICAL, mod_params::vertical),
    fm (fmc, mod_params::HORIZONTAL, mod_params::horizontal)
  {
    active = scrubbed = 0;
    t = ui_clk ();
    dt = 0.0;
  }

  void clear () {
    am.clear ();
    fm.clear ();
    active = 0;
  }

  void calc () {

    double now = ui_clk ();
    dt = now - t;
    t = now;

    am.calc (dt);
    fm.calc (dt);

  }

};

#endif