1
2
3
4 """
5 Handles communication between Python and Csound.
6
7 @author: Øyvind Brandtsegg
8 @contact: obrandts@gmail.com
9 @license: GPL
10 @requires: csnd
11 @requires: random
12 """
13
14 import csnd
15 import random
16
18 """This class handles all communication between Python and the csound instance."""
19
20 - def __init__(self, csound, performanceThread):
29
38
39
41 """
42 Returns a list of all allocated bus channels between Python and Csound.
43
44 @param self: The object pointer.
45 @return: Channel list.
46 """
47 chnlst = csnd.CsoundChannelList(self.csound)
48 channelList = []
49 n = chnlst.Count()
50 for i in range(n):
51 item = []
52 item.append(chnlst.Name(i))
53 if chnlst.IsControlChannel(i):
54 item.append('control')
55 elif chnlst.IsAudioChannel(i):
56 item.append('audio')
57 elif chnlst.IsStringChannel(i):
58 item.append('string')
59 channelList.append(item)
60 return channelList
61
63 """
64 Prints a list of all allocated bus channels between python and csound.
65
66 @param self: The object pointer.
67 """
68 chnlst = csnd.CsoundChannelList(self.csound)
69
70 n = chnlst.Count()
71 if n > 0:
72 print '============================================================'
73 print 'Csound chn channels listing'
74 print 'Currently using', n, 'channels'
75 print '------------------------------------------------------------'
76 for i in range(n):
77 print 'Name:', chnlst.Name(i)
78 if chnlst.IsControlChannel(i):
79 print ' | Type: control', '| Input:', ['no', 'yes'][chnlst.IsInputChannel(i)], '| Output:', ['no', 'yes'][chnlst.IsOutputChannel(i)]
80 elif chnlst.IsAudioChannel(i):
81 print ' | Type: audio', '| Input:', ['no', 'yes'][chnlst.IsInputChannel(i)], '| Output:', ['no', 'yes'][chnlst.IsOutputChannel(i)]
82 elif chnlst.IsStringChannel(i):
83 print ' | Type: string', '| Input:', ['no', 'yes'][chnlst.IsInputChannel(i)], '| Output:', ['no', 'yes'][chnlst.IsOutputChannel(i)]
84
86 """
87 Get the value stored in a csound chn channel
88
89 @param self: The object pointer.
90 @param name: The name of the channel to be interrogated.
91 @return: The value of the channel
92 """
93 return self.csound.GetChannel(name)
94
95
97 """
98 Send a control value to csound, using the software bus and chn opcode in csound.
99
100 @param self: The object pointer.
101 @param channelName: Channel name.
102 @param value: The value to be sent to the designated channel.
103 """
104 self.csound.SetChannel(channelName, value)
105
107 """
108 Wrapper for self.sendControlToCsound(), using channels name and value as a list.
109
110 @param self: The object pointer.
111 @param channelNameAndValue: Channel name and value as a list.
112 """
113 channelName, value = channelNameAndValue
114 print channelName, value
115 self.csound.SetChannel(channelName, value)
116