hydrogen 1.1.1
SongEditor Class Reference

Song editor. More...

#include <SongEditor.h>

Inheritance diagram for SongEditor:
Object SelectionWidget< QPoint >

Data Structures

struct  GridCell
 

Public Slots

void selectAll ()
 
void selectNone ()
 
void deleteSelection ()
 
void copy ()
 Copy a selection of cells to an XML representation in the clipboard. More...
 
void paste ()
 
void cut ()
 

Public Member Functions

 SongEditor (QWidget *parent, QScrollArea *pScrollView, SongEditorPanel *pSongEditorPanel)
 
 ~SongEditor ()
 
void createBackground ()
 
void cleanUp ()
 
int getGridWidth ()
 
void setGridWidth (uint width)
 
int getGridHeight ()
 
int getCursorRow () const
 
int getCursorColumn () const
 
void addPattern (int nColumn, int nRow)
 Add or delete pattern in the sequence grid. More...
 
void deletePattern (int nColumn, int nRow)
 
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. More...
 
void clearThePatternSequenceVector (QString filename)
 
void updateEditorandSetTrue ()
 
Selection interfaces

see Selection.h for details.

virtual std::vector< SelectionIndexelementsIntersecting (QRect r) override
 Find list of elements which intersect a rectangular area. More...
 
virtual QRect getKeyboardCursorRect () override
 Calculate screen space occupied by keyboard cursor. More...
 
virtual void validateSelection () override
 Ensure that the Selection contains only valid elements. More...
 
virtual void updateWidget () override
 Selection or selection-related visual elements have changed, widget needs to be updated. More...
 
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. More...
 
- Public Member Functions inherited from Object
 ~Object ()
 destructor More...
 
 Object (const Object &obj)
 copy constructor More...
 
 Object (const char *class_name)
 constructor More...
 
const char * class_name () const
 return the class name More...
 
virtual QString toQString (const QString &sPrefix, bool bShort=true) const
 Formatted string version for debugging purposes. More...
 
void Print (bool bShort=true) const
 Prints content of toQString() via DEBUGLOG. More...
 
- Public Member Functions inherited from SelectionWidget< QPoint >
virtual std::vector< SelectionIndexelementsIntersecting (QRect r)=0
 Find list of elements which intersect a rectangular area. More...
 
virtual bool canDragElements ()
 Can elements be dragged as well as being selected? This may change to suit widget's current state. More...
 
virtual QRect getKeyboardCursorRect ()=0
 Calculate screen space occupied by keyboard cursor. More...
 
virtual void validateSelection ()=0
 Ensure that the Selection contains only valid elements. More...
 
virtual void updateWidget ()=0
 Selection or selection-related visual elements have changed, widget needs to be updated. More...
 
virtual bool checkDeselectElements (std::vector< SelectionIndex > &elements)
 Inform the client that we're deselecting elements. More...
 
virtual QScrollArea * findScrollArea ()
 Find the QScrollArea, if any, which contains the widget. More...
 
virtual void selectionMoveUpdateEvent (QMouseEvent *ev)
 
virtual void selectionMoveCancelEvent ()
 
virtual void startMouseMove (QMouseEvent *ev)
 

Private Member Functions

QPoint movingGridOffset () const
 Quantise the selection move offset to the sequence grid. More...
 
bool togglePatternActive (int nColumn, int nRow)
 
void setPatternActive (int nColumn, int nRow, bool value)
 
void drawSequence ()
 
void drawPattern (int pos, int number, bool invertColour, double width)
 
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
 

Private Attributes

Selection< QPoint > m_selection
 
QScrollArea * m_pScrollView
 
SongEditorPanelm_pSongEditorPanel
 
QMenu * m_pPopupMenu
 
unsigned m_nGridHeight
 
unsigned m_nGridWidth
 
unsigned m_nMaxPatternSequence
 
bool m_bCopyNotMove
 
bool m_bSequenceChanged
 Pattern sequence or selection has changed, so must be redrawn. More...
 
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. More...
 
const int m_nMargin = 10
 
QPoint m_previousMousePosition
 Mouse position during selection gestures (used to detect crossing cell boundaries) More...
 
QPoint m_currentMousePosition
 
std::map< QPoint, GridCellm_gridCells
 
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 Object
static void set_count (bool flag)
 enable/disable class instances counting More...
 
static bool count_active ()
 return true if class instances counting is enabled More...
 
static unsigned objects_count ()
 return the number of objects More...
 
static void write_objects_map_to (std::ostream &out)
 output the full objects map to a given ostream More...
 
static void write_objects_map_to_cerr ()
 output objects map to stderr More...
 
static int bootstrap (Logger *logger, bool count=false)
 must be called before any Object instantiation ! More...
 
static Loggerlogger ()
 return the logger instance More...
 
- Static Public Attributes inherited from Object
static QString sPrintIndention = " "
 String used to format the debugging string output of some core classes. More...
 
- Static Protected Attributes inherited from Object
static Logger__logger = nullptr
 logger instance pointer More...
 

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.

Constructor & Destructor Documentation

◆ SongEditor()

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

◆ ~SongEditor()

~SongEditor ( )

Member Function Documentation

◆ addPattern()

void addPattern ( int  nColumn,
int  nRow 
)

