forked from osoumen/C700
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaveView.cpp
250 lines (224 loc) · 6.07 KB
/
WaveView.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
/*
* WaveView.cpp
* C700
*
* Created by osoumen on 12/10/04.
* Copyright 2012 __MyCompanyName__. All rights reserved.
*
*/
#include "C700GUI.h"
#include "WaveView.h"
#include <math.h>
//-----------------------------------------------------------------------------
CWaveView::CWaveView(CRect &size, CFrame *pFrame, CControlListener* listener, long tag)
: CControl(size, listener, tag, 0)
{
m_pDrawBuffer = new COffscreenContext(pFrame, size.right-size.left, size.bottom-size.top);
lineColor = MakeCColor(180, 248, 255, 255);
backColor = MakeCColor(67, 75, 88, 255);
mMessageFont = new CFontDesc("Courier", 18);
isWaveLoaded = false;
looppoint = 0;
datanum = 0;
converting = false;
}
//-----------------------------------------------------------------------------
CWaveView::~CWaveView()
{
delete m_pDrawBuffer;
mMessageFont->forget();
}
//-----------------------------------------------------------------------------
bool CWaveView::onDrop(CDragContainer* drag, const CPoint& where)
{
C700GUI *guiview = reinterpret_cast<C700GUI*> (getParentView());
if ( !guiview->isTypeOf("C700GUI") ) {
return false;
}
long size, type;
void* ptr = drag->first(size, type);
if ( ptr ) {
if ( type == CDragContainer::kFile ) {
return guiview->loadToCurrentProgram((char *)ptr);
}
}
return false;
}
//------------------------------------------------------------------------
void CWaveView::onDragEnter (CDragContainer* drag, const CPoint& where)
{
getFrame()->setCursor(kCursorCopy);
setDirty();
}
//------------------------------------------------------------------------
void CWaveView::onDragLeave (CDragContainer* drag, const CPoint& where)
{
getFrame()->setCursor(kCursorNotAllowed);
setDirty();
}
//------------------------------------------------------------------------
void CWaveView::onDragMove (CDragContainer* drag, const CPoint& where)
{
}
//------------------------------------------------------------------------
void CWaveView::draw(CDrawContext *pContext)
{
if (converting)
{
pContext->setFrameColor(kBlackCColor);
pContext->setFillColor(backColor);
pContext->drawRect(getVisibleSize(), kDrawFilledAndStroked);
//CRect oldClip;
//pContext->getClipRect(oldClip);
CRect newClip(size);
newClip.offset(10, 16);
//newClip.bound(oldClip);
//pContext->setClipRect(newClip);
pContext->setFont(mMessageFont);
pContext->setFontColor(lineColor);
#if VSTGUI_USES_UTF8
pContext->drawStringUTF8("Converting to ADPCM...", newClip, kLeftText, true);
#else
pContext->drawString("Converting to ADPCM...", newClip, true, kLeftText);
#endif
//pContext->setClipRect(oldClip);
}
else
{
if (isWaveLoaded)
{
m_pDrawBuffer->copyFrom(pContext, size);
//ループポイントの位置を描画
if (looppoint > 0) {
pContext->setFrameColor(kYellowCColor);
CPoint point(size.left + getWidth()*looppoint/datanum, size.top + 2);
pContext->moveTo(point);
point.offset(0, getHeight() - 3);
pContext->lineTo(point);
}
}
else
{
pContext->setFrameColor(kBlackCColor);
pContext->setFillColor(backColor);
pContext->drawRect(getVisibleSize(), kDrawFilledAndStroked);
//CRect oldClip;
//pContext->getClipRect(oldClip);
CRect newClip(size);
newClip.offset(10, 16);
//newClip.bound(oldClip);
//pContext->setClipRect(newClip);
pContext->setFont(mMessageFont);
pContext->setFontColor(lineColor);
#if VSTGUI_USES_UTF8
#if MAC
pContext->drawStringUTF8("Drop .aif .wav .brr .spc", newClip, kLeftText, true);
#else
pContext->drawStringUTF8("Drop .wav .brr .spc", newClip, kLeftText, true);
#endif
#else
#if MAC
pContext->drawString("Drop .aif .wav .brr .spc", newClip, true, kLeftText);
#else
pContext->drawString("Drop .wav .brr .spc", newClip, true, kLeftText);
#endif
#endif
//pContext->setClipRect(oldClip);
}
}
}
//------------------------------------------------------------------------
void CWaveView::setWave(short *wavedata, long frames)
{
CRect r(0, 0, m_pDrawBuffer->getWidth(), m_pDrawBuffer->getHeight());
m_pDrawBuffer->setFrameColor(kBlackCColor);
m_pDrawBuffer->setFillColor(backColor);
m_pDrawBuffer->drawRect(r, kDrawFilledAndStroked);
short *dataptr=wavedata;
short *dataend=wavedata+frames;
float pixelPerFrame=(float)m_pDrawBuffer->getWidth()/(float)frames;
//dataptr++;
m_pDrawBuffer->setFrameColor(lineColor);
m_pDrawBuffer->setDrawMode(kAntialias);
CPoint p;
float center = m_pDrawBuffer->getHeight()/2 - 1; //外枠1ドット分余白のため
float x=1,y=0;
float xLoc=1.0f;
float max=.0f,min=.0f;
while (dataptr < dataend) {
float temp = (*dataptr / 32768.0f) * center;
if (max==.0f) max = temp;
if (min==.0f) min = temp;
if (temp > max) max = temp;
if (temp < min) min = temp;
if (xLoc >= 1.0f) {
float xadd;
xLoc = modff(xLoc, &xadd);
y = center - min + 2; //外枠1ドット分余白のため
p.x = x;
p.y = y;
if ( x == 1 )
{
m_pDrawBuffer->moveTo(p);
}
else
{
m_pDrawBuffer->lineTo(p);
}
if (max != min) {
p.y = center-max + 2;
m_pDrawBuffer->lineTo(p);
}
max=0.0f;
min=0.0f;
x += xadd;
}
dataptr++;
xLoc += pixelPerFrame;
}
if (max != 0.0f) {
y = center-min;
m_pDrawBuffer->lineTo(p);
if (max != min) {
y = center-max;
m_pDrawBuffer->lineTo(p);
}
}
converting = false;
datanum = frames;
if ( frames > 0 ) {
isWaveLoaded = true;
}
else {
isWaveLoaded = false;
}
setDirty();
}
//------------------------------------------------------------------------
void CWaveView::setBackColor(CColor color)
{
backColor = color;
}
//------------------------------------------------------------------------
void CWaveView::setLineColor(CColor color)
{
lineColor = color;
}
//------------------------------------------------------------------------
void CWaveView::beginConverting()
{
converting = true;
setDirty();
}
//------------------------------------------------------------------------
void CWaveView::endConverting()
{
converting = false;
setDirty();
}
//------------------------------------------------------------------------
void CWaveView::setLooppoint(int loopStartSamp)
{
looppoint = loopStartSamp;
setDirty();
}