Rev 2097 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
964 | jag | 1 | /* |
2 | * scale_notes.cc |
||
2302 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2025 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 "scale_notes.h" |
||
9 | #include "main.h" |
||
10 | #include "ui.h" |
||
11 | #include "instrument.h" |
||
12 | |||
13 | #include <fstream> |
||
14 | using namespace std; |
||
15 | |||
16 | extern int NOTATION; |
||
17 | extern const char* WESTERN_FLAT []; |
||
18 | extern map<std::string, int> NOTE_POS; |
||
19 | extern int NUM_INTERVALS; |
||
20 | |||
21 | extern ofstream dlog; |
||
22 | |||
23 | void scale_notes::setup () { |
||
24 | |||
25 | lbl.set_text ("Scale = "); |
||
26 | lbl.children.clear (); |
||
27 | for (int i = 0; i < NUM_INTERVALS; ++i) { |
||
28 | checkbutton& cbi = cb_notes[i]; |
||
29 | cbi.set_listener (0); |
||
30 | cbi.turn_off (); |
||
31 | } |
||
32 | |||
33 | // label notes |
||
34 | if (NOTATION == WESTERN) { |
||
35 | for (int i = 0, j = NUM_INTERVALS, k = get_current_instrument()->scaleinfo.western; i < j; ++i) { |
||
1120 | jag | 36 | cb_notes[i].set_text (WESTERN_FLAT[k++]); |
964 | jag | 37 | k = k % 12; |
38 | } |
||
1829 | jag | 39 | } else if (NOTATION == NUMERIC) { |
964 | jag | 40 | for (int i = 0, j = NUM_INTERVALS; i < j; ++i) { |
1120 | jag | 41 | cb_notes[i].set_text (INTERVAL_NAMES[i]); |
964 | jag | 42 | } |
1829 | jag | 43 | } else { |
44 | extern map<string, string> INT2IND; |
||
45 | for (int i = 0, j = NUM_INTERVALS; i < j; ++i) { |
||
46 | cb_notes[i].set_text (INT2IND[INTERVAL_NAMES[i]]); |
||
47 | } |
||
964 | jag | 48 | } |
49 | |||
50 | // mark notes of the scale |
||
51 | scale_info& scaleinfo = get_current_instrument ()->scaleinfo; |
||
52 | for (int i = 0; i < scaleinfo.num_notes; ++i) { |
||
53 | int p = NOTE_POS [scaleinfo.notes[i]]; |
||
54 | cb_notes[p].turn_on (); |
||
55 | } |
||
56 | |||
57 | for (int i = 0, j = NUM_INTERVALS; i < j; ++i) { |
||
58 | lbl.add_child (&cb_notes[i]); |
||
59 | cb_notes[i].set_listener (this); |
||
60 | } |
||
61 | |||
62 | } |
||
63 | |||
64 | void scale_notes::set_pos (int x, int y) { |
||
65 | widget::set_pos (x, y); |
||
66 | lbl.set_pos (x, y); |
||
67 | advance_right (x, lbl); |
||
68 | for (int i = 0; i < NUM_INTERVALS; ++i) { |
||
69 | checkbutton& cb = cb_notes[i]; |
||
70 | cb.set_pos (x, y); |
||
71 | advance_right (x, cb); |
||
72 | } |
||
73 | } |
||
74 | |||
75 | int scale_notes::handle_input () { |
||
76 | int r = lbl.handle_input (); |
||
77 | for (size_t i = 1, j = NUM_INTERVALS - 1; i < j; ++i) { // dont let editing of tonic |
||
78 | r |= cb_notes[i].handle_input (); |
||
79 | } |
||
80 | return r; |
||
81 | } |
||
82 | |||
83 | void scale_notes::draw () { |
||
84 | lbl.draw (); |
||
85 | for (size_t i = 0, j = NUM_INTERVALS; i < j; ++i) cb_notes[i].draw (); |
||
86 | } |
||
87 | |||
88 | void scale_notes::update () { |
||
89 | lbl.update (); |
||
1120 | jag | 90 | for (int i = 0; i < NUM_INTERVALS; ++i) cb_notes[i].set_text (cb_notes[i].text); |
964 | jag | 91 | set_pos (posx, posy); |
92 | } |
||
93 | |||
94 | void scale_notes::refresh () { |
||
95 | setup (); |
||
96 | update (); |
||
97 | } |
||
98 | |||
99 | void scale_notes::changed (checkbutton& cb) { |
||
100 | get_current_instrument()->scaleinfo.update (cb_notes); |
||
101 | } |
||
102 |