Subversion Repositories DIN Is Noise

Rev

Rev 2006 | Rev 2097 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
964 jag 1
/*
2
* range.cc
2009 jag 3
* DIN Is Noise is copyright (c) 2006-2023 Jagannathan Sampath
1713 jag 4
* DIN Is Noise is released under GNU Public License 2.0
1479 jag 5
* For more information, please visit https://dinisnoise.org/
964 jag 6
*/
7
 
8
#include "range.h"
9
#include "font.h"
10
#include "utils.h"
11
#include "log.h"
12
#include "audio.h"
13
#include "scale_info.h"
14
#include "console.h"
15
 
16
#include <map>
17
#include <fstream>
18
using namespace std;
19
 
20
extern multi_curve ran_mod_width_crv, ran_mod_height_crv;
21
 
1445 jag 22
range::range () : fixed (CENTER), mod (&ran_mod_width_crv, &ran_mod_height_crv)  {}
964 jag 23
 
24
void range::calc_note_freq (int i, scale_info& si) {
25
  float interval = si.intervals [intervals[i]];
26
  notes[i].set_freq (si.lo_tonic, interval);
27
  delta_step = notes[1].step - notes[0].step;
28
}
29
 
30
void range::calc (scale_info& si) {
31
  calc_note_freq (0, si);
32
  calc_note_freq (1, si);
33
}
34
 
35
void range::change_note (int i, int j, scale_info& si) {
36
  note& ni = notes [i];
37
  ni.change_scale_pos (j, si);
38
  intervals[i] = si.notes [ni.scale_pos];
39
  calc_note_freq (i, si);
40
  ni.set_name (intervals[i], si.western);
41
}
42
 
1397 jag 43
void range::change_octave (int i, int o, scale_info& si) {
44
  note& ni = notes[i];
45
  ni.octave += o;
46
  calc_note_freq (i, si);
47
}
964 jag 48
 
2005 jag 49
void range::stamplabel (const string& lbl, int L, int B, int T/*, int w, int h*/) {
50
  glColor3f (1, 1, 1);
51
  draw_string (lbl, L, B);
52
  draw_string (lbl, L, T);
53
}
54
 
964 jag 55
void range::draw_labels (int label, int show_frequency) {
56
 
1802 jag 57
  int ln = line_height;
58
  int L = extents.left, B = extents.bottom - ln, B2 = B - ln;
59
  int R = extents.right, T = extents.top, T2 = T + ln;
964 jag 60
 
1802 jag 61
  glColor3f (1, 1, 1);
964 jag 62
  pts[0]=L; pts[1]=extents.bottom;
63
  pts[2]=R; pts[3]=extents.bottom;
64
  pts[4]=R; pts[5]=extents.top;
65
  pts[6]=L; pts[7]=extents.top;
66
  glVertexPointer (2, GL_INT, 0, pts);
67
  glDrawArrays (GL_LINE_LOOP, 0, 4);
68
 
69
  string& n0 = notes[0].name;
2006 jag 70
  stamplabel (n0, L, B, T);
2005 jag 71
 
964 jag 72
  if (show_frequency) {
73
    string& h0 = notes[0].hz_name;
2006 jag 74
    stamplabel (h0, L, B2, T2);
964 jag 75
  }
76
 
77
  if (label == BOTH) {
78
    string& n1 = notes[1].name;
2006 jag 79
    stamplabel (n1, R, B, T);
964 jag 80
    if (show_frequency) {
81
      string& h1 = notes[1].hz_name;
2006 jag 82
      stamplabel (h1, R, B2, T2);
964 jag 83
    }
84
  }
85
 
86
}
87
 
88
void range::sample_rate_changed () {
89
  for (int i = 0; i < 2; ++i) notes[i].set_freq (notes[i].hz);
90
  delta_step = notes[1].step - notes[0].step;
91
}
92
 
93
void range::init_mod () {
94
  extern rnd<int> RAN_MOD_BPM;
95
  mod.active = 0;
96
  mod.fm.depth = 0;
1760 jag 97
  mod.fm.bv.set_bpm (RAN_MOD_BPM());
964 jag 98
  mod.fm.initial = extents.width;
99
  mod.am.depth = 0;
1760 jag 100
  mod.am.bv.set_bpm (RAN_MOD_BPM());
964 jag 101
  mod.am.initial = extents.height;
102
}
103
 
104
void range::change_height (int dh) {
105
  int top = extents.top + dh;
106
  if (top > extents.bottom) {
107
    extents (extents.left, extents.bottom, extents.right, top);
108
    mod.am.initial = extents.height;
109
    mod.am.bv.now = 0.0f;
1403 jag 110
    cons << "Height = " << extents.height << " Vol/pixel = " << 1.0f / extents.height << eol;
964 jag 111
  }
112
}
1402 jag 113
 
114
void range::print_hz_per_pixel () {
115
  cons << YELLOW << "Width = " << extents.width << " pixels, Hz/pixel = " << hz_per_pix () << eol;
116
}