-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
63 lines (51 loc) · 1.85 KB
/
mainwindow.cpp
File metadata and controls
63 lines (51 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <aubio/aubio.h>
#include "aubiobeat.h"
#include "utils.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
const auto audioSource = "/Users/shincurry/dev/music-loop-kichiku/test_data/audio3.mp3";
audioPlayer = new QMediaPlayer;
audioPlayer->setNotifyInterval(1);
audioPlayer->setMedia(QUrl::fromLocalFile(audioSource));
QObject::connect(audioPlayer, SIGNAL(positionChanged(qint64)), this, SLOT(audioPositionChanged(qint64)));
beats = find_beat(audioSource);
const auto videoSource = "/Users/shincurry/dev/music-loop-kichiku/test_data/video4.mp4";
videoPlayer = new LoopPlayer();
videoPlayer->loadVideo(videoSource);
QObject::connect(videoPlayer, SIGNAL(processedImage(QImage)), this, SLOT(updateLoopPlayerUI(QImage)));
audioPlayer->play();
videoPlayer->play();
}
void MainWindow::audioPositionChanged(qint64 position) {
auto it = std::find(beats.begin(), beats.end(), long(position));
if (it != beats.end()) {
qint64 videoDuration = videoPlayer->getDuration();
qint64 beatDuration = beatDuration = qint64(*(it+1) - *it);
auto rate = double(beatDuration) / double(videoDuration);
videoPlayer->pause();
videoPlayer->setPlaybackRate(rate);
videoPlayer->play();
}
}
void MainWindow::updateLoopPlayerUI(QImage img)
{
if (!img.isNull())
{
ui->videoScreen->setAlignment(Qt::AlignCenter);
ui->videoScreen->setPixmap(QPixmap::fromImage(img)
.scaled(
ui->videoScreen->size(),
Qt::KeepAspectRatio,
Qt::FastTransformation)
);
}
}
MainWindow::~MainWindow()
{
delete ui;
}