hydrogen 1.2.3
SongEditor Class Reference

Song editor. More...

#include <SongEditor.h>

Inheritance diagram for SongEditor:
Object< SongEditor > SelectionWidget< QPoint > EventListener Base

Data Structures

struct  GridCell
 

Public Slots

void copy ()
 Copy a selection of cells to an XML representation in the clipboard.
 
void cut ()
 
void deleteSelection ()
 
void onPreferencesChanged (H2Core::Preferences::Changes changes)
 
void paste ()
 
void scrolled (int)
 
void selectAll ()
 
void selectNone ()
 

Public Member Functions

 SongEditor (QWidget *parent, QScrollArea *pScrollView, SongEditorPanel *pSongEditorPanel)
 
 ~SongEditor ()
 
void clearThePatternSequenceVector (QString filename)
 
void createBackground ()
 
int getCursorColumn () const
 
int getCursorRow () const
 
int getGridHeight ()
 
int getGridWidth ()
 
void invalidateBackground ()
 
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.
 
void setGridWidth (uint width)
 
void updateEditorandSetTrue ()
 
void updatePosition (float fTick)
 
int yScrollTarget (QScrollArea *pScrollArea, int *pnPatternInView)
 Calculate a target Y scroll value for tracking a playing song.
 
Selection interfaces

see Selection.h for details.

virtual std::vector< SelectionIndexelementsIntersecting (QRect r) override
 Find list of elements which intersect a rectangular area.
 
virtual QRect getKeyboardCursorRect () override
 Calculate screen space occupied by keyboard cursor.
 
virtual void validateSelection () override
 Ensure that the Selection contains only valid elements.
 
virtual void updateWidget () override
 Selection or selection-related visual elements have changed, widget needs to be updated.
 
virtual void mouseClickEvent (QMouseEvent *ev) override
 
virtual void mouseDragStartEvent (QMouseEvent *ev) override
 
virtual void mouseDragUpdateEvent (QMouseEvent *ev) override
 
virtual void mouseDragEndEvent (QMouseEvent *ev) override
 
virtual void selectionMoveEndEvent (QInputEvent *ev) override
 
virtual void updateModifiers (QInputEvent *ev)
 
virtual bool canDragElements () override
 Can elements be dragged as well as being selected? This may change to suit widget's current state.
 
- Public Member Functions inherited from Object< SongEditor >
 Object ()
 
 Object (const Object< SongEditor > &other)
 
- Public Member Functions inherited from Base
 Base ()
 
 Base (const Base &other)
 
virtual const char * class_name () const
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG.
 
virtual QString toQString (const QString &sPrefix="", bool bShort=true) const
 Formatted string version for debugging purposes.
 
- Public Member Functions inherited from SelectionWidget< QPoint >
virtual bool checkDeselectElements (std::vector< SelectionIndex > &elements)
 Inform the client that we're deselecting elements.
 
virtual QScrollArea * findScrollArea ()
 Find the QScrollArea, if any, which contains the widget.
 
virtual void selectionMoveUpdateEvent (QMouseEvent *ev)
 
virtual void selectionMoveCancelEvent ()
 
virtual void startMouseMove (QMouseEvent *ev)
 
- Public Member Functions inherited from EventListener
virtual ~EventListener ()
 
virtual void actionModeChangeEvent (int nValue)
 
virtual void bbtChangedEvent ()
 
virtual void driverChangedEvent ()
 
virtual void drumkitLoadedEvent ()
 
virtual void errorEvent (int nErrorCode)
 
virtual void gridCellToggledEvent ()
 
virtual void instrumentParametersChangedEvent (int nInstrumentNumber)
 
virtual void jacksessionEvent (int nValue)
 
virtual void jackTimebaseStateChangedEvent ()
 
virtual void jackTransportActivationEvent ()
 
virtual void loopModeActivationEvent ()
 
virtual void metronomeEvent (int nValue)
 
virtual void midiActivityEvent ()
 
virtual void midiMapChangedEvent ()
 
virtual void nextPatternsChangedEvent ()
 
