Csound Csound-dev Csound-tekno Search About

[Csnd] Openframeworks --> real-time Csound question

Date2025-04-23 14:39
FromRobert Gerard Pietrusko
Subject[Csnd] Openframeworks --> real-time Csound question
Hi Everyone,

I have a few questions about passing real-time events to Csound from Openframeworks/C++.


Setup -----------

Apple Silicon
Openframeworks / C++ compiled in XCode
Csound-MacOS-universal-6.18.1
installed from DMG / not homebrew.


Compositional Context -----------

. I'm working on a large, very public, real-time data visualization piece that opens next month.
. From within my application, I will be passing score events to Csound for real-time, keyframed sound design.
. I am writing launchd scripts to start and exit the openframeworks app at the same time everyday
. My openframeworks app will launch and close csound.
. It will be running for several months, all day long.
. I will not be there in person to oversee it.


Technical Context -----------

For reasons I won't bore you with, I was unable to get the csound performance thread working in my system.
It is some combination of lack of sleep, super tight deadlines, library binding issues, and reaching the boundary of my knowledge. 
(I would, however, like to revisit this issue with you all in the future because I've long used the performance thread in Java/Processing and would really love to use it in openframeworks projects. I want to learn how to do that successfully. )

I developed two workarounds:

(A) Openframeworks -- OSC --> Csound
Straight-forward. On startup, Openframeworks launches Csound using a posix_spawnp(); passes messages over a udp port; the CSD has a continuously running listener instr. I've worked in a similar way on other projects with Java and with Max and it's been predictable. But I've never had to run it for a long time unattended. What concerns me with this version is that, for a while, quitting the app would hang and I would have to hard quit Csound from the terminal. I've now written a hard kill function in my app's destructor. It seems to solve it, but I'm still cautious.


(B) Openframeworks -- popen() --> "-L stdin" --> Csound
Looking more into POSIX. My app launches Csound with popen(). It's a separate thread, open-loop / no feedback. I pass score messages to csound after setting the flag "-L stdin." It works. It works better than I thought it would. It feels very light and useful but I've not encountered discussions about using csound in this way and that makes me a bit cautious. At the moment, I'm preferring this method because it never crashes at shut down. But also, I'm completely unfamiliar with its "coffin corners." Is there anything I am missing?


The TL;DR Technical Question ---------

Given the context of this piece, can you spot any red flags about these two approaches? Are there things I should look out for? Is there something I'm doing that works fine as I prototype but that will bite in the butt when I try to scale the duration, etc? I'm scrambling to finish this on time and would like to not be caught off-guard.

I know this was a long email. I'm hoping a few of you might have the time to consider it. It would be a huge help!

Very best
Robert
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-04-23 15:45
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] [EXTERNAL] [Csnd] Openframeworks --> real-time Csound question
Some thoughts.

- running Csound as a separate process is the simplest way to separate user interface events and audio processing. So your choices are ok. You don't necessarily need to write a custom application embedding Csound.

- besides the two options you listed which sound both ok to me, you can also consider the UDP server 


- If you use Csound 7, you also have the option of sending OSC messages to the UDP server too.



Regarding your problem quitting Csound, you may consider using this opcode


HTH

Prof. Victor Lazzarini
Maynooth University
Ireland

On 23 Apr 2025, at 14:46, Robert Gerard Pietrusko <rgpietru@gmail.com> wrote:


You don't often get email from rgpietru@gmail.com. Learn why this is important

*Warning*

This email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.

Hi Everyone,

I have a few questions about passing real-time events to Csound from Openframeworks/C++.


Setup -----------

Apple Silicon
Openframeworks / C++ compiled in XCode
Csound-MacOS-universal-6.18.1
installed from DMG / not homebrew.


Compositional Context -----------

. I'm working on a large, very public, real-time data visualization piece that opens next month.
. From within my application, I will be passing score events to Csound for real-time, keyframed sound design.
. I am writing launchd scripts to start and exit the openframeworks app at the same time everyday
. My openframeworks app will launch and close csound.
. It will be running for several months, all day long.
. I will not be there in person to oversee it.


Technical Context -----------

