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