add samples with ButtonManager
This commit is contained in:
parent
3745393d24
commit
0d4f585d41
|
@ -50,6 +50,7 @@ private:
|
|||
|
||||
QTreeWidgetItem* getSelectedItem() const;
|
||||
RowItem* getCurrentRow() const;
|
||||
ButtonItem* getCurrentButton() const;
|
||||
|
||||
template<void (ButtonManagerItem::*T)()>
|
||||
void perform();
|
||||
|
|
|
@ -28,7 +28,7 @@ public:
|
|||
struct ButtonConfig {
|
||||
std::string name;
|
||||
std::string key;
|
||||
uint8_t width; // default is 6
|
||||
uint8_t width = DEFAULTWIDTH; // default is 6
|
||||
|
||||
std::vector<SampleConfig> samples;
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@ public:
|
|||
explicit EditSample(const std::string& audioFile, QWidget *parent = nullptr);
|
||||
~EditSample();
|
||||
|
||||
uint64_t getStartTime() const;
|
||||
uint64_t getLength() const;
|
||||
|
||||
public slots:
|
||||
void play();
|
||||
void stop();
|
||||
|
|
|
@ -36,7 +36,6 @@ public slots:
|
|||
|
||||
private slots:
|
||||
void alwaysOnTopSettingChange(int status);
|
||||
void addSample();
|
||||
void saveConfig();
|
||||
void openButtonManager();
|
||||
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
#include "ui_buttonmanager.h"
|
||||
|
||||
#include "addnewwhat.h"
|
||||
#include "editsample.h"
|
||||
|
||||
#include <QFileDialog>
|
||||
|
||||
#include <Log.h>
|
||||
|
||||
|
@ -62,6 +65,9 @@ void ButtonManager::addButton() {
|
|||
|
||||
//select the new button
|
||||
select(newButton);
|
||||
|
||||
// start editing
|
||||
ui->buttonTreeWidget->editItem(newButton, 1);
|
||||
} else {
|
||||
Log::error << "no row selected";
|
||||
}
|
||||
|
@ -69,6 +75,56 @@ void ButtonManager::addButton() {
|
|||
}
|
||||
if(type == AddNewWhat::ReturnCode::Sample) {
|
||||
// create new sample
|
||||
ButtonItem* btn = getCurrentButton();
|
||||
|
||||
if(btn) {
|
||||
// button to add sample to exists -> start sample editor
|
||||
QFileDialog fileselector(this);
|
||||
fileselector.setFileMode(QFileDialog::ExistingFile);
|
||||
fileselector.setDirectory(QString::fromStdString(Sound::FOLDER));
|
||||
fileselector.exec();
|
||||
|
||||
QStringList filelist = fileselector.selectedFiles();
|
||||
if(filelist.size() != 1) {
|
||||
Log::error << "no file selected";
|
||||
return;
|
||||
} else {
|
||||
QString qfile = filelist.at(0);
|
||||
std::string file = qfile.toStdString();
|
||||
if(file.find(Sound::FOLDER) != 0) {
|
||||
Log::error << "file outside of " << Sound::FOLDER << " was selected, that is not allowed";
|
||||
return;
|
||||
}
|
||||
file = file.substr(file.rfind('/')+1); // remove path; only keep filename
|
||||
Log::info << "selected file: " << file;
|
||||
|
||||
//spawn edit dialog
|
||||
EditSample esample(file, this);
|
||||
esample.exec();
|
||||
|
||||
if(esample.result() == 0) {
|
||||
Log::info << "Dialog failed";
|
||||
return;
|
||||
}
|
||||
|
||||
// create sample
|
||||
Config::SampleConfig sample;
|
||||
sample.file = file;
|
||||
sample.offset = esample.getStartTime();
|
||||
sample.length = esample.getLength();
|
||||
sample.volume = 1.0f;
|
||||
btn->getConfig().samples.push_back(sample);
|
||||
|
||||
// create SampleItem in GUI
|
||||
SampleItem* item = new SampleItem(btn, btn->getConfig().samples.size()-1, workingConfig);
|
||||
|
||||
btn->setExpanded(true);
|
||||
select(item);
|
||||
}
|
||||
} else {
|
||||
Log::error << "no button selected";
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -200,6 +256,23 @@ RowItem* ButtonManager::getCurrentRow() const {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
ButtonItem* ButtonManager::getCurrentButton() const {
|
||||
QTreeWidgetItem* selectedItem = getSelectedItem();
|
||||
if(!selectedItem) {
|
||||
// no item selected
|
||||
//TODO: search for first empty button, create a new button
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// is current selected item a button?
|
||||
if(ButtonItem* btn = dynamic_cast<ButtonItem*>(selectedItem)) {
|
||||
return btn;
|
||||
}
|
||||
|
||||
//TODO: scan for parents / siblings
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
template<void (ButtonManagerItem::*T)()>
|
||||
void ButtonManager::perform() {
|
||||
ButtonManagerItem* item = dynamic_cast<ButtonManagerItem*>(getSelectedItem());
|
||||
|
|
|
@ -33,13 +33,21 @@ EditSample::~EditSample() {
|
|||
delete ui;
|
||||
}
|
||||
|
||||
uint64_t EditSample::getStartTime() const {
|
||||
return getTimeInfo(ui->startTime);
|
||||
}
|
||||
|
||||
uint64_t EditSample::getLength() const {
|
||||
return getTimeInfo(ui->lengthTime);
|
||||
}
|
||||
|
||||
void EditSample::play() {
|
||||
// get audio device
|
||||
std::string devicename = ui->soundOutputselect->currentText().toStdString();
|
||||
|
||||
// get timing info
|
||||
uint64_t startTime = getTimeInfo(ui->startTime);
|
||||
uint64_t lengthTime = getTimeInfo(ui->lengthTime);
|
||||
uint64_t startTime = getStartTime();
|
||||
uint64_t lengthTime = getLength();
|
||||
|
||||
// convert relative time to absolute
|
||||
if(lengthTime != 0) {
|
||||
|
@ -60,14 +68,18 @@ void EditSample::stop() {
|
|||
void EditSample::setStartToCurrent() {
|
||||
QTime time = timeFromMS(currentposition);
|
||||
ui->startTime->setTime(time);
|
||||
|
||||
ui->graphicsView->updateEndPosition(currentposition);
|
||||
}
|
||||
|
||||
void EditSample::setStopToCurrent() {
|
||||
uint64_t offset = getTimeInfo(ui->startTime);
|
||||
uint64_t offset = getStartTime();
|
||||
if(offset < currentposition) {
|
||||
// current position is behind startposition -> shorten length to match
|
||||
QTime time = timeFromMS(currentposition-offset);
|
||||
ui->lengthTime->setTime(time);
|
||||
|
||||
ui->graphicsView->updateEndPosition(currentposition-offset);
|
||||
} else {
|
||||
// TODO:
|
||||
// currentposition is before offset -> move entire section to match? do nothing?
|
||||
|
@ -75,8 +87,8 @@ void EditSample::setStopToCurrent() {
|
|||
}
|
||||
|
||||
void EditSample::timesChanged() {
|
||||
uint64_t start = getTimeInfo(ui->startTime);
|
||||
uint64_t length = getTimeInfo(ui->lengthTime);
|
||||
uint64_t start = getStartTime();
|
||||
uint64_t length = getLength();
|
||||
|
||||
ui->graphicsView->updateStartPosition(start);
|
||||
ui->graphicsView->updateEndPosition(length == 0 ? 0 : (start + length));
|
||||
|
|
|
@ -28,7 +28,6 @@ MainWindow::MainWindow(const std::string& binary, QWidget* parent) : QMainWindow
|
|||
|
||||
QObject::connect(ui->reloadButton, SIGNAL(clicked()), this, SLOT(reloadConfig()));
|
||||
QObject::connect(ui->stopButton, SIGNAL( clicked() ), this, SLOT( stop() ));
|
||||
QObject::connect(ui->actionAddButton, SIGNAL( triggered() ), this, SLOT( addSample() ));
|
||||
QObject::connect(ui->actionSaveConfig, SIGNAL( triggered() ), this, SLOT( saveConfig() ));
|
||||
QObject::connect(ui->actionButtonManager, SIGNAL( triggered() ), this, SLOT( openButtonManager() ));
|
||||
QObject::connect(ui->alwaysOnTop, SIGNAL( stateChanged(int) ), this, SLOT( alwaysOnTopSettingChange(int) ));
|
||||
|
@ -132,30 +131,6 @@ void MainWindow::alwaysOnTopSettingChange(int status) {
|
|||
show();
|
||||
}
|
||||
|
||||
void MainWindow::addSample() {
|
||||
Log::debug << "open sampleEditor";
|
||||
|
||||
QFileDialog fileselector(this);
|
||||
fileselector.setFileMode(QFileDialog::ExistingFile);
|
||||
fileselector.setDirectory(QString::fromStdString(Sound::FOLDER));
|
||||
fileselector.exec();
|
||||
|
||||
QStringList filelist = fileselector.selectedFiles();
|
||||
if(filelist.size() != 1) {
|
||||
Log::error << "no file selected";
|
||||
return;
|
||||
} else {
|
||||
QString qfile = filelist.at(0);
|
||||
std::string file = qfile.toStdString();
|
||||
file = file.substr(file.rfind('/')+1);
|
||||
Log::info << "selected file: " << file;
|
||||
|
||||
//spawn edit dialog
|
||||
EditSample esample(file, this);
|
||||
esample.exec();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveConfig() {
|
||||
Log::info << "save Config";
|
||||
config.save();
|
||||
|
|
|
@ -77,14 +77,13 @@
|
|||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>615</width>
|
||||
<height>24</height>
|
||||
<height>25</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuEdit">
|
||||
<property name="title">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
<addaction name="actionAddButton"/>
|
||||
<addaction name="actionButtonManager"/>
|
||||
<addaction name="actionSaveConfig"/>
|
||||
</widget>
|
||||
|
|
Loading…
Reference in New Issue