Kaynağa Gözat

cmDevCfg.h/c: Initial commit.

master
kevin 11 yıl önce
ebeveyn
işleme
92c8f52ec8
3 değiştirilmiş dosya ile 737 ekleme ve 0 silme
  1. 3
    0
      Makefile.am
  2. 607
    0
      cmDevCfg.c
  3. 127
    0
      cmDevCfg.h

+ 3
- 0
Makefile.am Dosyayı Görüntüle

@@ -30,6 +30,9 @@ cmSRC += src/libcm/cmMidiFilePlay.c src/libcm/cmMidiPort.c src/libcm/cmMidiFile.
30 30
 cmHDR += src/libcm/cmAudioFile.h src/libcm/cmAudioFileMgr.h src/libcm/cmMsgProtocol.h src/libcm/cmAudioSys.h src/libcm/cmAudioPortFile.h src/libcm/cmAudioFileDev.h 
31 31
 cmSRC += src/libcm/cmAudioFile.c src/libcm/cmAudioFileMgr.c src/libcm/cmMsgProtocol.c src/libcm/cmAudioSys.c src/libcm/cmAudioPortFile.c src/libcm/cmAudioFileDev.c
32 32
 
33
+cmHDR += src/libcm/cmDevCfg.h
34
+cmSRC += src/libcm/cmDevCfg.c
35
+
33 36
 cmHDR += src/libcm/cmFrameFile.h src/libcm/cmFeatFile.h src/libcm/cmCsv.h src/libcm/cmAudLabelFile.h src/libcm/cmTagFile.h
34 37
 cmSRC += src/libcm/cmFrameFile.c src/libcm/cmFeatFile.c src/libcm/cmCsv.c src/libcm/cmAudLabelFile.c src/libcm/cmTagFile.c
35 38
 

+ 607
- 0
cmDevCfg.c Dosyayı Görüntüle

