Subversion Repositories DIN Is Noise

Rev

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

/*
* range.cc
* DIN Is Noise is copyright (c) 2006-2018 Jagannathan Sampath
* For more information, please visit http://dinisnoise.org/
*/


#include "range.h"
#include "font.h"
#include "utils.h"
#include "log.h"
#include "audio.h"
#include "scale_info.h"
#include "console.h"

#include <map>
#include <fstream>
using namespace std;

extern multi_curve ran_mod_width_crv, ran_mod_height_crv;

range::range () : mod (&ran_mod_width_crv, &ran_mod_height_crv) {}

void range::calc (scale_info& si) {
  calc_note_freq (0, si);
  calc_note_freq (1, si);
  /*float start_interval = _intervals [intervals[0]];
  float end_interval = _intervals [intervals[1]];

  note& n0 = notes[0];
  note& n1 = notes[1];
  n0.set_freq (lo_tonic_hz, start_interval);
  n1.set_freq (lo_tonic_hz, end_interval);

  delta_step = n1.step - n0.step;*/


  /*float start_frequency = start_interval * start * pow (2.0, n0.oct_pos);
  float end_frequency = end_interval * start * pow (2.0, n1.oct_pos);
  n0.set_freq (start_frequency);
  n1.set_freq (end_frequency);*/


  //delta_step = n1.step - n0.step;

  /*n0.octave_position = octave + start_interval - 1;
  n1.octave_position = octave + end_interval - 1;
  delta_octave_position = n1.octave_position - n0.octave_position;*/


}

void range::calc_note_freq (int i, scale_info& si) {
  float interval = si.intervals [intervals[i]];
  notes[i].set_freq (si.lo_tonic, interval);
  delta_step = notes[1].step - notes[0].step;
}

void range::change_note (int i, int j, scale_info& si) {
  note& ni = notes [i];
  ni.change_scale_pos (j, si);
  intervals[i] = si.notes [ni.scale_pos];
  calc_note_freq (i, si);
  ni.set_name (intervals[i], 1);
}

void range::draw_labels (int label, int show_frequency) {

  static float kr = 0.3f, kg = 1, kb = 0.3f;
  static float fr = 0.3f, fg = fr, fb = fr;
  static float nr = 1, ng = nr, nb = nr;

  float r0, g0, b0;
  float r1, g1, b1;

  static const int spc = 2;
  int ln = line_height + spc;
  int L = extents.left, B = extents.bottom - ln, B2 = B - ln, R = extents.right, T = extents.top + spc, T2 = T + ln;
  glColor3f (fr, fg, fb);
  pts[0]=L; pts[1]=extents.bottom;
  pts[2]=R; pts[3]=extents.bottom;
  pts[4]=R; pts[5]=extents.top;
  pts[6]=L; pts[7]=extents.top;
  glVertexPointer (2, GL_INT, 0, pts);
  glDrawArrays (GL_LINE_LOOP, 0, 4);

  if (key == LEFT) {
    r0 = kr; g0 = kg; b0 = kb;
    r1 = kr; g1 = kg; b1 = kb;
  } else {
    r0 = nr; g0 = ng; b0 = nb;
    r1 = fr; g1 = fg; b1 = fb;
  }

  glColor3f (r0, g0, b0);

  string& n0 = notes[0].name;
  draw_string (n0, L, B);
  draw_string (n0, L, T);
  if (show_frequency) {
    glColor3f (r1, g1, b1);
    string& h0 = notes[0].hz_name;
    draw_string (h0, L, B2);
    draw_string (h0, L, T2);
  }

  if (key == RIGHT) {
    r0 = kr; g0 = kg; b0 = kb;
    r1 = kr; g1 = kg; b1 = kb;
  } else {
    r0 = nr; g0 = ng; b0 = nb;
    r1 = fr; g1 = fg; b1 = fb;
  }


  if (label == BOTH) {
    string& n1 = notes[1].name;
    glColor3f (r0, g0, b0);
    draw_string (n1, R, B);
    draw_string (n1, R, T);
    if (show_frequency) {
      string& h1 = notes[1].hz_name;
      glColor3f (r1, g1, b1);
      draw_string (h1, R, B2);
      draw_string (h1, R, T2);
    }
  }

}

void range::sample_rate_changed () {
  for (int i = 0; i < 2; ++i) notes[i].set_freq (notes[i].hz);
  delta_step = notes[1].step - notes[0].step;
}

void range::init_mod () {
  extern rnd<int> RAN_MOD_DEPTH, RAN_MOD_BPM;
  mod.active = 0;
  mod.fm.depth = RAN_MOD_DEPTH();
  mod.fm.bv.set_bpm (RAN_MOD_BPM(), aout.samples_per_channel);
  mod.fm.initial = extents.width;
  mod.am.depth = 0;
  mod.am.bv.set_bpm (RAN_MOD_BPM(), aout.samples_per_channel);
  mod.am.initial = extents.height;
}

void range::change_height (int dh) {
  int top = extents.top + dh;
  if (top > extents.bottom) {
    extents (extents.left, extents.bottom, extents.right, top);
    mod.am.initial = extents.height;
    mod.am.bv.now = 0.0f;
  }
}