mirror of
https://bitbucket.org/smil3y/kde-playground.git
synced 2025-02-23 18:32:51 +00:00
kmixer: stub widgets
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
5bea5abf8f
commit
6ab8d47451
5 changed files with 159 additions and 37 deletions
|
@ -18,6 +18,7 @@ include_directories(${ALSA_INCLUDE_DIR})
|
||||||
|
|
||||||
set(kmixer_sources
|
set(kmixer_sources
|
||||||
kmixer.cpp
|
kmixer.cpp
|
||||||
|
kmixerwidgets.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
add_executable(kmixer ${kmixer_sources})
|
add_executable(kmixer ${kmixer_sources})
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "kmixer.h"
|
#include "kmixer.h"
|
||||||
|
#include "kmixerwidgets.h"
|
||||||
|
|
||||||
#include <KAboutData>
|
#include <KAboutData>
|
||||||
#include <KCmdLineArgs>
|
#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 alsaid = QString::number(snd_mixer_selem_get_index(alsaelement));
|
||||||
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
||||||
if (alsaid == channel->id() && alsaname == channel->name()) {
|
if (alsaid == channel->id() && alsaname == channel->name()) {
|
||||||
kDebug() << "Device" << channel->id() << channel->name();
|
kDebug() << "Channel" << channel->id() << channel->name();
|
||||||
long alsaplaybackvolume = 0;
|
long alsaplaybackvolume = 0;
|
||||||
m_alsaresult = snd_mixer_selem_get_playback_volume(alsaelement, alsachanneltype, &alsaplaybackvolume);
|
m_alsaresult = snd_mixer_selem_get_playback_volume(alsaelement, alsachanneltype, &alsaplaybackvolume);
|
||||||
if (m_alsaresult != 0) {
|
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 alsaid = QString::number(snd_mixer_selem_get_index(alsaelement));
|
||||||
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
||||||
if (alsaid == channel->id() && alsaname == channel->name()) {
|
if (alsaid == channel->id() && alsaname == channel->name()) {
|
||||||
kDebug() << "Device" << channel->id() << channel->name();
|
kDebug() << "Channel" << channel->id() << channel->name();
|
||||||
long alsaplaybackvolumemin = 0;
|
long alsaplaybackvolumemin = 0;
|
||||||
long alsaplaybackvolumemax = 0;
|
long alsaplaybackvolumemax = 0;
|
||||||
m_alsaresult = snd_mixer_selem_get_playback_volume_range(alsaelement, &alsaplaybackvolumemin, &alsaplaybackvolumemax);
|
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 alsaid = QString::number(snd_mixer_selem_get_index(alsaelement));
|
||||||
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
||||||
if (alsaid == channel->id() && alsaname == channel->name()) {
|
if (alsaid == channel->id() && alsaname == channel->name()) {
|
||||||
kDebug() << "Device" << channel->id() << channel->name();
|
kDebug() << "Channel" << channel->id() << channel->name();
|
||||||
long alsacapturevolume = 0;
|
long alsacapturevolume = 0;
|
||||||
m_alsaresult = snd_mixer_selem_get_capture_volume(alsaelement, alsachanneltype, &alsacapturevolume);
|
m_alsaresult = snd_mixer_selem_get_capture_volume(alsaelement, alsachanneltype, &alsacapturevolume);
|
||||||
if (m_alsaresult != 0) {
|
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 alsaid = QString::number(snd_mixer_selem_get_index(alsaelement));
|
||||||
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
const QString alsaname = QString::fromLocal8Bit(snd_mixer_selem_get_name(alsaelement));
|
||||||
if (alsaid == channel->id() && alsaname == channel->name()) {
|
if (alsaid == channel->id() && alsaname == channel->name()) {
|
||||||
kDebug() << "Device" << channel->id() << channel->name();
|
kDebug() << "Channel" << channel->id() << channel->name();
|
||||||
long alsacapturevolumemin = 0;
|
long alsacapturevolumemin = 0;
|
||||||
long alsacapturevolumemax = 0;
|
long alsacapturevolumemax = 0;
|
||||||
m_alsaresult = snd_mixer_selem_get_capture_volume_range(alsaelement, &alsacapturevolumemin, &alsacapturevolumemax);
|
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") {
|
if (backend == "alsa") {
|
||||||
m_backend = new KALSABackend(this);
|
m_backend = new KALSABackend(this);
|
||||||
#if 1
|
return m_backend->isAvailable();
|
||||||
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;
|
|
||||||
} else if (backend == "auto") {
|
} else if (backend == "auto") {
|
||||||
m_backend = new KALSABackend(this);
|
m_backend = new KALSABackend(this);
|
||||||
if (!m_backend->isAvailable()) {
|
return 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 false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -779,6 +753,14 @@ QString KMixer::errorString() const
|
||||||
return m_backend->errorString();
|
return m_backend->errorString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QList<KSoundCard> KMixer::soundCards() const
|
||||||
|
{
|
||||||
|
if (!m_backend) {
|
||||||
|
return QList<KSoundCard>();
|
||||||
|
}
|
||||||
|
return m_backend->soundCards();
|
||||||
|
}
|
||||||
|
|
||||||
void KMixer::slotBackend()
|
void KMixer::slotBackend()
|
||||||
{
|
{
|
||||||
qApp->quit();
|
qApp->quit();
|
||||||
|
@ -813,6 +795,7 @@ int main(int argc, char** argv)
|
||||||
kWarning() << kmixer.errorString();
|
kWarning() << kmixer.errorString();
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
KMixerWindow kmixerwin(nullptr, &kmixer);
|
||||||
qDebug() << "kmixer running, backend is" << args->getOption("backend");
|
qDebug() << "kmixer running, backend is" << args->getOption("backend");
|
||||||
|
|
||||||
return kmixerapp->exec();
|
return kmixerapp->exec();
|
||||||
|
|
|
@ -28,12 +28,14 @@
|
||||||
|
|
||||||
class KMixerBackend;
|
class KMixerBackend;
|
||||||
|
|
||||||
struct KVolumeRange {
|
struct KVolumeRange
|
||||||
|
{
|
||||||
int minvolume;
|
int minvolume;
|
||||||
int maxvolume;
|
int maxvolume;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KSoundChannel {
|
class KSoundChannel
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
enum KSoundChannelType {
|
enum KSoundChannelType {
|
||||||
Unknown = 0,
|
Unknown = 0,
|
||||||
|
@ -82,7 +84,8 @@ private:
|
||||||
friend class KALSABackend;
|
friend class KALSABackend;
|
||||||
};
|
};
|
||||||
|
|
||||||
class KSoundCard {
|
class KSoundCard
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
KSoundCard();
|
KSoundCard();
|
||||||
|
|
||||||
|
@ -150,12 +153,14 @@ class KMixer : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
KMixer(QObject *parent = nullptr);
|
KMixer(QObject *parent);
|
||||||
~KMixer();
|
~KMixer();
|
||||||
|
|
||||||
bool start(const QString &backend);
|
bool start(const QString &backend);
|
||||||
QString errorString() const;
|
QString errorString() const;
|
||||||
|
|
||||||
|
QList<KSoundCard> soundCards() const;
|
||||||
|
|
||||||
public Q_SLOTS:
|
public Q_SLOTS:
|
||||||
void slotBackend();
|
void slotBackend();
|
||||||
|
|
||||||
|
|
73
kmixer/kmixerwidgets.cpp
Normal file
73
kmixer/kmixerwidgets.cpp
Normal 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
60
kmixer/kmixerwidgets.h
Normal 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
|
Loading…
Add table
Reference in a new issue