virtual void nextShotEvent ()
 
virtual void noteOnEvent (int nInstrument)
 
virtual void playbackTrackChangedEvent ()
 
virtual void playingPatternsChangedEvent ()
 
virtual void playlistLoadSongEvent (int nIndex)
 
virtual void progressEvent (int nValue)
 
virtual void quitEvent (int nValue)
 
virtual void selectedInstrumentChangedEvent ()
 
virtual void selectedPatternChangedEvent ()
 
virtual void songModeActivationEvent ()
 
virtual void songModifiedEvent ()
 
virtual void songSizeChangedEvent ()
 
virtual void soundLibraryChangedEvent ()
 
virtual void stackedModeActivationEvent (int nValue)
 
virtual void stateChangedEvent (H2Core::AudioEngine::State state)
 
virtual void tempoChangedEvent (int nValue)
 
virtual void timelineActivationEvent ()
 
virtual void timelineUpdateEvent (int nValue)
 
virtual void undoRedoActionEvent (int nValue)
 
virtual void updatePreferencesEvent (int nValue)
 
virtual void updateSongEvent (int nValue)
 
virtual void XRunEvent ()
 

Static Public Attributes

static constexpr int nMargin = 10
 
- Static Public Attributes inherited from Base
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes.
 

Private Member Functions

void drawFocus (QPainter &painter)
 
void drawPattern (int pos, int number, bool invertColour, double width)
 
void drawSequence ()
 
QPoint movingGridOffset () const
 Quantise the selection move offset to the sequence grid.
 
virtual void patternEditorLockedEvent () override
 
virtual void patternModifiedEvent () override
 
virtual void relocationEvent () override
 
void setPatternActive (int nColumn, int nRow, bool bActivate)
 
void togglePatternActive (int nColumn, int nRow)
 
void updateGridCells ()
 
Conversion between sequence grid coordinates and screen (widget) coordinates.
QPoint xyToColumnRow (QPoint p)
 
QPoint columnRowToXy (QPoint p)
 
Change the mouse cursor during mouse gestures
virtual void startMouseLasso (QMouseEvent *ev) override
 
virtual void endMouseGesture () override
 
System events
virtual void mousePressEvent (QMouseEvent *ev) override
 
virtual void mouseReleaseEvent (QMouseEvent *ev) override
 
virtual void mouseMoveEvent (QMouseEvent *ev) override
 
virtual void keyPressEvent (QKeyEvent *ev) override
 
virtual void keyReleaseEvent (QKeyEvent *ev) override
 
virtual void paintEvent (QPaintEvent *ev) override
 
virtual void focusInEvent (QFocusEvent *ev) override
 
virtual void focusOutEvent (QFocusEvent *ev) override
 
virtual void enterEvent (QEvent *ev) override
 
virtual void leaveEvent (QEvent *ev) override
 

Private Attributes

bool m_bBackgroundInvalid
 
bool m_bCopyNotMove
 
bool m_bDrawingActiveCell
 In "draw" mode, whether we're activating pattern cells ("drawing") or deactivating ("erasing") is set at the start of the draw gesture.
 
bool m_bEntered
 
bool m_bIsMoving
 
bool m_bSequenceChanged
 Pattern sequence or selection has changed, so must be redrawn.
 
QPoint m_currentMousePosition
 
float m_fTick
 Cached position of the playhead.
 
std::map< QPoint, GridCellm_gridCells
 
unsigned m_nGridHeight
 
unsigned m_nGridWidth
 
int m_nMaxPatternColors
 
H2Core::AudioEnginem_pAudioEngine
 
H2Core::Hydrogenm_pHydrogen
 
QMenu * m_pPopupMenu
 
QPoint m_previousGridOffset
 
QPoint m_previousMousePosition
 Mouse position during selection gestures (used to detect crossing cell boundaries)
 
QScrollArea * m_pScrollView
 
SongEditorPanelm_pSongEditorPanel
 
Selection< QPoint > m_selection
 
Background pixmap caching

