Csound Csound-dev Csound-tekno Search About

[Csnd] Csound and Python.

Date2025-01-14 16:22
FromGabriele Battaglia <0000013f12e4daf0-dmarc-request@LISTSERV.HEANET.IE>
Subject[Csnd] Csound and Python.
Hi All.

Reading last messages about this topic I hve got a little bit confuse.


I'm beginner and I don't known allmost nothing about Csound... I am just 
reading books and taking the first exercises but my goal is to learn 
enogh to be able to play with it also using python.


Could someone explain with easy words how many way are there available 
to use Csound from a python script and which is the best, more complete 
I mean, no restriction or features lost?


Tanks.


Gabe.

-- 
Gabriele Battaglia (IZ4APU)
--... ...--  -.. .  .. --.. ....- .- .--. ..-  - ..-  . .
Sent from my Giant Desktop PC

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

Date2025-01-14 18:21
Fromjoachim heintz
SubjectRe: [Csnd] Csound and Python.
hi gabe -

eduardo has examples for his libcsound here: 
https://libcsound.readthedocs.io/en/latest/notebooks/01-Introduction.html

examples for ctcsound are here: 
https://csound.com/docs/ctcsound/cookbook.html
sources: https://github.com/csound/ctcsound/tree/master/cookbook

and there are python examples in the csound API collection for both, 
csound 6 and csound 7: 
https://github.com/csound/csoundAPI_examples/tree/master

hope this helps, best -
	joachim

On 14/01/2025 17:22, Gabriele Battaglia wrote:
> Hi All.
> 
> Reading last messages about this topic I hve got a little bit confuse.
> 
> 
> I'm beginner and I don't known allmost nothing about Csound... I am just 
> reading books and taking the first exercises but my goal is to learn 
> enogh to be able to play with it also using python.
> 
> 
> Could someone explain with easy words how many way are there available 
> to use Csound from a python script and which is the best, more complete 
> I mean, no restriction or features lost?
> 
> 
> Tanks.
> 
> 
> Gabe.
> 

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

Date2025-01-14 18:52
FromRory Walsh
SubjectRe: [Csnd] Csound and Python.
There is also Victor's book 'Computer Music Instruments'(Springer) which uses Csound and Python extensively to explore a range of computer DSP topics.  

On Tue, 14 Jan 2025 at 18:22, joachim heintz <jh@joachimheintz.de> wrote:
hi gabe -

eduardo has examples for his libcsound here:
https://libcsound.readthedocs.io/en/latest/notebooks/01-Introduction.html

examples for ctcsound are here:
https://csound.com/docs/ctcsound/cookbook.html
sources: https://github.com/csound/ctcsound/tree/master/cookbook

and there are python examples in the csound API collection for both,
csound 6 and csound 7:
https://github.com/csound/csoundAPI_examples/tree/master

hope this helps, best -
        joachim

On 14/01/2025 17:22, Gabriele Battaglia wrote:
> Hi All.
>
> Reading last messages about this topic I hve got a little bit confuse.
>
>
> I'm beginner and I don't known allmost nothing about Csound... I am just
> reading books and taking the first exercises but my goal is to learn
> enogh to be able to play with it also using python.
>
>
> Could someone explain with easy words how many way are there available
> to use Csound from a python script and which is the best, more complete
> I mean, no restriction or features lost?
>
>
> Tanks.
>
>
> Gabe.
>

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

Date2025-01-14 19:58
FromGabriele Battaglia <0000013f12e4daf0-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Csound and Python.
Il 14/01/2025 19:52, Rory Walsh ha scritto:
> There is also Victor's book 'Computer Music Instruments'(Springer) 
> which uses Csound and Python extensively to explore a range of 
> computer DSP topics.


Thank you both.

Do you know if this book is available also digitally?

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

Date2025-01-15 09:07
FromRory Walsh
SubjectRe: [Csnd] Csound and Python.
Yes, and it's currently available to buy for 28 euros. Maybe I can get a commission for the sale :rofl


