Mercurial > hg > dmlib
annotate edwaveform.cpp @ 403:d34922e6a244
Even more work towards the editor.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 19 Oct 2012 21:52:16 +0300 |
parents | f44a89a25c97 |
children | a4666c9e1336 |
rev | line source |
---|---|
357 | 1 #include <QtGui> |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
2 #include <SDL_audio.h> |
357 | 3 #include "edwaveform.h" |
4 | |
5 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
6 QEDWaveTrackDisplay::QEDWaveTrackDisplay(QWidget *parent) : QWidget(parent) |
357 | 7 { |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
8 data = NULL; |
391 | 9 size = 0; |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
10 format = AUDIO_S16SYS; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
11 channels = 1; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
12 freq = 1; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
13 scale = 1.0f; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
14 time = offs = 0; |
391 | 15 duration = 0; |
400
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
16 sduration = 0; |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
17 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
18 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); |
357 | 19 } |
20 | |
21 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
22 void QEDWaveTrackDisplay::setWaveform(void *mdata, int msize, int mformat, int mchannels, int mfreq) |
357 | 23 { |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
24 data = mdata; |
391 | 25 size = msize; |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
26 format = mformat; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
27 channels = mchannels; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
28 freq = mfreq; |
391 | 29 |
30 int bps = getBps(); | |
31 if (bps != 0) | |
400
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
32 { |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
33 // Duration in milliseconds |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
34 duration = ((float) (size / bps) / (float) freq) * 1000.0f; |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
35 |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
36 // Duration in samples |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
37 sduration = msize / bps; |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
38 } |
391 | 39 else |
400
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
40 { |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
41 duration = 0; |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
42 sduration = 0; |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
43 } |
391 | 44 |
357 | 45 update(); |
46 } | |
47 | |
48 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
49 int QEDWaveTrackDisplay::getBps() |
357 | 50 { |
391 | 51 int bps = channels; |
52 switch (format) | |
53 { | |
54 case AUDIO_S16SYS: | |
55 case AUDIO_U16SYS: | |
56 bps *= sizeof(quint16); | |
57 break; | |
58 case AUDIO_S8: | |
59 case AUDIO_U8: | |
60 bps *= sizeof(quint8); | |
61 break; | |
62 } | |
63 return bps; | |
64 } | |
65 | |
66 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
67 float QEDWaveTrackDisplay::getDuration() |
391 | 68 { |
69 return duration; | |
70 } | |
71 | |
72 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
73 float QEDWaveTrackDisplay::getTimeScale(float value) |
391 | 74 { |
75 return (value * scale * (float) freq) / 1000.0f; | |
357 | 76 } |
77 | |
78 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
79 float QEDWaveTrackDisplay::getTimeFromCoord(float value) |
357 | 80 { |
391 | 81 return value * scale; |
357 | 82 } |
83 | |
84 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
85 void QEDWaveTrackDisplay::setTime(const float mtime) |
391 | 86 { |
87 if (time != mtime && mtime >= 0 && mtime < duration) | |
88 { | |
89 time = mtime; | |
90 update(); | |
91 emit timeChanged(time); | |
92 } | |
93 } | |
94 | |
95 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
96 void QEDWaveTrackDisplay::setOffset(const float moffs) |
391 | 97 { |
98 if (offs != moffs && moffs >= 0 && moffs < getDuration()) | |
99 { | |
100 offs = moffs; | |
101 update(); | |
102 emit offsetChanged(offs); | |
103 } | |
104 } | |
105 | |
106 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
107 void QEDWaveTrackDisplay::setScale(const float mscale) |
357 | 108 { |
109 if (mscale > 0.05) | |
110 scale = mscale; | |
111 update(); | |
112 } | |
113 | |
114 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
115 float QEDWaveTrackDisplay::getScaledWidth() |
391 | 116 { |
117 return getTimeScale(width()); | |
118 } | |
119 | |
120 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
121 float QEDWaveTrackDisplay::getTime() |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
122 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
123 return time; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
124 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
125 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
126 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
127 float QEDWaveTrackDisplay::getOffset() |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
128 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
129 return offs; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
130 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
131 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
132 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
133 void QEDWaveTrackDisplay::paintEvent(QPaintEvent *) |
357 | 134 { |
135 QColor waveColor(0, 150, 0); | |
400
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
136 QColor waveCenterLine(100, 100, 100); |
391 | 137 QColor markerColor(255,255,255); |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
138 QColor bgColor(0, 0, 0);//255, 255, 255); |
357 | 139 |
140 QPainter painter(this); | |
141 painter.setRenderHint(QPainter::Antialiasing); | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
142 painter.fillRect(QRect(0, 0, width(), height()), bgColor); |
357 | 143 |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
144 if (data != NULL) |
357 | 145 { |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
146 int voffs = 0; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
147 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
148 painter.save(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
149 painter.translate(0, height() / 2); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
150 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
151 painter.setPen(waveCenterLine); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
152 painter.drawLine(0, 0, width(), 0); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
153 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
154 switch (format) |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
155 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
156 case AUDIO_S16SYS: |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
157 painter.scale(1.0f, (float) height() / 32768.0f); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
158 break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
159 case AUDIO_U16SYS: |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
160 voffs = -32768; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
161 painter.scale(1.0f, height() / 32768.0f); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
162 break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
163 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
164 case AUDIO_S8: |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
165 painter.scale(1.0f, height() / 128.0f); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
166 break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
167 case AUDIO_U8: |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
168 voffs = -128; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
169 painter.scale(1.0f, height() / 128.0f); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
170 break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
171 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
172 |
391 | 173 painter.scale(1.0f, 0.5f); |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
174 painter.setPen(waveColor); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
175 |
391 | 176 float mscale = (scale * (float)freq) / 1000.0f; |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
177 int prevY = 0, prevX = 0; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
178 if (format == AUDIO_S16SYS || format == AUDIO_U16SYS) |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
179 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
180 qint16 *buf = (qint16 *) data; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
181 for (int xc = 0; xc < width(); xc++) |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
182 { |
400
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
183 int moffs = (int) (((offs + xc) * mscale)); |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
184 if (moffs >= sduration) break; |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
185 int value = buf[moffs * channels] + voffs; |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
186 painter.drawLine(prevX, prevY, xc, value); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
187 prevY = value; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
188 prevX = xc; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
189 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
190 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
191 else |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
192 if (format == AUDIO_S8 || format == AUDIO_U8) |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
193 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
194 qint8 *buf = (qint8 *) data; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
195 for (int xc = 0; xc < width(); xc++) |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
196 { |
400
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
197 int moffs = (int) (((offs + xc) * mscale)); |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
198 if (moffs >= sduration) break; |
f44a89a25c97
Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents:
398
diff
changeset
|
199 int value = buf[moffs * channels] + voffs; |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
200 painter.drawLine(prevX, prevY, xc, value); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
201 prevY = value; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
202 prevX = xc; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
203 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
204 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
205 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
206 painter.restore(); |
357 | 207 } |
208 | |
391 | 209 float xc = getTimeScale(time - offs), wd = getTimeScale(width()); |
210 if (xc >= 0 && xc <= wd) | |
357 | 211 { |
391 | 212 xc = time - offs; |
213 painter.scale(scale, 1.0f); | |
357 | 214 painter.setPen(markerColor); |
215 painter.drawLine(xc, 0, xc, height()); | |
216 } | |
217 } | |
218 | |
219 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
220 void QEDWaveTrackDisplay::mousePressEvent(QMouseEvent *ev) |
357 | 221 { |
222 if (ev->button() == Qt::LeftButton) | |
223 { | |
391 | 224 dragPoint = ev->pos(); |
225 dragOffs = offs; | |
226 dragging = false; | |
357 | 227 } |
228 } | |
229 | |
230 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
231 void QEDWaveTrackDisplay::mouseMoveEvent(QMouseEvent *ev) |
357 | 232 { |
391 | 233 if ((ev->buttons() & Qt::LeftButton) && ev->pos().x() != dragPoint.x()) |
234 { | |
235 dragging = true; | |
236 setOffset(dragOffs - (ev->pos().x() - dragPoint.x()) / scale); | |
237 } | |
357 | 238 } |
239 | |
240 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
241 void QEDWaveTrackDisplay::mouseReleaseEvent(QMouseEvent *ev) |
357 | 242 { |
391 | 243 if (ev->button() == Qt::LeftButton) |
357 | 244 { |
391 | 245 dragging = false; |
357 | 246 } |
391 | 247 else |
248 if (ev->button() == Qt::RightButton && !dragging) | |
249 { | |
250 setTime(offs + getTimeFromCoord(ev->pos().x())); | |
251 } | |
357 | 252 } |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
253 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
254 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
255 QEDWaveTrackView::QEDWaveTrackView(QWidget *parent) : QWidget(parent) |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
256 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
257 QHBoxLayout *mainLayout = new QHBoxLayout(this); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
258 mainLayout->setMargin(0); |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
259 wave = new QEDWaveTrackDisplay(this); |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
260 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
261 QFrame *infoLayoutContainer = new QFrame(this); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
262 infoLayoutContainer->setFrameStyle(QFrame::StyledPanel | QFrame::Plain); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
263 infoLayoutContainer->setLineWidth(2); |
398 | 264 infoLayoutContainer->setFixedWidth(200); |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
265 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
266 QVBoxLayout *infoLayout = new QVBoxLayout(infoLayoutContainer); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
267 infoLayout->setMargin(0); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
268 // QVBoxLayout *infoLayout = new QVBoxLayout(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
269 infoName = new QLabel("Audio"); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
270 infoName->setStyleSheet("QLabel { background-color: black; color: white; padding: 2px; }"); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
271 infoLayout->addWidget(infoName); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
272 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
273 infoData = new QLabel(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
274 infoData->setStyleSheet("QLabel { padding: 2px; }"); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
275 infoLayout->addWidget(infoData); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
276 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
277 mainLayout->addWidget(infoLayoutContainer); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
278 // mainLayout->addLayout(infoLayout); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
279 mainLayout->addWidget(wave); |
391 | 280 |
281 connect(wave, SIGNAL(timeChanged(float)), this, SLOT(slotTimeChanged(float))); | |
282 connect(wave, SIGNAL(offsetChanged(float)), this, SLOT(slotOffsetChanged(float))); | |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
283 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
284 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
285 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
286 void QEDWaveTrackView::setWaveform(void *mdata, int msize, int mformat, int mchannels, int mfreq) |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
287 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
288 QString fmt; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
289 switch (mformat) |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
290 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
291 case AUDIO_S16SYS: fmt = "16bit (S)"; break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
292 case AUDIO_U16SYS: fmt = "16bit (U)"; break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
293 case AUDIO_S8: fmt = "8bit (S)"; break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
294 case AUDIO_U8: fmt = "8bit (U)"; break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
295 default: fmt = "?"; break; |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
296 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
297 infoData->setText(QString("<b>%1</b>, <b>%2</b> ch, <b>%3</b> Hz").arg(fmt).arg(mchannels).arg(mfreq)); |
391 | 298 wave->setWaveform(mdata, msize, mformat, mchannels, mfreq); |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
299 update(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
300 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
301 |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
302 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
303 void QEDWaveTrackView::setName(QString name) |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
304 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
305 infoName->setText(name); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
306 update(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
307 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
308 |
391 | 309 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
310 void QEDWaveTrackView::setTime(const float mtime) |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
311 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
312 wave->setTime(mtime); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
313 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
314 |
391 | 315 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
316 void QEDWaveTrackView::setOffset(const float moffs) |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
317 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
318 wave->setOffset(moffs); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
319 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
320 |
391 | 321 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
322 void QEDWaveTrackView::setScale(const float mscale) |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
323 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
324 wave->setScale(mscale); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
325 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
326 |
391 | 327 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
328 float QEDWaveTrackView::getTime() |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
329 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
330 return wave->getTime(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
331 } |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
332 |
391 | 333 |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
334 float QEDWaveTrackView::getOffset() |
384
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
335 { |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
336 return wave->getOffset(); |
e5220ff48bc8
Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
376
diff
changeset
|
337 } |
391 | 338 |
339 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
340 float QEDWaveTrackView::getScaledWidth() |
391 | 341 { |
342 return wave->getScaledWidth(); | |
343 } | |
344 | |
345 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
346 void QEDWaveTrackView::slotTimeChanged(float value) |
391 | 347 { |
348 emit timeChanged(value); | |
349 } | |
350 | |
351 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
352 void QEDWaveTrackView::slotOffsetChanged(float value) |
391 | 353 { |
354 emit offsetChanged(value); | |
355 } | |
356 | |
357 | |
403
d34922e6a244
Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
400
diff
changeset
|
358 float QEDWaveTrackView::getDuration() |
391 | 359 { |
360 return wave->getDuration(); | |
361 } |