Public Member Functions | Private Member Functions | Private Attributes | Friends

CsoundPerformanceThread Class Reference

#include <csPerfThread.hpp>

Public Member Functions

Private Member Functions

Private Attributes

Friends


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

volatile CsoundPerformanceThreadMessage* CsoundPerformanceThread::firstMessage [private]
CsoundPerformanceThreadMessage* CsoundPerformanceThread::lastMessage [private]