[r3028]: trunk / src / qtractorMidiEditor.h Maximize Restore History

Download this file

qtractorMidiEditor.h    614 lines (453 with data), 16.4 kB

  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
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
// qtractorMidiEditor.h
//
/****************************************************************************
Copyright (C) 2005-2012, rncbc aka Rui Nuno Capela. All rights reserved.
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 2
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 along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*****************************************************************************/
#ifndef __qtractorMidiEditor_h
#define __qtractorMidiEditor_h
#include "qtractorMidiCursor.h"
#include "qtractorMidiEditSelect.h"
#include "qtractorMidiEvent.h"
#include <QSplitter>
#include <QHash>
// Forward declarations.
class qtractorScrollView;
class qtractorRubberBand;
class qtractorCommandList;
class qtractorMidiEditList;
class qtractorMidiEditTime;
class qtractorMidiEditView;
class qtractorMidiEditEventScale;
class qtractorMidiEditEvent;
class qtractorMidiEditCommand;
class qtractorMidiClip;
class qtractorTimeScale;
class QFrame;
class QComboBox;
class QCloseEvent;
class QCursor;
//----------------------------------------------------------------------------
// qtractorMidiEditor -- The main session track listview widget.
class qtractorMidiEditor : public QSplitter
{
Q_OBJECT
public:
// Constructor.
qtractorMidiEditor(QWidget *pParent);
// Destructor.
~qtractorMidiEditor();
// MIDI clip sequence accessors.
void setMidiClip(qtractorMidiClip *pMidiClip);
qtractorMidiClip *midiClip() const;
// MIDI clip properties accessors.
const QString& filename() const;
unsigned short trackChannel() const;
unsigned short format() const;
qtractorMidiSequence *sequence() const;
// Event foreground (outline) color.
void setForeground(const QColor& fore);
const QColor& foreground() const;
// Event background (fill) color.
void setBackground(const QColor& back);
const QColor& background() const;
// Snap-to-bar zebra mode.
void setSnapZebra(bool bSnapZebra);
bool isSnapZebra() const;
// Snap-to-beat grid mode.
void setSnapGrid(bool bSnapGrid);
bool isSnapGrid() const;
// Floating tool-tips mode.
void setToolTips(bool bToolTips);
bool isToolTips() const;
// Edit (creational) mode.
void setEditMode(bool bEditMode);
bool isEditMode() const;
// Edit draw (notes) mode.
void setEditModeDraw(bool bEditModeDraw);
bool isEditModeDraw() const;
// Zoom (view) modes.
enum { ZoomNone = 0, ZoomHorizontal = 1, ZoomVertical = 2, ZoomAll = 3 };
void setZoomMode(int iZoomMode);
int zoomMode() const;
// Zoom ratio accessors.
void setHorizontalZoom(unsigned short iHorizontalZoom);
unsigned short horizontalZoom() const;
void setVerticalZoom(unsigned short iVerticalZoom);
unsigned short verticalZoom() const;
// Local time scale accessors.
qtractorTimeScale *timeScale() const;
unsigned long timeOffset() const;
// The original clip time-scale length/time.
void setClipLength(unsigned long iClipLength);
unsigned long clipLength() const;
// Reset original clip time-scale length/time.
void resetClipLength();
// Time-scale offset (in frames) accessors.
void setOffset(unsigned long iOffset);
unsigned long offset() const;
// Time-scale length (in frames) accessors.
void setLength(unsigned long iLength);
unsigned long length() const;
// Child widgets accessors.
QFrame *editListHeader() const;
qtractorMidiEditList *editList() const;
qtractorMidiEditTime *editTime() const;
qtractorMidiEditView *editView() const;
qtractorMidiEditEventScale *editEventScale() const;
qtractorMidiEditEvent *editEvent() const;
QFrame *editEventFrame() const;
// Edit-head/tail accessors.
void setEditHead(unsigned long iEditHead, bool bSyncView = true);
unsigned long editHead() const;
int editHeadX() const;
void setEditTail(unsigned long iEditTail, bool bSyncView = true);
unsigned long editTail() const;
int editTailX() const;
// Play-head positioning.
void setPlayHead(unsigned long iPlayHead, bool bSyncView = true);
unsigned long playHead() const;
int playHeadX() const;
// Update time-scale to master session.
void updateTimeScale();
// Play-head follow-ness.
void setSyncView(bool bSyncView);
bool isSyncView() const;
// Note autition while editing.
void setSendNotes(bool bSendNotes);
bool isSendNotes() const;
// Note event value vs. duration display.
void setNoteDuration(bool bNoteDuration);
bool isNoteDuration() const;
// Note event coloring.
void setNoteColor(bool bNoteColor);
bool isNoteColor() const;
// Note event coloring.
void setValueColor(bool bValueColor);
bool isValueColor() const;
// Snap-to-scale/quantize key accessor.
void setSnapToScaleKey(int iSnapToScaleKey);
int snapToScaleKey() const;
// Snap-to-scale/quantize type accessor.
void setSnapToScaleType(int iSnapToScaleType);
int snapToScaleType() const;
// Alterrnate command action update helper...
void updateUndoAction(QAction *pAction) const;
void updateRedoAction(QAction *pAction) const;
// Command predicate status.
bool canUndo() const;
bool canRedo() const;
// Undo/redo last edit command.
void undoCommand();
void redoCommand();
// Whether there's any items currently selected.
bool isSelected() const;
// Whether there's any items on the clipboard.
static bool isClipboard();
// Clipboard commands.
void cutClipboard();
void copyClipboard();
void pasteClipboard(
unsigned short iPasteCount = 1, unsigned long iPastePeriod = 0);
// Retrieve current paste period.
// (as from current clipboard width)
unsigned long pastePeriod() const;
// Execute event removal.
void deleteSelect();
// Select all/none contents.
void selectAll(qtractorScrollView *pScrollView,
bool bSelect = true, bool bToggle = false);
// Select range view contents.
void selectRange(qtractorScrollView *pScrollView,
bool bToggle = false, bool bCommit = false);
// Select everything between a given view rectangle.
void selectRect(qtractorScrollView *pScrollView,
const QRect& rect, bool bToggle = false, bool bCommit = false);
// Add/remove one single event to current selection.
void selectEvent(qtractorMidiEvent *pEvent, bool bSelect = true);
// Retrieve current selection.
QList<qtractorMidiEvent *> selectedEvents() const;
// Selectable event predicate.
bool isEventSelectable(qtractorMidiEvent *pEvent) const;
// Whether there's any events beyond the insertion point (edit-tail).
bool isInsertable() const;
// Insert edit range.
void insertEditRange();
// Update/sync integral contents.
void updateContents();
// Try to center vertically the edit-view...
void centerContents();
// Reset event cursors.
void reset(bool bSelectClear);
// Clear all contents.
void clear();
// To optimize and keep track of current (re)draw
// position, mostly like an sequence cursor/iterator.
qtractorMidiEvent *seekEvent(unsigned long iTime);
// Get event from given contents position.
qtractorMidiEvent *eventAt(qtractorScrollView *pScrollView,
const QPoint& pos, QRect *pRect = NULL);
// Start immediate some drag-edit mode...
qtractorMidiEvent *dragEditEvent(qtractorScrollView *pScrollView,
const QPoint& pos, Qt::KeyboardModifiers modifiers);
// Track drag-move-select cursor and mode...
qtractorMidiEvent *dragMoveEvent (qtractorScrollView *pScrollView,
const QPoint& pos, Qt::KeyboardModifiers modifiers);
// Start drag-move-selecting...
void dragMoveStart(qtractorScrollView *pScrollView,
const QPoint& pos, Qt::KeyboardModifiers modifiers);
// Update drag-move-selection...
void dragMoveUpdate(qtractorScrollView *pScrollView,
const QPoint& pos, Qt::KeyboardModifiers modifiers);
// Commit drag-move-selection...
void dragMoveCommit(qtractorScrollView *pScrollView,
const QPoint& pos, Qt::KeyboardModifiers modifiers);
// Trap for help/tool-tip and leave events.
bool dragMoveFilter(qtractorScrollView *pScrollView,
QObject *pObject, QEvent *pEvent);
// Keyboard event handler (common).
bool keyPress(qtractorScrollView *pScrollView,
int iKey, Qt::KeyboardModifiers modifiers);
// Keyboard step handler.
bool keyStep(int iKey);
// Lost focus handler.
void focusOut(qtractorScrollView *pScrollView);
// Show selection tooltip...
void showToolTip(qtractorScrollView *pScrollView, const QRect& rect) const;
// MIDI event tool tip helper.
QString eventToolTip(qtractorMidiEvent *pEvent,
long iTimeDelta = 0, int iNoteDelta = 0, int iValueDelta = 0) const;
// Visualize the event selection drag-move.
void paintDragState(qtractorScrollView *pScrollView,
QPainter *pPainter);
// Reset drag/select/move state.
void resetDragState(qtractorScrollView *pScrollView);
// Tool indexes.
enum Tool {
Quantize = 0,
Transpose = 1,
Normalize = 2,
Randomize = 3,
Resize = 4,
Rescale = 5,
Timeshift = 6
};
// Edit tools form page selector.
void executeTool(int iToolIndex);
// Command list accessor.
qtractorCommandList *commands() const;
// Note name map accessor.
const QString noteName(unsigned char note) const;
// Controller name map accessor.
const QString& controllerName(unsigned char controller) const;
// Default note name map accessor.
static const QString defaultNoteName(unsigned char note, bool fDrums = false);
// Default controller name accessor.
static const QString& defaultControllerName(unsigned char controller);
// Default scale key/type names accessors.
static const QStringList& scaleKeyNames();
static const QStringList& scaleTypeNames();
// Scale quantizer method.
static unsigned char snapToScale(
unsigned char note, int iKey, int iScale);
public slots:
// Redirect selection/change notification.
void selectionChangeNotify();
void contentsChangeNotify();
// Redirect note on/off;
void sendNote(int iNote, int iVelocity = 0);
// Update instrument defined names for current clip/track.
void updateInstrumentNames();
// Zoom view slots.
void zoomIn();
void zoomOut();
void zoomReset();
protected:
// Zoom factor constants.
enum { ZoomMin = 10, ZoomBase = 100, ZoomMax = 1000, ZoomStep = 10 };
// Common zoom factor settlers.
void horizontalZoomStep(int iZoomStep);
void verticalZoomStep(int iZoomStep);
// Zoom centering context.
struct ZoomCenter
{
int x, y, item;
unsigned long frame;
};
// Zoom centering prepare and post methods.
void zoomCenterPre(ZoomCenter& zc) const;
void zoomCenterPost(const ZoomCenter& zc);
// Selection flags
enum {
SelectNone = 0,
SelectClear = 1,
SelectToggle = 2,
SelectCommit = 4
};
// Update all selection rectangular areas.
void updateSelect(bool bSelectReset);
// Update the event selection list.
void updateDragSelect(qtractorScrollView *pScrollView,
const QRect& rectSelect, int flags);
// Compute current drag time snap (in ticks).
long timeSnap(long iTime) const;
// Compute current drag time delta (in ticks).
long timeDelta(qtractorScrollView *pScrollView) const;
// Compute current drag note delta.
int noteDelta(qtractorScrollView *pScrollView) const;
// Compute current drag value delta.
int valueDelta(qtractorScrollView *pScrollView) const;
// Apply the event drag-resize (also editing).
void resizeEvent(qtractorMidiEvent *pEvent,
long iTimeDelta, int iValueDelta,
qtractorMidiEditCommand *pEditCommand = NULL);
// Update event selection rectangle.
void updateEvent(qtractorMidiEvent *pEvent);
// Update event visual rectangles.
void updateEventRects(qtractorMidiEvent *pEvent,
QRect& rectEvent, QRect& rectView) const;
// Drag-move current selection.
void updateDragMove(qtractorScrollView *pScrollView, const QPoint& pos);
// Finalize the event drag-move.
void executeDragMove(qtractorScrollView *pScrollView, const QPoint& pos);
// Drag-resize current selection (also editing).
void updateDragResize(qtractorScrollView *pScrollView, const QPoint& pos);
// Finalize the event drag-resize (also editing).
void executeDragResize(qtractorScrollView *pScrollView, const QPoint& pos);
// Finalize the event drag-paste.
void executeDragPaste(qtractorScrollView *pScrollView, const QPoint& pos);
// Vertical line position drawing.
void drawPositionX(int& iPositionX, int x, bool bSyncView);
protected slots:
// Horizontal zoom view slots.
void horizontalZoomInSlot();
void horizontalZoomOutSlot();
void horizontalZoomResetSlot();
// Vertical zoom view slots.
void verticalZoomInSlot();
void verticalZoomOutSlot();
void verticalZoomResetSlot();
// Command execution notification slot.
void updateNotifySlot(bool bRefresh);
signals:
// Emitted on selection/changes.
void selectNotifySignal(qtractorMidiEditor *);
void changeNotifySignal(qtractorMidiEditor *);
// Send note event signale.
void sendNoteSignal(int, int);
private:
// The editing sequence.
qtractorMidiClip *m_pMidiClip;
// Event fore/background colors.
QColor m_foreground;
QColor m_background;
// The main child widgets.
QFrame *m_pEditListHeader;
qtractorMidiEditList *m_pEditList;
qtractorMidiEditTime *m_pEditTime;
qtractorMidiEditView *m_pEditView;
qtractorMidiEditEventScale *m_pEditEventScale;
qtractorMidiEditEvent *m_pEditEvent;
QFrame *m_pEditEventFrame;
// The local time scale.
qtractorTimeScale *m_pTimeScale;
// The original clip time-scale length/time.
unsigned long m_iClipLengthTime;
// The local time-scale offset/length.
unsigned long m_iOffset;
unsigned long m_iLength;
// Event cursors (main time-line).
qtractorMidiCursor m_cursor;
qtractorMidiCursor m_cursorAt;
// The current selection list.
qtractorMidiEditSelect m_select;
// Common drag state.
enum DragState {
DragNone = 0, DragStart, DragSelect,
DragMove, DragResize, DragPaste, DragStep
} m_dragState, m_dragCursor;
// Common drag-resize mode.
enum ResizeMode {
ResizeNone = 0, ResizeNoteRight, ResizeNoteLeft,
ResizeValueTop, ResizePitchBendTop, ResizePitchBendBottom
} m_resizeMode;
// The current selecting/dragging stuff.
qtractorMidiEvent *m_pEventDrag;
QPoint m_posDrag;
QRect m_rectDrag;
// Differential drag-move position.
QPoint m_posDelta;
// Step (keyboard) drag-move position
QPoint m_posStep;
// Which widget holds focus on drag-paste?
qtractorScrollView *m_pEditPaste;
// Viewport rubber-banding stuff.
qtractorRubberBand *m_pRubberBand;
// Zoom mode flag.
int m_iZoomMode;
// Edit mode flags.
bool m_bEditMode;
bool m_bEditModeDraw;
bool m_bEventDragEdit;
// Snap-to-beat/bar grid/zebra mode.
bool m_bSnapZebra;
bool m_bSnapGrid;
// Floating tool-tips mode.
bool m_bToolTips;
// Last useful editing values.
struct {
unsigned char note;
unsigned char value;
unsigned long duration;
unsigned short pitchBend;
} m_last;
// The local edit command list/queue.
qtractorCommandList *m_pCommands;
// Local edit-head/tail positioning.
unsigned long m_iEditHead;
int m_iEditHeadX;
unsigned long m_iEditTail;
int m_iEditTailX;
// Local playhead positioning.
unsigned long m_iPlayHead;
int m_iPlayHeadX;
bool m_bSyncView;
// Note autition while editing.
bool m_bSendNotes;
// Event value stick vs. duration rectangle.
bool m_bNoteDuration;
// Event (note, velocity) coloring.
bool m_bNoteColor;
bool m_bValueColor;
// The local clipboard stuff (singleton).
static struct ClipBoard
{
// Constructor.
ClipBoard() {}
// Destructor.
~ClipBoard() { clear(); }
// Clipboard clear.
void clear() { qDeleteAll(items); items.clear(); }
// Clipboard members.
QList<qtractorMidiEvent *> items;
// Singleton declaration.
} g_clipboard;
// Instrument defined names for current clip/track.
QHash<unsigned char, QString> m_controllerNames;
QHash<unsigned char, QString> m_noteNames;
// Snap-to-scale (aka.in-place scale-quantize) stuff.
int m_iSnapToScaleKey;
int m_iSnapToScaleType;
};
#endif // __qtractorMidiEditor_h
// end of qtractorMidiEditor.h