diff --git a/include/buttonmanager.h b/include/buttonmanager.h index 83b94f6..f94e70e 100644 --- a/include/buttonmanager.h +++ b/include/buttonmanager.h @@ -1,10 +1,9 @@ #pragma once #include -#include #include -#include "config.h" +#include "configdialog.h" #include "buttonmanageritems.h" #include "mainwindow.h" @@ -12,7 +11,7 @@ namespace Ui { class ButtonManager; } -class ButtonManager : public QDialog +class ButtonManager : public ConfigDialog { Q_OBJECT @@ -20,10 +19,6 @@ public: explicit ButtonManager(Config& conf, MainWindow *parent = nullptr); ~ButtonManager(); -public slots: - virtual void accept(); - virtual void reject(); - private slots: //buttons: void addButton(); @@ -35,17 +30,15 @@ private slots: void itemSelected(); void itemChanged(QTreeWidgetItem* item, int column); void itemDoubleClicked(QTreeWidgetItem* item); - void dialogButtonPressed(QAbstractButton* btn); - void saveChanges(); private: Ui::ButtonManager *ui; MainWindow* mainW = nullptr; - Config& mainConfig; - Config::RootConfig workingConfig; + virtual void saveChanges() override; + virtual void loadConfig() override; - void loadConfig(); + virtual QDialogButtonBox* getButtonBox() override; void select(QTreeWidgetItem* item); diff --git a/include/configdialog.h b/include/configdialog.h new file mode 100644 index 0000000..f00dc51 --- /dev/null +++ b/include/configdialog.h @@ -0,0 +1,30 @@ +#pragma once + +#include +#include + +#include "config.h" + +class ConfigDialog : public QDialog { + Q_OBJECT + +public: + explicit ConfigDialog(Config& conf, QWidget* parent = nullptr); + ~ConfigDialog(); + +public slots: + virtual void accept() override; + virtual void reject() override; + +protected slots: + virtual void saveChanges(); + void dialogButtonPressed(QAbstractButton* btn); + +protected: + Config& mainConfig; + Config::RootConfig workingConfig; + + virtual void loadConfig(); + virtual QDialogButtonBox* getButtonBox() = 0; + +}; diff --git a/include/mainwindow.h b/include/mainwindow.h index 3997519..45b7314 100644 --- a/include/mainwindow.h +++ b/include/mainwindow.h @@ -38,6 +38,7 @@ private slots: void alwaysOnTopSettingChange(int status); void saveConfig(); void openButtonManager(); + void openSettings(); signals: void newStatusMessage(const QString&); diff --git a/include/settings.h b/include/settings.h new file mode 100644 index 0000000..bb8c21b --- /dev/null +++ b/include/settings.h @@ -0,0 +1,29 @@ +#ifndef SETTINGS_H +#define SETTINGS_H + +#include "configdialog.h" + +namespace Ui { + class Settings; +} + +class Settings : public ConfigDialog { + Q_OBJECT + +public: + explicit Settings(Config& conf, QWidget *parent = nullptr); + ~Settings(); + +private slots: + void selectAudioPath(); + void masterVolumeChange(int val); + +private: + Ui::Settings *ui; + + void setAudioPath(); + + virtual QDialogButtonBox* getButtonBox() override; +}; + +#endif // SETTINGS_H diff --git a/include/sound.h b/include/sound.h index 50342ad..e2ae21a 100644 --- a/include/sound.h +++ b/include/sound.h @@ -31,6 +31,9 @@ public: SampleReader* openFile(const std::string& name); std::vector getOutputs(); + void setMasterVolume(float m); + float getMasterVolume() const; + static std::string FOLDER; private: @@ -53,6 +56,8 @@ private: std::mutex devicesMutex; std::vector devices; + float masterVolume = 1.0; + static Sound* inst; friend void sound_callback(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount); diff --git a/soundboard.json.backup b/soundboard.json.backup new file mode 100644 index 0000000..b439902 --- /dev/null +++ b/soundboard.json.backup @@ -0,0 +1,814 @@ +{ + "audio": { + "devices": [ + "", + "VirtualMic" + ], + "volume": 1.0 + }, + "audioPath": "/home/yannis/prog/ts3/soundboardsounds/neuesSB/", + "buttons": [ + [ + { + "key": "Shift+Num+5", + "name": "UwU", + "samples": [ + { + "file": "Uwu_voice-xjrU3N8M4eo-251.mp3", + "length": 518, + "offset": 11760 + }, + { + "file": "uwu2.mp3", + "length": 591 + }, + { + "file": "uwu2.mp3", + "length": 741, + "offset": 831 + } + ], + "width": 3 + }, + { + "name": "Onii Chan", + "samples": [ + { + "file": "oniichan.mp3", + "length": 927 + }, + { + "file": "oniichan.mp3", + "offset": 913 + } + ], + "width": 3 + }, + { + "file": "ARA_ARA.mp3", + "key": "Shift+Num+2", + "name": "Ara-Ara", + "offset": 100 + }, + { + "file": "bonk.wav", + "key": "Shift+F6", + "name": "Bonk", + "offset": 500 + }, + { + "file": "sigma.mp3", + "length": 21000, + "name": "Sigma", + "offset": 800 + }, + { + "file": "sigma.mp3", + "key": "Shift+Num+9", + "name": "SigmaDrop", + "offset": 21800 + } + ], + [ + { + "file": "Yeet.mp3", + "key": "Shift+F2", + "name": "Yeet", + "width": 3 + }, + { + "file": "scream.mp3", + "length": 1466, + "name": "Scream", + "offset": 322, + "width": 3 + }, + { + "file": "Nani.mp3", + "name": "NANI" + }, + { + "file": "niconiconii.mp3", + "name": "Nico Nico Nii", + "offset": 200 + }, + { + "file": "Spoiler.mp3", + "name": "Cyberpunk", + "offset": 21000 + }, + { + "file": "Spoiler.mp3", + "name": "CyberpunkDrop", + "offset": 41000 + } + ], + [ + { + "file": "neee.mp3", + "key": "Shift+F8", + "length": 1050, + "name": "Neeee", + "offset": 1700, + "width": 3 + }, + { + "file": "neee.mp3", + "length": 2200, + "name": "Lügen darf man nicht sagen!", + "offset": 19500, + "width": 3 + }, + { + "file": "pornhubintro.mp3", + "name": "pornhub Intro", + "offset": 400 + }, + { + "file": "haltstop.mp3", + "length": 1400, + "name": "Halt Stop", + "volume": 0.800000011920929, + "width": 3 + }, + { + "file": "neinjetzt.mp3", + "name": "Nein Jetzt hälst du die Schnautze", + "volume": 1.7999999523162842, + "width": 3 + }, + { + "file": "wii.mp3", + "name": "Wii" + }, + { + "file": "ohnononono.mp3", + "length": 4872, + "name": "OhNo", + "offset": 13200 + } + ], + [ + { + "file": "begonethot.mp3", + "name": "Begone Thot", + "offset": 500 + }, + { + "file": "startedasSpiel.mp3", + "name": "Starte das Spiel", + "width": 2 + }, + { + "file": "echtergangster.mp3", + "length": 1500, + "name": "Aus dem Weg", + "offset": 44350, + "width": 2 + }, + { + "file": "echtergangster.mp3", + "length": 1200, + "name": "Schrei", + "offset": 67900, + "width": 2 + }, + { + "file": "alarm.mp3", + "length": 2000, + "name": "Was suchst du den Hier?", + "offset": 141500, + "volume": 3.0, + "width": 2 + }, + { + "file": "alarm.mp3", + "length": 1150, + "name": "Die wolltest du wohl klauen", + "offset": 147000, + "volume": 3.0, + "width": 2 + }, + { + "file": "alarm.mp3", + "length": 3500, + "name": "Alarm", + "offset": 150000, + "volume": 3.0, + "width": 2 + }, + { + "name": "IsErDrin?", + "samples": [ + { + "file": "iserschondrin.mp3", + "length": 1297, + "offset": 5947 + }, + { + "file": "iserschondrin.mp3", + "length": 700, + "offset": 11329 + }, + { + "file": "iserschondrin.mp3", + "length": 800, + "offset": 15400 + }, + { + "file": "iserschondrin.mp3", + "length": 868, + "offset": 23000 + } + ] + }, + { + "name": "Puta", + "samples": [ + { + "file": "puuutttaaa.mp3", + "length": 1210, + "offset": 1001 + }, + { + "file": "puuutttaaa.mp3", + "length": 1626, + "offset": 2200 + } + ] + } + ], + [ + { + "file": "ahri.mp3", + "length": 2280, + "name": "le Bonc", + "offset": 282000, + "width": 2 + }, + { + "key": "Shift+Num+1", + "name": "Janna", + "samples": [ + { + "file": "ahri.mp3", + "length": 1000, + "offset": 198300 + }, + { + "file": "ahri.mp3", + "length": 2000, + "offset": 201000 + }, + { + "file": "ahri.mp3", + "length": 1000, + "offset": 204000 + } + ], + "width": 2 + }, + { + "file": "ahri.mp3", + "length": 4300, + "name": "Ahri", + "offset": 19000, + "width": 2 + }, + { + "name": "Vayne", + "samples": [ + { + "file": "vayne.mp3", + "length": 4000, + "offset": 500 + }, + { + "file": "vayne.mp3", + "length": 6000, + "offset": 8500 + }, + { + "file": "vayne.mp3", + "length": 6000, + "offset": 16500 + }, + { + "file": "vayne.mp3", + "offset": 23000 + } + ], + "width": 2 + }, + { + "file": "ahri.mp3", + "length": 2000, + "name": "Lux", + "offset": 334000, + "width": 2 + }, + { + "file": "ahri.mp3", + "length": 1800, + "name": "Kayle", + "offset": 267000, + "width": 2 + }, + { + "file": "ahri.mp3", + "length": 3500, + "name": "LuLu", + "offset": 324700, + "volume": 0.5, + "width": 2 + }, + { + "file": "explosion.mp3", + "key": "Shift+F5", + "name": "Explosion", + "offset": 700, + "volume": 0.5, + "width": 4 + }, + { + "file": "Nasheed - Liyakun Yawmuka.mp3", + "length": 9000, + "name": "Arab" + }, + { + "file": "Nasheed - Liyakun Yawmuka.mp3", + "name": "Arab2", + "offset": 9000 + } + ], + [ + { + "file": "spongebob.mp3", + "key": "Shift+F7", + "name": "Spongebob" + }, + { + "file": "lux.mp3", + "length": 2000, + "name": "Lux - Aber nur Händchen...", + "offset": 195000, + "width": 3 + }, + { + "file": "lux.mp3", + "length": 2000, + "name": "Lux - hier war ich...", + "offset": 93000, + "width": 3 + }, + { + "file": "butz.mp3", + "key": "Shift+Num+3", + "length": 500, + "name": "Butz", + "offset": 3500, + "width": 2 + }, + { + "file": "schlitz.mp3", + "key": "Shift+Num+6", + "length": 900, + "name": "Schlitz", + "offset": 21700, + "volume": 0.699999988079071, + "width": 2 + }, + { + "file": "dasistjagesternnichtsogutgelaufen.mp3", + "length": 1900, + "name": "Das ist ja gestern nicht so gut gelaufen", + "offset": 137500, + "volume": 4.0, + "width": 2 + }, + { + "file": "mayonnaise on an escalator (full song) [9K2Y-rfUy_4].mp3", + "name": "Mayo", + "offset": 4500 + }, + { + "file": "helloDarkness.mp3", + "name": "Darkness", + "offset": 3500 + } + ], + [ + { + "file": "Thecutestthingihaveseenmyentirelife.mp3", + "length": 3000, + "name": "cutest fucking thing", + "offset": 8500, + "volume": 5.0, + "width": 2 + }, + { + "file": "Thecutestthingihaveseenmyentirelife.mp3", + "length": 1000, + "name": "Pfeil", + "offset": 11500, + "volume": 4.0, + "width": 2 + }, + { + "file": "Thecutestthingihaveseenmyentirelife.mp3", + "key": "Shift+Num+7", + "length": 700, + "name": "Ahu", + "offset": 12700, + "volume": 4.0, + "width": 2 + }, + { + "file": "Herewego.mp3", + "key": "Shift+Num+4", + "name": "Here we go", + "offset": 700 + }, + { + "file": "fbiopenup.mp3", + "length": 3000, + "name": "FBI open up", + "offset": 14000, + "volume": 0.20000000298023224 + }, + { + "file": "roblox.mp3", + "length": 1366, + "name": "Roblox", + "offset": 500 + }, + { + "file": "minecraftDamage.mp3", + "length": 1000, + "name": "Minercraft", + "offset": 500 + } + ], + [ + { + "file": "HisNameIsjohnCena.mp3", + "length": 5450, + "name": "His Name is John Cena", + "offset": 2400, + "width": 3 + }, + { + "file": "Watchout.mp3", + "name": "Watch Out", + "offset": 3100, + "width": 3 + }, + { + "file": "ItsCalledHentai.mp3", + "name": "Its called Hentai", + "offset": 40000 + }, + { + "file": "ICQ.mp3", + "name": "ICQ", + "offset": 200 + }, + { + "file": "theRock.mp3", + "name": "TheRock" + }, + { + "file": "amongus.mp3", + "name": "Amongus" + } + ], + [ + { + "name": "Knocking", + "samples": [ + { + "file": "knocking.mp3", + "length": 1400, + "offset": 4000 + }, + { + "file": "knocking.mp3", + "length": 1400, + "offset": 10500 + } + ] + }, + { + "file": "richardUwU3.mp3", + "name": "Richard UwU", + "offset": 2440 + }, + { + "file": "beep.mp3", + "length": 970, + "name": "Beep", + "offset": 100 + }, + { + "file": "totalerkrieg.mp3", + "length": 2763, + "name": "Totaler Krieg", + "offset": 16600 + }, + { + "file": "totalerkrieg.mp3", + "length": 2000, + "name": "Jaaa", + "offset": 19277 + } + ], + [ + { + "file": "uhhh.mp3", + "length": 598, + "name": "Uhhh", + "offset": 22606 + }, + { + "name": "No", + "samples": [ + { + "file": "TikTok_ailaughtatmyownjokes_9h782ikvkmb81.mp3", + "length": 1117, + "offset": 36040 + }, + { + "file": "TikTok_ailaughtatmyownjokes_9h782ikvkmb81.mp3", + "length": 718, + "offset": 37600 + } + ] + }, + { + "file": "Uwu_voice-xjrU3N8M4eo-251.mp3", + "key": "Shift+Num+8", + "length": 1067, + "name": "Ah No!", + "offset": 12658 + }, + { + "file": "sieg.mp3", + "length": 800, + "name": "Sieg", + "offset": 8001 + }, + { + "file": "sieg.mp3", + "length": 700, + "name": "Heil", + "offset": 8600 + } + ], + [ + { + "file": "kranfahrerRonny2.mp3", + "length": 2272, + "name": "Nein das geht so nicht", + "offset": 46779, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 2408, + "name": "So was hab ich noch nie erlebt", + "offset": 248103, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 2925, + "name": "60t abstellen", + "offset": 360500, + "width": 2 + }, + { + "name": "Die leute kommen ihrer Arbeit nicht nach", + "samples": [ + { + "file": "kranfahrerRonny2.mp3", + "length": 3363, + "offset": 366300 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 6277, + "offset": 370000 + } + ], + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 3730, + "name": "Kranplätze...", + "offset": 384300, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 3619, + "name": "Leute einfach keine Lust?", + "offset": 392700, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 5913, + "name": "mal fragen", + "offset": 396400, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 3076, + "name": "Kran wiegt", + "offset": 405400, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 2800, + "name": "Ultra Übel", + "offset": 410000, + "width": 2 + }, + { + "name": "Bum", + "samples": [ + { + "file": "rage_tense1983.mp3", + "length": 2195, + "offset": 151500 + }, + { + "file": "rage_tense1983.mp3", + "length": 1287, + "offset": 403500 + } + ] + }, + { + "file": "chingChengHanji.mp3", + "name": "ChingChangHanji", + "offset": 5600 + } + ], + [ + { + "file": "kranfahrerRonny2.mp3", + "length": 5500, + "name": "Wild hier", + "offset": 413000, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "key": "Shift+F3", + "length": 2010, + "name": "Jetz reichts mir langsam", + "offset": 437200, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 2600, + "name": "Haben die kein 8m Maß", + "offset": 443000, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 1700, + "name": "Originale Nichtskönner", + "offset": 465000, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 4000, + "name": "Vollidioten wie die Norweger", + "offset": 468000, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 5500, + "name": "nicht in der EU", + "offset": 473000, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 2000, + "name": "Sind wir schon wieder schneller", + "offset": 640500, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 3500, + "name": "Junge Junge Junge", + "offset": 453800, + "width": 2 + }, + { + "file": "kranfahrerRonny2.mp3", + "length": 2500, + "name": "Einpacken", + "offset": 482200, + "width": 2 + }, + { + "file": "fastafboi.mp3", + "length": 2700, + "name": "how fast i am", + "offset": 7000 + }, + { + "file": "fastafboi.mp3", + "length": 2145, + "name": "Fast AF", + "offset": 10000 + } + ], + [ + { + "file": "kinski.mp3", + "length": 1300, + "name": "Leck mich doch am Arch", + "offset": 8500, + "width": 2 + }, + { + "file": "kinski.mp3", + "length": 2564, + "name": "Dies mal schlagich", + "offset": 13000, + "width": 2 + }, + { + "file": "kinski.mp3", + "length": 1815, + "name": "Mach doch dein Scheiß", + "offset": 39800, + "width": 2 + }, + { + "file": "brumbrum.mp3", + "name": "BrumBrum", + "width": 3 + }, + { + "file": "meepmeep.mp3", + "length": 420, + "name": "MeepMeep", + "width": 3 + }, + { + "file": "thx.mp3", + "name": "THX", + "offset": 14000 + }, + { + "file": "iWillKillyou.mp3", + "length": 5000, + "name": "I Will Kill you", + "offset": 38000 + }, + { + "file": "mariospeedrunanimated.mp3", + "length": 7303, + "name": "GayBowser", + "offset": 186500 + } + ], + [ + { + "file": "wide.mp3", + "length": 45000, + "name": "WIDE", + "offset": 6000, + "width": 3 + }, + { + "file": "wide.mp3", + "name": "WIDE", + "offset": 45500, + "width": 3 + } + ] + ], + "shortcuts": { + "down": "Shift+Down", + "left": "Shift+Left", + "play": "Shift+Num+Enter", + "right": "Shift+Right", + "stop": "Shift+Num+0", + "up": "Shift+Up" + } +} \ No newline at end of file diff --git a/soundboard.pro b/soundboard.pro index 86d5101..c7fcfd1 100644 --- a/soundboard.pro +++ b/soundboard.pro @@ -25,10 +25,12 @@ SOURCES += \ src/sounddevice.cpp \ src/soundbutton.cpp \ src/config.cpp \ + src/configdialog.cpp \ src/editbutton.cpp \ src/editsample.cpp \ src/soundview.cpp \ src/samplereader.cpp \ + src/settings.cpp \ src/buttonmanager.cpp \ src/buttonmanageritems.cpp \ src/addnewwhat.cpp \ @@ -41,10 +43,12 @@ HEADERS += \ include/sounddevice.h \ include/soundbutton.h \ include/config.h \ + include/configdialog.h \ include/editbutton.h \ include/editsample.h \ include/soundview.h \ include/samplereader.h \ + include/settings.h \ include/buttonmanager.h \ include/buttonmanageritems.h \ include/addnewwhat.h \ @@ -61,7 +65,8 @@ FORMS += \ ui/buttonmanager.ui \ ui/editbutton.ui \ ui/editsample.ui \ - ui/mainwindow.ui + ui/mainwindow.ui \ + ui/settings.ui TRANSLATIONS += \ testqt_de_DE.ts diff --git a/src/buttonmanager.cpp b/src/buttonmanager.cpp index ea6510c..1e67606 100644 --- a/src/buttonmanager.cpp +++ b/src/buttonmanager.cpp @@ -10,7 +10,7 @@ #include -ButtonManager::ButtonManager(Config& conf, MainWindow* parent) : QDialog(parent), ui(new Ui::ButtonManager), mainW(parent), mainConfig(conf) { +ButtonManager::ButtonManager(Config& conf, MainWindow* parent) : ConfigDialog(conf, parent), ui(new Ui::ButtonManager), mainW(parent) { ui->setupUi(this); loadConfig(); @@ -34,17 +34,6 @@ ButtonManager::~ButtonManager() { delete ui; } -void ButtonManager::accept() { - saveChanges(); - - QDialog::accept(); -} - -void ButtonManager::reject() { - // nothing? - QDialog::reject(); -} - void ButtonManager::addButton() { AddNewWhat whatshouldbeadded(this); whatshouldbeadded.exec(); @@ -188,8 +177,6 @@ void ButtonManager::itemChanged(QTreeWidgetItem* item, int column) { } else if(column == 2) { //shortcut button->keyWasChanged(); - } else { - Log::warn << "column: " << column << " of button was edited"; } } } @@ -201,28 +188,15 @@ void ButtonManager::itemDoubleClicked(QTreeWidgetItem* item) { } } - -void ButtonManager::dialogButtonPressed(QAbstractButton* btn) { - QDialogButtonBox::ButtonRole role = ui->buttonBox->buttonRole(btn); - if(role == QDialogButtonBox::ButtonRole::ResetRole) { - // reset - loadConfig(); - } else if(role == QDialogButtonBox::ButtonRole::ApplyRole) { - // apply - saveChanges(); - } -} - void ButtonManager::saveChanges() { // store working config to main config and save - mainConfig.rootConfig = workingConfig; - mainConfig.save(); + ConfigDialog::saveChanges(); mainW->reloadButtonConfig(); } void ButtonManager::loadConfig() { - workingConfig = mainConfig.rootConfig; + ConfigDialog::loadConfig(); while(ui->buttonTreeWidget->invisibleRootItem()->childCount()) { auto kid = ui->buttonTreeWidget->invisibleRootItem()->takeChild(0); @@ -236,6 +210,10 @@ void ButtonManager::loadConfig() { } } +QDialogButtonBox* ButtonManager::getButtonBox() { + return ui->buttonBox; +} + void ButtonManager::select(QTreeWidgetItem* item) { QList selected = ui->buttonTreeWidget->selectedItems(); for(QTreeWidgetItem* selectedItem : selected) { diff --git a/src/configdialog.cpp b/src/configdialog.cpp new file mode 100644 index 0000000..294291f --- /dev/null +++ b/src/configdialog.cpp @@ -0,0 +1,42 @@ +#include "configdialog.h" + +#include +#include + +ConfigDialog::ConfigDialog(Config& conf, QWidget* parent) : QDialog(parent), mainConfig(conf) { +} + +ConfigDialog::~ConfigDialog() {} + +void ConfigDialog::accept() { + saveChanges(); + + QDialog::accept(); +} + +void ConfigDialog::reject() { + // nothing? + QDialog::reject(); +} + + +void ConfigDialog::saveChanges() { + mainConfig.rootConfig = workingConfig; + mainConfig.save(); +} + +void ConfigDialog::dialogButtonPressed(QAbstractButton* btn) { + QDialogButtonBox::ButtonRole role = getButtonBox()->buttonRole(btn); + if(role == QDialogButtonBox::ButtonRole::ResetRole) { + // reset + loadConfig(); + } else if(role == QDialogButtonBox::ButtonRole::ApplyRole) { + // apply + saveChanges(); + } +} + +void ConfigDialog::loadConfig() { + // make a copy + workingConfig = mainConfig.rootConfig; +} \ No newline at end of file diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0c0b377..e92b7e3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -3,6 +3,7 @@ #include "buttonmanager.h" #include "editsample.h" +#include "settings.h" #include #include @@ -17,10 +18,11 @@ MainWindow::MainWindow(const std::string& binary, QWidget* parent) : QMainWindow reloadConfig(); - QObject::connect(ui->reloadButton, SIGNAL(clicked()), this, SLOT(reloadConfig())); QObject::connect(ui->stopButton, SIGNAL( clicked() ), this, SLOT( stop() )); QObject::connect(ui->actionSaveConfig, SIGNAL( triggered() ), this, SLOT( saveConfig() )); QObject::connect(ui->actionButtonManager, SIGNAL( triggered() ), this, SLOT( openButtonManager() )); + QObject::connect(ui->actionSettings, SIGNAL( triggered() ), this, SLOT( openSettings() )); + QObject::connect(ui->actionReloadConfig, SIGNAL( triggered() ), this, SLOT(reloadConfig())); QObject::connect(ui->alwaysOnTop, SIGNAL( stateChanged(int) ), this, SLOT( alwaysOnTopSettingChange(int) )); QObject::connect(this, SIGNAL(newStatusMessage(const QString&)), ui->statusbar, SLOT(showMessage(const QString&))); } @@ -129,8 +131,19 @@ void MainWindow::openButtonManager() { // reload button config if(buttonManager.result() == QMessageBox::ButtonRole::AcceptRole) { - removeAllButtons(); - loadButtonsFromConfig(); + reloadButtonConfig(); + } +} + +void MainWindow::openSettings() { + Log::info << "openSettings"; + + Settings settings(config, this); + settings.exec(); + + // reload complete config + if(settings.result() == QMessageBox::ButtonRole::AcceptRole) { + reloadConfig(); } } @@ -151,6 +164,8 @@ void MainWindow::loadSoundFromConfig() { Log::debug << "Sound devices loaded"; + sound.setMasterVolume(config.rootConfig.audio.volume); + Sound::FOLDER = config.rootConfig.audioPath; Log::debug << "Sound::FOLDER: " << Sound::FOLDER; } diff --git a/src/settings.cpp b/src/settings.cpp new file mode 100644 index 0000000..f294050 --- /dev/null +++ b/src/settings.cpp @@ -0,0 +1,54 @@ +#include "settings.h" +#include "ui_settings.h" + +#include + +#include + +#include "sound.h" + +Settings::Settings(Config& conf, QWidget *parent) : ConfigDialog(conf, parent), ui(new Ui::Settings) { + ui->setupUi(this); + + setAudioPath(); +} + +Settings::~Settings() { + delete ui; +} + +void Settings::selectAudioPath() { + Log::info << "select Audiopath"; + + QFileDialog fileselector(this); + fileselector.setFileMode(QFileDialog::Directory); + fileselector.setOption(QFileDialog::Option::ShowDirsOnly, true); + fileselector.setDirectory(QString::fromStdString(Sound::FOLDER)); + fileselector.exec(); + + QStringList filelist = fileselector.selectedFiles(); + if(filelist.size() != 1) { + Log::error << "no folder selected"; + return; + } + + std::string folder = filelist.at(0).toStdString(); + workingConfig.audioPath = folder; + setAudioPath(); +} + +void Settings::masterVolumeChange(int val) { + std::string text = "Master Volume: " + std::to_string(val) + "%"; + ui->masterVolumeLabel->setText(QString::fromStdString(text)); + workingConfig.audio.volume = (val / 100.0f); +} + +void Settings::setAudioPath() { + QString path = QString::fromStdString("Audio Folder: " + workingConfig.audioPath); + ui->audioFolderLabel->setText(path); + ui->audioFolderLabel->setToolTip(path); +} + +QDialogButtonBox* Settings::getButtonBox() { + return ui->buttonBox; +} diff --git a/src/sound.cpp b/src/sound.cpp index 4ff7cc0..3a070ce 100644 --- a/src/sound.cpp +++ b/src/sound.cpp @@ -33,6 +33,7 @@ #include "extras/stb_vorbis.c" //vorbis +#define MA_NO_WAV // disable wav encoding implementation #define MINIAUDIO_IMPLEMENTATION #include "miniaudio.h" @@ -68,6 +69,8 @@ void Sound::addPlayback(const std::string& name, float volume, uint64_t beginms, if(volume < 0.00001f) volume = 0.00001f; + volume *= masterVolume; + std::lock_guard lock(devicesMutex); for(SoundDevice* sd : devices) { sd->addPlayback(name, volume, beginms, length); @@ -78,6 +81,8 @@ void Sound::addPlayback(const std::string& audioDeviceName, const std::string& n if(volume < 0.00001f) volume = 0.00001f; + volume *= masterVolume; + std::lock_guard lock(devicesMutex); for(SoundDevice* sd : devices) { if(sd->getName() == audioDeviceName) { @@ -119,6 +124,8 @@ void Sound::reset() { deinit(); init(); + masterVolume = 1.0; + Log::info << "ResetAudio done"; } @@ -136,6 +143,13 @@ std::vector Sound::getOutputs() { return out; } +void Sound::setMasterVolume(float m) { + masterVolume = m; +} +float Sound::getMasterVolume() const { + return masterVolume; +} + Sound::Sound() { init(); startBackgroundThread(); diff --git a/ui/buttonmanager.ui b/ui/buttonmanager.ui index 4bb28f7..94be52a 100644 --- a/ui/buttonmanager.ui +++ b/ui/buttonmanager.ui @@ -68,6 +68,14 @@ + + addButton + editButton + deleteButton + moveUpButton + moveDownButton + buttonTreeWidget + @@ -142,7 +150,7 @@ 878 - 113 + 101 803 @@ -174,7 +182,7 @@ 878 - 187 + 167 804 diff --git a/ui/editbutton.ui b/ui/editbutton.ui index 716594d..ae623ca 100644 --- a/ui/editbutton.ui +++ b/ui/editbutton.ui @@ -11,7 +11,7 @@ - Dialog + Edit Button diff --git a/ui/mainwindow.ui b/ui/mainwindow.ui index cb0a024..645abb5 100644 --- a/ui/mainwindow.ui +++ b/ui/mainwindow.ui @@ -26,13 +26,6 @@ - - - - reload Config - - - @@ -77,7 +70,7 @@ 0 0 615 - 25 + 24 @@ -86,6 +79,8 @@ + + @@ -114,6 +109,22 @@ Ctrl+B + + + Settings + + + Ctrl+. + + + + + Reload Config + + + Ctrl+R + + diff --git a/ui/settings.ui b/ui/settings.ui new file mode 100644 index 0000000..4bc266a --- /dev/null +++ b/ui/settings.ui @@ -0,0 +1,179 @@ + + + Settings + + + + 0 + 0 + 409 + 285 + + + + + 0 + 0 + + + + SoundboardSettings + + + + + 30 + 240 + 341 + 32 + + + + Qt::Horizontal + + + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Reset|QDialogButtonBox::Save + + + + + + 10 + 10 + 381 + 221 + + + + + QLayout::SetDefaultConstraint + + + + + QLayout::SetDefaultConstraint + + + + + Audio Folder: + + + + + + + Choose + + + + + + + + + QLayout::SetDefaultConstraint + + + + + Master Volume: 100% + + + + + + + + 0 + 0 + + + + 200 + + + 100 + + + Qt::Horizontal + + + + + + + + + + + + buttonBox + accepted() + Settings + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + Settings + reject() + + + 316 + 260 + + + 286 + 274 + + + + + audioFolder + clicked() + Settings + selectAudioPath() + + + 282 + 65 + + + 285 + 118 + + + + + masterVolume + valueChanged(int) + Settings + masterVolumeChange(int) + + + 305 + 176 + + + 363 + 206 + + + + + + selectAudioPath() + masterVolumeChange(int) + +