hydrogen 1.2.6
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-2025 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;
109 static constexpr int m_nMinimumHeight = 90;
110
111 public slots:
112
113 void selectAll();
114 void selectNone();
115 void deleteSelection();
116 void copy();
117 void paste();
118 void cut();
120 void scrolled( int );
121
122 private:
123
125
126 QScrollArea * m_pScrollView;
128
131
133 unsigned m_nGridWidth;
136
138
139
143
146
148
150
151
163
169
172 QPoint xyToColumnRow( QPoint p );
173 QPoint columnRowToXy( QPoint p );
175
177 QPoint movingGridOffset() const;
178
181
184 virtual void startMouseLasso( QMouseEvent *ev ) override {
185 m_bSequenceChanged = true;
186 setCursor( Qt::CrossCursor );
187 }
188
189 virtual void endMouseGesture() override {
190 unsetCursor();
191 }
192
193
196 virtual void mousePressEvent(QMouseEvent *ev) override;
197 virtual void mouseReleaseEvent(QMouseEvent *ev) override;
198 virtual void mouseMoveEvent(QMouseEvent *ev) override;
199 virtual void keyPressEvent (QKeyEvent *ev) override;
200 virtual void keyReleaseEvent (QKeyEvent *ev) override;
201 virtual void paintEvent(QPaintEvent *ev) override;
202 virtual void focusInEvent( QFocusEvent *ev ) override;
203 virtual void focusOutEvent( QFocusEvent *ev ) override;
204#ifdef H2CORE_HAVE_QT6
205 virtual void enterEvent( QEnterEvent *ev ) override;
206#else
207 virtual void enterEvent( QEvent *ev ) override;
208#endif
209 virtual void leaveEvent( QEvent *ev ) override;
211
212 void togglePatternActive( int nColumn, int nRow );
213 void setPatternActive( int nColumn, int nRow, bool bActivate );
214
215 void drawSequence();
216
217 void drawPattern( int pos, int number, bool invertColour, double width );
218 void drawFocus( QPainter& painter );
219
220 std::map< QPoint, GridCell > m_gridCells;
221 void updateGridCells();
223
224 virtual void patternModifiedEvent() override;
225 virtual void relocationEvent() override;
226 virtual void patternEditorLockedEvent() override;
227
229 float m_fTick;
230public:
231
235 virtual std::vector<SelectionIndex> elementsIntersecting( QRect r ) override;
236 virtual QRect getKeyboardCursorRect() override;
237 virtual void validateSelection() override {};
238 virtual void updateWidget() override;
239 virtual void mouseClickEvent( QMouseEvent *ev ) override;
240 virtual void mouseDragStartEvent( QMouseEvent *ev ) override;
241 virtual void mouseDragUpdateEvent( QMouseEvent *ev ) override;
242 virtual void mouseDragEndEvent( QMouseEvent *ev ) override;
243 virtual void selectionMoveEndEvent( QInputEvent *ev ) override;
244 virtual void updateModifiers( QInputEvent *ev );
245 virtual bool canDragElements() override {
246 return false;
247 }
248
249
250};
251
252inline int SongEditor::getCursorRow() const {
253 return m_nCursorRow;
254}
255
256inline int SongEditor::getCursorColumn() const {
257 return m_nCursorColumn;
258}
259
260
264
265class SongEditorPatternList : public QWidget
266 , protected WidgetWithScalableFont<8, 10, 12>
268 , public H2Core::Object<SongEditorPatternList>
269 , public EventListener
270{
272 Q_OBJECT
273
274 public:
275
276 explicit SongEditorPatternList( QWidget *parent );
278
281
282 void updateEditor();
283 void createBackground();
285 void movePatternLine( int, int );
286 void acceptPatternPropertiesDialogSettings( QString newPatternName, QString newPatternInfo, QString newPatternCategory, int patternNr );
287 void revertPatternPropertiesDialogSettings(QString oldPatternName, QString oldPatternInfo, QString oldPatternCategory, int patternNr);
288 void fillRangeWithPattern(FillRange* r, int nPattern);
289 int getGridHeight() { return m_nGridHeight; }
290
291 virtual void patternModifiedEvent() override;
292 virtual void playingPatternsChangedEvent() override;
293 virtual void songModeActivationEvent() override;
294 virtual void stackedModeActivationEvent( int nValue ) override;
295 virtual void selectedPatternChangedEvent() override;
296 virtual void nextPatternsChangedEvent() override;
297 virtual void relocationEvent() override;
298 virtual void patternEditorLockedEvent() override;
299
300 public slots:
301 void patternPopup_edit();
302 void patternPopup_save();
303 void patternPopup_export();
304 void patternPopup_load();
306 void patternPopup_delete();
308 void patternPopup_fill();
312 virtual void dragEnterEvent(QDragEnterEvent *event) override;
313 virtual void dropEvent(QDropEvent *event) override;
314 virtual void timelineUpdateEvent( int nValue ) override;
316
317 private:
322 static constexpr uint m_nInitialHeight = 10;
323
326
333
335 QLineEdit * m_pLineEdit;
337
339
340 void inlineEditPatternName( int row );
341
342 virtual void mousePressEvent( QMouseEvent *ev ) override;
343 virtual void mouseDoubleClickEvent( QMouseEvent *ev ) override;
344 virtual void paintEvent( QPaintEvent *ev ) override;
345 virtual void mouseMoveEvent(QMouseEvent *event) override;
346 virtual void leaveEvent( QEvent *ev );
347
349
350 void togglePattern( int );
351
352
353 void setRowSelection( RowSelection rowSelection );
359
361};
362
363
364// class SongEditorPatternListener : public EventListener {
365//
366// }
367//
368
370class SongEditorPositionRuler : public QWidget, protected WidgetWithScalableFont<8, 10, 12>, public EventListener, public H2Core::Object<SongEditorPositionRuler>
371{
373 Q_OBJECT
374
375 public:
376 explicit SongEditorPositionRuler( QWidget *parent );
378
379 uint getGridWidth();
380 void setGridWidth (uint width);
381 virtual void tempoChangedEvent( int ) override;
382 virtual void playingPatternsChangedEvent() override;
383 virtual void songModeActivationEvent() override;
384 virtual void relocationEvent() override;
385 virtual void songSizeChangedEvent() override;
386 virtual void patternModifiedEvent() override;
387 virtual void updateSongEvent( int ) override;
388
389 virtual void timelineActivationEvent() override;
390 virtual void timelineUpdateEvent( int nValue ) override;
391
392 static int tickToColumn( float fTick, uint nGridWidth );
393 static constexpr int m_nMinimumHeight = 50;
394
395 public slots:
396 void updatePosition();
397 void showTagWidget( int nColumn );
398 void showBpmWidget( int nColumn );
400 void createBackground();
402 virtual void jackTimebaseStateChangedEvent( int nState ) override;
403
404 private:
407 QTimer * m_pTimer;
409
412
427
429 float m_fTick;
432
434
437
441
442 virtual void mouseMoveEvent(QMouseEvent *ev) override;
443 virtual void mousePressEvent( QMouseEvent *ev ) override;
444 virtual void mouseReleaseEvent(QMouseEvent *ev) override;
445 virtual void paintEvent( QPaintEvent *ev ) override;
446
447 virtual void leaveEvent( QEvent* ev ) override;
448 virtual bool event( QEvent* ev ) override;
449
456 int columnToX( int nColumn ) const;
457 int xToColumn( int nX ) const;
458
459 void showToolTip( const QPoint& pos, const QPoint& globalPos );
460
461 void drawTempoMarker( std::shared_ptr<const H2Core::Timeline::TempoMarker> pTempoMarker,
462 bool bEmphasize, QPainter& painter );
468 QRect calcTempoMarkerRect( std::shared_ptr<const H2Core::Timeline::TempoMarker> pTempoMarker,
469 bool bEmphasize = false ) const;
470
471};
472
473#endif
#define H2_OBJECT(name)
Definition Object.h:227
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:129
The audio engine deals with two distinct TransportPosition.
Definition AudioEngine.h:99
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:49
Selection management for editor widgets.
Definition Selection.h:194
Song editor pattern list.
Definition SongEditor.h:270
virtual void timelineUpdateEvent(int nValue) override
void setRowSelection(RowSelection rowSelection)
QPixmap m_playingPattern_empty_Pixmap
Definition SongEditor.h:332
virtual void mousePressEvent(QMouseEvent *ev) override
Single click, select the next pattern.
QPixmap m_playingPattern_on_Pixmap
Definition SongEditor.h:330
QPixmap m_playingPattern_off_Pixmap
Definition SongEditor.h:331
QPixmap m_labelBackgroundSelected
Definition SongEditor.h:329
QLineEdit * m_pLineEdit
Definition SongEditor.h:335
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:336
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:358
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:319
DragScroller * m_pDragScroller
Definition SongEditor.h:338
QPixmap m_labelBackgroundDark
Definition SongEditor.h:328
SongEditorPatternList(const SongEditorPatternList &)=delete
virtual void dragEnterEvent(QDragEnterEvent *event) override
drag & drop
SongEditorPatternList & operator=(const SongEditorPatternList &rhs)=delete
void inlineEditPatternName(int row)
virtual void playingPatternsChangedEvent() override
QTimer * m_pHighlightLockedTimer
Definition SongEditor.h:360
SongEditorPatternList(QWidget *parent)
QPixmap * m_pBackgroundPixmap
Definition SongEditor.h:324
virtual void relocationEvent() override
virtual void paintEvent(QPaintEvent *ev) override
static constexpr uint m_nInitialHeight
Definition SongEditor.h:322
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:327
virtual void nextPatternsChangedEvent() override
H2Core::Hydrogen * m_pHydrogen
Definition SongEditor.h:318
virtual void timelineUpdateEvent(int nValue) override
virtual void mouseMoveEvent(QMouseEvent *ev) override
float m_fTick
Cached position of the playhead.
Definition SongEditor.h:429
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:414
@ TempoMarker
Upper half until the lower end of the tempo marker text.
Definition SongEditor.h:419
@ None
Cursor is not hovering the widget.
Definition SongEditor.h:416
@ Tag
Still part of the upper half, but only the last m_nTagHeight pixels.
Definition SongEditor.h:422
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:431
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:406
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:438
virtual void relocationEvent() override
int m_nActiveColumns
Area covering the length of the song columns.
Definition SongEditor.h:436
static constexpr int m_nMinimumHeight
Definition SongEditor.h:393
virtual void paintEvent(QPaintEvent *ev) override
virtual void jackTimebaseStateChangedEvent(int nState) override
QRect calcTempoMarkerRect(std::shared_ptr< const H2Core::Timeline::TempoMarker > pTempoMarker, bool bEmphasize=false) const
H2Core::Hydrogen * m_pHydrogen
Definition SongEditor.h:405
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:245
virtual void mouseDragUpdateEvent(QMouseEvent *ev) override
virtual void mouseMoveEvent(QMouseEvent *ev) override
float m_fTick
Cached position of the playhead.
Definition SongEditor.h:229
void drawSequence()
virtual void keyReleaseEvent(QKeyEvent *ev) override
virtual void mousePressEvent(QMouseEvent *ev) override
int getCursorRow() const
Definition SongEditor.h:252
virtual void updateModifiers(QInputEvent *ev)
int m_nCursorColumn
Definition SongEditor.h:167
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:180
void updatePosition(float fTick)
QPixmap * m_pSequencePixmap
Definition SongEditor.h:161
bool m_bCopyNotMove
Definition SongEditor.h:135
void setPatternActive(int nColumn, int nRow, bool bActivate)
SongEditorPanel * m_pSongEditorPanel
Definition SongEditor.h:127
bool m_bSequenceChanged
Pattern sequence or selection has changed, so must be redrawn.
Definition SongEditor.h:145
int m_nMaxPatternColors
Definition SongEditor.h:137
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:130
bool m_bDrawingActiveCell
In "draw" mode, whether we're activating pattern cells ("drawing") or deactivating ("erasing") is set...
Definition SongEditor.h:142
unsigned m_nGridWidth
Definition SongEditor.h:133
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:237
QScrollArea * m_pScrollView
Definition SongEditor.h:126
QMenu * m_pPopupMenu
Definition SongEditor.h:147
void setGridWidth(uint width)
virtual void mouseDragStartEvent(QMouseEvent *ev) override
virtual void endMouseGesture() override
Definition SongEditor.h:189
unsigned m_nGridHeight
Definition SongEditor.h:132
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:124
virtual void startMouseLasso(QMouseEvent *ev) override
Definition SongEditor.h:184
void selectAll()
int m_nCursorRow
Definition SongEditor.h:166
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:160
QPoint m_previousMousePosition
Mouse position during selection gestures (used to detect crossing cell boundaries)
Definition SongEditor.h:180
std::map< QPoint, GridCell > m_gridCells
Definition SongEditor.h:220
void deleteSelection()
virtual void mouseDragEndEvent(QMouseEvent *ev) override
virtual void relocationEvent() override
void clearThePatternSequenceVector(QString filename)
static constexpr int m_nMinimumHeight
Default value of Preferences::m_nSongEditorGridHeight * 5 (patterns)
Definition SongEditor.h:109
int getCursorColumn() const
Definition SongEditor.h:256
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:180
virtual void enterEvent(QEvent *ev) override
H2Core::Hydrogen * m_pHydrogen
Definition SongEditor.h:129
QPoint movingGridOffset() const
Quantise the selection move offset to the sequence grid.
bool m_bEntered
Definition SongEditor.h:222
bool m_bBackgroundInvalid
Definition SongEditor.h:149
void updateEditorandSetTrue()
bool m_bIsMoving
Definition SongEditor.h:134
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.