Skip to content

Commit

Permalink
daemon mode now keeps Csound open indefinitely regardless of the scor…
Browse files Browse the repository at this point in the history
…e end
  • Loading branch information
vlazzarini committed Dec 18, 2017
1 parent b5c6a58 commit 96ad277
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Bela/BelaCsound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void render(BelaContext *context, void *Data)
/* this is where Csound is called */
for(n = 0; n < context->audioFrames; n++){
if(frame == blocksize) {
if((res = userData->csound->PerformBuffer()) == 0) j = 0;
if((res = userData->csound->PerformBuffer()) == 0) frame = 0;
else {
frame = -1;
break;
Expand Down
4 changes: 2 additions & 2 deletions Bela/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ int main(int argc, const char *argv[]) {
{NULL, 0, NULL, 0}};
BelaInitSettings settings;
Bela_defaultSettings(&settings);
if(Bela_getopt_long(argc, argv, "", opt, &settings) == 0) {
if(Bela_getopt_long(argc, argv, "", opt, &settings) != -1) {
csData.csd = new char[strlen(optarg)+1];
std::strcpy(csData.csd,optarg);
bool res = Bela_initAudio(&settings, &CsData);
Expand Down Expand Up @@ -81,7 +81,7 @@ void render(BelaContext *context, void *userData)
/* this is where Csound is called */
for(n = 0; n < context->audioFrames; n++){
if(frame == blocksize) {
if((res = userData->csound->PerformBuffer()) == 0) j = 0;
if((res = userData->csound->PerformBuffer()) == 0) frame = 0;
else {
frame = -1;
break;
Expand Down
29 changes: 19 additions & 10 deletions Engine/musmon.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,14 @@ int sensevents(CSOUND *csound)
else /* this should only happen at */
csound->cyclesRemaining = 0; /* beginning of performance */
}

retest:
while (csound->cyclesRemaining <= 0) { /* read each score event: */
/* in daemon mode, we will ignore the end of
the score, but allow for a realtime event
to stop Csound */
while (csound->cyclesRemaining <= 0 &&
(e->opcod != 'e' || !csound->oparms->daemon)){
/* read each score event: */
if (e->opcod != '\0') {
/* if there is a pending score event, handle it now */
switch (e->opcod) {
Expand Down Expand Up @@ -1016,9 +1021,12 @@ int sensevents(CSOUND *csound)
else /* else lcode */
memcpy((void*) e, (void*) &(STA(lsect)->strarg), sizeof(EVTBLK));
} else
if (!(rdscor(csound, e))) /* or rd nxt evt from scstr */
if (!(rdscor(csound, e))){
/* or rd nxt evt from scstr */
e->opcod = 'e';
}
csound->currevent = e;

switch (e->opcod) {
case 'w':
if (!O->Beatmode) /* Not beatmode: read 'w' */
Expand Down Expand Up @@ -1048,7 +1056,6 @@ int sensevents(CSOUND *csound)
continue;
}
}

/* calculate the number of k-periods remaining until next event */
if (!O->sampleAccurate) {
if (O->Beatmode)
Expand Down Expand Up @@ -1098,8 +1105,9 @@ int sensevents(CSOUND *csound)
csound->OrcTrigEvts->start_kcnt <=
(uint32) csound->global_kcounter) {

if ((retval = process_rt_event(csound, 4)) != 0)
if ((retval = process_rt_event(csound, 4)) != 0){
goto scode;
}
}
/* RM */
if ((sinp = getRemoteSocksIn(csound))) {
Expand Down Expand Up @@ -1142,18 +1150,18 @@ int sensevents(CSOUND *csound)
}
}
}

/* MIDI note messages */
if (O->Midiin || O->FMidiin)
while ((sensType = sensMidi(csound)) != 0)
if ((retval = process_rt_event(csound, sensType)) != 0)

if ((retval = process_rt_event(csound, sensType)) != 0) {
goto scode;
}
}
/* no score event at this time, return to continue performance */

return 0;
scode:
/* get out here in realtime mode */
if(csound->oparms->realtime && retval == 2) return retval;
/* end of section (retval == 1), score (retval == 2), */
/* or lplay list (retval == 3) */
if (getRemoteInsRfdCount(csound))
Expand Down Expand Up @@ -1185,7 +1193,8 @@ int sensevents(CSOUND *csound)
RT_SPIN_UNLOCK
goto retest; /* & back for more */
}
return 2; /* done with entire score */

return retval; /* done with entire score */
}

static inline uint64_t time2kcnt(CSOUND *csound, double tval)
Expand Down
2 changes: 1 addition & 1 deletion Top/argdecode.c
Original file line number Diff line number Diff line change
Expand Up @@ -1079,7 +1079,7 @@ static int decode_long(CSOUND *csound, char *s, int argc, char **argv)
return 1; /* Try new parser */
}
else if (!(strcmp(s, "daemon"))) {
O->daemon = 1;
if(O->daemon == 0) O->daemon = 1;
return 1;
}
else if (!(strncmp(s, "port=",5))) {
Expand Down

0 comments on commit 96ad277

Please sign in to comment.