forked from psemiletov/eko
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocument.h
514 lines (333 loc) · 9.06 KB
/
document.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
/***************************************************************************
* 2010-2021 by Peter Semiletov *
* peter.semiletov@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* aint with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#ifndef DOCUMENT_H
#define DOCUMENT_H
#include <QObject>
#include <QHash>
#include <QLabel>
#include <QStatusBar>
#include <QMainWindow>
#include <QScrollBar>
#include <QCheckBox>
#include <QTimer>
#include <QPushButton>
#include <portaudio.h>
#include "logmemo.h"
#include "tio.h"
#include "floatbuffer.h"
#include "envelope.h"
#include "cvlevelmeter.h"
#include "fxrack.h"
enum ETransportStates
{
STATE_STOP = 0,
STATE_PLAY,
STATE_PAUSE,
STATE_EXIT,
STATE_RECORD
};
enum EUndoModes
{
UNDO_UNDEFINED = 0,
UNDO_DELETE,
UNDO_PASTE,
UNDO_MODIFY,
UNDO_WHOLE,
UNDO_INSERT
};
class CDocumentHolder;
class CDocument;
class CTransportControl: public QObject
{
Q_OBJECT
signals:
void play_pause();
void stop();
public:
void call_play_pause();
void call_stop();
};
class CUndoElement: public QObject
{
Q_OBJECT
public:
int type;
bool selected;
size_t frames_per_section;
size_t start_frames; //selection start
size_t end_frames; //selection end
size_t cursor_frames;
CFloatBuffer *fb;
CUndoElement();
~CUndoElement();
};
class CChannelSamples
{
public:
float *samples;
float temp;
CChannelSamples (size_t size);
~CChannelSamples();
};
class CChannelMinmax
{
public:
CChannelSamples *min_values;
CChannelSamples *max_values;
CChannelMinmax (size_t size);
~CChannelMinmax();
};
class CMinmaxes
{
public:
CChannelMinmax **values;
size_t count;
CMinmaxes (size_t size, size_t sections);
~CMinmaxes();
};
class CWaveform;
class CTimeRuler: public QWidget
{
Q_OBJECT
public:
CWaveform *waveform;
bool init_state;
QColor background_color;
QColor foreground_color;
CTimeRuler (QWidget *parent);
protected:
void paintEvent (QPaintEvent *event);
};
class CWaveEdit;
class CWaveform: public QWidget
{
Q_OBJECT
public:
//top-level link:
CWaveEdit *wave_edit;
CFloatBuffer *fb;
CTimeRuler *timeruler;
CEnvelope env_vol;
bool show_db; //false if floats
bool play_looped;
int selection_selected; //0 - non, 1 - left, 2 - right
int envelope_selected; //-1 - non
CMinmaxes *minmaxes;
QScrollBar *scrollbar;
QTimer timer;
bool init_state;
bool draw_shadow;
bool mouse_pressed;
bool normal_cursor_shape;
bool selected;
QImage waveform_image;
float scale_factor;
int previous_mouse_pos_x;
size_t sel_start_frames;
size_t sel_end_frames;
//calculates positions:
int get_cursor_position_sections(); //in sections
int get_selection_start_sections(); //in sections
int get_selection_end_sections(); //in sections
void set_cursor_by_section (size_t section);
size_t frames_per_section;
size_t sections_total;
size_t get_section_from();
size_t get_section_to();
//colors
QColor cl_waveform_background;
QColor cl_waveform_foreground;
QColor cl_waveform_selection_foreground;
QColor cl_axis;
QColor cl_cursor;
QColor cl_text;
QColor cl_envelope;
QColor cl_env_point_selected;
QColor cl_shadow;
int waveform_selection_alpha;
void load_color (const QString &fname);
//end of colors
CWaveform (QWidget *parent);
~CWaveform();
void set_cursor_value (size_t section);
void set_selstart_value (size_t section);
void set_selend_value (size_t section);
void set_statusbar_text();
void set_cursorpos_text();
void scalef (float factor, size_t start_frm);
void scale (int delta);
void zoom (int factor);
void recalc_view();
void prepare_image();
void magic_update();
void fix_selection_bounds();
void deselect();
void select_all();
void copy_selected();
void delete_selected();
void cut_selected();
void paste();
size_t frames_start();
size_t frames_end();
void set_cursor_to_frames (size_t frame);
//undo/redo stuff
QList <CUndoElement*> undos;
int max_undos;
// int current_undo;
void undo_take_shot (int type, int param = 0);
void undo_top(); //simple test of the undo
void flush_undos();
void redo();
protected:
// void dragEnterEvent (QDragEnterEvent *event);
// void dropEvent (QDropEvent *event);
void paintEvent(QPaintEvent *event);
void mousePressEvent (QMouseEvent *event);
void wheelEvent (QWheelEvent *event );
void keyPressEvent (QKeyEvent *event);
void resizeEvent(QResizeEvent *event);
void mouseMoveEvent (QMouseEvent *event);
void mouseReleaseEvent (QMouseEvent * event);
void mouseDoubleClickEvent ( QMouseEvent * event);
public slots:
void timer_timeout();
};
class CWaveEdit: public QWidget
{
Q_OBJECT
public:
CDocument *doc;
CWaveform *waveform;
QScrollBar *scb_horizontal;
CTimeRuler *timeruler;
CWaveEdit (QWidget *parent = 0);
~CWaveEdit();
bool isReadOnly();
protected:
void dragEnterEvent (QDragEnterEvent *event);
void dropEvent (QDropEvent *event);
public slots:
void scb_horizontal_valueChanged (int value);
};
class CDocument: public QObject
{
Q_OBJECT
public:
QHash <QString, QString> fnameswoexts;
CDocumentHolder *holder;
CWaveEdit *wave_edit;
QString file_name;
QWidget *tab_page;
size_t position;
bool ronly;
CDocument (QObject *parent = 0);
~CDocument();
int get_tab_idx();
void set_tab_caption (const QString &fileName);
void create_new();
bool save_with_name (const QString &fileName);
bool save_with_name_plain (const QString &fileName);
bool open_file (const QString &fileName, bool set_fname = true);
void reload();
QString get_triplex();
void update_title (bool fullname = true);
void paste();
void effects_state_save();
void effects_state_restore();
void effects_close_all();
void effects_update_params();
};
class CDocumentHolder: public QObject
{
Q_OBJECT
public:
CTioHandler tio_handler;
QString fname_current_session;
QHash <QString, QString> palette;
QLabel *l_status_bar;
QLabel *l_maintime;
CTransportControl *transport_control;
CDocument *current;
QString dir_config;
QString def_palette;
QStatusBar *status_bar;
CLogMemo *log;
QList <CDocument*> list;
QMainWindow *parent_wnd;
QTabWidget *tab_widget;
QMenu *recent_menu;
QStringList recent_files;
QString recent_list_fname;
CDocumentHolder (QObject *parent = 0);
~CDocumentHolder();
CDocument* create_new();
CDocument* open_file (const QString &fileName, bool set_fname = true);
void reload_recent_list();
void save_to_session (const QString &fileName);
void load_from_session (const QString &fileName);
void load_palette (const QString &fileName);
void close_current();
void apply_settings();
void apply_settings_single (CDocument *d);
void add_to_recent (CDocument *d);
void update_recent_menu();
CDocument* get_current();
public slots:
void open_recent();
};
class CDSP: public QObject
{
Q_OBJECT
public:
float maxl; //for the current nframes
float maxr;
//mixer stuff
float gain; //in dB
CFloatBuffer *temp_float_buffer;
CDSP (QObject *parent = 0);
~CDSP();
// size_t process (CFloatBuffer *fb, size_t nframes);
size_t process (CDocument *d, size_t nframes);
size_t process_rec (float **buffer, size_t channels, size_t nframes);
};
class CFxRackWindow: public QWidget
{
Q_OBJECT
public:
CVLevelMeter *level_meter;
QTimer tm_level_meter;
CFxRack *fx_rack;
QCheckBox cb_l;
QCheckBox cb_r;
QPushButton *bt_apply;
CFxRackWindow();
~CFxRackWindow();
public slots:
void tm_level_meter_timeout();
// void apply_fx();
void cb_l_changed (int value);
void cb_r_changed (int value);
void dial_gain_valueChanged (int value);
protected:
void closeEvent (QCloseEvent *event);
signals:
void apply_fx_button_pressed();
};
#endif