From 5a8dce2650c93781f3630d2e023a6b6337aae53a Mon Sep 17 00:00:00 2001 From: Michael Gregorius Date: Sun, 28 Jun 2015 00:24:23 +0200 Subject: [PATCH] Fixes most of stuff found in Wallacoloo's code review for #1600 Removal of a superfluous include in AudioAlsaSetupWidget.cpp Removal of the function "bool hasCapabilities(char *device_name)" which was not used anyway. It implemented a test for ALSA device capabilities needed by LMMS (SND_PCM_ACCESS_RW_INTERLEAVED, SND_PCM_FORMAT_S16_LE, etc.). Corrected header name in AudioAlsaSetupWidget.h. Created an implementation file for AudioDeviceSetupWidget to make more clear that it's part of the GUI. Fix build for builds that use Port Audio. The setup widget of AudioPortAudio.h still inherited from AudioDevice::setupWidget instead of the new AudioDeviceSetupWidget. --- include/AudioAlsaSetupWidget.h | 4 +- include/AudioDeviceSetupWidget.h | 17 ++------- include/AudioPortAudio.h | 3 +- src/core/audio/AudioAlsa.cpp | 59 ------------------------------ src/core/audio/AudioPortAudio.cpp | 2 +- src/gui/AudioAlsaSetupWidget.cpp | 2 - src/gui/AudioDeviceSetupWidget.cpp | 41 +++++++++++++++++++++ src/gui/CMakeLists.txt | 1 + 8 files changed, 50 insertions(+), 79 deletions(-) create mode 100644 src/gui/AudioDeviceSetupWidget.cpp diff --git a/include/AudioAlsaSetupWidget.h b/include/AudioAlsaSetupWidget.h index 748536a0e..304870f22 100644 --- a/include/AudioAlsaSetupWidget.h +++ b/include/AudioAlsaSetupWidget.h @@ -1,5 +1,5 @@ /* - * AudioDeviceSetupWidget.h - Implements a setup widget for ALSA-PCM-output + * AudioAlsaSetupWidget.h - Implements a setup widget for ALSA-PCM-output * * Copyright (c) 2004-2015 Tobias Doerffel * @@ -57,7 +57,7 @@ private: int m_selectedDevice; AudioAlsa::DeviceInfoCollection m_deviceInfos; -} ; +}; #endif diff --git a/include/AudioDeviceSetupWidget.h b/include/AudioDeviceSetupWidget.h index 369d4d23c..6e23b3153 100644 --- a/include/AudioDeviceSetupWidget.h +++ b/include/AudioDeviceSetupWidget.h @@ -31,24 +31,13 @@ class AudioDeviceSetupWidget : public TabWidget { public: - AudioDeviceSetupWidget( const QString & _caption, QWidget * _parent ) : - TabWidget( TabWidget::tr( "Settings for %1" ).arg( - TabWidget::tr( _caption.toLatin1() ) ). - toUpper(), _parent ) - { - } + AudioDeviceSetupWidget( const QString & _caption, QWidget * _parent ); - virtual ~AudioDeviceSetupWidget() - { - } + virtual ~AudioDeviceSetupWidget(); virtual void saveSettings() = 0; - virtual void show() - { - parentWidget()->show(); - QWidget::show(); - } + virtual void show(); }; diff --git a/include/AudioPortAudio.h b/include/AudioPortAudio.h index a52ba52be..ab9be60c1 100644 --- a/include/AudioPortAudio.h +++ b/include/AudioPortAudio.h @@ -52,6 +52,7 @@ public: #endif #include "AudioDevice.h" +#include "AudioDeviceSetupWidget.h" #if defined paNeverDropInput || defined paNonInterleaved # define PORTAUDIO_V19 @@ -81,7 +82,7 @@ public: unsigned long _framesPerBuffer ); - class setupWidget : public AudioDevice::setupWidget + class setupWidget : public AudioDeviceSetupWidget { public: setupWidget( QWidget * _parent ); diff --git a/src/core/audio/AudioAlsa.cpp b/src/core/audio/AudioAlsa.cpp index fe26edccb..e903b436c 100644 --- a/src/core/audio/AudioAlsa.cpp +++ b/src/core/audio/AudioAlsa.cpp @@ -142,63 +142,6 @@ QString AudioAlsa::probeDevice() -/** - * @brief Checks whether the ALSA device with the given name has the needed - * capabilities for LMMS. - * @param deviceName Name of the device that is checked. - * @return If the device is usable for LMMS true is returned. - */ -bool hasCapabilities(char *device_name) -{ - snd_pcm_t *pcm; // PCM handle - snd_pcm_hw_params_t *hw_params; - int err; - - // Implicit check for SND_PCM_STREAM_PLAYBACK - err = snd_pcm_open(&pcm, device_name, SND_PCM_STREAM_PLAYBACK, 0); - if (err < 0) - { - std::cerr << "Cannot open device '" << device_name << "': " << snd_strerror(err) << std::endl; - return false; - } - - snd_pcm_hw_params_alloca(&hw_params); - err = snd_pcm_hw_params_any(pcm, hw_params); - if (err < 0) - { - std::cerr << "Cannot get hardware parameters: " << snd_strerror(err) << std::endl; - snd_pcm_close(pcm); - return false; - } - - // Checks for SND_PCM_ACCESS_RW_INTERLEAVED - err = snd_pcm_hw_params_test_access(pcm, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED); - if (err < 0) - { - std::cerr << "Interleaved access not possible for '" << device_name << "': " << snd_strerror(err) << std::endl; - snd_pcm_close(pcm); - return false; - } - - // Check for SND_PCM_FORMAT_S16_LE or SND_PCM_FORMAT_S16_BE - bool validFormatFound = false; - - validFormatFound |= !snd_pcm_hw_params_test_format(pcm, hw_params, SND_PCM_FORMAT_S16_LE); - validFormatFound |= !snd_pcm_hw_params_test_format(pcm, hw_params, SND_PCM_FORMAT_S16_BE); - - if (!validFormatFound) - { - std::cerr << "Device " << device_name << " does not not support SND_PCM_FORMAT_S16_LE or SND_PCM_FORMAT_S16_BE!" << std::endl; - snd_pcm_close(pcm); - return false; - } - - snd_pcm_close(pcm); - - return true; -} - - /** * @brief Creates a list of all available devices. * @@ -232,8 +175,6 @@ AudioAlsa::DeviceInfoCollection AudioAlsa::getAvailableDevices() char *name = snd_device_name_get_hint(*n, "NAME"); char *description = snd_device_name_get_hint(*n, "DESC"); - // We could call hasCapabilities(name) here but this gives strange - // results if (name != 0 && description != 0) { deviceInfos.push_back(DeviceInfo(QString(name), QString(description))); diff --git a/src/core/audio/AudioPortAudio.cpp b/src/core/audio/AudioPortAudio.cpp index d23baf277..b2ddf1d97 100644 --- a/src/core/audio/AudioPortAudio.cpp +++ b/src/core/audio/AudioPortAudio.cpp @@ -389,7 +389,7 @@ void AudioPortAudioSetupUtil::updateChannels() AudioPortAudio::setupWidget::setupWidget( QWidget * _parent ) : - AudioDevice::setupWidget( AudioPortAudio::name(), _parent ) + AudioDeviceSetupWidget( AudioPortAudio::name(), _parent ) { m_backend = new ComboBox( this, "BACKEND" ); m_backend->setGeometry( 64, 15, 260, 20 ); diff --git a/src/gui/AudioAlsaSetupWidget.cpp b/src/gui/AudioAlsaSetupWidget.cpp index 0e83922e4..43fe828f3 100644 --- a/src/gui/AudioAlsaSetupWidget.cpp +++ b/src/gui/AudioAlsaSetupWidget.cpp @@ -29,8 +29,6 @@ #ifdef LMMS_HAVE_ALSA -#include "AudioAlsa.h" - #include "ConfigManager.h" #include "LcdSpinBox.h" #include "gui_templates.h" diff --git a/src/gui/AudioDeviceSetupWidget.cpp b/src/gui/AudioDeviceSetupWidget.cpp new file mode 100644 index 000000000..85515aab9 --- /dev/null +++ b/src/gui/AudioDeviceSetupWidget.cpp @@ -0,0 +1,41 @@ +/* + * AudioDeviceSetupWidget.cpp - Base class for audio device setup widgets + * + * Copyright (c) 2004-2015 Tobias Doerffel + * + * This file is part of LMMS - http://lmms.io + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public + * License along with this program (see COPYING); if not, write to the + * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301 USA. + * + */ + +#include "AudioDeviceSetupWidget.h" + +AudioDeviceSetupWidget::AudioDeviceSetupWidget( const QString & _caption, QWidget * _parent ) : + TabWidget( TabWidget::tr( "Settings for %1" ).arg(TabWidget::tr( _caption.toLatin1() ) ).toUpper(), + _parent ) +{ +} + +AudioDeviceSetupWidget::~AudioDeviceSetupWidget() +{ +} + +void AudioDeviceSetupWidget::show() +{ + parentWidget()->show(); + QWidget::show(); +} diff --git a/src/gui/CMakeLists.txt b/src/gui/CMakeLists.txt index bfe43f15c..00f9f6296 100644 --- a/src/gui/CMakeLists.txt +++ b/src/gui/CMakeLists.txt @@ -3,6 +3,7 @@ SET(LMMS_SRCS gui/AboutDialog.cpp gui/ActionGroup.cpp gui/AudioAlsaSetupWidget.cpp + gui/AudioDeviceSetupWidget.cpp gui/AutomatableModelView.cpp gui/AutomationPatternView.cpp gui/ControllerConnectionDialog.cpp