Package cs :: Module csModule
[hide private]
[frames] | no frames]

Source Code for Module cs.csModule

 1  #!/usr/bin/python 
 2  # -*- coding: latin-1 -*- 
 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   
18 -class CsoundThreadRoutine:
19
20 - def __init__(self, theTime):
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 # Create an instance of CppSound, set orchestra and score 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 # Export the orc and sco, compile. 40 self.csound.exportForPerformance() 41 self.csound.compile() 42 43 #self.performanceThread = csnd.CsoundPerformanceThread(self.csound) 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 #self.callbackdata = '' 55 #self.performanceThread.SetProcessCallback(self.callback, self.callbackdata) 56
57 - def csoundThreadRoutine(self):
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 #self.performanceThread.Play() 64 65 # until I can work with callbacks , I need to do this the old way, with performKsmps 66 while self.isRunning: 67 self.csound.PerformKsmps() 68 self.theTime.doKsmpsTick() 69 time.sleep(0)
70
71 - def stop(self):
72 """ 73 Terminate the csound performanceThread. 74 75 @param self: The object pointer. 76 """ 77 self.isRunning = False 78 print 'stopping csound' 79 #self.performanceThread.Stop() 80 #self.performanceThread.Join() 81 time.sleep(1) 82 # Clean up after ourselves. 83 self.csound.Reset() 84 self.csound.Cleanup()
85