kmixer: stub widgets

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2022-03-06 16:41:26 +02:00
parent 5bea5abf8f
commit 6ab8d47451
5 changed files with 159 additions and 37 deletions

View file

@ -18,6 +18,7 @@ include_directories(${ALSA_INCLUDE_DIR})
set(kmixer_sources
kmixer.cpp
kmixerwidgets.cpp
)
add_executable(kmixer ${kmixer_sources})

View file

@ -17,6 +17,7 @@
*/
#include "kmixer.h"
#include "kmixerwidgets.h"
#include <KAboutData>
#include <KCmdLineArgs>
@ -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<KSoundCard> KMixer::soundCards() const
{
if (!m_backend) {
return QList<KSoundCard>();
}
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();

View file

@ -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<KSoundCard> soundCards() const;
public Q_SLOTS:
void slotBackend();

73
kmixer/kmixerwidgets.cpp Normal file
View file

@ -0,0 +1,73 @@
/* This file is part of KMixer
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
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 <KDebug>
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"

60
kmixer/kmixerwidgets.h Normal file
View file

@ -0,0 +1,60 @@
/* This file is part of KMixer
Copyright (C) 2022 Ivailo Monev <xakepa10@gmail.com>
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 <QTabWidget>
#include <QMainWindow>
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