[Csnd] A couple of questions about CSound and Python

Hi all,

I am new to both CSound and this list. I am also learning Python, and would like to combine the two, once I become good enough at both. However, I have a couple of questions at this point. I am unsure if this is the correct list to ask these questions, but I’ll try. If they should be asked on the developer list, please let me know.

My first question is, is there any particular reason that I must use Jupyter Notebooks, apart from the fact that the various examples of code are meant to be used with it? I’ll use it, if I absolutely have to, but I would prefer not to do so, if it is possible. As far as I can tell, the code can be written in any normal editor for text or code, and I even tried an example in the Python interactive interpreter with success. So is Jupyter Notebooks really necessary, and if so, why?

My second question is about porting CSound to Work with Python 3. I know, it’s not a big deal for me to install Python 2.7, but I personally think, it would be nicer to have only one version of Python to Work with, especially if I want to distribute programs, I create, to others. The less stuff to install, the better in my opinion. The Floss manual talks about a plugin, and I looked at the Github page, but I’m not sure what to do from there. Can anyone explain how to actually use this plugin to port CSound? I have always worked with Python 3, so I don’t have any prior experience with porting from Python 2.

Thanks in advance,

Susanne Pedersen

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

hi susanne -

working in the jupyter notebooks is certainly only one option..

and ctcsound is python3: GitHub - csound/ctcsound: Python Bindings for Csound using ctypes. Can be used from python2.x and python3.x as well.

(assuming you speak about using csound via API in python, not python integrated in csound.)

best -
  joachim

Hi all,

I am new to both CSound and this list. I am also learning Python, and would like to combine the two, once I become good enough at both. However, I have a couple of questions at this point. I am unsure if this is the correct list to ask these questions, but I’ll try. If they should be asked on the developer list, please let me know.

My first question is, is there any particular reason that I must use Jupyter Notebooks, apart from the fact that the various examples of code are meant to be used with it? I’ll use it, if I absolutely have to, but I would prefer not to do so, if it is possible. As far as I can tell, the code can be written in any normal editor for text or code, and I even tried an example in the Python interactive interpreter with success. So is Jupyter Notebooks really necessary, and if so, why?

My second question is about porting CSound to Work with Python 3. I know, it’s not a big deal for me to install Python 2.7, but I personally think, it would be nicer to have only one version of Python to Work with, especially if I want to distribute programs, I create, to others. The less stuff to install, the better in my opinion. The Floss manual talks about a plugin, and I looked at the Github page, but I’m not sure what to do from there. Can anyone explain how to actually use this plugin to port CSound? I have always worked with Python 3, so I don’t have any prior experience with porting from Python 2.

Thanks in advance,

Susanne Pedersen

Examples using ctcsound.py with Python 3 and without using Jupyter can be seen here: https://github.com/csound/csoundAPI_examples/tree/master/python/py3

François

Hi Susanne,

Welcome to the community, and wonderful idea to combine Csound and Python! The two languages complement each other very nicely and you will be able to build some very nice things with them together. You can run Python as the main program and load Csound as a module (with ctcsound) and this works with Python 3. No need to use Jupyter unless you find it helpful. This is the most standard way of combining Csound and Python, and will work well for most purposes.

Another way is to run Csound as the main program and then access Python via the py opcodes (e.g. pycall, pyrun etc), and this is probably the reason why you thought that you needed Python 2 (as the py opcodes are compiled for a specific Python version and have not yet been updated for Python 3). There are some limitations with the py opcodes that makes it slightly cumbersome to work with, so I would not recommend that route unless you really need it.

Yet another way that I have been using more and more is to run the two programs as separate processes and just use OSC to communicate between them. This can be useful for example if I wrap the Csound instruments as VSTs to run in a DAW, and I do not want the Python interpreter to potentially interfere with the audio thread of the whole DAW. Running Python as a server in the background allows Csound then to run very lightweight and only be taxed with producing audio in realtime, then Csound can poll the Python server for data values to use for note parameters and similar.

As Francois mentioned, the ctcsound examples are a good place to start. I just wanted to mention these other possibilities to fill out the context.

