Refactor Global Spacebar Play (#7926)

This PR simplifies #7762 by removing the editor-specific code from MainWindow and m_lastPlayMode from Song, and instead uses a static variable in Editor which keeps track of the last played editor.

This PR also removes the spacebar shortcut from MixerChannelView for changing the volume, as multiple users have noticed that it clashes with their intuition after getting used to the spacebar working everywhere else.
This commit is contained in:
regulus79
2025-08-14 10:08:04 -04:00
committed by GitHub
parent 0d6cbbdf5e
commit 981e266613
6 changed files with 16 additions and 30 deletions

View File

@@ -51,6 +51,7 @@ class Editor : public QMainWindow
public:
void setPauseIcon(bool displayPauseIcon=true);
QAction *playAction() const;
static Editor* lastPlayedEditor() { return s_lastPlayedEditor; }
protected:
DropToolBar * addDropToolBarToTop(QString const & windowTitle);
DropToolBar * addDropToolBar(Qt::ToolBarArea whereToAdd, QString const & windowTitle);
@@ -73,6 +74,8 @@ protected slots:
private slots:
void toggleMaximize();
private:
inline static Editor* s_lastPlayedEditor = nullptr;
signals:

View File

@@ -254,7 +254,6 @@ public:
return m_playMode;
}
PlayMode lastPlayMode() const { return m_lastPlayMode; }
inline PlayPos & getPlayPos( PlayMode pm )
{
return m_playPos[static_cast<std::size_t>(pm)];
@@ -490,7 +489,6 @@ private:
std::array<Timeline, PlayModeCount> m_timelines;
PlayMode m_playMode;
PlayMode m_lastPlayMode;
PlayPos m_playPos[PlayModeCount];
bar_t m_length;

View File

@@ -499,7 +499,6 @@ void Song::playSong()
}
m_playMode = PlayMode::Song;
m_lastPlayMode = m_playMode;
m_playing = true;
m_paused = false;
@@ -539,7 +538,6 @@ void Song::playPattern()
}
m_playMode = PlayMode::Pattern;
m_lastPlayMode = m_playMode;
m_playing = true;
m_paused = false;
@@ -566,7 +564,6 @@ void Song::playMidiClip( const MidiClip* midiClipToPlay, bool loop )
if( m_midiClipToPlay != nullptr )
{
m_playMode = PlayMode::MidiClip;
m_lastPlayMode = m_playMode;
m_playing = true;
m_paused = false;
}

View File

@@ -1285,27 +1285,11 @@ void MainWindow::keyPressEvent( QKeyEvent * _ke )
case Qt::Key_Alt: m_keyMods.m_alt = true; break;
case Qt::Key_Space:
{
Editor* lastEditor = nullptr;
switch (Engine::getSong()->lastPlayMode())
if (Editor::lastPlayedEditor() != nullptr)
{
case Song::PlayMode::Song:
lastEditor = getGUI()->songEditor();
break;
case Song::PlayMode::MidiClip:
lastEditor = getGUI()->pianoRoll();
break;
case Song::PlayMode::Pattern:
lastEditor = getGUI()->patternEditor();
break;
case Song::PlayMode::AutomationClip:
lastEditor = getGUI()->automationEditor();
break;
default:
lastEditor = getGUI()->songEditor();
break;
if (m_keyMods.m_shift) { Editor::lastPlayedEditor()->togglePause(); }
else { Editor::lastPlayedEditor()->togglePlayStop(); }
}
if (m_keyMods.m_shift) { lastEditor->togglePause(); }
else { lastEditor->togglePlayStop(); }
break;
}
default:

View File

@@ -240,10 +240,6 @@ void MixerChannelView::keyPressEvent(QKeyEvent* ke)
renameFinished();
}
}
else if (ke->key() == Qt::Key_Space)
{
m_fader->adjustByDialog();
}
else
{
ke->ignore();

View File

@@ -73,6 +73,7 @@ DropToolBar * Editor::addDropToolBar(QWidget * parent, Qt::ToolBarArea whereToAd
void Editor::togglePlayStop()
{
s_lastPlayedEditor = this;
if (Engine::getSong()->isPlaying())
stop();
else
@@ -81,6 +82,7 @@ void Editor::togglePlayStop()
void Editor::togglePause()
{
s_lastPlayedEditor = this;
Engine::getSong()->togglePause();
}
@@ -118,7 +120,6 @@ Editor::Editor(bool record, bool stepRecord) :
connect(m_recordAccompanyAction, SIGNAL(triggered()), this, SLOT(recordAccompany()));
connect(m_toggleStepRecordingAction, SIGNAL(triggered()), this, SLOT(toggleStepRecording()));
connect(m_stopAction, SIGNAL(triggered()), this, SLOT(stop()));
new QShortcut(QKeySequence(combine(Qt::SHIFT, Qt::Key_Space)), this, SLOT(togglePause()));
new QShortcut(QKeySequence(combine(Qt::SHIFT, Qt::Key_F11)), this, SLOT(toggleMaximize()));
// Add actions to toolbar
@@ -158,7 +159,14 @@ void Editor::closeEvent(QCloseEvent * event)
{
if (ke->key() == Qt::Key_Space)
{
togglePlayStop();
if (ke->modifiers() & Qt::ShiftModifier)
{
togglePause();
}
else
{
togglePlayStop();
}
return;
}
ke->ignore();