1 /* 2 * curve_editor.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 __curve_editor 10 #define __curve_editor 11 12 #include <vector> 13 #include <map> 14 #include <list> 15 #include <string> 16 #include <fstream> 17 18 #include "curve.h" 19 #include "multi_curve.h" 20 #include "basic_editor.h" 21 #include "curve_listener.h" 22 #include "curve_samples.h" 23 #include "ui.h" 24 #include "mocap.h" 25 #include "beat2value.h" 26 #include "box_selector.h" 27 #include "curve_picker.h" 28 #include "checkbutton.h" 29 #include "state_button.h" 30 #include "capturer.h" 31 #include "point_modulator.h" 32 #include "hit.h" 33 #include "help.h" 34 35 struct multi_curve; 36 struct curve_editor; 37 struct curve_library; 38 struct plugin; 39 40 extern const char spc; 41 42 struct mouse_macro { 43 // for applying mouse capture to hit vertex/tangent of hit curve 44 mocap mo; // mouse capture data 45 hit_t hit; // hit curve & vertex/tangent 46 state_button* sb; // button on capturer widget 47 int paused; mouse_macromouse_macro48 mouse_macro (const mocap& m, hit_t& h, state_button* b) : mo(m), hit(h), sb(b) { paused = 0;} 49 }; 50 51 struct undo_t { 52 int i; 53 multi_curve curve; 54 window win; undo_tundo_t55 undo_t (int ii, const multi_curve& mc, window& w) : i(ii), curve(mc), win(w) {} 56 }; 57 58 typedef undo_t redo_t; 59 60 struct curve_info { 61 multi_curve* curve; 62 int picked; 63 int disabled; 64 curve_listener* lisner; 65 curve_info (multi_curve* c, curve_listener* l, int picked = 0); 66 curve_info (); 67 }; 68 69 struct curve_editor : basic_editor { 70 71 std::vector <curve_info> curveinfo; // edited curves 72 int curcrv; 73 int num_curves; 74 void clear (); 75 void add (multi_curve* crv, curve_listener* lsnr); 76 curve_info& get_curve_info (int i); 77 multi_curve* get_curve (int i); 78 79 // curve editor features 80 // 81 82 int carry_tangents; // when vertex moves, their tangents move too. 83 int mirror_tangents; // when 1 tangent of a vertex moves, the other moves too. 84 85 int lmb_clicked; 86 87 // picking 88 // 89 90 std::vector <hit_t> hitlist; 91 92 hit_t pik; 93 94 multi_curve* get_picked_curve (); 95 std::string get_picked_curve_name (); 96 hit_t pick_cur_curve (); 97 void set_picked_curve_name (const std::string& n); 98 void curve_picked (); 99 void hilite_item (int id); 100 101 void hittest (multi_curve* crv, int crv_id, const points_array& points, unsigned int what); 102 void hittest (); 103 int filter_hitlist (); 104 void clear_hit (hit_t& h); 105 void calc_hit_params (hit_t& h); 106 void set_pick_from_hitlist (int i); 107 void picked_using_picker (int i); 108 109 // vertex/tangent operations 110 // 111 enum { 112 NOTHING = 0, 113 MOVE_PICKED, 114 MOVE_ALL, 115 PICK_CURVE, 116 INSERT_VERTEX, 117 REMOVE_VERTEX, 118 FOLD_VERTEX, 119 UNFOLD_VERTEX, 120 FOLD_ALL, 121 UNFOLD_ALL, 122 MIRROR_VERTEX, 123 MIRROR_ALL, 124 COPY, 125 PASTE, 126 ADD_VERTEX, 127 START_CAPTURE, 128 ASSIGN_CAPTURE, 129 REMOVE_CAPTURE, 130 MODULATE_POINT 131 }; 132 133 int todo; 134 int next_todo; 135 int stop_todo (); 136 137 void do_nothing (); 138 139 void do_pick_curve (); 140 141 int lmb_move; 142 enum {PREP = 1, FINISH_ON_CLICK = 2}; 143 void prep_move (); 144 int move (); 145 int move (int); 146 int move (hit_t& hit, float x, float y, int eval_now = 1); 147 148 void fold_tangents_using_menu (); 149 void unfold_tangents_using_menu (); 150 void fold_all_tangents (hit_t& hit); 151 void unfold_all_tangents (hit_t& hit); 152 void fold_tangents_of_vertex (hit_t& hit); 153 void unfold_tangents_of_vertex (hit_t& hit); 154 155 void insert (); 156 void insert_using_menu (); 157 158 void remove (); 159 void remove_using_menu (); 160 161 enum {MIRROR_X = 0, MIRROR_Y, MIRROR_BBX, MIRROR_BBY}; 162 int axis; 163 void mirror (int whole_curve = 0); 164 void mirror_using_menu (); 165 166 void set_limit (float f); 167 168 void copy_curve (); 169 void copy_using_menu (); 170 171 void replace (); 172 void paste_using_menu (); 173 174 void swap (); 175 176 // scratch curve 177 // 178 int show_scratch_curve; 179 points_array win_scratch_points, curv_scratch_points; 180 multi_curve scratch_curve; 181 void clear_scratch_curve (); 182 void draw_scratch_curve (); 183 void draw_replacement_curve_using_menu (); 184 void add_vertex (); 185 186 // load and save editor settings 187 std::string settings_filename; 188 189 // undo, redo 190 // 191 std::list <undo_t> undos; 192 std::list <redo_t> redos; 193 void dodo (std::list<undo_t>& do1, std::list<undo_t>& do2, std::string mesg); 194 void do_undo (); 195 void do_redo (); 196 197 // copy & paste 198 static multi_curve copy; 199 void paste (hit_t& h); 200 201 // curve library 202 // 203 curve_library* library; 204 void add_curve (); 205 void replace_curve (); 206 void insert_curve (); 207 void delete_curve (); 208 void load_curve (int dir); 209 void do_load_curve (int dir); 210 211 // mouse capture 212 // 213 std::vector<mouse_macro> macros; 214 capturer_t capturer; 215 void start_mouse_capture_from_menu (); 216 void assign_mouse_capture (); 217 void assign_mouse_capture_from_menu (); 218 void remove_mouse_capture (state_button* sb); 219 void toggle_mouse_capture (std::vector<state_button*>& caps); 220 221 // point modulation 222 point_modulator pomo; 223 void modulate_point (); 224 void modulate_point (int); 225 226 // settings 227 // 228 curve_editor (const std::string& settingsf, const std::string& helpf = "curve_editor.hlp"); 229 ~curve_editor (); 230 void load (const std::string& fname); 231 void save (); 232 233 // ui 234 int handle_input (); 235 236 237 // curve selection ops 238 void pick (int k); 239 void toggle (int k); 240 void enable (int k); 241 void enable_all (); 242 int one_curve_enabled (); 243 std::string selection (); 244 245 // drawing 246 // 247 248 int draw_curve_only; 249 void draw_curve (multi_curve* crv); 250 void draw_tangents (multi_curve* crv); 251 void draw_vertices (multi_curve* crv); 252 void draw_handle (const point<float>& p); 253 void draw_tangent (const point<float>& p, const point<float>& t); 254 void draw_curves (); 255 void draw_vertices (); 256 void draw_tangents (); 257 void draw_all (); 258 void draw (); 259 260 int draw_plugin_output; 261 262 int mark_segments; 263 void mark_curve_segments (); 264 265 int guides; 266 void draw_guides (); 267 268 #ifdef __SVG__ 269 // svg 270 void write_curve (multi_curve* crv, std::ofstream& svg, float w, float h, float t, float left, float top, box<float>& bb); 271 void write_svg (float h, float t, const std::string& fn, float left, float top); 272 void write_samples (std::ofstream& svg); 273 #endif 274 275 #ifdef __HPGL__ 276 // hpgl 277 void write_curve (multi_curve* crv, std::ofstream& hpgl, float scale, float penmag); 278 void write_hpgl (float scale = 5000, float penmag = 100); 279 #endif 280 281 void attach_library (curve_library* lib); 282 283 void enter (); 284 void bg (); 285 286 void set_curve_style (); 287 void toggle_curve_style (); 288 289 void apply_mocap (); 290 void apply_mocap (mouse_macro& m, int dir = 1); 291 292 int sine_enabled, fft_enabled; 293 294 int is_waveform_editor; 295 int samples_enabled; 296 float hz; 297 int nperiods; 298 int offset; 299 curve_samples cs; 300 void set_hz (float zh); 301 void set_periods (int p); 302 void toggle_waveform_samples_display (); 303 void render_curve_samples (); 304 305 std::vector<beat2value*> bv; 306 307 int label_vertices; 308 void toggle_vertex_labels (); 309 310 int overlay; 311 312 std::string next_cursor_mesg; 313 314 void setup_tools_menu (); 315 316 float startt; 317 hit_t rpm; 318 float rotx, roty; 319 float angle; 320 float last_rpm; 321 void set_rpm (float RPM); 322 void rotate (); 323 void scale (float sx, float sy); 324 325 void apply_plugin (plugin* p); 326 327 int hlabel_only; 328 329 int mkr[8]; 330 331 void calc_visual_params (); 332 333 multi_curve mix; 334 335 help helptext; 336 337 static color vtxlbl; 338 339 int esc (); 340 341 void drawerlay (); 342 343 }; 344 345 346 extern curve_picker_t curve_picker; 347 void show_curve_picker (); 348 349 #define CRVED uis.crved 350 351 #endif 352