-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnvelopeOpenGL.hpp
412 lines (412 loc) · 17.7 KB
/
EnvelopeOpenGL.hpp
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
////
//// EnvelopeOpenGL.hpp
//// AudioComponents
////
//// Created by Aaron Dawson on 9/11/16.
////
////
//
//#ifndef EnvelopeOpenGL_hpp
//#define EnvelopeOpenGL_hpp
//
//#include "IPlug_include_in_plug_hdr.h"
//#include "IControl.h"
//#include <stdio.h>
//#include <OpenGL/OpenGL.h>
//#include <OpenGL/glu.h>
//#include <stdlib.h>
//#include "time.h"
//#include "WaveForm.hpp"
//
//class EnvelopeOpenGL : public IControl {
//private:
//
// /* Think of a context as an object that holds all of OpenGL; when a context is destroyed, OpenGL is destroyed. */
// // The CGLContextObj type is the fundamental data type for an OpenGL Context on Mac.
// CGLContextObj mGLContext;
// WDL_TypedBuf<unsigned char> mData;
// int height;
// int width;
// int currentPosition;
// int leftBound;
// int rightBound;
// float mRotateTri, mRotateQuad;
// IRECT currentRect;
// int counter;
// Symphony *symphony;
//
//public:
// EnvelopeOpenGL(IPlugBase* pPlug, IRECT pR, Symphony *symphony)
// : IControl(pPlug, pR, -1)
// {
// // currentfilter = filter;
// currentRect = pR;
// leftBound = 0;
// mRotateTri = mRotateQuad = 0.f;
// createContext();
// mData.Resize(mRECT.W() * mRECT.H() * 4);
// counter = 0;
// this->symphony = symphony;
// srand(time(NULL));
// }
//
// ~EnvelopeOpenGL()
// {
// destroyContext();
// }
//
// int getStartingSample() {
// return leftBound;
// }
//
// int getEndingSample() {
// return rightBound;
// }
//
// void updatePosition(int position) {
// currentPosition = position;
// }
//
// long setContext()
// {
// /* Set the current context. In order for any OpenGL commands to work, a context must be current; all OpenGL commands affect the state of whichever context is current. */
// if(CGLSetCurrentContext(mGLContext))
// {
// DBGMSG("Could not make context current.");
// return 1;
// }
//
// return 0;
// }
//
//
//
// void restoreContext()
// {
// CGLSetCurrentContext(NULL);
// }
//
// long createContext()
// {
// const GLubyte *glstring;
//
// GLint npix;
// CGLPixelFormatObj PixelFormat;
//
// const CGLPixelFormatAttribute attributes[] =
// {
// //kCGLPFAOffScreen,
// // kCGLPFAColorSize, (CGLPixelFormatAttribute)8,
// // kCGLPFADepthSize, (CGLPixelFormatAttribute)16,
// kCGLPFAAccelerated, (CGLPixelFormatAttribute)0
// };
//
// // Create context if none exists
//
// CGLChoosePixelFormat(attributes, &PixelFormat, &npix);
//
// if (PixelFormat == NULL)
// {
// DBGMSG("Could not get pixel format.");
// return 1;
// }
//
// CGLCreateContext(PixelFormat, NULL, &mGLContext);
//
// if (mGLContext == NULL)
// {
// DBGMSG("Could not create rendering context.");
// return 1;
// }
//
// // Set the current context
//
// if(setContext())
// return 1;
//
// // Check OpenGL functionality:
// glstring = glGetString(GL_EXTENSIONS);
//
// if(!gluCheckExtension((const GLubyte *)"GL_EXT_framebuffer_object", glstring))
// {
// DBGMSG("The GL_EXT_framebuffer_object extension is not supported on this system.");
// return 1;
// }
//
// restoreContext();
//
// return 0;
// }
//
//
// void destroyContext()
// {
// if (mGLContext != NULL)
// CGLDestroyContext(mGLContext);
// }
//
// bool Draw(IGraphics* pGraphics)
// {
//
// GLuint framebuffer, renderbuffer;
//
// const int width = mRECT.W();
// const int height = mRECT.H();
//
// // Set context
// if (setContext())
// return false;
//
// // Set up a FBO with one renderbuffer attachment
// glGenFramebuffersEXT(1, &framebuffer);
// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuffer);
// glGenRenderbuffersEXT(1, &renderbuffer);
// glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, renderbuffer);
// glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_RGBA8, width, height);
// glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, renderbuffer);
//
// // glViewport(0,0,width,height); // Reset The Current Viewport
// //
// // glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
// // glLoadIdentity(); // Reset The Projection Matrix
//
// // Calculate The Aspect Ratio Of The Window
// // gluPerspective(45.0f,(GLfloat)width/(GLfloat)height, 0.1f, 100.0f);
// //
// // glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
// // glLoadIdentity(); // Reset The Modelview Matrix
// // glShadeModel(GL_SMOOTH); // Enable Smooth Shading
// // glClearColor(0.0f, 0.0f, 0.0f, 1.f); // Black Background
// // glClearDepth(1.0f); // Depth Buffer Setup
// // glEnable(GL_DEPTH_TEST); // Enables Depth Testing
// // glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
// // glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
// // glEnable(GL_CULL_FACE);
// // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
// // glLoadIdentity(); // Reset The Current Modelview Matrix
//
// // glTranslatef(-1.5f,0.0f,-6.0f); // Move Left 1.5 Units And Into The Screen 6.0
// // glRotatef(mRotateTri,0.0f,1.0f,0.0f); // Rotate The Triangle On The Y axis ( NEW )
// // glBegin(GL_TRIANGLES); // Start Drawing A Triangle
// // glColor3f(1.0f,0.0f,0.0f); // Red
// // glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Front)
// // glColor3f(0.0f,1.0f,0.0f); // Green
// // glVertex3f(-1.0f,-1.0f, 1.0f); // Left Of Triangle (Front)
// // glColor3f(0.0f,0.0f,1.0f); // Blue
// // glVertex3f( 1.0f,-1.0f, 1.0f); // Right Of Triangle (Front)
// // glColor3f(1.0f,0.0f,0.0f); // Red
// // glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Right)
// // glColor3f(0.0f,0.0f,1.0f); // Blue
// // glVertex3f( 1.0f,-1.0f, 1.0f); // Left Of Triangle (Right)
// // glColor3f(0.0f,1.0f,0.0f); // Green
// // glVertex3f( 1.0f,-1.0f, -1.0f); // Right Of Triangle (Right)
// // glColor3f(1.0f,0.0f,0.0f); // Red
// // glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Back)
// // glColor3f(0.0f,1.0f,0.0f); // Green
// // glVertex3f( 1.0f,-1.0f, -1.0f); // Left Of Triangle (Back)
// // glColor3f(0.0f,0.0f,1.0f); // Blue
// // glVertex3f(-1.0f,-1.0f, -1.0f); // Right Of Triangle (Back)
// // glColor3f(1.0f,0.0f,0.0f); // Red
// // glVertex3f( 0.0f, 1.0f, 0.0f); // Top Of Triangle (Left)
// // glColor3f(0.0f,0.0f,1.0f); // Blue
// // glVertex3f(-1.0f,-1.0f,-1.0f); // Left Of Triangle (Left)
// // glColor3f(0.0f,1.0f,0.0f); // Green
// // glVertex3f(-1.0f,-1.0f, 1.0f); // Right Of Triangle (Left)
// // glEnd(); // Done Drawing The Pyramid
// //
// // glLoadIdentity(); // Reset The Current Modelview Matrix
// // glTranslatef(1.5f,0.0f,-7.0f); // Move Right 1.5 Units And Into The Screen 7.0
// // glRotatef(mRotateQuad,1.0f,1.0f,1.0f); // Rotate The Quad On The X axis ( NEW )
// // glBegin(GL_QUADS); // Draw A Quad
// // glColor3f(0.0f,1.0f,0.0f); // Set The Color To Green
// // glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Top)
// // glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Top)
// // glVertex3f(-1.0f, 1.0f, 1.0f); // Bottom Left Of The Quad (Top)
// // glVertex3f( 1.0f, 1.0f, 1.0f); // Bottom Right Of The Quad (Top)
// // glColor3f(1.0f,0.5f,0.0f); // Set The Color To Orange
// // glVertex3f( 1.0f,-1.0f, 1.0f); // Top Right Of The Quad (Bottom)
// // glVertex3f(-1.0f,-1.0f, 1.0f); // Top Left Of The Quad (Bottom)
// // glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Bottom)
// // glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Bottom)
// // glColor3f(1.0f,0.0f,0.0f); // Set The Color To Red
// // glVertex3f( 1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Front)
// // glVertex3f(-1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Front)
// // glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Front)
// // glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Front)
// // glColor3f(1.0f,1.0f,0.0f); // Set The Color To Yellow
// // glVertex3f( 1.0f,-1.0f,-1.0f); // Top Right Of The Quad (Back)
// // glVertex3f(-1.0f,-1.0f,-1.0f); // Top Left Of The Quad (Back)
// // glVertex3f(-1.0f, 1.0f,-1.0f); // Bottom Left Of The Quad (Back)
// // glVertex3f( 1.0f, 1.0f,-1.0f); // Bottom Right Of The Quad (Back)
// // glColor3f(0.0f,0.0f,1.0f); // Set The Color To Blue
// // glVertex3f(-1.0f, 1.0f, 1.0f); // Top Right Of The Quad (Left)
// // glVertex3f(-1.0f, 1.0f,-1.0f); // Top Left Of The Quad (Left)
// // glVertex3f(-1.0f,-1.0f,-1.0f); // Bottom Left Of The Quad (Left)
// // glVertex3f(-1.0f,-1.0f, 1.0f); // Bottom Right Of The Quad (Left)
// // glColor3f(1.0f,0.0f,1.0f); // Set The Color To Violet
// // glVertex3f( 1.0f, 1.0f,-1.0f); // Top Right Of The Quad (Right)
// // glVertex3f( 1.0f, 1.0f, 1.0f); // Top Left Of The Quad (Right)
// // glVertex3f( 1.0f,-1.0f, 1.0f); // Bottom Left Of The Quad (Right)
// // glVertex3f( 1.0f,-1.0f,-1.0f); // Bottom Right Of The Quad (Right)
// // glEnd(); // Done Drawing The Quad
// //
// // mRotateTri+=1.5f; // Increase The Rotation Variable For The Triangle ( NEW )
// // mRotateQuad-=1.65f; // Decrease The Rotation Variable For The Quad ( NEW )
//
// // Setup OpenGL for 2D drawing with the correct blending
// glViewport(0, 0, width, height);
// glMatrixMode (GL_PROJECTION);
// glLoadIdentity ();
// glOrtho (0, width, height, 0, 0, 1);
// glMatrixMode (GL_MODELVIEW);
//
// glDepthMask(GL_FALSE);
// glEnable(GL_BLEND);
// glEnable(GL_LINE_SMOOTH);
// glEnable( GL_POINT_SMOOTH );
// glHint(GL_LINE_SMOOTH_HINT, GL_FASTEST);
// glHint(GL_POINT_SMOOTH_HINT, GL_FASTEST);
// glDisable(GL_TEXTURE_2D);
// glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
// //glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
//
//// glClearColor(0., 0., 0., 0.);
// glClearColor(BACKGROUND_COLOR_1_R, BACKGROUND_COLOR_1_G, BACKGROUND_COLOR_1_B, 1.0);
// glClear(GL_COLOR_BUFFER_BIT);
//
// glLineWidth(1.1);
// glPointSize(2.6);
//
// // ----------------- DRAW ----------------- ALL DRAWING HAPPENS BELOW THIS LINE
//
// // Calculate the total length of the envelope
// int totalEnvLength = symphony->getAmpEnvLength();
//
// // Calculate the percent length of each stage of the envelope
// double percentAttack = (double)symphony->getAmpEnvAttack()/(double)totalEnvLength;
// double percentDecay = (double)symphony->getAmpEnvDecay()/(double)totalEnvLength;
// double percentRelease = (double)symphony->getAmpEnvRelease()/(double)totalEnvLength;
//
// // Calculate scaled length of each envelope stage, relative to the window width
// int scaledAttackLength = percentAttack*width*0.9;
// int scaledDecayLength = percentDecay*width*0.9;
// int scaledReleaseLength = percentRelease*width*0.9;
//
// // Get sustain of envelope
// double sustain = symphony->getAmpEnvSustain();
//
// int currentIndex = 0;
//
// int envBottom = height*0.9;
//
// int x_indices[] = {0.0 + width*0.05,
// scaledAttackLength + width*0.05,
// currentIndex + scaledAttackLength + scaledDecayLength + width*0.05,
// currentIndex + scaledAttackLength + scaledDecayLength + scaledReleaseLength + width*0.05};
// int y_indices[] = {envBottom + height*0.05,
// height*0.05,
// (1.0-sustain)*envBottom + height*0.05,
// envBottom + height*0.05};
//
// // Draw envelope
// glBegin(GL_POLYGON);
// glColor4f(0.25, 0.75, 1.0, 0.2);
// glVertex2d(x_indices[0], y_indices[0]); // Start of envelope
// glVertex2d(x_indices[1], y_indices[1]); // Attack stage over
// glVertex2d(x_indices[2], y_indices[2]); // Decay stage over
// glVertex2d(x_indices[3], y_indices[3]); // Release stage over
// glEnd();
//
// // Draw envelope outline
// glBegin(GL_LINE_STRIP);
// glColor4f(0.25, 0.75, 1.0, 1.0);
// glVertex2d(x_indices[0], y_indices[0]); // Start of envelope
// glVertex2d(x_indices[1], y_indices[1]); // Attack stage over
// glVertex2d(x_indices[2], y_indices[2]); // Decay stage over
// glVertex2d(x_indices[3], y_indices[3]); // Release stage over
// glEnd();
//
// // Draw envelope points
// glPointSize(5.0);
// glBegin(GL_POINTS);
// glColor4f(0.25, 0.75, 1.0, 1.0);
// glVertex2d(x_indices[0], y_indices[0]); // Start of envelope
// glVertex2d(x_indices[1], y_indices[1]); // Attack stage over
// glVertex2d(x_indices[2], y_indices[2]); // Decay stage over
// glVertex2d(x_indices[3], y_indices[3]); // Release stage over
// glEnd();
//
// // Draw the waveform associated with the current wave type
// // glBegin(GL_LINE_STRIP);
// // for (int i=0; i<WAVETABLE_SIZE; i++) {
// // double x_value = ((double)(width*0.9*i)/(double)WAVETABLE_SIZE) + width*0.05;
// // double y_value = (1.0 - ((symphony->getWaveTableValueAtIndex(i) + 1.0)/2.0))*height*0.9 + height*0.05;
// // double distFromCenter = fabs(y_value - height/2);
// // glColor4f(0.0, 1.0, 0.0, 1.0*distFromCenter*2.0/(double)height);
// // glVertex2d(x_value, y_value);
// // }
// // glEnd();
//
// // Draw the line in the center of the waveform
// // glBegin(GL_LINE_STRIP);
// // glColor4f(0.0, 1.0, 0.0, 0.25);
// // glVertex2d(0, height/2);
// // glVertex2d(width, height/2);
// // glEnd();
//
// // Draw vertical lines from the waveform to the center
//// glColor4f(0.0, 1.0, 0.0, 0.25);
//// for (int i=0; i<WAVETABLE_SIZE; i += 100) {
//// glBegin(GL_LINE_STRIP);
//// double waveform_y = (1.0 - ((symphony->getWaveTableValueAtIndex(i) + 1.0)/2.0))*height*0.9 + height*0.05;
//// double center_y = height/2;
//// double offset_y = waveform_y - center_y;
//// int numSegs = 5;
//// double inc_y = offset_y/(double)numSegs;
//// double waveform_x = ((double)(width*0.9*i)/(double)WAVETABLE_SIZE) + width*0.05;
//// for (int j=0; j<numSegs+1; j++) {
//// glColor4f(0.0, 1.0, 0.0, 1.0*(double)j/(double)numSegs);
//// glVertex2d(waveform_x, center_y + inc_y*(double)j);
//// }
//// glEnd();
//// }
//
// // ----------------- END DRAW ----------------- ALL DRAWING HAPPENS ABOVE THIS LINE
//
//
// glFlush();
// glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
// glReadPixels(0, 0, width, height, GL_RGBA, GL_UNSIGNED_BYTE, mData.Get());
//
// // Delete the renderbuffer attachment
// glDeleteRenderbuffersEXT(1, &renderbuffer);
//
// // Make the window the target
// glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
// glDeleteFramebuffersEXT(1, &framebuffer);
//
// restoreContext();
//
// unsigned char* val = mData.Get();
//
// for(int v=0; v<height; v++)
// {
// for(int h=0; h<width; h++)
// {
// LICE_pixel pix = LICE_RGBA(*val, *(val + 1), *(val + 2), *(val + 3));
// LICE_PutPixel(pGraphics->GetDrawBitmap(), mRECT.L + h, mRECT.B - v, pix, 1., LICE_BLIT_MODE_COPY | LICE_BLIT_USE_ALPHA);
// val += 4;
// }
// }
//
// return true;
// }
//
// bool IsDirty()
// {
// return true;
// }
//};
//
//
//#endif /* EnvelopeOpenGL_hpp */