Exemple #1
0
void PdBase::PdContext::clear() {

    // detach callbacks
    if(bInited) {

        computeAudio(false);

        libpd_set_concatenated_printhook(NULL);

        libpd_set_banghook(NULL);
        libpd_set_floathook(NULL);
        libpd_set_symbolhook(NULL);
        libpd_set_listhook(NULL);
        libpd_set_messagehook(NULL);

        libpd_set_noteonhook(NULL);
        libpd_set_controlchangehook(NULL);
        libpd_set_programchangehook(NULL);
        libpd_set_pitchbendhook(NULL);
        libpd_set_aftertouchhook(NULL);
        libpd_set_polyaftertouchhook(NULL);

        libpd_set_midibytehook(NULL);
    }

    messages.clear();

    bInited = false;

    bMsgInProgress = false;
    curMsgLen = 0;
    msgType = MSG;
    midiPort = 0;
}
Exemple #2
0
int main(int argc, char **argv) {
    if (argc < 3) {
    fprintf(stderr, "usage: %s file folder\n", argv[0]);
    return -1;
    }

    // init pd
    int srate = 44100, foo;
    libpd_set_printhook((t_libpd_printhook)pdprint);
    libpd_set_noteonhook((t_libpd_noteonhook)pdnoteon);
    libpd_init();
    libpd_init_audio(1, 2, srate);

    // compute audio    [; pd dsp 1(
    libpd_start_message(1); // one entry in list
    libpd_add_float(1.0f);
    libpd_finish_message("pd", "dsp");

    // open patch       [; pd open file folder(
    void *file = libpd_openfile(argv[1], argv[2]);

    // now run pd
    for (foo = 0; foo < 2; foo++)  /* note: doesn't yet work the second time */
    {
        printf("running nogui for 1000 ticks...\n");

        runawhile(1);

        printf("starting gui..\n");
        if (libpd_start_gui("../../../pure-data/"))
            printf("gui startup failed\n");

        printf("running for 2000 more ticks...\n");
        runawhile(2);

        libpd_stop_gui();
    }

    printf("Closing and exiting\n");
    libpd_closefile(file);

    return 0;
}
Exemple #3
0
/// init the pd instance
bool PdBase::PdContext::init(const int numInChannels, const int numOutChannels, const int sampleRate) {

    // attach callbacks
	libpd_set_printhook(libpd_print_concatenator);
    libpd_set_concatenated_printhook(_print);

    libpd_set_banghook(_bang);
    libpd_set_floathook(_float);
    libpd_set_symbolhook(_symbol);
    libpd_set_listhook(_list);
    libpd_set_messagehook(_message);

    libpd_set_noteonhook(_noteon);
    libpd_set_controlchangehook(_controlchange);
    libpd_set_programchangehook(_programchange);
    libpd_set_pitchbendhook(_pitchbend);
    libpd_set_aftertouchhook(_aftertouch);
    libpd_set_polyaftertouchhook(_polyaftertouch);

    libpd_set_midibytehook(_midibyte);

    // init libpd, should only be called once!
	if(!bLibPDInited) {
		libpd_init();
		bLibPDInited = true;
	}
	// init audio
    if(libpd_init_audio(numInChannels, numOutChannels, sampleRate) != 0) {
        return false;
    }
    bInited = true;

    messages.clear();

    return bInited;
}
Exemple #4
0
int main(int argc, char **argv) {
  t_pdinstance *pd1 = pdinstance_new(), *pd2 = pdinstance_new();
  if (argc < 3) {
    fprintf(stderr, "usage: %s file folder\n", argv[0]);
    return -1;
  }
  
  int srate = 44100;
    // maybe these two calls should be available per-instnace somehow:
  libpd_set_printhook(pdprint);   
  libpd_set_noteonhook(pdnoteon);
    /* set a "current" instance before libpd_init() or else Pd will make
    an unnecessary third "default" instance. */
  pd_setinstance(pd1);
  libpd_init();
    /* ... here we'd sure like to be able to have number of channels be
    per-nstance.  The sample rate is still global within Pd but we might
    also consider relaxing that restrction. */
  libpd_init_audio(1, 2, srate);

  float inbuf[64], outbuf[128];  // one input channel, two output channels
                                 // block size 64, one tick per buffer

  pd_setinstance(pd1);  // talk to first pd instance 

  // compute audio    [; pd dsp 1(
  libpd_start_message(1); // one entry in list
  libpd_add_float(1.0f);
  libpd_finish_message("pd", "dsp");

  // open patch       [; pd open file folder(
  libpd_openfile(argv[1], argv[2]);

  pd_setinstance(pd2);

  // compute audio    [; pd dsp 1(
  libpd_start_message(1); // one entry in list
  libpd_add_float(1.0f);
  libpd_finish_message("pd", "dsp");

  // open patch       [; pd open file folder(
  libpd_openfile(argv[1], argv[2]);

    /* the following two messages can be sent without setting the pd nstance
    and anyhow the symbols are global so they may affect multiple instances.
    However, if the messages change anyhing in the pd instacne structure
    (DSP state; current time; list of all canvases n our instance) those
    changes will apply to the current Pd nstance, so the earlier messages,
    for instance, were sensitive to which was the current one. 
    
    Note also that I'm using the fact that $0 is set to 1003, 1004, ...
    as patches are opened -it would be better to opent the patches with 
    settable $1, etc parameters to libpd_openfile().  */
    
  // [; pd frequency 1 (
  libpd_start_message(1); // one entry in list
  libpd_add_float(1.0f);
  libpd_finish_message("1003-frequency", "float");

  // [; pd frequency 1 (
  libpd_start_message(1); // one entry in list
  libpd_add_float(2.0f);
  libpd_finish_message("1004-frequency", "float");

  // now run pd for ten seconds (logical time)
  int i, j;
  for (i = 0; i < 3; i++) {
    // fill inbuf here
    pd_setinstance(pd1);
    libpd_process_float(1, inbuf, outbuf);
    if (i < 2)
    {
        for (j = 0; j < 8; j++)
            printf("%f ", outbuf[j]);
        printf("\n");
    }
    pd_setinstance(pd2);
    libpd_process_float(1, inbuf, outbuf);
    if (i < 2)
    {
        for (j = 0; j < 8; j++)
            printf("%f ", outbuf[j]);
        printf("\n");
    }
  }

  return 0;
}