To make painting the song editor sequence grid more efficient, the drawing uses multiple levels of lazy painting.

  • The grid background pixmap is only updated when the size of the pattern grid changes.
  • The sequence pixmap are only updated when cells are added/removed or selections change
    • the cached grid background pixmap is used when repainting the pattern
  • selections and moving cells are painted on top of the cached sequence pixmap
QPixmap * m_pBackgroundPixmap
 
QPixmap * m_pSequencePixmap
 
Position of the keyboard input cursor
int m_nCursorRow
 
int m_nCursorColumn
 

Additional Inherited Members

- Public Types inherited from SelectionWidget< QPoint >
typedef QPoint SelectionIndex
 
- Static Public Member Functions inherited from Base
static const char * _class_name ()
 return the class name
 
static QString base_clock (const QString &sMsg)
 Measures the current time and stores it in __last_clock.
 
static QString base_clock_in (const QString &sMsg)
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation !
 
static bool count_active ()
 
static int getAliveObjectCount ()
 
static object_map_t getObjectMap ()
 
static Loggerlogger ()
 return the logger instance
 
static int objects_count ()
 
static void printObjectMapDiff (object_map_t map)
 Creates the difference between a snapshot of the object map and its current state and prints it to std::cout.
 
static void set_count (bool flag)
 enable/disable class instances counting
 
static void write_objects_map_to (std::ostream &out, object_map_t *map=nullptr)
 output the full objects map to a given ostream
 
static void write_objects_map_to_cerr ()
 output objects map to stderr
 
- Protected Member Functions inherited from Object< SongEditor >
 ~Object ()
 
- Protected Member Functions inherited from Base
 ~Base ()
 
- Static Protected Member Functions inherited from Base
static void registerClass (const char *name, const atomic_obj_cpt_t *counters)
 
- Static Protected Attributes inherited from Base
static bool __count = false
 should we count class instances
 
static timeval __last_clock = { 0, 0 }
 
static Logger__logger = nullptr
 

Detailed Description

Song editor.

The main widget of SongEditorPanel, responsible for altering the sequence of patterns.

It supports mouse and keyboard based activation of patterns in timeslots, as well as visual editing of multiple pattern+timeslot cells using a 2-dimensional visual representation, with copy, paste, move, delete, duplicate etc.

Definition at line 68 of file SongEditor.h.

Constructor & Destructor Documentation

◆ SongEditor()

SongEditor ( QWidget * parent,
QScrollArea * pScrollView,
SongEditorPanel * pSongEditorPanel )

Definition at line 74 of file SongEditor.cpp.

◆ ~SongEditor()

~SongEditor ( )

Definition at line 128 of file SongEditor.cpp.

Member Function Documentation

◆ canDragElements()

virtual bool canDragElements ( )
inlineoverridevirtual

Can elements be dragged as well as being selected? This may change to suit widget's current state.

Reimplemented from SelectionWidget< QPoint >.

Definition at line 238 of file SongEditor.h.

◆ clearThePatternSequenceVector()

void clearThePatternSequenceVector ( QString filename)

Definition at line 1357 of file SongEditor.cpp.

◆ columnRowToXy()

QPoint columnRowToXy ( QPoint p)
private

Definition at line 325 of file SongEditor.cpp.

◆ copy

void copy ( )
slot

Copy a selection of cells to an XML representation in the clipboard.

  • <patternSelection>
    • <sourcePosition>
  • <cellList>
    • <cell>
    • ...

Definition at line 393 of file SongEditor.cpp.

◆ createBackground()

void createBackground ( )

Definition at line 1116 of file SongEditor.cpp.

◆ cut

void cut ( )
slot

Definition at line 489 of file SongEditor.cpp.

◆ deleteSelection

void deleteSelection ( )
slot

Definition at line 374 of file SongEditor.cpp.

◆ drawFocus()

void drawFocus ( QPainter & painter)
private

Definition at line 1069 of file SongEditor.cpp.

◆ drawPattern()

void drawPattern ( int pos,
int number,
bool invertColour,
double width )
private

