#include "editsample.h" #include "ui_editsample.h" #include "sound.h" #include #include EditSample::EditSample(const std::string& audioFile_, QWidget *parent) : QDialog(parent), ui(new Ui::EditSample), audioFile(audioFile_) { ui->setupUi(this); std::vector sounddevices = Sound::instance().getOutputs(); for(const std::string& dev : sounddevices) { QString qdeviceName = QString::fromStdString(dev); ui->soundOutputselect->addItem(qdeviceName, qdeviceName); } QObject::connect(ui->playButton, SIGNAL( clicked() ), this, SLOT( play() )); QObject::connect(ui->stopButton, SIGNAL( clicked() ), this, SLOT( stop() )); } EditSample::~EditSample() { delete ui; } 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); // convert relative time to absolute if(lengthTime != 0) { lengthTime = startTime + lengthTime; } Log::info << "play audio: " << std::quoted(audioFile) << " on " << std::quoted(devicename) << " with " << startTime << " and " << lengthTime; Sound::instance().addPlayback(devicename, audioFile, 1.0, startTime, lengthTime); } void EditSample::stop() { Sound::instance().stopAll(); } uint64_t EditSample::getTimeInfo(const QTimeEdit* time) const { QTime timedata = time->time(); return ((((( (timedata.hour() * 60) + timedata.minute()) * 60) + timedata.second()) * 1000) + timedata.msec()); } void EditSample::setCurrentPosition(uint64_t cp) { currentposition = cp; }