blob: c4841c091b61b3f2dfb25e150a6b96c6a8c89f81 (
plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
#ifndef WAVEFORMWIDGETRENDERER_H
#define WAVEFORMWIDGETRENDERER_H
#include <QPainter>
#include <QTime>
#include <QVector>
#include <QtDebug>
#include "track/track.h"
#include "util/class.h"
#include "util/performancetimer.h"
#include "waveform/renderers/waveformmark.h"
#include "waveform/renderers/waveformrendererabstract.h"
#include "waveform/renderers/waveformsignalcolors.h"
//#define WAVEFORMWIDGETRENDERER_DEBUG
class Track;
class ControlProxy;
class VisualPlayPosition;
class VSyncThread;
class WaveformWidgetRenderer {
public:
static const double s_waveformMinZoom;
static const double s_waveformMaxZoom;
static const double s_waveformDefaultZoom;
static const double s_defaultPlayMarkerPosition;
public:
explicit WaveformWidgetRenderer(const char* group);
virtual ~WaveformWidgetRenderer();
bool init();
virtual bool onInit() {return true;}
void setup(const QDomNode& node, const SkinContext& context);
void onPreRender(VSyncThread* vsyncThread);
void draw(QPainter* painter, QPaintEvent* event);
inline const char* getGroup() const { return m_group;}
const TrackPointer getTrackInfo() const { return m_pTrack;}
// Get cue at a point on the waveform widget.
CuePointer getCueAtPoint(QPoint point);
double getFirstDisplayedPosition() const { return m_firstDisplayedPosition;}
double getLastDisplayedPosition() const { return m_lastDisplayedPosition;}
void setZoom(double zoom);
void setDisplayBeatGrid(bool set);
void setDisplayBeatGridAlpha(int alpha);
double getVisualSamplePerPixel() const { return m_visualSamplePerPixel;};
double getAudioSamplePerPixel() const { return m_audioSamplePerPixel;};
// those function replace at its best sample position to an admissible
// sample position according to the current visual resampling
// this make mark and signal deterministic
void regulateVisualSample(int& sampleIndex) const;
// this "regulate" against visual sampling to make the position in widget
// stable and deterministic
// Transform sample index to pixel in track.
inline double transformSamplePositionInRendererWorld(double samplePosition) const {
const double relativePosition = samplePosition / m_trackSamples;
return transformPositionInRendererWorld(relativePosition);
}
// Transform position (percentage of track) to pixel in track.
inline double transformPositionInRendererWorld(double position) const {
return m_trackPixelCount * (position - m_firstDisplayedPosition);
}
double getPlayPos() const { return m_playPos;}
double getPlayPosVSample() const { return m_playPosVSample;}
double getZoomFactor() const { return m_zoomFactor;}
double getGain() const { return m_gain;}
int getTrackSamples() const { return m_trackSamples;}
int beatGridAlpha() const { return m_alphaBeatGrid; }
void resize(int width, int height, float devicePixelRatio);
int getHeight() const { return m_height;}
int getWidth() const { return m_width;}
float getDevicePixelRatio() const { return m_devicePixelRatio; }
int getLength() const { return m_orientation == Qt::Horizontal ? m_width : m_height;}
int getBreadth() const { return m_orientation == Qt::Horizontal ? m_height : m_width;}
Qt::Orientation getOrientation() const { return m_orientation;}
const WaveformSignalColors* getWaveformSignalColors() const { return &m_colors; };
template< class T_Renderer>
inline T_Renderer* addRenderer() {
T_Renderer* renderer = new T_Renderer(this);
m_rendererStack.push_back(renderer);
return renderer;
}
void setTrack(TrackPointer track);
inline void setMarkLabelBoundaries(
QMap<WaveformMarkPointer, int> markLabelOffsets) {
m_markLabelOffsets = markLabelOffsets;
}
double getPlayMarkerPosition() {
return m_playMarkerPosition;
}
void setPlayMarkerPosition(double newPos) {
VERIFY_OR_DEBUG_ASSERT(newPos >= 0.0 && newPos <= 1.0) {
newPos = math_clamp(newPos, 0.0, 1.0);
}
m_playMarkerPosition = newPos;
}
protected:
const char* m_group;
TrackPointer m_pTrack;
QList<WaveformRendererAbstract*> m_rendererStack;
Qt::Orientation m_orientation;
int m_height;
int m_width;
float m_devicePixelRatio;
WaveformSignalColors m_colors;
double m_firstDisplayedPosition;
double m_lastDisplayedPosition;
double m_trackPixelCount;
double m_zoomFactor;
double m_visualSamplePerPixel;
double m_audioSamplePerPixel;
int m_alphaBeatGrid;
//TODO: vRince create some class to manage control/value
//ControlConnection
QSharedPointer<VisualPlayPosition> m_visualPlayPosition;
double m_playPos;
int m_playPosVSample;
ControlProxy* m_pRateRatioCO;
double m_rateRatio;
ControlProxy* m_pGainControlObject;
double m_gain;
ControlProxy* m_pTrackSamplesControlObject;
int m_trackSamples;
double m_scaleFactor;
double m_playMarkerPosition; // 0.0 - left, 0.5 - center, 1.0 - right
#ifdef WAVEFORMWIDGETRENDERER_DEBUG
PerformanceTimer* m_timer;
int m_lastFrameTime;
int m_lastFramesTime[100];
int m_lastSystemFrameTime;
int m_lastSystemFramesTime[100];
int currentFrame;
#endif
private:
DISALLOW_COPY_AND_ASSIGN(WaveformWidgetRenderer);
friend class WaveformWidgetFactory;
QMap<WaveformMarkPointer, int> m_markLabelOffsets;
};
#endif // WAVEFORMWIDGETRENDERER_H
|