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

Enhanced quantize in PianoRoll #5946

Merged
merged 5 commits into from
Mar 16, 2021
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
18 changes: 17 additions & 1 deletion data/themes/classic/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ QToolButton#stopButton {

/* all tool buttons */

QToolButton {
QToolButton, QToolButton::menu-button {
padding: 1px 1px 1px 1px;
border-radius: 5px;
border: 1px solid rgba(63, 63, 63, 128);
Expand All @@ -510,6 +510,22 @@ QToolButton:checked {
color: black;
}

/* buttons with combined menu */

QToolButton[popupMode="1"] {
margin-right: 11px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

QToolButton::menu-button {
subcontrol-origin: margin;
width: 11px;
padding: 0;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}

/* track label buttons - the part that contains the icon and track title */

TrackLabelButton {
Expand Down
18 changes: 17 additions & 1 deletion data/themes/default/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ QToolBar::separator {

/* all tool buttons */

QToolButton {
QToolButton, QToolButton::menu-button {
margin: 1px;
padding: 2px 2px 2px 2px;
border-top: 1px solid #778394;
Expand Down Expand Up @@ -522,6 +522,22 @@ QToolButton:checked {
background-image: url(resources:shadow_p.png);
}

/* buttons with combined menu */

QToolButton[popupMode="1"] {
margin-right: 13px;
border-top-right-radius: 0;
border-bottom-right-radius: 0;
}

QToolButton::menu-button {
subcontrol-origin: margin;
width: 13px;
padding: 0;
border-top-left-radius: 0;
border-bottom-left-radius: 0;
}

/* track label buttons - the part that contains the icon and track title */

TrackLabelButton {
Expand Down
9 changes: 8 additions & 1 deletion include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ class PianoRoll : public QWidget
int quantization() const;

protected:
enum QuantizeActions
{
QuantizeBoth,
QuantizePos,
QuantizeLength
};

void keyPressEvent( QKeyEvent * ke ) override;
void keyReleaseEvent( QKeyEvent * ke ) override;
void leaveEvent( QEvent * e ) override;
Expand Down Expand Up @@ -198,7 +205,7 @@ protected slots:
void quantizeChanged();
void noteLengthChanged();
void keyChanged();
void quantizeNotes();
void quantizeNotes(QuantizeActions mode = QuantizeBoth);

void updateSemiToneMarkerMenu();

Expand Down
34 changes: 28 additions & 6 deletions src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4554,7 +4554,7 @@ int PianoRoll::quantization() const
}


void PianoRoll::quantizeNotes()
void PianoRoll::quantizeNotes(QuantizeActions mode)
{
if( ! hasValidPattern() )
{
Expand Down Expand Up @@ -4582,8 +4582,15 @@ void PianoRoll::quantizeNotes()

Note copy(*n);
m_pattern->removeNote( n );
copy.quantizePos( quantization() );
m_pattern->addNote( copy );
if (mode == QuantizeBoth || mode == QuantizePos)
{
copy.quantizePos(quantization());
}
if (mode == QuantizeBoth || mode == QuantizeLength)
{
copy.quantizeLength(quantization());
}
m_pattern->addNote(copy, false);
}

update();
Expand Down Expand Up @@ -4704,15 +4711,30 @@ PianoRollWindow::PianoRollWindow() :

connect( editModeGroup, SIGNAL( triggered( int ) ), m_editor, SLOT( setEditMode( int ) ) );

QAction* quantizeAction = new QAction(embed::getIconPixmap( "quantize" ), tr( "Quantize" ), this );
connect( quantizeAction, SIGNAL( triggered() ), m_editor, SLOT( quantizeNotes() ) );
// Quantize combo button
QToolButton* quantizeButton = new QToolButton(notesActionsToolBar);
QMenu* quantizeButtonMenu = new QMenu(quantizeButton);

QAction* quantizeAction = new QAction(embed::getIconPixmap("quantize"), tr("Quantize"), this);
QAction* quantizePosAction = new QAction(tr("Quantize positions"), this);
QAction* quantizeLengthAction = new QAction(tr("Quantize lengths"), this);

connect(quantizeAction, &QAction::triggered, [this](){ m_editor->quantizeNotes(); });
connect(quantizePosAction, &QAction::triggered, [this](){ m_editor->quantizeNotes(PianoRoll::QuantizePos); });
connect(quantizeLengthAction, &QAction::triggered, [this](){ m_editor->quantizeNotes(PianoRoll::QuantizeLength); });

quantizeButton->setPopupMode(QToolButton::MenuButtonPopup);
quantizeButton->setDefaultAction(quantizeAction);
quantizeButton->setMenu(quantizeButtonMenu);
quantizeButtonMenu->addAction(quantizePosAction);
quantizeButtonMenu->addAction(quantizeLengthAction);

notesActionsToolBar->addAction( drawAction );
notesActionsToolBar->addAction( eraseAction );
notesActionsToolBar->addAction( selectAction );
notesActionsToolBar->addAction( pitchBendAction );
notesActionsToolBar->addSeparator();
notesActionsToolBar->addAction( quantizeAction );
notesActionsToolBar->addWidget(quantizeButton);

// Copy + paste actions
DropToolBar *copyPasteActionsToolBar = addDropToolBarToTop( tr( "Copy paste controls" ) );
Expand Down