-
Notifications
You must be signed in to change notification settings - Fork 2
/
bpd-lampe~.cc
124 lines (104 loc) · 3.02 KB
/
bpd-lampe~.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#include <m_pd.h>
#include "lampes/lampes.h"
static t_class *bpd_lampe_tilde_class = nullptr;
enum e_modele_lampe {
#define L(x) L_##x,
MODELES_LAMPE(L)
#undef L
NUM_MODELES_LAMPE,
};
struct t_bpd_lampe_tilde {
t_object x_obj;
dsp *x_lampe;
float x_signalin;
t_outlet *x_otl_outp;
#define L(x) x *x_lampe_##x;
MODELES_LAMPE(L)
#undef L
t_symbol *x_lampe_syms[NUM_MODELES_LAMPE];
};
static void bpd_lampe_tilde_model(t_bpd_lampe_tilde *x, t_symbol *s);
static void *bpd_lampe_tilde_new(t_symbol *s, int argc, t_atom argv[])
{
t_bpd_lampe_tilde *x = (t_bpd_lampe_tilde *)pd_new(bpd_lampe_tilde_class);
t_float sr = sys_getsr();
#define L(lampe) \
x->x_lampe_##lampe = new lampe; \
x->x_lampe_##lampe->init(sr); \
x->x_lampe_syms[L_##lampe] = gensym(#lampe);
MODELES_LAMPE(L)
#undef L
x->x_lampe = x->x_lampe_T1_12AX7;
x->x_signalin = 0;
x->x_otl_outp = outlet_new(&x->x_obj, &s_signal);
switch (argc) {
default:
pd_free((t_pd *)x);
return nullptr;
case 1:
if (argv[0].a_type != A_SYMBOL) {
pd_free((t_pd *)x);
return nullptr;
}
bpd_lampe_tilde_model(x, argv[0].a_w.w_symbol);
break;
case 0:
break;
}
return x;
}
static void bpd_lampe_tilde_free(t_bpd_lampe_tilde *x)
{
#define L(lampe) delete x->x_lampe_##lampe;
MODELES_LAMPE(L)
#undef L
}
static t_int *bpd_lampe_tilde_perform(t_int *w)
{
t_bpd_lampe_tilde *x = (t_bpd_lampe_tilde *)*++w;
t_sample *in = (t_sample *)*++w;
t_sample *out = (t_sample *)*++w;
unsigned n = (t_int)*++w;
dsp *lampe = x->x_lampe;
lampe->compute(n, &in, &out);
return ++w;
}
static void bpd_lampe_tilde_dsp(t_bpd_lampe_tilde *x, t_signal **sp)
{
dsp_add(&bpd_lampe_tilde_perform, 4, x, sp[0]->s_vec, sp[1]->s_vec, (t_int)sp[0]->s_n);
}
static void bpd_lampe_tilde_model(t_bpd_lampe_tilde *x, t_symbol *s)
{
dsp *lampe = nullptr;
#define L(l) \
if (s == x->x_lampe_syms[L_##l]) { lampe = x->x_lampe_##l; } \
else
MODELES_LAMPE(L)
#undef L
{
error(u8"bpd-lampe~ : modèle de lampe inconnu \"%s\"", s->s_name);
return;
}
if (lampe != x->x_lampe) {
lampe->instanceClear();
x->x_lampe = lampe;
}
}
extern "C" {
EXTERN void setup_bpd0x2dlampe_tilde()
{
t_class *cls = bpd_lampe_tilde_class = class_new(
gensym("bpd-lampe~"),
(t_newmethod)&bpd_lampe_tilde_new,
(t_method)&bpd_lampe_tilde_free,
sizeof(t_bpd_lampe_tilde),
CLASS_DEFAULT,
A_GIMME, A_NULL);
CLASS_MAINSIGNALIN(
cls, t_bpd_lampe_tilde, x_signalin);
class_addmethod(
cls, (t_method)&bpd_lampe_tilde_dsp, gensym("dsp"), A_CANT, A_NULL);
class_addmethod(
cls, (t_method)&bpd_lampe_tilde_model, gensym("model"), A_SYMBOL, A_NULL);
}
} // extern "C"