File: globals.cc

package info (click to toggle)
din 5.2.1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,152 kB
  • ctags: 2,490
  • sloc: cpp: 9,369; sh: 6,563; ansic: 2,977; tcl: 1,770; makefile: 285
file content (141 lines) | stat: -rw-r--r-- 3,390 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * This file is part of din.
 *
 * din is copyright (c) 2006 - 2012 S Jagannathan <jag@dinisnoise.org>
 * For more information, please visit http://dinisnoise.org
 *
 * din is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * din is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with din.  If not, see <http://www.gnu.org/licenses/>.
 *
*/

#include "globals.h"
#include <map>
#include <fstream>
#include <iostream>
#include "viewwin.h"
#include "ansi_color_codes.h"
using namespace std;

extern string APP_NAME;
extern int SCREEN_WIDTH, SCREEN_HEIGHT, SCREEN_DEPTH;

extern int SAMPLE_RATE;
extern float MIN_TONIC, MAX_TONIC;

extern string TUNING;
extern string INTERVALS_FILE;
extern int NUM_INTERVALS;
extern string FIRST_INTERVAL_NAME, LAST_INTERVAL_NAME;
extern map <string, float> INTERVALS;
extern vector<float> INTERVALS_SEQ;
extern map <string, int> NOTE_POS;

extern int NUM_VOLUMES, LAST_VOLUME;
extern float DELTA_VOLUME;

extern int NUM_MICROTONES;
extern int LEFT, BOTTOM, RIGHT, TOP, HEIGHT;

extern string SCALE;

extern int FPS, USLEEP;
extern double FPS_T;

extern float DELTA_BPM;

extern int DRONE_HANDLE_SIZE;

extern int NUM_OCTAVES;

void calc_volume_vars (int h) { // for microtonal keyboard
  NUM_VOLUMES = h + 1;
  DELTA_VOLUME = 1./ h;
  LAST_VOLUME = h;
}

bool load_globals::load_intervals (const string& fname) {

  extern string dotdin;
  ifstream file ((dotdin + fname).c_str(), ios::in);
  if (file) {

    INTERVALS_FILE = fname;

    file >> ignore >> NUM_INTERVALS;

    INTERVALS.clear ();
    INTERVALS_SEQ.clear ();

    for (int i = 0, last = NUM_INTERVALS - 1, pos = 0; i < NUM_INTERVALS; ++i, ++pos) {

      string note_name;
      float value;

      file >> note_name >> value;

      if (i == 0) FIRST_INTERVAL_NAME = note_name;
      else if (i == last) LAST_INTERVAL_NAME = note_name;

      INTERVALS [note_name] = value;
      NOTE_POS [note_name] = pos;

      INTERVALS_SEQ.push_back (value);

    }

    return true;


  } else return false;

}

load_globals::load_globals () {

  extern string dotdin;

  string fname = dotdin + "globals";

  ifstream file (fname.c_str(), ios::in);
  if (file) {
    cout << LOAD << "<<< loading globals";
    APP_NAME = "DIN Is Noise 5.2.1";
    file >> ignore >> SCREEN_WIDTH >> SCREEN_HEIGHT;
    file >> ignore >> INTERVALS_FILE;
    file >> ignore >> SCALE;
    file >> ignore >> LEFT >> BOTTOM;
    file >> ignore >> HEIGHT;
    file >> ignore >> NUM_MICROTONES;
    file >> ignore >> NUM_OCTAVES;
    file >> ignore >> viewport::handle_radius;
    cout << ", done >>>" << ENDL;
  } else {
    cout << "bad globals file, will use defaults " << endl;
    APP_NAME = "din";
    SCREEN_WIDTH = 640; SCREEN_HEIGHT = 480;
    INTERVALS_FILE = "et.tuning";
    SCALE = "minor";
    LEFT = 0; BOTTOM = 150; HEIGHT = 300;
    NUM_MICROTONES = 150;
  }

  load_intervals (INTERVALS_FILE);
  TOP = BOTTOM + HEIGHT;
  calc_volume_vars (HEIGHT);

}