CsoundPerformanceThread class provides a high-level interface for running Csound performance in a separate thread with playback control, event scheduling, and real-time recording capabilities.
Location: include/csPerfThread.hpp
Class definition
include/csPerfThread.hpp:112
Constructors
From Csound pointer
csoundCompile()must have been called successfully before creating the thread- Performance is paused by default; call
Play()to start
From Csound wrapper
Csound wrapper objects.
Playback control
Play
include/csPerfThread.hpp:175
Pause
Play().
Location: include/csPerfThread.hpp:180
TogglePause
include/csPerfThread.hpp:186
Stop
include/csPerfThread.hpp:191
After calling Stop(), the performance thread will:
- Complete the current k-pass
- Call
csoundCleanup() - Exit the thread
Join
include/csPerfThread.hpp:254
Returns:
- Positive value - Normal completion (end of score or
Stop()called) - Negative value - Error occurred
Join() after Stop() or when performance completes.
Status methods
GetStatus
include/csPerfThread.hpp:167
Returns:
0- Still playing- Positive value - End of score reached or stopped
- Negative value - Error occurred
IsRunning
include/csPerfThread.hpp:140
Returns:
1- Thread is running0- Thread is not running
Score events
ScoreEvent
include/csPerfThread.hpp:210
Parameters:
absp2mode- If non-zero, p2 time is absolute from start of performance; otherwise relative to current timeopcod- Event type character (e.g., ‘i’, ‘f’, ‘e’)pcnt- Number of p-fieldsp- Array of p-field values (p[0] is p1)
InputMessage
-L line events).
Location: include/csPerfThread.hpp:215
Example:
Recording
Record
include/csPerfThread.hpp:197
Parameters:
filename- Output file pathsamplebits- Sample bit depth (default: 16)numbufs- Number of buffers (default: 4)
StopRecord
include/csPerfThread.hpp:202
Orchestra compilation
CompileOrc
include/csPerfThread.hpp:226
Example:
EvalCode
include/csPerfThread.hpp:233
Parameters:
code- Code to evaluatereturncb- Callback function receiving the return value
Score timing
SetScoreOffsetSeconds
include/csPerfThread.hpp:220
Parameters:
timeVal- Time position in seconds
Advanced features
SetProcessCallback
include/csPerfThread.hpp:150
Parameters:
Callback- Function to call each cyclecbdata- User data passed to callback
GetProcessCallback
include/csPerfThread.hpp:145
RequestCallback
include/csPerfThread.hpp:239
Example:
FlushMessageQueue
include/csPerfThread.hpp:246
Useful for ensuring events are processed before continuing:
GetCsound
include/csPerfThread.hpp:157
Complete examples
Basic usage
Interactive control
With recording
Event scheduling
Thread safety
TheCsoundPerformanceThread class uses internal locking to ensure thread-safe communication:
- All public methods can be safely called from any thread
- Messages are queued and processed by the performance thread
- Use
FlushMessageQueue()to ensure synchronization when needed
Notes
- The performance thread automatically calls
csoundCleanup()when stopping - Always call
Join()before destroying the object - Default state after construction is paused - must call
Play()to start - The thread continues until end of score,
Stop()is called, or an error occurs