forked from MrBesen/soundboard
editing samples
This commit is contained in:
parent
a13f57f4a8
commit
724c1c5872
|
@ -76,8 +76,10 @@ public:
|
|||
|
||||
const static int TYPE = 1002;
|
||||
|
||||
virtual bool hasEdit() const override;
|
||||
virtual bool hasRemove() const override;
|
||||
|
||||
virtual void edit() override;
|
||||
virtual void remove() override;
|
||||
|
||||
Config::SampleConfig& getConfig();
|
||||
|
|
|
@ -19,6 +19,9 @@ public:
|
|||
uint64_t getStartTime() const;
|
||||
uint64_t getLength() const;
|
||||
|
||||
void setStartTime(uint64_t);
|
||||
void setLength(uint64_t);
|
||||
|
||||
public slots:
|
||||
void play();
|
||||
void stop();
|
||||
|
|
|
@ -158,7 +158,6 @@ void ButtonManager::itemSelected() {
|
|||
ButtonManagerItem* item = dynamic_cast<ButtonManagerItem*>(getSelectedItem());
|
||||
if(item) {
|
||||
// set buttons
|
||||
// ui->addButton->setEnabled(item->hasAdd());
|
||||
ui->editButton->setEnabled(item->hasEdit());
|
||||
ui->deleteButton->setEnabled(item->hasRemove());
|
||||
ui->moveUpButton->setEnabled(item->hasMoveUp());
|
||||
|
@ -166,7 +165,6 @@ void ButtonManager::itemSelected() {
|
|||
} else {
|
||||
Log::info << "no valid item selected";
|
||||
|
||||
// ui->addButton->setEnabled(false);
|
||||
ui->editButton->setEnabled(false);
|
||||
ui->deleteButton->setEnabled(false);
|
||||
ui->moveUpButton->setEnabled(false);
|
||||
|
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
#include <Log.h>
|
||||
|
||||
// itemtypes
|
||||
const static int ROWTYPE = 1000;
|
||||
const static int BUTTONTYPE = 1001;
|
||||
const static int SAMPLETYPE = 1002;
|
||||
#include "editsample.h"
|
||||
|
||||
ButtonManagerItem::ButtonManagerItem(QTreeWidgetItem* parent, int type) : QTreeWidgetItem(parent, type), mparent(parent) {
|
||||
}
|
||||
|
@ -164,13 +161,34 @@ Config::ButtonConfig& ButtonItem::getConfig() {
|
|||
SampleItem::SampleItem(ButtonItem* parent, uint8_t samplenr, Config::RootConfig& conf) : ButtonManagerItem(parent, TYPE), conf(conf), samplenr(samplenr), button(parent) {
|
||||
const Config::SampleConfig& sample = getConfig();
|
||||
updatePosition();
|
||||
setData(3, Qt::ItemDataRole::DisplayRole, QVariant(QString::fromStdString(sample.file)));
|
||||
setText(3, QString::fromStdString(sample.file));
|
||||
setToolTip(2, "Doubleclick to play");
|
||||
}
|
||||
|
||||
bool SampleItem::hasEdit() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SampleItem::hasRemove() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void SampleItem::edit() {
|
||||
Config::SampleConfig& sammpleConf = getConfig();
|
||||
EditSample editor(sammpleConf.file);
|
||||
editor.setStartTime(sammpleConf.offset);
|
||||
editor.setLength(sammpleConf.length);
|
||||
editor.exec();
|
||||
|
||||
if(editor.result() == 0) {
|
||||
Log::info << "Dialog failed";
|
||||
return;
|
||||
}
|
||||
|
||||
sammpleConf.offset = editor.getStartTime();
|
||||
sammpleConf.length = editor.getLength();
|
||||
}
|
||||
|
||||
void SampleItem::remove() {
|
||||
auto& btnconf = button->getConfig().samples;
|
||||
btnconf.erase(btnconf.begin() + samplenr);
|
||||
|
@ -190,4 +208,4 @@ Config::SampleConfig& SampleItem::getConfig() {
|
|||
|
||||
void SampleItem::updatePosition() {
|
||||
setData(2, Qt::ItemDataRole::DisplayRole, QVariant((int) samplenr+1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,20 @@ uint64_t EditSample::getLength() const {
|
|||
return getTimeInfo(ui->lengthTime);
|
||||
}
|
||||
|
||||
void EditSample::setStartTime(uint64_t start) {
|
||||
QTime time = timeFromMS(start);
|
||||
ui->startTime->setTime(time);
|
||||
|
||||
ui->graphicsView->updateStartPosition(start);
|
||||
}
|
||||
|
||||
void EditSample::setLength(uint64_t len) {
|
||||
QTime time = timeFromMS(len);
|
||||
ui->lengthTime->setTime(time);
|
||||
|
||||
ui->graphicsView->updateEndPosition(len + getStartTime());
|
||||
}
|
||||
|
||||
void EditSample::play() {
|
||||
// get audio device
|
||||
std::string devicename = ui->soundOutputselect->currentText().toStdString();
|
||||
|
@ -61,20 +75,14 @@ void EditSample::stop() {
|
|||
}
|
||||
|
||||
void EditSample::setStartToCurrent() {
|
||||
QTime time = timeFromMS(currentposition);
|
||||
ui->startTime->setTime(time);
|
||||
|
||||
ui->graphicsView->updateEndPosition(currentposition);
|
||||
setStartTime(currentposition);
|
||||
}
|
||||
|
||||
void EditSample::setStopToCurrent() {
|
||||
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);
|
||||
setLength(currentposition-offset);
|
||||
} else {
|
||||
// TODO:
|
||||
// currentposition is before offset -> move entire section to match? do nothing?
|
||||
|
|
Loading…
Reference in New Issue