All best
Øyvind Brandtsegg

In fact the py opcodes have been ported to Python 3. They’re not distributed with the core Csound release anymore. They are available in the plugins repository (https://github.com/csound/plugins), as they depend on third party libraries.

François

Oh, that is great. Thanks!

man. 10. jan. 2022 kl. 14:00 skrev Francois PINOT <fggpinot@gmail.com>:

In fact the py opcodes have been ported to Python 3. They’re not distributed with the core Csound release anymore. They are available in the plugins repository (https://github.com/csound/plugins), as they depend on third party libraries.

François

Hi Susanne,

Welcome to the community, and wonderful idea to combine Csound and Python! The two languages complement each other very nicely and you will be able to build some very nice things with them together. You can run Python as the main program and load Csound as a module (with ctcsound) and this works with Python 3. No need to use Jupyter unless you find it helpful. This is the most standard way of combining Csound and Python, and will work well for most purposes.

Another way is to run Csound as the main program and then access Python via the py opcodes (e.g. pycall, pyrun etc), and this is probably the reason why you thought that you needed Python 2 (as the py opcodes are compiled for a specific Python version and have not yet been updated for Python 3). There are some limitations with the py opcodes that makes it slightly cumbersome to work with, so I would not recommend that route unless you really need it.

Yet another way that I have been using more and more is to run the two programs as separate processes and just use OSC to communicate between them. This can be useful for example if I wrap the Csound instruments as VSTs to run in a DAW, and I do not want the Python interpreter to potentially interfere with the audio thread of the whole DAW. Running Python as a server in the background allows Csound then to run very lightweight and only be taxed with producing audio in realtime, then Csound can poll the Python server for data values to use for note parameters and similar.

As Francois mentioned, the ctcsound examples are a good place to start. I just wanted to mention these other possibilities to fill out the context.

All best
Øyvind Brandtsegg

Hi all,

I am new to both CSound and this list. I am also learning Python, and would like to combine the two, once I become good enough at both. However, I have a couple of questions at this point. I am unsure if this is the correct list to ask these questions, but I’ll try. If they should be asked on the developer list, please let me know.

My first question is, is there any particular reason that I must use Jupyter Notebooks, apart from the fact that the various examples of code are meant to be used with it? I’ll use it, if I absolutely have to, but I would prefer not to do so, if it is possible. As far as I can tell, the code can be written in any normal editor for text or code, and I even tried an example in the Python interactive interpreter with success. So is Jupyter Notebooks really necessary, and if so, why?

My second question is about porting CSound to Work with Python 3. I know, it’s not a big deal for me to install Python 2.7, but I personally think, it would be nicer to have only one version of Python to Work with, especially if I want to distribute programs, I create, to others. The less stuff to install, the better in my opinion. The Floss manual talks about a plugin, and I looked at the Github page, but I’m not sure what to do from there. Can anyone explain how to actually use this plugin to port CSound? I have always worked with Python 3, so I don’t have any prior experience with porting from Python 2.

Thanks in advance,

Susanne Pedersen

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

Hi François.

Thanks a lot for the link. I’ll check it out.

Best regards,

Susanne

Hi Øyvind.

Thanks for the clarification.

The reason, I thought, Python 2 was necessary was that I couldn’t get earlier versions of Csound to work at all without it. However, I just got a new computer, and tried installing it without also installing Python 2, and this time, it works with no problems. Another reason was that during the installation, you get the option to install Python features, and this option specifically mentions that Python 2.7 is required.

For now, I intend to use Csound from within Python code. I intend to use Csound for handling audio in games, as the sound handling abilities of Pygame are very limited in my opinion. I have looked at other options, but to me, it looks like Csound is the most flexible and versatile one.

Best regards,

Susanne

hi oeyvind -

thanks for the detailed insights. may i ask: what are you using as GUI?

cheers -
  joachim

Hi Joachim,

Do you mean what I use as a GUI when I warp Csound as a VST and communicate with Python via OSC?
Wrapping as VST is done with Cabbage, so that creates the possibility of a GUI on the DAW end. On the Python end I do not really need a GUI as it is just a command line back end where control parameters are sent via OSC from the VST.

all best
Øyvind

man. 10. jan. 2022 kl. 23:46 skrev joachim heintz <jh@joachimheintz.de>:

hi oeyvind -

thanks for the detailed insights. may i ask: what are you using as GUI?

cheers -
joachim

Hi Susanne,

Welcome to the community, and wonderful idea to combine Csound and
Python! The two languages complement each other very nicely and you will
be able to build some very nice things with them together. You can run
Python as the main program and load Csound as a module (with ctcsound)
and this works with Python 3. No need to use Jupyter unless you find it
helpful. This is the most standard way of combining Csound and Python,
and will work well for most purposes.

Another way is to run Csound as the main program and then access Python
via the py opcodes (e.g. pycall, pyrun etc), and this is probably the
reason why you thought that you needed Python 2 (as the py opcodes are
compiled for a specific Python version and have not yet been updated for
Python 3). There are some limitations with the py opcodes that makes it
slightly cumbersome to work with, so I would not recommend that route
unless you really need it.

Yet another way that I have been using more and more is to run the two
programs as separate processes and just use OSC to communicate between
them. This can be useful for example if I wrap the Csound instruments as
VSTs to run in a DAW, and I do not want the Python interpreter to
potentially interfere with the audio thread of the whole DAW. Running
Python as a server in the background allows Csound then to run very
lightweight and only be taxed with producing audio in realtime, then
Csound can poll the Python server for data values to use for note
parameters and similar.

As Francois mentioned, the ctcsound examples are a good place to start.
I just wanted to mention these other possibilities to fill out the context.

All best
Øyvind Brandtsegg

søn. 9. jan. 2022 kl. 22:44 skrev Susanne Pedersen
<sp@susanne-pedersen.dk mailto:[sp@susanne-pedersen.dk](mailto:sp@susanne-pedersen.dk)>:

Hi all,

I am new to both CSound and this list. I am also learning Python,
and would like to combine the two, once I become good enough at
both. However, I have a couple of questions at this point. I am
unsure if this is the correct list to ask these questions, but I’ll
try. If they should be asked on the developer list, please let me know.

My first question is, is there any particular reason that I must use
Jupyter Notebooks, apart from the fact that the various examples of
code are meant to be used with it? I’ll use it, if I absolutely have
to, but I would prefer not to do so, if it is possible. As far as I
can tell, the code can be written in any normal editor for text or
code, and I even tried an example in the Python interactive
interpreter with success. So is Jupyter Notebooks really necessary,
and if so, why?

My second question is about porting CSound to Work with Python 3. I
know, it’s not a big deal for me to install Python 2.7, but I
personally think, it would be nicer to have only one version of
Python to Work with, especially if I want to distribute programs, I
create, to others. The less stuff to install, the better in my
opinion. The Floss manual talks about a plugin, and I looked at the
Github page, but I’m not sure what to do from there. Can anyone
explain how to actually use this plugin to port CSound? I have
always worked with Python 3, so I don’t have any prior experience
with porting from Python 2.


Thanks in advance,

Susanne Pedersen


Csound mailing list Csound@listserv.heanet.ie
mailto:[Csound@listserv.heanet.ie](mailto:Csound@listserv.heanet.ie)
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
<https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND> Send bugs reports
to https://github.com/csound/csound/issues
<https://github.com/csound/csound/issues> Discussions of bugs and
features can be posted here

Csound mailing list Csound@listserv.heanet.ie
mailto:[Csound@listserv.heanet.ie](mailto:Csound@listserv.heanet.ie)
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
<https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND> Send bugs reports to
https://github.com/csound/csound/issues
<https://github.com/csound/csound/issues> Discussions of bugs and
features can be posted here

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Csound mailing list Csound@listserv.heanet.ie https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND Send bugs reports to https://github.com/csound/csound/issues Discussions of bugs and features can be posted here

thanks oeyvind. yes i was wondering whether you use the DAW for GUI, or anything else in python.
cheers -
  joachim