1 /* 2 * keyboard_keyboard.h 3 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath 4 * DIN Is Noise is released under GNU Public License 2.0 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 idkey_info37 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 color note_color [2]; 108 static const int color_index []; 109 note midi_notes [MIDI_MAX]; 110 void setup_midi_notes (); 111 void note_on (unsigned char id, unsigned char vel); 112 void note_off (unsigned char id); 113 void pitch_bend (float v); 114 115 // MIDI velocity curve 116 multi_curve velcrv; 117 velocity_listener vellis; 118 curve_editor veled; 119 curve_library vellib; 120 solver velsol; 121 122 void enter (); 123 void bg (); 124 125 void load_scale (int dummy = 0); 126 void scale_changed (); 127 void scale_loaded (); 128 void tonic_changed (); 129 130 }; 131 132 extern keyboard_keyboard keybd2; 133 extern float ATTACK_TIME; 134 extern float DECAY_TIME; 135 extern int PITCH_BEND; 136 extern float PITCH_BEND_PER_PIXEL; 137 extern float NOTE_VOLUME; 138 139 #endif 140 141 142 143