Rev 437 |
Rev 786 |
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 <map>
#include <fstream>
using namespace std;
extern ofstream dlog;
extern font fnt;
void range::calc (int octave, float start, map<string, float>& _intervals) {
float start_interval = _intervals [intervals[0]];
float end_interval = _intervals [intervals[1]];
clamp<float> (1, start_interval, 2);
clamp<float> (1, end_interval, 2);
float start_frequency = start_interval * start;
float end_frequency = end_interval * start;
notes[0].set_frequency (start_frequency);
notes[0].octave_position = octave + start_interval - 1;
notes[1].set_frequency (end_frequency);
notes[1].octave_position = octave + end_interval - 1;
delta_step = notes[1].step - notes[0].step;
delta_octave_position = notes[1].octave_position - notes[0].octave_position;
}
void range::draw_labels (int label_what, int show_frequency) {
static float kr = 0.3f, kg = 1, kb = 0.3f; // key color
static float fr = 0.3f, fg = fr, fb = fr; // frequency color
static float nr = 1, ng = nr, nb = nr; // normal color
float r0, g0, b0;
float r1, g1, b1;
if (key == range::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;
}
glVertexPointer (2, GL_INT, 0, pts);
int L = extents.left;
glColor3f (r0, g0, b0);
pts[0]=L; pts[1]=extents.bottom;
pts[2]=L; pts[3]=extents.top;
glDrawArrays (GL_LINES, 0, 2);
draw_string (notes[0].name, L, ytop1);
draw_string (notes[0].name, L, ybot1);
if (show_frequency) {
glColor3f (r1, g1, b1);
draw_string (notes[0].hz_name, L, ybot2);
draw_string (notes[0].hz_name, L, ytop2);
}
if (label_what == BOTH) {
if (key == range::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;
}
int R = extents.right;
glColor3f (r0, g0, b0);
pts[0]=R; pts[1]=extents.bottom;
pts[2]=R; pts[3]=extents.top;
glVertexPointer (2, GL_INT, 0, pts);
glDrawArrays (GL_LINES, 0, 2);
draw_string (notes[1].name, R, ybot1);
draw_string (notes[1].name, R, ytop1);
if (show_frequency) {
glColor3f (r1, g1, b1);
draw_string (notes[1].hz_name, R, ybot2);
draw_string (notes[1].hz_name, R, ytop2);
}
}
glColor3f (fr, fr, fr);
draw_string (octave, extents.midx, extents.midy);
}
void range::sample_rate_changed () {
for (int i = 0; i < 2; ++i) notes[i].set_frequency (notes[i].hz);
delta_step = notes[1].step - notes[0].step;
}