Csound and CsoundAC API
5.17
|
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. | |
CSOUND * | GetCsound () |
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 |
CSOUND * | csound |
volatile CsoundPerformanceThreadMessage * | firstMessage |
void * | flushLock |
CsoundPerformanceThreadMessage * | lastMessage |
int | paused |
void * | pauseLock |
void * | perfThread |
void(* | processcallback )(void *cdata) |
void * | queueLock |
int | running |
int | status |
Friends | |
class | CsoundPerformanceThreadMessage |
class | CsPerfThread_PerformScore |
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; }
CsoundPerformanceThread::CsoundPerformanceThread | ( | Csound * | ) |
CsoundPerformanceThread::CsoundPerformanceThread | ( | CSOUND * | ) |
CsoundPerformanceThread::~CsoundPerformanceThread | ( | ) |
|
private |
void CsoundPerformanceThread::FlushMessageQueue | ( | ) |
Waits until all pending messages (pause, send score event, etc.) are actually received by the performance thread.
|
inline |
Returns the Csound instance pointer.
|
inline |
Returns the process callback as a void pointer.
|
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).
|
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()).
|
private |
void CsoundPerformanceThread::Play | ( | ) |
Continues performance if it was paused.
|
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.
|
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.
|
friend |
|
friend |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |
|
private |