Ejemplo n.º 1
0
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_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 CsoundObject_delete(CsoundObject *self)
{
    csoundStop(self->csound);
    csoundDestroy(self->csound);
    free(self);
    self = NULL;
}
Ejemplo n.º 4
0
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);
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
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);
}
Ejemplo n.º 7
0
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);
}
Ejemplo n.º 8
0
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);
}
Ejemplo n.º 9
0
void test_debugger_init(void)
{
    CSOUND* csound = csoundCreate(NULL);
    csoundCreateMessageBuffer(csound, 0);
    csoundDebuggerInit(csound);
    csoundDebuggerClean(csound);
    csoundDestroy(csound);
}
Ejemplo n.º 10
0
void test_add_callback(void)
{
    CSOUND* csound = csoundCreate(NULL);
    csoundCreateMessageBuffer(csound, 0);
    csoundDebuggerInit(csound);
    csoundSetBreakpointCallback(csound, brkpt_cb, NULL);
    csoundDebuggerClean(csound);
    csoundDestroy(csound);
}
Ejemplo n.º 11
0
 ~TamTamSound()
 {
     if (csound)
     {
         stop();
         ll->printf(2, "Going for csoundDestroy\n");
         csoundDestroy(csound);
     }
     ll->printf(2, "TamTamSound destroyed\n");
     delete ll;
 }
Ejemplo n.º 12
0
void ConfigLists::refreshModules()
{
	rtMidiNames.clear();
	rtAudioNames.clear();
#ifdef CSOUND6
	CSOUND *csound = csoundCreate(NULL);
	char *name, *type;
	int n = 0;
	while(!csoundGetModule(csound, n++, &name, &type)) {
		if (strcmp(type, "audio") == 0) {
			rtAudioNames << name;
//			printf("Module %d:  %s (%s) \n", n, name, type);
		}
	}
	rtAudioNames << "null"; // add also none (-+rtaudio=null)
	n = 0;
	while(!csoundGetModule(csound, n++, &name, &type)) {
		if (strcmp(type, "midi") == 0) {
			rtMidiNames << name;
//			printf("MIDI Module %d:  %s (%s) \n", n, name, type);
		}
	}
	rtMidiNames << "virtual" << "none";
#else
#ifdef Q_OS_LINUX
	rtAudioNames << "portaudio" << "alsa" << "jack" << "pulse" << "none";
#endif
#ifdef Q_OS_SOLARIS
	rtAudioNames << "portaudio" << "pulse" << "none";
#endif
#ifdef Q_OS_MAC
	rtAudioNames << "coreaudio" << "portaudio" << "auhal" << "jack" << "none";
#endif
#ifdef Q_OS_WIN32
	rtAudioNames << "portaudio" << "winmm" << "jack" <<  "none";
#endif
#ifdef Q_OS_HAIKU
	rtAudioNames << "haiku" << "none";
#endif
#ifdef Q_OS_LINUX
	rtMidiNames << "none" << "alsa" << "alsaseq" << "portmidi" << "virtual";
#endif
#ifdef Q_OS_SOLARIS
	rtMidiNames << "none" << "portmidi"<< "virtual";
#endif
#ifdef Q_OS_MAC
	rtMidiNames << "none" << "coremidi" << "portmidi" << "virtual";
#endif
#ifdef Q_OS_WIN32
	rtMidiNames << "none" << "winmm" << "portmidi" << "virtual";
#endif
#endif
    csoundDestroy(csound);
}
Ejemplo n.º 13
0
void test_add_bkpt(void)
{
    CSOUND* csound = csoundCreate(NULL);
    csoundCreateMessageBuffer(csound, 0);
    csoundDebuggerInit(csound);
    csoundSetBreakpoint(csound, 3, 0, 0);
    csoundSetBreakpoint(csound, 5, 1, 0);
    csoundSetInstrumentBreakpoint(csound, 3.4, 0);
    csoundSetInstrumentBreakpoint(csound, 1.1, 0);
    csoundClearBreakpoints(csound);
    csoundDebuggerClean(csound);
    csoundDestroy(csound);
}
Ejemplo n.º 14
0
void test_no_callback(void)
{
    CSOUND* csound = csoundCreate(NULL);
    csoundCreateMessageBuffer(csound, 0);
    csoundStart(csound);
    csoundDebuggerInit(csound);
    csoundSetInstrumentBreakpoint(csound, 1, 0);

    csoundPerformKsmps(csound);

    csoundDebuggerClean(csound);
    csoundDestroy(csound);
}
Ejemplo n.º 15
0
void test_line_breakpoint_orc_file(void)
{
    FILE *f = fopen("debug.orc", "w");
    CU_ASSERT_PTR_NOT_NULL(f);

    const char *orc = "\n"
                      "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";
    fprintf(f, "%s", orc);
    fclose(f);
    f = fopen("debug.sco", "w");
    CU_ASSERT_PTR_NOT_NULL(f);

    const char *sco = "i 1 0 1\n";
    fprintf(f, "%s", sco);
    fclose(f);
    count = 0;
    CSOUND* csound = csoundCreate(NULL);

    csoundCreateMessageBuffer(csound, 0);
    const char* argv[] = {"csound", "debug.orc", "debug.sco"};
    csoundCompile(csound, 3, (char **) argv);

    csoundDebuggerInit(csound);
    int line = 5;
    csoundSetBreakpointCallback(csound, brkpt_cb7, &line);
    csoundSetBreakpoint(csound, line, 0, 0);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
    csoundRemoveBreakpoint(csound, line, 0);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);

    line = 6;
    csoundSetBreakpoint(csound, line, 0, 0);
    csoundPerformKsmps(csound);
    csoundDebugContinue(csound);
