soundboard/src/mainwindow.cpp

60 lines
1.6 KiB
C++
Raw Normal View History

2021-12-13 00:28:04 +01:00
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <iostream>
2021-12-13 01:23:03 +01:00
#include <string>
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
#include <Log.h>
2021-12-13 01:23:03 +01:00
2021-12-13 14:48:43 +01:00
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::Soundboard) {
ui->setupUi(this);
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
reloadConfig();
2021-12-13 01:23:03 +01:00
2021-12-13 14:48:43 +01:00
// init Buttons
SoundButton* sb;
sb = new SoundButton("Uwu_voice-xjrU3N8M4eo-251.mp3", "UwU", "Shift+F1");
ui->gridLayout->addWidget(sb->getButton(), 0, 0);
soundbuttons.push_back(sb);
sb = new SoundButton("bonk.wav", "Bonk");
ui->gridLayout->addWidget(sb->getButton(), 0, 1);
soundbuttons.push_back(sb);
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
QObject::connect(ui->reloadButton, SIGNAL( clicked() ), this, SLOT( reloadConfig() ));
QObject::connect(this, SIGNAL( newStatusMessage(const QString&) ), ui->statusbar, SLOT( showMessage(const QString&) ));
2021-12-13 00:28:04 +01:00
}
MainWindow::~MainWindow() {
delete ui;
Sound::deinit();
}
2021-12-13 14:48:43 +01:00
void MainWindow::reloadConfig() {
Log::info << "realodConfig()";
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
QString loaded = QString::fromStdString("loading config");
emit newStatusMessage(loaded);
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
config.load();
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
Sound& sound = Sound::instance(); // init sound
sound.reset();
const std::vector<std::string>& devices = config.rootConfig.audio.devices;
for(const std::string& device : devices) {
Log::note << "loadAudio device: \"" << device << '"';
if(!sound.addDeviceWithName(device)) {
Log::warn << "AudioDevice could not be loaded: \"" << device << '"';
QString done = QString::fromStdString("Sound Device: " + device + " not found!");
emit newStatusMessage(done);
return;
}
}
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
QString done = QString::fromStdString("config loaded");
emit newStatusMessage(done);
2021-12-13 00:28:04 +01:00
2021-12-13 14:48:43 +01:00
Log::info << "realodConfig() done";
2021-12-13 00:28:04 +01:00
}