Definition at line 1268 of file SongEditor.cpp.

◆ drawSequence()

void drawSequence ( )
private

Definition at line 1238 of file SongEditor.cpp.

◆ elementsIntersecting()

std::vector< SongEditor::SelectionIndex > elementsIntersecting ( QRect r)
overridevirtual

Find list of elements which intersect a rectangular area.

This may be a selection lasso rectangle, or a single point such as a mouse click. This should concern itself only with the geometry.

Implements SelectionWidget< QPoint >.

Definition at line 1338 of file SongEditor.cpp.

◆ endMouseGesture()

virtual void endMouseGesture ( )
inlineoverrideprivatevirtual

Reimplemented from SelectionWidget< QPoint >.

Definition at line 186 of file SongEditor.h.

◆ enterEvent()

void enterEvent ( QEvent * ev)
overrideprivatevirtual

Definition at line 1104 of file SongEditor.cpp.

◆ focusInEvent()

void focusInEvent ( QFocusEvent * ev)
overrideprivatevirtual

Definition at line 682 of file SongEditor.cpp.

◆ focusOutEvent()

void focusOutEvent ( QFocusEvent * ev)
overrideprivatevirtual

Definition at line 703 of file SongEditor.cpp.

◆ getCursorColumn()

int getCursorColumn ( ) const
inline

Definition at line 249 of file SongEditor.h.

◆ getCursorRow()

int getCursorRow ( ) const
inline

Definition at line 245 of file SongEditor.h.

◆ getGridHeight()

int getGridHeight ( )
inline

Definition at line 92 of file SongEditor.h.

◆ getGridWidth()

int getGridWidth ( )

Definition at line 302 of file SongEditor.cpp.

◆ getKeyboardCursorRect()

QRect getKeyboardCursorRect ( )
overridevirtual

Calculate screen space occupied by keyboard cursor.

Implements SelectionWidget< QPoint >.

Definition at line 1352 of file SongEditor.cpp.

◆ invalidateBackground()

void invalidateBackground ( )

Definition at line 1188 of file SongEditor.cpp.

◆ keyPressEvent()

void keyPressEvent ( QKeyEvent * ev)
overrideprivatevirtual

Definition at line 494 of file SongEditor.cpp.

◆ keyReleaseEvent()

void keyReleaseEvent ( QKeyEvent * ev)
overrideprivatevirtual

Definition at line 677 of file SongEditor.cpp.

◆ leaveEvent()

void leaveEvent ( QEvent * ev)
overrideprivatevirtual

Definition at line 1110 of file SongEditor.cpp.

◆ modifyPatternCellsAction()

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.

Modify pattern cells by first deleting some, then adding some.

deleteCells and addCells may safely overlap

Definition at line 931 of file SongEditor.cpp.

◆ mouseClickEvent()

void mouseClickEvent ( QMouseEvent * ev)
overridevirtual

Implements SelectionWidget< QPoint >.

Definition at line 900 of file SongEditor.cpp.

◆ mouseDragEndEvent()

void mouseDragEndEvent ( QMouseEvent * ev)
overridevirtual

Implements SelectionWidget< QPoint >.

Definition at line 854 of file SongEditor.cpp.

◆ mouseDragStartEvent()

void mouseDragStartEvent ( QMouseEvent * ev)
overridevirtual

Implements SelectionWidget< QPoint >.

Definition at line 846 of file SongEditor.cpp.

◆ mouseDragUpdateEvent()

void mouseDragUpdateEvent ( QMouseEvent * ev)
overridevirtual

Implements SelectionWidget< QPoint >.

Definition at line 850 of file SongEditor.cpp.

◆ mouseMoveEvent()

void mouseMoveEvent ( QMouseEvent * ev)
overrideprivatevirtual

Definition at line 805 of file SongEditor.cpp.

◆ mousePressEvent()

void mousePressEvent ( QMouseEvent * ev)
overrideprivatevirtual

Definition at line 730 of file SongEditor.cpp.

◆ mouseReleaseEvent()

void mouseReleaseEvent ( QMouseEvent * ev)
overrideprivatevirtual

