def createChannel(csound, channelName): "Creates a Csound Channel and returns a CsoundMYFLTArray wrapper object" chn = csnd6.CsoundMYFLTArray(1) csound.GetChannelPtr( chn.GetPtr(), channelName, csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_INPUT_CHANNEL) return chn
def fill_table(self, tabnum, arr): '''Create or fill a Csound f-table with the values passed in the arr variable. This variable can be a python list or a numpy array. Having ctypes installed will make this function significantly faster''' if type(arr) != np.ndarray and type(arr) != list and type( arr) != tuple: raise TypeError("Argument is not array, list or tuple") if type(arr) == np.ndarray and arr.ndim > 1: raise ValueError("Only one dimensional arrays are valid") if self._client_addr: data = ', '.join(map(str, arr)) data = 'gitemp ftgen %i, 0, %i, -2, ' % (tabnum, len(arr)) + data self.send_code(data) return if use_ctypes: tbl = csnd6.CsoundMYFLTArray() # FIXME what about guard point? tblSize = self._cs.GetTable(tbl.GetPtr(), tabnum) # Needs + 1 due to guard point if tblSize <= 0: self._debug_print("Creating table ", tabnum) self.make_table(tabnum, len(arr), 2, 0) tblSize = self._cs.GetTable(tbl.GetPtr(), tabnum) elif not tblSize == len(arr): self._debug_print("Resizing table", tabnum, "from", tblSize, "to", len(arr)) self.make_table(tabnum, len(arr), 2, 0) tblSize = self._cs.GetTable(tbl.GetPtr(), tabnum) if self._myfltsize == 8: myflt = ctypes.c_double else: myflt = ctypes.c_float cs_ftable = ctypes.ARRAY(myflt, tblSize).from_address( tbl.GetPtr(0).__long__()) if type(arr) == np.ndarray: src_array = arr.astype(np.float64).ctypes.data_as( ctypes.POINTER(myflt)) else: fltarray = myflt * len(arr) src_array = fltarray(*arr) ctypes.memmove(cs_ftable, src_array, len(arr) * self._myfltsize) else: data = ', '.join(map(str, arr)) data = 'gitemp ftgen %i, 0, %i, -2, ' % (tabnum, len(arr)) + data self.send_code(data)
def createChannel(csound, channelName): chn = csnd6.CsoundMYFLTArray(1) csound.GetChannelPtr( chn.GetPtr(), channelName, csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_INPUT_CHANNEL) return chn
aout moogladder aout, 2000, 0.25 outs aout, aout endin""" c = csnd6.Csound() # create an instance of Csound c.SetOption("-odac") # Set option for Csound c.SetOption("-m7") # Set option for Csound c.CompileOrc(orc) # Compile Orchestra from String sco = "i1 0 60\n" c.ReadScore(sco) # Read in Score generated from notes c.Start() # When compiling from strings, this call is necessary before doing any performing ampChannel = csnd6.CsoundMYFLTArray(1) # create a CsoundMYFLTArray of size 1 freqChannel = csnd6.CsoundMYFLTArray(1) # create a CsoundMYFLTArray of size 1 # the following calls store the Channel Pointer retreived from Csound into the # CsoundMYFLTArray Objects c.GetChannelPtr(ampChannel.GetPtr(), "amp", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_INPUT_CHANNEL) c.GetChannelPtr(freqChannel.GetPtr(), "freq", csnd6.CSOUND_CONTROL_CHANNEL | csnd6.CSOUND_INPUT_CHANNEL) amp = RandomLine(.4, .2) freq = RandomLine(400, 80) ampChannel.SetValue(0, amp.getValue()) # note we are now setting values on the CsoundMYFLTArray freqChannel.SetValue(0, freq.getValue())