Commit 17752a6c64daf683813798beb68b8c8b81c10f0a

Thomas de Grivel 2020-03-04T14:03:48

Downgrade to C89 = ANSI C

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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
diff --git a/Makefile.am b/Makefile.am
index 75aa87d..999d613 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -12,6 +12,8 @@ else
 AM_CFLAGS = -DNDEBUG -O2
 endif
 
+AM_CFLAGS += -std=c89 -pedantic
+
 lib_LTLIBRARIES += librtbuf.la
 librtbuf_la_CFLAGS = ${LIBRTBUF_CFLAGS}
 librtbuf_la_LIBADD = ${LIBRTBUF_LIBS}
diff --git a/rtbuf.c b/rtbuf.c
index 92bf3d0..4ecb531 100644
--- a/rtbuf.c
+++ b/rtbuf.c
@@ -523,3 +523,18 @@ void rtbuf_print_sorted ()
   }
   printf("\n");
 }
+
+double min (double a, double b)
+{
+  return a < b ? a : b;
+}
+
+double max (double a, double b)
+{
+  return a < b ? b : a;
+}
+
+double clamp (double inf, double x, double sup)
+{
+  return max(inf, min(x, sup));
+}
diff --git a/rtbuf.h b/rtbuf.h
index 25cc225..b2e54fb 100644
--- a/rtbuf.h
+++ b/rtbuf.h
@@ -71,22 +71,8 @@ void  rtbuf_print_sorted ();
 
 int  rtbuf_out_int (s_rtbuf *rtb, unsigned int out, int default_value);
 
-static inline
-double min (double a, double b)
-{
-  return a < b ? a : b;
-}
-
-static inline
-double max (double a, double b)
-{
-  return a < b ? b : a;
-}
-
-static inline
-double clamp (double inf, double x, double sup)
-{
-  return max(inf, min(x, sup));
-}
+double min (double a, double b);
+double max (double a, double b);
+double clamp (double inf, double x, double sup);
 
 #endif /* RTBUF_H */
diff --git a/rtbuf_cli.c b/rtbuf_cli.c
index e26add4..6f8c6db 100644
--- a/rtbuf_cli.c
+++ b/rtbuf_cli.c
@@ -69,7 +69,7 @@ int rtbuf_cli_load (int argc, const char *argv[])
     printf("load failed\n");
     return -1;
   }
-  i = ((void*) lib - (void*) g_rtbuf_lib) / sizeof(s_rtbuf_lib);
+  i = ((char*) lib - (char*) g_rtbuf_lib) / sizeof(s_rtbuf_lib);
   rtbuf_lib_print(i);
   return 0;
 }
@@ -271,8 +271,8 @@ int rtbuf_cli_help (int argc, const char *argv[])
          " load PATH                   Load library at PATH.\n"
          " buffers                     List buffers.\n"
          " buffer N                    Show buffer N.\n"
