1## Load and play the csd file
2
3d = q.loadDocument("audioin.csd")
4q.play(d)
5q.setDocument(q.getDocument("openGl.py"))
6
7##
8
9import PythonQt.QtGui as pqt
10import PythonQt.QtOpenGL as pgl
11from OpenGL.GL import *
12from OpenGL.GLU import *
13import math
14
15# From http://www.siafoo.net/snippet/316?nolinenos
16class SpiralWidget(pgl.QGLWidget):
17    '''
18    Widget for drawing two spirals.
19    '''
20
21    def __init__(self, parent):
22        pgl.QGLWidget.__init__(self, parent)
23        self.setMinimumSize(500, 500)
24        self.rms = 0
25
26    def setRms(self,rms):
27        self.rms = rms
28        self.updateGL()
29
30    def paintGL(self):
31        '''
32        Drawing routine
33        '''
34
35        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
36        glLoadIdentity()
37
38        glRotatef(self.rms *200, 0.0, 0.1, 1.0);
39
40        # Draw the spiral in 'immediate mode'
41        # WARNING: You should not be doing the spiral calculation inside the loop
42        # even if you are using glBegin/glEnd, sin/cos are fairly expensive functions
43        # I've left it here as is to make the code simpler.
44        radius = 1.0
45        x = radius*math.sin(0)
46        y = radius*math.cos(0)
47        glColor(0.0, 1.0, 0.0)
48        glBegin(GL_LINE_STRIP)
49        for deg in xrange(1000):
50            glVertex(x, y, 0.0)
51            rad = math.radians(deg)
52            radius -= 0.001
53            x = radius*math.sin(rad)
54            y = radius*math.cos(rad)
55        glEnd()
56
57        glEnableClientState(GL_VERTEX_ARRAY)
58
59        spiral_array = []
60
61        # Second Spiral using "array immediate mode" (i.e. Vertex Arrays)
62        radius = 0.8
63        x = radius*math.sin(0)
64        y = radius*math.cos(0)
65        glColor(1.0, 0.0, 0.0)
66        for deg in xrange(820):
67            spiral_array.append([x, y])
68            rad = math.radians(deg)
69            radius -= 0.001
70            x = radius*math.sin(rad)
71            y = radius*math.cos(rad)
72
73        glVertexPointerf(spiral_array)
74        glDrawArrays(GL_LINE_STRIP, 0, len(spiral_array))
75        glFlush()
76
77    def resizeGL(self, w, h):
78        '''
79        Resize the GL window
80        '''
81
82        glViewport(0, 0, w, h)
83        glMatrixMode(GL_PROJECTION)
84        glLoadIdentity()
85        gluPerspective(40.0, 1.0, 1.0, 30.0)
86
87    def initializeGL(self):
88        '''
89        Initialize GL
90        '''
91
92        # set viewing projection
93        glClearColor(0.0, 0.0, 0.0, 1.0)
94        glClearDepth(1.0)
95
96        glMatrixMode(GL_PROJECTION)
97        glLoadIdentity()
98        gluPerspective(40.0, 1.0, 1.0, 30.0)
99
100
101w = SpiralWidget(None)
102w.setGeometry(30,30, 256,256)
103w.show()
104
105## Pass value
106
107import time
108run = True
109
110while run:
111    rms = q.getChannelValue("rms", d)
112    w.setRms(rms * 20)
113    q.refresh()
114    time.sleep(0.02)
115
116## To stop passing values this line:
117run = False
118