For reasons I won't bore you with, I was unable to get the csound performance thread working in my system.
It is some combination of lack of sleep, super tight deadlines, library binding issues, and reaching the boundary of my knowledge. 
(I would, however, like to revisit this issue with you all in the future because I've long used the performance thread in Java/Processing and would really love to use it in openframeworks projects. I want to learn how to do that successfully. )

I developed two workarounds:

(A) Openframeworks -- OSC --> Csound
Straight-forward. On startup, Openframeworks launches Csound using a posix_spawnp(); passes messages over a udp port; the CSD has a continuously running listener instr. I've worked in a similar way on other projects with Java and with Max and it's been predictable. But I've never had to run it for a long time unattended. What concerns me with this version is that, for a while, quitting the app would hang and I would have to hard quit Csound from the terminal. I've now written a hard kill function in my app's destructor. It seems to solve it, but I'm still cautious.


(B) Openframeworks -- popen() --> "-L stdin" --> Csound
Looking more into POSIX. My app launches Csound with popen(). It's a separate thread, open-loop / no feedback. I pass score messages to csound after setting the flag "-L stdin." It works. It works better than I thought it would. It feels very light and useful but I've not encountered discussions about using csound in this way and that makes me a bit cautious. At the moment, I'm preferring this method because it never crashes at shut down. But also, I'm completely unfamiliar with its "coffin corners." Is there anything I am missing?


The TL;DR Technical Question ---------

Given the context of this piece, can you spot any red flags about these two approaches? Are there things I should look out for? Is there something I'm doing that works fine as I prototype but that will bite in the butt when I try to scale the duration, etc? I'm scrambling to finish this on time and would like to not be caught off-guard.

I know this was a long email. I'm hoping a few of you might have the time to consider it. It would be a huge help!

Very best
Robert
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-04-28 13:02
From"Dr. Richard Boulanger"
SubjectRe: [Csnd] Openframeworks --> real-time Csound question
Hello Robert!

I can't wait to see the installation!
It is so great that you are using Csound for this major project.
Good luck.  

Maybe I will see you at ICMC50 (especially, on June 11, 12 ;-). 

Hope so.

Take care

- Dr.B


Dr. Richard Boulanger

Professor

Electronic Production and Design

Berklee College of Music

Professional Writing & Technology Division



On Wed, Apr 23, 2025 at 9:46 AM Robert Gerard Pietrusko <rgpietru@gmail.com> wrote:
Hi Everyone,

I have a few questions about passing real-time events to Csound from Openframeworks/C++.


Setup -----------

Apple Silicon
Openframeworks / C++ compiled in XCode
Csound-MacOS-universal-6.18.1
installed from DMG / not homebrew.


Compositional Context -----------

. I'm working on a large, very public, real-time data visualization piece that opens next month.
. From within my application, I will be passing score events to Csound for real-time, keyframed sound design.
. I am writing launchd scripts to start and exit the openframeworks app at the same time everyday
. My openframeworks app will launch and close csound.
. It will be running for several months, all day long.
. I will not be there in person to oversee it.


Technical Context -----------

For reasons I won't bore you with, I was unable to get the csound performance thread working in my system.
It is some combination of lack of sleep, super tight deadlines, library binding issues, and reaching the boundary of my knowledge. 
(I would, however, like to revisit this issue with you all in the future because I've long used the performance thread in Java/Processing and would really love to use it in openframeworks projects. I want to learn how to do that successfully. )

I developed two workarounds:

(A) Openframeworks -- OSC --> Csound
Straight-forward. On startup, Openframeworks launches Csound using a posix_spawnp(); passes messages over a udp port; the CSD has a continuously running listener instr. I've worked in a similar way on other projects with Java and with Max and it's been predictable. But I've never had to run it for a long time unattended. What concerns me with this version is that, for a while, quitting the app would hang and I would have to hard quit Csound from the terminal. I've now written a hard kill function in my app's destructor. It seems to solve it, but I'm still cautious.


(B) Openframeworks -- popen() --> "-L stdin" --> Csound
Looking more into POSIX. My app launches Csound with popen(). It's a separate thread, open-loop / no feedback. I pass score messages to csound after setting the flag "-L stdin." It works. It works better than I thought it would. It feels very light and useful but I've not encountered discussions about using csound in this way and that makes me a bit cautious. At the moment, I'm preferring this method because it never crashes at shut down. But also, I'm completely unfamiliar with its "coffin corners." Is there anything I am missing?


The TL;DR Technical Question ---------

Given the context of this piece, can you spot any red flags about these two approaches? Are there things I should look out for? Is there something I'm doing that works fine as I prototype but that will bite in the butt when I try to scale the duration, etc? I'm scrambling to finish this on time and would like to not be caught off-guard.

I know this was a long email. I'm hoping a few of you might have the time to consider it. It would be a huge help!

Very best
Robert
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