Rev 2009 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1528 | jag | 1 | /* |
2 | * keyboard_keyboard.h |
||
2097 | jag | 3 | * DIN Is Noise is copyright (c) 2006-2024 Jagannathan Sampath |
1713 | jag | 4 | * DIN Is Noise is released under GNU Public License 2.0 |
1528 | jag | 5 | * For more information, please visit https://dinisnoise.org/ |
6 | */ |
||
7 | |||
8 | |||
9 | #ifndef __keyboard_keyboard |
||
10 | #define __keyboard_keyboard |
||
11 | |||
12 | #include "ui.h" |
||
13 | #include "instrument.h" |
||
14 | #include "note.h" |
||
15 | #include "solver.h" |
||
16 | #include "play.h" |
||
17 | #include "multi_curve.h" |
||
18 | #include "curve_editor.h" |
||
19 | #include "listeners.h" |
||
20 | #include "random.h" |
||
21 | #include "color.h" |
||
22 | #include "triggered_note.h" |
||
23 | #include "curve_library.h" |
||
24 | #include <SDL/SDL.h> |
||
25 | |||
26 | struct key_info { |
||
27 | |||
28 | Uint8 id; // from SDL |
||
29 | |||
30 | // visual |
||
31 | char ch; // character |
||
32 | int x, y; // position |
||
33 | float r, g, b; // color |
||
34 | |||
35 | int attacked; // attacked? |
||
36 | |||
37 | key_info (int i = -1, char c = '.', int a = 0) : id (i), ch (c), attacked (a) {r = g = b = 1;} |
||
38 | |||
39 | }; |
||
40 | |||
41 | struct keyboard_keyboard : instrument, scale_listener { |
||
42 | |||
43 | multi_curve wave; // waveform |
||
44 | curve_editor waved; // waveform shape editor |
||
45 | wave_listener wavlis; // waveform edit listener |
||
46 | void update_waveform (multi_curve& crv); |
||
47 | |||
48 | std::vector<note> notes; // notes of the scale |
||
49 | void setup_notes (int overwrite = 1); |
||
50 | |||
51 | int num_triggered_notes; |
||
52 | std::list <triggered_note> triggered_notes; // currently active notes |
||
53 | int trig_what; |
||
54 | |||
55 | void remove_finished_notes (); |
||
56 | void attack_note (int ky); |
||
57 | void decay_note (int ky); |
||
58 | int render_audio (float* L, float* R); |
||
59 | |||
60 | std::map <int, std::vector<key_info> > scale2keybd; |
||
61 | static const int MAX_KEYS = 256; // assume no keycode exceeds 255 |
||
62 | int keybd2notes [MAX_KEYS]; |
||
63 | std::vector<key_info> keys; |
||
64 | |||
65 | // attack & decay curve |
||
66 | multi_curve attackcrv, decaycrv; |
||
67 | curve_editor attacked, decayed; |
||
68 | attack_listener attacklis; |
||
69 | decay_listener decaylis; |
||
70 | void update_attack (); |
||
71 | void update_decay (); |
||
72 | |||
73 | int handle_input (); |
||
74 | |||
75 | // visual |
||
76 | |||
77 | int pts[8]; // for opengl |
||
78 | |||
79 | float recent_note_hz; |
||
80 | int show_nearby_notes; |
||
81 | |||
82 | // mouse based pitch bend |
||
83 | // |
||
84 | int last_mousex, last_mousey; |
||
85 | int marker_x; |
||
86 | void mouse_bend (); |
||
87 | void calc_mouse_bend (triggered_note& ti); |
||
88 | int turn_off_bend (); |
||
89 | |||
90 | int pressx, hearx; // for the words Press and Hear (see draw ()) |
||
91 | int arm, ymarker, ychars, ynotes, spacing; |
||
92 | void calc_visual_params (); |
||
93 | |||
94 | void draw (); |
||
95 | |||
96 | std::string fname; |
||
97 | keyboard_keyboard (); |
||
98 | ~keyboard_keyboard (); |
||
99 | |||
100 | void setup (); |
||
101 | |||
102 | help helptext; |
||
103 | |||
104 | // MIDI |
||
105 | // |
||
106 | static const int MIDI_MAX = 128; |
||
107 | static const int color_index []; |
||
108 | note midi_notes [MIDI_MAX]; |
||
109 | void setup_midi_notes (); |
||
110 | void note_on (unsigned char id, unsigned char vel); |
||
111 | void note_off (unsigned char id); |
||
112 | void pitch_bend (float v); |
||
113 | |||
114 | // MIDI velocity curve |
||
115 | multi_curve velcrv; |
||
116 | velocity_listener vellis; |
||
117 | curve_editor veled; |
||
118 | curve_library vellib; |
||
119 | solver velsol; |
||
120 | |||
121 | void enter (); |
||
122 | void bg (); |
||
123 | |||
124 | void load_scale (int dummy = 0); |
||
125 | void scale_changed (); |
||
126 | void scale_loaded (); |
||
127 | void tonic_changed (); |
||
128 | |||
129 | }; |
||
130 | |||
131 | extern keyboard_keyboard keybd2; |
||
132 | extern float ATTACK_TIME; |
||
133 | extern float DECAY_TIME; |
||
134 | extern int PITCH_BEND; |
||
135 | extern float PITCH_BEND_PER_PIXEL; |
||
136 | extern float NOTE_VOLUME; |
||
137 | |||
138 | #endif |
||
139 | |||
140 | |||
141 |