void test_breakpoint_remove(void) { int i; int break_count = 0; CSOUND* csound = csoundCreate(NULL); csoundCreateMessageBuffer(csound, 0); csoundCompileOrc(csound, "instr 1\nasig oscil 1, p4\nendin\n"); csoundInputMessage(csound, "i 1.1 0 1 440"); csoundInputMessage(csound, "i 1.2 0 1 880"); csoundInputMessage(csound, "i 1.1 0.1 1 440"); csoundStart(csound); csoundDebuggerInit(csound); csoundSetBreakpointCallback(csound, brkpt_cb2, (void *) &break_count); csoundSetInstrumentBreakpoint(csound, 1.1, 0); for (i = 0; i < 10; i++) { csoundPerformKsmps(csound); csoundDebugContinue(csound); } csoundRemoveInstrumentBreakpoint(csound, 1.1); for (i = 0; i < 10; i++) { csoundPerformKsmps(csound); csoundDebugContinue(csound); } CU_ASSERT(break_count == 1); csoundDebuggerClean(csound); csoundDestroy(csound); }
void test_string_channel(void) { const char orcS[] = "chn_S \"strchan1\",1\n chn_S \"strchan2\",2\n chn_S \"strchan3\",3\n instr 1\n endin\n"; csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=NULL"); csoundCompileOrc(csound, orcS); int err = csoundStart(csound); CU_ASSERT(err == CSOUND_SUCCESS); csoundSetStringChannel(csound, "testing", "ttt"); int len = csoundGetChannelDatasize(csound, "testing"); char string[len]; csoundGetStringChannel(csound, "testing", string); CU_ASSERT_STRING_EQUAL(string, "ttt"); csoundSetStringChannel(csound, "strchan1", "strchan1_val"); csoundSetStringChannel(csound, "strchan2", "strchan2_val"); csoundSetStringChannel(csound, "strchan3", "strchan3_val"); csoundGetStringChannel(csound, "strchan1", string); CU_ASSERT_STRING_EQUAL(string, "strchan1_val"); csoundGetStringChannel(csound, "strchan2", string); CU_ASSERT_STRING_EQUAL(string, "strchan2_val"); csoundGetStringChannel(csound, "strchan3", string); CU_ASSERT_STRING_EQUAL(string, "strchan3_val"); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_pvs_opcodes(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=null"); int err = csoundCompileOrc(csound, orc5); CU_ASSERT(err == CSOUND_SUCCESS); err = csoundStart(csound); PVSDATEXT pvs_data, pvs_data2; memset(&pvs_data,0,sizeof(PVSDATEXT)); memset(&pvs_data2,0,sizeof(PVSDATEXT)); pvs_data.N = 16; pvs_data.winsize = 32; err = csoundSetPvsChannel(csound, &pvs_data, "1"); err = csoundGetPvsChannel(csound, &pvs_data2, "1"); CU_ASSERT_EQUAL(pvs_data.N, pvs_data2.N); MYFLT pFields[] = {1.0, 0.0, 1.0}; err = csoundScoreEvent(csound, 'i', pFields, 3); err = csoundPerformKsmps(csound); CU_ASSERT_EQUAL(32.0, csoundGetControlChannel(csound, "winsize", NULL)); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_line_breakpoint_add_remove(void) { CSOUND* csound = csoundCreate(NULL); csoundCreateMessageBuffer(csound, 0); count = 0; csoundCompileOrc(csound, "instr 1\n" "Svar init \"hello\"\n" "ksig line 0, p3, 1\n" "ksig2 line 1, p3, 0\n" "asig3 oscils 0.5, 440, 0.5\n" "endin\n"); csoundInputMessage(csound, "i 1 0 1.1 440"); csoundStart(csound); csoundDebuggerInit(csound); csoundSetBreakpointCallback(csound, brkpt_cb5, NULL); csoundSetBreakpoint(csound, 5, 1, 0); csoundPerformKsmps(csound); csoundDebugContinue(csound); csoundPerformKsmps(csound); // This block performs csoundPerformKsmps(csound); // This block breaks csoundRemoveBreakpoint(csound, 5, 1); csoundPerformKsmps(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); csoundDebuggerClean(csound); csoundDestroy(csound); CU_ASSERT_EQUAL(count, 2); }
void test_chn_hints(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=null"); csoundCompileOrc(csound, orc6); (void)csoundStart(csound); // err = csoundPerformKsmps(csound); //Need this to load instr 0 controlChannelHints_t hints; hints.attributes = 0; CU_ASSERT_EQUAL(0, csoundGetControlChannelHints(csound, "chan", &hints)); CU_ASSERT_EQUAL(hints.x, 10); CU_ASSERT_EQUAL(hints.y, 10); CU_ASSERT_EQUAL(hints.width, 50); CU_ASSERT_EQUAL(hints.height, 100); CU_ASSERT_EQUAL(hints.attributes, 0); CU_ASSERT_EQUAL(0, csoundGetControlChannelHints(csound, "chan2", &hints)); CU_ASSERT_EQUAL(hints.x, 10); CU_ASSERT_EQUAL(hints.y, 10); CU_ASSERT_EQUAL(hints.width, 50); CU_ASSERT_EQUAL(hints.height, 100); CU_ASSERT_STRING_EQUAL(hints.attributes, "testattr"); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_buffer_run(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); int result = csoundCompileOrc(csound, "instr 1\n" "asig oscil 0.1, 440\n" "out asig\n" "endin\n"); csoundReadScore(csound, "i 1 0 0.1\n"); csoundStart(csound); csoundPerform(csound); while (csoundGetMessageCnt(csound)) { const char * msg = csoundGetFirstMessage(csound); CU_ASSERT_PTR_NOT_NULL(msg); csoundPopFirstMessage(csound); printf("CSOUND MESSAGE: %s", msg); } csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_control_channel_params(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=NULL"); //int argc = 2; csoundCompileOrc(csound, orc1); CU_ASSERT(csoundStart(csound) == CSOUND_SUCCESS); controlChannelHints_t hints; hints.behav = CSOUND_CONTROL_CHANNEL_INT; hints.dflt = 5; hints.min = 1; hints.max = 10; hints.attributes = NULL; csoundSetControlChannelHints(csound, "testing", hints); controlChannelHints_t hints2; csoundGetControlChannelHints(csound, "testing", &hints2); CU_ASSERT(hints2.behav == CSOUND_CONTROL_CHANNEL_INT); CU_ASSERT(hints2.dflt == 5); CU_ASSERT(hints2.min == 1); CU_ASSERT(hints2.max == 10); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
int compile_str_i(CSOUND *csound, COMPILE *p){ void csp_orc_sa_print_list(CSOUND*); //printf("START\n"); *p->res = (MYFLT)(csoundCompileOrc(csound, ((STRINGDAT *)p->str)->data)); //printf("END\n"); //csp_orc_sa_print_list(csound); return OK; }
int main(int arg, char** argv) { random_line *amp, *freq; /* initialize random seed: */ srand (time(NULL)); csoundInitialize(CSOUNDINIT_NO_ATEXIT); CSOUND* csound = csoundCreate(NULL); /* Using SetOption() to configure Csound Note: use only one commandline flag at a time */ csoundSetOption(csound, "-odac"); /* Compile the Csound Orchestra string */ csoundCompileOrc(csound, orc); /* Read in the Score from loop-generated String */ csoundReadScore(csound, "i1 0 60"); /* When compiling from strings, this call is necessary * before doing any performing */ csoundStart(csound); /* Create a random_line for use with Amplitude */ amp = random_line_create(0.4, 0.2); /* Create a random_line for use with Frequency */ freq = random_line_create(400.0, 80.0); /* Initialize channel values before running Csound */ csoundSetControlChannel(csound, "amp", random_line_tick(amp)); csoundSetControlChannel(csound, "freq", random_line_tick(freq)); /* The following is our main performance loop. We will perform one * block of sound at a time and continue to do so while it returns 0, * which signifies to keep processing. */ while (csoundPerformKsmps(csound) == 0) { /* Update Channel Values */ csoundSetControlChannel(csound, "amp", random_line_tick(amp)); csoundSetControlChannel(csound, "freq", random_line_tick(freq)); } csoundStop(csound); return 0; }
void test_bkpt_instrument(void) { CSOUND* csound = csoundCreate(NULL); csoundCreateMessageBuffer(csound, 0); csoundCompileOrc(csound, "instr 1\n Svar init \"hello\"\n endin\n"); csoundInputMessage(csound, "i 1 0 1.1 440"); csoundStart(csound); csoundDebuggerInit(csound); csoundSetBreakpointCallback(csound, brkpt_cb4, NULL); csoundSetInstrumentBreakpoint(csound, 1, 0); csoundPerformKsmps(csound); csoundDebuggerClean(csound); csoundDestroy(csound); }
void test_control_channel(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=null"); //int argc = 2; csoundCompileOrc(csound, orc1); CU_ASSERT(csoundStart(csound) == CSOUND_SUCCESS); csoundSetControlChannel(csound, "testing", 5.0); CU_ASSERT_EQUAL(5.0, csoundGetControlChannel(csound, "testing", NULL)); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_invalid_channel(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=null"); csoundCompileOrc(csound, orc5); int err; CU_ASSERT_EQUAL(0.0, csoundGetControlChannel(csound, "nonexistent_channel", &err)); CU_ASSERT_EQUAL(err, CSOUND_SUCCESS); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_line_breakpoint(void) { CSOUND* csound = csoundCreate(NULL); csoundCreateMessageBuffer(csound, 0); count = 0; csoundCompileOrc(csound, "instr 1\n" "Svar init \"hello\"\n" "ksig line 0, p3, 1\n" "ksig2 line 1, p3, 0\n" "asig3 oscils 0.5, 440, 0.5\n" "endin\n"); csoundInputMessage(csound, "i 1 0 1.1 440"); csoundStart(csound); csoundDebuggerInit(csound); csoundSetBreakpointCallback(csound, brkpt_cb6, NULL); csoundSetBreakpoint(csound, 5, 1, 0); csoundPerformKsmps(csound); csoundDebugContinue(csound); csoundPerformKsmps(csound); csoundSetBreakpoint(csound, 4, 1, 0); csoundPerformKsmps(csound); csoundDebugContinue(csound); csoundPerformKsmps(csound); csoundRemoveBreakpoint(csound, 4, 1); csoundPerformKsmps(csound); csoundDebugContinue(csound); csoundSetBreakpoint(csound, 1, 1, 0); // This breakpoint shouldn't be triggered as it's an init opcode csoundPerformKsmps(csound); csoundDebugContinue(csound); csoundSetBreakpoint(csound, 2, 2, 0); // This breakpoint shouldn't be triggered as instr 2 is not defined csoundPerformKsmps(csound); csoundDebuggerClean(csound); csoundDestroy(csound); CU_ASSERT_EQUAL(count, 2); }
int main(int arg, char** argv) { /* initialize random seed: */ srand (time(NULL)); csoundInitialize(CSOUNDINIT_NO_ATEXIT); CSOUND* csound = csoundCreate(NULL); /* Using SetOption() to configure Csound Note: use only one commandline flag at a time */ csoundSetOption(csound, "-odac"); /* Compile the Csound Orchestra string */ csoundCompileOrc(csound, orc); /* Read in the Score from pre-written String */ /*csoundReadScore(csound, (char*)sco);*/ /* Read in the Score from loop-generated String */ /*csoundReadScore(csound, generate_example2());*/ /* Read in the Score from loop-generated String */ csoundReadScore(csound, generate_example3()); /* When compiling from strings, this call is necessary * before doing any performing */ csoundStart(csound); /* The following is our main performance loop. We will perform one * block of sound at a time and continue to do so while it returns 0, * which signifies to keep processing. We will explore this loop * technique in further examples. */ while (csoundPerformKsmps(csound) == 0) { /* pass for now */ } csoundStop(csound); return 0; }
int main(int arg, char** argv) { void* thread; csoundInitialize(CSOUNDINIT_NO_ATEXIT); CSOUND* csound = csoundCreate(NULL); /* Using SetOption() to configure Csound Note: use only one commandline flag at a time */ csoundSetOption(csound, "-odac"); /* Compile the Csound Orchestra string */ csoundCompileOrc(csound, orc); /* Compile the Csound SCO String */ csoundReadScore(csound, (char*)sco); /* When compiling from strings, this call is necessary * before doing any performing */ csoundStart(csound); /* Create a new thread that will use our performance function and * pass in our CSOUND structure. This call is asynchronous and * will immediately return back here to continue code execution */ thread = csoundCreateThread(&performance_function, (void*)csound); /* Join will wait for the other thread to complete. If we did not * call csoundJoinThread(), after csoundCreateThread() returns we * would immediately move to the next line, csoundStop(). That * would stop Csound without really giving it time to run. */ csoundJoinThread(thread); csoundStop(csound); /* clean up Csound; this is useful if you're going to reuse a Csound * instance */ csoundCleanup(csound); return 0; }
void test_channel_list(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=null"); //int argc = 2; csoundCompileOrc(csound, orc2); CU_ASSERT(csoundStart(csound) == CSOUND_SUCCESS); controlChannelInfo_t *lst; int numchnls = csoundListChannels(csound, &lst); CU_ASSERT(numchnls == 2); CU_ASSERT_STRING_EQUAL(lst->name, "testing"); CU_ASSERT_EQUAL(lst->type, CSOUND_CONTROL_CHANNEL | CSOUND_INPUT_CHANNEL | CSOUND_OUTPUT_CHANNEL | CSOUND_CONTROL_CHANNEL_INT) CU_ASSERT_STRING_EQUAL(lst[1].name, "testing2"); csoundDeleteChannelList(csound, lst); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_channel_callbacks(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=null"); csoundCompileOrc(csound, orc3); csoundSetInputChannelCallback(csound, (channelCallback_t) inputCallback); csoundSetOutputChannelCallback(csound, (channelCallback_t) outputCallback); int err = csoundStart(csound); CU_ASSERT(err == CSOUND_SUCCESS); MYFLT pFields[] = {1.0, 0.0, 1.0}; err = csoundScoreEvent(csound, 'i', pFields, 3); MYFLT pFields2[] = {2.0, 0.0, 1.0}; err += csoundScoreEvent(csound, 'i', pFields2, 3); CU_ASSERT(err == CSOUND_SUCCESS); err = csoundPerformKsmps(csound); CU_ASSERT(err == CSOUND_SUCCESS); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
PUBLIC int csoundCompileCsd(CSOUND *csound, char *str) { if((csound->engineStatus & CS_STATE_COMP) == 0) { char *argv[2] = { "csound", (char *) str }; int argc = 2; return csoundCompile(csound, argc, argv); } else { int res = read_unified_file2(csound, (char *) str); if(res) { res = csoundCompileOrc(csound, NULL); if(res == CSOUND_SUCCESS){ csoundLockMutex(csound->API_lock); char *sc = scsortstr(csound, csound->scorestr); csoundInputMessageInternal(csound, (const char *) sc); free(sc); csoundUnlockMutex(csound->API_lock); return CSOUND_SUCCESS; } } return res; } }
int compile_orc_i(CSOUND *csound, COMPILE *p){ FILE *fp; int size=0; char *orc, c, *name; name = ((STRINGDAT *)p->str)->data; fp = fopen(name, "rb"); if (fp == NULL) { csound->Warning(csound, Str("compileorc: could not open %s\n"), name); *p->res = (MYFLT)(CSOUND_ERROR); return NOTOK; } while(!feof(fp)) size += fread(&c,1,1,fp); if(size==0) { fclose(fp); *p->res = (MYFLT)(CSOUND_ERROR); csound->InitError(csound, Str("compileorc: could not read %s\n"), name); return NOTOK; } orc = (char *) csound->Calloc(csound, size+1); fseek(fp, 0, SEEK_SET); if (UNLIKELY(fread(orc,1,size,fp)!=size)) { fclose(fp); csound->Free(csound,orc); return NOTOK; } *p->res = (MYFLT)(csoundCompileOrc(csound, orc)); fclose(fp); csound->Free(csound,orc); return OK; }
void test_channel_opcodes(void) { csoundSetGlobalEnv("OPCODE6DIR64", "../../"); CSOUND *csound = csoundCreate(0); csoundCreateMessageBuffer(csound, 0); csoundSetOption(csound, "--logfile=null"); csoundCompileOrc(csound, orc4); csoundSetInputChannelCallback(csound, (channelCallback_t) inputCallback2); csoundSetOutputChannelCallback(csound, (channelCallback_t) outputCallback2); int err = csoundStart(csound); CU_ASSERT(err == CSOUND_SUCCESS); csoundGetControlChannel(csound, "1", &err); CU_ASSERT(err == CSOUND_SUCCESS) csoundSetControlChannel(csound, "1", 5.0); MYFLT pFields[] = {1.0, 0.0, 1.0}; err = csoundScoreEvent(csound, 'i', pFields, 3); err = csoundPerformKsmps(csound); CU_ASSERT(err == CSOUND_SUCCESS); CU_ASSERT_EQUAL(5.0, csoundGetControlChannel(csound, "2", NULL)); MYFLT pFields2[] = {2.0, 0.0, 1.0}; err = csoundScoreEvent(csound, 'i', pFields2, 3); CU_ASSERT(err == CSOUND_SUCCESS); err = csoundPerformKsmps(csound); CU_ASSERT(err == CSOUND_SUCCESS); CU_ASSERT_EQUAL(6.0, csoundGetControlChannel(csound, "3", NULL)); MYFLT pFields3[] = {3.0, 0.0, 1.0}; err = csoundScoreEvent(csound, 'i', pFields3, 3); CU_ASSERT(err == CSOUND_SUCCESS); err = csoundPerformKsmps(csound); CU_ASSERT(err == CSOUND_SUCCESS); CU_ASSERT_EQUAL(7.0, csoundGetControlChannel(csound, "4", NULL)); csoundCleanup(csound); csoundDestroyMessageBuffer(csound); csoundDestroy(csound); }
void test_next(void) { CSOUND* csound = csoundCreate(NULL); csoundCreateMessageBuffer(csound, 0); count = 0; csoundCompileOrc(csound, "instr 1\n" "Svar init \"hello\"\n" "ksig line 0, p3, 1\n" "ksig2 line 1, p3, 0\n" "asig3 oscils 0.5, 440, 0.5\n" "endin\n" "instr 30\n" "kvar init 10\n" "kvar = kvar + 1\n" "ksig2 line 1, p3, 0\n" "kvar = kvar + 1\n" "endin\n"); csoundInputMessage(csound, "i 1 0 0.1"); csoundInputMessage(csound, "i 1.2 0 0.1"); csoundInputMessage(csound, "i 30.1 0 0.01"); csoundInputMessage(csound, "i 30 0 0.01"); csoundInputMessage(csound, "i 30 1 0.11"); csoundInputMessage(csound, "i 1.3 0 0.1"); csoundStart(csound); csoundDebuggerInit(csound); csoundSetBreakpointCallback(csound, brkpt_cb8, NULL); csoundSetInstrumentBreakpoint(csound, 1.2, 0); csoundPerformKsmps(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); // Only the first call should have effect as we have already stopped csoundDebugNext(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); // Ignored csoundDebugNext(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); // Ignored csoundDebugNext(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); // Ignored csoundDebugNext(csound); csoundPerformKsmps(csound); csoundPerformKsmps(csound); // Ignored csoundRemoveInstrumentBreakpoint(csound, 1.2); csoundDebugContinue(csound); int i; for (i = 0; i < 200; i++) { csoundPerformKsmps(csound); } csoundSetBreakpointCallback(csound, brkpt_cb9, NULL); csoundSetInstrumentBreakpoint(csound, 30.1, 0); for (i = 0; i < 1000; i++) { csoundPerformKsmps(csound); } /* step to next line */ csoundDebugNext(csound); csoundPerformKsmps(csound); /* step to next line */ csoundDebugNext(csound); csoundPerformKsmps(csound); /* step to next line */ csoundDebugNext(csound); csoundPerformKsmps(csound); csoundDebuggerClean(csound); csoundDestroy(csound); CU_ASSERT_EQUAL(count, 5); }
PUBLIC int csoundStart(CSOUND *csound) // DEBUG { OPARMS *O = csound->oparms; int n; /* if a CSD was not used, check options */ if(csound->csdname == NULL) checkOptions(csound); if(csound->engineStatus & CS_STATE_COMP){ csound->Message(csound, "Csound is already started, call csoundReset()\n" "before starting again \n"); return CSOUND_ERROR; } { /* test for dummy module request */ char *s; if((s = csoundQueryGlobalVariable(csound, "_RTAUDIO")) != NULL) if(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || strcmp(s, "NULL") == 0) { csound->Message(csound, Str("setting dummy interface\n")); csound->SetPlayopenCallback(csound, playopen_dummy); csound->SetRecopenCallback(csound, recopen_dummy); csound->SetRtplayCallback(csound, rtplay_dummy); csound->SetRtrecordCallback(csound, rtrecord_dummy); csound->SetRtcloseCallback(csound, rtclose_dummy); csound->SetAudioDeviceListCallback(csound, audio_dev_list_dummy); } /* and midi */ if(csound->enableHostImplementedMIDIIO == 0){ if((s = csoundQueryGlobalVariable(csound, "_RTMIDI")) != NULL) if(strcmp(s, "null") == 0 || strcmp(s, "Null") == 0 || strcmp(s, "NULL") == 0) { csound->SetMIDIDeviceListCallback(csound, midi_dev_list_dummy); csound->SetExternalMidiInOpenCallback(csound, DummyMidiInOpen); csound->SetExternalMidiReadCallback(csound, DummyMidiRead); csound->SetExternalMidiInCloseCallback(csound, NULL); csound->SetExternalMidiOutOpenCallback(csound, DummyMidiOutOpen); csound->SetExternalMidiWriteCallback(csound, DummyMidiWrite); csound->SetExternalMidiOutCloseCallback(csound, NULL); } } else { s = csoundQueryGlobalVariable(csound, "_RTMIDI"); strcpy(s, "hostbased"); csoundSetConfigurationVariable(csound,"rtmidi", s); } } /* VL 30-12-12 csoundInitModules is always called here now to enable Csound to start without calling csoundCompile, but directly from csoundCompileOrc() and csoundReadSco() */ if(csound->modules_loaded == 0){ csoundLoadExternals(csound); /* load plugin opcodes */ if (csoundInitModules(csound) != 0) csound->LongJmp(csound, 1); csound->modules_loaded = 1; } if (csound->instr0 == NULL) { /* compile dummy instr0 to allow csound to start with no orchestra */ csoundCompileOrc(csound, "idummy = 0 \n"); } if ((n = setjmp(csound->exitjmp)) != 0) { return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); } /* if sound file type is still not known, check SFOUTYP */ if (O->filetyp <= 0) { const char *envoutyp; envoutyp = csoundGetEnv(csound, "SFOUTYP"); if (envoutyp != NULL && envoutyp[0] != '\0') { if (strcmp(envoutyp, "AIFF") == 0) O->filetyp = TYP_AIFF; else if (strcmp(envoutyp, "WAV") == 0 || strcmp(envoutyp, "WAVE") == 0) O->filetyp = TYP_WAV; else if (strcmp(envoutyp, "IRCAM") == 0) O->filetyp = TYP_IRCAM; else if (strcmp(envoutyp, "RAW") == 0) O->filetyp = TYP_RAW; else { dieu(csound, Str("%s not a recognised SFOUTYP env setting"), envoutyp); } } else #if !defined(__MACH__) O->filetyp = TYP_WAV; /* default to WAV if even SFOUTYP is unset */ #else O->filetyp = TYP_AIFF; /* ... or AIFF on the Mac */ #endif } /* everything other than a raw sound file has a header */ O->sfheader = (O->filetyp == TYP_RAW ? 0 : 1); if (O->Linein || O->Midiin || O->FMidiin) O->RTevents = 1; if (!O->sfheader) O->rewrt_hdr = 0; /* cannot rewrite header of headerless file */ /* VL 9 04 15: these not need occur jointly anymore */ /* if (O->sr_override || O->kr_override) { if (!O->sr_override || !O->kr_override) dieu(csound, Str("srate and krate overrides must occur jointly")); } */ if (!O->outformat) /* if no audioformat yet */ O->outformat = AE_SHORT; /* default to short_ints */ O->sfsampsize = sfsampsize(FORMAT2SF(O->outformat)); O->informat = O->outformat; /* informat default */ if (O->numThreads > 1) { void csp_barrier_alloc(CSOUND *, pthread_barrier_t **, int); int i; THREADINFO *current = NULL; csound->multiThreadedBarrier1 = csound->CreateBarrier(O->numThreads); csound->multiThreadedBarrier2 = csound->CreateBarrier(O->numThreads); csp_barrier_alloc(csound, &(csound->barrier1), O->numThreads); csp_barrier_alloc(csound, &(csound->barrier2), O->numThreads); csound->multiThreadedComplete = 0; for (i = 1; i < O->numThreads; i++) { THREADINFO *t = csound->Malloc(csound, sizeof(THREADINFO)); t->threadId = csound->CreateThread(&kperfThread, (void *)csound); t->next = NULL; if (current == NULL) { csound->multiThreadedThreadInfo = t; } else { current->next = t; } current = t; } csound->WaitBarrier(csound->barrier2); } csound->engineStatus |= CS_STATE_COMP; if(csound->oparms->daemon > 1) UDPServerStart(csound,csound->oparms->daemon); return musmon(csound); }
PUBLIC int csoundCompileArgs(CSOUND *csound, int argc, char **argv) { OPARMS *O = csound->oparms; char *s; FILE *xfile = NULL; int n; int csdFound = 0; char *fileDir; if ((n = setjmp(csound->exitjmp)) != 0) { return ((n - CSOUND_EXITJMP_SUCCESS) | CSOUND_EXITJMP_SUCCESS); } if(csound->engineStatus & CS_STATE_COMP){ csound->Message(csound, Str("Csound is already started, call csoundReset()\n" "before starting again \n")); return CSOUND_ERROR; } if (--argc <= 0) { dieu(csound, Str("insufficient arguments")); } /* command line: allow orc/sco/csd name */ csound->orcname_mode = 0; /* 0: normal, 1: ignore, 2: fail */ if (argdecode(csound, argc, argv) == 0) csound->LongJmp(csound, 1); /* do not allow orc/sco/csd name in .csound6rc */ csound->orcname_mode = 2; checkOptions(csound); if (csound->delayederrormessages) { if (O->msglevel>8) csound->Warning(csound, csound->delayederrormessages); free(csound->delayederrormessages); csound->delayederrormessages = NULL; } /* check for CSD file */ if (csound->orchname == NULL) { if(csound->info_message_request) { csound->info_message_request = 0; csound->LongJmp(csound, 1); } else if(csound->oparms->daemon == 0) dieu(csound, Str("no orchestra name")); } else if (csound->use_only_orchfile == 0 && (csound->scorename == NULL || csound->scorename[0] == (char) 0) && csound->orchname[0] != '\0') { /* FIXME: allow orc/sco/csd name in CSD file: does this work ? */ csound->orcname_mode = 0; csound->Message(csound, "UnifiedCSD: %s\n", csound->orchname); /* Add directory of CSD file to search paths before orchname gets * replaced with temp orch name if default paths is enabled */ if (!O->noDefaultPaths) { fileDir = csoundGetDirectoryForPath(csound, csound->orchname); csoundAppendEnv(csound, "SADIR", fileDir); csoundAppendEnv(csound, "SSDIR", fileDir); csoundAppendEnv(csound, "INCDIR", fileDir); csoundAppendEnv(csound, "MFDIR", fileDir); csound->Free(csound, fileDir); } if(csound->orchname != NULL) { csound->csdname = csound->orchname; /* save original CSD name */ if (!read_unified_file(csound, &(csound->orchname), &(csound->scorename))) { csound->Die(csound, Str("Reading CSD failed ... stopping")); } csdFound = 1; } } /* IV - Feb 19 2005: run a second pass of argdecode so that */ /* command line options override CSD options */ /* this assumes that argdecode is safe to run multiple times */ csound->orcname_mode = 1; /* ignore orc/sco name */ argdecode(csound, argc, argv); /* should not fail this time */ /* some error checking */ if (csound->stdin_assign_flg && (csound->stdin_assign_flg & (csound->stdin_assign_flg - 1)) != 0) { csound->Die(csound, Str("error: multiple uses of stdin")); } if (csound->stdout_assign_flg && (csound->stdout_assign_flg & (csound->stdout_assign_flg - 1)) != 0) { csound->Die(csound, Str("error: multiple uses of stdout")); } /* done parsing csound6rc, CSD, and command line options */ if (csound->scorename == NULL && csound->scorestr==NULL) { /* No scorename yet */ csound->scorestr = corfile_create_r("f0 800000000000.0\n"); corfile_flush(csound->scorestr); if (O->RTevents) csound->Message(csound, Str("realtime performance using dummy " "numeric scorefile\n")); } else if (!csdFound && !O->noDefaultPaths){ /* Add directory of SCO file to search paths*/ fileDir = csoundGetDirectoryForPath(csound, csound->scorename); csoundAppendEnv(csound, "SADIR", fileDir); csoundAppendEnv(csound, "SSDIR", fileDir); csoundAppendEnv(csound, "MFDIR", fileDir); csound->Free(csound, fileDir); } /* Add directory of ORC file to search paths*/ if (!csdFound && !O->noDefaultPaths) { fileDir = csoundGetDirectoryForPath(csound, csound->orchname); csoundAppendEnv(csound, "SADIR", fileDir); csoundAppendEnv(csound, "SSDIR", fileDir); csoundAppendEnv(csound, "MFDIR", fileDir); csound->Free(csound, fileDir); } if (csound->orchstr==NULL && csound->orchname) { /* does not deal with search paths */ csound->Message(csound, Str("orchname: %s\n"), csound->orchname); csound->orchstr = copy_to_corefile(csound, csound->orchname, NULL, 0); if (csound->orchstr==NULL) csound->Die(csound, Str("Failed to open input file - %s\n"), csound->orchname); corfile_puts("\n#exit\n", csound->orchstr); corfile_putc('\0', csound->orchstr); corfile_putc('\0', csound->orchstr); //csound->orchname = NULL; } if (csound->xfilename != NULL) csound->Message(csound, "xfilename: %s\n", csound->xfilename); csoundLoadExternals(csound); /* load plugin opcodes */ /* VL: added this also to csoundReset() in csound.c */ if (csoundInitModules(csound) != 0) csound->LongJmp(csound, 1); if(csoundCompileOrc(csound, NULL) != 0){ if(csound->oparms->daemon == 0) csoundDie(csound, Str("cannot compile orchestra")); else { /* VL -- 21-10-13 Csound does not need to die on failure to compile. It can carry on, because new instruments can be compiled again */ csound->Warning(csound, Str("cannot compile orchestra.")); csound->Warning(csound, Str("Csound will start with no instruments")); } } csound->modules_loaded = 1; s = csoundQueryGlobalVariable(csound, "_RTMIDI"); if (csound->enableHostImplementedMIDIIO == 1) { if (s == NULL) { s = "hostbased"; } else { strcpy(s, "hostbased"); } csoundSetConfigurationVariable(csound,"rtmidi", s); } /* IV - Jan 28 2005 */ print_benchmark_info(csound, Str("end of orchestra compile")); if (!csoundYield(csound)) return -1; /* IV - Oct 31 2002: now we can read and sort the score */ if (csound->scorename != NULL && (n = strlen(csound->scorename)) > 4 && /* if score ?.srt or ?.xtr */ (!strcmp(csound->scorename + (n - 4), ".srt") || !strcmp(csound->scorename + (n - 4), ".xtr"))) { csound->Message(csound, Str("using previous %s\n"), csound->scorename); //playscore = sortedscore = csound->scorename; /* use that one */ csound->scorestr = NULL; csound->scorestr = copy_to_corefile(csound, csound->scorename, NULL, 1); } else { //sortedscore = NULL; if (csound->scorestr==NULL) { csound->scorestr = copy_to_corefile(csound, csound->scorename, NULL, 1); if (csound->scorestr==NULL) csoundDie(csound, Str("cannot open scorefile %s"), csound->scorename); } csound->Message(csound, Str("sorting score ...\n")); scsortstr(csound, csound->scorestr); if (csound->keep_tmp) { FILE *ff = fopen("score.srt", "w"); fputs(corfile_body(csound->scstr), ff); fclose(ff); } } if (csound->xfilename != NULL) { /* optionally extract */ if (!(xfile = fopen(csound->xfilename, "r"))) csoundDie(csound, Str("cannot open extract file %s"),csound->xfilename); csoundNotifyFileOpened(csound, csound->xfilename, CSFTYPE_EXTRACT_PARMS, 0, 0); csound->Message(csound, Str(" ... extracting ...\n")); scxtract(csound, csound->scstr, xfile); fclose(xfile); csound->tempStatus &= ~csPlayScoMask; } csound->Message(csound, Str("\t... done\n")); /* copy sorted score name */ O->playscore = csound->scstr; /* IV - Jan 28 2005 */ print_benchmark_info(csound, Str("end of score sort")); if (O->syntaxCheckOnly) { csound->Message(csound, Str("Syntax check completed.\n")); return CSOUND_EXITJMP_SUCCESS; } /* open MIDI output (moved here from argdecode) */ if (O->Midioutname != NULL && O->Midioutname[0] == (char) '\0') O->Midioutname = NULL; if (O->FMidioutname != NULL && O->FMidioutname[0] == (char) '\0') O->FMidioutname = NULL; if (O->Midioutname != NULL || O->FMidioutname != NULL) openMIDIout(csound); return CSOUND_SUCCESS; }
uint32_t CsoundObj_compileOrc(CsoundObj *self, const char *string) { int returnValue = csoundCompileOrc(self->csound, (char *) string); csoundStart(self->csound); return returnValue; }