Subversion Repositories DIN Is Noise

Rev

Rev 2327 | Details | Compare with Previous | Last modification | View Log | RSS feed

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