@@ -0,0 +1,607 @@
1
+#include "cmGlobal.h"
2
+#include "cmRpt.h"
3
+#include "cmErr.h"
4
+#include "cmCtx.h"
5
+#include "cmMem.h"
6
+#include "cmMallocDebug.h"
7
+#include "cmJson.h"
8
+#include "cmMidi.h"
9
+#include "cmMidiPort.h"
10
+
11
+#include "cmDevCfg.h"
12
+
13
+cmDevCfgH_t cmDevCfgNullHandle = cmSTATIC_NULL_HANDLE;
14
+
15
+
16
+typedef struct
17
+{
18
+  cmChar_t* dcLabelStr;     // Name of this cfg recd or NULL if the recd is inactive.
19
+  cmChar_t* devLabelStr;    // Midi device label.
20
+  cmChar_t* portLabelStr;   // Midi device port label.
21
+  bool      inputFl;        // 'True' if this is an input port.
22
+  unsigned  devIdx;         // Midi device index.
23
+  unsigned  portIdx;        // Midi port index.
24
+} cmDcmMidi_t;
25
+
26
+typedef struct
27
+{
28
+  cmChar_t* dcLabelStr;        // Name of this cfg record or NULL if the recd is inactive.
29
+  cmChar_t* inDevLabelStr;     // Input audio device label.
30
+  cmChar_t* outDevLabelStr;    // Output audio device label.
31
+  bool      syncToInputFl;     // 'True' if the audio system should sync to the input port.
32
+  unsigned  msgQueueByteCnt;   // Audio system msg queue in bytes.
33
+  unsigned  devFramesPerCycle; // Audio system sample frames per device callback.
34
+  unsigned  dspFramesPerCycle; // DSP system samples per block.
35
+  unsigned  audioBufCnt;       // Count of audio buffers (of size devFramesPerCycle) 
36
+  double    srate;             // Audio system sample rate.
37
+} cmDcmAudio_t;
38
+
39
+typedef struct              
40
+{
41
+  cmChar_t* dcLabelStr;        // Name of this cfg recd or NULL if the recd is inactive
42
+  cmChar_t* sockAddr;          // Remote socket address.
43
+  unsigned  portNumber;        // Remote socket port number
44
+  unsigned  netNodeId;         // Network node id associated with sockAddr and portNumber.
45
+} cmDcmNet_t;
46
+
47
+typedef struct
48
+{
49
+  cmTypeDcmId_t tid;      // Type Id for this map or tInvalidDcmTId if the record is not active.
50
+  unsigned   usrDevId; // Same as index into p->map[] for this recd.
51
+  unsigned   cfgIndex; // Index into p->midi[],p->audio[], or p->net[].
52
+} cmDcmMap_t;
53
+
54
+typedef struct
55
+{
56
+  unsigned    usrAppId;
57
+  bool        activeFl;
58
+  cmDcmMap_t* map;
59
+  unsigned    mapCnt;
60
+} cmDcmApp_t;
61
+
62
+typedef struct
63
+{
64
+  cmErr_t       err;
65
+
66
+  cmDcmApp_t*   app;
67
+  unsigned      appCnt;
68
+
69
+  cmDcmMidi_t*  midi;
70
+  unsigned      midiCnt;
71
+
72
+  cmDcmAudio_t* audio;
73
+  unsigned      audioCnt;
74
+
75
+  cmDcmNet_t*   net;
76
+  unsigned      netCnt;
77
+} cmDcm_t;
78
+
79
+cmDcm_t* _cmDcmHandleToPtr( cmDevCfgH_t h )
80
+{
81
+  cmDcm_t* p = (cmDcm_t*)h.h;
82
+  assert( p!=NULL );
83
+  return p;
84
+}
85
+
86
+void _cmDcmMidiFree( cmDcmMidi_t* r )
87
+{
88
+  cmMemPtrFree(&r->dcLabelStr);
89
+  cmMemPtrFree(&r->devLabelStr);
90
+  cmMemPtrFree(&r->portLabelStr);
91
+}
92
+
93
+void _cmDcmAudioFree( cmDcmAudio_t* r )
94
+{
95
+  cmMemPtrFree(&r->dcLabelStr);
96
+  cmMemPtrFree(&r->inDevLabelStr);
97
+  cmMemPtrFree(&r->outDevLabelStr);
98
+}
99
+
100
+void _cmDcmNetFree( cmDcmNet_t* r )
101
+{
102
+  cmMemPtrFree(&r->dcLabelStr);
103
+  cmMemPtrFree(&r->sockAddr);
104
+}
105
+
106
+void _cmDcmAppFree( cmDcmApp_t* r )
107
+{
108
+  cmMemPtrFree(&r->map);
109
+}
110
+
111
+cmDcRC_t _cmDcmFree( cmDcm_t* p )
112
+{
113
+  unsigned i;
114
+
115
+  for(i=0; p->midi!=NULL && i<p->midiCnt; ++i)
116
+    _cmDcmMidiFree(p->midi + i );
117
+  cmMemPtrFree(&p->midi);
118
+
119
+  for(i=0; p->audio!=NULL && i<p->audioCnt; ++i)
120
+    _cmDcmAudioFree(p->audio + i );
121
+  cmMemPtrFree(&p->audio);
122
+
123
+  for(i=0; p->net!=NULL && i<p->netCnt; ++i)
124
+    _cmDcmNetFree(p->net + i );
125
+  cmMemPtrFree(&p->net);
126
+
127
+  for(i=0; p->app!=NULL && i<p->appCnt; ++i)
128
+    _cmDcmAppFree(p->app + i );
129
+  cmMemPtrFree(&p->app);
130
+  
131
+  return kOkDcRC;
132
+}
133
+
134
+cmDcmMidi_t* _cmDcmMidiFind( cmDcm_t* p, const cmChar_t* dcLabelStr, bool errFl )
135
+{
136
+  assert( dcLabelStr != NULL );
137
+
138
+  unsigned i;
139
+  for(i=0; i<p->midiCnt; ++i)
140
+    if(p->midi[i].dcLabelStr!=NULL && strcmp(p->midi[i].dcLabelStr,dcLabelStr)==0)
141
+      return p->midi + i;
142
+
143
+  if( errFl )
144
+    cmErrMsg(&p->err,cmLabelNotFoundDcRC,"The MIDI cfg. record '%s' not found.",dcLabelStr);
145
+
146
+  return NULL;
147
+}
148
+
149
+cmDcmAudio_t* _cmDcmAudioFind( cmDcm_t* p, const cmChar_t* dcLabelStr, bool errFl )
150
+{
151
+  assert( dcLabelStr != NULL );
152
+
153
+  unsigned i;
154
+  for(i=0; i<p->audioCnt; ++i)
155
+    if(p->audio[i].dcLabelStr!=NULL && strcmp(p->audio[i].dcLabelStr,dcLabelStr)==0)
156
+      return p->audio + i;
157
+
158
+  if( errFl )
159
+    cmErrMsg(&p->err,cmLabelNotFoundDcRC,"The audio cfg. record '%s' not found.",dcLabelStr);
160
+
161
+  return NULL;
162
+}
163
+
164
+cmDcmNet_t* _cmDcmNetFind( cmDcm_t* p, const cmChar_t* dcLabelStr, bool errFl )
165
+{
166
+  assert( dcLabelStr != NULL );
167
+
168
+  unsigned i;
169
+  for(i=0; i<p->netCnt; ++i)
170
+    if(p->net[i].dcLabelStr!=NULL && strcmp(p->net[i].dcLabelStr,dcLabelStr)==0)
171
+      return p->net + i;
172
+
173
+  if( errFl )
174
+    cmErrMsg(&p->err,cmLabelNotFoundDcRC,"The net cfg. record '%s' not found.",dcLabelStr);
175
+
176
+  return NULL;
177
+}
178
+
179
+
180
+cmDcmApp_t*  _cmDcmFindOrCreateApp(cmDcm_t* p, unsigned usrAppId ) 
181
+{
182
+  cmDcmApp_t* a;
183
+  if( usrAppId < p->appCnt )
184
+    a = p->app + usrAppId;
185
+  else
186
+  {
187
+    p->appCnt = usrAppId + 1;
188
+    p->app    = cmMemResizePZ(cmDcmApp_t,p->app,p->appCnt);
189
+    a = p->app + usrAppId;
190
+    a->usrAppId = usrAppId;
191
+    a->activeFl = true;    
192
+  }
193
+
194
+  return a;
195
+}
196
+
197
+cmDcmMap_t* _cmDcmFindOrCreateMap(cmDcm_t* p, cmDcmApp_t* a, unsigned usrDevId )
198
+{
199
+  cmDcmMap_t* m;
200
+
201
+  if( usrDevId < a->mapCnt )
202
+    m = a->map + usrDevId;
203
+  else
204
+  {
205
+    a->mapCnt   = usrDevId + 1;
206
+    a->map      = cmMemResizePZ(cmDcmMap_t,a->map,a->mapCnt);        
207
+    m           = a->map + usrDevId;    
208
+    m->usrDevId = usrDevId;
209
+  }
210
+
211
+  return m;
212
+}
213
+
214
+cmDcRC_t  _cmDcmLookupApp(cmDcm_t* p, unsigned usrAppId, cmDcmApp_t** appRef)
215
+{
216
+  // validate the usrAppId
217
+  if( usrAppId >= p->appCnt )
218
+    return cmErrMsg(&p->err,kInvalidDevArgDcRC,"Invalid user app. id:%i\n",usrAppId);
219
+
220
+  // check that the app recd is active
221
+  if( p->app[usrAppId].activeFl == false )
222
+    return cmErrMsg(&p->err,kInvalidDevArgDcRC,"The user app. with id:%i is not active.",usrAppId);
223
+
224
+  *appRef = p->app + usrAppId;
225
+
226
+  return kOkDcRC;
227
+}
228
+
229
+cmDcRC_t  _cmDcmLookupMap(cmDcm_t* p, cmDcmApp_t* a, unsigned usrDevId, cmDcmMap_t** mapRef )
230
+{
231
+  // validate the usrDevId
232
+  if( usrDevId >= a->mapCnt )
233
+    return cmErrMsg(&p->err,kInvalidDevArgDcRC,"Invalid user device id:%i on app:%i\n",usrDevId,a->usrAppId);
234
+
235
+  // check that the map recd is active
236
+  if( a->map[ usrDevId ].tid == kInvalidDcmTId )
237
+    return cmErrMsg(&p->err,kInvalidDevArgDcRC,"The user device id:%i on app:%i is not active.",usrDevId,a->usrAppId);
238
+
239
+  *mapRef =  a->map + usrDevId;
240
+  return kOkDcRC;
241
+}
242
+
243
+cmDcRC_t  _cmDcmLookupAppMap(cmDcm_t* p, unsigned usrAppId, unsigned usrDevId, cmDcmMap_t** mapRef )
244
+{
245
+  cmDcRC_t rc;
246
+  cmDcmApp_t* a;
247
+
248
+  if((rc = _cmDcmLookupApp(p,usrAppId,&a)) == kOkDcRC )
249
+    return rc;
250
+
251
+  return _cmDcmLookupMap(p,a,usrDevId,mapRef );
252
+}
253
+
254
+// Delete all maps in all apps which reference a particular cfg recd.
255
+void _cmDevCfgDeleteCfgMaps( cmDcm_t* p, cmTypeDcmId_t tid, unsigned cfgIndex )
256
+{
257
+  unsigned i,j;
258
+  for(i=0; i<p->appCnt; ++i)
259
+    if( p->app[i].activeFl )
260
+      for(j=0; j<p->app[i].mapCnt; ++j)
261
+        if( p->app[i].map[j].tid == tid && p->app[i].map[j].cfgIndex == cfgIndex )
262
+        {
263
+          p->app[i].map[j].tid = kInvalidDcmTId;
264
+          break;
265
+        }
266
+}
267
+
268
+
269
+cmDcRC_t cmDevCfgMgrAlloc( cmCtx_t* ctx, cmDevCfgH_t* hp, cmJsonH_t jsH )
270
+{
271
+  cmDcRC_t rc;
272
+  if((rc = cmDevCfgMgrFree(hp)) != kOkDcRC )
273
+    return rc;
274
+
275
+  cmDcm_t* p = cmMemAllocZ(cmDcm_t,1);
276
+  cmErrSetup(&p->err,&ctx->rpt,"DevCfgMgr");
277
+
278
+
279
+  hp->h = p;
280
+
281
+  if( rc != kOkDcRC )
282
+    _cmDcmFree(p);
283
+
284
+  return rc;
285
+}
286
+
287
+
288
+cmDcRC_t cmDevCfgMgrFree( cmDevCfgH_t* hp )
289
+{
290
+  cmDcRC_t rc = kOkDcRC;
291
+
292
+  if(hp!=NULL || cmDevCfgIsValid(*hp))
293
+    return rc;
294
+
295
+  cmDcm_t* p = _cmDcmHandleToPtr(*hp);
296
+
297
+  if((rc = _cmDcmFree(p)) != kOkDcRC )
298
+    return rc;
299
+
300
+  cmMemFree(p);
301
+
302
+  hp->h = NULL;
303
+
304
+  return rc;
305
+}
306
+
307
+cmDcRC_t cmDevCfgIsValid( cmDevCfgH_t h )
308
+{ return h.h != NULL; }
309
+
310
+cmDcRC_t _cmDcmFindCfgIndex( cmDcm_t* p, cmTypeDcmId_t tid, const cmChar_t* dcLabelStr, unsigned* cfgIndexRef )
311
+{
312
+  cmDcRC_t rc = kOkDcRC;
313
+
314
+  *cfgIndexRef = cmInvalidIdx;
315
+
316
+  switch( tid )
317
+  {
318
+    case kMidiDcmTId:
319
+      {
320
+        const cmDcmMidi_t* r;
321
+
322
+        if((r = _cmDcmMidiFind(p,dcLabelStr,true)) == NULL )
323
+          rc = cmErrLastRC(&p->err);
324
+        else
325
+          *cfgIndexRef = r - p->midi;
326
+      }
327
+      break;
328
+
329
+    case kAudioDcmTId:
330
+      {
331
+        const cmDcmAudio_t* r;
332
+
333
+        if((r = _cmDcmAudioFind(p,dcLabelStr,true)) == NULL )
334
+          rc = cmErrLastRC(&p->err);
335
+        else
336
+          *cfgIndexRef = r - p->audio;
337
+      }
338
+      break;
339
+
340
+    case kNetDcmTId:
341
+      {
342
+        const cmDcmNet_t* r;
343
+
344
+        if((r = _cmDcmNetFind(p,dcLabelStr,true)) == NULL )
345
+          rc = cmErrLastRC(&p->err);
346
+        else
347
+          *cfgIndexRef = r - p->net;
348
+      }
349
+      break;
350
+      
351
+    default:
352
+      assert(0);
353
+      break;
354
+  }
355
+
356
+  return rc;
357
+}
358
+
359
+cmDcRC_t _cmDevCfgDeleteCfg( cmDcm_t* p, cmTypeDcmId_t tid, unsigned cfgIndex )
360
+{
361
+  // release any resources held by this cfg record and mark
362
+  // the record as inactive by setting the dcLabelStr field to NULL.
363
+  switch( tid )
364
+  {
365
+    case kMidiDcmTId:
366
+      _cmDcmMidiFree( p->midi + cfgIndex );
367
+      break;
368
+
369
+    case kAudioDcmTId:
370
+      _cmDcmAudioFree( p->audio + cfgIndex );
371
+      break;
372
+
373
+    case kNetDcmTId:
374
+      _cmDcmNetFree( p->net + cfgIndex );
375
+      break;
376
+      
377
+    default:
378
+      assert(0);
379
+      break;
380
+  }
381
+
382
+  // delete all maps which reference this cfg recd
383
+  if( cfgIndex != cmInvalidIdx )
384
+    _cmDevCfgDeleteCfgMaps(p, tid, cfgIndex );
385
+  
386
+
387
+  return kOkDcRC;
388
+}
389
+
390
+cmDcRC_t cmDevCfgDeleteCfg(  cmDevCfgH_t h, cmTypeDcmId_t tid, const cmChar_t* dcLabelStr )
391
+{
392
+  cmDcRC_t rc;
393
+  cmDcm_t* p        = _cmDcmHandleToPtr(h);
394
+  unsigned cfgIndex = cmInvalidIdx;
395
+
396
+  // locate the cfg record index
397
+  if((rc = _cmDcmFindCfgIndex(p,tid,dcLabelStr,&cfgIndex)) == kOkDcRC )
398
+    return rc;
399
+  
400
+  return _cmDevCfgDeleteCfg( p, tid, cfgIndex );
401
+}
402
+
403
+cmDcRC_t cmDevCfgCreateMap( cmDevCfgH_t h, cmTypeDcmId_t tid, const cmChar_t* dcLabelStr, unsigned usrAppId, unsigned usrDevId )
404
+{
405
+  cmDcRC_t    rc       = kOkDcRC;
406
+  cmDcm_t*    p        = _cmDcmHandleToPtr(h);
407
+  unsigned    cfgIndex = cmInvalidIdx;
408
+
409
+  if((rc = _cmDcmFindCfgIndex(p,tid,dcLabelStr,&cfgIndex)) == kOkDcRC )
410
+    return rc;
411
+
412
+  if( cfgIndex != cmInvalidIdx )
413
+  {
414
+    cmDcmApp_t* a;
415
+    cmDcmMap_t* m;
416
+
417
+    // locate or create the requested app recrod
418
+    if((a = _cmDcmFindOrCreateApp(p,usrAppId)) == NULL )
419
+    {
420
+      rc = cmErrLastRC(&p->err);
421
+      goto errLabel;
422
+    }
423
+
424
+    // locate or create the requested map record
425
+    if((m = _cmDcmFindOrCreateMap(p,a,usrDevId)) == NULL )
426
+    {
427
+      rc = cmErrLastRC(&p->err);
428
+      goto errLabel;
429
+    }
430
+
431
+    m->usrDevId = usrDevId;
432
+    m->tid      = tid;
433
+    m->cfgIndex = cfgIndex;
434
+  }
435
+
436
+ errLabel:
437
+  return rc;
438
+}
439
+
440
+cmDcRC_t cmDevCfgDeleteMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned usrAppId, unsigned usrDevId )
441
+{
442
+  cmDcRC_t   rc = kOkDcRC;
443
+  cmDcm_t*    p = _cmDcmHandleToPtr(h);
444
+  cmDcmMap_t* m;
445
+
446
+  if((rc =  _cmDcmLookupAppMap(p,usrAppId,usrDevId,&m)) != kOkDcRC )
447
+    return rc;
448
+
449
+  m->usrDevId = cmInvalidId;
450
+  m->tid      = kInvalidDcmTId;
451
+  m->cfgIndex = cmInvalidIdx;
452
+  return rc;
453
+}
454
+  
455
+cmDcRC_t cmDevCfgNameMidiPort( 
456
+  cmDevCfgH_t     h,
457
+  const cmChar_t* dcLabelStr, 
458
+  const cmChar_t* devNameStr, 
459
+  const cmChar_t* portNameStr,
460
+  bool            inputFl )
461
+{
462
+  cmDcRC_t    rc = kOkDcRC;
463
+  cmDcm_t*     p  = _cmDcmHandleToPtr(h);
464
+  cmDcmMidi_t* r  = _cmDcmMidiFind(p,dcLabelStr,false);
465
+  unsigned     i;
466
+
467
+  // if 'dcLabelStr' was not already used then look for an empty MIDI record.
468
+  if( r == NULL )
469
+    for(i=0; i<p->midiCnt; ++i)
470
+      if( p->midi[i].dcLabelStr == NULL )
471
+      {
472
+        r = p->midi + i;
473
+        break;
474
+      }
475
+  
476
+  // if no available cfg record exists then create one 
477
+  if( r == NULL )
478
+  {
479
+    p->midi     = cmMemResizePZ(cmDcmMidi_t,p->midi,p->midiCnt+1);    
480
+    r           = p->midi + p->midiCnt;
481
+    p->midiCnt += 1;
482
+  }
483
+
484
+ 
485
+  assert( r != NULL );
486
+ 
487
+  // verify that the device label is valid
488
+  if((r->devIdx = cmMpDeviceNameToIndex( r->devLabelStr )) == cmInvalidIdx )
489
+  {
490
+    rc = cmErrMsg(&p->err, kInvalidDevArgDcRC,"The MIDI device name '%s' is not valid.",r->devLabelStr);
491
+    goto errLabel;
492
+  }
493
+
494
+  // verify that the port label is valid
495
+  if((r->portIdx = cmMpDevicePortNameToIndex( r->devIdx, r->inputFl ? kInMpFl : kOutMpFl, r->portLabelStr )) == cmInvalidIdx )
496
+  {
497
+    rc = cmErrMsg(&p->err, kInvalidDevArgDcRC,"The MIDI port name '%s' is not valid on the device '%s'.",r->portLabelStr,r->devLabelStr);
498
+    goto errLabel;
499
+  }
500
+
501
+  // if this cfg recd was not previously active then assign a cfg label
502
+  if( r->dcLabelStr == NULL )
503
+    r->dcLabelStr  = cmMemAllocStr(dcLabelStr);
504
+
505
+  // fill in the cfg recd
506
+  r->devLabelStr  = cmMemResizeStr(r->devLabelStr,devNameStr);
507
+  r->portLabelStr = cmMemResizeStr(r->portLabelStr,portNameStr);
508
+  r->inputFl      = inputFl;
509
+
510
+ errLabel:
511
+  // on error delete the cfg record and any maps depending on it
512
+  if( rc != kOkDcRC && r != NULL )
513
+    _cmDevCfgDeleteCfg( p, kMidiDcmTId, r - p->midi );
514
+
515
+  return rc;
516
+}
517
+
518
+
519
+cmDcRC_t cmDevCfgMidiDevIdx(    cmDevCfgH_t h, unsigned usrAppId, unsigned usrDevId, unsigned* midiDevIdxRef, unsigned* midiPortIdxRef )
520
+{
521
+  cmDcRC_t   rc = kOkDcRC;
522
+  cmDcm_t*    p = _cmDcmHandleToPtr(h);
523
+  cmDcmMap_t* m;
524
+
525
+  if((rc =  _cmDcmLookupAppMap(p,usrAppId,usrDevId,&m)) != kOkDcRC )
526
+    return rc;
527
+                                                
528
+  cmDcmMidi_t* r = p->midi + m->cfgIndex;
529
+
530
+  assert(r->dcLabelStr != NULL );
531
+
532
+  *midiDevIdxRef  = r->devIdx;
533
+  *midiPortIdxRef = r->portIdx;
534
+
535
+  return rc;
536
+}
537
+
538
+cmDcRC_t cmDevCfgNameAudioPort( 
539
+  cmDevCfgH_t     h,
540
+  const cmChar_t* dcLabelStr, 
541
+  const cmChar_t* inDevNameStr, 
542
+  const cmChar_t* outDevNameStr,
543
+  bool            syncInputFl,
544
+  unsigned        msgQueueByteCnt,
545
+  unsigned        devFramesPerCycle,
546
+  unsigned        dspFramesPerCycle,
547
+  unsigned        audioBufCnt,
548
+  double          srate  )
549
+{
550
+  return kOkDcRC;
551
+}
552
+
553
+
554
+const struct cmAudioSysArgs_str* cmDevCfgAudioSysArgs( cmDevCfgH_t h, unsigned usrAppId, unsigned usrDevId )
555
+{
556
+  return NULL;
557
+}
558
+
559
+
560
+cmDcRC_t cmDevCfgNetPort(
561
+  cmDevCfgH_t      h,
562
+  const cmChar_t* dcLabelStr,
563
+  const cmChar_t* sockAddr,
564
+  unsigned        portNumber )
565
+{
566
+  return kOkDcRC;
567
+}
568
+
569
+
570
+unsigned        cmDevCfgNetNodeId(     cmDevCfgH_t h, unsigned usrAppId, unsigned usrDevId )
571
+{
572
+  return cmInvalidId;
573
+}
574
+
575
+
576
+// Preset Management Functions:
577
+unsigned        cmDevCfgPresetCount( cmDevCfgH_t h )
578
+{
579
+  return 0;
580
+}
581
+
582
+const cmChar_t* cmDevCfgPresetLabel( cmDevCfgH_t h, unsigned presetIdx )
583
+{
584
+  return NULL;
585
+}
586
+
587
+cmDcRC_t        cmDevCfgStore(       cmDevCfgH_t h, const cmChar_t* presetLabelStr )
588
+{
589
+  return kOkDcRC;
590
+}
591
+
592
+cmDcRC_t        cmDevCfgRecall(      cmDevCfgH_t h, const cmChar_t* presetLabelStr )
593
+{
594
+  return kOkDcRC;
595
+}
596
+
597
+cmDcRC_t        cmDevCfgDelete(      cmDevCfgH_t h, const cmChar_t* presetLabelStr )
598
+{
599
+  return kOkDcRC;
600
+}
601
+
602
+
603
+cmDcRC_t cmDevCfgWrite( cmDevCfgH_t h )
604
+{
605
+  return kOkDcRC;
606
+}
607
+

