Rev 315 |
Rev 407 |
Go to most recent revision |
Blame |
Compare with Previous |
Last modification |
View Log
| RSS feed
/*
* globals.cc
* DIN Is Noise is copyright (c) 2006-2017 Jagannathan Sampath
* For more information, please visit http://dinisnoise.org/
*/
#include "globals.h"
#include <map>
#include <iostream>
#include "viewwin.h"
#include <fstream>
using namespace std;
extern ofstream dlog;
extern int SAMPLE_RATE;
extern string INTERVALS_FILE;
extern int NUM_INTERVALS;
extern map <string, float> INTERVALS;
extern vector<string> INTERVAL_NAMES;
extern vector<float> INTERVAL_VALUES;
extern map <string, int> NOTE_POS;
extern int NUM_VOLUMES, LAST_VOLUME;
extern float DELTA_VOLUME;
extern int NUM_MICROTONES;
extern float BOTTOM01, HEIGHT01;
extern string SCALE;
extern float DELTA_BPM;
extern int NUM_OCTAVES;
extern string user_data_dir;
void calc_volume_vars (int h) { // for microtonal keyboard
NUM_VOLUMES = h + 1;
DELTA_VOLUME = 1.0f / h;
LAST_VOLUME = h;
}
int load_globals::load_intervals (const string& fname) {
ifstream file ((user_data_dir + fname).c_str(), ios::in);
if (file) {
INTERVALS_FILE = fname;
file >> ignore >> NUM_INTERVALS;
INTERVALS.clear ();
INTERVAL_NAMES.clear ();
INTERVAL_VALUES.clear ();
for (int i = 0, pos = 0; i < NUM_INTERVALS; ++i) {
string note_name;
float value;
file >> note_name >> value;
INTERVALS [note_name] = value;
NOTE_POS [note_name] = pos++;
INTERVAL_NAMES.push_back (note_name);
INTERVAL_VALUES.push_back (value);
}
return 1;
} else return 0;
}
load_globals::load_globals () {
string fname (user_data_dir + "globals");
ifstream file (fname.c_str(), ios::in);
if (file) {
file >> ignore >> INTERVALS_FILE;
file >> ignore >> BOTTOM01;
file >> ignore >> HEIGHT01;
file >> ignore >> NUM_MICROTONES;
file >> ignore >> NUM_OCTAVES;
file >> ignore >> viewport::handle_radius;
dlog << "loaded globals from: " << fname << endl;
load_intervals (INTERVALS_FILE);
} else {
dlog << "!!! could not load globals !!!" << endl;
}
}