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