hydrogen 1.2.6
PatternEditor.h
Go to the documentation of this file.
1/*
2 * Hydrogen
3 * Copyright(c) 2002-2020 by the Hydrogen Team
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 PATERN_EDITOR_H
24#define PATERN_EDITOR_H
25
26#include "../EventListener.h"
27#include "../Selection.h"
28
29#include <core/Object.h>
31
32#include <QtGui>
33#if QT_VERSION >= 0x050000
34# include <QtWidgets>
35#endif
36
37namespace H2Core
38{
39 class AudioEngine;
40 class Note;
41 class Pattern;
42 class Instrument;
43}
44
46
56
57class PatternEditor : public QWidget,
58 public EventListener,
59 public H2Core::Object<PatternEditor>,
60 public SelectionWidget<H2Core::Note *>
61{
63 Q_OBJECT
64
65public:
66 enum class Editor {
70 None = 3
71 };
72
73 enum class Mode {
75 Pan = 1,
79 None = 5
80 };
81 static QString modeToQString( Mode mode );
82
83 PatternEditor( QWidget *pParent,
84 PatternEditorPanel *panel );
85
87
88
90 void setResolution( uint res, bool bUseTriplets );
91 uint getResolution() const { return m_nResolution; }
92 bool isUsingTriplets() const { return m_bUseTriplets; }
93
94 float getGridWidth() const { return m_fGridWidth; }
95 unsigned getGridHeight() const { return m_nGridHeight; }
97 void zoomIn();
98 void zoomOut();
99
102 m_selection.clearSelection();
103 }
104
106 static QColor computeNoteColor( float velocity );
107
108
110 void mergeSelectionGroups( PatternEditor *pPatternEditor ) {
111 m_selection.merge( &pPatternEditor->m_selection );
112 }
113
115 virtual void validateSelection() override;
116
118 virtual void updateModifiers( QInputEvent *ev );
119
121 virtual void updateWidget() override {
122 updateEditor( true );
123 }
124
126 virtual bool checkDeselectElements( std::vector<SelectionIndex> &elements ) override;
127
129 virtual void startMouseLasso( QMouseEvent *ev ) override {
130 setCursor( Qt::CrossCursor );
131 }
132
133 virtual void startMouseMove( QMouseEvent *ev ) override {
134 setCursor( Qt::DragMoveCursor );
135 }
136
137 virtual void endMouseGesture() override {
138 unsetCursor();
139 }
140
143 bool notesMatchExactly( H2Core::Note *pNoteA, H2Core::Note *pNoteB ) const;
144
146 void deselectAndOverwriteNotes( std::vector< H2Core::Note *> &selected, std::vector< H2Core::Note *> &overwritten );
147
148 void undoDeselectAndOverwriteNotes( std::vector< H2Core::Note *> &selected, std::vector< H2Core::Note *> &overwritten );
149
151 virtual void mousePressEvent( QMouseEvent *ev ) override;
152 virtual void mouseMoveEvent( QMouseEvent *ev ) override;
153 virtual void mouseReleaseEvent( QMouseEvent *ev ) override;
154
155 virtual void mouseDragStartEvent( QMouseEvent *ev ) override;
156 virtual void mouseDragUpdateEvent( QMouseEvent *ev ) override;
157 virtual void mouseDragEndEvent( QMouseEvent *ev ) override;
158
159
160 virtual void songModeActivationEvent() override;
161 virtual void stackedModeActivationEvent( int nValue ) override;
162
163 static constexpr int nMargin = 20;
164
167 void updatePosition( float fTick );
168 void editNoteLengthAction( int nColumn,
169 int nRealColumn,
170 int nRow,
171 int nLength,
172 int nSelectedPatternNumber,
173 int nSelectedInstrumentnumber,
174 Editor editor );
175
176 void editNotePropertiesAction( int nColumn,
177 int nRealColumn,
178 int nRow,
179 int nSelectedPatternNumber,
180 int nSelectedInstrumentNumber,
181 Mode mode,
182 Editor editor,
183 float fVelocity,
184 float fPan,
185 float fLeadLag,
186 float fProbability );
187 static void triggerStatusMessage( H2Core::Note* pNote, Mode mode );
188
189 // Pitch / line conversions
190 int lineToPitch( int nLine ) {
191 return 12 * (OCTAVE_MIN+m_nOctaves) - 1 - nLine;
192 }
193 int pitchToLine( int nPitch ) {
194 return 12 * (OCTAVE_MIN+m_nOctaves) - 1 - nPitch;
195 }
196
201 static bool isUsingAdditionalPatterns( const H2Core::Pattern* pPattern );
202
203protected:
204
207
208public slots:
209 virtual void updateEditor( bool bPatternOnly = false ) = 0;
210 virtual void selectAll() = 0;
211 virtual void selectNone();
212 virtual void deleteSelection() = 0;
213 virtual void copy();
214 virtual void paste() = 0;
215 virtual void cut();
216 virtual void selectInstrumentNotes( int nInstrument );
217 void setCurrentInstrument( int nInstrument );
219 void scrolled( int nValue );
220
221protected:
222
224 int granularity() const {
225 int nBase;
226 if (m_bUseTriplets) {
227 nBase = 3;
228 }
229 else {
230 nBase = 4;
231 }
232 return 4 * MAX_NOTES / ( nBase * m_nResolution );
233 }
234
237
238 // width of the editor covered by the current pattern.
240
243
246
251
254
256
259
260 int getColumn( int x, bool bUseFineGrained = false ) const;
261 QPoint movingGridOffset() const;
262
264 void drawGridLines( QPainter &p, Qt::PenStyle style = Qt::SolidLine ) const;
265
267 QColor selectedNoteColor() const;
268
279 void drawNoteSymbol( QPainter &p, QPoint pos, H2Core::Note *pNote, bool bIsForeground = true ) const;
280
284 std::vector< H2Core::Pattern *> getPatternsToShow( void );
285
287 void updatePatternInfo();
288
290 virtual void createBackground();
294
299 void updateWidth();
300
303#ifdef H2CORE_HAVE_QT6
304 virtual void enterEvent( QEnterEvent *ev ) override;
305#else
306 virtual void enterEvent( QEvent *ev ) override;
307#endif
308 virtual void leaveEvent( QEvent *ev ) override;
309 virtual void focusInEvent( QFocusEvent *ev ) override;
310 virtual void focusOutEvent( QFocusEvent *ev ) override;
311
313
314 unsigned m_nOctaves = 7;
315
317 void storeNoteProperties( const H2Core::Note* pNote );
318
324 int m_nColumn = 0;
325 int m_nRow = 0;
328
330 float m_fVelocity = 0;
331 float m_fOldVelocity = 0;
332 float m_fPan = 0;
333 float m_fOldPan = 0;
334 float m_fLeadLag = 0;
335 float m_fOldLeadLag = 0;
336 float m_fProbability = 0;
340};
341
342#endif // PATERN_EDITOR_H
#define OCTAVE_MIN
Definition Note.h:36
#define H2_OBJECT(name)
Definition Object.h:227
The audio engine deals with two distinct TransportPosition.
Definition AudioEngine.h:99
Instrument class.
Definition Instrument.h:55
A note plays an associated instrument with a velocity left and right pan.
Definition Note.h:101
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...
Pattern Editor Panel.
virtual bool checkDeselectElements(std::vector< SelectionIndex > &elements) override
Deselecting notes.
static QString modeToQString(Mode mode)
virtual void selectInstrumentNotes(int nInstrument)
virtual void mouseDragUpdateEvent(QMouseEvent *ev) override
virtual void mouseMoveEvent(QMouseEvent *ev) override
int lineToPitch(int nLine)
virtual void validateSelection() override
Ensure that the Selection contains only valid elements.
void editNotePropertiesAction(int nColumn, int nRealColumn, int nRow, int nSelectedPatternNumber, int nSelectedInstrumentNumber, Mode mode, Editor editor, float fVelocity, float fPan, float fLeadLag, float fProbability)
void scrolled(int nValue)
int m_nSelectedPatternNumber
virtual void updateWidget() override
Update a widget in response to a change in selection.
static QColor computeNoteColor(float velocity)
Calculate colour to use for note representation based on note velocity.
virtual void mousePressEvent(QMouseEvent *ev) override
Raw Qt mouse events are passed to the Selection.
virtual void updateModifiers(QInputEvent *ev)
Update the status of modifier keys in response to input events.
virtual void selectNone()
int granularity() const
Granularity of grid positioning (in ticks)
static bool isUsingAdditionalPatterns(const H2Core::Pattern *pPattern)
Determines whether to pattern editor should show further patterns (determined by getPattersToShow()) ...
QColor selectedNoteColor() const
Colour to use for outlining selected notes.
virtual void stackedModeActivationEvent(int nValue) override
virtual void deleteSelection()=0
int m_nSelectedInstrumentNumber
Cached properties used when adjusting a note property via right-press mouse movement.
float m_fOldProbability
int pitchToLine(int nPitch)
void storeNoteProperties(const H2Core::Note *pNote)
Stores the properties of pNote in member variables.
void updatePosition(float fTick)
Caches the AudioEngine::m_nPatternTickPosition in the member variable m_nTick and triggers an update(...
static void triggerStatusMessage(H2Core::Note *pNote, Mode mode)
void editNoteLengthAction(int nColumn, int nRealColumn, int nRow, int nLength, int nSelectedPatternNumber, int nSelectedInstrumentnumber, Editor editor)
void drawNoteSymbol(QPainter &p, QPoint pos, H2Core::Note *pNote, bool bIsForeground=true) const
Draw a note.
virtual void updateEditor(bool bPatternOnly=false)=0
bool isUsingTriplets() const
bool notesMatchExactly(H2Core::Note *pNoteA, H2Core::Note *pNoteB) const
Do two notes match exactly, from the pattern editor's point of view?
void onPreferencesChanged(H2Core::Preferences::Changes changes)
virtual void createBackground()
Updates m_pBackgroundPixmap to show the latest content.
static constexpr int nMargin
virtual void songModeActivationEvent() override
PatternEditorPanel * m_pPatternEditorPanel
unsigned getGridHeight() const
void mergeSelectionGroups(PatternEditor *pPatternEditor)
Merge together the selection groups of two PatternEditor objects to share a common selection.
virtual void focusInEvent(QFocusEvent *ev) override
H2Core::AudioEngine * m_pAudioEngine
void zoomIn()
Zoom in / out on the time axis.
virtual void leaveEvent(QEvent *ev) override
H2Core::Note * m_pDraggedNote
virtual void mouseReleaseEvent(QMouseEvent *ev) override
float getGridWidth() const
QMenu * m_pPopupMenu
void deselectAndOverwriteNotes(std::vector< H2Core::Note * > &selected, std::vector< H2Core::Note * > &overwritten)
Deselect some notes, and "overwrite" some others.
void updatePatternInfo()
Update current pattern information.
virtual void mouseDragStartEvent(QMouseEvent *ev) override
virtual void endMouseGesture() override
unsigned m_nGridHeight
virtual void copy()
Copy selection to clipboard in XML.
virtual void focusOutEvent(QFocusEvent *ev) override
void setCurrentInstrument(int nInstrument)
std::vector< H2Core::Pattern * > getPatternsToShow(void)
Get notes to show in pattern editor.
virtual void startMouseLasso(QMouseEvent *ev) override
Change the mouse cursor during mouse gestures.
void undoDeselectAndOverwriteNotes(std::vector< H2Core::Note * > &selected, std::vector< H2Core::Note * > &overwritten)
void clearSelection()
Clear the pattern editor selection.
QPixmap * m_pBackgroundPixmap
void setResolution(uint res, bool bUseTriplets)
Set the editor grid resolution, dividing a whole note into res subdivisions.
virtual void mouseDragEndEvent(QMouseEvent *ev) override
PatternEditor(QWidget *pParent, PatternEditorPanel *panel)
virtual void selectAll()=0
virtual void cut()
unsigned m_nOctaves
virtual void paste()=0
int getColumn(int x, bool bUseFineGrained=false) const
H2Core::Pattern * m_pPattern
void invalidateBackground()
void updateWidth()
Adjusts m_nActiveWidth and m_nEditorWidth to the current state of the editor.
virtual void enterEvent(QEvent *ev) override
Selection< SelectionIndex > m_selection
The Selection object.
QPoint movingGridOffset() const
bool m_bEntered
Indicates whether the mouse pointer entered the widget.
virtual void startMouseMove(QMouseEvent *ev) override
bool m_bBackgroundInvalid
uint getResolution() const
void drawGridLines(QPainter &p, Qt::PenStyle style=Qt::SolidLine) const
Draw lines for note grid.
SelectionWidget defines the interface used by the Selection manager to communicate with a widget impl...
Definition Selection.h:49
#define MAX_NOTES
Maximum number of notes.
Definition config.dox:79