Csound Csound-dev Csound-tekno Search About

Re: [Cs-dev] Csound API Question?

Date2010-10-10 02:08
From"Art Hunkins"
SubjectRe: [Cs-dev] Csound API Question?
Victor,

Thanks for your code example and assurance that the Csound API is in great 
shape. (I think that the only remaining darkness is in my head.)

Indeed I hadn't used SetChannel as needed. Reason? I've hardly had to, 
because of my thoroughgoing use of your excellent csndsugui package. (I 
simply forgot you had to do this.)

Modeling after your example as closely as feasible, I added these lines (in 
filemix.py) to my import header:
import csnd
cs = csnd.Csound()

This became my chooser method (which I should think would send the filename 
to my .csd file - which remains the same as previously):
 def choose(self, widget):
  chooser =  ObjectChooser(self, what_filter=mime.GENERIC_TYPE_AUDIO)
  result = chooser.run()
  if result == gtk.RESPONSE_ACCEPT:
    jobject = chooser.get_selected_object()
    if jobject and jobject.file_path:
      filename1 = jobject.file_path
      print 'FileName = ', filename1
      cs.SetChannel("filename1", filename1)

However the result is as before: what is passed is "0", which means my code 
defaults to (and prints out) my default internal file, soundin.1.

Here are the (now expanded) log error/warning messages:
1286670270.971350 WARNING root: Invocation of ObjectChooser() has deprecated 
parameters.
/usr/lib/python2.6/site-packages/dbus/connection.py:242: DeprecationWarning: 
object.__init__() takes no parameters
super(Connection, self).__init__(*args, **kwargs)
FileName = 
/home/liveuser/.sugar/default/data/9b3f3023-58f1-44ad-87c3-c19d2a7561ae.ogg
Traceback (most recent call last):
File "/home/liveuser/Activities/FileMix.activity/filemix.py", line 216, in 
choose
cs.SetChannel("filename1", filename1)
File "/usr/lib/python2.6/site-packages/csnd.py", line 1736, in SetChannel
return _csnd.Csound_SetChannel(self, *args)
NotImplementedError: Wrong number of arguments for overloaded function 
'Csound_SetChannel'.
Possible C/C++ prototypes are:
SetChannel(Csound *,char const *,double)
SetChannel(Csound *,char const *,char const *)

I feel I've taken a step backwards. At the same time, I'm very grateful for 
your enlightenment (or for that of any other more technically astute 
Csounder than I).

(I wonder if the filename is of the wrong type or some such, needing a cast 
of some sort?)

Ever appreciative -

Art Hunkins

----- Original Message ----- 
From: "Victor Lazzarini" 
To: "Developer discussions" 
Sent: Friday, October 08, 2010 7:15 PM
Subject: Re: [Cs-dev] Csound API Question?