On Tue, 14 Jan 2025 at 19:59, Gabriele Battaglia <0000013f12e4daf0-dmarc-request@listserv.heanet.ie> wrote:
Il 14/01/2025 19:52, Rory Walsh ha scritto:
> There is also Victor's book 'Computer Music Instruments'(Springer)
> which uses Csound and Python extensively to explore a range of
> computer DSP topics.


Thank you both.

Do you know if this book is available also digitally?

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

Date2025-01-15 11:51
FromMichael Gogins
SubjectRe: [Csnd] Csound and Python.
Attachmentssimplest-score-bin.csd  
Hello Gabriele,

There are several ways of combining Csound with Python. As far as I know, none of them limit the functionality of Csound or of Python in any way.

There is another method, which embeds a Python script inside a Csound .csd file. This method does not require ctcsound or any external libraries, just Csound and Python. The way it works is that a "bin" attribute of the .csd <CsScore> tag is specified, which can be e.g. "python3." When Csound detects this attribute during performance, it creates two temporary filenames and then runs the contents of the <CsScore> tag as a Python script, passing the two filenames to Python. That script can read data from sys.argv[0], and should write generated Csound score events to sys.argv[1]. Csound will then read the file named in sys.argv[1] and perform it as a regular Csound score. I have attached a complete working example, with explanatory comments, to this email.

Regards,
Mike

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com


On Tue, Jan 14, 2025 at 5:22 PM Gabriele Battaglia <0000013f12e4daf0-dmarc-request@listserv.heanet.ie> wrote:
Hi All.

Reading last messages about this topic I hve got a little bit confuse.


I'm beginner and I don't known allmost nothing about Csound... I am just
reading books and taking the first exercises but my goal is to learn
enogh to be able to play with it also using python.


Could someone explain with easy words how many way are there available
to use Csound from a python script and which is the best, more complete
I mean, no restriction or features lost?


Tanks.


Gabe.

--
Gabriele Battaglia (IZ4APU)
--... ...--  -.. .  .. --.. ....- .- .--. ..-  - ..-  . .
Sent from my Giant Desktop PC

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

Date2025-01-15 13:38
FromCian
SubjectRe: [Csnd] Csound and Python.
Eduardo has an excellent library, Maelzel, that also uses Python and works in Jupyter notebooks:

Very easy to get running, well thought out and solves a number of problems for you.

On Wed, Jan 15, 2025 at 6:51 AM Michael Gogins <michael.gogins@gmail.com> wrote:
Hello Gabriele,

There are several ways of combining Csound with Python. As far as I know, none of them limit the functionality of Csound or of Python in any way.

There is another method, which embeds a Python script inside a Csound .csd file. This method does not require ctcsound or any external libraries, just Csound and Python. The way it works is that a "bin" attribute of the .csd <CsScore> tag is specified, which can be e.g. "python3." When Csound detects this attribute during performance, it creates two temporary filenames and then runs the contents of the <CsScore> tag as a Python script, passing the two filenames to Python. That script can read data from sys.argv[0], and should write generated Csound score events to sys.argv[1]. Csound will then read the file named in sys.argv[1] and perform it as a regular Csound score. I have attached a complete working example, with explanatory comments, to this email.

Regards,
Mike

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com


On Tue, Jan 14, 2025 at 5:22 PM Gabriele Battaglia <0000013f12e4daf0-dmarc-request@listserv.heanet.ie> wrote:
Hi All.

Reading last messages about this topic I hve got a little bit confuse.


I'm beginner and I don't known allmost nothing about Csound... I am just
reading books and taking the first exercises but my goal is to learn
enogh to be able to play with it also using python.


Could someone explain with easy words how many way are there available
to use Csound from a python script and which is the best, more complete
I mean, no restriction or features lost?


Tanks.


Gabe.

--
Gabriele Battaglia (IZ4APU)
--... ...--  -.. .  .. --.. ....- .- .--. ..-  - ..-  . .
Sent from my Giant Desktop PC

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

