2020-04-27 22:59:30 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
2020-04-29 19:48:41 +02:00
|
|
|
#include <optional>
|
|
|
|
#include <tuple>
|
|
|
|
|
|
|
|
#include <QWidget>
|
|
|
|
#include <QButtonGroup>
|
|
|
|
#include <QTimer>
|
2020-04-27 22:59:30 +02:00
|
|
|
|
|
|
|
#include "audioplayer.h"
|
|
|
|
|
|
|
|
namespace Ui { class TrackDeck; }
|
|
|
|
class AudioDecoder;
|
|
|
|
class QAudioBuffer;
|
2022-12-27 21:19:21 +01:00
|
|
|
struct frame_t;
|
2020-04-27 22:59:30 +02:00
|
|
|
|
|
|
|
class TrackDeck : public QWidget
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit TrackDeck(QWidget *parent = nullptr);
|
|
|
|
~TrackDeck() override;
|
|
|
|
|
|
|
|
void loadTrack(const QString &filename);
|
|
|
|
|
|
|
|
void injectDecodingThread(QThread &thread);
|
|
|
|
|
|
|
|
void writeSamples(frame_t *begin, frame_t *end);
|
|
|
|
|
|
|
|
signals:
|
|
|
|
void startDecoding(const QString &filename);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void dragEnterEvent(QDragEnterEvent *event) override;
|
|
|
|
void dragLeaveEvent(QDragLeaveEvent *event) override;
|
|
|
|
void dropEvent(QDropEvent *event) override;
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void decodingProgress(int progress, int total);
|
|
|
|
void decodingFinished(const QAudioBuffer &buffer);
|
2020-04-28 00:26:40 +02:00
|
|
|
void scratchBegin();
|
|
|
|
void scratchEnd();
|
|
|
|
void speedChanged(int value);
|
|
|
|
void updatePlayButtonText(bool playing);
|
2020-04-29 19:48:41 +02:00
|
|
|
void bpmTap();
|
|
|
|
void timeout();
|
|
|
|
void updatePlaybackBpm();
|
2020-04-27 22:59:30 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
const std::unique_ptr<Ui::TrackDeck> m_ui;
|
|
|
|
|
2020-04-29 19:48:41 +02:00
|
|
|
QButtonGroup m_loopGroup;
|
|
|
|
|
2020-04-27 22:59:30 +02:00
|
|
|
std::unique_ptr<AudioDecoder> m_decoder;
|
|
|
|
|
|
|
|
AudioPlayer m_player;
|
|
|
|
|
|
|
|
QString m_filename;
|
2020-04-28 00:26:40 +02:00
|
|
|
|
|
|
|
bool m_playingBeforeScratch;
|
|
|
|
float m_speedBeforeScratch;
|
|
|
|
bool m_stopOnEndBeforeScratch;
|
2020-04-29 19:48:41 +02:00
|
|
|
|
|
|
|
QTimer m_timer;
|
|
|
|
|
|
|
|
std::optional<std::tuple<double, double, int>> m_bpmTap;
|
2020-04-27 22:59:30 +02:00
|
|
|
};
|