annotate editor/edwaveform.cpp @ 2294:7f6ba3b32f54

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Jul 2019 10:28:43 +0300
parents e2ac08228a0f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "edwaveform.h"
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 {
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
8 data = NULL;
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
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
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
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
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 {
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
24 data = mdata;
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
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
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
29
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
30 int bps = getBps();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
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
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
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
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
44
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 update();
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
49 int QEDWaveTrackDisplay::getBps()
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 {
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
51 int bps = channels;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
52 switch (format)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
53 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
54 case AUDIO_S16SYS:
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
55 case AUDIO_U16SYS:
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
56 bps *= sizeof(quint16);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
57 break;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
58 case AUDIO_S8:
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
59 case AUDIO_U8:
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
60 bps *= sizeof(quint8);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
61 break;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
62 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
63 return bps;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
64 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
65
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
66
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
67 float QEDWaveTrackDisplay::getDuration()
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
68 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
69 return duration;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
70 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
71
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
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
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
74 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
75 return (value * scale * (float) freq) / 1000.0f;
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 {
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
81 return value * scale;
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
86 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
87 if (time != mtime && mtime >= 0 && mtime < duration)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
88 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
89 time = mtime;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
90 emit timeChanged(time);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
91 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
92 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
93
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
94
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
95 void QEDWaveTrackDisplay::setOffset(const float moffs)
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
96 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
97 if (offs != moffs && moffs >= 0 && moffs < getDuration())
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
98 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
99 offs = moffs;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
100 emit offsetChanged(offs);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
101 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
102 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
103
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
104
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
105 void QEDWaveTrackDisplay::setScale(const float mscale)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 {
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 if (mscale > 0.05)
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 scale = mscale;
565
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
109 emit scaleChanged(scale);
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
110 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
111
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
112
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
113 void QEDWaveTrackDisplay::setSelection(const float mstart, const float mend)
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
114 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
115 if (mstart >= 0 && mend >= 0 && fabs(mend - mstart) > 0)
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
116 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
117 selectionValid = true;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
118 if (mend > mstart)
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
119 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
120 selectionStart = mstart;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
121 selectionDuration = mend - mstart + 1;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
122 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
123 else
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
124 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
125 selectionStart = mend;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
126 selectionDuration = mstart - mend + 1;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
127 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
128 emit selectionChanged(selectionStart, selectionDuration);
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
129 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
130 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
131
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
132
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
133 void QEDWaveTrackDisplay::clearSelection()
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
134 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
135 selectionValid = false;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
136 selectionStart = 0;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
137 selectionDuration = 0;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
138 emit selectionChanged(selectionStart, selectionDuration);
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
139 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
140
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
141
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
142 bool QEDTimelineTrackDisplay::getSelection(float *mstart, float *mduration)
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
143 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
144 if (selectionValid)
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
145 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
146 *mstart = selectionStart;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
147 *mduration = selectionDuration;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
148 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
149 return selectionValid;
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
153 float QEDWaveTrackDisplay::getScaledWidth()
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
154 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
155 return getTimeScale(width());
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
156 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
157
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
158
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
159 float QEDWaveTrackDisplay::getTime()
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
160 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
161 return time;
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
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
164
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
165 float QEDWaveTrackDisplay::getOffset()
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
166 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
167 return offs;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
168 }
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
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
171 void QEDWaveTrackDisplay::paintEvent(QPaintEvent *)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 {
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 QColor waveColor(0, 150, 0);
400
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
174 QColor waveCenterLine(100, 100, 100);
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
175 QColor markerColor(255,255,255);
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
176 QColor bgColor(0, 0, 0);//255, 255, 255);
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 QPainter painter(this);
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 painter.setRenderHint(QPainter::Antialiasing);
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
180 painter.fillRect(QRect(0, 0, width(), height()), bgColor);
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
182 if (data != NULL)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183 {
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
184 int voffs = 0;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
185
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
186 painter.save();
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
187 painter.translate(0, height() / 2);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
188
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
189 painter.setPen(waveCenterLine);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
190 painter.drawLine(0, 0, width(), 0);
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 switch (format)
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 case AUDIO_S16SYS:
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
195 painter.scale(1.0f, (float) height() / 32768.0f);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
196 break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
197 case AUDIO_U16SYS:
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
198 voffs = -32768;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
199 painter.scale(1.0f, height() / 32768.0f);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
200 break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
201
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
202 case AUDIO_S8:
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
203 painter.scale(1.0f, height() / 128.0f);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
204 break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
205 case AUDIO_U8:
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
206 voffs = -128;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
207 painter.scale(1.0f, height() / 128.0f);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
208 break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
209 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
210
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
211 painter.scale(1.0f, 0.5f);
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
212 painter.setPen(waveColor);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
213
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
214 float mscale = (scale * (float)freq) / 1000.0f;
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
215 int prevY = 0, prevX = 0;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
216 if (format == AUDIO_S16SYS || format == AUDIO_U16SYS)
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
217 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
218 qint16 *buf = (qint16 *) data;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
219 for (int xc = 0; xc < width(); xc++)
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
220 {
400
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
221 int moffs = (int) (((offs + xc) * mscale));
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
222 if (moffs >= sduration) break;
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
223 int value = buf[moffs * channels] + voffs;
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
224 painter.drawLine(prevX, prevY, xc, value);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
225 prevY = value;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
226 prevX = xc;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
227 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
228 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
229 else
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
230 if (format == AUDIO_S8 || format == AUDIO_U8)
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
231 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
232 qint8 *buf = (qint8 *) data;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
233 for (int xc = 0; xc < width(); xc++)
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
234 {
400
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
235 int moffs = (int) (((offs + xc) * mscale));
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
236 if (moffs >= sduration) break;
f44a89a25c97 Fix waveform display from going over buffer limit.
Matti Hamalainen <ccr@tnsp.org>
parents: 398
diff changeset
237 int value = buf[moffs * channels] + voffs;
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
238 painter.drawLine(prevX, prevY, xc, value);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
239 prevY = value;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
240 prevX = xc;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
241 }
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
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
244 painter.restore();
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
247 float xc = getTimeScale(time - offs), wd = getTimeScale(width());
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
248 if (xc >= 0 && xc <= wd)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 {
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
250 xc = time - offs;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
251 painter.scale(scale, 1.0f);
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 painter.setPen(markerColor);
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 painter.drawLine(xc, 0, xc, height());
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
258 void QEDWaveTrackDisplay::mousePressEvent(QMouseEvent *ev)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259 {
565
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
260 switch (ev->button())
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 {
565
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
262 case Qt::LeftButton:
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
263 selectionPoint = ev->pos();
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
264 selectionOffs = offs;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
265 selecting = false;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
266 break;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
267
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
268 case Qt::RightButton:
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
269 dragPoint = ev->pos();
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
270 dragOffs = offs;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
271 dragging = false;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
272 break;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
273
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
274 default:
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
275 break;
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
280 void QEDWaveTrackDisplay::mouseMoveEvent(QMouseEvent *ev)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 {
565
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
282 if ((ev->buttons() & Qt::LeftButton) && ev->pos().x() != selPoint.x())
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
283 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
284 selecting = true;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
285 setSelection(selectionOffs + (ev->pos().x() - selectionPoint.x()) / scale);
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
286 }
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
287 if ((ev->buttons() & Qt::RightButton) && ev->pos().x() != dragPoint.x())
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
288 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
289 dragging = true;
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
290 setOffset(dragOffs - (ev->pos().x() - dragPoint.x()) / scale);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
291 }
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 }
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
295 void QEDWaveTrackDisplay::mouseReleaseEvent(QMouseEvent *ev)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 {
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
297 if (ev->button() == Qt::LeftButton)
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 {
565
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
299 if (selecting)
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
300 {
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
301 selecting = false;
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
302 setSelection(selOffs + (ev->pos().x() - selPoint.x()) / scale);
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
303 }
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 }
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
305 else
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
306 if (ev->button() == Qt::RightButton && !dragging)
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
307 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
308 setTime(offs + getTimeFromCoord(ev->pos().x()));
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
309 }
357
1b8362a26692 Work towards Qt based editor.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 }
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
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
313 QEDWaveTrackView::QEDWaveTrackView(QWidget *parent) : QWidget(parent)
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
314 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
315 QHBoxLayout *mainLayout = new QHBoxLayout(this);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
316 mainLayout->setMargin(0);
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
317 wave = new QEDWaveTrackDisplay(this);
384
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 QFrame *infoLayoutContainer = new QFrame(this);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
320 infoLayoutContainer->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
321 infoLayoutContainer->setLineWidth(2);
398
8660c6005032 More work.
Matti Hamalainen <ccr@tnsp.org>
parents: 393
diff changeset
322 infoLayoutContainer->setFixedWidth(200);
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 QVBoxLayout *infoLayout = new QVBoxLayout(infoLayoutContainer);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
325 infoLayout->setMargin(0);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
326 infoName = new QLabel("Audio");
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
327 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
328 infoLayout->addWidget(infoName);
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 infoData = new QLabel();
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
331 infoData->setStyleSheet("QLabel { padding: 2px; }");
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
332 infoLayout->addWidget(infoData);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
333
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
334 mainLayout->addWidget(infoLayoutContainer);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
335 mainLayout->addWidget(wave);
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
336
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
337 connect(wave, SIGNAL(timeChanged(float)), this, SLOT(slotTimeChanged(float)));
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
338 connect(wave, SIGNAL(offsetChanged(float)), this, SLOT(slotOffsetChanged(float)));
565
a4666c9e1336 Moar work on the editor (broken).
Matti Hamalainen <ccr@tnsp.org>
parents: 403
diff changeset
339 connect(wave, SIGNAL(selectionChanged(float,float)), this, SLOT(slotSelectionChanged(float,float)));
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
340 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
341
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
342
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
343 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
344 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
345 QString fmt;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
346 switch (mformat)
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
347 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
348 case AUDIO_S16SYS: fmt = "16bit (S)"; break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
349 case AUDIO_U16SYS: fmt = "16bit (U)"; break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
350 case AUDIO_S8: fmt = "8bit (S)"; break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
351 case AUDIO_U8: fmt = "8bit (U)"; break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
352 default: fmt = "?"; break;
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
353 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
354 infoData->setText(QString("<b>%1</b>, <b>%2</b> ch, <b>%3</b> Hz").arg(fmt).arg(mchannels).arg(mfreq));
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
355 wave->setWaveform(mdata, msize, mformat, mchannels, mfreq);
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
356 update();
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
357 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
358
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
359
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
360 void QEDWaveTrackView::setName(QString name)
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
361 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
362 infoName->setText(name);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
363 update();
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
364 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
365
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
366
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
367 void QEDWaveTrackView::setTime(const float mtime)
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
368 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
369 wave->setTime(mtime);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
370 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
371
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
372
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
373 void QEDWaveTrackView::setOffset(const float moffs)
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
374 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
375 wave->setOffset(moffs);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
376 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
377
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
378
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
379 void QEDWaveTrackView::setScale(const float mscale)
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
380 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
381 wave->setScale(mscale);
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
382 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
383
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
384
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
385 float QEDWaveTrackView::getTime()
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
386 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
387 return wave->getTime();
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
388 }
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
389
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
390
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
391 float QEDWaveTrackView::getOffset()
384
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
392 {
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
393 return wave->getOffset();
e5220ff48bc8 Slowly working on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 376
diff changeset
394 }
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
395
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
396
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
397 float QEDWaveTrackView::getScaledWidth()
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
398 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
399 return wave->getScaledWidth();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
400 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
401
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
402
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
403 void QEDWaveTrackView::slotTimeChanged(float value)
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
404 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
405 emit timeChanged(value);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
406 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
407
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
408
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
409 void QEDWaveTrackView::slotOffsetChanged(float value)
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
410 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
411 emit offsetChanged(value);
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
412 }
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
413
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
414
403
d34922e6a244 Even more work towards the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 400
diff changeset
415 float QEDWaveTrackView::getDuration()
391
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
416 {
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
417 return wave->getDuration();
28a74940f2b6 More work on the editor.
Matti Hamalainen <ccr@tnsp.org>
parents: 384
diff changeset
418 }