Definition at line 920 of file SongEditor.cpp.

◆ movingGridOffset()

QPoint movingGridOffset ( ) const
private

Quantise the selection move offset to the sequence grid.

Definition at line 1222 of file SongEditor.cpp.

◆ onPreferencesChanged

void onPreferencesChanged ( H2Core::Preferences::Changes changes)
slot

Definition at line 1390 of file SongEditor.cpp.

◆ paintEvent()

void paintEvent ( QPaintEvent * ev)
overrideprivatevirtual

Definition at line 1013 of file SongEditor.cpp.

◆ paste

void paste ( )
slot

Definition at line 428 of file SongEditor.cpp.

◆ patternEditorLockedEvent()

void patternEditorLockedEvent ( )
overrideprivatevirtual

Reimplemented from EventListener.

Definition at line 1006 of file SongEditor.cpp.

◆ patternModifiedEvent()

void patternModifiedEvent ( )
overrideprivatevirtual

Reimplemented from EventListener.

Definition at line 992 of file SongEditor.cpp.

◆ relocationEvent()

void relocationEvent ( )
overrideprivatevirtual

Reimplemented from EventListener.

Definition at line 999 of file SongEditor.cpp.

◆ scrolled

void scrolled ( int nValue)
slot

Definition at line 1099 of file SongEditor.cpp.

◆ selectAll

void selectAll ( )
slot

Definition at line 348 of file SongEditor.cpp.

◆ selectionMoveEndEvent()

void selectionMoveEndEvent ( QInputEvent * ev)
overridevirtual

Implements SelectionWidget< QPoint >.

Definition at line 859 of file SongEditor.cpp.

◆ selectNone

void selectNone ( )
slot

Definition at line 367 of file SongEditor.cpp.

◆ setGridWidth()

void setGridWidth ( uint width)

Definition at line 309 of file SongEditor.cpp.

◆ setPatternActive()

void setPatternActive ( int nColumn,
int nRow,
bool bActivate )
private

Definition at line 336 of file SongEditor.cpp.

◆ startMouseLasso()

virtual void startMouseLasso ( QMouseEvent * ev)
inlineoverrideprivatevirtual

Reimplemented from SelectionWidget< QPoint >.

Definition at line 181 of file SongEditor.h.

◆ togglePatternActive()

void togglePatternActive ( int nColumn,
int nRow )
private

Definition at line 331 of file SongEditor.cpp.

◆ updateEditorandSetTrue()

void updateEditorandSetTrue ( )

Definition at line 1384 of file SongEditor.cpp.

◆ updateGridCells()

void updateGridCells ( )
private

Definition at line 1193 of file SongEditor.cpp.

◆ updateModifiers()

void updateModifiers ( QInputEvent * ev)
virtual

Definition at line 776 of file SongEditor.cpp.

◆ updatePosition()

void updatePosition ( float fTick)

Definition at line 975 of file SongEditor.cpp.

◆ updateWidget()

void updateWidget ( )
overridevirtual

Selection or selection-related visual elements have changed, widget needs to be updated.

At a minimum, the widget's own update() method should be called.

Implements SelectionWidget< QPoint >.

Definition at line 948 of file SongEditor.cpp.

◆ validateSelection()

virtual void validateSelection ( )
inlineoverridevirtual

Ensure that the Selection contains only valid elements.

Implements SelectionWidget< QPoint >.

Definition at line 230 of file SongEditor.h.

◆ xyToColumnRow()

QPoint xyToColumnRow ( QPoint p)
private

Definition at line 320 of file SongEditor.cpp.

◆ yScrollTarget()

int yScrollTarget ( QScrollArea * pScrollArea,
int * pnPatternInView )

Calculate a target Y scroll value for tracking a playing song.

Songs with many patterns may not fit in the current viewport of the Song Editor. Depending on how the song is structured, as the viewport scrolls to show different times, the playing patterns may end up being off-screen. It would be ideal to be able to follow the progression of the song in a meaningful and useful way, but since multiple patterns may be active at any one time, it's non-trivial to define a useful behaviour that captures more than the simple case of a song with one pattern active at a time.

