[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-dev] calling a Function from a primitive



hi ross,

what i am doing, and what is generally done in the
distro is to just call sclang methods to evaluate your function.
the clocks schedule function invocations, but that's more
complicated.

i'm calling runInterpreter on the C side from my own pthread,
to call a method of an object passed in as the thread (void*)data,
which evaluates a user defined opengl rendering function.

if you call thisThread.clock on the lang side from inside the render function
your clock is still the SystemClock. i don't think there are any problems
with that, none have come up anyway, do i need to implement my own clock?

best,
_c

p.s. i just came in for lunch from the vines, going back out now.
got your other message, will write back tonight.

my scheduling thread so far, i need to rework my timing code.
james is this kind of thing alright to do?

void * glSchedThreadFunc( void * data ) {


VMGlobals * g = gMainVMGlobals;
PyrObject * w = (PyrObject*)data;
double startTime, endTime, timeTaken, framesTaken, frameFrac;
struct timespec ts;
ts.tv_sec = 0;
SC_GLRenderFrameInfo fi;


SC_GLWindow * cppWin = (SC_GLWindow*)w->slots->uptr;
if(cppWin) {
cppWin->makeCurrentContext();
cppWin->mStartTime = elapsedTime();
} else goto leave;



true) {


pthread_mutex_lock(&gLangMutex);


cppWin = (SC_GLWindow*)w->slots->uptr;
if(cppWin) {

while( (fi = cppWin->mRenderFrameInfo).isStopped ) {
pthread_cond_wait( &cppWin->mSchedCond, &gLangMutex );
cppWin = (SC_GLWindow*)w->slots->uptr;
if( !cppWin ) goto unlockAndLeave;
cppWin->resetTime();
}


startTime = elapsedTime();
++g->sp; SetObject( g->sp, w );
runInterpreter(g, s_prRender, 1);


pthread_mutex_unlock(&gLangMutex);


endTime = elapsedTime();
timeTaken = endTime - startTime;
framesTaken = timeTaken * fi.fps;
frameFrac = 1.0 - (framesTaken - (int)framesTaken);


ts.tv_nsec = (long int)(frameFrac * fi.nanoFrameDur);


cppWin->setElapsedTimeAndFrameTimes( startTime );
cppWin->incrementFrameCount();


nanosleep(&ts, 0);
} else goto unlockAndLeave;


}
unlockAndLeave:
pthread_mutex_unlock(&gLangMutex);
leave:
//pthread_exit((void*)0);
return (0;
}



On Monday, December 15, 2003, at 12:55 PM, Ross Bencina wrote:

So how should one implement event-driven code where the events come from C?

Ross.

----- Original Message -----
From: "James McCartney" <asynth@xxxxxx>
To: "SuperCollider developers list" <sc-dev@xxxxxxxxxxxxxxx>
Sent: Sunday, December 14, 2003 5:35 PM
Subject: Re: [sc-dev] calling a Function from a primitive


You must never do that. Primitives may not reenter the interpreter. It
would make yielding from and resuming a coroutine impossible.

On Dec 13, 2003, at 4:56 PM, ccos wrote:

what's the best way of calling an sclang
Function stored in an instance variable
of an object from inside a primitive?

--
--- james mccartney james@xxxxxxxxxxxxxx <http://www.audiosynth.com>
SuperCollider - a real time audio synthesis programming language

_______________________________________________
sc-dev mailing list
sc-dev@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-dev

_______________________________________________
sc-dev mailing list
sc-dev@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-dev