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

Adds a feature that captures the keyboard on the Piano Roll #5503

Closed
wants to merge 8 commits into from
Closed
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/classic/capture_keyboard_off.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/classic/capture_keyboard_on.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/capture_keyboard_off.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/capture_keyboard_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions include/PianoRoll.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include "ToolTip.h"
#include "StepRecorder.h"
#include "StepRecorderWidget.h"
#include "NStateButton.h"

class QPainter;
class QPixmap;
Expand Down Expand Up @@ -235,6 +236,8 @@ protected slots:

void clearGhostPattern();

// For toggling the capture keyboard feature
void toggleCaptureKeyboard(int state);

signals:
void currentPatternChanged();
Expand Down Expand Up @@ -453,6 +456,11 @@ protected slots:
bool m_ghostNoteBorders;
QColor m_backgroundShade;

// Capture Keyboard
bool m_captureKeyboard;
bool m_captureKeyboardAsk; // Enables/Disables the confirmation dialog
NStateButton *m_captureKeyboardButton;

signals:
void positionChanged( const MidiTime & );
} ;
Expand Down
78 changes: 77 additions & 1 deletion src/gui/editors/PianoRoll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <QPointer>
#include <QScrollBar>
#include <QStyleOption>
#include <QMessageBox>
#include <QCheckBox>

#ifndef __USE_XOPEN
#define __USE_XOPEN
Expand Down Expand Up @@ -63,6 +65,7 @@
#include "TextFloat.h"
#include "TimeLineWidget.h"
#include "StepRecorderWidget.h"
#include "NStateButton.h"


using std::move;
Expand Down Expand Up @@ -206,7 +209,9 @@ PianoRoll::PianoRoll() :
m_ghostNoteOpacity( 255 ),
m_noteBorders( true ),
m_ghostNoteBorders( true ),
m_backgroundShade( 0, 0, 0 )
m_backgroundShade( 0, 0, 0 ),
m_captureKeyboard(false),
m_captureKeyboardAsk(true)
{
// gui names of edit modes
m_nemStr.push_back( tr( "Note Velocity" ) );
Expand Down Expand Up @@ -1214,6 +1219,17 @@ int PianoRoll::selectionCount() const // how many notes are selected?

void PianoRoll::keyPressEvent(QKeyEvent* ke)
{
// Just for the capture keyboard feature:
if (m_captureKeyboard)
{
// In that context, escape will turn off the capture keyboard feature (but we don't
// consume the event because it also does something inside the piano roll).
if (ke->key() == Qt::Key_Escape)
{
m_captureKeyboardButton->changeState(0); // Disable the capture keyboard
}
}

if(m_stepRecorder.isRecording())
{
bool handled = m_stepRecorder.keyPressEvent(ke);
Expand Down Expand Up @@ -4317,6 +4333,55 @@ void PianoRoll::zoomingYChanged()
update();
}

// Toggle capture keyboard variable
void PianoRoll::toggleCaptureKeyboard(int state)
{
// Message box for confirmation
QMessageBox mb(tr("Are you sure you want to capture the keyboard?"),
tr("Enabling this feature will capture the keyboard to the piano roll, "
"making it unusable on other applications until it's disabled.\n"
"Are you sure you want to enable it?\n\n"
"Hint: Press Esc to quickly disable the keyboard capture."),
QMessageBox::Warning,
QMessageBox::Yes,
QMessageBox::No,
QMessageBox::NoButton,
this);

// Don't ask again checkbox
QCheckBox *cb = new QCheckBox("Don't ask me again.");
QObject::connect(cb, &QCheckBox::stateChanged, [this](int state){
if (state == static_cast<int>(Qt::CheckState::Checked)){
m_captureKeyboardAsk = false;
}
});
mb.setCheckBox(cb);

// State 1 = On. State 0 = Off
if (state == 1)
{
// Answer is Yes if the "Don't ask again" box was ticked
int answer = m_captureKeyboardAsk ? mb.exec() : static_cast<int>(QMessageBox::Yes);

if (answer == static_cast<int>(QMessageBox::Yes))
{
this->grabKeyboard();
m_captureKeyboard = true;
}
else
{
m_captureKeyboardButton->changeState(0);
}
}
else
{
if (m_captureKeyboard == true)
{
this->releaseKeyboard();
m_captureKeyboard = false;
}
}
}

void PianoRoll::quantizeChanged()
{
Expand Down Expand Up @@ -4532,6 +4597,17 @@ PianoRollWindow::PianoRollWindow() :
m_editor->m_timeLine->addToolButtons( timeLineToolBar );


// Add a toolbar with capture keyboard feature
DropToolBar *keyboardControlToolBar = addDropToolBarToTop(tr("Keyboard controls"));

m_editor->m_captureKeyboardButton = new NStateButton(keyboardControlToolBar);
m_editor->m_captureKeyboardButton->setGeneralToolTip(tr("Enable/Disable Keyboard Capture"));
m_editor->m_captureKeyboardButton->addState(embed::getIconPixmap("capture_keyboard_off"));
m_editor->m_captureKeyboardButton->addState(embed::getIconPixmap("capture_keyboard_on"));

keyboardControlToolBar->addWidget(m_editor->m_captureKeyboardButton);
connect(m_editor->m_captureKeyboardButton, SIGNAL(changedState(int)), m_editor, SLOT(toggleCaptureKeyboard(int)));

addToolBarBreak();


Expand Down