Loading...
Searching...
No Matches
CsoundThreaded Class Reference

This class provides a multi-threaded C++ interface to the "C" Csound API. More...

`#include <csound_threaded.hpp>`

Inheritance diagram for CsoundThreaded:

## Public Member Functions

| CsoundThreaded ()
| CsoundThreaded (CSOUND *csound_)
| CsoundThreaded (void *host_data)
virtual | ~CsoundThreaded ()
virtual void | SetKperiodCallback (void(*kperiod_callback_)(CSOUND *, void *), void *kperiod_callback_user_data_)
virtual int | PerformRoutine ()
virtual int | PerformAndResetRoutine ()
virtual int | Perform ()
| Overrides Csound::Perform to run in a separate thread of execution.
virtual int | PerformAndReset ()
| Like Perform, but calls Cleanup() and Reset() at the conclusion of the performance, so that this is done in the performance thread.
virtual int | ScoreEvent (char opcode, const MYFLT *pfields, long pfield_count)
| Enqueues a low-level score event with raw pfields for dispatch from the performance thread routine.
virtual void | InputMessage (const char *message)
| Enqueues a textual score event or events for dispatch from the performance thread routine.
virtual int | ReadScore (const char *score)
| Enqueues a textual score event, score fragment, or entire score for dispatch from the performance thread routine.
virtual void | Stop ()
| Signals the performance thread routine to stop and return.
virtual void | Join ()
| Causes the calling thread to wait for the end of the performance thread routine.
virtual bool | IsPlaying () const
| Returns whether or not the performance thread routine is running.

## Protected Member Functions

void | ClearQueue ()

## Protected Attributes

std::thread | performance_thread
std::atomic< bool > | keep_running
void(* | kperiod_callback )(CSOUND *, void *)
void * | kperiod_callback_user_data
concurrent_queue< CsoundEvent * > | input_queue

## Detailed Description

This class provides a multi-threaded C++ interface to the "C" Csound API.

The interface is identical to the C++ interface of the Csound class in csound.hpp; however, the ::Perform() function runs in a separate thread of execution that is fed by a thread-safe FIFO of messages from ::ScoreEvent, ::InputMessage, and ::ReadScore.

This is a header-file-only facility. The multi-threaded features of this class are minimalistic, but seem sufficient for most purposes. There are no external dependences apart from Csound and the standard C++ library.

## Constructor & Destructor Documentation

## CsoundThreaded() [1/3]

CsoundThreaded::CsoundThreaded | ( |  | ) |

inline

References keep_running, kperiod_callback, and kperiod_callback_user_data.

## CsoundThreaded() [2/3]

CsoundThreaded::CsoundThreaded | ( | CSOUND * | csound_ | ) |

inline

References keep_running, kperiod_callback, and kperiod_callback_user_data.

## CsoundThreaded() [3/3]

CsoundThreaded::CsoundThreaded | ( | void * | host_data | ) |

inline

References keep_running, kperiod_callback, and kperiod_callback_user_data.

## ~CsoundThreaded()

virtual CsoundThreaded::~CsoundThreaded | ( |  | ) |

inline virtual

References ClearQueue(), Join(), and Stop().

## Member Function Documentation

## ClearQueue()

void CsoundThreaded::ClearQueue | ( |  | ) |

inline protected

References input_queue.

Referenced by PerformAndResetRoutine(), PerformRoutine(), and ~CsoundThreaded().

## InputMessage()

virtual void CsoundThreaded::InputMessage | ( | const char * | message | ) |

inline virtual

Enqueues a textual score event or events for dispatch from the performance thread routine.

References input_queue.

## IsPlaying()

virtual bool CsoundThreaded::IsPlaying | ( |  | ) | const

inline virtual

Returns whether or not the performance thread routine is running.

References keep_running.

## Join()

virtual void CsoundThreaded::Join | ( |  | ) |

inline virtual

Causes the calling thread to wait for the end of the performance thread routine.

References performance_thread.

Referenced by ~CsoundThreaded().

## Perform()

virtual int CsoundThreaded::Perform | ( |  | ) |

inline virtual

Overrides Csound::Perform to run in a separate thread of execution.

The granularity of time is one kperiod. If a kperiod callback has been set, it is called with the CSOUND object and any user data on every kperiod.

References performance_thread, and PerformRoutine().

## PerformAndReset()

virtual int CsoundThreaded::PerformAndReset | ( |  | ) |

inline virtual

Like Perform, but calls Cleanup() and Reset() at the conclusion of the performance, so that this is done in the performance thread.

References performance_thread, and PerformAndResetRoutine().

## PerformAndResetRoutine()

virtual int CsoundThreaded::PerformAndResetRoutine | ( |  | ) |

inline virtual

References ClearQueue(), input_queue, keep_running, kperiod_callback, and kperiod_callback_user_data.

Referenced by PerformAndReset().

## PerformRoutine()

virtual int CsoundThreaded::PerformRoutine | ( |  | ) |

inline virtual

References ClearQueue(), input_queue, keep_running, kperiod_callback, and kperiod_callback_user_data.

Referenced by Perform().

## ReadScore()

virtual int CsoundThreaded::ReadScore | ( | const char * | score | ) |

inline virtual

Enqueues a textual score event, score fragment, or entire score for dispatch from the performance thread routine.

References input_queue.

## ScoreEvent()

virtual int CsoundThreaded::ScoreEvent | ( | char | opcode,
|  | const MYFLT * | pfields,
|  | long | pfield_count )

inline virtual

Enqueues a low-level score event with raw pfields for dispatch from the performance thread routine.

References input_queue.

## SetKperiodCallback()

virtual void CsoundThreaded::SetKperiodCallback | ( | void(* | kperiod_callback_ )(CSOUND *, void *),
|  | void * | kperiod_callback_user_data_ )

inline virtual

References kperiod_callback, and kperiod_callback_user_data.

## Stop()

virtual void CsoundThreaded::Stop | ( |  | ) |

inline virtual

Signals the performance thread routine to stop and return.

References keep_running.

Referenced by ~CsoundThreaded().

## Field Documentation

## input_queue

concurrent_queue<CsoundEvent *> CsoundThreaded::input_queue

protected

Referenced by ClearQueue(), InputMessage(), PerformAndResetRoutine(), PerformRoutine(), ReadScore(), and ScoreEvent().

## keep_running

std::atomic<bool> CsoundThreaded::keep_running

protected

Referenced by CsoundThreaded(), CsoundThreaded(), CsoundThreaded(), IsPlaying(), PerformAndResetRoutine(), PerformRoutine(), and Stop().

## kperiod_callback

void(* CsoundThreaded::kperiod_callback) (CSOUND *, void *)

protected

Referenced by CsoundThreaded(), CsoundThreaded(), CsoundThreaded(), PerformAndResetRoutine(), PerformRoutine(), and SetKperiodCallback().

## kperiod_callback_user_data

void* CsoundThreaded::kperiod_callback_user_data

protected

Referenced by CsoundThreaded(), CsoundThreaded(), CsoundThreaded(), PerformAndResetRoutine(), PerformRoutine(), and SetKperiodCallback().

## performance_thread

std::thread CsoundThreaded::performance_thread

protected

Referenced by Join(), Perform(), and PerformAndReset().