1
2
3
4 """
5 A separate thread which keeps Csound output going.
6
7 @author: Øyvind Brandtsegg
8 @contact: obrandts@gmail.com
9 @license: GPL
10 @requires: threading
11 """
12
13 import csnd
14 import csoundCommandline
15 import threading
16 import time
17
19
21 """
22 Class constructor.
23
24 @param self: The object pointer.
25 """
26
27 self.isRunning = True
28 """A flag that keeps the thread running, can be deleted when we start using csnd.PerformanceThread properly"""
29
30
31 self.csound = csnd.CppSound()
32 self.csound.setOrchestra('''#include "simple.orc" ''')
33 self.csound.setScore('''#include "simple.sco" ''')
34
35 self.csound.setCommand(csoundCommandline.csoundCommandline)
36 """The Csound commandline read from file "csoundCommandLine.py", setting options for audio i/o and buffers."""
37 print 'commandline', csoundCommandline.csoundCommandline
38
39
40 self.csound.exportForPerformance()
41 self.csound.compile()
42
43
44 """The C++ csound performance thread"""
45
46 self.theTime = theTime
47 """Pointer to the precise timed queue."""
48 self.theTime.setTimePerKperiod(self.csound.GetKr())
49 """Set control rate for the timed queue clock."""
50
51 self.csoundThread = threading.Thread(None, self.csoundThreadRoutine)
52 """The csoundThreadRoutine is run in it's own thread"""
53
54
55
56
58 """
59 Start the performanceThread, a C++ thread for running csound, independent from the Python GIL.
60
61 @param self: The object pointer.
62 """
63
64
65
66 while self.isRunning:
67 self.csound.PerformKsmps()
68 self.theTime.doKsmpsTick()
69 time.sleep(0)
70
72 """
73 Terminate the csound performanceThread.
74
75 @param self: The object pointer.
76 """
77 self.isRunning = False
78 print 'stopping csound'
79
80
81 time.sleep(1)
82
83 self.csound.Reset()
84 self.csound.Cleanup()
85