forked from MrBesen/soundboard
67 lines
1.6 KiB
C++
67 lines
1.6 KiB
C++
#include "mainwindow.h"
|
|
#include "ui_mainwindow.h"
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
|
|
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) {
|
|
ui->setupUi(this);
|
|
|
|
Sound& sound = Sound::instance(); // init sound
|
|
sound.addDeviceWithName("VirtualMic");
|
|
sound.addDefaultDevice();
|
|
|
|
QPushButton* btn = ui->pushButton;
|
|
QObject::connect(btn, SIGNAL( clicked() ), this, SLOT( buttonPressed0() ));
|
|
|
|
QPushButton* btn2 = ui->pushButton2;
|
|
QObject::connect(btn2, SIGNAL( clicked() ), this, SLOT( buttonPressed1() ));
|
|
|
|
sc = new QShortcut(QKeySequence("Shift+1"), this, 0, 0, Qt::ApplicationShortcut);
|
|
QObject::connect(sc, SIGNAL( activated() ), this, SLOT( shortcut() ));
|
|
|
|
globalShortcut = new QxtGlobalShortcut(QKeySequence("Shift+F1"));
|
|
QObject::connect(globalShortcut, SIGNAL(activated()), this, SLOT( shortcut2() ));
|
|
}
|
|
|
|
static const std::string SOUNDS[2] {"Uwu_voice-xjrU3N8M4eo-251.mp3", "bonk.wav"};
|
|
static const unsigned int SOUNDSSIZE = 2;
|
|
|
|
MainWindow::~MainWindow() {
|
|
delete ui;
|
|
|
|
Sound::deinit();
|
|
}
|
|
|
|
void MainWindow::buttonPressed(unsigned int id) {
|
|
std::cout << "Button Pressed: " << id << std::endl;
|
|
|
|
playSound(id);
|
|
}
|
|
|
|
void MainWindow::buttonPressed0() {
|
|
buttonPressed(0);
|
|
}
|
|
|
|
void MainWindow::buttonPressed1() {
|
|
buttonPressed(1);
|
|
}
|
|
|
|
void MainWindow::shortcut() {
|
|
std::cout << "Shortcut Pressed" << std::endl;
|
|
|
|
// playSound();
|
|
}
|
|
|
|
void MainWindow::shortcut2() {
|
|
std::cout << "Shortcut2 Pressed!!" << std::endl;
|
|
|
|
// playSound();
|
|
}
|
|
|
|
void MainWindow::playSound(unsigned int soundid) {
|
|
if(soundid < SOUNDSSIZE) {
|
|
Sound::instance().addPlayback(SOUNDS[soundid]);
|
|
}
|
|
}
|