Browse Source

cmUiAudioSysMstr.h/c: Initial commit.

master
kevin 11 years ago
parent
commit
43678d3c38
2 changed files with 487 additions and 0 deletions
  1. 450
    0
      cmUiAudioSysMstr.c
  2. 37
    0
      cmUiAudioSysMstr.h

+ 450
- 0
cmUiAudioSysMstr.c View File

@@ -0,0 +1,450 @@
1
+#include "cmGlobal.h"
2
+#include "cmFloatTypes.h"
3
+#include "cmRpt.h"
4
+#include "cmErr.h"
5
+#include "cmCtx.h"
6
+#include "cmMem.h"
7
+#include "cmMallocDebug.h"
8
+#include "cmJson.h"
9
+#include "cmThread.h"
10
+#include "cmUdpPort.h"
11
+#include "cmUdpNet.h"
12
+#include "cmAudioSysMsg.h"
13
+#include "cmAudioSys.h"
14
+#include "cmUiDrvr.h"
15
+#include "cmUi.h"
16
+#include "cmUiAudioSysMstr.h"
17
+
18
+enum
19
+{
20
+  kLabelAmId,
21
+  kInSliderAmId,
22
+  kInMeterAmId,
23
+  kInToneAmId,
24
+  kInPassAmId,
25
+  kInMuteAmId,
26
+  kOutSliderAmId,
27
+  kOutMeterAmId,
28
+  kOutToneAmId,
29
+  kOutPassAmId,
30
+  kOutMuteAmId,
31
+  kAmCnt
32
+};
33
+
34
+
35
+enum
36
+{
37
+  kMinDb =  24,
38
+  kMaxDb = -24,
39
+  kMtrMin  = 0,
40
+  kMtrMax  = 100
41
+};
42
+
43
+typedef struct cmAmPanel_str
44
+{
45
+  unsigned              asSubIdx;
46
+
47
+  unsigned              panelId;
48
+
49
+  unsigned              updateId;
50
+  unsigned              wakeupId;
51
+  unsigned              msgCbId;
52
+  unsigned              audioCbId;
53
+
54
+  unsigned              updateCnt;
55
+  unsigned              wakeupCnt;
56
+  unsigned              msgCbCnt;
57
+  unsigned              audioCbCnt;
58
+
59
+  unsigned              baseOutId;
60
+  unsigned              iDevIdx;
61
+  unsigned              oDevIdx;
62
+  unsigned              iChCnt;
63
+  unsigned              oChCnt;
64
+  
65
+  unsigned              a[ kAmCnt ];
66
+
67
+
68
+  struct cmAmPanel_str* link;
69
+} cmAmPanel_t;
70
+
71
+typedef struct
72
+{
73
+  cmErr_t       err;
74
+  unsigned      appId;
75
+  cmUiH_t       uiH;
76
+  cmAudioSysH_t asH;
77
+  unsigned      nextId;
78
+  cmAmPanel_t*  list;
79
+} cmAm_t;
80
+
81
+cmUiASMstrH_t cmUiASMstrNullHandle = cmSTATIC_NULL_HANDLE;
82
+
83
+cmAm_t* _cmUiAmHandleToPtr( cmUiASMstrH_t h )
84
+{
85
+  cmAm_t* p = (cmAm_t*)h.h;
86
+  assert( p!=NULL);
87
+  return p;
88
+}
89
+
90
+cmAmRC_t _cmUiAmFreePanels( cmAm_t* p, bool callDriverFl )
91
+{
92
+  cmAmRC_t       rc = kOkAmRC;
93
+  cmAmPanel_t* pp = p->list;
94
+  
95
+  while( pp != NULL )
96
+  {
97
+    cmAmPanel_t* np = pp->link;
98
+
99
+    unsigned panelId = pp->panelId;
100
+
101
+    if( callDriverFl )
102
+      if( cmUiClearPanel( p->uiH, panelId ) != kOkUiRC )
103
+      {
104
+        rc = cmErrMsg(&p->err,kUiFailAmRC,"The panel %i clear failed.",panelId);
105
+        goto errLabel;
106
+      }
107
+
108
+    cmMemFree(pp);
109
+
110
+    pp = np;
111
+  }
112
+
113
+  p->nextId = 0;
114
+  p->list   = NULL;
115
+ 
116
+ errLabel:
117
+  return rc;
118
+}
119
+
120
+
121
+cmAmRC_t _cmUiAmFree( cmAm_t* p )
122
+{
123
+  _cmUiAmFreePanels(p,false);
124
+  cmMemFree(p);
125
+  return kOkAmRC;
126
+}
127
+
128
+cmAmRC_t cmUiAudioSysMstrAlloc( cmCtx_t* ctx, cmUiASMstrH_t* hp, cmUiH_t uiH, cmAudioSysH_t asH, unsigned appId )
129
+{
130
+  cmAmRC_t rc = kOkAmRC;
131
+  
132
+  if((rc = cmUiAudioSysMstrFree(hp)) != kOkAmRC )
133
+    return rc;
134
+
135
+  cmAm_t* p = cmMemAllocZ(cmAm_t,1);
136
+  cmErrSetup(&p->err,&ctx->rpt,"Audio System Master UI");
137
+  p->appId  = appId;
138
+  p->uiH    = uiH;
139
+  p->asH    = asH;
140
+  p->nextId = 0;
141
+  hp->h     = p;
142
+  return rc;
143
+}
144
+
145
+cmAmRC_t cmUiAudioSysMstrFree(  cmUiASMstrH_t* hp )
146
+{
147
+  cmAmRC_t rc = kOkAmRC;
148
+
149
+  if(hp==NULL || cmUiAudioSysMstrIsValid(*hp)==false )
150
+    return kOkAmRC;
151
+
152
+  cmAm_t* p = _cmUiAmHandleToPtr(*hp);
153
+
154
+  if((rc = _cmUiAmFree(p)) != kOkAmRC )
155
+    return rc;
156
+
157
+  hp->h = NULL;
158
+
159
+  return rc;
160
+}
161
+
162
+bool     cmUiAudioSysMstrIsValid( cmUiASMstrH_t h )
163
+{ return h.h != NULL; }
164
+
165
+
166
+cmAmRC_t cmUiAudioSysMstrInitialize( cmUiASMstrH_t amH, const cmAudioSysSsInitMsg_t* m, const cmChar_t* inDevLabel, const cmChar_t* outDevLabel )
167
+{
168
+  cmAmRC_t rc  = kOkAmRC;
169
+  cmAm_t*  p   = _cmUiAmHandleToPtr(amH);
170
+  cmUiH_t  uiH = p->uiH;
171
+
172
+  cmUiSetAppId( p->uiH, p->appId );
173
+
174
+  if( m->asSubIdx == 0 )
175
+  {
176
+    if((rc = _cmUiAmFreePanels(p,true)) != kOkAmRC )
177
+      return rc;
178
+    assert(p->list == NULL );
179
+  }
180
+
181
+  // create the panel recd and link it to the beginning of the list
182
+  cmAmPanel_t* pp = cmMemAllocZ(cmAmPanel_t,1);
183
+
184
+  pp->link     = p->list;    
185
+  p->list      = pp;
186
+  pp->asSubIdx = m->asSubIdx;
187
+  pp->iDevIdx  = m->inDevIdx;
188
+  pp->oDevIdx  = m->outDevIdx;
189
+  pp->iChCnt   = m->inChCnt;
190
+  pp->oChCnt   = m->outChCnt;
191
+
192
+  
193
+  pp->panelId           = p->nextId++;  
194
+  pp->updateId          = p->nextId++;
195
+  pp->wakeupId          = p->nextId++;
196
+  pp->msgCbId           = p->nextId++;
197
+  pp->audioCbId         = p->nextId++;
198
+
199
+  pp->a[kLabelAmId]     = p->nextId;
200
+  pp->a[kInSliderAmId]  = p->nextId += m->inChCnt;
201
+  pp->a[kInMeterAmId]   = p->nextId += m->inChCnt;
202
+  pp->a[kInToneAmId]    = p->nextId += m->inChCnt;
203
+  pp->a[kInPassAmId]    = p->nextId += m->inChCnt;
204
+  pp->a[kInMuteAmId]    = p->nextId += m->inChCnt;
205
+
206
+  pp->baseOutId         = p->nextId += m->inChCnt;  
207
+
208
+  pp->a[kOutSliderAmId] = pp->baseOutId;
209
+  pp->a[kOutMeterAmId]  = p->nextId += m->outChCnt;
210
+  pp->a[kOutToneAmId]   = p->nextId += m->outChCnt;
211
+  pp->a[kOutPassAmId]   = p->nextId += m->outChCnt;
212
+  pp->a[kOutMuteAmId]   = p->nextId += m->outChCnt;
213
+  p->nextId += m->outChCnt;
214
+
215
+  unsigned panelId = pp->panelId;
216
+  unsigned colW    = 50;
217
+  unsigned ctlW    = 45;
218
+  unsigned n       = 31;
219
+  cmChar_t chNumStr[ n+1 ];
220
+  int      w;
221
+
222
+  if( cmUiCreatePanel(uiH, panelId, "Master" ) != kOkUiRC )
223
+  {
224
+    rc = cmErrMsg(&p->err,kUiFailAmRC,"Panel %i create failed.",panelId);
225
+    goto errLabel;
226
+  }
227
+
228
+  cmUiSetFillRows( uiH, panelId, true );
229
+  cmUiCreateProgress(uiH, panelId, pp->updateId, "Update",  0, 0, 1, 0 );
230
+  cmUiCreateProgress(uiH, panelId, pp->wakeupId, "Wakeup",  0, 0, 1, 0 );
231
+  cmUiCreateProgress(uiH, panelId, pp->msgCbId,  "Message", 0, 0, 1, 0 );
232
+  cmUiCreateProgress(uiH, panelId, pp->audioCbId,"Audio",   0, 0, 1, 0 );
233
+  cmUiSetFillRows( uiH, panelId, false );
234
+
235
+  cmUiNewLine(     uiH, panelId );
236
+  cmUiCreateLabel( uiH, panelId, cmInvalidId, inDevLabel, kInsideUiFl | kLeftUiFl ); 
237
+  cmUiNewLine(     uiH, panelId );
238
+
239
+  unsigned i;
240
+  for(i=0; i<m->inChCnt; ++i)
241
+  {
242
+    snprintf(chNumStr,n,"%i",i);
243
+    
244
+    cmUiSetNextW(     uiH, panelId, ctlW );
245
+    cmUiCreateLabel(  uiH, panelId, cmInvalidId, chNumStr, 0 );
246
+    cmUiCreateVSlider(uiH, panelId, pp->a[kInSliderAmId] + i, NULL,     0, kMinDb,  kMaxDb, 0.1, 0 );
247
+    cmUiPlaceRight(   uiH, panelId );
248
+    cmUiCreateVMeter( uiH, panelId, pp->a[kInMeterAmId]  + i, NULL,     0, kMtrMin, kMtrMax, 0 ); 
249
+    w = cmUiSetW(     uiH, panelId, ctlW );
250
+    cmUiCreateCheck(  uiH, panelId, pp->a[kInToneAmId]   + i, "T",      0, false );
251
+    cmUiCreateCheck(  uiH, panelId, pp->a[kInPassAmId]   + i, "P",      0, false );
252
+    cmUiCreateCheck(  uiH, panelId, pp->a[kInMuteAmId]   + i, "M",      0, false );
253
+    cmUiSetW(         uiH, panelId, w );
254
+    cmUiSetBaseCol( uiH, panelId, 5 + (i+1)*colW);
255
+  }
256
+
257
+  cmUiSetBaseCol(  uiH, panelId, 0);
258
+  cmUiNewLine(     uiH, panelId );
259
+  cmUiCreateLabel( uiH,panelId, cmInvalidId, outDevLabel, kInsideUiFl | kLeftUiFl ); 
260
+  cmUiNewLine(     uiH, panelId );
261
+
262
+  for(i=0; i<m->outChCnt; ++i)
263
+  {
264
+    snprintf(chNumStr,n,"%i",i);
265
+    
266
+    cmUiSetNextW(     uiH, panelId, ctlW );
267
+    cmUiCreateLabel(  uiH, panelId, cmInvalidId, chNumStr, 0 );
268
+    cmUiCreateVSlider(uiH, panelId, pp->a[kOutSliderAmId] + i, NULL,     0, kMinDb,  kMaxDb, 0.1, 0 );
269
+    cmUiPlaceRight(   uiH, panelId );
270
+    cmUiCreateVMeter( uiH, panelId, pp->a[kOutMeterAmId]  + i, NULL,     0, kMtrMin, kMtrMax, 0 ); 
271
+    w = cmUiSetW(     uiH, panelId, ctlW );
272
+    cmUiCreateCheck(  uiH, panelId, pp->a[kOutToneAmId]   + i, "T",      0, false );
273
+    cmUiCreateCheck(  uiH, panelId, pp->a[kOutPassAmId]   + i, "P",      0, false );
274
+    cmUiCreateCheck(  uiH, panelId, pp->a[kOutMuteAmId]   + i, "M",      0, false );
275
+    cmUiSetW(         uiH, panelId, w );
276
+    cmUiSetBaseCol( uiH, panelId, 5 + (i+1)*colW);
277
+  }
278
+
279
+ errLabel:
280
+  return rc;
281
+}
282
+
283
+
284
+cmAmPanel_t* _cmUiAmFindPanel( cmAm_t* p, unsigned panelId )
285
+{
286
+  cmAmPanel_t* pp = p->list;
287
+  for(; pp!=NULL; pp=pp->link)
288
+    if( pp->panelId == panelId )
289
+      return pp;
290
+
291
+  cmErrMsg(&p->err,kPanelNotFoundAmRC,"The panel %i was not found.",panelId);
292
+
293
+  return NULL;
294
+}
295
+
296
+unsigned  _cmUiAmCtlTypeId( cmAm_t* p, cmAmPanel_t* pp, cmUiCId_t cId, unsigned usrId,
297
+  unsigned sliderId, unsigned toneId, unsigned passId, unsigned muteId )
298
+{
299
+    switch( cId )
300
+    {
301
+      case kSliderUiCId:
302
+        assert( pp->a[sliderId] <= usrId && usrId < pp->a[sliderId]+pp->oChCnt);
303
+        return sliderId;
304
+        break;
305
+
306
+      case kCheckUiCId:
307
+        if( pp->a[toneId] <= usrId && usrId < pp->a[toneId]+pp->oChCnt )
308
+          return toneId;
309
+
310
+        if( pp->a[passId] <= usrId && usrId < pp->a[passId]+pp->oChCnt )
311
+          return passId;
312
+
313
+        if( pp->a[muteId] <= usrId && usrId < pp->a[muteId]+pp->oChCnt )
314
+          return muteId;
315
+        break;
316
+
317
+      default:
318
+        assert(0);
319
+        break;
320
+    
321
+  }
322
+
323
+  return cmInvalidId;
324
+}
325
+
326
+
327
+cmUiRC_t cmUiAudioSysMstrOnUiEvent( cmUiASMstrH_t h, const cmUiDriverArg_t* a )
328
+{
329
+  cmUiRC_t          rc = kOkUiRC;
330
+  cmAm_t*            p = _cmUiAmHandleToPtr(h);
331
+  cmAmPanel_t*      pp;
332
+  cmAudioSysMstr_t  r;
333
+  unsigned          typeId;
334
+
335
+  if((pp = _cmUiAmFindPanel( p, a->panelId )) == NULL)
336
+    return cmErrLastRC(&p->err);
337
+
338
+  if( a->usrId == pp->panelId )
339
+  {
340
+    cmAudioSysStatusNotifyEnable(p->asH, pp->asSubIdx, a->ival );
341
+    return rc;
342
+  }
343
+
344
+  if( a->usrId >= pp->baseOutId )
345
+    typeId = _cmUiAmCtlTypeId(p,pp,a->cId,a->usrId,kOutSliderAmId,kOutToneAmId,kOutPassAmId,kOutMuteAmId);
346
+  else
347
+    typeId = _cmUiAmCtlTypeId(p,pp,a->cId,a->usrId,kInSliderAmId,kInToneAmId,kInPassAmId,kInMuteAmId);
348
+
349
+  
350
+  assert( typeId != cmInvalidId );
351
+  if( typeId == cmInvalidId )
352
+    return cmErrMsg(&p->err,kCtlNotFoundUiRC,"The type of a UI control could not be determined.");
353
+
354
+  
355
+  unsigned asInFl = 0;
356
+  unsigned asCtlId = cmInvalidId;
357
+  unsigned asCh    = a->usrId - pp->a[typeId];
358
+  double   asValue = 0;
359
+
360
+  switch( typeId )
361
+  {
362
+    case kInSliderAmId: 
363
+      asInFl  = 1;
364
+      asCtlId = kSliderUiAsId;
365
+      asValue = a->fval;
366
+      break;
367
+
368
+    case kInToneAmId:   
369
+      asInFl  = 1;
370
+      asCtlId = kToneUiAsId;
371
+      asValue = a->ival;
372
+      break;
373
+
374
+    case kInPassAmId:   
375
+      asInFl  = 1;
376
+      asCtlId = kPassUiAsId;
377
+      asValue = a->ival;
378
+      break;
379
+
380
+    case kInMuteAmId:   
381
+      asInFl  = 1;;
382
+      asCtlId = kMuteUiAsId;
383
+      asValue = a->ival;
384
+      break;
385
+
386
+    case kOutSliderAmId: 
387
+      asCtlId = kSliderUiAsId;
388
+      asValue = a->fval;
389
+      break;
390
+
391
+    case kOutToneAmId:   
392
+      asCtlId = kToneUiAsId;
393
+      asValue = a->ival;
394
+      break;
395
+
396
+    case kOutPassAmId:   
397
+      asCtlId = kPassUiAsId;
398
+      asValue = a->ival;
399
+      break;
400
+
401
+    case kOutMuteAmId:   
402
+      asCtlId = kMuteUiAsId;
403
+      asValue = a->ival;
404
+      break;
405
+
406
+  }
407
+
408
+  unsigned asDevIdx = asInFl ? pp->iDevIdx : pp->oDevIdx;
409
+
410
+  r.asSubIdx  = pp->asSubIdx;
411
+  r.uiId      = kUiMstrSelAsId;
412
+  r.selId     = cmInvalidId;
413
+  r.instId    = cmAudioSysFormUiInstId(asDevIdx,asCh,asInFl,asCtlId);
414
+  r.instVarId = cmInvalidId;
415
+  r.value     = asValue;
416
+
417
+  if( cmAudioSysDeliverMsg(p->asH,  &r, sizeof(r), cmInvalidId ) != kOkAsRC )
418
+     rc = cmErrMsg(&p->err,kSubSysFailUiRC,"Audio System master control UI message delivery to the audio system failed.");
419
+
420
+
421
+  return rc;
422
+}
423
+
424
+cmUiRC_t cmUiAudioSysMstrOnStatusEvent( cmUiASMstrH_t h, const cmAudioSysStatus_t* m, const double* iMeterArray, const double* oMeterArray )
425
+{
426
+  cmAm_t*       p = _cmUiAmHandleToPtr(h);
427
+  cmAmPanel_t* pp = p->list;
428
+  for(; pp!=NULL; pp=pp->link)
429
+    if(pp->asSubIdx == m->asSubIdx )
430
+      break;
431
+
432
+  if( pp == NULL )
433
+    return cmErrMsg(&p->err,kPanelNotFoundUiRC,"The panel associated with Audio system index %i could not be found.",m->asSubIdx);
434
+
435
+  cmUiSetAppId(p->uiH,p->appId);
436
+
437
+  cmUiSetInt(p->uiH, pp->updateId,  m->updateCnt  != pp->updateCnt );
438
+  cmUiSetInt(p->uiH, pp->wakeupId,  m->wakeupCnt  != pp->wakeupCnt );
439
+  cmUiSetInt(p->uiH, pp->msgCbId,   m->msgCbCnt   != pp->msgCbCnt );
440
+  cmUiSetInt(p->uiH, pp->audioCbId, m->audioCbCnt != pp->audioCbCnt );
441
+
442
+  pp->updateCnt = m->updateCnt;
443
+  pp->wakeupCnt = m->wakeupCnt;
444
+  pp->msgCbCnt  = m->msgCbCnt;
445
+  pp->audioCbCnt= m->audioCbCnt;
446
+
447
+  cmUiSetAppId(p->uiH,cmInvalidId);
448
+
449
+  return kOkUiRC;
450
+}

