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; libpd_printhook = (t_libpd_printhook) pdprint; libpd_init(); libpd_init_audio(1, 2, srate, 1); float inbuf[64], outbuf[128]; // one input channel, two output channels // block size 64, one tick per buffer // compute audio [; pd dsp 1( libpd_start_message(); libpd_add_float(1.0f); libpd_finish_message("pd", "dsp"); // open patch [; pd open file folder( libpd_start_message(); libpd_add_symbol(argv[1]); libpd_add_symbol(argv[2]); libpd_finish_message("pd", "open"); // now run pd for ten seconds (logical time) int i; for (i = 0; i < 10 * srate / 64; i++) { // fill inbuf here libpd_process_float(inbuf, outbuf); // use outbuf here } return 0; }
void PdBase::addSymbol(const std::string& symbol) { PdContext& context = PdContext::instance(); if(!context.bMsgInProgress) { cerr << "Pd: Can not add symbol, message not in progress" << endl;; return; } if(context.msgType != MSG) { cerr << "Pd: Can not add symbol, midi byte stream in progress" << endl;; return; } if(context.curMsgLen+1 >= context.maxMsgLen) { cerr << "Pd: Can not add symbol, max message len of " << context.maxMsgLen << " reached" << endl; return; } _LOCK(); libpd_add_symbol(symbol.c_str()); _UNLOCK(); context.curMsgLen++; }
JNIEXPORT void JNICALL Java_org_puredata_core_PdBase_addSymbol (JNIEnv *env, jclass cls, jstring jsym) { if (!jsym) return; const char *csym = (char *) (*env)->GetStringUTFChars(env, jsym, NULL); libpd_add_symbol(csym); (*env)->ReleaseStringUTFChars(env, jsym, csym); }