diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f0a8a569b1..afc77ba013 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -896,6 +896,14 @@ optional_source(WIN32 ${CMAKE_SOURCE_DIR}/3rdparty/tinysvcmdns ) +# Platform specific - Linux +optional_source(LINUX + SOURCES + engines/alsadevicefinder.cpp + HEADERS + engines/alsadevicefinder.h +) + # Platform specific - X11 optional_source(LINUX SOURCES widgets/osd_x11.cpp) diff --git a/src/engines/alsadevicefinder.cpp b/src/engines/alsadevicefinder.cpp new file mode 100644 index 0000000000..7b58a0594d --- /dev/null +++ b/src/engines/alsadevicefinder.cpp @@ -0,0 +1,58 @@ +/* This file is part of Clementine. + Copyright 2017, Adam Borowski + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine 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 Clementine. If not, see . +*/ + +#include + +#include "alsadevicefinder.h" + +AlsaDeviceFinder::AlsaDeviceFinder() + : DeviceFinder("alsasink") { +} + +QList AlsaDeviceFinder::ListDevices() { + QList ret; + + QFile cards("/proc/asound/cards"); + if (!cards.open(QIODevice::ReadOnly)) return ret; + +/* Syntax: + snd_iprintf(buffer, "%2i [%-15s]: %s - %s\n", + idx, + card->id, + card->driver, + card->shortname); + snd_iprintf(buffer, " %s\n", + card->longname); +*/ + QRegExp regid("^ ?(\\d{1,2}) \\[.{15}\\]: .* - .*$"); + QRegExp regln("^ (.*)\n"); + + while (1) { + QString line = cards.readLine(); + if (regid.indexIn(line) == -1) break; + line = cards.readLine(); + if (regln.indexIn(line) == -1) break; + + Device dev; + dev.description = regln.cap(1).remove(QRegExp(" at .*$")); + dev.device_property_value = QString("hw:%1").arg(regid.cap(1)); + dev.icon_name = GuessIconName(dev.description); + ret.append(dev); + } + + return ret; +} diff --git a/src/engines/alsadevicefinder.h b/src/engines/alsadevicefinder.h new file mode 100644 index 0000000000..73f90d4c2f --- /dev/null +++ b/src/engines/alsadevicefinder.h @@ -0,0 +1,31 @@ +/* This file is part of Clementine. + Copyright 2017 Adam Borowski + + Clementine 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 3 of the License, or + (at your option) any later version. + + Clementine 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 Clementine. If not, see . +*/ + +#ifndef ALSADEVICEFINDER_H +#define ALSADEVICEFINDER_H + +#include "engines/devicefinder.h" + +class AlsaDeviceFinder : public DeviceFinder { + public: + AlsaDeviceFinder(); + + virtual bool Initialise() { return true; } + virtual QList ListDevices(); +}; + +#endif // ALSADEVICEFINDER_H diff --git a/src/engines/gstengine.cpp b/src/engines/gstengine.cpp index f0d47b4e95..a59aa1a7bd 100644 --- a/src/engines/gstengine.cpp +++ b/src/engines/gstengine.cpp @@ -58,6 +58,10 @@ #include "engines/pulsedevicefinder.h" #endif +#ifdef Q_OS_LINUX +#include "engines/alsadevicefinder.h" +#endif + #ifdef Q_OS_DARWIN #include "engines/osxdevicefinder.h" #endif @@ -162,6 +166,9 @@ void GstEngine::InitialiseGstreamer() { #ifdef HAVE_LIBPULSE device_finders.append(new PulseDeviceFinder); #endif +#ifdef Q_OS_LINUX + device_finders.append(new AlsaDeviceFinder); +#endif #ifdef Q_OS_DARWIN device_finders.append(new OsxDeviceFinder); #endif