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