Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pd multichannel improvements #1037

Merged
merged 3 commits into from
Jul 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 33 additions & 14 deletions architecture/puredata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Please note that this is to be compiled as a shared library, which is
then loaded dynamically by Pd as an external. */

#include <assert.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
Expand Down Expand Up @@ -317,6 +318,17 @@ void PdUI::run() {}
#include <string>
#include "m_pd.h"

// For some reason, the first inlet has always been
// reserved for messages, so the input signals (if any)
// would only start at the *second* inlet.
// This is not very idiomatic as the first inlet can
// be a signal inlet and still take messages.
// If MESSAGE_INLET is 0, the first inlet becomes a
// signal inlet; otherwise, you get the old behavior.
#ifndef MESSAGE_INLET
#define MESSAGE_INLET 1
#endif

// for dlsym() resp. GetProcAddress()
#ifdef _WIN32
# include <windows.h>
Expand Down Expand Up @@ -349,11 +361,6 @@ static t_class *faust_class;

struct t_faust {
t_object x_obj;
#ifdef __MINGW32__
/* This seems to be necessary as some as yet undetermined Pd routine seems
to write past the end of x_obj on Windows. */
int fence; /* dummy field (not used) */
#endif
mydsp *dsp;
PdUI *ui;
std::string *label;
Expand Down Expand Up @@ -500,30 +507,30 @@ static void faust_dsp(t_faust *x, t_signal **sp)
* class, we need to call signal_setmultiout() on all outputs
* - even in single-channel mode! */
if (x->multi) {
g_signal_setmultiout(&sp[2], x->n_out);
g_signal_setmultiout(&sp[1], x->n_out);
} else {
for (int i = 0; i < x->n_out; ++i) {
g_signal_setmultiout(&sp[x->n_in+i+1], 1);
g_signal_setmultiout(&sp[x->n_in+i], 1);
}
}
}
/* now we can store the input and output signals */
if (x->multi) {
for (int i = 0; i < x->n_in; i++) {
if (i < sp[1]->s_nchans)
x->inputs[i] = sp[1]->s_vec + (i*n);
if (i < sp[0]->s_nchans)
x->inputs[i] = sp[0]->s_vec + (i*n);
else
x->inputs[i] = x->dummy;
}
for (int i = 0; i < x->n_out; i++)
x->outputs[i] = sp[2]->s_vec + (i*n);
x->outputs[i] = sp[1]->s_vec + (i*n);
} else
#endif
{
for (int i = 0; i < x->n_in; i++)
x->inputs[i] = sp[i+1]->s_vec;
x->inputs[i] = sp[i]->s_vec;
for (int i = 0; i < x->n_out; i++)
x->outputs[i] = sp[x->n_in+i+1]->s_vec;
x->outputs[i] = sp[x->n_in+i]->s_vec;
}

dsp_add(faust_perform, 2, x, (t_int)n);
Expand Down Expand Up @@ -683,6 +690,7 @@ static void *faust_new(t_symbol *s, int argc, t_atom *argv)
}
x->n_in = x->dsp->getNumInputs();
x->n_out = x->dsp->getNumOutputs();
assert((x->n_in + x->n_out) > 0); /* there must be at least one signal */
if (x->n_in > 0)
x->inputs = (t_sample**)malloc(x->n_in*sizeof(t_sample*));
if (x->n_out > 0) {
Expand All @@ -694,11 +702,19 @@ static void *faust_new(t_symbol *s, int argc, t_atom *argv)
x->dsp->init(sr);
x->dsp->buildUserInterface(x->ui);
if (x->multi) {
// only create a single (multi-channel) signal inlet and outlet
/* only create a single (multi-channel) signal inlet and outlet;
* NB: if MESSAGE_INLET is 0, we already have a signal inlet! */
#if MESSAGE_INLET
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
#endif
outlet_new(&x->x_obj, &s_signal);
} else {
#if MESSAGE_INLET
for (int i = 0; i < x->n_in; i++)
#else
/* we already have a signal inlet */
for (int i = 1; i < x->n_in; i++)
#endif
inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal);
for (int i = 0; i < x->n_out; i++)
outlet_new(&x->x_obj, &s_signal);
Expand Down Expand Up @@ -733,8 +749,11 @@ extern "C" void faust_setup(mydsp)
faust_class = class_new(s, (t_newmethod)faust_new, (t_method)faust_free,
sizeof(t_faust), classflags, A_GIMME, A_NULL);
class_addmethod(faust_class, (t_method)faust_dsp, gensym((char*)"dsp"), A_NULL);
#if !MESSAGE_INLET
/* the first inlet is a signal inlet */
CLASS_MAINSIGNALIN(faust_class, t_faust, f);
#endif
class_addanything(faust_class, faust_any);
class_addmethod(faust_class, nullfn, &s_signal, A_NULL);
s_button = gensym((char*)"button");
s_checkbox = gensym((char*)"checkbox");
s_vslider = gensym((char*)"vslider");
Expand Down