refactor: adjust code to our clang-tidy
This commit is contained in:
parent
f471ba7f06
commit
5e0861d397
@ -44,4 +44,8 @@ Checks: "*,\
|
|||||||
-modernize-avoid-c-arrays,\
|
-modernize-avoid-c-arrays,\
|
||||||
-cppcoreguidelines-avoid-c-arrays,\
|
-cppcoreguidelines-avoid-c-arrays,\
|
||||||
-cert-env33-c,\
|
-cert-env33-c,\
|
||||||
-abseil-*"
|
-abseil-*,\
|
||||||
|
-fuchsia-default-arguments-declarations,\
|
||||||
|
-readability-redundant-access-specifiers,\
|
||||||
|
-readability-convert-member-functions-to-static,\
|
||||||
|
-readability-implicit-bool-conversion"
|
@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <qlist.h>
|
#include <qlist.h>
|
||||||
|
#include <utility>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
@ -15,7 +16,7 @@ struct QPulseAudioRecordingStream
|
|||||||
public:
|
public:
|
||||||
void setInstance(Soundux::Playback::internal::PulseAudioRecordingStream instance)
|
void setInstance(Soundux::Playback::internal::PulseAudioRecordingStream instance)
|
||||||
{
|
{
|
||||||
this->instance = instance;
|
this->instance = std::move(instance);
|
||||||
}
|
}
|
||||||
Q_INVOKABLE QString getName() const
|
Q_INVOKABLE QString getName() const
|
||||||
{
|
{
|
||||||
@ -41,7 +42,7 @@ struct QSound
|
|||||||
public:
|
public:
|
||||||
void setInstance(Soundux::Config::Sound instance)
|
void setInstance(Soundux::Config::Sound instance)
|
||||||
{
|
{
|
||||||
this->instance = instance;
|
this->instance = std::move(instance);
|
||||||
}
|
}
|
||||||
Soundux::Config::Sound getInstance() const
|
Soundux::Config::Sound getInstance() const
|
||||||
{
|
{
|
||||||
@ -80,7 +81,7 @@ struct QTab
|
|||||||
public:
|
public:
|
||||||
void setInstance(Soundux::Config::Tab instance)
|
void setInstance(Soundux::Config::Tab instance)
|
||||||
{
|
{
|
||||||
this->instance = instance;
|
this->instance = std::move(instance);
|
||||||
}
|
}
|
||||||
Soundux::Config::Tab getInstance() const
|
Soundux::Config::Tab getInstance() const
|
||||||
{
|
{
|
||||||
@ -96,7 +97,7 @@ struct QTab
|
|||||||
}
|
}
|
||||||
Q_INVOKABLE std::vector<QSound> getSounds() const
|
Q_INVOKABLE std::vector<QSound> getSounds() const
|
||||||
{
|
{
|
||||||
auto &sounds = instance.sounds;
|
const auto &sounds = instance.sounds;
|
||||||
|
|
||||||
std::vector<QSound> qSounds;
|
std::vector<QSound> qSounds;
|
||||||
for (const auto &sound : sounds)
|
for (const auto &sound : sounds)
|
||||||
|
@ -13,7 +13,7 @@ namespace Soundux
|
|||||||
{
|
{
|
||||||
namespace Config
|
namespace Config
|
||||||
{
|
{
|
||||||
using namespace nlohmann;
|
using nlohmann::json;
|
||||||
|
|
||||||
struct Sound
|
struct Sound
|
||||||
{
|
{
|
||||||
@ -22,11 +22,11 @@ namespace Soundux
|
|||||||
std::vector<int> hotKeys;
|
std::vector<int> hotKeys;
|
||||||
std::uint64_t lastWriteTime;
|
std::uint64_t lastWriteTime;
|
||||||
|
|
||||||
bool operator==(const std::string &path)
|
bool operator==(const std::string &path) const
|
||||||
{
|
{
|
||||||
return path == this->path;
|
return path == this->path;
|
||||||
}
|
}
|
||||||
bool operator==(const Sound &other)
|
bool operator==(const Sound &other) const
|
||||||
{
|
{
|
||||||
return other.name == name && other.path == path;
|
return other.name == name && other.path == path;
|
||||||
}
|
}
|
||||||
@ -37,7 +37,7 @@ namespace Soundux
|
|||||||
std::string folder;
|
std::string folder;
|
||||||
std::vector<Sound> sounds;
|
std::vector<Sound> sounds;
|
||||||
|
|
||||||
bool operator==(const Tab &other)
|
bool operator==(const Tab &other) const
|
||||||
{
|
{
|
||||||
return other.folder == folder && other.title == title;
|
return other.folder == folder && other.title == title;
|
||||||
}
|
}
|
||||||
@ -84,7 +84,9 @@ namespace Soundux
|
|||||||
j.at("hotKeys").get_to(sound.hotKeys);
|
j.at("hotKeys").get_to(sound.hotKeys);
|
||||||
|
|
||||||
if (j.contains("lastWriteTime"))
|
if (j.contains("lastWriteTime"))
|
||||||
|
{
|
||||||
j.at("lastWriteTime").get_to(sound.lastWriteTime);
|
j.at("lastWriteTime").get_to(sound.lastWriteTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void to_json(json &j, const Tab &tab)
|
inline void to_json(json &j, const Tab &tab)
|
||||||
@ -121,13 +123,21 @@ namespace Soundux
|
|||||||
j.at("tabHotkeysOnly").get_to(config.tabHotkeysOnly);
|
j.at("tabHotkeysOnly").get_to(config.tabHotkeysOnly);
|
||||||
|
|
||||||
if (j.contains("volumes"))
|
if (j.contains("volumes"))
|
||||||
|
{
|
||||||
j.at("volumes").get_to(config.volumes);
|
j.at("volumes").get_to(config.volumes);
|
||||||
|
}
|
||||||
if (j.contains("width"))
|
if (j.contains("width"))
|
||||||
|
{
|
||||||
j.at("width").get_to(config.width);
|
j.at("width").get_to(config.width);
|
||||||
|
}
|
||||||
if (j.contains("height"))
|
if (j.contains("height"))
|
||||||
|
{
|
||||||
j.at("height").get_to(config.height);
|
j.at("height").get_to(config.height);
|
||||||
|
}
|
||||||
if (j.contains("allowOverlapping"))
|
if (j.contains("allowOverlapping"))
|
||||||
|
{
|
||||||
j.at("allowOverlapping").get_to(config.allowOverlapping);
|
j.at("allowOverlapping").get_to(config.allowOverlapping);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void loadConfig()
|
inline void loadConfig()
|
||||||
|
10
src/core.cpp
10
src/core.cpp
@ -4,10 +4,10 @@
|
|||||||
#include "hotkeys/global.h"
|
#include "hotkeys/global.h"
|
||||||
#include "playback/global.h"
|
#include "playback/global.h"
|
||||||
#include "playback/linux.h"
|
#include "playback/linux.h"
|
||||||
#include <filesystem>
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <filesystem>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ void Core::addFolderTab(QUrl folder)
|
|||||||
|
|
||||||
void Core::updateFolderSounds(QTab qTab)
|
void Core::updateFolderSounds(QTab qTab)
|
||||||
{
|
{
|
||||||
// TODO: fix that the previously selected item is selected afterwards when it's still there
|
// TODO(d3s0x): fix that the previously selected item is selected afterwards when it's still there
|
||||||
auto instance = qTab.getInstance();
|
auto instance = qTab.getInstance();
|
||||||
for (auto &tab : Soundux::Config::gConfig.tabs)
|
for (auto &tab : Soundux::Config::gConfig.tabs)
|
||||||
{
|
{
|
||||||
@ -310,7 +310,7 @@ void Core::playSound(std::string path)
|
|||||||
}
|
}
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
static std::string moveBackCmd;
|
static std::string moveBackCmd;
|
||||||
auto sinkMonitorId = "TODO";
|
const auto *sinkMonitorId = "TODO";
|
||||||
|
|
||||||
auto outputApp = Soundux::Playback::getCurrentOutputApplication();
|
auto outputApp = Soundux::Playback::getCurrentOutputApplication();
|
||||||
|
|
||||||
@ -350,12 +350,12 @@ void Core::playSound(std::string path)
|
|||||||
|
|
||||||
void Core::changeLocalVolume(int volume)
|
void Core::changeLocalVolume(int volume)
|
||||||
{
|
{
|
||||||
Soundux::Playback::setVolume(Soundux::Playback::defaultPlayback.name, volume / 100.f);
|
Soundux::Playback::setVolume(Soundux::Playback::defaultPlayback.name, volume / 100.F);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::changeRemoteVolume(int volume)
|
void Core::changeRemoteVolume(int volume)
|
||||||
{
|
{
|
||||||
Soundux::Playback::setVolume(sink.name, volume / 100.f);
|
Soundux::Playback::setVolume(sink.name, volume / 100.F);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Core::stopPlayback()
|
void Core::stopPlayback()
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <QObject>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <qglobal.h>
|
#include <qglobal.h>
|
||||||
#include <QObject>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
@ -25,7 +25,7 @@ class Core : public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit Core(QObject * = 0);
|
explicit Core(QObject * = nullptr);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setEngine(QQmlApplicationEngine *);
|
void setEngine(QQmlApplicationEngine *);
|
||||||
|
@ -12,8 +12,10 @@ void Soundux::Hooks::internal::onKeyEvent(int key, bool down)
|
|||||||
for (auto keyState : capturedKeyStates)
|
for (auto keyState : capturedKeyStates)
|
||||||
{
|
{
|
||||||
if (keyState.second.first)
|
if (keyState.second.first)
|
||||||
|
{
|
||||||
pressedStates.push_back(
|
pressedStates.push_back(
|
||||||
std::make_tuple(keyState.first, keyState.second.first, keyState.second.second));
|
std::make_tuple(keyState.first, keyState.second.first, keyState.second.second));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pressedStates.push_back(std::make_tuple(key, down, std::chrono::system_clock::now()));
|
pressedStates.push_back(std::make_tuple(key, down, std::chrono::system_clock::now()));
|
||||||
@ -85,7 +87,7 @@ void Soundux::Hooks::internal::onKeyEvent(int key, bool down)
|
|||||||
for (const auto &sound : tab.sounds)
|
for (const auto &sound : tab.sounds)
|
||||||
{
|
{
|
||||||
bool allPressed = !sound.hotKeys.empty();
|
bool allPressed = !sound.hotKeys.empty();
|
||||||
for (auto &hotKey : sound.hotKeys)
|
for (const auto &hotKey : sound.hotKeys)
|
||||||
{
|
{
|
||||||
if (!pressedKeys[hotKey])
|
if (!pressedKeys[hotKey])
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "../config/config.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include "../config/config.h"
|
|
||||||
|
|
||||||
namespace Soundux
|
namespace Soundux
|
||||||
{
|
{
|
||||||
namespace Hooks
|
namespace Hooks
|
||||||
{
|
{
|
||||||
// Defined by linux/windows.h
|
// Defined by linux/windows.h
|
||||||
std::string getKeyName(const int key);
|
std::string getKeyName(int key);
|
||||||
|
|
||||||
namespace internal
|
namespace internal
|
||||||
{
|
{
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <atomic>
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include <iostream>
|
|
||||||
#include <X11/XKBlib.h>
|
#include <X11/XKBlib.h>
|
||||||
#include <X11/extensions/XI2.h>
|
#include <X11/extensions/XI2.h>
|
||||||
#include <X11/extensions/XInput2.h>
|
#include <X11/extensions/XInput2.h>
|
||||||
|
#include <atomic>
|
||||||
|
#include <chrono>
|
||||||
|
#include <iostream>
|
||||||
|
#include <thread>
|
||||||
|
|
||||||
namespace Soundux
|
namespace Soundux
|
||||||
{
|
{
|
||||||
@ -22,7 +22,7 @@ namespace Soundux
|
|||||||
const char *displayenv = std::getenv("DISPLAY");
|
const char *displayenv = std::getenv("DISPLAY");
|
||||||
Display *x11display = XOpenDisplay(displayenv);
|
Display *x11display = XOpenDisplay(displayenv);
|
||||||
|
|
||||||
if (x11display == NULL)
|
if (x11display == nullptr)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to get X11-Display with value provided by environment variable(" << displayenv
|
std::cerr << "Failed to get X11-Display with value provided by environment variable(" << displayenv
|
||||||
<< "), falling back "
|
<< "), falling back "
|
||||||
@ -31,7 +31,7 @@ namespace Soundux
|
|||||||
x11display = XOpenDisplay(":0");
|
x11display = XOpenDisplay(":0");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (x11display == NULL)
|
if (x11display == nullptr)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open X11 Display" << std::endl;
|
std::cerr << "Failed to open X11 Display" << std::endl;
|
||||||
return nullptr;
|
return nullptr;
|
||||||
@ -41,8 +41,11 @@ namespace Soundux
|
|||||||
|
|
||||||
inline void hook()
|
inline void hook()
|
||||||
{
|
{
|
||||||
int xiOpCode, queryEvent, queryError;
|
int xiOpCode = 0;
|
||||||
if (!XQueryExtension(display, "XInputExtension", &xiOpCode, &queryEvent, &queryError))
|
int queryEvent = 0;
|
||||||
|
int queryError = 0;
|
||||||
|
|
||||||
|
if (XQueryExtension(display, "XInputExtension", &xiOpCode, &queryEvent, &queryError) == 0)
|
||||||
{
|
{
|
||||||
std::cerr << "XInput extension is not aviable" << std::endl;
|
std::cerr << "XInput extension is not aviable" << std::endl;
|
||||||
return;
|
return;
|
||||||
@ -50,15 +53,17 @@ namespace Soundux
|
|||||||
|
|
||||||
// Custom context
|
// Custom context
|
||||||
{
|
{
|
||||||
int major = 2, minor = 0;
|
int major = 2;
|
||||||
|
int minor = 0;
|
||||||
int queryResult = XIQueryVersion(display, &major, &minor);
|
int queryResult = XIQueryVersion(display, &major, &minor);
|
||||||
|
|
||||||
if (queryResult == BadRequest)
|
if (queryResult == BadRequest)
|
||||||
{
|
{
|
||||||
std::cerr << "XI 2.0 support is required - Current Version: " << major << "." << minor
|
std::cerr << "XI 2.0 support is required - Current Version: " << major << "." << minor
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (queryResult != Success)
|
if (queryResult != Success)
|
||||||
{
|
{
|
||||||
std::cerr << "Unknown error" << std::endl;
|
std::cerr << "Unknown error" << std::endl;
|
||||||
return;
|
return;
|
||||||
@ -69,29 +74,29 @@ namespace Soundux
|
|||||||
XIEventMask mask;
|
XIEventMask mask;
|
||||||
mask.deviceid = XIAllMasterDevices;
|
mask.deviceid = XIAllMasterDevices;
|
||||||
mask.mask_len = XIMaskLen(XI_LASTEVENT);
|
mask.mask_len = XIMaskLen(XI_LASTEVENT);
|
||||||
mask.mask = (unsigned char *)calloc(mask.mask_len, sizeof(char));
|
mask.mask = static_cast<unsigned char *>(calloc(mask.mask_len, sizeof(char)));
|
||||||
|
|
||||||
XISetMask(mask.mask, XI_RawKeyPress);
|
XISetMask(mask.mask, XI_RawKeyPress);
|
||||||
XISetMask(mask.mask, XI_RawKeyRelease);
|
XISetMask(mask.mask, XI_RawKeyRelease);
|
||||||
XISelectEvents(display, root, &mask, 1);
|
XISelectEvents(display, root, &mask, 1);
|
||||||
XSync(display, false);
|
XSync(display, 0);
|
||||||
free(mask.mask);
|
free(mask.mask);
|
||||||
|
|
||||||
while (!killThread.load())
|
while (!killThread.load())
|
||||||
{
|
{
|
||||||
while (!killThread.load())
|
while (!killThread.load())
|
||||||
{
|
{
|
||||||
if (XPending(display))
|
if (XPending(display) != 0)
|
||||||
{
|
{
|
||||||
XEvent event;
|
XEvent event;
|
||||||
XNextEvent(display, &event);
|
XNextEvent(display, &event);
|
||||||
XGenericEventCookie *cookie = reinterpret_cast<XGenericEventCookie *>(&event.xcookie);
|
auto *cookie = reinterpret_cast<XGenericEventCookie *>(&event.xcookie);
|
||||||
|
|
||||||
if (XGetEventData(display, cookie) && cookie->type == GenericEvent &&
|
if ((XGetEventData(display, cookie) != 0) && cookie->type == GenericEvent &&
|
||||||
cookie->extension == xiOpCode &&
|
cookie->extension == xiOpCode &&
|
||||||
(cookie->evtype == XI_RawKeyRelease || cookie->evtype == XI_RawKeyPress))
|
(cookie->evtype == XI_RawKeyRelease || cookie->evtype == XI_RawKeyPress))
|
||||||
{
|
{
|
||||||
XIRawEvent *ev = reinterpret_cast<XIRawEvent *>(cookie->data);
|
auto *ev = reinterpret_cast<XIRawEvent *>(cookie->data);
|
||||||
auto key = ev->detail;
|
auto key = ev->detail;
|
||||||
|
|
||||||
internal::onKeyEvent(key, cookie->evtype == XI_RawKeyPress);
|
internal::onKeyEvent(key, cookie->evtype == XI_RawKeyPress);
|
||||||
@ -120,11 +125,15 @@ namespace Soundux
|
|||||||
{
|
{
|
||||||
KeySym s = XkbKeycodeToKeysym(internal::display, key, 0, 0);
|
KeySym s = XkbKeycodeToKeysym(internal::display, key, 0, 0);
|
||||||
if (NoSymbol == s)
|
if (NoSymbol == s)
|
||||||
|
{
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
char *str = XKeysymToString(s);
|
char *str = XKeysymToString(s);
|
||||||
if (str == nullptr)
|
if (str == nullptr)
|
||||||
|
{
|
||||||
return "Unknown";
|
return "Unknown";
|
||||||
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#include <QQmlApplicationEngine>
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QQuickStyle>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QQmlContext>
|
#include <QQmlContext>
|
||||||
|
#include <QQuickStyle>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <qqml.h>
|
#include <qqml.h>
|
||||||
@ -9,9 +9,9 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
#include "bindings/bindings.h"
|
||||||
#include "config/config.h"
|
#include "config/config.h"
|
||||||
#include "playback/global.h"
|
#include "playback/global.h"
|
||||||
#include "bindings/bindings.h"
|
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include "hotkeys/windows.h"
|
#include "hotkeys/windows.h"
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <miniaudio.h>
|
|
||||||
#include <functional>
|
|
||||||
#include <exception>
|
|
||||||
#include <iostream>
|
|
||||||
#include <vector>
|
|
||||||
#include <thread>
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <exception>
|
||||||
|
#include <functional>
|
||||||
|
#include <iostream>
|
||||||
|
#include <map>
|
||||||
|
#include <map>
|
||||||
|
#include <miniaudio.h>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <map>
|
#include <thread>
|
||||||
#include <map>
|
#include <vector>
|
||||||
|
|
||||||
namespace Soundux
|
namespace Soundux
|
||||||
{
|
{
|
||||||
@ -51,7 +51,7 @@ namespace Soundux
|
|||||||
std::uint64_t playAudio(const std::string &file, const ma_device_info &deviceInfo);
|
std::uint64_t playAudio(const std::string &file, const ma_device_info &deviceInfo);
|
||||||
|
|
||||||
void stop(const std::uint64_t &deviceId);
|
void stop(const std::uint64_t &deviceId);
|
||||||
inline std::function<void(const internal::PlayingDevice &)> stopCallback = [](const auto &) {};
|
inline std::function<void(const internal::PlayingDevice &)> stopCallback = [](const auto &device) {};
|
||||||
|
|
||||||
void pause(const std::uint64_t &deviceId);
|
void pause(const std::uint64_t &deviceId);
|
||||||
|
|
||||||
@ -78,7 +78,9 @@ namespace Soundux
|
|||||||
{
|
{
|
||||||
auto &device = currentlyPlayingDevices.at(i);
|
auto &device = currentlyPlayingDevices.at(i);
|
||||||
if (device.device != sound->first)
|
if (device.device != sound->first)
|
||||||
|
{
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
stop(device.id);
|
stop(device.id);
|
||||||
}
|
}
|
||||||
playingDeviceMutex.unlock();
|
playingDeviceMutex.unlock();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
|
#include "global.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#define MINIAUDIO_IMPLEMENTATION
|
#define MINIAUDIO_IMPLEMENTATION
|
||||||
#include <miniaudio.h>
|
#include <miniaudio.h>
|
||||||
#include "global.h"
|
|
||||||
|
|
||||||
namespace Soundux
|
namespace Soundux
|
||||||
{
|
{
|
||||||
@ -9,7 +9,7 @@ namespace Soundux
|
|||||||
{
|
{
|
||||||
ma_device device;
|
ma_device device;
|
||||||
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
|
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_playback);
|
||||||
ma_device_init(0, &deviceConfig, &device);
|
ma_device_init(nullptr, &deviceConfig, &device);
|
||||||
|
|
||||||
Playback::internal::DefaultDevice playbackInfo;
|
Playback::internal::DefaultDevice playbackInfo;
|
||||||
playbackInfo.name = device.playback.name;
|
playbackInfo.name = device.playback.name;
|
||||||
@ -22,7 +22,7 @@ namespace Soundux
|
|||||||
{
|
{
|
||||||
ma_device device;
|
ma_device device;
|
||||||
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_capture);
|
ma_device_config deviceConfig = ma_device_config_init(ma_device_type_capture);
|
||||||
ma_device_init(0, &deviceConfig, &device);
|
ma_device_init(nullptr, &deviceConfig, &device);
|
||||||
|
|
||||||
Playback::internal::DefaultDevice captureInfo;
|
Playback::internal::DefaultDevice captureInfo;
|
||||||
captureInfo.name = device.capture.name;
|
captureInfo.name = device.capture.name;
|
||||||
@ -35,16 +35,16 @@ namespace Soundux
|
|||||||
{
|
{
|
||||||
ma_context context;
|
ma_context context;
|
||||||
|
|
||||||
if (ma_context_init(0, 0, 0, &context) != MA_SUCCESS)
|
if (ma_context_init(nullptr, 0, nullptr, &context) != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to initialize context" << std::endl;
|
std::cerr << "Failed to initialize context" << std::endl;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_device_info *pPlayBackDeviceInfos;
|
ma_device_info *pPlayBackDeviceInfos{};
|
||||||
ma_uint32 deviceCount;
|
ma_uint32 deviceCount{};
|
||||||
|
|
||||||
ma_result result = ma_context_get_devices(&context, &pPlayBackDeviceInfos, &deviceCount, 0, 0);
|
ma_result result = ma_context_get_devices(&context, &pPlayBackDeviceInfos, &deviceCount, nullptr, nullptr);
|
||||||
if (result != MA_SUCCESS)
|
if (result != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to get playback devices!" << std::endl;
|
std::cerr << "Failed to get playback devices!" << std::endl;
|
||||||
@ -65,16 +65,16 @@ namespace Soundux
|
|||||||
{
|
{
|
||||||
ma_context context;
|
ma_context context;
|
||||||
|
|
||||||
if (ma_context_init(0, 0, 0, &context) != MA_SUCCESS)
|
if (ma_context_init(nullptr, 0, nullptr, &context) != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to initialize context" << std::endl;
|
std::cerr << "Failed to initialize context" << std::endl;
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_device_info *pCaptureDeviceInfos;
|
ma_device_info *pCaptureDeviceInfos{};
|
||||||
ma_uint32 deviceCount;
|
ma_uint32 deviceCount{};
|
||||||
|
|
||||||
ma_result result = ma_context_get_devices(&context, &pCaptureDeviceInfos, &deviceCount, 0, 0);
|
ma_result result = ma_context_get_devices(&context, &pCaptureDeviceInfos, &deviceCount, nullptr, nullptr);
|
||||||
if (result != MA_SUCCESS)
|
if (result != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to get playback devices!" << std::endl;
|
std::cerr << "Failed to get playback devices!" << std::endl;
|
||||||
@ -102,10 +102,12 @@ namespace Soundux
|
|||||||
//? Theoretically we could remove this, but this will result in the defaultPlayBackVolume being 0. This will
|
//? Theoretically we could remove this, but this will result in the defaultPlayBackVolume being 0. This will
|
||||||
//? only change when the user manually changes this value in the ui where the default value will not match.
|
//? only change when the user manually changes this value in the ui where the default value will not match.
|
||||||
if (usedDevices.find(defaultPlayback.name) == usedDevices.end())
|
if (usedDevices.find(defaultPlayback.name) == usedDevices.end())
|
||||||
usedDevices.insert(std::make_pair(defaultPlayback.name, 1.f));
|
{
|
||||||
|
usedDevices.insert(std::make_pair(defaultPlayback.name, 1.F));
|
||||||
|
}
|
||||||
|
|
||||||
ma_decoder *decoder = new ma_decoder;
|
auto *decoder = new ma_decoder;
|
||||||
ma_result result = ma_decoder_init_file(file.c_str(), 0, decoder);
|
ma_result result = ma_decoder_init_file(file.c_str(), nullptr, decoder);
|
||||||
|
|
||||||
if (result != MA_SUCCESS)
|
if (result != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
@ -113,7 +115,7 @@ namespace Soundux
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_device *device = new ma_device;
|
auto *device = new ma_device;
|
||||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||||
config.playback.format = decoder->outputFormat;
|
config.playback.format = decoder->outputFormat;
|
||||||
config.playback.channels = decoder->outputChannels;
|
config.playback.channels = decoder->outputChannels;
|
||||||
@ -121,7 +123,7 @@ namespace Soundux
|
|||||||
config.dataCallback = internal::data_callback;
|
config.dataCallback = internal::data_callback;
|
||||||
config.pUserData = decoder;
|
config.pUserData = decoder;
|
||||||
|
|
||||||
if (ma_device_init(0, &config, device) != MA_SUCCESS)
|
if (ma_device_init(nullptr, &config, device) != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open playback device" << std::endl;
|
std::cerr << "Failed to open playback device" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
@ -145,10 +147,12 @@ namespace Soundux
|
|||||||
static std::uint64_t counter = 0;
|
static std::uint64_t counter = 0;
|
||||||
|
|
||||||
if (usedDevices.find(deviceInfo.name) == usedDevices.end())
|
if (usedDevices.find(deviceInfo.name) == usedDevices.end())
|
||||||
usedDevices.insert(std::make_pair(deviceInfo.name, 1.f));
|
{
|
||||||
|
usedDevices.insert(std::make_pair(deviceInfo.name, 1.F));
|
||||||
|
}
|
||||||
|
|
||||||
ma_decoder *decoder = new ma_decoder;
|
auto *decoder = new ma_decoder;
|
||||||
ma_result result = ma_decoder_init_file(file.c_str(), 0, decoder);
|
ma_result result = ma_decoder_init_file(file.c_str(), nullptr, decoder);
|
||||||
|
|
||||||
if (result != MA_SUCCESS)
|
if (result != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
@ -156,7 +160,7 @@ namespace Soundux
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ma_device *device = new ma_device;
|
auto *device = new ma_device;
|
||||||
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
ma_device_config config = ma_device_config_init(ma_device_type_playback);
|
||||||
config.playback.format = decoder->outputFormat;
|
config.playback.format = decoder->outputFormat;
|
||||||
config.playback.channels = decoder->outputChannels;
|
config.playback.channels = decoder->outputChannels;
|
||||||
@ -165,7 +169,7 @@ namespace Soundux
|
|||||||
config.playback.pDeviceID = &deviceInfo.id;
|
config.playback.pDeviceID = &deviceInfo.id;
|
||||||
config.pUserData = decoder;
|
config.pUserData = decoder;
|
||||||
|
|
||||||
if (ma_device_init(0, &config, device) != MA_SUCCESS)
|
if (ma_device_init(nullptr, &config, device) != MA_SUCCESS)
|
||||||
{
|
{
|
||||||
std::cerr << "Failed to open playback device" << std::endl;
|
std::cerr << "Failed to open playback device" << std::endl;
|
||||||
return -1;
|
return -1;
|
||||||
@ -267,12 +271,16 @@ namespace Soundux
|
|||||||
void Playback::internal::data_callback(ma_device *device, void *output, [[maybe_unused]] const void *input,
|
void Playback::internal::data_callback(ma_device *device, void *output, [[maybe_unused]] const void *input,
|
||||||
std::uint32_t frameCount)
|
std::uint32_t frameCount)
|
||||||
{
|
{
|
||||||
ma_decoder *decoder = reinterpret_cast<ma_decoder *>(device->pUserData);
|
auto *decoder = reinterpret_cast<ma_decoder *>(device->pUserData);
|
||||||
if (decoder == 0)
|
if (decoder == nullptr)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (usedDevices.find(device->playback.name) != usedDevices.end())
|
if (usedDevices.find(device->playback.name) != usedDevices.end())
|
||||||
|
{
|
||||||
device->masterVolumeFactor = usedDevices[device->playback.name];
|
device->masterVolumeFactor = usedDevices[device->playback.name];
|
||||||
|
}
|
||||||
|
|
||||||
auto readFrames = ma_decoder_read_pcm_frames(decoder, output, frameCount);
|
auto readFrames = ma_decoder_read_pcm_frames(decoder, output, frameCount);
|
||||||
|
|
||||||
|
@ -1,15 +1,15 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
#include <stdexcept>
|
|
||||||
#include <exception>
|
|
||||||
#include <optional>
|
|
||||||
#include <iostream>
|
|
||||||
#include <cstdio>
|
|
||||||
#include <string>
|
|
||||||
#include <memory>
|
|
||||||
#include <vector>
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <exception>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
#include <optional>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
#include "../config/config.h"
|
#include "../config/config.h"
|
||||||
@ -61,7 +61,7 @@ namespace Soundux
|
|||||||
std::string resampleMethod;
|
std::string resampleMethod;
|
||||||
std::string processBinary;
|
std::string processBinary;
|
||||||
|
|
||||||
operator bool()
|
operator bool() const
|
||||||
{
|
{
|
||||||
return index >= 0;
|
return index >= 0;
|
||||||
}
|
}
|
||||||
@ -76,7 +76,8 @@ namespace Soundux
|
|||||||
inline std::string createSink()
|
inline std::string createSink()
|
||||||
{
|
{
|
||||||
system(("pactl load-module module-null-sink sink_name=" + internal::sinkName +
|
system(("pactl load-module module-null-sink sink_name=" + internal::sinkName +
|
||||||
" sink_properties=device.description=" + internal::sinkName + " > nul").c_str());
|
" sink_properties=device.description=" + internal::sinkName + " > nul")
|
||||||
|
.c_str());
|
||||||
|
|
||||||
auto defaultInput = internal::getDefaultCaptureDevice();
|
auto defaultInput = internal::getDefaultCaptureDevice();
|
||||||
// Create loopback for input
|
// Create loopback for input
|
||||||
@ -91,13 +92,14 @@ namespace Soundux
|
|||||||
};
|
};
|
||||||
inline void deleteSink()
|
inline void deleteSink()
|
||||||
{
|
{
|
||||||
// TODO: only unload soundboard sink
|
// TODO(d3s0x): only unload soundboard sink
|
||||||
system("pactl unload-module module-null-sink 2> nul");
|
system("pactl unload-module module-null-sink 2> nul");
|
||||||
system("pactl unload-module module-loopback 2> nul");
|
system("pactl unload-module module-loopback 2> nul");
|
||||||
};
|
};
|
||||||
inline auto getSources()
|
inline auto getSources()
|
||||||
{
|
{
|
||||||
using namespace internal;
|
using internal::getOutput;
|
||||||
|
using internal::PulseAudioRecordingStream;
|
||||||
|
|
||||||
auto input = getOutput("pactl list source-outputs");
|
auto input = getOutput("pactl list source-outputs");
|
||||||
|
|
||||||
@ -106,7 +108,9 @@ namespace Soundux
|
|||||||
auto ss = std::stringstream{str};
|
auto ss = std::stringstream{str};
|
||||||
|
|
||||||
for (std::string line; std::getline(ss, line, '\n');)
|
for (std::string line; std::getline(ss, line, '\n');)
|
||||||
|
{
|
||||||
result.push_back(line);
|
result.push_back(line);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
@ -136,13 +140,21 @@ namespace Soundux
|
|||||||
else if (stream)
|
else if (stream)
|
||||||
{
|
{
|
||||||
if (match[4].matched)
|
if (match[4].matched)
|
||||||
|
{
|
||||||
stream.driver = match[4];
|
stream.driver = match[4];
|
||||||
|
}
|
||||||
else if (match[6].matched)
|
else if (match[6].matched)
|
||||||
|
{
|
||||||
stream.source = match[6];
|
stream.source = match[6];
|
||||||
|
}
|
||||||
else if (match[8].matched)
|
else if (match[8].matched)
|
||||||
|
{
|
||||||
stream.processBinary = match[8];
|
stream.processBinary = match[8];
|
||||||
|
}
|
||||||
else if (match[10].matched)
|
else if (match[10].matched)
|
||||||
|
{
|
||||||
stream.resampleMethod = match[10];
|
stream.resampleMethod = match[10];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user