As an attempt to define a useful behaviour which captures what the user might expect to happen, we define the behaviour as follows:

  • If there are no currently playing patterns which are entirely visible:
    • Find the position with the smallest amount of scrolling from the current location which:
      • Fits the maximum number of currently playing patterns in view at the same time.

This covers the trivial cases where only a single pattern is playing, and gives some intuitive behaviour for songs containing multiple playing patterns where the general progression is diagonal but with constant (or near-constant) background elements, and the "minimum scrolling" allows the user to hint if we stray off the path.

Definition at line 158 of file SongEditor.cpp.

Field Documentation

◆ m_bBackgroundInvalid

bool m_bBackgroundInvalid
private

Definition at line 146 of file SongEditor.h.

◆ m_bCopyNotMove

bool m_bCopyNotMove
private

Definition at line 132 of file SongEditor.h.

◆ m_bDrawingActiveCell

bool m_bDrawingActiveCell
private

In "draw" mode, whether we're activating pattern cells ("drawing") or deactivating ("erasing") is set at the start of the draw gesture.

Definition at line 139 of file SongEditor.h.

◆ m_bEntered

bool m_bEntered
private

Definition at line 215 of file SongEditor.h.

◆ m_bIsMoving

bool m_bIsMoving
private

Definition at line 131 of file SongEditor.h.

◆ m_bSequenceChanged

bool m_bSequenceChanged
private

Pattern sequence or selection has changed, so must be redrawn.

Definition at line 142 of file SongEditor.h.

◆ m_currentMousePosition

QPoint m_currentMousePosition
private

Definition at line 177 of file SongEditor.h.

◆ m_fTick

float m_fTick
private

Cached position of the playhead.

Definition at line 222 of file SongEditor.h.

◆ m_gridCells

std::map< QPoint, GridCell > m_gridCells
private

Definition at line 213 of file SongEditor.h.

◆ m_nCursorColumn

int m_nCursorColumn
private

Definition at line 164 of file SongEditor.h.

◆ m_nCursorRow

int m_nCursorRow
private

Definition at line 163 of file SongEditor.h.

◆ m_nGridHeight

unsigned m_nGridHeight
private

Definition at line 129 of file SongEditor.h.

◆ m_nGridWidth

unsigned m_nGridWidth
private

Definition at line 130 of file SongEditor.h.

◆ m_nMaxPatternColors

int m_nMaxPatternColors
private

Definition at line 134 of file SongEditor.h.

◆ m_pAudioEngine

H2Core::AudioEngine* m_pAudioEngine
private

Definition at line 127 of file SongEditor.h.

◆ m_pBackgroundPixmap

QPixmap* m_pBackgroundPixmap
private

Definition at line 157 of file SongEditor.h.

◆ m_pHydrogen

H2Core::Hydrogen* m_pHydrogen
private

Definition at line 126 of file SongEditor.h.

◆ m_pPopupMenu

QMenu* m_pPopupMenu
private

Definition at line 144 of file SongEditor.h.

◆ m_previousGridOffset

QPoint m_previousGridOffset
private

Definition at line 177 of file SongEditor.h.

◆ m_previousMousePosition

QPoint m_previousMousePosition
private

Mouse position during selection gestures (used to detect crossing cell boundaries)

Definition at line 177 of file SongEditor.h.

◆ m_pScrollView

QScrollArea* m_pScrollView
private

Definition at line 123 of file SongEditor.h.

◆ m_pSequencePixmap

QPixmap* m_pSequencePixmap
private

Definition at line 158 of file SongEditor.h.

◆ m_pSongEditorPanel

SongEditorPanel* m_pSongEditorPanel
private

Definition at line 124 of file SongEditor.h.

◆ m_selection

Selection<QPoint> m_selection
private

Definition at line 121 of file SongEditor.h.

◆ nMargin

constexpr int nMargin = 10
staticconstexpr

Definition at line 106 of file SongEditor.h.