Skip to content

Commit

Permalink
Ghost notes improvements.
Browse files Browse the repository at this point in the history
* Make a copy of a pattern it’s notes instead of pointing to a pattern.
* Save/load the ghost notes in/from the DOM document.
  • Loading branch information
CYBERDEViLNL authored and zonkmachine committed Feb 8, 2019
1 parent 7a0b874 commit 9981b76
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
9 changes: 8 additions & 1 deletion include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ class PianoRoll : public QWidget

void setCurrentPattern( Pattern* newPattern );
void setGhostPattern( Pattern* newPattern );
void loadGhostNotes( const QDomElement & de );

inline void stopRecording()
{
Expand Down Expand Up @@ -325,7 +326,13 @@ protected slots:
static const QVector<double> m_zoomLevels;

Pattern* m_pattern;
Pattern* m_ghostPattern;
NoteVector m_ghostNotes;

inline const NoteVector & ghostNotes() const
{
return m_ghostNotes;
}

QScrollBar * m_leftRightScroll;
QScrollBar * m_topBottomScroll;

Expand Down
50 changes: 45 additions & 5 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ void PianoRoll::reset()
{
m_lastNoteVolume = DefaultVolume;
m_lastNotePanning = DefaultPanning;
clearGhostPattern();
}

void PianoRoll::showTextFloat(const QString &text, const QPoint &pos, int timeout)
Expand Down Expand Up @@ -605,11 +606,33 @@ PianoRoll::~PianoRoll()

void PianoRoll::setGhostPattern( Pattern* newPattern )
{
m_ghostPattern = newPattern;
// Expects a pointer to a pattern or nullptr.
m_ghostNotes.clear();
if( newPattern != nullptr )
{
// make sure to always get informed about the pattern being destroyed
connect( m_ghostPattern, SIGNAL( destroyedPattern( Pattern* ) ), this, SLOT( clearGhostPattern() ) );
for( Note *note : newPattern->notes() )
{
Note * new_note = new Note( note->length(), note->pos(), note->key() );
m_ghostNotes.push_back( new_note );
}
emit ghostPatternSet( true );
}
}


void PianoRoll::loadGhostNotes( const QDomElement & de )
{
// Load ghost notes from DOM element.
if( de.isElement() )
{
QDomNode node = de.firstChild();
while( !node.isNull() )
{
Note * n = new Note;
n->restoreState( node.toElement() );
m_ghostNotes.push_back( n );
node = node.nextSibling();
}
emit ghostPatternSet( true );
}
}
Expand Down Expand Up @@ -3072,9 +3095,9 @@ void PianoRoll::paintEvent(QPaintEvent * pe )
QPolygonF editHandles;

// -- Begin ghost pattern
if( m_ghostPattern != nullptr && m_ghostPattern != m_pattern )
if( !m_ghostNotes.empty() )
{
for( const Note *note : m_ghostPattern->notes() )
for( const Note *note : m_ghostNotes )
{
int len_ticks = note->length();

Expand Down Expand Up @@ -4459,6 +4482,21 @@ void PianoRollWindow::reset()

void PianoRollWindow::saveSettings( QDomDocument & doc, QDomElement & de )
{
if( !m_editor->ghostNotes().empty() )
{
QDomElement ghostNotesRoot = doc.createElement( "ghostnotes" );
for( Note *note : m_editor->ghostNotes() )
{
QDomElement ghostNoteNode = doc.createElement( "ghostnote" );
ghostNoteNode.setAttribute( "len", note->length() );
ghostNoteNode.setAttribute( "key", note->key() );
ghostNoteNode.setAttribute( "pos", note->pos() );

ghostNotesRoot.appendChild(ghostNoteNode);
}
de.appendChild( ghostNotesRoot );
}

MainWindow::saveWidgetState( this, de );
}

Expand All @@ -4467,6 +4505,8 @@ void PianoRollWindow::saveSettings( QDomDocument & doc, QDomElement & de )

void PianoRollWindow::loadSettings( const QDomElement & de )
{
m_editor->loadGhostNotes( de.firstChildElement("ghostnotes") );

MainWindow::restoreWidgetState( this, de );
}

Expand Down
4 changes: 1 addition & 3 deletions src/tracks/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,9 +676,7 @@ void PatternView::constructContextMenu( QMenu * _cm )
connect( a, SIGNAL( triggered( bool ) ),
this, SLOT( openInPianoRoll() ) );

if( gui->pianoRoll()->currentPattern() &&
gui->pianoRoll()->currentPattern() != m_pat &&
!m_pat->empty() )
if( gui->pianoRoll()->currentPattern() && !m_pat->empty() )
{
QAction * b = new QAction( embed::getIconPixmap( "ghost_note" ),
tr( "Set as ghost in piano-roll" ), _cm );
Expand Down

0 comments on commit 9981b76

Please sign in to comment.