[Csnd-dev] the ctcsound.setMessageCallback()
| Date | 2019-08-01 01:39 |
| From | "Worrall, David" |
| Subject | [Csnd-dev] the ctcsound.setMessageCallback() |
|
Hello All, I searched but couldn’t see a discussion on this so Perhaps I’m missing something….
I’m looking at the ctcsound equivalent or workaround for csnd6.SetMessageCallback()
In François’ documentation (thanks François), it says: https://csound.com/docs/ctcsound/ctcsound-API.html?highlight=setmessagecallback is says (my red)
Turns on the transmission of console messages to UDP on addr:port. If mirror is one, the messages will continue to be sent to the usual destination (see setMessageCallback()) as well as to UDP. Returns CSOUND_SUCCESS or CSOUND_ERROR if the UDP transmission could not be set up. and at http://pydoc.net/ctcsound/0.0.2/ctcsound/ it shows: #def setDefaultMessageCallback():
#def setMessageCallback(): Can someone please advise me, what the correct way of setting a callback message? This is what I used to do using csnd6: cs = csnd6.Csound() def passCallback(): pass # suppress all terminal output from CS TRACE = False if not TRACE: cs.SetMessageCallback(passCallback())
Many thanks, David
--- Dr David Worrall Professor, Audio Arts and Acoustics Columbia College Chicago 33 E. Ida B. Wells Drive Room 601A Chicago, ILLINOIS, USA 60605 Tel: (1)312.369.8821 Fax: (1)312.369.8427 Wikipedia: David Worrall Personal research/creative practice website: avatar.com.au Some music/sonification: on soundcloud Youtube videos
|
| Date | 2019-08-01 09:34 |
| From | Francois PINOT |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
Hi David, I didn't implement the setMessageCallback methods in ctcsound because actually ctypes cannot translate correctly the varlist arg. A workaround is to use the createMessageBuffer(False) method of the Csound object. This will redirect all the messages generated by Csound in a buffer that you can use as you want with the firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt() and destroyMessageBuffer() methods of the Csound object. Note that you should not use the pydoc version of ctcsound.py. ctcsound.py is part of Csound and it is distributed within each release of Csound. The reason is that if the API changes in a release, those modifications are reflected in the ctcsound.py file distributed with this release. I don't now who uploaded ctcsound.py to pydoc, but it wasn't a good idea. François Le jeu. 1 août 2019 à 02:39, Worrall, David <dworrall@colum.edu> a écrit :
|
| Date | 2019-08-01 19:25 |
| From | "Worrall, David" |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
Hi François, Thank you for your detailed reply. Much appreciated. I will try to implement an alternative, as you suggest.
I AM aware of the need to use the version of ctcsound that comes with the csound installer. Yesterday I was just searching quickly for online documentation…
On a related matter – should be a different post, I know :-) – I’m doing installations on many machines. I always install anaconda python first – and the csound installer picks it up OK. But somehow, access to ctcsound is not automatic.: following installation, sometimes python import it, othertimes not and I have to manually copy it to a general place. To make it a bit more complicated, Anaconda python does not use $PYTHONPATH. Do you have a suggestion/mod for how to ensure that, following installation, ctcsound will be available to the python used during the install?
Thank you for your assistance, and your work on this wonderful tool!
Regards,
David
--- Dr David Worrall Professor, Audio Arts and Acoustics Columbia College Chicago 33 E. Ida B. Wells Drive Room 601A Chicago, ILLINOIS, USA 60605 Tel: (1)312.369.8821 Fax: (1)312.369.8427 Wikipedia: David Worrall President, International Community for Auditory Display icad.org Personal research/creative practice website: avatar.com.au Some music/sonification: on soundcloud Youtube videos New Book: Sonification Design: From data to intelligible soundfields (Springer)
From:
Csound-developers <CSOUND-DEV@LISTSERV.HEANET.IE> on behalf of Francois PINOT <fggpinot@GMAIL.COM>
Hi David,
I didn't implement the setMessageCallback methods in ctcsound because actually ctypes cannot translate correctly the varlist arg. A workaround is to use the createMessageBuffer(False) method of the Csound object. This will redirect all the messages generated by Csound in a buffer that you can use as you want with the firstMessage(), firstMessageAttr(), popFirstMessage(), messageCnt() and destroyMessageBuffer() methods of the Csound object.
Note that you should not use the pydoc version of ctcsound.py. ctcsound.py is part of Csound and it is distributed within each release of Csound. The reason is that if the API changes in a release, those modifications are reflected in the ctcsound.py file distributed with this release. I don't now who uploaded ctcsound.py to pydoc, but it wasn't a good idea.
François
Le jeu. 1 août 2019 à 02:39, Worrall, David <dworrall@colum.edu> a écrit :
|
| Date | 2019-08-01 20:47 |
| From | Francois PINOT |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
Which OS on your machines? François Le jeu. 1 août 2019 à 20:25, Worrall, David <dworrall@colum.edu> a écrit :
|
| Date | 2019-08-01 22:07 |
| From | Eduardo Moguillansky |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
I don't know much about anaconda / conda, but using pip you can do pip install ctcsound==6.13 and that will ensure that you install that specific version
(otherwise it will install the latest version). When developing
your own package that depends on ctcsound you can add ctcsound to
the install_requires in the setup.py to automate the process. On 01.08.19 20:25, Worrall, David
wrote:
|
| Date | 2019-08-02 01:49 |
| From | "Worrall, David" |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
Sorry for the omission: OSX in this case. I suspect this is a csound install issue. Maybe not.
Is ctcsound the same across platforms for the same version of Csound?
Thanks, David
From:
Csound-developers <CSOUND-DEV@LISTSERV.HEANET.IE> on behalf of Francois PINOT <fggpinot@GMAIL.COM>
Which OS on your machines?
François
Le jeu. 1 août 2019 à 20:25, Worrall, David <dworrall@colum.edu> a écrit :
|
| Date | 2019-08-02 01:56 |
| From | "Worrall, David" |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
Hi Eduardo, Thanks for the tip. I’m trying to arrive at a method for our IT people to set up/maintain installations in several labs. Pip is part of the anaconda python packages so I’ll experiment with different versions/csound installations and see if that works.
David
--- Dr David Worrall Professor, Audio Arts and Acoustics Columbia College Chicago 33 E. Ida B. Wells Drive Room 601A Chicago, ILLINOIS, USA 60605 Tel: (1)312.369.8821 Fax: (1)312.369.8427 Wikipedia: David Worrall Personal research/creative practice website: avatar.com.au Some music/sonification: on soundcloud Youtube videos New Book: Sonification Design: From data to intelligible soundfields (Springer)
From:
Csound-developers <CSOUND-DEV@LISTSERV.HEANET.IE> on behalf of Eduardo Moguillansky <eduardo.moguillansky@GMAIL.COM>
I don't know much about anaconda / conda, but using pip you can do pip install ctcsound==6.13 and that will ensure that you install that specific version (otherwise it will install the latest version). When developing your own package that depends on ctcsound you can add ctcsound to the install_requires in the setup.py to automate the process. On 01.08.19 20:25, Worrall, David wrote:
|
| Date | 2019-08-02 07:40 |
| From | Francois PINOT |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
ctcsound is a pure Python library. It detects the platform where it is loaded (lines 38 to 45 in ctcsound.py) so that it can bind to the correct dynamic library. So it is effectively the same ctcsound.py file that is used on linux, window, and OSX. Actually Csound is built with Python 2.7.x due to the compilation of the Python opcodes. I recommend to use ctcsound with Python 3.x. On my linux system, I copy manually the ctcsound.py file into ~/.local/lib/python3.6/site-pacakages which is the user directory for Python3.6 packages, because the Csound build system put ctcsound.py into ~/.local/lib/python2.7/site-pacakages. You can display the python3 path on your system with this command: python3 -c "import sys; print(sys.path)" Then it is easy to write a script for copying ctcsound.py from the directory where the Csound installer put it into the python3 path. François Le ven. 2 août 2019 à 02:49, Worrall, David <dworrall@colum.edu> a écrit :
|
| Date | 2019-08-02 08:39 |
| From | joachim heintz |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
not sure it is what you (david) are asking, but i have this in my ~/.bashrc:
export PYTHONPATH=${PYTHONPATH}:/path/to/my/ctcsound/folder
and i have no issues to work with anaconda python or another python on
my (linux) system: 'import ctcsound' is always working.
joachim
On 02/08/19 08:40, Francois PINOT wrote:
> ctcsound is a pure Python library. It detects the platform where it is
> loaded (lines 38 to 45 in ctcsound.py) so that it can bind to the
> correct dynamic library. So it is effectively the same ctcsound.py file
> that is used on linux, window, and OSX.
>
> Actually Csound is built with Python 2.7.x due to the compilation of the
> Python opcodes. I recommend to use ctcsound with Python 3.x. On my linux
> system, I copy manually the ctcsound.py file into
> ~/.local/lib/python3.6/site-pacakages which is the user directory for
> Python3.6 packages, because the Csound build system put ctcsound.py into
> ~/.local/lib/python2.7/site-pacakages.
>
> You can display the python3 path on your system with this command:
> python3 -c "import sys; print(sys.path)"
>
> Then it is easy to write a script for copying ctcsound.py from the
> directory where the Csound installer put it into the python3 path.
>
> François
>
> Le ven. 2 août 2019 à 02:49, Worrall, David |
| Date | 2019-08-02 19:37 |
| From | "Worrall, David" |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
Ah, that’s an excellent explanation, thanks François. When I get a chance, I’ll test Eduardo’s pip install suggestion and report back.
– I suspect that will be a more robust solution for the tech support team. David
From:
Csound-developers <CSOUND-DEV@LISTSERV.HEANET.IE> on behalf of Francois PINOT <fggpinot@GMAIL.COM>
ctcsound is a pure Python library. It detects the platform where it is loaded (lines 38 to 45 in ctcsound.py) so that it can bind to the correct dynamic library. So it is effectively the same ctcsound.py file that is used on linux, window, and OSX.
Actually Csound is built with Python 2.7.x due to the compilation of the Python opcodes. I recommend to use ctcsound with Python 3.x. On my linux system, I copy manually the ctcsound.py file into ~/.local/lib/python3.6/site-pacakages which is the user directory for Python3.6 packages, because the Csound build system put ctcsound.py into ~/.local/lib/python2.7/site-pacakages.
You can display the python3 path on your system with this command: python3 -c "import sys; print(sys.path)"
Then it is easy to write a script for copying ctcsound.py from the directory where the Csound installer put it into the python3 path.
François
Le ven. 2 août 2019 à 02:49, Worrall, David <dworrall@colum.edu> a écrit :
|
| Date | 2019-08-02 19:38 |
| From | "Worrall, David" |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
Hi Joachim,
Thanks. Yes, that ‘normally’ works but, as I mentioned, Anaconda python doesn’t use $PYTHONPATH so it doesn’t work in that situation.
--- Dr David Worrall Professor, Audio Arts and Acoustics Columbia College Chicago 33 E. Ida B. Wells Drive Room 601A Chicago, ILLINOIS, USA 60605 Tel: (1)312.369.8821 Fax: (1)312.369.8427 Wikipedia: David Worrall President, International Community for Auditory Display icad.org Personal research/creative practice website: avatar.com.au Some music/sonification: on soundcloud Youtube videos New Book: Sonification Design: From data to intelligible soundfields (Springer)
From:
Csound-developers <CSOUND-DEV@LISTSERV.HEANET.IE> on behalf of joachim heintz <jh@JOACHIMHEINTZ.DE>
not sure it is what you (david) are asking, but i have this in my ~/.bashrc: export PYTHONPATH=${PYTHONPATH}:/path/to/my/ctcsound/folder
and i have no issues to work with anaconda python or another python on my (linux) system: 'import ctcsound' is always working.
joachim
On 02/08/19 08:40, Francois PINOT wrote:
|
| Date | 2019-08-02 19:50 |
| From | Victor Lazzarini |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
I suspect we will need to retire Python 2.x support in Csound 7.
Not sure whether we can keep backward compatibility if we update the code to 3.x
I am also not sure we should do this update
only to cause more problems in the future.
Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
| Date | 2019-08-04 16:01 |
| From | Francois PINOT |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
Actually most of the Python libraries have been updated for Python3 (see https://pythonclock.org/). We'd need to refactor the Python opcodes for Python3, the syntax of these opcodes remaining the same. Of course this would break backward compatibility. But adapting Python2 code to Python3 is not that hard. So I think th Le ven. 2 août 2019 à 20:50, Victor Lazzarini <Victor.Lazzarini@mu.ie> a écrit :
|
| Date | 2019-08-04 16:04 |
| From | Francois PINOT |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
Actually most of the Python libraries have been updated for Python3 (see https://pythonclock.org/).
We'd need to refactor the Python opcodes for Python3, the syntax of
these opcodes remaining the same. We'd leave csnd6.py too... Of course this would break backward
compatibility. But adapting Python2 code to Python3 is not that hard. So
I think that, in this particular case, we could make an exception about backward compatibility... François Le ven. 2 août 2019 à 20:50, Victor Lazzarini <Victor.Lazzarini@mu.ie> a écrit :
|
| Date | 2019-08-04 17:42 |
| From | Victor Lazzarini |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
Yes, the SWIG wrapper goes. I am just wondering how much of job it is to port the opcodes to Python 3, if the python API changed a lot. You probably have a much better idea of the magnitude of the task.
Victor Lazzarini
Dean of Arts, Celtic Studies, and Philosophy
Maynooth University
Ireland
|
| Date | 2019-08-04 18:02 |
| From | Francois PINOT |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
I think that Python 3 has many changes to the C API. I'll have a look. François Le dim. 4 août 2019 à 18:42, Victor Lazzarini <Victor.Lazzarini@mu.ie> a écrit :
|
| Date | 2019-08-04 20:25 |
| From | "Worrall, David" |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
FWIW, with the exception of print(), I rarely (never?) have Python 2.7.x code that doesn’t run in Python3. The v2 >>> print x,y Can be implemented in v3 as >>> print (x,y) which also works in v2.
There is a problem occurring w. v2 ‘print but don’t linefeed’ : >>> print x , ; print y # uses the comma to suspend line feed
This can be implemented in v3 as >>> print (x, end=’’) ; print (y)
But the “end=” argument is not available in v2 print(). Which renders print incompatible in that operation.
-drw --- Dr David Worrall Professor, Audio Arts and Acoustics Columbia College Chicago Wikipedia: David Worrall Personal research/creative practice website: avatar.com.au Some music/sonification: on soundcloud Youtube videos New Book: Sonification Design: From data to intelligible soundfields (Springer)
From:
Csound-developers <CSOUND-DEV@LISTSERV.HEANET.IE> on behalf of Victor Lazzarini <Victor.Lazzarini@MU.IE>
Yes, the SWIG wrapper goes. I am just wondering how much of job it is to port the opcodes to Python 3, if the python API changed a lot. You probably have a much better idea of the magnitude of the task.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|
| Date | 2019-08-04 20:29 |
| From | "Worrall, David" |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
|
Are you referring to just the embedded python/opcode, or other situations as well?
--- Dr David Worrall Professor, Audio Arts and Acoustics Columbia College Chicago Wikipedia: David Worrall Personal research/creative practice website: avatar.com.au Some music/sonification: on soundcloud Youtube videos New Book: Sonification Design: From data to intelligible soundfields (Springer)
From:
Csound-developers <CSOUND-DEV@LISTSERV.HEANET.IE> on behalf of Victor Lazzarini <Victor.Lazzarini@MU.IE>
I suspect we will need to retire Python 2.x support in Csound 7.
Not sure whether we can keep backward compatibility if we update the code to 3.x
I am also not sure we should do this update only to cause more problems in the future.
Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy Maynooth University Ireland
|
| Date | 2019-08-04 20:53 |
| From | Victor Lazzarini |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
I am referring to opcodes. The Csound API access is guaranteed across versions by ctcsound. ======================== Prof. Victor Lazzarini Dean of Arts, Celtic Studies, and Philosophy, Maynooth University, Maynooth, Co Kildare, Ireland Tel: 00 353 7086936 Fax: 00 353 1 7086952 > On 4 Aug 2019, at 20:29, Worrall, David |
| Date | 2019-08-04 20:57 |
| From | Francois PINOT |
| Subject | Re: [Csnd-dev] the ctcsound.setMessageCallback() |
There's a bit more; see here for example: https://sebastianraschka.com/Articles/2014_python_2_3_key_diff.html. If we move the python opcodes to Python3, some orchestra using these opcodes might need a lot of changes depending on the way they use Python... François Le dim. 4 août 2019 à 21:26, Worrall, David <dworrall@colum.edu> a écrit :
|