> For instance the following Python code:
>
> import csnd
> cs = csnd.Csound()
> cs.Compile("string.csd", "-n")
> cs.SetChannel("filename1", "haha")
> cs.Perform()
>
> ============ string.csd: =========
>
> 
> 
> instr 1
> Sname chnget "filename1"
> puts Sname, 1
> endin
> 
> 
> i1 0 1
> 
> 
>
> ============= interactive run =======
> Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
> >>> import csnd
> >>> cs = csnd.Csound()
> >>> cs.Compile("string.csd", "-n")
> PortMIDI real time MIDI plugin for Csound
> PortAudio real-time audio module for Csound
> virtual_keyboard real time MIDI plugin for Csound
> 0dBFS level = 32768.0
> Csound version 5.12 (double samples) Jun  9 2010
> libsndfile-1.0.21
> UnifiedCSD:  string.csd
> STARTING FILE
> Creating options
> Creating orchestra
> Creating score
> orchname:  /var/folders/5P/5PSrqM3mGnCIxRlBhio0cE+++TM/-Tmp-//csound-
> gtttlC.orc
> scorename: /var/folders/5P/5PSrqM3mGnCIxRlBhio0cE+++TM/-Tmp-//csound-
> hz4vNl.sco
> rtaudio: PortAudio module enabled ... using callback interface
> rtmidi: PortMIDI module enabled
> orch compiler:
> instr 1
> Elapsed time at end of orchestra compile: real: 0.070s, CPU: 0.004s
> sorting score ...
> ... done
> Elapsed time at end of score sort: real: 0.152s, CPU: 0.023s
> Csound version 5.12 (double samples) Jun  9 2010
> 0dBFS level = 32768.0
> orch now loaded
> audio buffered in 1024 sample-frame blocks
> not writing to sound disk
> SECTION 1:
> 0
> >>> cs.SetChannel("filename1", "haha")
> >>> cs.Perform()
> new alloc for instr 1:
> haha
> B  0.000 ..100.000 T100.000 TT100.000 M:      0.0
> Score finished in csoundPerform().
> 2
> >>> exit()
> inactive allocs returned to freespace
> end of score.    overall amps:      0.0
>    overall samples out of range:        0
> 0 errors in performance
> Elapsed time at end of performance: real: 61.690s, CPU: 0.362s
> no sound written to disk
>
> ==================
> NB: there is nothing wrong with the API.
>
> Victor
>
> On 9 Oct 2010, at 00:05, Victor Lazzarini wrote:
>
>> Where is the call to pass the filename to Csound?
>>
>> Victor
>>
>> On 8 Oct 2010, at 22:12, Art Hunkins wrote:
>>
>>> At least I *think* it's an API/communication problem, rather than a
>>> Python/pygtk problem.
>>>
>>> Here's the situation: I'm getting users to click on a Journal entry
>>> in Sugar
>>> (python 2.6 - Sugar 0.84, FWIW), to identify a user-supplied
>>> soundfile to
>>> load into diskin2. It's close to working.
>>>
>>> The Python side:
>>> This statement is in the main loop:
>>> self.filename1 = "0" (or "" - they both work the same)
>>>
>>> In the method in question, the Journal selection process seems to be
>>> working; the code ends with:
>>>     self.filename1 = jobject.file_path
>>>     print 'FileName = ', self.filename1
>>>     return self.filename1
>>>
>>> Through the print line, things seem to work; the following line is
>>> printed
>>> (in the log), with data (filename/path) one would expect:
>>> FileName =
>>> /home/liveuser/.sugar/default/data/9b3f3023-58f1-44ad-87c3-
>>> c19d2a7561ae.ogg
>>>
>>> (BTW, this is Csound 5.10 with a recent libsndfile that accepts Ogg
>>> Vorbis
>>> files - of which the above is one.)
>>>
>>> At this point the filename does not appear to transfer via the API to
>>> Csound. The Csound side (within an instrument definition):
>>> Sname   chnget "filename1"
>>> puts Sname, 1
>>> i1      strcmp  Sname, "0"
>>>       if i1 == 0 goto cont2
>>> Sname   =       "soundin.1"
>>>       goto cont2
>>>
>>> Problem result:
>>> 1) puts prints a blank line.
>>> 2) strcmp evaluates to "0", which is the "no file name to
>>> communicate"
>>> value.
>>> 3) as a result, the default file, soundin1, is substituted. Here
>>> there is
>>> always a substitution.
>>>
>>> Bottom line: the (very long/complicated) filename seems not to be
>>> passed.
>>> Does anyone know why? (IOW, what am I doing wrong?)
>>>
>>> TIA for insight -
>>>
>>> Art Hunkins
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Beautiful is writing same markup. Internet Explorer 9 supports
>>> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
>>> Spend less time writing and  rewriting code and more time creating
>>> great
>>> experiences on the web. Be a part of the beta today.
>>> http://p.sf.net/sfu/beautyoftheweb
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> ------------------------------------------------------------------------------
>> Beautiful is writing same markup. Internet Explorer 9 supports
>> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
>> Spend less time writing and  rewriting code and more time creating
>> great
>> experiences on the web. Be a part of the beta today.
>> http://p.sf.net/sfu/beautyoftheweb
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> Spend less time writing and  rewriting code and more time creating great
> experiences on the web. Be a part of the beta today.
> http://p.sf.net/sfu/beautyoftheweb
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel 


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net

