soundboard/include/soundbutton.h

56 lines
1016 B
C
Raw Normal View History

2021-12-13 14:48:43 +01:00
#pragma once
#include <string>
#include <cstdint>
2021-12-15 14:39:39 +01:00
#include <QPushButton>
2021-12-13 14:48:43 +01:00
#include "qxtglobalshortcut.h"
2021-12-15 14:39:39 +01:00
class SoundButton : public QPushButton
{
2021-12-13 14:48:43 +01:00
Q_OBJECT
public:
2021-12-19 15:53:57 +01:00
struct Sample {
std::string file;
uint64_t startms = 0;
uint64_t lengthms = 0; // ignored when length = 0
float volume = 1.f;
};
explicit SoundButton(const std::string& name_ = "", const std::string& keycombo = "", QWidget* parent = nullptr);
2021-12-13 14:48:43 +01:00
~SoundButton();
const std::string& getName() const;
const std::string& getKeyCombo() const;
2021-12-19 15:53:57 +01:00
void addSample(Sample& sample);
2021-12-13 17:28:32 +01:00
2021-12-15 14:39:39 +01:00
void setHighlighted(bool highlighted);
2021-12-13 14:48:43 +01:00
void paintEvent(QPaintEvent *) override;
2021-12-13 14:48:43 +01:00
public slots:
void play();
private:
2021-12-14 10:32:23 +01:00
void setDisabled();
2021-12-15 14:39:39 +01:00
QString getInfo() const;
2021-12-14 10:32:23 +01:00
2021-12-13 14:48:43 +01:00
static uint64_t nextid;
2021-12-13 17:28:32 +01:00
2021-12-13 14:48:43 +01:00
uint64_t id;
std::string name;
std::string keycombo;
2021-12-19 15:53:57 +01:00
uint8_t currentSample = 0;
std::vector<Sample> samples;
2021-12-13 14:48:43 +01:00
2021-12-19 14:57:18 +01:00
bool highlighted = false;
2021-12-14 10:32:23 +01:00
bool disabled = false;
2021-12-19 14:57:18 +01:00
const static uint8_t HIGHLIGHTBORDEROFFSET = 5;
2021-12-13 14:48:43 +01:00
QxtGlobalShortcut* globalShortcut = nullptr;
2022-02-26 16:00:02 +01:00
};