Add or delete pattern in the sequence grid.

◆ 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 >.

◆ cleanUp()

void cleanUp ( )

◆ clearThePatternSequenceVector()

void clearThePatternSequenceVector ( QString  filename)

◆ columnRowToXy()

QPoint columnRowToXy ( QPoint  p)
private

◆ copy

void copy ( )
slot

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

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

◆ createBackground()

void createBackground ( )

◆ cut

void cut ( )
slot

◆ deletePattern()

void deletePattern ( int  nColumn,
int  nRow 
)

◆ deleteSelection

void deleteSelection ( )
slot

◆ drawPattern()

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

◆ drawSequence()

void drawSequence ( )
private

◆ 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 >.

◆ endMouseGesture()

virtual void endMouseGesture ( )
inlineoverrideprivatevirtual

Reimplemented from SelectionWidget< QPoint >.

◆ focusInEvent()

void focusInEvent ( QFocusEvent *  ev)
overrideprivatevirtual

◆ getCursorColumn()

int getCursorColumn ( ) const
inline

◆ getCursorRow()

int getCursorRow ( ) const
inline

◆ getGridHeight()

int getGridHeight ( )
inline

◆ getGridWidth()

int getGridWidth ( )

◆ getKeyboardCursorRect()

QRect getKeyboardCursorRect ( )
overridevirtual

Calculate screen space occupied by keyboard cursor.

Implements SelectionWidget< QPoint >.

◆ keyPressEvent()

void keyPressEvent ( QKeyEvent *  ev)
overrideprivatevirtual

◆ keyReleaseEvent()

void keyReleaseEvent ( QKeyEvent *  ev)
overrideprivatevirtual

◆ 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

◆ mouseClickEvent()

void mouseClickEvent ( QMouseEvent *  ev)
overridevirtual

◆ mouseDragEndEvent()

void mouseDragEndEvent ( QMouseEvent *  ev)
overridevirtual

◆ mouseDragStartEvent()

void mouseDragStartEvent ( QMouseEvent *  ev)
overridevirtual

◆ mouseDragUpdateEvent()

void mouseDragUpdateEvent ( QMouseEvent *  ev)
overridevirtual

◆ mouseMoveEvent()

void mouseMoveEvent ( QMouseEvent *  ev)
overrideprivatevirtual

◆ mousePressEvent()

void mousePressEvent ( QMouseEvent *  ev)
overrideprivatevirtual

◆ mouseReleaseEvent()

void mouseReleaseEvent ( QMouseEvent *  ev)
overrideprivatevirtual

◆ movingGridOffset()

QPoint movingGridOffset ( ) const
private

Quantise the selection move offset to the sequence grid.

◆ paintEvent()

void paintEvent ( QPaintEvent *  ev)
overrideprivatevirtual

◆ paste

void paste ( )
slot

◆ selectAll

void selectAll ( )
slot

◆ selectionMoveEndEvent()

void selectionMoveEndEvent ( QInputEvent *  ev)
overridevirtual

◆ selectNone

void selectNone ( )
slot

◆ setGridWidth()

void setGridWidth ( uint  width)

◆ setPatternActive()

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

◆ startMouseLasso()

virtual void startMouseLasso ( QMouseEvent *  ev)
inlineoverrideprivatevirtual

Reimplemented from SelectionWidget< QPoint >.

◆ togglePatternActive()

bool togglePatternActive ( int  nColumn,
int  nRow 
)
private

◆ updateEditorandSetTrue()

void updateEditorandSetTrue ( )

◆ updateGridCells()

void updateGridCells ( )
private

◆ updateModifiers()

void updateModifiers ( QInputEvent *  ev)
virtual

◆ 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 >.

◆ validateSelection()

virtual void validateSelection ( )
inlineoverridevirtual

Ensure that the Selection contains only valid elements.

Implements SelectionWidget< QPoint >.

◆ xyToColumnRow()

QPoint xyToColumnRow ( QPoint  p)
private

Field Documentation

◆ m_bCopyNotMove

bool m_bCopyNotMove
private

◆ 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.

◆ m_bSequenceChanged

bool m_bSequenceChanged
private

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

◆ m_currentMousePosition

QPoint m_currentMousePosition
private

◆ m_gridCells

std::map< QPoint, GridCell > m_gridCells
private

◆ m_nCursorColumn

int m_nCursorColumn
private

◆ m_nCursorRow

int m_nCursorRow
private

◆ m_nGridHeight

unsigned m_nGridHeight
private

◆ m_nGridWidth

unsigned m_nGridWidth
private

◆ m_nMargin

const int m_nMargin = 10
private

◆ m_nMaxPatternSequence

unsigned m_nMaxPatternSequence
private

◆ m_pBackgroundPixmap

QPixmap* m_pBackgroundPixmap
private

◆ m_pPopupMenu

QMenu* m_pPopupMenu
private

◆ m_previousMousePosition

QPoint m_previousMousePosition
private

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

◆ m_pScrollView

QScrollArea* m_pScrollView
private

◆ m_pSequencePixmap

QPixmap* m_pSequencePixmap
private

◆ m_pSongEditorPanel

SongEditorPanel* m_pSongEditorPanel
private

◆ m_selection

Selection<QPoint> m_selection
private