Csound and CsoundAC API  5.17
Public Member Functions | Private Member Functions | Private Attributes | Friends
CsoundPerformanceThread Class Reference

CsoundPerformanceThread(Csound *) CsoundPerformanceThread(CSOUND *) More...

#include <csPerfThread.hpp>

Public Member Functions

 CsoundPerformanceThread (Csound *)
 CsoundPerformanceThread (CSOUND *)
void FlushMessageQueue ()
 Waits until all pending messages (pause, send score event, etc.) are actually received by the performance thread.
CSOUNDGetCsound ()
 Returns the Csound instance pointer.
void * GetProcessCallback ()
 Returns the process callback as a void pointer.
int GetStatus ()
 Returns the current status, zero if still playing, positive if the end of score was reached or performance was stopped, and negative if an error occured.
void InputMessage (const char *s)
 Sends a score event as a string, similarly to line events (-L).
int isRunning ()
int Join ()
 Waits until the performance is finished or fails, and returns a positive value if the end of score was reached or Stop() was called, and a negative value if an error occured.
void Pause ()
 Pauses performance (can be continued by calling Play()).
void Play ()
 Continues performance if it was paused.
void ScoreEvent (int absp2mode, char opcod, int pcnt, const MYFLT *p)
 Sends a score event of type 'opcod' (e.g.
void SetProcessCallback (void(*Callback)(void *), void *cbdata)
 Sets the process callback.
void SetScoreOffsetSeconds (double timeVal)
 Sets the playback time pointer to the specified value (in seconds).
void Stop ()
 Stops performance (cannot be continued).
void TogglePause ()
 Pauses performance unless it is already paused, in which case it is continued.
 ~CsoundPerformanceThread ()

Private Member Functions

void csPerfThread_constructor (CSOUND *)
int Perform ()
void QueueMessage (CsoundPerformanceThreadMessage *)

Private Attributes

void * cdata
CSOUNDcsound
volatile
CsoundPerformanceThreadMessage
firstMessage
void * flushLock
CsoundPerformanceThreadMessagelastMessage
int paused
void * pauseLock
void * perfThread
void(* processcallback )(void *cdata)
void * queueLock
int running
int status

Friends

class CsoundPerformanceThreadMessage
class CsPerfThread_PerformScore

Detailed Description

CsoundPerformanceThread(Csound *) CsoundPerformanceThread(CSOUND *)

Performs a score in a separate thread until the end of score is reached, the playback (which is paused by default) is stopped by calling CsoundPerformanceThread::Stop(), or an error occurs. The constructor takes a Csound instance pointer as argument; it assumes that csoundCompile() was called successfully before creating the performance thread. Once the playback is stopped for one of the above mentioned reasons, the performance thread calls csoundCleanup() and returns.

An example program using the CsoundPerformanceThread class

#include <stdio.h> #include "csound.hpp" #include "csPerfThread.hpp"

int main(int argc, char *argv[]) { int result=0; Csound cs; csoundInitialize(NULL,NULL,NULL); result = cs.Compile(argc,argv);

if(!result) { CsoundPerformanceThread perfThread(cs.GetCsound()); perfThread.Play(); // Starts performance while(perfThread.GetStatus() == 0); // nothing to do here... but you could process input events, graphics etc perfThread.Stop(); // Stops performance. In fact, performance should have already been finished, so this is just an example of how to stop if you need perfThread.Join(); // always call Join() after Stop() as a rule of thumb. } else{ printf("csoundCompile returned an error\n"); return 1; }

return 0; }

Constructor & Destructor Documentation

CsoundPerformanceThread::CsoundPerformanceThread ( Csound *  )
CsoundPerformanceThread::CsoundPerformanceThread ( CSOUND )
CsoundPerformanceThread::~CsoundPerformanceThread ( )

Member Function Documentation

void CsoundPerformanceThread::csPerfThread_constructor ( CSOUND )
private
void CsoundPerformanceThread::FlushMessageQueue ( )

Waits until all pending messages (pause, send score event, etc.) are actually received by the performance thread.

CSOUND* CsoundPerformanceThread::GetCsound ( )
inline

Returns the Csound instance pointer.

void* CsoundPerformanceThread::GetProcessCallback ( )
inline

Returns the process callback as a void pointer.

int CsoundPerformanceThread::GetStatus ( )
inline

Returns the current status, zero if still playing, positive if the end of score was reached or performance was stopped, and negative if an error occured.

void CsoundPerformanceThread::InputMessage ( const char *  s)

Sends a score event as a string, similarly to line events (-L).

int CsoundPerformanceThread::isRunning ( )
inline
int CsoundPerformanceThread::Join ( )

Waits until the performance is finished or fails, and returns a positive value if the end of score was reached or Stop() was called, and a negative value if an error occured.

Also releases any resources associated with the performance thread object.

void CsoundPerformanceThread::Pause ( )

Pauses performance (can be continued by calling Play()).

int CsoundPerformanceThread::Perform ( )
private
void CsoundPerformanceThread::Play ( )

Continues performance if it was paused.

void CsoundPerformanceThread::QueueMessage ( CsoundPerformanceThreadMessage )
private
void CsoundPerformanceThread::ScoreEvent ( int  absp2mode,
char  opcod,
int  pcnt,
const MYFLT p 
)

Sends a score event of type 'opcod' (e.g.

'i' for a note event), with 'pcnt' p-fields in array 'p' (p[0] is p1). If absp2mode is non-zero, the start time of the event is measured from the beginning of performance, instead of the default of relative to the current time.

void CsoundPerformanceThread::SetProcessCallback ( void(*)(void *)  Callback,
void *  cbdata 
)
inline

Sets the process callback.

void CsoundPerformanceThread::SetScoreOffsetSeconds ( double  timeVal)

Sets the playback time pointer to the specified value (in seconds).

void CsoundPerformanceThread::Stop ( )

Stops performance (cannot be continued).

void CsoundPerformanceThread::TogglePause ( )

Pauses performance unless it is already paused, in which case it is continued.

Friends And Related Function Documentation

friend class CsoundPerformanceThreadMessage
friend
friend class CsPerfThread_PerformScore
friend

Field Documentation

void* CsoundPerformanceThread::cdata
private
CSOUND* CsoundPerformanceThread::csound
private
volatile CsoundPerformanceThreadMessage* CsoundPerformanceThread::firstMessage
private
void* CsoundPerformanceThread::flushLock
private
CsoundPerformanceThreadMessage* CsoundPerformanceThread::lastMessage
private
int CsoundPerformanceThread::paused
private
void* CsoundPerformanceThread::pauseLock
private
void* CsoundPerformanceThread::perfThread
private
void(* CsoundPerformanceThread::processcallback)(void *cdata)
private
void* CsoundPerformanceThread::queueLock
private
int CsoundPerformanceThread::running
private
int CsoundPerformanceThread::status
private