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`.
This commit is contained in:
Michael Gregorius
2024-06-02 14:17:45 +02:00
parent 48c4dce96f
commit 5495530745
5 changed files with 25 additions and 5 deletions

View File

@@ -666,6 +666,10 @@ void AudioEngine::restoreAudioDevice()
}
bool AudioEngine::captureDeviceAvailable() const
{
return audioDev()->supportsCapture();
}
void AudioEngine::removeAudioPort(AudioPort * port)

View File

@@ -30,6 +30,7 @@
#include <QMenu>
#include <QPainter>
#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

View File

@@ -35,7 +35,6 @@
#include <QTimeLine>
#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"));