+ 37
- 0
cmUiAudioSysMstr.h View File

@@ -0,0 +1,37 @@
1
+#ifndef cmUiAudioSysMstr_h
2
+#define cmUiAudioSysMstr_h
3
+
4
+#ifdef __cplusplus
5
+extern "C" {
6
+#endif
7
+
8
+  enum
9
+  {
10
+    kOkAmRC = cmOkRC,
11
+    kUiFailAmRC,
12
+    kPanelNotFoundAmRC
13
+  };
14
+
15
+  typedef cmHandle_t cmUiASMstrH_t;
16
+  typedef cmRC_t     cmAmRC_t;
17
+
18
+  extern cmUiASMstrH_t cmUiASMstrNullHandle;
19
+
20
+  cmAmRC_t cmUiAudioSysMstrAlloc( cmCtx_t* ctx, cmUiASMstrH_t* hp, cmUiH_t uiH, cmAudioSysH_t asH, unsigned appId );
21
+  cmAmRC_t cmUiAudioSysMstrFree(  cmUiASMstrH_t* hp );
22
+
23
+  bool     cmUiAudioSysMstrIsValid( cmUiASMstrH_t h );
24
+
25
+  cmAmRC_t cmUiAudioSysMstrInitialize( cmUiASMstrH_t h, const cmAudioSysSsInitMsg_t* m, const cmChar_t* inDevLabel, const cmChar_t* outDevLabel );
26
+
27
+  // Receive UI events.
28
+  cmUiRC_t cmUiAudioSysMstrOnUiEvent( cmUiASMstrH_t h, const cmUiDriverArg_t* a );
29
+
30
+  // Receive UI status events
31
+  cmUiRC_t cmUiAudioSysMstrOnStatusEvent( cmUiASMstrH_t h, const cmAudioSysStatus_t* m, const double* iMeterArray, const double* oMeterArray );
32
+
33
+#ifdef __cplusplus
34
+}
35
+#endif
36
+
37
+#endif

Loading…
Cancel
Save