hydrogen 1.2.3
SongEditor.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2008 by Alex >Comix< Cominu [comix@users.sourceforge.net]
4 * Copyright(c) 2008-2024 The hydrogen development team [hydrogen-devel@lists.sourceforge.net]
5 *
6 * http://www.hydrogen-music.org
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY, without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see https://www.gnu.org/licenses
20 *
21 */
22
23#ifndef SONG_EDITOR_H
24#define SONG_EDITOR_H
25
26#include <vector>
27#include <memory>
28
29#include <unistd.h>
30
31#include <QtGui>
32#include <QtWidgets>
33#include <QList>
34
35#include <core/Object.h>
37#include <core/Timeline.h>
38#include "../EventListener.h"
39#include "PatternFillDialog.h"
40#include "../Selection.h"
43
44namespace H2Core {
45 class Hydrogen;
46 class AudioEngine;
47}
48
49class SongEditor;
52class SongEditorPanel;
53
54static const uint SONG_EDITOR_MIN_GRID_WIDTH = 8;
55static const uint SONG_EDITOR_MAX_GRID_WIDTH = 16;
56
57
67
68class SongEditor : public QWidget
69 , public H2Core::Object<SongEditor>
70 , public SelectionWidget<QPoint>
71 , public EventListener
72{
74 Q_OBJECT
75
76 struct GridCell {
79 float m_fWidth;
80 };
81
82 public:
83 SongEditor( QWidget *parent, QScrollArea *pScrollView, SongEditorPanel *pSongEditorPanel );
85
86 void createBackground();
88 void updatePosition( float fTick );
89
90 int getGridWidth ();
91 void setGridWidth( uint width);
92 int getGridHeight () { return m_nGridHeight; }
93
94 int getCursorRow() const;
95 int getCursorColumn() const;
96
98 void modifyPatternCellsAction( std::vector<QPoint> & addCells, std::vector<QPoint> & deleteCells,
99 std::vector<QPoint> & selectCells );
100
101 void clearThePatternSequenceVector( QString filename );
103
104 int yScrollTarget( QScrollArea *pScrollArea, int *pnPatternInView );
105
106 static constexpr int nMargin = 10;
107
108 public slots:
109
110 void selectAll();
111 void selectNone();
112 void deleteSelection();
113 void copy();
114 void paste();
115 void cut();
117 void scrolled( int );
118
119 private:
120
122
123 QScrollArea * m_pScrollView;
125
128
130 unsigned m_nGridWidth;
133
135
136
140
143
145
147
148
160
166
169 QPoint xyToColumnRow( QPoint p );
170 QPoint columnRowToXy( QPoint p );
172
174 QPoint movingGridOffset() const;
175
178
181 virtual void startMouseLasso( QMouseEvent *ev ) override {
182 m_bSequenceChanged = true;
183 setCursor( Qt::CrossCursor );
184 }
185
186 virtual void endMouseGesture() override {
187 unsetCursor();
188 }
190
193 virtual void mousePressEvent(QMouseEvent *ev) override;
194 virtual void mouseReleaseEvent(QMouseEvent *ev) override;
195 virtual void mouseMoveEvent(QMouseEvent *ev) override;
196 virtual void keyPressEvent (QKeyEvent *ev) override;
197 virtual void keyReleaseEvent (QKeyEvent *ev) override;
198 virtual void paintEvent(QPaintEvent *ev) override;
199 virtual void focusInEvent( QFocusEvent *ev ) override;
200 virtual void focusOutEvent( QFocusEvent *ev ) override;
201 virtual void enterEvent( QEvent *ev ) override;
202 virtual void leaveEvent( QEvent *ev ) override;
204
205 void togglePatternActive( int nColumn, int nRow );
206 void setPatternActive( int nColumn, int nRow, bool bActivate );
207
208 void drawSequence();
209
210 void drawPattern( int pos, int number, bool invertColour, double width );
211 void drawFocus( QPainter& painter );
212
213 std::map< QPoint, GridCell > m_gridCells;
214 void updateGridCells();
216
217 virtual void patternModifiedEvent() override;
218 virtual void relocationEvent() override;
219 virtual void patternEditorLockedEvent() override;
220
222 float m_fTick;
223public:
224
228 virtual std::vector<SelectionIndex> elementsIntersecting( QRect r ) override;
229 virtual QRect getKeyboardCursorRect() override;
230 virtual void validateSelection() override {};
231 virtual void updateWidget() override;
232 virtual void mouseClickEvent( QMouseEvent *ev ) override;
233 virtual void mouseDragStartEvent( QMouseEvent *ev ) override;
234 virtual void mouseDragUpdateEvent( QMouseEvent *ev ) override;
235 virtual void mouseDragEndEvent( QMouseEvent *ev ) override;
236 virtual void selectionMoveEndEvent( QInputEvent *ev ) override;
237 virtual void updateModifiers( QInputEvent *ev );
238 virtual bool canDragElements() override {
239 return false;
240 }
242
243};
244
245inline int SongEditor::getCursorRow() const {
246 return m_nCursorRow;
247}
248
249inline int SongEditor::getCursorColumn() const {
250 return m_nCursorColumn;
251}
252
253
257
258class SongEditorPatternList : public QWidget
259 , protected WidgetWithScalableFont<8, 10, 12>
261 , public H2Core::Object<SongEditorPatternList>
262 , public EventListener
263{
265 Q_OBJECT
266
267 public:
268
269 explicit SongEditorPatternList( QWidget *parent );
271
274
275 void updateEditor();
276 void createBackground();
278 void movePatternLine( int, int );
279 void acceptPatternPropertiesDialogSettings( QString newPatternName, QString newPatternInfo, QString newPatternCategory, int patternNr );
280 void revertPatternPropertiesDialogSettings(QString oldPatternName, QString oldPatternInfo, QString oldPatternCategory, int patternNr);
281 void fillRangeWithPattern(FillRange* r, int nPattern);
282 int getGridHeight() { return m_nGridHeight; }
283
284 virtual void patternModifiedEvent() override;
285 virtual void playingPatternsChangedEvent() override;
286 virtual void songModeActivationEvent() override;
287 virtual void stackedModeActivationEvent( int nValue ) override;
288 virtual void selectedPatternChangedEvent() override;
289 virtual void nextPatternsChangedEvent() override;
290 virtual void relocationEvent() override;
291 virtual void patternEditorLockedEvent() override;
292
293 public slots:
294 void patternPopup_edit();
295 void patternPopup_save();
296 void patternPopup_export();
297 void patternPopup_load();
299 void patternPopup_delete();
301 void patternPopup_fill();
305 virtual void dragEnterEvent(QDragEnterEvent *event) override;
306 virtual void dropEvent(QDropEvent *event) override;
307 virtual void timelineUpdateEvent( int nValue ) override;
309
310 private:
315 static const uint m_nInitialHeight = 10;
316
319
326
328 QLineEdit * m_pLineEdit;
330
332
333 void inlineEditPatternName( int row );
334
335 virtual void mousePressEvent( QMouseEvent *ev ) override;
336 virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override;
337 virtual void paintEvent( QPaintEvent *ev ) override;
338 virtual void mouseMoveEvent(QMouseEvent *event) override;
339 virtual void leaveEvent( QEvent *ev );
340
342
343 void togglePattern( int );
344
345
346 void setRowSelection( RowSelection rowSelection );
352
354};
355
356
357// class SongEditorPatternListener : public EventListener {
358//
359// }
360//
361
363class SongEditorPositionRuler : public QWidget, protected WidgetWithScalableFont<8, 10, 12>, public EventListener, public H2Core::Object<SongEditorPositionRuler>
364{
366 Q_OBJECT
367
368 public:
369 explicit SongEditorPositionRuler( QWidget *parent );
371
372 uint getGridWidth();
373 void setGridWidth (uint width);
374 virtual void tempoChangedEvent( int ) override;
375 virtual void playingPatternsChangedEvent() override;
376 virtual void songModeActivationEvent() override;
377 virtual void relocationEvent() override;
378 virtual void songSizeChangedEvent() override;
379 virtual void patternModifiedEvent() override;
380 virtual void updateSongEvent( int ) override;
381
382 virtual void timelineActivationEvent() override;
383 virtual void timelineUpdateEvent( int nValue ) override;
384 virtual void jackTimebaseStateChangedEvent() override;
385
386 static int tickToColumn( float fTick, uint nGridWidth );
387
388 public slots:
389 void updatePosition();
390 void showTagWidget( int nColumn );
391 void showBpmWidget( int nColumn );
393 void createBackground();
395
396 private:
399 QTimer * m_pTimer;
401 static constexpr uint m_nHeight = 50;
402
405
407 enum class HoveredRow {
409 None,
415 Tag,
417 Ruler
418 };
420
422 float m_fTick;
425
427
430
434
435 virtual void mouseMoveEvent(QMouseEvent *ev) override;
436 virtual void mousePressEvent( QMouseEvent *ev ) override;
437 virtual void mouseReleaseEvent(QMouseEvent *ev) override;
438 virtual void paintEvent( QPaintEvent *ev ) override;
439
440 // virtual void enterEvent( QEvent* ev ) override;
441 virtual void leaveEvent( QEvent* ev ) override;
442 virtual bool event( QEvent* ev ) override;
443
450 int columnToX( int nColumn ) const;
451 int xToColumn( int nX ) const;
452
453 void showToolTip( const QPoint& pos, const QPoint& globalPos );
454
455 void drawTempoMarker( std::shared_ptr<const H2Core::Timeline::TempoMarker> pTempoMarker,
456 bool bEmphasize, QPainter& painter );
462 QRect calcTempoMarkerRect( std::shared_ptr<const H2Core::Timeline::TempoMarker> pTempoMarker,
463 bool bEmphasize = false ) const;
464
465};
466
467#endif
#define H2_OBJECT(name)
Definition Object.h:224
static const uint SONG_EDITOR_MAX_GRID_WIDTH
Definition SongEditor.h:55
static const uint SONG_EDITOR_MIN_GRID_WIDTH
Definition SongEditor.h:54
Drag scroller object.
Definition Selection.h:127
The audio engine deals with two distinct #TransportPosition.
Definition AudioEngine.h:97
Hydrogen Audio Engine.
Definition Hydrogen.h:54
Pattern class is a Note container.
Definition Pattern.h:46
Changes
Bitwise or-able options showing which part of the Preferences were altered using the PreferencesDialo...
SelectionWidget defines the interface used by the Selection manager to communicate with a widget impl...
Definition Selection.h:47
Selection management for editor widgets.
Definition Selection.h:192
Song editor pattern list.
Definition SongEditor.h:263
virtual void timelineUpdateEvent(int nValue) override
void setRowSelection(RowSelection rowSelection)
QPixmap m_playingPattern_empty_Pixmap
Definition SongEditor.h:325
virtual void mousePressEvent(QMouseEvent *ev) override
Single click, select the next pattern.
QPixmap m_playingPattern_on_Pixmap
Definition SongEditor.h:323
QPixmap m_playingPattern_off_Pixmap
Definition SongEditor.h:324
QPixmap m_labelBackgroundSelected
Definition SongEditor.h:322
QLineEdit * m_pLineEdit
Definition SongEditor.h:328
virtual void mouseDoubleClickEvent(QMouseEvent *ev) override
virtual void stackedModeActivationEvent(int nValue) override
virtual void leaveEvent(QEvent *ev)
void fillRangeWithPattern(FillRange *r, int nPattern)
H2Core::Pattern * m_pPatternBeingEdited
Definition SongEditor.h:329
virtual void mouseMoveEvent(QMouseEvent *event) override
void movePatternLine(int, int)
virtual void patternModifiedEvent() override
void onPreferencesChanged(H2Core::Preferences::Changes changes)
int m_nRowHovered
Specifies the row the mouse cursor is currently hovered over.
Definition SongEditor.h:351
void acceptPatternPropertiesDialogSettings(QString newPatternName, QString newPatternInfo, QString newPatternCategory, int patternNr)
virtual void songModeActivationEvent() override
void togglePattern(int)
Start/stop playing a pattern in "pattern mode".
H2Core::AudioEngine * m_pAudioEngine
Definition SongEditor.h:312
DragScroller * m_pDragScroller
Definition SongEditor.h:331
QPixmap m_labelBackgroundDark
Definition SongEditor.h:321
SongEditorPatternList(const SongEditorPatternList &)=delete
virtual void dragEnterEvent(QDragEnterEvent *event) override
drag & drop
static const uint m_nInitialHeight
Definition SongEditor.h:315
SongEditorPatternList & operator=(const SongEditorPatternList &rhs)=delete
void inlineEditPatternName(int row)
virtual void playingPatternsChangedEvent() override
QTimer * m_pHighlightLockedTimer
Definition SongEditor.h:353
SongEditorPatternList(QWidget *parent)
QPixmap * m_pBackgroundPixmap
Definition SongEditor.h:317
virtual void relocationEvent() override
virtual void paintEvent(QPaintEvent *ev) override
virtual void dropEvent(QDropEvent *event) override
virtual void selectedPatternChangedEvent() override
void revertPatternPropertiesDialogSettings(QString oldPatternName, QString oldPatternInfo, QString oldPatternCategory, int patternNr)
virtual void patternEditorLockedEvent() override
QPixmap m_labelBackgroundLight
Definition SongEditor.h:320
virtual void nextPatternsChangedEvent() override
H2Core::Hydrogen * m_pHydrogen
Definition SongEditor.h:311
virtual void timelineUpdateEvent(int nValue) override
virtual void mouseMoveEvent(QMouseEvent *ev) override
float m_fTick
Cached position of the playhead.
Definition SongEditor.h:422
static constexpr uint m_nHeight
Definition SongEditor.h:401
virtual void timelineActivationEvent() override
virtual void mousePressEvent(QMouseEvent *ev) override
HoveredRow
Indicated the part of the widget the cursor is hovering over.
Definition SongEditor.h:407
@ TempoMarker
Upper half until the lower end of the tempo marker text.
@ None
Cursor is not hovering the widget.
@ Tag
Still part of the upper half, but only the last m_nTagHeight pixels.
int columnToX(int nColumn) const
Calculates the position in pixel required to the painter for a particular nColumn of the grid.
int m_nColumn
Cached and coarsed-grained position of the playhead.
Definition SongEditor.h:424
void showTagWidget(int nColumn)
void drawTempoMarker(std::shared_ptr< const H2Core::Timeline::TempoMarker > pTempoMarker, bool bEmphasize, QPainter &painter)
static int tickToColumn(float fTick, uint nGridWidth)
void showBpmWidget(int nColumn)
virtual void patternModifiedEvent() override
void onPreferencesChanged(H2Core::Preferences::Changes changes)
virtual void songModeActivationEvent() override
H2Core::AudioEngine * m_pAudioEngine
Definition SongEditor.h:398
virtual void leaveEvent(QEvent *ev) override
void showToolTip(const QPoint &pos, const QPoint &globalPos)
virtual void tempoChangedEvent(int) override
virtual void mouseReleaseEvent(QMouseEvent *ev) override
virtual bool event(QEvent *ev) override
void setGridWidth(uint width)
int xToColumn(int nX) const
SongEditorPositionRuler(QWidget *parent)
virtual void songSizeChangedEvent() override
virtual void playingPatternsChangedEvent() override
virtual void updateSongEvent(int) override
QPixmap * m_pBackgroundPixmap
Definition SongEditor.h:431
virtual void relocationEvent() override
int m_nActiveColumns
Area covering the length of the song columns.
Definition SongEditor.h:429
virtual void paintEvent(QPaintEvent *ev) override
QRect calcTempoMarkerRect(std::shared_ptr< const H2Core::Timeline::TempoMarker > pTempoMarker, bool bEmphasize=false) const
virtual void jackTimebaseStateChangedEvent() override
H2Core::Hydrogen * m_pHydrogen
Definition SongEditor.h:397
Song editor.
Definition SongEditor.h:72
virtual bool canDragElements() override
Can elements be dragged as well as being selected? This may change to suit widget's current state.
Definition SongEditor.h:238
virtual void mouseDragUpdateEvent(QMouseEvent *ev) override
virtual void mouseMoveEvent(QMouseEvent *ev) override
float m_fTick
Cached position of the playhead.
Definition SongEditor.h:222
void drawSequence()
virtual void keyReleaseEvent(QKeyEvent *ev) override
virtual void mousePressEvent(QMouseEvent *ev) override
int getCursorRow() const
Definition SongEditor.h:245
virtual void updateModifiers(QInputEvent *ev)
int m_nCursorColumn
Definition SongEditor.h:164
virtual void selectionMoveEndEvent(QInputEvent *ev) override
int getGridHeight()
Definition SongEditor.h:92
void selectNone()
virtual QRect getKeyboardCursorRect() override
Calculate screen space occupied by keyboard cursor.
void drawPattern(int pos, int number, bool invertColour, double width)
QPoint columnRowToXy(QPoint p)
void scrolled(int)
void modifyPatternCellsAction(std::vector< QPoint > &addCells, std::vector< QPoint > &deleteCells, std::vector< QPoint > &selectCells)
Modify many pattern cells at once, for use in a single efficient undo/redo action.
QPoint m_currentMousePosition
Definition SongEditor.h:177
void updatePosition(float fTick)
QPixmap * m_pSequencePixmap
Definition SongEditor.h:158
bool m_bCopyNotMove
Definition SongEditor.h:132
void setPatternActive(int nColumn, int nRow, bool bActivate)
SongEditorPanel * m_pSongEditorPanel
Definition SongEditor.h:124
bool m_bSequenceChanged
Pattern sequence or selection has changed, so must be redrawn.
Definition SongEditor.h:142
int m_nMaxPatternColors
Definition SongEditor.h:134
QPoint xyToColumnRow(QPoint p)
virtual void patternModifiedEvent() override
void onPreferencesChanged(H2Core::Preferences::Changes changes)
void createBackground()
static constexpr int nMargin
Definition SongEditor.h:106
virtual std::vector< SelectionIndex > elementsIntersecting(QRect r) override
Find list of elements which intersect a rectangular area.
virtual void updateWidget() override
Selection or selection-related visual elements have changed, widget needs to be updated.
virtual void focusInEvent(QFocusEvent *ev) override
H2Core::AudioEngine * m_pAudioEngine
Definition SongEditor.h:127
bool m_bDrawingActiveCell
In "draw" mode, whether we're activating pattern cells ("drawing") or deactivating ("erasing") is set...
Definition SongEditor.h:139
unsigned m_nGridWidth
Definition SongEditor.h:130
virtual void leaveEvent(QEvent *ev) override
virtual void keyPressEvent(QKeyEvent *ev) override
virtual void mouseReleaseEvent(QMouseEvent *ev) override
void updateGridCells()
virtual void validateSelection() override
Ensure that the Selection contains only valid elements.
Definition SongEditor.h:230
QScrollArea * m_pScrollView
Definition SongEditor.h:123
QMenu * m_pPopupMenu
Definition SongEditor.h:144
void setGridWidth(uint width)
virtual void mouseDragStartEvent(QMouseEvent *ev) override
virtual void endMouseGesture() override
Definition SongEditor.h:186
unsigned m_nGridHeight
Definition SongEditor.h:129
void copy()
Copy a selection of cells to an XML representation in the clipboard.
virtual void focusOutEvent(QFocusEvent *ev) override
Selection< QPoint > m_selection
Definition SongEditor.h:121
virtual void startMouseLasso(QMouseEvent *ev) override
Definition SongEditor.h:181
void selectAll()
int m_nCursorRow
Definition SongEditor.h:163
SongEditor(QWidget *parent, QScrollArea *pScrollView, SongEditorPanel *pSongEditorPanel)
int yScrollTarget(QScrollArea *pScrollArea, int *pnPatternInView)
Calculate a target Y scroll value for tracking a playing song.
QPixmap * m_pBackgroundPixmap
Definition SongEditor.h:157
QPoint m_previousMousePosition
Mouse position during selection gestures (used to detect crossing cell boundaries)
Definition SongEditor.h:177
std::map< QPoint, GridCell > m_gridCells
Definition SongEditor.h:213
void deleteSelection()
virtual void mouseDragEndEvent(QMouseEvent *ev) override
virtual void relocationEvent() override
void clearThePatternSequenceVector(QString filename)
int getCursorColumn() const
Definition SongEditor.h:249
virtual void mouseClickEvent(QMouseEvent *ev) override
virtual void paintEvent(QPaintEvent *ev) override
int getGridWidth()
void togglePatternActive(int nColumn, int nRow)
void drawFocus(QPainter &painter)
void invalidateBackground()
virtual void patternEditorLockedEvent() override
QPoint m_previousGridOffset
Definition SongEditor.h:177
virtual void enterEvent(QEvent *ev) override
H2Core::Hydrogen * m_pHydrogen
Definition SongEditor.h:126
QPoint movingGridOffset() const
Quantise the selection move offset to the sequence grid.
bool m_bEntered
Definition SongEditor.h:215
bool m_bBackgroundInvalid
Definition SongEditor.h:146
void updateEditorandSetTrue()
bool m_bIsMoving
Definition SongEditor.h:131
Widget has a list of items associated with a popup which in turn can open dialog windows.
RowSelection
Specifies whether the row corresponding to m_nRowClicked should be highlighted and determines the lif...
Widget is affected by the "Font size" settings in the PreferencesDialog.