//    csoundPerformKsmps(csound);

    csoundDebuggerClean(csound);
    CU_ASSERT_EQUAL(count, 2);
    csoundDestroy(csound);
}
Ejemplo n.º 16
0
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);
}
Ejemplo n.º 17
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);
}
Ejemplo n.º 18
0
int main(void)                          /* stdio stub for standalone scsort */
{
    CSOUND *csound;
    int    err;

    csound = csoundCreate(NULL);
#if defined(LINUX) || defined(SGI) || defined(sol) || \
    defined(__MACH__) || defined(__EMX__)
    signal(SIGPIPE, SIG_DFL);
#endif
    csoundSetMessageCallback(csound, msg_callback);
    err = csoundScoreSort(csound, stdin, stdout);
    csoundDestroy(csound);

    return err;
}
Ejemplo n.º 19
0
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);

}
Ejemplo n.º 20
0
int main(int argc, char **argv)
{
    CSOUND  *csound;
    char    *fname = NULL;
    int     k, result;
    PVSDATEXT dataout, datain;

    /* initialise PVSATEXT data */
    datain.N = 1024;
    datain.format = 0;
    datain.overlap = 256;
    datain.winsize = 1024;
    datain.frame = (float *) calloc(sizeof(float),(datain.N+2));

    dataout.N = 1024;
    dataout.format = 0;
    dataout.overlap = 256;
    dataout.winsize = 1024;
    dataout.frame = (float *) calloc(sizeof(float),(dataout.N+2));

    /*  Create Csound. */
    csound = csoundCreate(NULL);

    /*  One complete performance cycle. */
    result = csoundCompile(csound, argc, argv);
    while (!result){

      /* copy data from pvs out to pvs in bus */
      for(k=0; k < 1026; k++)
          datain.frame[k] = dataout.frame[k];
      datain.framecount = dataout.framecount;
      /* send in the pvs in bus data */
      csoundSetPvsChannel(csound, &datain, "0");
      /* one ksmps pass */
      result = csoundPerformKsmps(csound);
      /* receive the pvs out bus data */
      csoundGetPvsChannel(csound, &dataout, "0");
    }
    /* delete Csound instance */
    csoundDestroy(csound);
    free(datain.frame);
    free(dataout.frame);
    return (result >= 0 ? 0 : result);
}
Ejemplo n.º 21
0
QList<QPair<QString, QString> > ConfigLists::getAudioInputDevices(QString module)
{
	//  qDebug("CsoundQt::getAudioInputDevices()");
	QList<QPair<QString, QString> > deviceList;
#ifdef CSOUND6
	CSOUND *cs = csoundCreate(NULL);
	csoundSetRTAudioModule(cs, module.toLatin1().data());
	int i,newn, n = csoundGetAudioDevList(cs,NULL,0);
	CS_AUDIODEVICE *devs = (CS_AUDIODEVICE *) malloc(n*sizeof(CS_AUDIODEVICE));
	newn = csoundGetAudioDevList(cs,devs,0);
	if (newn != n) {
		qDebug() << "ConfigLists::getAudioInputDevices Device number changed";
		return deviceList;
	}
	for (i = 0; i < n; i++) {
//		qDebug() << devs[i].device_name;
		deviceList.append(QPair<QString,QString>(devs[i].device_name,  QString(devs[i].device_id)));
	}
	free(devs);
    csoundDestroy(cs);
#else
	if (module == "none") {
		return deviceList;
	}
	if (module == "alsa") {
		QFile f("/proc/asound/pcm");
		f.open(QIODevice::ReadOnly | QIODevice::Text);
		QString values = QString(f.readAll());
		QStringList st = values.split("\n");
		foreach (QString line, st) {
			if (line.indexOf("capture") >= 0) {
				QStringList parts = line.split(":");

				QStringList cardId = parts[0].split("-");
				QString buffer = "";
				buffer.append(parts[1]).append(" : ").append(parts[2]);

				QPair<QString, QString> device;
				device.first = buffer;
				device.second = "adc:hw:" + QString::number(cardId[0].toInt()) + "," + QString::number(cardId[1].toInt());
				deviceList.append(device);
			}
		}
	}
Ejemplo n.º 22
0
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);
}
Ejemplo n.º 23
0
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);
}
Ejemplo n.º 24
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);
}
Ejemplo n.º 25
0
void test_create_buffer(void)
{
    csoundSetGlobalEnv("OPCODE6DIR64", "../../");
    CSOUND *csound = csoundCreate(0);
    int argc = 2;
    char *argv[] = {"csound", "-v"};
    csoundCreateMessageBuffer(csound, 0);
    int result = csoundCompile(csound, argc, argv);

    int cnt = csoundGetMessageCnt(csound);
    CU_ASSERT(cnt > 0);
    const char * msg = csoundGetFirstMessage(csound);
    CU_ASSERT_PTR_NOT_NULL(msg);
    int newcnt = csoundGetMessageCnt(csound);
    CU_ASSERT_EQUAL(cnt, newcnt);
    csoundPopFirstMessage(csound);
    newcnt = csoundGetMessageCnt(csound);
    CU_ASSERT_EQUAL(cnt - 1, newcnt);

    csoundCleanup(csound);
    csoundDestroyMessageBuffer(csound);
    csoundDestroy(csound);
}
Ejemplo n.º 26
0
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);
}
Ejemplo n.º 27
0
QHash<QString,QString> ConfigLists::getMidiInputDevices(QString module)
{
	// based on code by Steven Yi
	QHash<QString,QString> deviceList;
#ifdef CSOUND6
	CSOUND *cs = csoundCreate(NULL);
	csoundSetMIDIModule(cs, module.toLatin1().data());
	int i,newn, n = csoundGetMIDIDevList(cs,NULL,0);
	CS_MIDIDEVICE *devs = (CS_MIDIDEVICE *) malloc(n*sizeof(CS_MIDIDEVICE));
	newn = csoundGetMIDIDevList(cs,devs,0);
	if (newn != n) {
		qDebug() << "ConfigLists::getMidiInputDevices Device number changed";
		return deviceList;
	}
	for (i = 0; i < n; i++) {
//		qDebug() << devs[i].device_name;
		QString displayName = QString("%1 (%2)").arg(devs[i].device_name).arg(devs[i].interface_name);
		deviceList.insert(displayName, QString(devs[i].device_id));
	}
	free(devs);
    csoundDestroy(cs);
#else
	if (module == "none") {
		return deviceList;
	}
	if (module == "alsa") {
		QProcess amidi;
		amidi.start("amidi", QStringList() << "-l");
		if (!amidi.waitForFinished())
			return deviceList;

		QByteArray result = amidi.readAllStandardOutput();
		QString values = QString(result);
		QStringList st = values.split("\n");
		st.takeFirst(); // Remove first column lines
		for (int i = 0; i < st.size(); i++){
			QStringList parts = st[i].split(" ", QString::SkipEmptyParts);
			if (parts.size() > 0 && parts[0].contains("I")) {
				QString devname = parts[1]; // Devce name
				parts.takeFirst(); // Remove IO flags
				QString fullname = parts.join(" ") ; // Full name with description
				deviceList.insert(fullname, devname);
			}
		}
		deviceList.insert("All available devices ", "a");
	}
	else if (module == "virtual") {
		QString name = qApp->translate("Enabled", "Virtual MIDI keyboard Enabled");
		deviceList.insert(name, "0");
	}
	else { // if not alsa (i.e. winmm or portmidi)
		QFile file(":/test.csd");
		if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
			return deviceList;
		QString jackCSD = QString(file.readAll());
		QString tempText = jackCSD;
		tempText.replace("$SR", "441000");
		QTemporaryFile tempFile(QDir::tempPath() + QDir::separator() + "testcsdCsoundQtXXXXXX.csd");
		tempFile.open();
		QTextStream out(&tempFile);
		out << tempText;
		tempFile.close();
		tempFile.open();

		QStringList flags;
		QString rtMidiFlag = "-+rtmidi=" + module;
		flags << "-+msg_color=false" << rtMidiFlag << "-otest"  << "-n"  << "-M999" << tempFile.fileName();
		QStringList messages = runCsoundInternally(flags);

		QString startText, endText;
		if (module == "portmidi") {
			startText = "The available MIDI";
			endText = "*** PortMIDI";
		}
		else if (module == "winmm") {
			startText = "The available MIDI";
			endText = "rtmidi: input device number is out of range";
		}
		else if (module == "coremidi") {
			int index = messages.indexOf(QRegExp("[0-9]{1,1} MIDI sources in system\\s*"));
            if (index >= 0) {
                for (int i = 0; i < messages[index].split(" ")[0].toInt(); i++) {
                    deviceList.insert(QString::number(i), QString::number(i));
                }
            }
		}
		else if (module == "alsaseq") {
			//FIXME parse alsaseq devices
		}
		if (startText == "" && endText == "") {
			return deviceList;
		}
		bool collect = false;
		foreach (QString line, messages) {
			if (collect) {
				if (endText.length() > 0 && line.indexOf(endText) >= 0) {
					collect = false;
				}
				else {
					if (line.indexOf(":") >= 0) {
//						qDebug() << "getMidiInputDevices " << line;
						QString fullname = line.mid(line.indexOf(":") + 1).trimmed();
						QString devname = line.mid(0,line.indexOf(":")).trimmed();
						deviceList.insert(fullname, devname);
					}
				}
			}
			else if (line.indexOf(startText) >= 0) {
				collect = true;
			}
		}
	}
#endif
	return deviceList;
}
Ejemplo n.º 28
0
QList<QPair<QString, QString> > ConfigLists::getMidiOutputDevices(QString module)
{
	QList<QPair<QString, QString> > deviceList;
#ifdef CSOUND6
	CSOUND *cs = csoundCreate(NULL);
	csoundSetMIDIModule(cs, module.toLatin1().data());
	int i,newn, n = csoundGetMIDIDevList(cs,NULL,1);
	CS_MIDIDEVICE *devs = (CS_MIDIDEVICE *) malloc(n*sizeof(CS_MIDIDEVICE));
	newn = csoundGetMIDIDevList(cs,devs,1);
	if (newn != n) {
		qDebug() << "ConfigLists::getMidiOutputDevices Device number changed";
		return deviceList;
	}
	for (i = 0; i < n; i++) {
//		qDebug() << devs[i].device_name;
		QString displayName = QString("%1 (%2)").arg(devs[i].device_name).arg(devs[i].interface_name);
		deviceList.append(QPair<QString,QString>(displayName, QString(devs[i].device_id)));
	}
	free(devs);
    csoundDestroy(cs);
#else
	if (module == "none") {
		return deviceList;
	}
	if (module == "alsa") {
		QProcess amidi;
		amidi.start("amidi", QStringList() << "-l");
		if (!amidi.waitForFinished())
			return deviceList;

		QByteArray result = amidi.readAllStandardOutput();
		QString values = QString(result);
		QStringList st = values.split("\n");
		st.takeFirst(); // Remove first column lines
		for (int i = 0; i < st.size(); i++){
			QStringList parts = st[i].split(" ", QString::SkipEmptyParts);
			if (parts.size() > 0 && parts[0].contains("O")) {
				QPair<QString, QString> device;
				device.second = parts[1]; // Devce name
				parts.takeFirst(); // Remove IO flags
				device.first = parts.join(" ") ; // Full name with description
				deviceList.append(device);
			}
		}
	}
	else if (module == "virtual") {
		// do nothing
	}
	else { // if not alsa (i.e. winmm or portmidi)
		QFile file(":/test.csd");
		if (!file.open(QIODevice::ReadOnly | QIODevice::Text))
			return deviceList;
		QString jackCSD = QString(file.readAll());
		QString tempText = jackCSD;
		tempText.replace("$SR", "441000");
		QTemporaryFile tempFile(QDir::tempPath() + QDir::separator() + "testcsdCsoundQtXXXXXX.csd");
		tempFile.open();
		QTextStream out(&tempFile);
		out << tempText;
		tempFile.close();
		tempFile.open();

		QStringList flags;
		flags << "-+msg_color=false" << "-otest"  << "-n"   << "-Q999" << tempFile.fileName();
		QStringList messages = runCsoundInternally(flags);

		QString startText, endText;
		if (module == "portmidi") {
			startText = "The available MIDI";
			endText = "*** PortMIDI";
		}
		else if (module == "winmm") {
			startText = "The available MIDI";
			endText = "rtmidi: output device number is out of range";
		}
		if (startText == "" && endText == "") {
			return deviceList;
		}
		bool collect = false;
		foreach (QString line, messages) {
			if (collect) {
				if (endText.length() > 0 && line.indexOf(endText) >= 0) {
					collect = false;
				}
				else {
					if (line.indexOf(":") >= 0) {
						qDebug("%s", line.toLocal8Bit().constData());
						QPair<QString, QString> device;
						device.first = line.mid(line.indexOf(":") + 1).trimmed();
						device.second = line.mid(0,line.indexOf(":")).trimmed();
						deviceList.append(device);
					}
				}
			}
			else if (line.indexOf(startText) >= 0) {
				collect = true;
			}
		}
	}
#endif
	return deviceList;
}
Ejemplo n.º 29
0
int main(int argc, char **argv)
{
    CSOUND  *csound;
    char    *fname = NULL;
    int     i, result, nomessages=0;
#ifdef GNU_GETTEXT
    const char* lang;
#endif
    install_signal_handler();
    csoundInitialize(CSOUNDINIT_NO_SIGNAL_HANDLER);

    /* set stdout to non buffering if not outputing to console window */
    if (!isatty(fileno(stdout))) {
#if !defined(WIN32)
      setvbuf(stdout, (char*) NULL, _IONBF, 0);
#endif
    }

#ifdef GNU_GETTEXT
    /* We need to set the locale for the translations to work */
    lang = csoundGetEnv(NULL, "CS_LANG");
    /* If set, use that. Otherwise use the system locale */
    if(lang == NULL)
        lang = setlocale(LC_MESSAGES, "");
    else
        lang = setlocale(LC_MESSAGES, lang);
    /* Should we warn if we couldn't set the locale (lang == NULL)? */
    /* If the strings for this binary are ever translated,
     * the textdomain should be set here */
#endif

    /* Real-time scheduling on Linux by Istvan Varga (Jan 6 2002) */
#ifdef LINUX
    if (set_rt_priority(argc, argv) != 0)
      return -1;

#endif
    /* open log file if specified */
    for (i = 1; i < argc; i++) {
      if (strncmp(argv[i], "-O", 2) == 0 && (int) strlen(argv[i]) > 2)
        fname = argv[i] + 2;
      else if (strncmp(argv[i], "--logfile=", 10) == 0 &&
               (int) strlen(argv[i]) > 10)
        fname = argv[i] + 10;
      else if (i < (argc - 1) && strcmp(argv[i], "-O") == 0)
        fname = argv[i + 1];
    }
    if (fname != NULL) {
      if (!strcmp(fname, "NULL") || !strcmp(fname, "null"))
               nomessages = 1;
      else if ((logFile = fopen(fname, "w")) == NULL) {
        fprintf(stderr, "Error opening log file '%s': %s\n",
                        fname, strerror(errno));
        return -1;
      }
    }
    /* if logging to file, set message callback */
    if (logFile != NULL)
      csoundSetDefaultMessageCallback(msg_callback);
    else if (nomessages)
      csoundSetDefaultMessageCallback(nomsg_callback);

    /*  Create Csound. */
    csound = csoundCreate(NULL);
    _csound = csound;

    /*  One complete performance cycle. */
    result = csoundCompile(csound, argc, argv);

     if(!result) csoundPerform(csound);

    /* delete Csound instance */
     csoundDestroy(csound);
     _csound = NULL;
    /* close log file */
    if (logFile != NULL)
      fclose(logFile);

    if(result == 0 && _result != 0) result = _result;
    // printf("csound returned with value: %d \n", result);
#if 0
    /* remove global configuration variables, if there are any */
    csoundDeleteAllGlobalConfigurationVariables();
#endif
    return (result >= 0 ? 0 : result);
}
Ejemplo n.º 30
0
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);
}