Date2025-01-15 13:39
FromCian
SubjectRe: [Csnd] Csound and Python.
Victor's book is also excellent for so many reasons (and it's huge - was really surprised when it arrived).

On Wed, Jan 15, 2025 at 8:38 AM Cian <cian.oconnor@gmail.com> wrote:
Eduardo has an excellent library, Maelzel, that also uses Python and works in Jupyter notebooks:

Very easy to get running, well thought out and solves a number of problems for you.

On Wed, Jan 15, 2025 at 6:51 AM Michael Gogins <michael.gogins@gmail.com> wrote:
Hello Gabriele,

There are several ways of combining Csound with Python. As far as I know, none of them limit the functionality of Csound or of Python in any way.

There is another method, which embeds a Python script inside a Csound .csd file. This method does not require ctcsound or any external libraries, just Csound and Python. The way it works is that a "bin" attribute of the .csd <CsScore> tag is specified, which can be e.g. "python3." When Csound detects this attribute during performance, it creates two temporary filenames and then runs the contents of the <CsScore> tag as a Python script, passing the two filenames to Python. That script can read data from sys.argv[0], and should write generated Csound score events to sys.argv[1]. Csound will then read the file named in sys.argv[1] and perform it as a regular Csound score. I have attached a complete working example, with explanatory comments, to this email.

Regards,
Mike

-----------------------------------------------------
Michael Gogins
Irreducible Productions
http://michaelgogins.tumblr.com
Michael dot Gogins at gmail dot com


On Tue, Jan 14, 2025 at 5:22 PM Gabriele Battaglia <0000013f12e4daf0-dmarc-request@listserv.heanet.ie> wrote:
Hi All.

Reading last messages about this topic I hve got a little bit confuse.


I'm beginner and I don't known allmost nothing about Csound... I am just
reading books and taking the first exercises but my goal is to learn
enogh to be able to play with it also using python.


Could someone explain with easy words how many way are there available
to use Csound from a python script and which is the best, more complete
I mean, no restriction or features lost?


Tanks.


Gabe.

--
Gabriele Battaglia (IZ4APU)
--... ...--  -.. .  .. --.. ....- .- .--. ..-  - ..-  . .
Sent from my Giant Desktop PC

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

Date2025-01-18 08:05
FromGabriele Battaglia <0000013f12e4daf0-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Csound and Python.
Il 15/01/2025 14:38, Cian ha scritto:
> Eduardo has an excellent library, Maelzel, that also uses Python and 
> works in Jupyter notebooks:
> https://github.com/gesellkammer/maelzel
>
> Very easy to get running, well thought out and solves a number of 
> problems for you.


Wow guys, too much ways, it is confusing. I know that sometime more is 
better than less but here I don't know what I need yet, what is the best 
to work on.

I'd like to concentrate on a single solution that offers me to manage 
Csound from a python script like to define an instrument and pass it 
something to play.

And I would like something that pyinstaller will be able to compile so 
the users that run my script don't need to have Csound installed. Just 
that. :)

Gabe.

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

Date2025-01-18 08:09
FromGabriele Battaglia <0000013f12e4daf0-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] Csound and Python.
Il 15/01/2025 12:51, Michael Gogins ha scritto:
> Hello Gabriele,
>
> There are several ways of combining Csound with Python. As far as I 
> know, none of them limit the functionality of Csound or of Python in 
> any way.
>
> There is another method, which embeds a Python script inside a Csound 
> .csd file. This method does not require ctcsound or any external 
> libraries, just Csound and Python. The way it works is that a "bin" 
> attribute of the .csd  tag is specified, which can be e.g. 
> "python3." When Csound detects this attribute during performance, it 
> creates two temporary filenames and then runs the contents of the 
>  tag as a Python script, passing the two filenames to Python. 
> That script can read data from sys.argv[0], and should write generated 
> Csound score events to sys.argv[1]. Csound will then read the file 
> named in sys.argv[1] and perform it as a regular Csound score. I have 
> attached a complete working example, with explanatory comments, to 
> this email.
>

Thank you Mike. I'm going to study carefully the example you provided.

Gabe.

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