Date2010-10-10 10:08
FromVictor Lazzarini
SubjectRe: [Cs-dev] Csound API Question?
I think this means that one of the arguments is of the wrong type,  
which means.
jobject.file_path. This line in your printed messages

FileName =

seems to indicate that it is not a string and the line

print 'FileName = ', filename1

is not printing it.

Try, just to test it, placing a string (any) instead of that argument  
and see if you get
a result.

Victor

> File "/usr/lib/python2.6/site-packages/csnd.py", line 1736, in  
> SetChannel
> return _csnd.Csound_SetChannel(self, *args)
> NotImplementedError: Wrong number of arguments for overloaded function
> 'Csound_SetChannel'.
> Possible C/C++ prototypes are:
> SetChannel(Csound *,char const *,double)
> SetChannel(Csound *,char const *,char const *)
>
> I feel I've taken a step backwards. At the same time, I'm very  
> grateful for
> your enlightenment (or for that of any other more technically astute
> Csounder than I).
>
> (I wonder if the filename is of the wrong type or some such, needing  
> a cast
> of some sort?)
>
> Ever appreciative -
>
> Art Hunkins
>
> ----- Original Message -----
> From: "Victor Lazzarini" 
> To: "Developer discussions" 
> Sent: Friday, October 08, 2010 7:15 PM
> Subject: Re: [Cs-dev] Csound API Question?
>
>
>> For instance the following Python code:
>>
>> import csnd
>> cs = csnd.Csound()
>> cs.Compile("string.csd", "-n")
>> cs.SetChannel("filename1", "haha")
>> cs.Perform()
>>
>> ============ string.csd: =========
>>
>> 
>> 
>> instr 1
>> Sname chnget "filename1"
>> puts Sname, 1
>> endin
>> 
>> 
>> i1 0 1
>> 
>> 
>>
>> ============= interactive run =======
>> Python 2.6.4 (r264:75821M, Oct 27 2009, 19:48:32)
>> [GCC 4.0.1 (Apple Inc. build 5493)] on darwin
>> Type "help", "copyright", "credits" or "license" for more  
>> information.
>>>>> import csnd
>>>>> cs = csnd.Csound()
>>>>> cs.Compile("string.csd", "-n")
>> PortMIDI real time MIDI plugin for Csound
>> PortAudio real-time audio module for Csound
>> virtual_keyboard real time MIDI plugin for Csound
>> 0dBFS level = 32768.0
>> Csound version 5.12 (double samples) Jun  9 2010
>> libsndfile-1.0.21
>> UnifiedCSD:  string.csd
>> STARTING FILE
>> Creating options
>> Creating orchestra
>> Creating score
>> orchname:  /var/folders/5P/5PSrqM3mGnCIxRlBhio0cE+++TM/-Tmp-//csound-
>> gtttlC.orc
>> scorename: /var/folders/5P/5PSrqM3mGnCIxRlBhio0cE+++TM/-Tmp-//csound-
>> hz4vNl.sco
>> rtaudio: PortAudio module enabled ... using callback interface
>> rtmidi: PortMIDI module enabled
>> orch compiler:
>> instr 1
>> Elapsed time at end of orchestra compile: real: 0.070s, CPU: 0.004s
>> sorting score ...
>> ... done
>> Elapsed time at end of score sort: real: 0.152s, CPU: 0.023s
>> Csound version 5.12 (double samples) Jun  9 2010
>> 0dBFS level = 32768.0
>> orch now loaded
>> audio buffered in 1024 sample-frame blocks
>> not writing to sound disk
>> SECTION 1:
>> 0
>>>>> cs.SetChannel("filename1", "haha")
>>>>> cs.Perform()
>> new alloc for instr 1:
>> haha
>> B  0.000 ..100.000 T100.000 TT100.000 M:      0.0
>> Score finished in csoundPerform().
>> 2
>>>>> exit()
>> inactive allocs returned to freespace
>> end of score.    overall amps:      0.0
>>   overall samples out of range:        0
>> 0 errors in performance
>> Elapsed time at end of performance: real: 61.690s, CPU: 0.362s
>> no sound written to disk
>>
>> ==================
>> NB: there is nothing wrong with the API.
>>
>> Victor
>>
>> On 9 Oct 2010, at 00:05, Victor Lazzarini wrote:
>>
>>> Where is the call to pass the filename to Csound?
>>>
>>> Victor
>>>
>>> On 8 Oct 2010, at 22:12, Art Hunkins wrote:
>>>
>>>> At least I *think* it's an API/communication problem, rather than a
>>>> Python/pygtk problem.
>>>>
>>>> Here's the situation: I'm getting users to click on a Journal entry
>>>> in Sugar
>>>> (python 2.6 - Sugar 0.84, FWIW), to identify a user-supplied
>>>> soundfile to
>>>> load into diskin2. It's close to working.
>>>>
>>>> The Python side:
>>>> This statement is in the main loop:
>>>> self.filename1 = "0" (or "" - they both work the same)
>>>>
>>>> In the method in question, the Journal selection process seems to  
>>>> be
>>>> working; the code ends with:
>>>>    self.filename1 = jobject.file_path
>>>>    print 'FileName = ', self.filename1
>>>>    return self.filename1
>>>>
>>>> Through the print line, things seem to work; the following line is
>>>> printed
>>>> (in the log), with data (filename/path) one would expect:
>>>> FileName =
>>>> /home/liveuser/.sugar/default/data/9b3f3023-58f1-44ad-87c3-
>>>> c19d2a7561ae.ogg
>>>>
>>>> (BTW, this is Csound 5.10 with a recent libsndfile that accepts Ogg
>>>> Vorbis
>>>> files - of which the above is one.)
>>>>
>>>> At this point the filename does not appear to transfer via the  
>>>> API to
>>>> Csound. The Csound side (within an instrument definition):
>>>> Sname   chnget "filename1"
>>>> puts Sname, 1
>>>> i1      strcmp  Sname, "0"
>>>>      if i1 == 0 goto cont2
>>>> Sname   =       "soundin.1"
>>>>      goto cont2
>>>>
>>>> Problem result:
>>>> 1) puts prints a blank line.
>>>> 2) strcmp evaluates to "0", which is the "no file name to
>>>> communicate"
>>>> value.
>>>> 3) as a result, the default file, soundin1, is substituted. Here
>>>> there is
>>>> always a substitution.
>>>>
>>>> Bottom line: the (very long/complicated) filename seems not to be
>>>> passed.
>>>> Does anyone know why? (IOW, what am I doing wrong?)
>>>>
>>>> TIA for insight -
>>>>
>>>> Art Hunkins
>>>>
>>>>
>>>> ------------------------------------------------------------------------------
>>>> Beautiful is writing same markup. Internet Explorer 9 supports
>>>> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
>>>> Spend less time writing and  rewriting code and more time creating
>>>> great
>>>> experiences on the web. Be a part of the beta today.
>>>> http://p.sf.net/sfu/beautyoftheweb
>>>> _______________________________________________
>>>> Csound-devel mailing list
>>>> Csound-devel@lists.sourceforge.net
>>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Beautiful is writing same markup. Internet Explorer 9 supports
>>> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
>>> Spend less time writing and  rewriting code and more time creating
>>> great
>>> experiences on the web. Be a part of the beta today.
>>> http://p.sf.net/sfu/beautyoftheweb
>>> _______________________________________________
>>> Csound-devel mailing list
>>> Csound-devel@lists.sourceforge.net
>>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>>
>>
>> ------------------------------------------------------------------------------
>> Beautiful is writing same markup. Internet Explorer 9 supports
>> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
>> Spend less time writing and  rewriting code and more time creating  
>> great
>> experiences on the web. Be a part of the beta today.
>> http://p.sf.net/sfu/beautyoftheweb
>> _______________________________________________
>> Csound-devel mailing list
>> Csound-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/csound-devel
>
>
> ------------------------------------------------------------------------------
> Beautiful is writing same markup. Internet Explorer 9 supports
> standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
> Spend less time writing and  rewriting code and more time creating  
> great
> experiences on the web. Be a part of the beta today.
> http://p.sf.net/sfu/beautyoftheweb
> _______________________________________________
> Csound-devel mailing list
> Csound-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/csound-devel


------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Csound-devel mailing list
Csound-devel@lists.sourceforge.net