diff --git a/kmixer/CMakeLists.txt b/kmixer/CMakeLists.txt index 804a042c..d1924266 100644 --- a/kmixer/CMakeLists.txt +++ b/kmixer/CMakeLists.txt @@ -18,6 +18,7 @@ include_directories(${ALSA_INCLUDE_DIR}) set(kmixer_sources kmixer.cpp + kmixerwidgets.cpp ) add_executable(kmixer ${kmixer_sources}) diff --git a/kmixer/kmixer.cpp b/kmixer/kmixer.cpp index 0b428408..c0d7e034 100644 --- a/kmixer/kmixer.cpp +++ b/kmixer/kmixer.cpp @@ -17,6 +17,7 @@ */ #include "kmixer.h" +#include "kmixerwidgets.h" #include #include @@ -392,7 +393,7 @@ int KALSABackend::playbackVolume(const KSoundChannel *channel) const const QString alsaid = QString::number(snd_mixer_selem_get_index(alsaelement)); const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement)); if (alsaid == channel->id() && alsaname == channel->name()) { - kDebug() << "Device" << channel->id() << channel->name(); + kDebug() << "Channel" << channel->id() << channel->name(); long alsaplaybackvolume = 0; m_alsaresult = snd_mixer_selem_get_playback_volume(alsaelement, alsachanneltype, &alsaplaybackvolume); if (m_alsaresult != 0) { @@ -430,7 +431,7 @@ KVolumeRange KALSABackend::playbackRange(const KSoundChannel *channel) const const QString alsaid = QString::number(snd_mixer_selem_get_index(alsaelement)); const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement)); if (alsaid == channel->id() && alsaname == channel->name()) { - kDebug() << "Device" << channel->id() << channel->name(); + kDebug() << "Channel" << channel->id() << channel->name(); long alsaplaybackvolumemin = 0; long alsaplaybackvolumemax = 0; m_alsaresult = snd_mixer_selem_get_playback_volume_range(alsaelement, &alsaplaybackvolumemin, &alsaplaybackvolumemax); @@ -519,7 +520,7 @@ int KALSABackend::captureVolume(const KSoundChannel *channel) const const QString alsaid = QString::number(snd_mixer_selem_get_index(alsaelement)); const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement)); if (alsaid == channel->id() && alsaname == channel->name()) { - kDebug() << "Device" << channel->id() << channel->name(); + kDebug() << "Channel" << channel->id() << channel->name(); long alsacapturevolume = 0; m_alsaresult = snd_mixer_selem_get_capture_volume(alsaelement, alsachanneltype, &alsacapturevolume); if (m_alsaresult != 0) { @@ -557,7 +558,7 @@ KVolumeRange KALSABackend::captureRange(const KSoundChannel *channel) const const QString alsaid = QString::number(snd_mixer_selem_get_index(alsaelement)); const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement)); if (alsaid == channel->id() && alsaname == channel->name()) { - kDebug() << "Device" << channel->id() << channel->name(); + kDebug() << "Channel" << channel->id() << channel->name(); long alsacapturevolumemin = 0; long alsacapturevolumemax = 0; m_alsaresult = snd_mixer_selem_get_capture_volume_range(alsaelement, &alsacapturevolumemin, &alsacapturevolumemax); @@ -736,37 +737,10 @@ bool KMixer::start(const QString &backend) { if (backend == "alsa") { m_backend = new KALSABackend(this); -#if 1 - foreach (const KSoundCard &kcard, m_backend->soundCards()) { - foreach (KSoundChannel kchannel, kcard.channels()) { - qDebug() << kcard.name() << kcard.description() << kchannel.name() << kchannel.description(); - qDebug() << "Channel volume is" << kchannel.playbackVolume() << kchannel.captureVolume(); - kchannel.setPlaybackVolume(10); - kchannel.setCaptureVolume(10); - qDebug() << "Channel volume is" << kchannel.playbackVolume() << kchannel.captureVolume(); - qDebug() << "Channel volume range is" << kchannel.playbackRange().minvolume << kchannel.playbackRange().maxvolume; - } - } -#endif - return true; + return m_backend->isAvailable(); } else if (backend == "auto") { m_backend = new KALSABackend(this); - if (!m_backend->isAvailable()) { - return false; - } -#if 1 - foreach (const KSoundCard &kcard, m_backend->soundCards()) { - foreach (KSoundChannel kchannel, kcard.channels()) { - qDebug() << kcard.name() << kcard.description() << kchannel.name() << kchannel.description(); - qDebug() << "Channel volume is" << kchannel.playbackVolume() << kchannel.captureVolume(); - kchannel.setPlaybackVolume(10); - kchannel.setCaptureVolume(10); - qDebug() << "Channel volume is" << kchannel.playbackVolume() << kchannel.captureVolume(); - qDebug() << "Channel volume range is" << kchannel.playbackRange().minvolume << kchannel.playbackRange().maxvolume; - } - } -#endif - return true; + return m_backend->isAvailable(); } return false; } @@ -779,6 +753,14 @@ QString KMixer::errorString() const return m_backend->errorString(); } +QList KMixer::soundCards() const +{ + if (!m_backend) { + return QList(); + } + return m_backend->soundCards(); +} + void KMixer::slotBackend() { qApp->quit(); @@ -813,6 +795,7 @@ int main(int argc, char** argv) kWarning() << kmixer.errorString(); return 1; } + KMixerWindow kmixerwin(nullptr, &kmixer); qDebug() << "kmixer running, backend is" << args->getOption("backend"); return kmixerapp->exec(); diff --git a/kmixer/kmixer.h b/kmixer/kmixer.h index ce74afc8..cee67943 100644 --- a/kmixer/kmixer.h +++ b/kmixer/kmixer.h @@ -28,12 +28,14 @@ class KMixerBackend; -struct KVolumeRange { +struct KVolumeRange +{ int minvolume; int maxvolume; }; -class KSoundChannel { +class KSoundChannel +{ public: enum KSoundChannelType { Unknown = 0, @@ -82,7 +84,8 @@ private: friend class KALSABackend; }; -class KSoundCard { +class KSoundCard +{ public: KSoundCard(); @@ -150,12 +153,14 @@ class KMixer : public QObject { Q_OBJECT public: - KMixer(QObject *parent = nullptr); + KMixer(QObject *parent); ~KMixer(); bool start(const QString &backend); QString errorString() const; + QList soundCards() const; + public Q_SLOTS: void slotBackend(); diff --git a/kmixer/kmixerwidgets.cpp b/kmixer/kmixerwidgets.cpp new file mode 100644 index 00000000..17f34dd1 --- /dev/null +++ b/kmixer/kmixerwidgets.cpp @@ -0,0 +1,73 @@ +/* This file is part of KMixer + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "kmixer.h" +#include "kmixerwidgets.h" + +#include + +KVolumeWidget::KVolumeWidget(QWidget *parent) + : QWidget(parent) +{ +} + +KVolumeWidget::~KVolumeWidget() +{ +} + +KSoundDeviceWidget::KSoundDeviceWidget(QWidget *parent) + : QWidget(parent) +{ +} + +KSoundDeviceWidget::~KSoundDeviceWidget() +{ +} + +KSoundCardWidget::KSoundCardWidget(QTabWidget *parent) + : QTabWidget(parent) +{ +} + +KSoundCardWidget::~KSoundCardWidget() +{ +} + +KMixerWindow::KMixerWindow(QWidget *parent, const KMixer *mixer) + : QMainWindow(parent), + m_mixer(mixer) +{ +#if 1 + foreach (const KSoundCard &kcard, m_mixer->soundCards()) { + foreach (KSoundChannel kchannel, kcard.channels()) { + qDebug() << kcard.name() << kcard.description() << kchannel.name() << kchannel.description(); + qDebug() << "Channel volume is" << kchannel.playbackVolume() << kchannel.captureVolume(); + kchannel.setPlaybackVolume(10); + kchannel.setCaptureVolume(10); + qDebug() << "Channel volume is" << kchannel.playbackVolume() << kchannel.captureVolume(); + qDebug() << "Channel volume range is" << kchannel.playbackRange().minvolume << kchannel.playbackRange().maxvolume; + } + } +#endif +} + +KMixerWindow::~KMixerWindow() +{ +} + +#include "moc_kmixerwidgets.cpp" diff --git a/kmixer/kmixerwidgets.h b/kmixer/kmixerwidgets.h new file mode 100644 index 00000000..9bc37007 --- /dev/null +++ b/kmixer/kmixerwidgets.h @@ -0,0 +1,60 @@ +/* This file is part of KMixer + Copyright (C) 2022 Ivailo Monev + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2, as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KMIXERWIDGETS_H +#define KMIXERWIDGETS_H + +#include +#include + +class KVolumeWidget : public QWidget +{ + Q_OBJECT +public: + KVolumeWidget(QWidget *parent); + ~KVolumeWidget(); +}; + +class KSoundDeviceWidget : public QWidget +{ + Q_OBJECT +public: + KSoundDeviceWidget(QWidget *parent); + ~KSoundDeviceWidget(); +}; + +class KSoundCardWidget : public QTabWidget +{ + Q_OBJECT +public: + KSoundCardWidget(QTabWidget *parent); + ~KSoundCardWidget(); +}; + +class KMixerWindow : public QMainWindow +{ + Q_OBJECT +public: + KMixerWindow(QWidget *parent, const KMixer *mixer); + ~KMixerWindow(); + +private: + const KMixer *m_mixer; +}; + +#endif // KMIXERWIDGETS_H