libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmDspUi.c 19KB

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