Skip to content

Commit

Permalink
Add track move commands to controls library. Sending key event to lib…
Browse files Browse the repository at this point in the history
…rary widget.

Co-authored-by: ronso0 <[email protected]>
  • Loading branch information
Nicolau Leal Werneck and ronso0 committed Jun 18, 2024
1 parent c6a1993 commit e1d6fcc
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 6 deletions.
70 changes: 64 additions & 6 deletions src/library/librarycontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,30 @@ LibraryControl::LibraryControl(Library* pLibrary)
&LibraryControl::slotMoveFocus);
}

// Controls to move tracks on playlist
// Track move controls (emulate Alt+up/down button press)
m_pMoveTrackUp = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "MoveTrackUp"));
m_pMoveTrackDown = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "MoveTrackDown"));
m_pMoveTrack = std::make_unique<ControlEncoder>(ConfigKey("[Library]", "MoveTrack"), false);
#ifdef MIXXX_USE_QML
if (!CmdlineArgs::Instance().isQml())
#endif
{
connect(m_pMoveTrackUp.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveTrackUp);
connect(m_pMoveTrackDown.get(),
&ControlPushButton::valueChanged,
this,
&LibraryControl::slotMoveTrackDown);
connect(m_pMoveTrack.get(),
&ControlEncoder::valueChanged,
this,
&LibraryControl::slotMoveTrack);
}

// Direct focus control, read/write
m_pFocusedWidgetCO = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "focused_widget"));
Expand Down Expand Up @@ -219,7 +243,7 @@ LibraryControl::LibraryControl(Library* pLibrary)
}

// Auto DJ controls
m_pAutoDjAddTop = std::make_unique<ControlPushButton>(ConfigKey("[Library]","AutoDjAddTop"));
m_pAutoDjAddTop = std::make_unique<ControlPushButton>(ConfigKey("[Library]", "AutoDjAddTop"));
m_pAutoDjAddTop->addAlias(ConfigKey(
QStringLiteral("[Playlist]"), QStringLiteral("AutoDjAddTop")));
#ifdef MIXXX_USE_QML
Expand All @@ -232,7 +256,8 @@ LibraryControl::LibraryControl(Library* pLibrary)
&LibraryControl::slotAutoDjAddTop);
}

m_pAutoDjAddBottom = std::make_unique<ControlPushButton>(ConfigKey("[Library]","AutoDjAddBottom"));
m_pAutoDjAddBottom = std::make_unique<ControlPushButton>(
ConfigKey("[Library]", "AutoDjAddBottom"));
m_pAutoDjAddBottom->addAlias(ConfigKey(
QStringLiteral("[Playlist]"), QStringLiteral("AutoDjAddBottom")));
#ifdef MIXXX_USE_QML
Expand Down Expand Up @@ -419,7 +444,8 @@ LibraryControl::LibraryControl(Library* pLibrary)
&LibraryControl::slotSelectPrevTrack);

// Ignoring no-ops is important since this is for +/- tickers.
m_pSelectTrack = std::make_unique<ControlObject>(ConfigKey("[Playlist]","SelectTrackKnob"), false);
m_pSelectTrack = std::make_unique<ControlObject>(
ConfigKey("[Playlist]", "SelectTrackKnob"), false);
connect(m_pSelectTrack.get(),
&ControlObject::valueChanged,
this,
Expand Down Expand Up @@ -450,7 +476,8 @@ LibraryControl::LibraryControl(Library* pLibrary)
this,
&LibraryControl::slotToggleSelectedSidebarItem);

m_pLoadSelectedIntoFirstStopped = std::make_unique<ControlPushButton>(ConfigKey("[Playlist]","LoadSelectedIntoFirstStopped"));
m_pLoadSelectedIntoFirstStopped = std::make_unique<ControlPushButton>(
ConfigKey("[Playlist]", "LoadSelectedIntoFirstStopped"));
connect(m_pLoadSelectedIntoFirstStopped.get(),
&ControlPushButton::valueChanged,
this,
Expand Down Expand Up @@ -734,7 +761,7 @@ void LibraryControl::slotScrollDown(double v) {
}

void LibraryControl::slotScrollVertical(double v) {
const auto key = (v < 0) ? Qt::Key_PageUp: Qt::Key_PageDown;
const auto key = (v < 0) ? Qt::Key_PageUp : Qt::Key_PageDown;
const auto times = static_cast<unsigned short>(std::abs(v));
emitKeyEvent(QKeyEvent{QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
}
Expand All @@ -752,7 +779,7 @@ void LibraryControl::slotMoveRight(double v) {
}

void LibraryControl::slotMoveHorizontal(double v) {
const auto key = (v < 0) ? Qt::Key_Left: Qt::Key_Right;
const auto key = (v < 0) ? Qt::Key_Left : Qt::Key_Right;
const auto times = static_cast<unsigned short>(std::abs(v));
emitKeyEvent(QKeyEvent{QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
}
Expand Down Expand Up @@ -781,6 +808,37 @@ void LibraryControl::slotMoveFocus(double v) {
QEvent::KeyPress, key, Qt::NoModifier, QString(), false, times});
}

void LibraryControl::slotMoveTrackUp(double v) {
if (v > 0) {
slotMoveTrack(-1);
}
}

void LibraryControl::slotMoveTrackDown(double v) {
if (v > 0) {
slotMoveTrack(1);
}
}

/// Move a selected track up or down a playlist by emulating Alt + Up/Down keypresses
void LibraryControl::slotMoveTrack(double v) {
if (!m_pLibraryWidget) {
return;
}

auto* pTrackTableview = m_pLibraryWidget->getCurrentTrackTableView();
if (!pTrackTableview) {
// no track table view is currently visible
return;
}

const auto key = (v < 0) ? Qt::Key_Up : Qt::Key_Down;
const auto times = static_cast<unsigned short>(std::abs(v));
QKeyEvent pEvent = QKeyEvent{
QEvent::KeyPress, key, Qt::AltModifier, QString(), false, times};
QApplication::sendEvent(pTrackTableview, &pEvent);
}

void LibraryControl::emitKeyEvent(QKeyEvent&& event) {
if (!QApplication::focusWindow()) {
qInfo() << "No Mixxx window, popup or menu has focus."
Expand Down
8 changes: 8 additions & 0 deletions src/library/librarycontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ class LibraryControl : public QObject {
void slotMoveFocusForward(double);
void slotMoveFocusBackward(double);
void slotMoveFocus(double);
void slotMoveTrackUp(double);
void slotMoveTrackDown(double);
void slotMoveTrack(double);
void slotGoToItem(double v);

void slotTrackColorPrev(double v);
Expand Down Expand Up @@ -140,6 +143,11 @@ class LibraryControl : public QObject {
std::unique_ptr<ControlPushButton> m_pRefocusPrevWidgetCO;
FocusWidget m_prevFocusedWidget;

// Controls to move tracks (alt+up/down buttons)
std::unique_ptr<ControlPushButton> m_pMoveTrackUp;
std::unique_ptr<ControlPushButton> m_pMoveTrackDown;
std::unique_ptr<ControlEncoder> m_pMoveTrack;

// Control to choose the currently selected item in focused widget (double click)
std::unique_ptr<ControlObject> m_pGoToItem;

Expand Down

0 comments on commit e1d6fcc

Please sign in to comment.