libcm is a C development framework with an emphasis on audio signal processing applications.
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

cmDspUi.c 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. #include "cmPrefix.h"
  2. #include "cmGlobal.h"
  3. #include "cmFloatTypes.h"
  4. #include "cmRpt.h"
  5. #include "cmErr.h"
  6. #include "cmCtx.h"
  7. #include "cmMem.h"
  8. #include "cmMallocDebug.h"
  9. #include "cmLinkedHeap.h"
  10. #include "cmJson.h"
  11. #include "cmSymTbl.h"
  12. #include "cmPrefs.h"
  13. #include "cmDspValue.h"
  14. #include "cmMsgProtocol.h"
  15. #include "cmProcObj.h"
  16. #include "cmDspCtx.h"
  17. #include "cmDspClass.h"
  18. #include "cmDspUi.h"
  19. #include "cmThread.h"
  20. #include "cmUdpPort.h"
  21. #include "cmUdpNet.h"
  22. #include "cmSerialPort.h"
  23. #include "cmTime.h"
  24. #include "cmAudioSys.h"
  25. /*
  26. // buffer layout is:
  27. // [ cmDspUiHdr_t <data> ]
  28. // The format of the <data> is determiend by hdr.value.
  29. // Since hdr.value is the last field in the cmDspUiHdr_t record
  30. // the data follows this value.
  31. cmDspRC_t cmDspMsgSend(
  32. cmErr_t* err,
  33. unsigned asSubIdx,
  34. unsigned msgTypeId,
  35. unsigned selId,
  36. unsigned flags,
  37. unsigned instId,
  38. unsigned instVarId,
  39. const cmDspValue_t* valPtr,
  40. cmRC_t (*sendFunc)(void* cbDataPtr, const void* msgArray[], unsigned msgByteCntArray[], unsigned segCnt ),
  41. void* cbDataPtr )
  42. {
  43. unsigned bufByteCnt = sizeof(cmDspUiHdr_t);
  44. unsigned dataByteCnt = 0;
  45. if( valPtr != NULL )
  46. dataByteCnt = cmDsvSerialDataByteCount(valPtr);
  47. bufByteCnt += dataByteCnt;
  48. char buf[ bufByteCnt ];
  49. cmDspUiHdr_t* hdr = (cmDspUiHdr_t*)buf;
  50. hdr->asSubIdx = asSubIdx;
  51. hdr->uiId = msgTypeId; // see kXXXSelAsId identifiers in cmAudioSys.h
  52. hdr->selId = selId; // if msgTypeId==kUiSelAsId then see kXXXDuId in cmDspUi.h
  53. hdr->flags = flags;
  54. hdr->instId = instId;
  55. hdr->instVarId = instVarId;
  56. if( valPtr == NULL )
  57. cmDsvSetNull(&hdr->value);
  58. else
  59. {
  60. // this function relies on the 'hdr.value' field being the last field in the 'hdr'.
  61. if( cmDsvSerialize( valPtr, &hdr->value, sizeof(cmDspValue_t) + dataByteCnt) != kOkDsvRC )
  62. return cmErrMsg(err,kSerializeUiMsgFailDspRC,"An attempt to serialize a UI msg failed.");
  63. }
  64. const void* vp = buf;
  65. if( sendFunc(cbDataPtr,&vp,&bufByteCnt,1) != cmOkRC )
  66. return cmErrMsg(err,kSendToHostFailDspRC,"An attempt to transmit a msg to the host failed.");
  67. return kOkDspRC;
  68. }
  69. */
  70. // This function is passed to cmDspMsgSend() by _cmDspUiMsg().
  71. // It is used to coerce the callback data ptr 'cbDataPtr' into a
  72. // cmAudioSysCtx_str* for calling back into cmDspSys. It then translates
  73. // the result code from a cmAsRC_t to a cmRC_t.
  74. cmMsgRC_t _cmDspUiDspToHostCb( void* cbDataPtr, unsigned msgByteCnt, const void* msg)
  75. {
  76. struct cmAudioSysCtx_str* asCtx = (struct cmAudioSysCtx_str*)cbDataPtr;
  77. cmMsgRC_t rc = kOkMsgRC;
  78. if(asCtx->dspToHostFunc(asCtx, &msg, &msgByteCnt, 1) != kOkAsRC )
  79. rc = kSendFailMsgRC;
  80. return rc;
  81. }
  82. cmDspRC_t _cmDspUiMsg(cmDspCtx_t* ctx, unsigned msgTypeId, unsigned selId, unsigned flags, cmDspInst_t* inst, unsigned instVarId, const cmDspValue_t* valPtr )
  83. {
  84. return cmMsgSend(
  85. &ctx->cmCtx->err,
  86. ctx->ctx->asSubIdx,
  87. msgTypeId,
  88. selId,
  89. flags,
  90. inst==NULL ? cmInvalidId : inst->id,
  91. instVarId,
  92. valPtr,
  93. _cmDspUiDspToHostCb,
  94. ctx->ctx );
  95. }
  96. // buffer layout is:
  97. // [ cmDspUiHdr_t <data> ]
  98. // The format of the <data> is determiend by hdr.value.
  99. // Since hdr.value is the last field in the cmDspUiHdr_t record
  100. // the data follows this value.
  101. /*
  102. cmDspRC_t _cmDspUiMsg(cmDspCtx_t* ctx, unsigned msgTypeId, unsigned selId, unsigned flags, cmDspInst_t* inst, unsigned instVarId, const cmDspValue_t* valPtr )
  103. {
  104. unsigned bufByteCnt = sizeof(cmDspUiHdr_t);
  105. unsigned dataByteCnt = 0;
  106. if( valPtr != NULL )
  107. dataByteCnt = cmDsvSerialDataByteCount(valPtr);
  108. bufByteCnt += dataByteCnt;
  109. char buf[ bufByteCnt ];
  110. cmDspUiHdr_t* hdr = (cmDspUiHdr_t*)buf;
  111. hdr->asSubIdx = ctx->ctx->asSubIdx;
  112. hdr->uiId = msgTypeId; // see kXXXSelAsId identifiers in cmAudioSys.h
  113. hdr->selId = selId; // if msgTypeId==kUiSelAsId then see kXXXDuId in cmDspUi.h
  114. hdr->flags = flags;
  115. hdr->instId = inst==NULL ? cmInvalidId : inst->id;
  116. hdr->instVarId = instVarId;
  117. if( valPtr == NULL )
  118. cmDsvSetNull(&hdr->value);
  119. else
  120. {
  121. // this function relies on the 'hdr.value' field being the last field in the 'hdr'.
  122. if( cmDsvSerialize( valPtr, &hdr->value, sizeof(cmDspValue_t) + dataByteCnt) != kOkDsvRC )
  123. {
  124. if( inst == NULL )
  125. return cmErrMsg(&ctx->cmCtx->err,kSerializeUiMsgFailDspRC,"An attempt to serialize a UI msg failed.");
  126. else
  127. return cmDspInstErr(ctx,inst,kSerializeUiMsgFailDspRC,"An attempt to serialize a msg for '%s' failed.",inst->classPtr->labelStr);
  128. }
  129. }
  130. const void* vp = buf;
  131. if( ctx->ctx->dspToHostFunc(ctx->ctx,&vp,&bufByteCnt,1) != kOkAsRC )
  132. {
  133. if( inst == NULL )
  134. return cmErrMsg(&ctx->cmCtx->err,kSendToHostFailDspRC,"An attempt to transmit a msg to the host failed.");
  135. else
  136. return cmDspInstErr(ctx,inst,kSendToHostFailDspRC,"An attempt to transmit a msg to the host failed.");
  137. }
  138. return kOkDspRC;
  139. }
  140. */
  141. cmDspRC_t _cmDspUiUseInstSymbolAsLabel( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned lblVarId, const cmChar_t* ctlTypeStr )
  142. {
  143. if( inst->symId != cmInvalidId )
  144. {
  145. cmDspValue_t v;
  146. // use the instance symbol as the default UI control label
  147. const cmChar_t* label = cmDspDefaultStrcz(inst,lblVarId);
  148. if( label == NULL )
  149. label = cmSymTblLabel(ctx->stH,inst->symId);
  150. if(label != NULL )
  151. {
  152. cmDsvSetStrcz(&v,label);
  153. if( _cmDspUiMsg(ctx, kUiSelAsId, kValueDuiId, 0, inst, lblVarId, &v ) != kOkDspRC )
  154. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"%s label UI elment create failed.", ctlTypeStr);
  155. }
  156. }
  157. return kOkDspRC;
  158. }
  159. cmDspRC_t cmDspSendValueToAudioSys( cmDspCtx_t* ctx, unsigned msgTypeId, unsigned selId, unsigned valId, const cmDspValue_t* valPtr )
  160. { return _cmDspUiMsg(ctx, msgTypeId, selId, 0, NULL, valId, valPtr ); }
  161. cmDspRC_t cmDspUiConsolePrint( cmDspCtx_t* ctx, cmChar_t* text )
  162. {
  163. cmDspValue_t v;
  164. cmDsvSetStrz(&v,text);
  165. return _cmDspUiMsg( ctx, kUiSelAsId, kPrintDuiId, 0, NULL, cmInvalidId, &v );
  166. }
  167. cmDspRC_t cmDspUiSendValue( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned varId, const cmDspValue_t* valPtr )
  168. { return _cmDspUiMsg(ctx, kUiSelAsId, kValueDuiId, 0, inst, varId, valPtr ); }
  169. cmDspRC_t cmDspUiSendVar( cmDspCtx_t* ctx, cmDspInst_t* inst, cmDspVar_t* var )
  170. { return _cmDspUiMsg(ctx, kUiSelAsId, kValueDuiId, 0, inst, var->constId, &var->value ); }
  171. cmDspRC_t cmDspUiScalarCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned ctlDuiId, unsigned minVarId, unsigned maxVarId, unsigned stpVarId, unsigned valVarId, unsigned lblVarId )
  172. {
  173. cmDspRC_t rc;
  174. unsigned arr[] = { minVarId, maxVarId, stpVarId, valVarId, lblVarId };
  175. cmDspValue_t v;
  176. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  177. cmDsvSetUIntMtx(&v,arr,vn,1);
  178. // tell the UI to create a slider control
  179. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, ctlDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  180. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Scalar UI element create failed.");
  181. // use instance symbol as default label
  182. if((rc = _cmDspUiUseInstSymbolAsLabel(ctx, inst, lblVarId, "Scalar")) != kOkDspRC )
  183. return rc;
  184. // Set the kUiDsvFl on the variables used for the min/max/def/val for this scalar
  185. // Setting this flag will cause their values to be sent to the UI whenever they change.
  186. cmDspInstVarSetFlags( ctx, inst, minVarId, kUiDsvFl );
  187. cmDspInstVarSetFlags( ctx, inst, maxVarId, kUiDsvFl );
  188. cmDspInstVarSetFlags( ctx, inst, stpVarId, kUiDsvFl );
  189. cmDspInstVarSetFlags( ctx, inst, valVarId, kUiDsvFl );
  190. return rc;
  191. }
  192. cmDspRC_t cmDspUiTextCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned valVarId, unsigned lblVarId )
  193. {
  194. cmDspRC_t rc;
  195. unsigned arr[] = { valVarId, lblVarId };
  196. cmDspValue_t v;
  197. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  198. cmDsvSetUIntMtx(&v,arr,vn,1);
  199. // tell the UI to create a text control
  200. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kTextDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  201. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Text UI element create failed.");
  202. // use instance symbol as default label
  203. if((rc = _cmDspUiUseInstSymbolAsLabel(ctx, inst, lblVarId, "Text")) != kOkDspRC )
  204. return rc;
  205. // Set the kUiDsvFl on the variables used for the min/max/def/val for this scalar
  206. // Setting this flag will cause their values to be sent to the UI whenever they change.
  207. cmDspInstVarSetFlags( ctx, inst, valVarId, kUiDsvFl );
  208. return rc;
  209. }
  210. cmDspRC_t cmDspUiFnameCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned valVarId, unsigned patVarId, unsigned dirVarId )
  211. {
  212. cmDspRC_t rc = kOkDspRC;
  213. unsigned arr[] = { valVarId, patVarId, dirVarId };
  214. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  215. cmDspValue_t v;
  216. unsigned i;
  217. cmDsvSetUIntMtx(&v,arr,vn,1);
  218. if((rc = _cmDspUiMsg(ctx, kUiSelAsId, kFnameDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  219. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"File/Directory chooser UI element create failed.");
  220. // set the kDsvUiFl in the variabes which update the UI
  221. for(i=0; i<vn; ++i)
  222. cmDspInstVarSetFlags( ctx, inst, arr[i], kUiDsvFl );
  223. return rc;
  224. }
  225. cmDspRC_t cmDspUiMsgListCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned height, unsigned listVarId, unsigned selVarId )
  226. {
  227. cmDspRC_t rc = kOkDspRC;
  228. unsigned arr[] = { height, selVarId, listVarId };
  229. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  230. cmDspValue_t v;
  231. unsigned i;
  232. cmDsvSetUIntMtx(&v,arr,vn,1);
  233. if((rc = _cmDspUiMsg(ctx, kUiSelAsId, kMsgListDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  234. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Msg List UI element create failed.");
  235. // set the kDsvUiFl in the variabes which update the UI
  236. for(i=1; i<vn; ++i)
  237. cmDspInstVarSetFlags( ctx, inst, arr[i], kUiDsvFl );
  238. return rc;
  239. }
  240. cmDspRC_t cmDspUiMeterCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned minVarId, unsigned maxVarId, unsigned valVarId, unsigned lblVarId )
  241. {
  242. cmDspRC_t rc;
  243. unsigned arr[] = { minVarId, maxVarId, valVarId, lblVarId };
  244. cmDspValue_t v;
  245. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  246. cmDsvSetUIntMtx(&v,arr,vn,1);
  247. // tell the UI to create a meter control
  248. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kMeterDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  249. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Meter UI element create failed.");
  250. // use instance symbol as default label
  251. if((rc = _cmDspUiUseInstSymbolAsLabel(ctx, inst, lblVarId, "Meter")) != kOkDspRC )
  252. return rc;
  253. // Set the kUiDsvFl on the variables used for the min/max/val for this meter
  254. // Setting this flag will cause their values to be sent to the UI whenever they change.
  255. cmDspInstVarSetFlags( ctx, inst, minVarId, kUiDsvFl );
  256. cmDspInstVarSetFlags( ctx, inst, maxVarId, kUiDsvFl );
  257. cmDspInstVarSetFlags( ctx, inst, valVarId, kUiDsvFl );
  258. return rc;
  259. }
  260. cmDspRC_t cmDspUiButtonCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned typeDuiId, unsigned outVarId, unsigned lblVarId )
  261. {
  262. cmDspRC_t rc;
  263. unsigned arr[] = { outVarId, lblVarId };
  264. cmDspValue_t v;
  265. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  266. cmDsvSetUIntMtx(&v, arr, vn, 1);
  267. // tell the UI to create a button control
  268. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, typeDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  269. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Button UI element create failed.");
  270. // use instance symbol as default label
  271. if((rc = _cmDspUiUseInstSymbolAsLabel(ctx, inst, lblVarId, "Button" )) != kOkDspRC )
  272. return rc;
  273. // Set the kUiDsvFl on the variables used for the val for this button
  274. // Setting this flag will cause their values to be sent to the UI whenever they change.
  275. cmDspInstVarSetFlags( ctx, inst, outVarId, kUiDsvFl );
  276. return rc;
  277. }
  278. cmDspRC_t cmDspUiLabelCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned lblVarId, unsigned alignVarId )
  279. {
  280. cmDspRC_t rc;
  281. unsigned arr[] = { lblVarId, alignVarId };
  282. cmDspValue_t v;
  283. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  284. cmDsvSetUIntMtx(&v, arr, vn, 1);
  285. // tell the UI to create a button control
  286. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kLabelDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  287. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Button UI element create failed.");
  288. // use instance symbol as default label
  289. if((rc = _cmDspUiUseInstSymbolAsLabel(ctx, inst, lblVarId, "Label" )) != kOkDspRC )
  290. return rc;
  291. // Set the kUiDsvFl on the variables used for the val for this button
  292. // Setting this flag will cause their values to be sent to the UI whenever they change.
  293. cmDspInstVarSetFlags( ctx, inst, lblVarId, kUiDsvFl );
  294. cmDspInstVarSetFlags( ctx, inst, alignVarId, kUiDsvFl );
  295. return rc;
  296. }
  297. cmDspRC_t cmDspUiTimeLineCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned tlFileVarId, unsigned audPathVarId, unsigned selVarId, unsigned measVarId, unsigned cursVarId )
  298. {
  299. cmDspRC_t rc;
  300. unsigned arr[] = { tlFileVarId, audPathVarId, selVarId, measVarId, cursVarId };
  301. cmDspValue_t v;
  302. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  303. cmDsvSetUIntMtx(&v,arr,vn,1);
  304. // tell the UI to create a time-line control
  305. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kTimeLineDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  306. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Time Line UI element create failed.");
  307. // use instance symbol as default label
  308. //if((rc = _cmDspUiUseInstSymbolAsLabel(ctx, inst, lblVarId, "TimeLine")) != kOkDspRC )
  309. // return rc;
  310. // Set the kUiDsvFl on the variables used for the min/max/def/val for this scalar
  311. // Setting this flag will cause their values to be sent to the UI whenever they change.
  312. cmDspInstVarSetFlags( ctx, inst, tlFileVarId, kUiDsvFl );
  313. cmDspInstVarSetFlags( ctx, inst, audPathVarId, kUiDsvFl );
  314. cmDspInstVarSetFlags( ctx, inst, selVarId, kUiDsvFl );
  315. cmDspInstVarSetFlags( ctx, inst, measVarId, kUiDsvFl );
  316. cmDspInstVarSetFlags( ctx, inst, cursVarId, kUiDsvFl );
  317. return rc;
  318. }
  319. cmDspRC_t cmDspUiScoreCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned scFileVarId, unsigned selVarId, unsigned smpIdxVarId, unsigned pitchVarId, unsigned velVarId, unsigned locIdxVarId, unsigned evtIdxVarId, unsigned dynVarId, unsigned valTypeVarId, unsigned valueVarId, unsigned measVarId )
  320. {
  321. cmDspRC_t rc;
  322. unsigned arr[] = { scFileVarId, selVarId, smpIdxVarId, pitchVarId, velVarId, locIdxVarId, evtIdxVarId, dynVarId, valTypeVarId, valueVarId, measVarId };
  323. cmDspValue_t v;
  324. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  325. cmDsvSetUIntMtx(&v,arr,vn,1);
  326. // tell the UI to create a score control
  327. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kScoreDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  328. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Score UI element create failed.");
  329. // Set the kUiDsvFl on the variables used for the min/max/def/val for this scalar
  330. // Setting this flag will cause their values to be sent to the UI whenever they change.
  331. cmDspInstVarSetFlags( ctx, inst, scFileVarId, kUiDsvFl );
  332. cmDspInstVarSetFlags( ctx, inst, selVarId, kUiDsvFl );
  333. cmDspInstVarSetFlags( ctx, inst, smpIdxVarId, kUiDsvFl );
  334. cmDspInstVarSetFlags( ctx, inst, pitchVarId, kUiDsvFl );
  335. cmDspInstVarSetFlags( ctx, inst, velVarId, kUiDsvFl );
  336. cmDspInstVarSetFlags( ctx, inst, locIdxVarId, kUiDsvFl );
  337. cmDspInstVarSetFlags( ctx, inst, evtIdxVarId, kUiDsvFl );
  338. cmDspInstVarSetFlags( ctx, inst, dynVarId, kUiDsvFl );
  339. cmDspInstVarSetFlags( ctx, inst, valTypeVarId, kUiDsvFl );
  340. cmDspInstVarSetFlags( ctx, inst, valueVarId, kUiDsvFl );
  341. cmDspInstVarSetFlags( ctx, inst, measVarId, kUiDsvFl );
  342. return rc;
  343. }
  344. cmDspRC_t cmDspUiTakeSeqBldrCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned fileNameVarId, unsigned ptrVarId, unsigned selVarId, unsigned refreshVarId )
  345. {
  346. cmDspRC_t rc;
  347. unsigned arr[] = { fileNameVarId, ptrVarId, selVarId, refreshVarId };
  348. cmDspValue_t v;
  349. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  350. cmDsvSetUIntMtx(&v,arr,vn,1);
  351. // tell the UI to create a sequence builder control
  352. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kTakeSeqBldrDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  353. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Take Sequence Builder UI element create failed.");
  354. // Setting kUiDsvFl will cause variable values to be sent to the UI whenever they change.
  355. cmDspInstVarSetFlags( ctx, inst, fileNameVarId, kUiDsvFl );
  356. cmDspInstVarSetFlags( ctx, inst, ptrVarId, kUiDsvFl );
  357. cmDspInstVarSetFlags( ctx, inst, selVarId, kUiDsvFl );
  358. cmDspInstVarSetFlags( ctx, inst, refreshVarId, kUiDsvFl );
  359. return rc;
  360. }
  361. cmDspRC_t cmDspUiTakeSeqRendCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned ptrVarId, unsigned refreshVarId, unsigned selVarId )
  362. {
  363. cmDspRC_t rc;
  364. unsigned arr[] = { ptrVarId, refreshVarId, selVarId };
  365. cmDspValue_t v;
  366. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  367. cmDsvSetUIntMtx(&v,arr,vn,1);
  368. // tell the UI to create a sequence render control
  369. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kTakeSeqRendDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  370. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"Take Sequence Render UI element create failed.");
  371. // Setting kUiDsvFl will cause variable values to be sent to the UI whenever they change.
  372. cmDspInstVarSetFlags( ctx, inst, ptrVarId, kUiDsvFl );
  373. cmDspInstVarSetFlags( ctx, inst, refreshVarId, kUiDsvFl );
  374. cmDspInstVarSetFlags( ctx, inst, selVarId, kUiDsvFl );
  375. return rc;
  376. }
  377. cmDspRC_t cmDspUi2dCreate( cmDspCtx_t* ctx, cmDspInst_t* inst, unsigned xVarId, unsigned yVarId, unsigned radiusVarId, unsigned angleVarId)
  378. {
  379. cmDspRC_t rc;
  380. unsigned arr[] = { xVarId, yVarId, radiusVarId, angleVarId };
  381. cmDspValue_t v;
  382. unsigned vn = sizeof(arr)/sizeof(arr[0]);
  383. cmDsvSetUIntMtx(&v,arr,vn,1);
  384. // tell the UI to create a sequence render control
  385. if((rc = _cmDspUiMsg( ctx, kUiSelAsId, kTwodDuiId, 0, inst, cmInvalidId, &v )) != kOkDspRC )
  386. return cmDspInstErr(ctx,inst,kUiEleCreateFailDspRC,"2-d UI element create failed.");
  387. // Setting kUiDsvFl will cause variable values to be sent to the UI whenever they change.
  388. cmDspInstVarSetFlags( ctx, inst, xVarId, kUiDsvFl );
  389. cmDspInstVarSetFlags( ctx, inst, yVarId, kUiDsvFl );
  390. cmDspInstVarSetFlags( ctx, inst, radiusVarId, kUiDsvFl );
  391. cmDspInstVarSetFlags( ctx, inst, angleVarId, kUiDsvFl );
  392. return rc;
  393. }
  394. cmDspRC_t cmDspUiNewColumn( cmDspCtx_t* ctx, unsigned colW )
  395. {
  396. cmDspRC_t rc = kOkDspRC;
  397. cmDspValue_t val;
  398. cmDsvSetUInt(&val,colW);
  399. if((rc = _cmDspUiMsg(ctx, kUiSelAsId, kColumnDuiId, 0, NULL, cmInvalidId, &val )) != kOkDspRC )
  400. return cmErrMsg(&ctx->cmCtx->err,kUiEleCreateFailDspRC,"New UI column request failed.");
  401. return rc;
  402. }
  403. cmDspRC_t cmDspUiInsertHorzBorder( cmDspCtx_t* ctx )
  404. {
  405. cmDspRC_t rc = kOkDspRC;
  406. if((rc = _cmDspUiMsg(ctx, kUiSelAsId, kHBorderDuiId, 0, NULL, cmInvalidId, NULL )) != kOkDspRC )
  407. return cmErrMsg(&ctx->cmCtx->err,kUiEleCreateFailDspRC,"Horizontal border request failed.");
  408. return rc;
  409. }
  410. cmDspRC_t cmDspUiNewPage( cmDspCtx_t* ctx, const cmChar_t* title )
  411. {
  412. cmDspRC_t rc = kOkDspRC;
  413. cmDspValue_t v;
  414. cmDsvSetStrcz(&v,title==NULL ? "Controls" : title );
  415. if((rc = _cmDspUiMsg(ctx, kUiSelAsId, kPageDuiId, 0, NULL, cmInvalidId, &v )) != kOkDspRC )
  416. return cmErrMsg(&ctx->cmCtx->err,kUiEleCreateFailDspRC,"New page request failed.");
  417. return rc;
  418. }