cursors
This commit is contained in:
parent
b4dcbd176d
commit
1ebc965066
|
@ -24,6 +24,8 @@ private slots:
|
|||
void setStartToCurrent();
|
||||
void setStopToCurrent();
|
||||
|
||||
void timesChanged();
|
||||
|
||||
private:
|
||||
Ui::EditSample* ui;
|
||||
|
||||
|
|
|
@ -16,6 +16,7 @@ public:
|
|||
void setWidth(uint32_t w);
|
||||
|
||||
float readSample(uint32_t pos);
|
||||
uint64_t getLength(); // length of the sample in ms
|
||||
private:
|
||||
ma_decoder decoder;
|
||||
|
||||
|
|
|
@ -17,12 +17,22 @@ public:
|
|||
|
||||
void paintEvent(QPaintEvent*) override;
|
||||
void resizeEvent(QResizeEvent*) override;
|
||||
|
||||
public slots:
|
||||
void updatePosition(unsigned long newpos);
|
||||
void updateStartPosition(unsigned long newpos);
|
||||
void updateEndPosition(unsigned long newpos);
|
||||
|
||||
private:
|
||||
void drawCursor(uint64_t pos, QPen pen);
|
||||
|
||||
QGraphicsScene scene;
|
||||
|
||||
SampleReader* samples = nullptr;
|
||||
|
||||
std::string file;
|
||||
uint64_t offset = 0;
|
||||
uint64_t length = 0;
|
||||
|
||||
uint64_t currentPosition = 0;
|
||||
uint64_t startPos = 0;
|
||||
uint64_t endPos = 0;
|
||||
};
|
|
@ -15,12 +15,17 @@ EditSample::EditSample(const std::string& audioFile_, QWidget *parent) : QDialog
|
|||
ui->soundOutputselect->addItem(qdeviceName, qdeviceName);
|
||||
}
|
||||
|
||||
ui->graphicsView->loadFile(audioFile);
|
||||
|
||||
QObject::connect(ui->playButton, SIGNAL( clicked() ), this, SLOT( play() ));
|
||||
QObject::connect(ui->stopButton, SIGNAL( clicked() ), this, SLOT( stop() ));
|
||||
|
||||
QObject::connect(ui->starttoCurrentButton, SIGNAL( clicked() ), this, SLOT( setStartToCurrent() ));
|
||||
QObject::connect(ui->stoptoCurrentButton, SIGNAL( clicked() ), this, SLOT( setStopToCurrent() ));
|
||||
|
||||
QObject::connect(ui->startTime, SIGNAL( editingFinished() ), this, SLOT( timesChanged() ));
|
||||
QObject::connect(ui->lengthTime, SIGNAL( editingFinished() ), this, SLOT( timesChanged() ));
|
||||
|
||||
setCurrentPosition(0);
|
||||
}
|
||||
|
||||
|
@ -42,6 +47,9 @@ void EditSample::play() {
|
|||
}
|
||||
|
||||
Log::info << "play audio: " << std::quoted(audioFile) << " on " << std::quoted(devicename) << " with " << startTime << " and " << lengthTime;
|
||||
// stop all other sounds first
|
||||
Sound::instance().stopAll();
|
||||
// start new
|
||||
Sound::instance().addPlayback(devicename, audioFile, 1.0, startTime, lengthTime, std::bind(&EditSample::setCurrentPosition, this, std::placeholders::_1));
|
||||
}
|
||||
|
||||
|
@ -66,6 +74,14 @@ void EditSample::setStopToCurrent() {
|
|||
}
|
||||
}
|
||||
|
||||
void EditSample::timesChanged() {
|
||||
uint64_t start = getTimeInfo(ui->startTime);
|
||||
uint64_t length = getTimeInfo(ui->lengthTime);
|
||||
|
||||
ui->graphicsView->updateStartPosition(start);
|
||||
ui->graphicsView->updateEndPosition(length == 0 ? 0 : (start + length));
|
||||
}
|
||||
|
||||
uint64_t EditSample::getTimeInfo(const QTimeEdit* time) const {
|
||||
QTime timedata = time->time();
|
||||
return (((((
|
||||
|
@ -100,4 +116,7 @@ void EditSample::setCurrentPosition(uint64_t cp) {
|
|||
// set text async
|
||||
QString input = QString::fromStdString("Current: " + formatedTime);
|
||||
QMetaObject::invokeMethod(ui->currentPosLabel, "setText", Qt::QueuedConnection, Q_ARG(QString, input));
|
||||
|
||||
// update cursor in view
|
||||
QMetaObject::invokeMethod(ui->graphicsView, "updatePosition", Qt::QueuedConnection, Q_ARG(unsigned long, currentposition));
|
||||
}
|
|
@ -51,4 +51,8 @@ float SampleReader::readSample(uint32_t pos) {
|
|||
if(avg > 1) avg = 1;
|
||||
else if(avg < 0) avg = 0;
|
||||
return avg;
|
||||
}
|
||||
|
||||
uint64_t SampleReader::getLength() {
|
||||
return decoderSize / (decoder.outputSampleRate / 1000);
|
||||
}
|
|
@ -30,15 +30,22 @@ void SoundView::redraw() {
|
|||
|
||||
//Log::info << "scene Size: " << scene.width() << " " << scene.height() << " " << width() << " " << height();
|
||||
|
||||
// red center line
|
||||
scene.addLine(0, h/2, scene.width()-4, h/2, QPen(Qt::red));
|
||||
|
||||
/*
|
||||
for(uint32_t x = 0; x < width(); ++x) {
|
||||
float s = samples->readSample(x);
|
||||
scene.addLine(x, h/2, x, s*h, QPen(Qt::white));
|
||||
//Log::info << "Line: " << x << " " << h/2;
|
||||
// cursor
|
||||
if(samples) {
|
||||
drawCursor(currentPosition, QPen(Qt::blue));
|
||||
drawCursor(startPos, QPen(Qt::yellow));
|
||||
drawCursor(endPos == 0 ? samples->getLength() : endPos, QPen(Qt::yellow));
|
||||
|
||||
/*
|
||||
for(uint32_t x = 0; x < width(); ++x) {
|
||||
float s = samples->readSample(x);
|
||||
scene.addLine(x, h/2, x, s*h, QPen(Qt::white));
|
||||
//Log::info << "Line: " << x << " " << h/2;
|
||||
} */
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void SoundView::paintEvent(QPaintEvent* event) {
|
||||
|
@ -54,3 +61,23 @@ void SoundView::resizeEvent(QResizeEvent* event) {
|
|||
samples->setWidth(event->size().width());
|
||||
}
|
||||
}
|
||||
|
||||
void SoundView::updatePosition(unsigned long newpos) {
|
||||
currentPosition = newpos;
|
||||
update();
|
||||
}
|
||||
|
||||
void SoundView::updateStartPosition(unsigned long newpos) {
|
||||
startPos = newpos;
|
||||
update();
|
||||
}
|
||||
|
||||
void SoundView::updateEndPosition(unsigned long newpos) {
|
||||
endPos = newpos;
|
||||
update();
|
||||
}
|
||||
|
||||
void SoundView::drawCursor(uint64_t pos, QPen pen) {
|
||||
uint32_t cursorXpos = (pos * (scene.width()-4)) / samples->getLength();
|
||||
scene.addLine(cursorXpos, 0, cursorXpos, scene.height() -4, pen);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue