Przeglądaj źródła

cmDspPgm.h/c : Added IntToSym example. Added initial set of shortened macros for programming.

master
kevin 4 lat temu
rodzic
commit
003a7deddf
3 zmienionych plików z 116 dodań i 17 usunięć
  1. 45
    0
      src/cmPP_NARG.h
  2. 58
    15
      src/dsp/cmDspPgm.c
  3. 13
    2
      src/dsp/cmDspSys.h

+ 45
- 0
src/cmPP_NARG.h Wyświetl plik

@@ -0,0 +1,45 @@
1
+#ifndef cmPP_NARG_H
2
+#define cmPP_NARG_H
3
+
4
+
5
+// Taken from here:
6
+// https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
7
+// and here:
8
+// https://stackoverflow.com/questions/4421681/how-to-count-the-number-of-arguments-passed-to-a-function-that-accepts-a-variabl
9
+
10
+#define PP_NARG(...) \
11
+         PP_NARG_(__VA_ARGS__,PP_RSEQ_N())
12
+
13
+#define PP_NARG_(...) \
14
+         PP_128TH_ARG(__VA_ARGS__)
15
+
16
+#define PP_128TH_ARG( \
17
+          _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
18
+         _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
19
+         _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
20
+         _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
21
+         _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
22
+         _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
23
+         _61,_62,_63,_64,_65,_66,_67,_68,_69,_70, \
24
+         _71,_72,_73,_74,_75,_76,_77,_78,_79,_80, \
25
+         _81,_82,_83,_84,_85,_86,_87,_88,_89,_90, \
26
+         _91,_92,_93,_94,_95,_96,_97,_98,_99,_100, \
27
+         _101,_102,_103,_104,_105,_106,_107,_108,_109,_110, \
28
+         _111,_112,_113,_114,_115,_116,_117,_118,_119,_120, \
29
+         _121,_122,_123,_124,_125,_126,_127,N,...) N
30
+#define PP_RSEQ_N() \
31
+         127,126,125,124,123,122,121,120, \
32
+         119,118,117,116,115,114,113,112,111,110, \
33
+         109,108,107,106,105,104,103,102,101,100, \
34
+         99,98,97,96,95,94,93,92,91,90, \
35
+         89,88,87,86,85,84,83,82,81,80, \
36
+         79,78,77,76,75,74,73,72,71,70, \
37
+         69,68,67,66,65,64,63,62,61,60, \
38
+         59,58,57,56,55,54,53,52,51,50, \
39
+         49,48,47,46,45,44,43,42,41,40, \
40
+         39,38,37,36,35,34,33,32,31,30, \
41
+         29,28,27,26,25,24,23,22,21,20, \
42
+         19,18,17,16,15,14,13,12,11,10, \
43
+         9,8,7,6,5,4,3,2,1,0
44
+
45
+#endif

+ 58
- 15
src/dsp/cmDspPgm.c Wyświetl plik

@@ -21,6 +21,7 @@
21 21
 #include "cmTime.h"
22 22
 #include "cmAudioSys.h"
23 23
 #include "cmProcObj.h"
24
+#include "cmPP_NARG.h"
24 25
 #include "cmDspCtx.h"
25 26
 #include "cmDspClass.h"
26 27
 #include "cmDspSys.h"
@@ -2870,36 +2871,77 @@ cmDspRC_t _cmDspSysPgm_PortToSym( cmDspSysH_t h, void** userPtrPtr )
2870 2871
 {
2871 2872
   cmDspRC_t rc = kOkDspRC;
2872 2873
 
2873
-  cmDspInst_t* btn0  = cmDspSysAllocButton( h, "Btn0", 0.0 );
2874
-  cmDspInst_t* btn1  = cmDspSysAllocButton( h, "Btn1", 0.0 );
2875
-  cmDspInst_t* btn2  = cmDspSysAllocButton( h, "Btn2", 0.0 );  
2874
+  inst_t* btn0  = button( "Btn0", 0.0 );
2875
+  inst_t* btn1  = button( "Btn1", 0.0 );
2876
+  inst_t* btn2  = button( "Btn2", 0.0 );  
2876 2877
 
2877
-  cmDspInst_t* pts   = cmDspSysAllocInst( h, "PortToSym", NULL, 3, "one", "two", "three");
2878
+  inst_t* pts   = inst( "PortToSym", NULL, "one", "two", "three");
2878 2879
 
2879
-  cmDspInst_t* pr0  = cmDspSysAllocInst( h, "Printer", NULL, 1, "0:" );
2880
-  cmDspInst_t* pr1  = cmDspSysAllocInst( h, "Printer", NULL, 1, "1:" );
2880
+  inst_t* pr0  = inst( "Printer", NULL,  "sym:" );
2881
+  inst_t* pr1  = inst( "Printer", NULL,  "btn:" );
2882
+  inst_t* pr2  = inst( "Printer", NULL,  "out:" );
2881 2883
 
2882 2884
   // check for allocation errors
2883 2885
   if((rc = cmDspSysLastRC(h)) != kOkDspRC )
2884 2886
     goto errLabel;
2885 2887
   
2886
-  cmDspSysInstallCb(   h, btn0, "out", pts, "one",NULL);
2887
-  cmDspSysInstallCb(   h, btn1, "out", pts, "two",NULL);
2888
-  cmDspSysInstallCb(   h, btn2, "out", pts, "three",NULL);
2888
+  event( btn0, out, pts, one );
2889
+  event( btn1, out, pts, two );
2890
+  event( btn2, out, pts, three );
2891
+
2892
+  event( btn0, out, pr1, in );
2893
+  event( btn1, out, pr1, in );
2894
+  event( btn2, out, pr1, in );
2895
+
2896
+  event( pts,  one,   pr0, in );
2897
+  event( pts,  two,   pr0, in );
2898
+  event( pts,  three, pr0, in );
2899
+  event( pts,  out,   pr2, in );
2900
+
2901
+ errLabel:
2902
+  return rc;
2903
+}
2904
+
2905
+//------------------------------------------------------------------------------
2906
+//)
2907
+//( { label:cmDspPgm_IntToSym file_desc:"IntToSym example program." kw:[spgm] }
2908
+cmDspRC_t _cmDspSysPgm_IntToSym( cmDspSysH_t h, void** userPtrPtr )
2909
+{
2910
+  cmDspRC_t rc = kOkDspRC;
2889 2911
 
2890
-  cmDspSysInstallCb(   h, btn0, "out", pr1, "in",NULL);
2891
-  cmDspSysInstallCb(   h, btn1, "out", pr1, "in",NULL);
2892
-  cmDspSysInstallCb(   h, btn2, "out", pr1, "in",NULL);
2912
+  inst_t* btn0  = button( "Btn0", 0.0 );
2913
+  inst_t* btn1  = button( "Btn1", 1.0 );
2914
+  inst_t* btn2  = button( "Btn2", 2.0 );  
2893 2915
 
2894
-  cmDspSysInstallCb(   h, pts,  "one",   pr0, "in", NULL );
2895
-  cmDspSysInstallCb(   h, pts,  "two",   pr0, "in", NULL );
2896
-  cmDspSysInstallCb(   h, pts,  "three", pr0, "in", NULL );
2916
+  inst_t* pts   = inst( "IntToSym", NULL, 1, "one", 2, "two", 3, "three");
2897 2917
 
2918
+  inst_t* pr0  = inst( "Printer", NULL,  "btn:" );
2919
+  inst_t* pr1  = inst( "Printer", NULL,  "sym:" );
2920
+  inst_t* pr2  = inst( "Printer", NULL,  "out:" );
2898 2921
 
2922
+  // check for allocation errors
2923
+  if((rc = cmDspSysLastRC(h)) != kOkDspRC )
2924
+    goto errLabel;
2925
+  
2926
+  event( btn0, out, pts, one );
2927
+  event( btn1, out, pts, two );
2928
+  event( btn2, out, pts, three );
2929
+
2930
+  event( btn0, out, pr0, in );
2931
+  event( btn1, out, pr0, in );
2932
+  event( btn2, out, pr0, in );
2933
+
2934
+  event( pts,  one,   pr1, in );
2935
+  event( pts,  two,   pr1, in );
2936
+  event( pts,  three, pr1, in );
2937
+
2938
+  event( pts, out, pr2, in );
2939
+  
2899 2940
  errLabel:
2900 2941
   return rc;
2901 2942
 }
2902 2943
 
2944
+
2903 2945
 //------------------------------------------------------------------------------
2904 2946
 //)
2905 2947
 //( { label:cmDspPgm_Line file_desc:"Line generator example program." kw:[spgm] }
@@ -3288,6 +3330,7 @@ _cmDspSysPgm_t _cmDspSysPgmArray[] =
3288 3330
   { "line",              _cmDspSysPgm_Line,           NULL, NULL },
3289 3331
   { "1Up",               _cmDspSysPgm_1Up,            NULL, NULL },
3290 3332
   { "PortToSym",         _cmDspSysPgm_PortToSym,      NULL, NULL },
3333
+  { "IntToSym",          _cmDspSysPgm_IntToSym,       NULL, NULL },
3291 3334
   { "preset",            _cmDspSysPgm_Preset,         NULL, NULL },
3292 3335
   { "rsrcWr",            _cmDspSysPgm_RsrcWr,         NULL, NULL },
3293 3336
   { "router",            _cmDspSysPgm_Router,         NULL, NULL },

+ 13
- 2
src/dsp/cmDspSys.h Wyświetl plik

@@ -109,8 +109,7 @@ extern "C" {
109 109
   cmDspRC_t    cmDspSysInsertHorzBorder( cmDspSysH_t h );
110 110
 
111 111
   cmDspRC_t    cmDspSysNewPage( cmDspSysH_t h, const cmChar_t* title );
112
-
113
-
112
+  
114 113
   //----------------------------------------------------------------------------------------------------
115 114
   // Connection Functions.
116 115
   //
@@ -278,6 +277,18 @@ extern "C" {
278 277
 
279 278
   //)
280 279
 
280
+  typedef cmDspInst_t inst_t;
281
+  
282
+#define inst( classLabel, instLabel, ... )       cmDspSysAllocInst( h, classLabel, instLabel, PP_NARG(__VA_ARGS__), __VA_ARGS__ )
283
+#define button( label, real_val )                cmDspSysAllocButton(  h, label, real_val )
284
+#define scalar( label, rmin, rmax, rstep, rval ) cmDspSysAllocScalar(  h, label, rmin, rmax, rstep, rval )
285
+
286
+  
287
+#define audio( src, sarg, dst, darg )      cmDspSysConnectAudio( h, src, #sarg, dst, #darg )
288
+#define event( src, sarg, dst, darg )      cmDspSysInstallCb( h, src, #sarg, dst, #darg, NULL )
289
+
290
+  
291
+  
281 292
 #ifdef __cplusplus
282 293
   }
283 294
 #endif

Ładowanie…
Anuluj
Zapisz