renamed project, search for config file next to binary and not in CWD
This commit is contained in:
parent
d614316af6
commit
5d2beeb643
|
@ -6,7 +6,7 @@
|
|||
|
||||
class Config {
|
||||
public:
|
||||
Config();
|
||||
Config(const std::string binaryArgument);
|
||||
~Config();
|
||||
|
||||
bool hasChanged();
|
||||
|
@ -36,5 +36,6 @@ public:
|
|||
} rootConfig;
|
||||
|
||||
private:
|
||||
std::string file = "soundboard.json";
|
||||
std::string binaryPath;
|
||||
const std::string file = "soundboard.json";
|
||||
};
|
|
@ -19,7 +19,7 @@ class MainWindow : public QMainWindow
|
|||
Q_OBJECT
|
||||
|
||||
public:
|
||||
MainWindow(QWidget *parent = nullptr);
|
||||
MainWindow(const std::string& binary, QWidget *parent = nullptr);
|
||||
~MainWindow();
|
||||
|
||||
public slots:
|
||||
|
|
|
@ -4,9 +4,14 @@
|
|||
#include <iostream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <stdlib.h> // realpath
|
||||
#include <libgen.h> // dirname
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
using json = nlohmann::json;
|
||||
|
||||
#include <Log.h>
|
||||
|
||||
template<typename T>
|
||||
static void readVector(std::vector<T>& v, const json& j) {
|
||||
v.clear();
|
||||
|
@ -14,7 +19,18 @@ static void readVector(std::vector<T>& v, const json& j) {
|
|||
std::copy(j.begin(), j.end(), std::insert_iterator<std::vector<T>>(v, v.begin()));
|
||||
}
|
||||
|
||||
Config::Config() {
|
||||
Config::Config(const std::string binaryArgument) {
|
||||
char* buff = realpath(binaryArgument.c_str(), NULL); // buff needs free !
|
||||
//ssize_t read = readlink(binaryArgument.c_str(), buf, MAXBUF);
|
||||
if(buff) {
|
||||
// success
|
||||
char* binPath = dirname(buff);
|
||||
binaryPath = std::string(binPath) + '/';
|
||||
free(buff);
|
||||
} else {
|
||||
// error
|
||||
Log::error << "unable to read path of the binaryFile";
|
||||
}
|
||||
}
|
||||
|
||||
Config::~Config() {
|
||||
|
@ -53,15 +69,17 @@ bool Config::ButtonConfig::isValid() const {
|
|||
}
|
||||
|
||||
void Config::load() {
|
||||
std::ifstream stream(file);
|
||||
std::ifstream stream(binaryPath + file);
|
||||
json json;
|
||||
if(stream) {
|
||||
try {
|
||||
stream >> json;
|
||||
rootConfig = json;
|
||||
} catch(nlohmann::detail::parse_error& pe) {
|
||||
std::cout << "json error: " << pe.what() << std::endl;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
Log::error << "config File not found";
|
||||
}
|
||||
rootConfig = json;
|
||||
}
|
||||
|
|
|
@ -6,12 +6,16 @@
|
|||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
if(argc < 1) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Log::init();
|
||||
Log::setColoredOutput(true);
|
||||
Log::setConsoleLogLevel(Log::Level::TRACE);
|
||||
|
||||
QApplication a(argc, argv);
|
||||
MainWindow w;
|
||||
MainWindow w(argv[0]);
|
||||
w.show();
|
||||
int result = a.exec();
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
#include <Log.h>
|
||||
|
||||
MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent), ui(new Ui::Soundboard) {
|
||||
MainWindow::MainWindow(const std::string& binary, QWidget* parent) : QMainWindow(parent), ui(new Ui::Soundboard), config(binary) {
|
||||
ui->setupUi(this);
|
||||
|
||||
up = new QxtGlobalShortcut(QKeySequence("Shift+Up"));
|
||||
|
@ -85,25 +85,25 @@ static uint8_t wrap0(uint8_t a, uint8_t max) {
|
|||
|
||||
void MainWindow::moveUp() {
|
||||
Log::debug << "up";
|
||||
reselectNext([max = ui->gridLayout->rowCount()](uint8_t& x, uint8_t& y){ y = wrap(--y, max); });
|
||||
reselectNext([max = ui->gridLayout->rowCount()](uint8_t&, uint8_t& y){ y = wrap(--y, max); });
|
||||
Log::debug << "x " << (int) xCoord << " y " << (int) yCoord;
|
||||
}
|
||||
|
||||
void MainWindow::moveDown() {
|
||||
Log::debug << "down";
|
||||
reselectNext([max = ui->gridLayout->rowCount()](uint8_t& x, uint8_t& y){ y = wrap0(++y, max); });
|
||||
reselectNext([max = ui->gridLayout->rowCount()](uint8_t&, uint8_t& y){ y = wrap0(++y, max); });
|
||||
Log::debug << "x " << (int) xCoord << " y " << (int) yCoord;
|
||||
}
|
||||
|
||||
void MainWindow::moveLeft() {
|
||||
Log::debug << "left";
|
||||
reselectNext([max = ui->gridLayout->columnCount()](uint8_t& x, uint8_t& y){ x = wrap(--x, max); });
|
||||
reselectNext([max = ui->gridLayout->columnCount()](uint8_t& x, uint8_t&){ x = wrap(--x, max); });
|
||||
Log::debug << "x " << (int) xCoord << " y " << (int) yCoord;
|
||||
}
|
||||
|
||||
void MainWindow::moveRight() {
|
||||
Log::debug << "right";
|
||||
reselectNext([max = ui->gridLayout->columnCount()](uint8_t& x, uint8_t& y){ x = wrap0(++x, max); });
|
||||
reselectNext([max = ui->gridLayout->columnCount()](uint8_t& x, uint8_t&){ x = wrap0(++x, max); });
|
||||
Log::debug << "x " << (int) xCoord << " y " << (int) yCoord;
|
||||
}
|
||||
|
||||
|
|
|
@ -130,3 +130,9 @@ Sound::~Sound() {
|
|||
ma_context_uninit(&context);
|
||||
}
|
||||
|
||||
void Sound::backgroundThreadLoop() {
|
||||
while(threadShouldrun) {
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ void SoundDevice::sound_callback(void* outbuffer, ma_uint32 frameCount) {
|
|||
unsigned int decoderCount = data.decoderCount;
|
||||
|
||||
unsigned int streamDivider = std::max<unsigned int>(decoderCount, MINSTREAMCOUNT); //nicht listplaybacks.size() verwenden, da manche playbacks möglicherweise noch fertig sind, aber noch nicht aus der list entfernt wurden. (wird von anderem thread gemacht)
|
||||
unsigned int count = 0; //nummer des aktuellen decoders (nur für debugging)
|
||||
// unsigned int count = 0; //nummer des aktuellen decoders (nur für debugging)
|
||||
|
||||
for (SoundDevice::Playback* pb : data.playbacks) {
|
||||
if (pb->isDone) continue; //fertige encoder ignorieren
|
||||
|
@ -96,6 +96,10 @@ SoundDevice* SoundDevice::createDevice(ma_context* ctx, const std::string& name)
|
|||
ma_device_info* pPlaybackDeviceInfos;
|
||||
ma_uint32 playbackDeviceCount;
|
||||
ma_result result = ma_context_get_devices(ctx, &pPlaybackDeviceInfos, &playbackDeviceCount, NULL, 0);
|
||||
if(result != MA_SUCCESS) {
|
||||
Log::error << "could not get sound device list";
|
||||
return nullptr;
|
||||
}
|
||||
int8_t choosenDevice = -1;
|
||||
|
||||
Log::info << " " << playbackDeviceCount << " playback devices found:";
|
||||
|
|
Loading…
Reference in New Issue