From 54955307452fa7c639ae1c8ac6cbe530e165da9e Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 2 Jun 2024 14:17:45 +0200 Subject: [PATCH] Recording widget/options visibility Only show the recording widget in the sample clip if the audio engine has a device configured that can capture audio. For simplicity of the code, i.e. no nullptr checks, the widget is always created but only shown if capture capabilities are available. Rename the context menu entry "Set/clear record" to "Toggle record" and only enable it if capture is possible. In `SampleClipView` the test for the availability of a capture device is abstracted behind the helper method `recordingCapabilitiesAvailable`. Technical details ------------------ Add the method `captureDeviceAvailable` to `AudioEngine` because clients should not be concerned with driver details. Drivers should mostly be used by the audio engine and therefore hidden to clients. Add a private `const` version of the method `audioDev` so that `captureDeviceAvailable` can be implemented in a `const` correct way. Use `captureDeviceAvailable` in the constructor of `SongEditorWindow`. --- include/AudioEngine.h | 7 +++++++ include/SampleClipView.h | 1 + src/core/AudioEngine.cpp | 4 ++++ src/gui/clips/SampleClipView.cpp | 15 ++++++++++++--- src/gui/editors/SongEditor.cpp | 3 +-- 5 files changed, 25 insertions(+), 5 deletions(-) diff --git a/include/AudioEngine.h b/include/AudioEngine.h index e434b7f15..d4c8331d4 100644 --- a/include/AudioEngine.h +++ b/include/AudioEngine.h @@ -172,6 +172,8 @@ public: return m_audioDev; } + bool captureDeviceAvailable() const; + // audio-port-stuff inline void addAudioPort(AudioPort * port) @@ -355,6 +357,11 @@ private: AudioDevice * tryAudioDevices(); MidiClient * tryMidiClients(); + inline const AudioDevice* audioDev() const + { + return m_audioDev; + } + void renderStageNoteSetup(); void renderStageInstruments(); void renderStageEffects(); diff --git a/include/SampleClipView.h b/include/SampleClipView.h index 73ed474e7..7f7d5a302 100644 --- a/include/SampleClipView.h +++ b/include/SampleClipView.h @@ -67,6 +67,7 @@ protected: private: QWidget* buildRecordWidget(BoolModel& recordModel); void adjustRecordWidget(); + bool recordingCapabilitiesAvailable() const; private: SampleClip * m_clip; diff --git a/src/core/AudioEngine.cpp b/src/core/AudioEngine.cpp index 3dc0f7c15..8951dcde5 100644 --- a/src/core/AudioEngine.cpp +++ b/src/core/AudioEngine.cpp @@ -666,6 +666,10 @@ void AudioEngine::restoreAudioDevice() } +bool AudioEngine::captureDeviceAvailable() const +{ + return audioDev()->supportsCapture(); +} void AudioEngine::removeAudioPort(AudioPort * port) diff --git a/src/gui/clips/SampleClipView.cpp b/src/gui/clips/SampleClipView.cpp index ca8ec0978..faa56ceb2 100644 --- a/src/gui/clips/SampleClipView.cpp +++ b/src/gui/clips/SampleClipView.cpp @@ -30,6 +30,7 @@ #include #include +#include "AudioEngine.h" #include "GuiApplication.h" #include "AutomationEditor.h" #include "embed.h" @@ -61,8 +62,9 @@ SampleClipView::SampleClipView( SampleClip * _clip, TrackView * _tv ) : setStyle( QApplication::style() ); + // To simplify the code we always create the widget but we do not always show it m_recordWidget = buildRecordWidget(_clip->getRecordModel()); - m_recordWidget->setVisible(true); + m_recordWidget->setVisible(recordingCapabilitiesAvailable()); adjustRecordWidget(); } @@ -87,9 +89,11 @@ void SampleClipView::constructContextMenu(QMenu* cm) cm->addSeparator(); - cm->addAction(embed::getIconPixmap("record"), - tr("Set/clear record"), + QAction* recordToggleAction = cm->addAction(embed::getIconPixmap("record"), + tr("Toggle record"), m_clip, SLOT(toggleRecord())); + + recordToggleAction->setEnabled(recordingCapabilitiesAvailable()); cm->addAction( embed::getIconPixmap("flip_x"), @@ -405,4 +409,9 @@ void SampleClipView::adjustRecordWidget() m_recordWidget->move(1, height() - m_recordWidget->height() - 1); } +bool SampleClipView::recordingCapabilitiesAvailable() const +{ + return Engine::audioEngine()->captureDeviceAvailable(); +} + } // namespace lmms::gui diff --git a/src/gui/editors/SongEditor.cpp b/src/gui/editors/SongEditor.cpp index ded928157..f020e58d7 100644 --- a/src/gui/editors/SongEditor.cpp +++ b/src/gui/editors/SongEditor.cpp @@ -35,7 +35,6 @@ #include #include "ActionGroup.h" -#include "AudioDevice.h" #include "AudioEngine.h" #include "AutomatableSlider.h" #include "ClipView.h" @@ -1025,7 +1024,7 @@ SongEditorWindow::SongEditorWindow(Song* song) : // In case our current audio device does not support capture, // disable the record buttons. - if(!Engine::audioEngine()->audioDev()->supportsCapture()) { + if(!Engine::audioEngine()->captureDeviceAvailable()) { for (auto &recordAction : {m_recordAccompanyAction, m_recordAction}) { recordAction->setEnabled(false); recordAction->setToolTip(tr("Recording is unavailable: try connecting an input device or switching backend"));