Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ghost notes improvements. #4812

Merged
merged 2 commits into from Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
21 changes: 6 additions & 15 deletions src/tracks/Pattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,22 +676,13 @@ 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() )
{
QAction * b = new QAction( embed::getIconPixmap( "ghost_note" ),
QAction * b = new QAction( embed::getIconPixmap( "ghost_note" ),
tr( "Set as ghost in piano-roll" ), _cm );
_cm->insertAction( _cm->actions()[1], b );
connect( b, SIGNAL( triggered( bool ) ),
this, SLOT( setGhostInPianoRoll() ) );
_cm->insertSeparator( _cm->actions()[2] );
}
else
{
_cm->insertSeparator( _cm->actions()[1] );
}

if( m_pat->empty() ) { b->setEnabled( false ); }
_cm->insertAction( _cm->actions()[1], b );
connect( b, SIGNAL( triggered( bool ) ),
this, SLOT( setGhostInPianoRoll() ) );
_cm->insertSeparator( _cm->actions()[2] );
_cm->addSeparator();

_cm->addAction( embed::getIconPixmap( "edit_erase" ),
Expand Down