-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaveform.h
79 lines (54 loc) · 1.79 KB
/
waveform.h
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef WAVEFORM_H
#define WAVEFORM_H
#include <QGraphicsView>
#include <QAudioBuffer>
#include <QGraphicsRectItem>
#include <QGraphicsLineItem>
#include <QTime>
/**
* @brief The Waveform class displays an audio waveform and allows interaction
* with it to set a cursor position (for a playhead) and a selection (to grab
* a subset of the whole audio file).
*/
class Waveform : public QGraphicsView
{
Q_OBJECT
public:
Waveform(QWidget *parent = nullptr);
virtual ~Waveform();
virtual void reset();
void setDuration (qint64 millis);
void addBuffer (const QAudioBuffer &buffer);
void bufferComplete ();
void setSelectionStart (qint64 millis);
void setSelectionLength (qint64 millis);
void setPlayheadPosition (qint64 millis);
qint64 getDuration () const;
qint64 getPlayheadPosition () const;
qint64 getSelectionStart () const;
virtual qint64 getSelectionLength () const;
signals:
void playheadManuallyChanged (qint64 millis);
void selectionRegionChanged (qint64 start, qint64 length);
protected:
virtual void mousePressEvent(QMouseEvent *event);
virtual void mouseReleaseEvent(QMouseEvent *event);
virtual void mouseMoveEvent(QMouseEvent *event);
virtual void resizeEvent(QResizeEvent *event);
//virtual void paintEvent(QPaintEvent *event);
qint64 pixelsToMillis(qint64 pixels) const;
qint64 millisToPixels (qint64 millis) const;
protected:
QGraphicsScene _scene;
qint64 _totalLength;
qint64 _selectionStart;
qint64 _selectionLength;
qint64 _playheadPosition;
qreal _maxValue;
bool _bufferComplete;
// Elements in the scene that we need to change over time:
QGraphicsLineItem *_cursorLine;
QGraphicsLineItem *_playheadLine;
qint64 _playheadPixels;
};
#endif // WAVEFORM_H