+ 127
- 0
cmDevCfg.h Dosyayı Görüntüle

@@ -0,0 +1,127 @@
1
+#ifndef cmDevCfg_h
2
+#define cmDevCfg_h
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+  /*
8
+    IMPLEMENTATION:
9
+    1) A 'cfg' record is a device reference with a 'cfg label'.
10
+       There are three kinds of cfg records MIDI,Audio,Net.
11
+       The device record identifies a particlar device
12
+       end-point or pre-configured setup.  The 'cfg label'
13
+       associated with this setup allows an application
14
+       to refer to the setup by name.  This releives the
15
+       application from having to handle the details of
16
+       forming, storing, and maintaining device configurations.
17
+
18
+    2) A 'map' record is a record which links an 
19
+       application and reference id to a cfg record.
20
+
21
+       The goal of this is to allow applications to refer to
22
+       pre-configured device setups by name and then to 
23
+       associate a numeric id with this setup. 
24
+       The application can then send data to the device using
25
+       only the numeric id. Likewise data arriving from the
26
+       device to the application is tagged with 
27
+       id of the of the device.
28
+
29
+    NOTES:
30
+    1) usrAppId's must be unique among all app.s'.
31
+    2) usrDevId's must be unique among all usrDevId's for particular app.
32
+       In other words the same 'usrDevId' may not be used by devices
33
+       of different types.
34
+    3) The usrAppId's and usrDevIds' are used internally as index
35
+       locations. They should therefore be low numbers and 
36
+       densely packed.
37
+   */
38
+
39
+
40
+  struct cmAudioSysArgs_t;
41
+
42
+  enum
43
+  {
44
+    kOkDcRC = cmOkRC,
45
+    cmLabelNotFoundDcRC,
46
+    cmIdNotFoundDcRC,
47
+    kInvalidDevArgDcRC
48
+  };
49
+
50
+  typedef enum
51
+  {
52
+    kInvalidDcmTId,
53
+    kMidiDcmTId,
54
+    kAudioDcmTId,
55
+    kNetDcmTId
56
+  } cmTypeDcmId_t;
57
+
58
+  typedef cmRC_t     cmDcRC_t;
59
+  typedef cmHandle_t cmDevCfgH_t;
60
+
61
+  extern cmDevCfgH_t cmDevCfgNullHandle;
62
+
63
+  cmDcRC_t cmDevCfgMgrAlloc( cmCtx_t* c, cmDevCfgH_t* hp, cmJsonH_t jsH );
64
+  cmDcRC_t cmDevCfgMgrFree( cmDevCfgH_t* hp );
65
+  cmDcRC_t cmDevCfgIsValid( cmDevCfgH_t h );
66
+
67
+  
68
+  // Delete a cfg record created by cmDevCfgNameMidiPort(), cmDevCfgNameAudioPort(), etc.
69
+  cmDcRC_t cmDevCfgDeleteCfg( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr );
70
+
71
+  // Create a map record to associate a app/dev id with a cfg. record.
72
+  // Note that multiple app/dev id's may be assoc'd with the same cfg. record.
73
+  cmDcRC_t cmDevCfgCreateMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, const cmChar_t* dcLabelStr, unsigned usrAppId, unsigned usrDevId );
74
+
75
+  // Delete a map record created by cmDevCfgCreateMap().
76
+  cmDcRC_t cmDevCfgDeleteMap( cmDevCfgH_t h, cmTypeDcmId_t typeId, unsigned usrAppId, unsigned usrDevId );
77
+  
78
+  // Create a MIDI cfg. record.
79
+  cmDcRC_t cmDevCfgNameMidiPort( 
80
+    cmDevCfgH_t     h,
81
+    const cmChar_t* dcLabelStr, 
82
+    const cmChar_t* devNameStr, 
83
+    const cmChar_t* portNameStr, 
84
+    bool            inputFl );
85
+
86
+  cmDcRC_t cmDevCfgMidiDevIdx(    cmDevCfgH_t h, unsigned usrAppId, unsigned usrDevId, unsigned* midiDevIdxRef, unsigned* midiPortIdxRef );
87
+
88
+
89
+  cmDcRC_t cmDevCfgNameAudioPort( 
90
+    cmDevCfgH_t     h,
91
+    const cmChar_t* dcLabelStr, 
92
+    const cmChar_t* inDevNameStr, 
93
+    const cmChar_t* outDevNameStr,
94
+    bool            syncInputFl,
95
+    unsigned        msgQueueByteCnt,
96
+    unsigned        devFramesPerCycle,
97
+    unsigned        dspFramesPerCycle,
98
+    unsigned        audioBufCnt,
99
+    double          srate  );
100
+
101
+  const struct cmAudioSysArgs_str* cmDevCfgAudioSysArgs( cmDevCfgH_t h, unsigned usrAppId, unsigned usrDevId );
102
+
103
+  cmDcRC_t cmDevCfgNetPort(
104
+    cmDevCfgH_t      h,
105
+    const cmChar_t* dcLabelStr,
106
+    const cmChar_t* sockAddr,
107
+    unsigned        portNumber );
108
+
109
+  unsigned        cmDevCfgNetNodeId(     cmDevCfgH_t h, unsigned usrAppId, unsigned usrDevId );
110
+
111
+  // Preset Management Functions:
112
+  // Store and recall groups cfg records.
113
+
114
+  unsigned        cmDevCfgPresetCount( cmDevCfgH_t h );
115
+  const cmChar_t* cmDevCfgPresetLabel( cmDevCfgH_t h, unsigned presetIdx );
116
+  cmDcRC_t        cmDevCfgStore(       cmDevCfgH_t h, const cmChar_t* presetLabelStr );
117
+  cmDcRC_t        cmDevCfgRecall(      cmDevCfgH_t h, const cmChar_t* presetLabelStr );
118
+  cmDcRC_t        cmDevCfgDelete(      cmDevCfgH_t h, const cmChar_t* presetLabelStr );
119
+
120
+  cmDcRC_t cmDevCfgWrite( cmDevCfgH_t h );
121
+  
122
+
123
+#ifdef __cplusplus
124
+}
125
+#endif
126
+
127
+#endif

Loading…
İptal
Kaydet