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

@@ -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();