-         " set VAR = buffer N          Set variable.\n"
-         " new LIB PROC                Instanciate library procedure.\n"
+         " set VAR = buffer N          Set variable.\n");
+  printf(" new LIB PROC                Instanciate library procedure.\n"
          " set VAR = new LIB PROC      Set variable.\n"
          " delete BUFFER               Unlink and delete RTBUF.\n"
          " bind SOURCE OUT DEST IN     Bind SOURCE OUT to DEST IN.\n"
@@ -314,14 +314,19 @@ s_cli_function rtbuf_cli_functions[] = {
 
 void debug_read (int argc, const char **argv, f_cli f)
 {
+  union {
+    f_cli f;
+    void *p;
+  } fp;
   if (argc < 1)
     return;
   printf("CLI READ %i %s(", argc, *argv);
   argv++;
   argc--;
+  fp.f = f;
   while (1) {
     if (argc < 1) {
-      printf("); %p\n", f);
+      printf("); %p\n", fp.p);
       return;
     }
     printf("%s", *argv);
diff --git a/rtbuf_defs.h b/rtbuf_defs.h
index b8faf3c..4d88bc7 100644
--- a/rtbuf_defs.h
+++ b/rtbuf_defs.h
@@ -28,7 +28,11 @@ typedef struct rtbuf_lib_proc_out s_rtbuf_lib_proc_out;
 typedef struct rtbuf_type         s_rtbuf_type;
 typedef struct rtbuf_var          s_rtbuf_var;
 typedef union rtbuf_var_data      u_rtbuf_var_data;
-typedef enum rtbuf_var_type       e_rtbuf_var_type;
+
+typedef enum rtbuf_var_type {
+  RTBUF_VAR_NULL  = 0,
+  RTBUF_VAR_RTBUF = 1
+} e_rtbuf_var_type;
 
 typedef int f_rtbuf_proc (s_rtbuf *rtbuf);
 typedef int f_rtbuf_lib_init (s_rtbuf_lib *lib);
diff --git a/rtbuf_glfw3_keyboard.c b/rtbuf_glfw3_keyboard.c
index 6a51b51..a623512 100644
--- a/rtbuf_glfw3_keyboard.c
+++ b/rtbuf_glfw3_keyboard.c
@@ -138,7 +138,7 @@ void rtbuf_glfw3_keyboard_size (GLFWwindow *w, int width,
   glLoadIdentity();
 }
 
-static inline
+static
 void rtbuf_glfw3_keyboard_draw_panel (float y1, float y2)
 {
   glColor3f(0.5f, 0.5f, 0.5f);
@@ -150,7 +150,7 @@ void rtbuf_glfw3_keyboard_draw_panel (float y1, float y2)
   glEnd();
 }
 
-static inline
+static
 void rtbuf_glfw3_keyboard_draw_white (unsigned int i, float n,
                                       float y1, float y2)
 {
@@ -165,7 +165,7 @@ void rtbuf_glfw3_keyboard_draw_white (unsigned int i, float n,
   glEnd();
 }
 
-static inline
+static
 void rtbuf_glfw3_keyboard_draw_black (unsigned int i, float n,
                                       float y1, float y2)
 {
diff --git a/rtbuf_gtk.c b/rtbuf_gtk.c
index 6d3579e..5acc998 100644
--- a/rtbuf_gtk.c
+++ b/rtbuf_gtk.c
@@ -27,12 +27,12 @@ void rtbuf_gtk_rtbuf_menu (RtbufWidget *widget, GdkEvent *event)
   gtk_menu_popup_at_pointer(menu, event);
 }
 
-gboolean rtbuf_gtk_rtbuf_label_mouse_down (GtkWidget *widget,
-                                           GdkEvent *event,
-                                           gpointer data)
+gboolean rtbuf_gtk_rtbuf_mouse_down (GtkWidget *widget,
+                                     GdkEvent *event,
+                                     gpointer data)
 {
-  (void) widget;
   (void) data;
+  printf("rtbuf-gtk rtbuf mouse down\n");
   if (event->type == GDK_BUTTON_PRESS) {
     GdkEventButton *eb = (GdkEventButton*) event;
     if (eb->button == 1) {
@@ -53,11 +53,14 @@ RtbufWidget * rtbuf_gtk_modular_layout_new (s_rtbuf *rtb,
                                             const gint x, const gint y)
 {
   RtbufWidget *widget = rtbuf_widget_new(rtb, "rtbuf");
-  GtkWidget *label;
+  GtkWidget *label = rtbuf_widget_get_label_widget(widget);
+  printf("rtbuf-gtk modular layout new\n");
+  gtk_widget_add_events(GTK_WIDGET(widget), GDK_BUTTON_PRESS_MASK);
+  gtk_widget_add_events(label, GDK_BUTTON_PRESS_MASK);
   gtk_layout_put(modular_layout, GTK_WIDGET(widget), x, y);
-  label = rtbuf_widget_get_label_widget(widget);
-  g_signal_connect(G_OBJECT(widget), "button-press-event",
-                   G_CALLBACK(rtbuf_gtk_rtbuf_label_mouse_down),
+  rtbuf_widget_set_label(widget, "test");
+  g_signal_connect(G_OBJECT(label), "button-press-event",
+                   G_CALLBACK(rtbuf_gtk_rtbuf_mouse_down),
                    NULL);
   return widget;
 }
diff --git a/rtbuf_lib.c b/rtbuf_lib.c
index d8c56a1..e3a00ef 100644
--- a/rtbuf_lib.c
+++ b/rtbuf_lib.c
@@ -161,7 +161,10 @@ s_rtbuf_lib * rtbuf_lib_load (const char *name)
   s_rtbuf_lib_proc *proc;
   unsigned long *ver;
   unsigned int i = 0;
-  f_rtbuf_lib_init *init;
+  union {
+    void *ptr;
+    f_rtbuf_lib_init *init;
+  } init_ptr;
   if (!lib)
     return 0;
   rtbuf_lib_load_path(lib, name);
@@ -170,12 +173,12 @@ s_rtbuf_lib * rtbuf_lib_load (const char *name)
     return 0;
   }
   ver = dlsym(lib->lib, "rtbuf_lib_ver");
-  //printf("lib_load ver %lu\n", *ver);
+  /* printf("lib_load ver %lu\n", *ver); */
   assert(*ver == RTBUF_LIB_VER);
   lib->name = symbol_intern(name);
-  //printf("lib_load name %s\n", lib->name);
-  if ((init = dlsym(lib->lib, "rtbuf_lib_init")))
-    if (init(lib) < 0) {
+  /* printf("lib_load name %s\n", lib->name); */
+  if ((init_ptr.ptr = dlsym(lib->lib, "rtbuf_lib_init")))
+    if (init_ptr.init(lib) < 0) {
       rtbuf_lib_delete(lib);
       return 0;
     }
diff --git a/rtbuf_music.c b/rtbuf_music.c
index eee7737..a0178cc 100644
--- a/rtbuf_music.c
+++ b/rtbuf_music.c
@@ -132,7 +132,7 @@ s_rtbuf_music_notes * rtbuf_music_notes (s_rtbuf *rtb,
   assert(target->proc);
   assert(v->out < target->proc->out_n);
   offset = target->proc->out[v->out].offset;
-  return (s_rtbuf_music_notes*) (target->data + offset);
+  return (s_rtbuf_music_notes*) ((char*) target->data + offset);
 }
 
 int rtbuf_music_note_p (s_rtbuf_music_note *note)
diff --git a/rtbuf_portaudio_output.c b/rtbuf_portaudio_output.c
index 156ecf4..0d210b6 100644
--- a/rtbuf_portaudio_output.c
+++ b/rtbuf_portaudio_output.c
@@ -83,7 +83,7 @@ int rtbuf_portaudio_output (s_rtbuf *rtb)
   }
   data = (s_rtbuf_portaudio_output_data*) rtb->data;
   sample = data->samples;
-  //printf("portaudio_output");
+  /* printf("portaudio_output"); */
   while (i < RTBUF_SIGNAL_SAMPLES) {
     j = 0;
     while (j < RTBUF_PORTAUDIO_CHANNELS) {
@@ -104,6 +104,6 @@ int rtbuf_portaudio_output (s_rtbuf *rtb)
     rtbuf_err(Pa_GetErrorText(err));
     rtbuf_err("portaudio output: Pa_WriteStream failed");
   }
-  //printf("\n");
+  /* printf("\n"); */
   return 0;
 }
diff --git a/rtbuf_signal.c b/rtbuf_signal.c
index dc11edd..56ca092 100644
--- a/rtbuf_signal.c
+++ b/rtbuf_signal.c
@@ -381,7 +381,7 @@ rtbuf_signal_sample (s_rtbuf *rtb,
     assert(out->type);
     if (out->type->t.bits >= sizeof(t_rtbuf_signal_sample) * 8) {
       t_rtbuf_signal_sample *sample = (t_rtbuf_signal_sample*)
-        (src->data + out->offset);
+        ((char*) src->data + out->offset);
       return *sample;
     }
   }
@@ -429,7 +429,7 @@ void rtbuf_signal_fun (s_rtbuf *rtb,
     out = &dest->proc->out[v->out];
     assert(out->type);
     if (out->type->t.bits >= sizeof(t_rtbuf_signal_sample) * 8)
-      rsf->signal = (double*)(dest->data + out->offset);
+      rsf->signal = (double*)((char*) dest->data + out->offset);
     if (out->type->t.bits >= sizeof(t_rtbuf_signal) * 8)
       rsf->sample_fun = rtbuf_signal_sample_from_signal;
   }
diff --git a/rtbuf_signal_sinus.c b/rtbuf_signal_sinus.c
index b881369..d7e5a46 100644
--- a/rtbuf_signal_sinus.c
+++ b/rtbuf_signal_sinus.c
@@ -46,7 +46,7 @@ int rtbuf_signal_sinus (s_rtbuf *rtb)
     f /= (double) RTBUF_SIGNAL_SAMPLERATE;
     data->phase = fmod(data->phase + 2.0 * M_PI * f, 2.0 * M_PI);
     data->signal[i] = a * sin(data->phase);
-    //printf(" i=%u f=%f a=%f %f", i, f, a, data->samples[i]);
+    /* printf(" i=%u f=%f a=%f %f", i, f, a, data->samples[i]); */
     i++;
   }
   return 0;
diff --git a/rtbuf_signal_square.c b/rtbuf_signal_square.c
index fb9cc73..90ea7f2 100644
--- a/rtbuf_signal_square.c
+++ b/rtbuf_signal_square.c
@@ -19,7 +19,7 @@
 #include "rtbuf.h"
 #include "rtbuf_signal.h"
 
-static inline
+static
 double square (double amp, double phase, double pulse)
 {
   return phase < pulse ? amp : -amp;
@@ -43,11 +43,11 @@ int rtbuf_signal_square (s_rtbuf *rtb)
     f = max(0.0, f);
     a = max(0.0, a);
     p = clamp(0.0, p, 1.0);
-    //printf(" i=%u freq=%f amp=%f pulse=%f", i, f, a, p);
+    /* printf(" i=%u freq=%f amp=%f pulse=%f", i, f, a, p); */
     f /= (double) RTBUF_SIGNAL_SAMPLERATE;
     data->phase = fmod(data->phase + f, 1.0);
     data->signal[i] = square(a, data->phase, p);
-    //printf(" f=%f a=%f p=%f square=%f", f, a, p, data->samples[i]);
+    /* printf(" f=%f a=%f p=%f square=%f", f, a, p, data->samples[i]); */
     i++;
   }
   return 0;
diff --git a/rtbuf_sndio_output.c b/rtbuf_sndio_output.c
index a4ba564..72f0653 100644
--- a/rtbuf_sndio_output.c
+++ b/rtbuf_sndio_output.c
@@ -37,12 +37,14 @@ void rtbuf_sndio_output_parameters (struct sio_par *want)
 
 int rtbuf_sndio_output_check_parameters (struct sio_par *have)
 {
-  print_sio_par(have); printf("\n");
-  int ok = (have->bits == 16 &&
-            have->sig == 1 &&
-            have->rchan == 0 &&
-            have->pchan == RTBUF_SNDIO_CHANNELS &&
-            have->rate == RTBUF_SIGNAL_SAMPLERATE);
+  int ok;
+  print_sio_par(have);
+  printf("\n");
+  ok = (have->bits == 16 &&
+        have->sig == 1 &&
+        have->rchan == 0 &&
+        have->pchan == RTBUF_SNDIO_CHANNELS &&
+        have->rate == RTBUF_SIGNAL_SAMPLERATE);
   return ok;
 }
 
@@ -102,7 +104,7 @@ int rtbuf_sndio_output (s_rtbuf *rtb)
   }
   data = (s_rtbuf_sndio_output_data*) rtb->data;
   sample = data->samples;
-  //printf("sndio_output");
+  /* printf("sndio_output"); */
   while (i < RTBUF_SIGNAL_SAMPLES) {
     j = 0;
     while (j < RTBUF_SNDIO_CHANNELS) {
@@ -120,6 +122,6 @@ int rtbuf_sndio_output (s_rtbuf *rtb)
   }
   sio_write(data->reserved.sio_hdl, data->samples,
             sizeof(t_rtbuf_sndio_samples));
-  //printf("\n");
+  /* printf("\n"); */
   return 0;
 }
diff --git a/rtbuf_synth.h b/rtbuf_synth.h
index 8970475..a1124b1 100644
--- a/rtbuf_synth.h
+++ b/rtbuf_synth.h
@@ -30,7 +30,7 @@ enum {
   RTBUF_SYNTH_ADSR_IN_DECAY,
   RTBUF_SYNTH_ADSR_IN_SUSTAIN,
   RTBUF_SYNTH_ADSR_IN_RELEASE,
-  RTBUF_SYNTH_ADSR_IN_N,
+  RTBUF_SYNTH_ADSR_IN_N
 };
 
 enum {
diff --git a/rtbuf_synth_adsr.c b/rtbuf_synth_adsr.c
index 110675a..3fbcf51 100644
--- a/rtbuf_synth_adsr.c
+++ b/rtbuf_synth_adsr.c
@@ -20,7 +20,7 @@
 #include "rtbuf.h"
 #include "rtbuf_synth.h"
 
-static inline
+static
 double adsr (double attack, double decay, double sustain,
              double release, double start, double stop)
 {
diff --git a/rtbuf_synth_synth.c b/rtbuf_synth_synth.c
index ac0e790..a165606 100644
--- a/rtbuf_synth_synth.c
+++ b/rtbuf_synth_synth.c
@@ -111,7 +111,7 @@ s_rtbuf * rtbuf_synth_synth_new_envelope (s_rtbuf *rtb,
     env->proc->start(env);
   if (env->proc->f)
     env->proc->f(env);
-  //rtbuf_print_long(env_i);
+  /* rtbuf_print_long(env_i); */
   printf("synth_synth_new_envelope %u\n", i);
   return env;
 }
@@ -141,7 +141,7 @@ s_rtbuf * rtbuf_synth_synth_new_oscillator (s_rtbuf *rtb,
     osc->proc->start(osc);
   if (osc->proc->f)
     osc->proc->f(osc);
-  //rtbuf_print_long(osc_i);
+  /* rtbuf_print_long(osc_i); */
   return osc;
 }
 
@@ -165,7 +165,7 @@ void rtbuf_synth_synth_update_note_signal (s_rtbuf *rtb,
     double o = osc.sample_fun(osc.signal, j);
     e = max(0.0, e);
     *signal += e * o;
-    //printf(" e=%f o=%f s=%f", e, o, *signal);
+    /* printf(" e=%f o=%f s=%f", e, o, *signal); */
     signal++;
     j++;
   }
diff --git a/rtbuf_var.h b/rtbuf_var.h
index 9f89bd6..714012f 100644
--- a/rtbuf_var.h
+++ b/rtbuf_var.h
@@ -3,11 +3,6 @@
 
 #include "rtbuf_defs.h"
 
-enum rtbuf_var_type {
-  RTBUF_VAR_NULL  = 0,
-  RTBUF_VAR_RTBUF = 1
-};
-
 #define RTBUF_VAR_MAX 1000
 
 struct rtbuf_var {
diff --git a/rtbuf_widget.h b/rtbuf_widget.h
index ccff6af..d78279b 100644
--- a/rtbuf_widget.h
+++ b/rtbuf_widget.h
@@ -38,10 +38,10 @@ struct _RtbufWidgetClass {
   GtkBoxClass parent_class;
 };
 
-GType rtbuf_widget_get_type (void) G_GNUC_CONST;
+GType         rtbuf_widget_get_type (void) G_GNUC_CONST;
 RtbufWidget * rtbuf_widget_new (s_rtbuf *rtb, const gchar *label);
-void rtbuf_widget_set_label (RtbufWidget *widget, const gchar *label);
+void          rtbuf_widget_set_label (RtbufWidget *widget, const gchar *label);
 const gchar * rtbuf_widget_get_label (RtbufWidget *widget);
-GtkWidget * rtbuf_widget_get_label_widget (RtbufWidget *widget);
+GtkWidget *   rtbuf_widget_get_label_widget (RtbufWidget *widget);
 
 #endif