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

Glue rebase 2 #5721

Merged
merged 1 commit into from
Oct 19, 2020
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
Binary file added data/themes/default/glue.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/themes/default/tool.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ protected slots:
void selectRegionFromPixels( int xStart, int xEnd );

void clearGhostPattern();
void glueNotes();


signals:
Expand Down
83 changes: 83 additions & 0 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <QScrollBar>
#include <QStyleOption>
#include <QtMath>
#include <QToolButton>

#ifndef __USE_XOPEN
#define __USE_XOPEN
Expand Down Expand Up @@ -644,6 +645,73 @@ void PianoRoll::clearGhostPattern()
}


void PianoRoll::glueNotes()
{
if (hasValidPattern())
{
NoteVector selectedNotes = getSelectedNotes();
if (selectedNotes.empty())
{
TextFloat::displayMessage( tr( "Glue notes failed" ),
tr( "Please select notes to glue first." ),
embed::getIconPixmap( "glue", 24, 24 ),
3000 );
return;
}

// Make undo possible
m_pattern->addJournalCheckPoint();

// Sort notes on key and then pos.
std::sort(selectedNotes.begin(), selectedNotes.end(),
[](const Note * note, const Note * compareNote) -> bool
{
if (note->key() == compareNote->key())
{
return note->pos() < compareNote->pos();
}
return note->key() < compareNote->key();
});

QList<Note *> noteToRemove;

NoteVector::iterator note = selectedNotes.begin();
auto nextNote = note+1;
NoteVector::iterator end = selectedNotes.end();

while (note != end && nextNote != end)
{
// key and position match for glue. The notes are already
// sorted so we don't need to test that nextNote is the same
// position or next in sequence.
if ((*note)->key() == (*nextNote)->key()
&& (*nextNote)->pos() <= (*note)->pos()
+ qMax(MidiTime(0), (*note)->length()))
{
(*note)->setLength(qMax((*note)->length(),
MidiTime((*nextNote)->endPos() - (*note)->pos())));
noteToRemove.push_back(*nextNote);
++nextNote;
}
// key or position doesn't match
else
{
note = nextNote;
nextNote = note+1;
}
}

// Remove old notes
for (int i = 0; i < noteToRemove.count(); ++i)
{
m_pattern->removeNote(noteToRemove[i]);
}

update();
}
}


void PianoRoll::loadMarkedSemiTones(const QDomElement & de)
{
// clear marked semitones to prevent leftover marks
Expand Down Expand Up @@ -4361,6 +4429,21 @@ PianoRollWindow::PianoRollWindow() :
DropToolBar *timeLineToolBar = addDropToolBarToTop( tr( "Timeline controls" ) );
m_editor->m_timeLine->addToolButtons( timeLineToolBar );

// -- Note modifier tools
// Toolbar
QToolButton * noteToolsButton = new QToolButton(m_toolBar);
noteToolsButton->setIcon(embed::getIconPixmap("tool"));
noteToolsButton->setPopupMode(QToolButton::InstantPopup);

// Glue
QAction * glueAction = new QAction(embed::getIconPixmap("glue"),
tr("Glue"), noteToolsButton);
connect(glueAction, SIGNAL(triggered()), m_editor, SLOT(glueNotes()));
glueAction->setShortcut( Qt::SHIFT | Qt::Key_G );

noteToolsButton->addAction(glueAction);

notesActionsToolBar->addWidget(noteToolsButton);

addToolBarBreak();

Expand Down