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.

cmDspSys.c 78KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587
  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 "cmText.h"
  11. #include "cmFileSys.h"
  12. #include "cmSymTbl.h"
  13. #include "cmTime.h"
  14. #include "cmMidi.h"
  15. #include "cmJson.h"
  16. #include "cmPrefs.h"
  17. #include "cmDspValue.h"
  18. #include "cmMsgProtocol.h"
  19. #include "cmThread.h"
  20. #include "cmUdpPort.h"
  21. #include "cmUdpNet.h"
  22. #include "cmSerialPort.h"
  23. #include "cmAudioSys.h"
  24. #include "cmProcObj.h"
  25. #include "cmDspCtx.h"
  26. #include "cmDspClass.h"
  27. #include "cmDspStore.h"
  28. #include "cmDspSys.h"
  29. #include "cmDspBuiltIn.h"
  30. #include "cmDspPgm.h"
  31. #include "cmDspPreset.h"
  32. #include "cmDspNet.h"
  33. #include "cmTime.h"
  34. cmDspSysH_t cmDspNullHandle = cmSTATIC_NULL_HANDLE;
  35. #define kDspSysLabelCharCnt (127)
  36. cmChar_t _cmDspSysLabel0[ kDspSysLabelCharCnt + 1 ];
  37. cmChar_t _cmDspSysLabel1[ kDspSysLabelCharCnt + 1 ];
  38. const cmChar_t* cmDspSysPrintLabel( const cmChar_t* label, unsigned i )
  39. {
  40. snprintf(_cmDspSysLabel0,kDspSysLabelCharCnt,"%s-%i",label,i);
  41. assert( strlen(_cmDspSysLabel0 ) <= kDspSysLabelCharCnt );
  42. return _cmDspSysLabel0;
  43. }
  44. const cmChar_t* cmDspSysPrintLabel2( const cmChar_t* label, unsigned i )
  45. {
  46. snprintf(_cmDspSysLabel1,kDspSysLabelCharCnt,"%s-%i",label,i);
  47. assert( strlen(_cmDspSysLabel1 ) <= kDspSysLabelCharCnt );
  48. return _cmDspSysLabel1;
  49. }
  50. ///============================================================================================
  51. cmDsp_t* _cmDspHandleToPtr( cmDspSysH_t h )
  52. {
  53. assert(h.h != NULL);
  54. return (cmDsp_t*)h.h;
  55. }
  56. cmDspInst_t* _cmDspSysInstSymIdToPtr( cmDsp_t* p, unsigned instSymId )
  57. {
  58. _cmDspInst_t* ip = p->instList;
  59. for(; ip!=NULL; ip = ip->linkPtr )
  60. if( ip->instPtr->symId == instSymId )
  61. return ip->instPtr;
  62. return NULL;
  63. }
  64. // free a single instance
  65. cmDspRC_t _cmDspInstFree( cmDspCtx_t* ctx, cmDspInst_t* inst )
  66. {
  67. cmDspRC_t rc = kOkDspRC;
  68. if( inst->freeFunc != NULL )
  69. if((rc = inst->freeFunc( ctx, inst, NULL )) != kOkDspRC )
  70. return rc;
  71. cmLHeapFree(ctx->lhH,inst);
  72. return kOkDspRC;
  73. }
  74. cmDspRC_t _cmDspSysFreeInst( cmDsp_t* p, unsigned instId )
  75. {
  76. cmDspRC_t rc = kOkDspRC;
  77. _cmDspInst_t* ip = p->instList;
  78. _cmDspInst_t* pp = NULL;
  79. // locate the requested instance
  80. for(; ip!=NULL; ip=ip->linkPtr)
  81. {
  82. if( ip->instPtr->id == instId )
  83. break;
  84. pp = ip;
  85. }
  86. // verify the instance was located
  87. if( ip == NULL )
  88. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The DSP instance %i could not be found.",instId);
  89. // instruct the instance to release its resources
  90. if( _cmDspInstFree(&p->ctx,ip->instPtr ) != kOkDspRC )
  91. return cmErrMsg(&p->err,kInstFinalFailDspRC,"An attempt to free DSP instance '%s' id:%i failed.",ip->instPtr->classPtr->labelStr,ip->instPtr->id);
  92. // remove the instance from the linked list
  93. if( pp == NULL )
  94. p->instList = NULL;
  95. else
  96. pp->linkPtr = ip->linkPtr;
  97. return rc;
  98. }
  99. cmDspRC_t _cmDspSysFinalize( cmDsp_t* p )
  100. {
  101. cmDspRC_t rc = kOkDspRC;
  102. _cmDspClass_t* cp = p->classList;
  103. _cmDspSysNetFree(p);
  104. // finalize the classes - no need to free the class ctl
  105. // recd's because they were allocated in the linked heap
  106. for(; cp!=NULL; cp=cp->linkPtr)
  107. {
  108. if( cp->classPtr->finalClassFunc != NULL )
  109. if( cp->classPtr->finalClassFunc(&p->ctx,cp->classPtr) != kOkDspRC )
  110. rc = cmErrMsg(&p->err,kClassFinalFailDspRC,"Class finalization failed on class '%s'.",cp->classPtr->labelStr);
  111. }
  112. if( p->ctx.cmProcCtx != NULL )
  113. if( cmCtxFree(&p->ctx.cmProcCtx) != cmOkRC )
  114. rc = cmErrMsg(&p->err,kProcFailDspRC,"The proc context finalizatoin failed.");
  115. cmDspStoreFree(&p->dsH);
  116. if( cmSymTblIsValid(p->stH) )
  117. cmSymTblDestroy(&p->stH);
  118. if( cmJsonIsValid(p->jsH) )
  119. if( cmJsonFinalize(&p->jsH) != kOkJsRC )
  120. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON finalization failed.");
  121. if( cmLHeapIsValid(p->lhH) )
  122. cmLHeapDestroy(&p->lhH);
  123. if( rc == kOkJsRC )
  124. {
  125. cmMemFree(p);
  126. // clear the cmAudioSysCtx_t
  127. memset(&p->ctx.ctx,0,sizeof(p->ctx.ctx));
  128. }
  129. return rc;
  130. }
  131. cmDspRC_t cmDspSysInitialize( cmCtx_t* ctx, cmDspSysH_t* hp, cmUdpNetH_t netH, cmSeH_t serialPortH )
  132. {
  133. unsigned i;
  134. cmDspRC_t rc = kOkDspRC;
  135. if((rc = cmDspSysFinalize(hp )) != kOkDspRC )
  136. return rc;
  137. cmDsp_t* p = cmMemAllocZ( cmDsp_t, 1 );
  138. cmErrSetup(&p->err,&ctx->rpt,"DSP System");
  139. //p->ctx.ctx = asCtx;
  140. p->cmCtx = *ctx;
  141. p->netH = netH;
  142. p->serialPortH = serialPortH;
  143. p->pgmIdx = cmInvalidIdx;
  144. // create the DSP class linked heap
  145. if(cmLHeapIsValid( p->lhH = cmLHeapCreate(1024,ctx)) == false)
  146. return cmErrMsg(&p->err,kLHeapFailDspRC,"Linked heap intiialization failed.");
  147. // initialize the DSP class JSON object
  148. if( cmJsonInitialize(&p->jsH,ctx) != kOkJsRC )
  149. {
  150. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON initialization failed.");
  151. goto errLabel;
  152. }
  153. // intialize the DSP class symbol table
  154. if( cmSymTblIsValid( p->stH = cmSymTblCreate(cmSymTblNullHandle,1,ctx)) == false )
  155. {
  156. rc = cmErrMsg(&p->err,kSymTblFailDspRC,"Symbol table initialization failed.");
  157. goto errLabel;
  158. }
  159. // allocate the DSP system variable storage object
  160. if( cmDspStoreAlloc(ctx,&p->dsH,10,10) != kOkDspRC )
  161. {
  162. rc = cmErrMsg(&p->err,kDspStoreFailDspRC,"DSP store allocation failed.");
  163. goto errLabel;
  164. }
  165. // initialize the proc context
  166. if( (p->ctx.cmProcCtx = cmCtxAlloc(NULL,&ctx->rpt,p->lhH,p->stH)) == NULL )
  167. {
  168. rc = cmErrMsg(&p->err,kProcFailDspRC,"cmProc context initialization failed.");
  169. goto errLabel;
  170. }
  171. // allocate the the preset mgr
  172. _cmDspPresetAlloc(&p->pm);
  173. // initialize the networking compenents
  174. if((rc = _cmDspSysNetAlloc(p)) != kOkDspRC )
  175. goto errLabel;
  176. // set the DSP ctx to use the system lHeap and sym. tbl so that the
  177. // DSP class instantions use them
  178. p->ctx.lhH = p->lhH;
  179. p->ctx.jsH = p->jsH;
  180. p->ctx.stH = p->stH;
  181. p->ctx.dsH = p->dsH;
  182. p->ctx.rsrcJsH = cmJsonNullHandle;
  183. p->ctx.rpt = &ctx->rpt;
  184. p->ctx.cmCtx = &p->cmCtx;
  185. p->ctx.dspH.h = p;
  186. _cmDspClass_t* pp = NULL;
  187. cmDspClassConsFunc_t classConsFunc = NULL;
  188. // Get each DSP class construction function
  189. for(i=0; (classConsFunc = cmDspClassGetBuiltIn(i))!=NULL; ++i)
  190. {
  191. // allocate the class ctl recd
  192. _cmDspClass_t* cp = cmLhAllocZ(p->ctx.lhH,_cmDspClass_t,1);
  193. // call the class constructor func
  194. cp->classPtr = classConsFunc(&p->ctx);
  195. // set the class symbol id
  196. cp->symId = cmSymTblRegister(p->ctx.stH,cp->classPtr->labelStr,true);
  197. // link in the class ctl recd
  198. if( pp == NULL )
  199. p->classList = cp;
  200. else
  201. pp->linkPtr = cp;
  202. pp = cp;
  203. }
  204. hp->h = p;
  205. p->ctx.lhH = cmLHeapNullHandle;
  206. p->ctx.jsH = cmJsonNullHandle;
  207. p->ctx.stH = cmSymTblNullHandle;
  208. errLabel:
  209. if( rc != kOkDspRC )
  210. _cmDspSysFinalize(p);
  211. return rc;
  212. }
  213. cmDspRC_t cmDspSysFinalize( cmDspSysH_t* hp )
  214. {
  215. cmDspRC_t rc = kOkDspRC;
  216. if( hp==NULL || cmDspSysIsValid(*hp)==false )
  217. return kOkDspRC;
  218. if((rc = cmDspSysUnload(*hp)) != kOkDspRC )
  219. return rc;
  220. cmDsp_t* p = _cmDspHandleToPtr(*hp);
  221. if((rc = _cmDspSysFinalize(p)) == kOkDspRC )
  222. hp->h = NULL;
  223. return rc;
  224. }
  225. unsigned cmDspSysPgmCount( cmDspSysH_t h )
  226. {
  227. _cmDspSysPgm_t* arr = _cmDspSysPgmArrayBase();
  228. unsigned i = 0;
  229. while( arr != NULL && arr[i].label != NULL )
  230. ++i;
  231. return i;
  232. }
  233. const cmChar_t* cmDspPgmLabel( cmDspSysH_t h, unsigned idx )
  234. {
  235. if( idx < cmDspSysPgmCount(h) )
  236. {
  237. _cmDspSysPgm_t* arr = _cmDspSysPgmArrayBase();
  238. return arr[idx].label;
  239. }
  240. return NULL;
  241. }
  242. bool cmDspSysIsValid( cmDspSysH_t h )
  243. { return h.h != NULL; }
  244. cmDspRC_t cmDspSysLastRC( cmDspSysH_t h )
  245. {
  246. cmDsp_t* p = _cmDspHandleToPtr(h);
  247. return cmErrLastRC(&p->err);
  248. }
  249. // This function is assigns a unique symbol id (cmDspInst_t.symId)
  250. // to all DSP instances whose symId is set to cmInvalidId.
  251. cmDspRC_t _cmDspSysAssignUniqueInstSymId( cmDsp_t* p )
  252. {
  253. typedef struct class_str
  254. {
  255. const cmChar_t* label;
  256. unsigned cnt;
  257. struct class_str* link;
  258. } class_t;
  259. cmDspRC_t rc = kOkDspRC;
  260. class_t* map = NULL;
  261. _cmDspInst_t* dip = p->instList;
  262. for(; dip!=NULL; dip=dip->linkPtr)
  263. {
  264. cmDspInst_t* ip = dip->instPtr;
  265. // if this instance does not have a valid symbol id then create one
  266. if( ip->symId == cmInvalidId )
  267. {
  268. // look for the instance class in map[]
  269. class_t* mp = map;
  270. for(; mp!=NULL; mp=mp->link)
  271. if( strcmp(ip->classPtr->labelStr,mp->label) == 0 )
  272. break;
  273. // if map[] does not yet have a recd for this class ....
  274. if( mp == NULL )
  275. {
  276. mp = cmMemAllocZ(class_t,1); // ... then make one
  277. mp->label = ip->classPtr->labelStr;
  278. mp->link = map;
  279. map = mp;
  280. }
  281. // generate a new unique symbol
  282. while( ip->symId==cmInvalidId && mp->cnt != cmInvalidId )
  283. {
  284. // increment the instance count for this class
  285. mp->cnt += 1;
  286. // form a symbol label
  287. cmChar_t* idStr = cmTsPrintfP(NULL,"%s-%i",ip->classPtr->labelStr,mp->cnt);
  288. // register the new symbol
  289. unsigned symId = cmSymTblRegisterSymbol(p->ctx.stH,idStr);
  290. cmMemFree(idStr); // the symbol label is no longer need
  291. // if the symbol has not yet been used then it must be unique
  292. if( _cmDspSysInstSymIdToPtr(p,symId) == NULL )
  293. ip->symId = symId;
  294. else
  295. cmSymTblRemove(p->ctx.stH,symId); // ... otherwise remove the symbol and try again
  296. }
  297. // check for the very unlikely case that no unique symbol could be generated
  298. if(mp->cnt == cmInvalidId )
  299. rc = cmErrMsg(&p->err,kSymNotFoundDspRC,"All DSP instances were not assigned a unique symbol id.");
  300. }
  301. }
  302. // free the class list
  303. class_t* mp = map;
  304. while( mp != NULL )
  305. {
  306. class_t* np = mp->link;
  307. cmMemFree(mp);
  308. mp = np;
  309. }
  310. return rc;
  311. }
  312. cmDspRC_t cmDspSysLoad( cmDspSysH_t h, cmAudioSysCtx_t* asCtx, unsigned pgmIdx )
  313. {
  314. cmDspRC_t rc;
  315. cmDsp_t* p = _cmDspHandleToPtr(h);
  316. p->pgmIdx = cmInvalidIdx;
  317. if( pgmIdx >= cmDspSysPgmCount(h) )
  318. return cmErrMsg(&p->err,kInvalidPgmIdxDspRC,"%i is not a valid program index.",pgmIdx);
  319. // unload the previously loaded DSP program
  320. if((rc = cmDspSysUnload(h)) != kOkDspRC )
  321. return rc;
  322. // assign the cmAudioSysCtx_t context recd
  323. p->ctx.ctx = asCtx;
  324. _cmDspSysPgm_t* arr = _cmDspSysPgmArrayBase();
  325. // form the resource file name
  326. if((p->rsrcFn = cmFsMakeFn(cmFsPrefsDir(),arr[pgmIdx].label,"js",NULL)) == NULL )
  327. {
  328. rc = cmErrMsg(&p->err,kFileSysFailDspRC,"Resource file name formation failed.");
  329. goto errLabel;
  330. }
  331. // if the pgm specific resource file already exists
  332. if( cmFsIsFile(p->rsrcFn) )
  333. {
  334. // open and parse the resource file
  335. if( cmJsonInitializeFromFile(&p->ctx.rsrcJsH,p->rsrcFn,&p->cmCtx) != kOkJsRC )
  336. {
  337. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Resource file open failed.");
  338. goto errLabel;
  339. }
  340. }
  341. else // ... the resource file does not currently exists - create it
  342. {
  343. cmJsonNode_t* rootPtr;
  344. if( cmJsonInitialize(&p->ctx.rsrcJsH,&p->cmCtx) != kOkJsRC )
  345. {
  346. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Resource object allocate failed.");
  347. goto errLabel;
  348. }
  349. if((rootPtr = cmJsonCreateObject(p->ctx.rsrcJsH, NULL )) == NULL )
  350. {
  351. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Resource object root allocate failed.");
  352. goto errLabel;
  353. }
  354. }
  355. // create a linked heap for use by the DSP instances
  356. if(cmLHeapIsValid( p->ctx.lhH = cmLHeapCreate(1024,&p->cmCtx)) == false)
  357. return cmErrMsg(&p->err,kLHeapFailDspRC,"DSP instance linked heap intiialization failed.");
  358. // initialize a JSON object for use by the DSP instances
  359. if( cmJsonInitialize(&p->ctx.jsH,&p->cmCtx) != kOkJsRC )
  360. {
  361. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON initialization failed.");
  362. goto errLabel;
  363. }
  364. // create a symbol table for use by the DSP instance (note that it uses the system sym. tbl. as it's parent)
  365. if( cmSymTblIsValid( p->ctx.stH = cmSymTblCreate(p->stH, cmDspSys_PARENT_SYM_TBL_BASE_ID, &p->cmCtx)) == false )
  366. {
  367. rc = cmErrMsg(&p->err,kSymTblFailDspRC,"DSP instance symbol table initialization failed.");
  368. goto errLabel;
  369. }
  370. // load the preset mgr
  371. if((rc = _cmDspPresetLoad(&p->pm,&p->cmCtx,&p->err,p->ctx.lhH,p->ctx.stH,arr[pgmIdx].label)) != kOkDspRC )
  372. {
  373. rc = cmErrMsg(&p->err,rc,"Preset manager load failed.");
  374. goto errLabel;
  375. }
  376. // setup the DSP network components
  377. if((rc = _cmDspSysNetPreLoad(p)) != kOkDspRC )
  378. goto errLabel;
  379. p->ctx.cycleCnt = 0;
  380. p->ctx._disableSymId = cmSymTblRegisterStaticSymbol(p->ctx.stH,"_disable");
  381. p->ctx._enableSymId = cmSymTblRegisterStaticSymbol(p->ctx.stH,"_enable");
  382. void** vpp = &arr[ pgmIdx ].userPtr;
  383. cmDspPgmFunc_t pgm = arr[ pgmIdx ].loadFunc;
  384. // allocate and connect user defined signal processing network
  385. if((rc = pgm(h,vpp)) == kOkDspRC )
  386. if((rc = cmErrLastRC(&p->err)) != kOkDspRC )
  387. {
  388. cmErrMsg(&p->err,rc,"User DSP system load failed.");
  389. goto errLabel;
  390. }
  391. p->pgmIdx = pgmIdx;
  392. // enter sync mode
  393. if((rc = _cmDspSysNetSync(p)) != kOkDspRC )
  394. {
  395. cmErrMsg(&p->err,rc,"DSP system sync failed.");
  396. goto errLabel;
  397. }
  398. rc = _cmDspSysAssignUniqueInstSymId(p);
  399. errLabel:
  400. if( rc != kOkDspRC )
  401. cmDspSysUnload(h);
  402. return rc;
  403. }
  404. cmDspRC_t cmDspSysUnload( cmDspSysH_t h )
  405. {
  406. if( cmDspSysIsValid(h) == false )
  407. return kOkDspRC;
  408. cmDspRC_t rc = kOkDspRC;
  409. cmDsp_t* p = _cmDspHandleToPtr(h);
  410. _cmDspInst_t* ip = p->instList;
  411. // call the DSP network unload function - this function is provided
  412. // by the client network to release any resources obtained when
  413. // the network was created
  414. if( p->pgmIdx != cmInvalidIdx )
  415. {
  416. _cmDspSysPgm_t* arr = _cmDspSysPgmArrayBase();
  417. void** vpp = &arr[ p->pgmIdx ].userPtr;
  418. cmDspPgmFunc_t pgm = arr[ p->pgmIdx ].unloadFunc;
  419. if( pgm != NULL )
  420. if((rc = pgm(h,vpp)) == kOkDspRC )
  421. if((rc = cmErrLastRC(&p->err)) != kOkDspRC )
  422. cmErrMsg(&p->err,rc,"User DSP system unload failed.");
  423. }
  424. p->pgmIdx = cmInvalidIdx;
  425. // unload the networking components
  426. _cmDspSysNetUnload(p);
  427. // free the DSP instances
  428. for(; ip!=NULL; ip=ip->linkPtr)
  429. if((rc = _cmDspInstFree(&p->ctx,ip->instPtr)) != kOkDspRC )
  430. rc = cmErrMsg(&p->err,kInstFinalFailDspRC,"An attempt to free DSP instance '%s' id:%i failed.",ip->instPtr->classPtr->labelStr,ip->instPtr->id);
  431. p->instList = NULL;
  432. // unload the preset manager
  433. if((rc = _cmDspPresetUnload(&p->pm,&p->cmCtx)) != kOkDspRC)
  434. rc = cmErrMsg(&p->err,rc,"Preset manager 'unload' failed.");
  435. // finalize the pgm specific JSON tree
  436. if( cmJsonIsValid(p->ctx.rsrcJsH))
  437. {
  438. // if the JSON tree has been modified.
  439. if( cmJsonIsModified(p->ctx.rsrcJsH) )
  440. if( cmJsonWrite(p->ctx.rsrcJsH, cmJsonRoot(p->ctx.rsrcJsH), p->rsrcFn ) != kOkJsRC )
  441. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON resource file write failed on '%s'.",cmStringNullGuard(p->rsrcFn));
  442. if( cmJsonFinalize(&p->ctx.rsrcJsH) != kOkJsRC )
  443. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Resource JSON finalization failed.");
  444. }
  445. // release the JSON file name
  446. if( p->rsrcFn != NULL )
  447. {
  448. cmFsFreeFn(p->rsrcFn); // free the resource file name
  449. p->rsrcFn = NULL;
  450. }
  451. // tell the DSP net system that the pgm has been unloaded
  452. _cmDspSysNetUnload(p);
  453. // elimnate the linked heap, system table, and json object used by the DSP instance objects
  454. if( cmLHeapIsValid(p->ctx.lhH) )
  455. cmLHeapDestroy(&p->ctx.lhH);
  456. if( cmJsonIsValid(p->ctx.jsH) )
  457. if( cmJsonFinalize(&p->ctx.jsH) != kOkJsRC )
  458. rc = cmErrMsg(&p->err,kJsonFailDspRC,"DSP instance JSON object finalization failed.");
  459. if( cmSymTblIsValid(p->ctx.stH) )
  460. cmSymTblDestroy(&p->ctx.stH);
  461. return rc;
  462. }
  463. cmDspRC_t cmDspSysReset( cmDspSysH_t h )
  464. {
  465. cmDsp_t* p = _cmDspHandleToPtr(h);
  466. cmDspRC_t rc = kOkDspRC;
  467. // call reset on each of the instances
  468. _cmDspInst_t* ip = p->instList;
  469. for(; ip != NULL; ip = ip->linkPtr )
  470. if( ip->instPtr->resetFunc != NULL )
  471. {
  472. if( ip->instPtr->resetFunc(&p->ctx,ip->instPtr,NULL) != kOkDspRC )
  473. rc = cmErrMsg(&p->err,kInstResetFailDspRC,"Reset failed on DSP instance '%s' id:%i.",ip->instPtr->classPtr->labelStr,ip->instPtr->id);
  474. ip->instPtr->flags = 0;
  475. }
  476. // send the _reset symbol to every instance which has the _reset attribute symbol
  477. if( rc == kOkDspRC )
  478. {
  479. cmDspValue_t v;
  480. unsigned resetSymId = cmDspSysRegisterStaticSymbol(h,"_reset");
  481. cmDsvSetSymbol(&v,resetSymId);
  482. rc = cmDspSysBroadcastValue(h, resetSymId, &v);
  483. }
  484. return rc;
  485. }
  486. // Handle msg's arriving from the UI
  487. cmDspRC_t _cmDspSysHandleUiMsg(cmDsp_t* p, _cmDspInst_t* ip, const void* msgPtr, unsigned msgByteCnt)
  488. {
  489. cmDspRC_t rc = kOkDspRC;
  490. cmDspUiHdr_t* h = (cmDspUiHdr_t*)msgPtr;
  491. cmDspEvt_t e;
  492. assert( h->uiId == kUiSelAsId );
  493. // the only source of msg's (at the time of this writing) is the UI so:
  494. // Mark the msg as a UI event and set the kUiEchoDspFl if the UI has requested duplex operation.
  495. e.flags = kUiDspFl | (cmIsFlag(h->flags,kDuplexDuiFl) ? kUiEchoDspFl : 0);
  496. e.srcInstPtr = NULL; // the UI has no source instance
  497. e.srcVarId = h->selId; // set the event srcVarId to the UI selId
  498. e.dstVarId = h->instVarId; // identify the dst inst variable
  499. e.dstDataPtr = NULL; // UI msg's don't have custom data (yet)
  500. e.valuePtr = &h->value; //
  501. // if the value associated with this msg is a mtx then set
  502. // its mtx data area pointer to just after the msg header.
  503. if( cmDsvIsMtx(&h->value) )
  504. h->value.u.m.u.vp = ((char*)msgPtr) + sizeof(cmDspUiHdr_t);
  505. else
  506. rc = cmDsvDeserializeInPlace(&h->value,msgByteCnt-sizeof(cmDspUiHdr_t));
  507. if( rc != kOkDsvRC )
  508. cmErrMsg(&p->err,kSerializeUiMsgFailDspRC,"DSP system receive Deserialize failed.");
  509. // find the dest. DSP instance for this msg
  510. for(; ip != NULL; ip = ip->linkPtr )
  511. if( ip->instPtr->id == h->instId )
  512. {
  513. // send the msg to the DSP dst. instance
  514. if( ip->instPtr->recvFunc != NULL )
  515. if( ip->instPtr->recvFunc(&p->ctx,ip->instPtr,&e) != kOkDspRC )
  516. rc = cmErrMsg(&p->err,kInstMsgRcvFailDspRC,"Message recv failed on DSP instance '%s' id:%i.",ip->instPtr->classPtr->labelStr,ip->instPtr->id);
  517. break;
  518. }
  519. if( ip == NULL )
  520. rc = cmErrMsg(&p->err,kInstNotFoundDspRC,"No DSP instance with id %i was found during message delivery.",h->instId);
  521. return rc;
  522. }
  523. // Recv msg's arriving from the audio engine.
  524. cmDspRC_t cmDspSysRcvMsg( cmDspSysH_t h, cmAudioSysCtx_t* asCtx, const void* msgPtr, unsigned msgByteCnt, unsigned srcNetNodeId )
  525. {
  526. cmDsp_t* p = _cmDspHandleToPtr(h);
  527. _cmDspInst_t* ip = p->instList;
  528. if( msgByteCnt == 0 && asCtx->audioRateFl==true)
  529. {
  530. cmTimeSpec_t t0,t1;
  531. cmTimeGet(&t0);
  532. for(; ip != NULL; ip = ip->linkPtr )
  533. if( ip->instPtr->execFunc != NULL && cmIsFlag(ip->instPtr->flags,kDisableExecInstFl)==false )
  534. {
  535. if( ip->instPtr->execFunc(&p->ctx,ip->instPtr,NULL) != kOkDspRC )
  536. cmErrMsg(&p->err,kInstExecFailDspRC,"Execution failed on DSP instance '%s' id:%i.",ip->instPtr->classPtr->labelStr,ip->instPtr->id);
  537. //printf("%i %s\n",p->ctx.cycleCnt,ip->instPtr->classPtr->labelStr);
  538. }
  539. cmTimeGet(&t1);
  540. p->ctx.execDurUsecs = cmTimeElapsedMicros(&t0,&t1);
  541. ++p->ctx.cycleCnt;
  542. }
  543. else
  544. {
  545. unsigned* hdr = (unsigned*)msgPtr;
  546. // the msg selector is the second field in the data packet (following the audio system sub-system id)
  547. //const unsigned msgTypeSelId = ((const unsigned*)msgPtr)[1];
  548. switch( hdr[1] )
  549. {
  550. case kUiSelAsId:
  551. _cmDspSysHandleUiMsg(p,ip,msgPtr,msgByteCnt);
  552. break;
  553. case kNetSyncSelAsId:
  554. _cmDspSysNetRecv(p, (const cmDspNetMsg_t*)msgPtr, msgByteCnt, srcNetNodeId );
  555. break;
  556. case kMidiMsgArraySelAsId:
  557. {
  558. cmMidiPacket_t pkt;
  559. cmDspValue_t v;
  560. pkt.cbDataPtr = NULL;
  561. pkt.devIdx = hdr[2];
  562. pkt.portIdx = hdr[3];
  563. pkt.msgCnt = hdr[4];
  564. pkt.msgArray = (cmMidiMsg*)(hdr + 5);
  565. unsigned midiSymId = cmDspSysRegisterStaticSymbol(h,"_midi");
  566. // HACK:
  567. v.flags = kMtxDsvFl; // The value is not really a matrix but only _cmDspMidiInRecvFunc()
  568. // ever needs to decode value and it does not look at the value type flags.
  569. v.u.m.u.vp = &pkt;
  570. cmDspSysBroadcastValue(h, midiSymId, &v);
  571. /*
  572. // data format for MIDI messages
  573. { kMidiMsgArraytSelAsId, devIdx, portIdx, msgCnt, msgArray[msgCnt] }
  574. where each msgArray[] record is a cmMidiMsg record.
  575. */
  576. }
  577. break;
  578. }
  579. }
  580. // report any error - this should stop further calls to the DSP process
  581. return cmErrLastRC(&p->err);
  582. }
  583. unsigned cmDspSysSyncState( cmDspSysH_t h )
  584. {
  585. cmDsp_t* p = _cmDspHandleToPtr(h);
  586. return p->syncState;
  587. }
  588. cmDspRC_t cmDspSysPrintPgm( cmDspSysH_t h, const cmChar_t* outFn )
  589. {
  590. cmDsp_t* p = _cmDspHandleToPtr(h);
  591. cmDspRC_t rc = kOkDspRC;
  592. cmJsonH_t jsH = cmJsonNullHandle;
  593. if( cmJsonInitialize(&jsH, &p->cmCtx ) != kOkJsRC )
  594. return cmErrMsg(&p->err,kJsonFailDspRC,"JSON output object create failed.");
  595. // create the root object
  596. cmJsonNode_t* onp = cmJsonCreateObject(jsH,NULL);
  597. assert( onp != NULL );
  598. // create the instance array
  599. cmJsonNode_t* iap = cmJsonInsertPairArray(jsH, cmJsonRoot(jsH), "inst_array" );
  600. assert( iap != NULL );
  601. // create the connection array
  602. cmJsonNode_t* cap = cmJsonInsertPairArray(jsH, cmJsonRoot(jsH), "conn_array" );
  603. assert( cap != NULL );
  604. _cmDspInst_t* dip = p->instList;
  605. for(; dip!=NULL; dip=dip->linkPtr)
  606. {
  607. cmDspInst_t* ip = dip->instPtr;
  608. onp = cmJsonCreateObject(jsH,iap);
  609. if( cmJsonInsertPairs(jsH, onp,
  610. "class", kStringTId, ip->classPtr->labelStr,
  611. "label", kStringTId, cmSymTblLabel(p->ctx.stH,ip->symId),
  612. "id", kIntTId, ip->symId,
  613. NULL ) != kOkJsRC )
  614. {
  615. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON DSP instance create failed.");
  616. goto errLabel;
  617. }
  618. unsigned i;
  619. for(i=0; i<ip->varCnt; ++i)
  620. {
  621. const cmDspVar_t* v = ip->varArray + i;
  622. cmDspCb_t* cp = v->cbList;
  623. for(; cp!=NULL; cp=cp->linkPtr)
  624. {
  625. const cmDspVar_t* dvar = cmDspVarIdToCPtr(cp->dstInstPtr, cp->dstVarId );
  626. onp = cmJsonCreateObject(jsH,cap);
  627. assert(dvar != NULL);
  628. if(cmJsonInsertPairs(jsH,onp,
  629. "sid", kStringTId, cmSymTblLabel(p->ctx.stH,ip->symId),
  630. "svar", kStringTId, cmSymTblLabel(p->ctx.stH,v->symId),
  631. "did", kStringTId, cmSymTblLabel(p->ctx.stH,cp->dstInstPtr->symId),
  632. "dvar", kStringTId, cmSymTblLabel(p->ctx.stH,dvar->symId),
  633. NULL ) != kOkJsRC )
  634. {
  635. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON DSP connect create failed.");
  636. goto errLabel;
  637. }
  638. }
  639. }
  640. }
  641. if( cmJsonWrite(jsH,NULL,outFn) != kOkJsRC )
  642. {
  643. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON file write failed on '%s.",cmStringNullGuard(outFn));
  644. goto errLabel;
  645. }
  646. if( cmJsonFinalize(&jsH) != kOkJsRC )
  647. rc = cmErrMsg(&p->err,kJsonFailDspRC,"JSON tree release failed.");
  648. errLabel:
  649. return rc;
  650. }
  651. unsigned cmDspSysPresetGroupCount( cmDspSysH_t h )
  652. {
  653. cmDsp_t* p = _cmDspHandleToPtr(h);
  654. return _cmDspPresetGroupCount(&p->pm);
  655. }
  656. unsigned cmDspSysPresetGroupSymId( cmDspSysH_t h, unsigned groupIdx )
  657. {
  658. cmDsp_t* p = _cmDspHandleToPtr(h);
  659. return _cmDspPresetGroupSymId(&p->pm,groupIdx);
  660. }
  661. const cmChar_t* cmDspSysPresetGroupLabel( cmDspSysH_t h, unsigned groupIdx )
  662. {
  663. cmDsp_t* p = _cmDspHandleToPtr(h);
  664. return _cmDspPresetGroupLabel(&p->pm,groupIdx);
  665. }
  666. cmDspRC_t cmDspSysPresetGroupJsonList( cmDspSysH_t h, cmJsonH_t* jsHPtr )
  667. {
  668. cmDsp_t* p = _cmDspHandleToPtr(h);
  669. return _cmDspPresetGroupJsonList(&p->pm,jsHPtr);
  670. }
  671. unsigned cmDspSysPresetPresetCount( cmDspSysH_t h, unsigned groupIdx )
  672. {
  673. cmDsp_t* p = _cmDspHandleToPtr(h);
  674. return _cmDspPresetPresetCount(&p->pm,groupIdx);
  675. }
  676. unsigned cmDspSysPresetPresetSymId( cmDspSysH_t h, unsigned groupIdx, unsigned presetIdx )
  677. {
  678. cmDsp_t* p = _cmDspHandleToPtr(h);
  679. return _cmDspPresetPresetSymId(&p->pm,groupIdx,presetIdx);
  680. }
  681. const cmChar_t* cmDspSysPresetPresetLabel( cmDspSysH_t h, unsigned groupIdx, unsigned presetIdx )
  682. {
  683. cmDsp_t* p = _cmDspHandleToPtr(h);
  684. return _cmDspPresetPresetLabel(&p->pm,groupIdx,presetIdx);
  685. }
  686. cmDspRC_t cmDspSysPresetPresetJsonList( cmDspSysH_t h, unsigned groupSymId, cmJsonH_t* jsHPtr )
  687. {
  688. cmDsp_t* p = _cmDspHandleToPtr(h);
  689. return _cmDspPresetPresetJsonList(&p->pm,jsHPtr,groupSymId);
  690. }
  691. unsigned cmDspSysPresetRegisterGroup( cmDspSysH_t h, const cmChar_t* groupLabel )
  692. {
  693. cmDsp_t* p = _cmDspHandleToPtr(h);
  694. assert( groupLabel != NULL );
  695. unsigned grpSymId;
  696. if((grpSymId = cmSymTblRegisterSymbol(p->ctx.stH,groupLabel)) == cmInvalidIdx )
  697. cmErrMsg(&p->err,kSymTblFailDspRC,"Registration of the group label:'%s' failed.",cmStringNullGuard(groupLabel));
  698. return grpSymId;
  699. }
  700. cmDspRC_t cmDspSysPresetCreate( cmDspSysH_t h, const cmChar_t* groupLabel, const cmChar_t* presetLabel )
  701. {
  702. cmDspRC_t rc;
  703. cmDsp_t* p = _cmDspHandleToPtr(h);
  704. // create a new preset and make it active
  705. if((rc = _cmDspPresetCreatePreset(&p->pm, groupLabel, presetLabel )) != kOkDspRC )
  706. return rc;
  707. assert( p->pm.gp != NULL );
  708. // call store on each of the instances
  709. _cmDspInst_t* ip = p->instList;
  710. for(; ip != NULL; ip = ip->linkPtr )
  711. if( ip->instPtr->symId != cmInvalidId && ip->instPtr->presetGroupSymId == p->pm.gp->symId && ip->instPtr->storeFunc != NULL )
  712. {
  713. // create an instance preset and make it active
  714. if((rc = _cmDspPresetCreateInstance(&p->pm, ip->instPtr->symId )) != kOkDspRC )
  715. return rc;
  716. // call the store function on each instance
  717. if( ip->instPtr->storeFunc(&p->ctx,ip->instPtr,true) != kOkDspRC )
  718. rc = cmErrMsg(&p->err,kInstStoreFailDspRC,"Save failed on DSP instance '%s' id:%i.",ip->instPtr->classPtr->labelStr,ip->instPtr->id);
  719. }
  720. return rc;
  721. }
  722. cmDspRC_t cmDspSysPresetRecall( cmDspSysH_t h, const cmChar_t* groupLabel, const cmChar_t* presetLabel )
  723. {
  724. cmDspRC_t rc;
  725. cmDsp_t* p = _cmDspHandleToPtr(h);
  726. // make the given group/preset active
  727. if((rc = _cmDspPresetRecallPreset(&p->pm, groupLabel, presetLabel )) != kOkDspRC )
  728. return rc;
  729. assert( p->pm.gp != NULL );
  730. // call store on each of the instances
  731. _cmDspInst_t* ip = p->instList;
  732. for(; ip != NULL; ip = ip->linkPtr )
  733. if( ip->instPtr->symId != cmInvalidId && ip->instPtr->storeFunc != NULL && ip->instPtr->presetGroupSymId == p->pm.gp->symId )
  734. {
  735. // make the instance active
  736. if((rc = _cmDspPresetRecallInstance(&p->pm, ip->instPtr->symId )) != kOkDspRC )
  737. {
  738. if( rc == kPresetInstNotFoundDspRC )
  739. {
  740. cmErrWarnMsg(&p->err,kOkDspRC,"Assuming a new instance was added to the preset - continuing with preset load.");
  741. continue;
  742. }
  743. }
  744. // call the store function on each instance
  745. if( ip->instPtr->storeFunc(&p->ctx,ip->instPtr,false) != kOkDspRC )
  746. rc = cmErrMsg(&p->err,kInstStoreFailDspRC,"Restore failed on DSP instance '%s' id:%i.",ip->instPtr->classPtr->labelStr,ip->instPtr->id);
  747. }
  748. return rc;
  749. }
  750. cmDspRC_t cmDspSysPresetWriteValue( cmDspSysH_t h, unsigned varSymId, const cmDspValue_t* valPtr )
  751. {
  752. cmDsp_t* p = _cmDspHandleToPtr(h);
  753. return _cmDspPresetCreateVar(&p->pm,varSymId,valPtr);
  754. }
  755. cmDspRC_t cmDspSysPresetReadValue( cmDspSysH_t h, unsigned varSymId, cmDspValue_t* valPtr )
  756. {
  757. cmDsp_t* p = _cmDspHandleToPtr(h);
  758. return _cmDspPresetRecallVar(&p->pm,varSymId,valPtr);
  759. }
  760. // allocate an instance given the class symbol id
  761. cmDspInst_t* _cmDspSysAllocateInst( cmDsp_t* p, unsigned classSymId, unsigned storeSymId, unsigned instSymId, unsigned va_cnt, va_list vl )
  762. {
  763. _cmDspClass_t* cp = p->classList;
  764. cmDspInst_t* instPtr = NULL;
  765. // locate the DSP class
  766. for(; cp != NULL; cp=cp->linkPtr )
  767. if( cp->symId == classSymId )
  768. break;
  769. // if the DSP class was not found
  770. if( cp == NULL )
  771. {
  772. cmErrMsg(&p->err,kClassNotFoundDspRC,"The DSP class '%s' could not be found.",cmSymTblLabel(p->ctx.stH,classSymId));
  773. return NULL;
  774. }
  775. // allocate the instance
  776. if((instPtr = cp->classPtr->allocFunc( &p->ctx, cp->classPtr, storeSymId, instSymId, p->nextInstId, va_cnt, vl )) == NULL )
  777. {
  778. cmErrMsg(&p->err,kAllocInstFailDspRC,"DSP instance allocation failed for class '%s'.",cp->classPtr->labelStr);
  779. return NULL;
  780. }
  781. // assign the symbol attributes
  782. cmDspInstSymId_t* ip = p->symIdList;
  783. for(; ip!=NULL; ip=ip->link)
  784. if( ip->symId != cmInvalidId )
  785. if( cmDspInstRegisterAttrSym(&p->ctx, instPtr, ip->symId ) != kOkDspRC )
  786. {
  787. cmErrMsg(&p->err,kAllocInstFailDspRC,"The DSP instance failed due to attribute symbol registration failure.");
  788. return NULL;
  789. }
  790. // allocate the instance ctl recd
  791. _cmDspInst_t* instCtlPtr = cmLhAllocZ( p->ctx.lhH, _cmDspInst_t, 1 );
  792. assert( instCtlPtr != NULL );
  793. // setup the inst ctl recd
  794. instCtlPtr->instPtr = instPtr;
  795. instCtlPtr->linkPtr = NULL;
  796. // link the inst ctl recd onto the end of the instance list
  797. if( p->instList == NULL )
  798. p->instList = instCtlPtr;
  799. else
  800. {
  801. _cmDspInst_t* ip = p->instList;
  802. while( ip->linkPtr != NULL )
  803. ip = ip->linkPtr;
  804. ip->linkPtr = instCtlPtr;
  805. }
  806. ++p->nextInstId;
  807. return instPtr;
  808. }
  809. // allocate a an instance from the class label - this function calls _cmDspSysAllocateInst()
  810. cmDspInst_t* cmDspSysAllocInstSV( cmDspSysH_t h, const cmChar_t* classLabelStr, unsigned storeSymId, const cmChar_t* instLabelStr, unsigned va_cnt, va_list vl)
  811. {
  812. cmDsp_t* p = _cmDspHandleToPtr(h);
  813. unsigned instSymId = cmInvalidId;
  814. cmDspInst_t* newInstPtr;
  815. unsigned classSymId;
  816. // get the class symbold
  817. if((classSymId = cmSymTblId(p->ctx.stH,classLabelStr)) == cmInvalidId )
  818. {
  819. cmErrMsg(&p->err,kSymNotFoundDspRC,"The symbol id associated with the class '%s' could not be found.",classLabelStr);
  820. return NULL;
  821. }
  822. if( instLabelStr != NULL )
  823. {
  824. // get the symbold id assoc'd with the instance label
  825. if((instSymId = cmSymTblRegisterSymbol(p->ctx.stH,instLabelStr)) == cmInvalidId )
  826. {
  827. cmErrMsg(&p->err,kSymTblFailDspRC,"The DSP instance symbol '%s' failed to register with the symbol table.",instLabelStr);
  828. return NULL;
  829. }
  830. // do not allow instance labels to be re-used
  831. if( _cmDspSysInstSymIdToPtr(p,instSymId) != NULL )
  832. {
  833. cmErrMsg(&p->err,kDuplInstSymIdDspRC,"The DSP instance label '%s' was reused (class:'%s').",cmStringNullGuard(instLabelStr),cmStringNullGuard(classLabelStr));
  834. return NULL;
  835. }
  836. }
  837. // allocate the instance
  838. newInstPtr = _cmDspSysAllocateInst(p, classSymId, storeSymId, instSymId, va_cnt, vl );
  839. return newInstPtr;
  840. }
  841. cmDspInst_t* cmDspSysAllocInstS( cmDspSysH_t h, const cmChar_t* classLabelStr, unsigned storeSymId, const cmChar_t* instLabelStr, unsigned va_cnt, ... )
  842. {
  843. cmDspInst_t* p;
  844. va_list vl;
  845. va_start(vl,va_cnt);
  846. p = cmDspSysAllocInstSV(h, classLabelStr, storeSymId, instLabelStr, va_cnt, vl);
  847. va_end(vl);
  848. return p;
  849. }
  850. cmDspInst_t* cmDspSysAllocInst( cmDspSysH_t h, const cmChar_t* classLabelStr, const cmChar_t* instLabelStr, unsigned va_cnt, ... )
  851. {
  852. cmDspInst_t* p;
  853. va_list vl;
  854. va_start(vl,va_cnt);
  855. p = cmDspSysAllocInstSV(h, classLabelStr, cmInvalidId, instLabelStr, va_cnt, vl);
  856. va_end(vl);
  857. return p;
  858. }
  859. cmDspInst_t** cmDspSysAllocInstArraySV( cmDspSysH_t h, unsigned cnt, unsigned presetGroupSymId, const cmChar_t* classLabelStr, const cmChar_t* instLabelStr, cmDspSysLabelFunc_t labelFunc, unsigned va_cnt, va_list vl )
  860. {
  861. cmDsp_t* p = _cmDspHandleToPtr(h);
  862. cmDspInst_t** a = cmLhAllocZ( p->lhH, cmDspInst_t*, cnt );
  863. unsigned i;
  864. for(i=0; i<cnt; ++i)
  865. {
  866. const cmChar_t* label = instLabelStr;
  867. va_list vl1;
  868. va_copy(vl1,vl);
  869. if( labelFunc != NULL )
  870. label = labelFunc(h,i);
  871. else
  872. if( instLabelStr != NULL )
  873. label = cmDspSysPrintLabel(instLabelStr,i);
  874. a[i] = cmDspSysAllocInstSV(h,classLabelStr,presetGroupSymId,label,va_cnt,vl1);
  875. }
  876. return a;
  877. }
  878. cmDspInst_t** cmDspSysAllocInstArrayS( cmDspSysH_t h, unsigned cnt, unsigned presetGroupSymId, const cmChar_t* classLabelStr, const cmChar_t* instLabelStr, cmDspSysLabelFunc_t labelFunc, unsigned va_cnt, ... )
  879. {
  880. va_list vl;
  881. va_start(vl,va_cnt);
  882. cmDspInst_t** a = cmDspSysAllocInstArraySV(h,cnt,presetGroupSymId,classLabelStr,instLabelStr,labelFunc,va_cnt,vl);
  883. va_end(vl);
  884. return a;
  885. }
  886. cmDspInst_t** cmDspSysAllocInstArray( cmDspSysH_t h, unsigned cnt, const cmChar_t* classLabelStr, const cmChar_t* instLabelStr, cmDspSysLabelFunc_t labelFunc, unsigned va_cnt, ... )
  887. {
  888. va_list vl;
  889. va_start(vl,va_cnt);
  890. cmDspInst_t** a = cmDspSysAllocInstArraySV(h,cnt,cmInvalidId,classLabelStr,instLabelStr,labelFunc,va_cnt,vl);
  891. va_end(vl);
  892. return a;
  893. }
  894. cmDspRC_t cmDspSysNewColumn( cmDspSysH_t h, unsigned colW )
  895. { return cmDspUiNewColumn(&_cmDspHandleToPtr(h)->ctx,colW); }
  896. cmDspRC_t cmDspSysInsertHorzBorder( cmDspSysH_t h )
  897. { return cmDspUiInsertHorzBorder(&_cmDspHandleToPtr(h)->ctx); }
  898. cmDspRC_t cmDspSysNewPage( cmDspSysH_t h, const cmChar_t* title )
  899. { return cmDspUiNewPage(&_cmDspHandleToPtr(h)->ctx,title); }
  900. cmDspRC_t _cmDspSysConnAudio( cmDsp_t* p, cmDspInst_t* srcInstPtr, unsigned srcVarSymId, cmDspInst_t* dstInstPtr, unsigned dstVarSymId )
  901. {
  902. cmDspVar_t* srcVarPtr;
  903. cmDspVar_t* dstVarPtr;
  904. //cmSample_t* srcDataPtr;
  905. if( srcInstPtr == NULL )
  906. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The audio connection process was passed a NULL source processor instance pointer for connection to '%s' Destination Instance:%s.",cmStringNullGuard(dstInstPtr->classPtr->labelStr),cmStringNullGuard(cmSymTblLabel(p->stH,dstInstPtr->symId)));
  907. if( dstInstPtr == NULL )
  908. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The audio connection process was passed a NULL destination processor instance pointer for connection from '%s'.",cmStringNullGuard(srcInstPtr->classPtr->labelStr));
  909. // locate the src audio variable
  910. if((srcVarPtr = cmDspVarSymbolToPtr( &p->ctx, srcInstPtr, srcVarSymId, kOutDsvFl )) == NULL )
  911. return cmErrMsg(&p->err,kVarNotFoundDspRC,"Audio connection failed. The source variable '%s' could not be found in DSP instance '%s' id=%i.", cmStringNullGuard(cmSymTblLabel(p->ctx.stH,srcVarSymId)), cmStringNullGuard(srcInstPtr->classPtr->labelStr),srcInstPtr->id);
  912. // validate the src variable type
  913. if( cmIsFlag(srcVarPtr->flags,kAudioBufDsvFl) == false )
  914. return cmErrMsg(&p->err,kVarTypeErrDspRC,"Audio connection failed. The source variable '%s' in '%s' id=%i was not an audio variable.", cmStringNullGuard(cmSymTblLabel(p->ctx.stH,srcVarSymId)), cmStringNullGuard(srcInstPtr->classPtr->labelStr),srcInstPtr->id);
  915. // locate the dst audio variable
  916. if((dstVarPtr = cmDspVarSymbolToPtr( &p->ctx, dstInstPtr, dstVarSymId, kInDsvFl )) == NULL )
  917. return cmErrMsg(&p->err,kVarNotFoundDspRC,"Audio connection failed. The destination variable '%s' could not be found in DSP instance '%s' id=%i.", cmStringNullGuard(cmSymTblLabel(p->ctx.stH,dstVarSymId)), cmStringNullGuard(dstInstPtr->classPtr->labelStr),dstInstPtr->id);
  918. // validate the dst variable type
  919. if( cmIsFlag(dstVarPtr->flags,kAudioBufDsvFl) == false )
  920. return cmErrMsg(&p->err,kVarTypeErrDspRC,"Audio connection failed. The destination variable '%s' in '%s' id=%i was not an audio variable.", cmStringNullGuard(cmSymTblLabel(p->ctx.stH,dstVarSymId)), cmStringNullGuard(dstInstPtr->classPtr->labelStr),dstInstPtr->id);
  921. // get a pointer to the source sample buffer
  922. //if( (srcDataPtr = cmDsvSampleMtx( &srcVarPtr->value )) == NULL )
  923. // return cmErrMsg(&p->err,kVarNotValidDspRC,"Audio connection failed. The audio source variable '%s' in '%s' id=%i has not been allocated.",cmSymTblLabel(p->ctx.stH,srcVarSymId), srcInstPtr->classPtr->labelStr,srcInstPtr->id);
  924. // set the destination sample buffer to point to the source sample buffer.
  925. //cmDsvSetSampleMtx( &dstVarPtr->value, srcDataPtr, cmDsvRows(&srcVarPtr->value), cmDsvCols(&srcVarPtr->value));
  926. cmDsvSetProxy( &dstVarPtr->value, &srcVarPtr->value );
  927. return kOkDspRC;
  928. }
  929. cmDspRC_t cmDspSysConnectAudio( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarLbl, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarLbl )
  930. {
  931. cmDsp_t* p = _cmDspHandleToPtr(h);
  932. unsigned srcSymId, dstSymId;
  933. if( srcInstPtr == NULL && dstInstPtr == NULL )
  934. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The audio connection process was passed a NULL source and destination processor instance.");
  935. if( srcInstPtr == NULL )
  936. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The audio connection process was passed a NULL source processor instance pointer for connection to '%s' Destination Instance:%s.",cmStringNullGuard(dstInstPtr->classPtr->labelStr),cmStringNullGuard(cmSymTblLabel(p->stH,dstInstPtr->symId)));
  937. if( dstInstPtr == NULL )
  938. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The audio connection process was passed a NULL destination processor instance pointer for connection from '%s'.",cmStringNullGuard(srcInstPtr->classPtr->labelStr));
  939. if((srcSymId = cmSymTblId(p->ctx.stH,srcVarLbl)) == cmInvalidId )
  940. return cmErrMsg(&p->err,kSymNotFoundDspRC,"Audio connection failed. The source variable symbol '%s' for source DSP instance '%s' id=%i could not be found.",cmStringNullGuard(srcVarLbl),cmStringNullGuard(srcInstPtr->classPtr->labelStr),srcInstPtr->id);
  941. if((dstSymId = cmSymTblId(p->ctx.stH,dstVarLbl)) == cmInvalidId )
  942. return cmErrMsg(&p->err,kSymNotFoundDspRC,"Audio connection failed. The destination variable symbol '%s' for source DSP instance '%s' id=%i could not be found.",cmStringNullGuard(dstVarLbl),cmStringNullGuard(dstInstPtr->classPtr->labelStr),dstInstPtr->id);
  943. return _cmDspSysConnAudio(p,srcInstPtr,srcSymId,dstInstPtr,dstSymId);
  944. }
  945. cmDspRC_t cmDspSysConnectAudioN11N( cmDspSysH_t h, cmDspInst_t* srcInstArray[], const cmChar_t* srcVarLabel, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarPrefixStr, unsigned n )
  946. {
  947. cmDspRC_t rc = kOkDspRC;
  948. unsigned i;
  949. for(i=0; i<n; ++i)
  950. {
  951. const cmChar_t* dstVarStr = dstVarPrefixStr;
  952. if( n >= 2 )
  953. dstVarStr = cmDspSysPrintLabel(dstVarPrefixStr,i);
  954. if((rc = cmDspSysConnectAudio( h, srcInstArray[i], srcVarLabel, dstInstPtr, dstVarStr )) != kOkDspRC )
  955. break;
  956. }
  957. return rc;
  958. }
  959. cmDspRC_t cmDspSysConnectAudio1NN1( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, cmDspInst_t* dstInstArray[], const cmChar_t* dstVarLabel, unsigned n )
  960. {
  961. cmDspRC_t rc = kOkDspRC;
  962. unsigned i;
  963. for(i=0; i<n; ++i)
  964. {
  965. const cmChar_t* label = srcVarPrefixStr;
  966. if( n >= 2 )
  967. label = cmDspSysPrintLabel(srcVarPrefixStr,i);
  968. if((rc = cmDspSysConnectAudio( h, srcInstPtr, label, dstInstArray[i], dstVarLabel )) != kOkDspRC )
  969. break;
  970. }
  971. return rc;
  972. }
  973. cmDspRC_t cmDspSysConnectAudio1N1N( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarPrefixStr, unsigned n )
  974. {
  975. cmDspRC_t rc = kOkDspRC;
  976. unsigned i;
  977. for(i=0; i<n; ++i)
  978. {
  979. const cmChar_t* label0 = cmDspSysPrintLabel(srcVarPrefixStr,i);
  980. const cmChar_t* label1 = cmDspSysPrintLabel2(dstVarPrefixStr,i);
  981. if((rc = cmDspSysConnectAudio( h, srcInstPtr, label0, dstInstPtr, label1 )) != kOkDspRC )
  982. break;
  983. }
  984. return rc;
  985. }
  986. cmDspRC_t cmDspSysConnectAudioN1N1( cmDspSysH_t h, cmDspInst_t* srcInstArray[], const cmChar_t* srcVarLabel, cmDspInst_t* dstInstArray[], const cmChar_t* dstVarLabel, unsigned n )
  987. {
  988. cmDspRC_t rc = kOkDspRC;
  989. unsigned i;
  990. for(i=0; i<n; ++i)
  991. {
  992. if((rc = cmDspSysConnectAudio( h, srcInstArray[i], srcVarLabel, dstInstArray[i], dstVarLabel )) != kOkDspRC )
  993. break;
  994. }
  995. return rc;
  996. }
  997. cmDspRC_t cmDspSysConnectAudio11N1( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarLabel, cmDspInst_t* dstInstArray[],const cmChar_t* dstVarLabel, unsigned n )
  998. {
  999. cmDspRC_t rc = kOkDspRC;
  1000. unsigned i;
  1001. for(i=0; i<n; ++i)
  1002. {
  1003. if((rc = cmDspSysConnectAudio( h, srcInstPtr, srcVarLabel, dstInstArray[i], dstVarLabel )) != kOkDspRC )
  1004. break;
  1005. }
  1006. return rc;
  1007. }
  1008. cmDspRC_t cmDspSysConnectAudio111N( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarLabel, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarLabel, unsigned n )
  1009. {
  1010. cmDspRC_t rc = kOkDspRC;
  1011. unsigned i;
  1012. for(i=0; i<n; ++i)
  1013. {
  1014. const cmChar_t* label1 = cmDspSysPrintLabel(dstVarLabel,i);
  1015. const cmChar_t* label = n>1 ? label1 : dstVarLabel;
  1016. if((rc = cmDspSysConnectAudio( h, srcInstPtr, srcVarLabel, dstInstPtr, label )) != kOkDspRC )
  1017. break;
  1018. }
  1019. return rc;
  1020. }
  1021. cmDspRC_t cmDspSysConnectAudioN11NM( cmDspSysH_t h, cmDspInst_t* srcInstArray[], const cmChar_t* srcVarLabel, unsigned srcCnt, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarPrefixStr, unsigned dstCnt, const unsigned* map )
  1022. {
  1023. cmDsp_t* p = _cmDspHandleToPtr(h);
  1024. cmDspRC_t rc = kOkDspRC;
  1025. unsigned i;
  1026. for(i=0; i<dstCnt; ++i)
  1027. {
  1028. const cmChar_t* dstVarStr = dstVarPrefixStr;
  1029. if( dstCnt >= 2 )
  1030. dstVarStr = cmDspSysPrintLabel(dstVarPrefixStr,i);
  1031. if( map[i] >= srcCnt )
  1032. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The source instance map connection index %i is of range %i.",i,srcCnt);
  1033. if((rc = cmDspSysConnectAudio( h, srcInstArray[ map[i] ], srcVarLabel, dstInstPtr, dstVarStr )) != kOkDspRC )
  1034. break;
  1035. }
  1036. return rc;
  1037. }
  1038. cmDspRC_t cmDspSysInstallCb( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarLabel, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarLabel, void* dstCbDataPtr)
  1039. {
  1040. cmDsp_t* p = _cmDspHandleToPtr(h);
  1041. return cmDspInstallCb(&p->ctx,srcInstPtr,srcVarLabel,dstInstPtr,dstVarLabel,dstCbDataPtr);
  1042. }
  1043. cmDspRC_t cmDspSysInstallCbN11N( cmDspSysH_t h, cmDspInst_t* srcInstArray[], const cmChar_t* srcVarLabel, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarPrefixStr, unsigned n )
  1044. {
  1045. cmDspRC_t rc = kOkDspRC;
  1046. unsigned i;
  1047. for(i=0; i<n; ++i)
  1048. {
  1049. const cmChar_t* dstVarStr = dstVarPrefixStr;
  1050. if( n >= 2 )
  1051. dstVarStr = cmDspSysPrintLabel(dstVarPrefixStr,i);
  1052. if((rc = cmDspSysInstallCb( h, srcInstArray[i], srcVarLabel, dstInstPtr, dstVarStr, NULL )) != kOkDspRC )
  1053. break;
  1054. }
  1055. return rc;
  1056. }
  1057. cmDspRC_t cmDspSysInstallCb1NN1( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, cmDspInst_t* dstInstArray[], const cmChar_t* dstVarLabel, unsigned n )
  1058. {
  1059. cmDspRC_t rc = kOkDspRC;
  1060. unsigned i;
  1061. for(i=0; i<n; ++i)
  1062. {
  1063. const cmChar_t* srcVarStr = srcVarPrefixStr;
  1064. if( n >= 2 )
  1065. srcVarStr = cmDspSysPrintLabel(srcVarPrefixStr,i);
  1066. if((rc = cmDspSysInstallCb( h, srcInstPtr, srcVarStr, dstInstArray[i], dstVarLabel, NULL )) != kOkDspRC )
  1067. break;
  1068. }
  1069. return rc;
  1070. }
  1071. cmDspRC_t cmDspSysInstallCb1N1N( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarPrefixStr, unsigned n )
  1072. {
  1073. cmDspRC_t rc = kOkDspRC;
  1074. unsigned i;
  1075. for(i=0; i<n; ++i)
  1076. {
  1077. const cmChar_t* label0 = srcVarPrefixStr;
  1078. const cmChar_t* label1 = dstVarPrefixStr;
  1079. if( n >= 2 )
  1080. {
  1081. label0 = cmDspSysPrintLabel(srcVarPrefixStr,i);
  1082. label1 = cmDspSysPrintLabel2(dstVarPrefixStr,i);
  1083. }
  1084. if((rc = cmDspSysInstallCb( h, srcInstPtr, label0, dstInstPtr, label1, NULL )) != kOkDspRC )
  1085. break;
  1086. }
  1087. return rc;
  1088. }
  1089. cmDspRC_t cmDspSysInstallCbN1N1( cmDspSysH_t h, cmDspInst_t* srcInstArray[], const cmChar_t* srcVarLabel, cmDspInst_t* dstInstArray[], const cmChar_t* dstVarLabel, unsigned n )
  1090. {
  1091. cmDspRC_t rc = kOkDspRC;
  1092. unsigned i;
  1093. for(i=0; i<n; ++i)
  1094. {
  1095. if((rc = cmDspSysInstallCb( h, srcInstArray[i], srcVarLabel, dstInstArray[i], dstVarLabel, NULL )) != kOkDspRC )
  1096. break;
  1097. }
  1098. return rc;
  1099. }
  1100. cmDspRC_t cmDspSysInstallCb11N1( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarLabel, cmDspInst_t* dstInstArray[], const cmChar_t* dstVarLabel, unsigned n )
  1101. {
  1102. cmDspRC_t rc = kOkDspRC;
  1103. unsigned i;
  1104. for(i=0; i<n; ++i)
  1105. {
  1106. if((rc = cmDspSysInstallCb( h, srcInstPtr, srcVarLabel, dstInstArray[i], dstVarLabel, NULL )) != kOkDspRC )
  1107. break;
  1108. }
  1109. return rc;
  1110. }
  1111. cmDspRC_t cmDspSysInstallCb111N( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarLabel, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarPrefixLabel, unsigned n )
  1112. {
  1113. cmDspRC_t rc = kOkDspRC;
  1114. unsigned i;
  1115. for(i=0; i<n; ++i)
  1116. {
  1117. const cmChar_t* dstVarStr = dstVarPrefixLabel;
  1118. if( n >= 2 )
  1119. dstVarStr = cmDspSysPrintLabel(dstVarPrefixLabel,i);
  1120. if((rc = cmDspSysInstallCb( h, srcInstPtr, srcVarLabel, dstInstPtr, dstVarStr, NULL )) != kOkDspRC )
  1121. break;
  1122. }
  1123. return rc;
  1124. }
  1125. cmDspRC_t cmDspSysInstallCbN111( cmDspSysH_t h, cmDspInst_t* srcInstArray[], const cmChar_t* srcVarLabel, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarLabel, unsigned n )
  1126. {
  1127. cmDspRC_t rc = kOkDspRC;
  1128. unsigned i;
  1129. for(i=0; i<n; ++i)
  1130. {
  1131. if((rc = cmDspSysInstallCb( h, srcInstArray[i], srcVarLabel, dstInstPtr, dstVarLabel, NULL )) != kOkDspRC )
  1132. break;
  1133. }
  1134. return rc;
  1135. }
  1136. cmDspRC_t cmDspSysInstallCb1N11( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixLabel, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarLabel, unsigned n )
  1137. {
  1138. cmDspRC_t rc = kOkDspRC;
  1139. unsigned i;
  1140. for(i=0; i<n; ++i)
  1141. {
  1142. const cmChar_t* srcVarStr = srcVarPrefixLabel;
  1143. if( n >= 2 )
  1144. srcVarStr = cmDspSysPrintLabel(srcVarPrefixLabel,i);
  1145. if((rc = cmDspSysInstallCb( h, srcInstPtr, srcVarStr, dstInstPtr, dstVarLabel, NULL )) != kOkDspRC )
  1146. break;
  1147. }
  1148. return rc;
  1149. }
  1150. cmDspRC_t cmDspSysInstallCb1N1NM( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, unsigned srcCnt, cmDspInst_t* dstInstPtr, const cmChar_t* dstVarPrefixStr, unsigned dstCnt, const unsigned* map )
  1151. {
  1152. cmDsp_t* p = _cmDspHandleToPtr(h);
  1153. cmDspRC_t rc = kOkDspRC;
  1154. unsigned i;
  1155. for(i=0; i<dstCnt; ++i)
  1156. {
  1157. const cmChar_t* label0 = srcVarPrefixStr;
  1158. const cmChar_t* label1 = dstVarPrefixStr;
  1159. if( map[i] >= srcCnt )
  1160. {
  1161. if( map[i] >= srcCnt )
  1162. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The source instance map connection index %i is of range %i.",i,srcCnt);
  1163. }
  1164. if( srcCnt >= 2 )
  1165. label0 = cmDspSysPrintLabel(srcVarPrefixStr,map[i]);
  1166. if( dstCnt >= 2 )
  1167. label1 = cmDspSysPrintLabel2(dstVarPrefixStr,i);
  1168. if((rc = cmDspSysInstallCb( h, srcInstPtr, label0, dstInstPtr, label1, NULL )) != kOkDspRC )
  1169. break;
  1170. }
  1171. return rc;
  1172. }
  1173. cmDspRC_t cmDspSysInstallCb1NN1M( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, unsigned srcCnt, cmDspInst_t* dstInstArray[], const cmChar_t* dstVarLabel, unsigned dstCnt, const unsigned* map )
  1174. {
  1175. cmDsp_t* p = _cmDspHandleToPtr(h);
  1176. cmDspRC_t rc = kOkDspRC;
  1177. unsigned i;
  1178. for(i=0; i<dstCnt; ++i)
  1179. {
  1180. if( map[i] >= srcCnt )
  1181. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The source instance map connection index %i is of range %i.",i,srcCnt);
  1182. const cmChar_t* srcVarStr = srcVarPrefixStr;
  1183. if( srcCnt >= 2 )
  1184. srcVarStr = cmDspSysPrintLabel(srcVarPrefixStr,map[i]);
  1185. if((rc = cmDspSysInstallCb( h, srcInstPtr, srcVarStr, dstInstArray[i], dstVarLabel, NULL )) != kOkDspRC )
  1186. break;
  1187. }
  1188. return rc;
  1189. }
  1190. cmDspRC_t cmDspSysInstallCb1NN1M2( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, unsigned srcCnt, const unsigned* map, cmDspInst_t* dstInstArray[], const cmChar_t* dstVarLabel, unsigned dstCnt )
  1191. {
  1192. cmDsp_t* p = _cmDspHandleToPtr(h);
  1193. cmDspRC_t rc = kOkDspRC;
  1194. unsigned i;
  1195. for(i=0; i<srcCnt; ++i)
  1196. {
  1197. if( map[i] >= dstCnt )
  1198. return cmErrMsg(&p->err,kInstNotFoundDspRC,"The dest. instance map connection index %i is of range %i.",map[i],dstCnt);
  1199. const cmChar_t* srcVarStr = srcVarPrefixStr;
  1200. if( srcCnt >= 2 )
  1201. srcVarStr = cmDspSysPrintLabel(srcVarPrefixStr,i);
  1202. if((rc = cmDspSysInstallCb( h, srcInstPtr, srcVarStr, dstInstArray[ map[i] ], dstVarLabel, NULL )) != kOkDspRC )
  1203. break;
  1204. }
  1205. return rc;
  1206. }
  1207. double cmDspSysSampleRate( cmDspSysH_t h )
  1208. {
  1209. cmDsp_t* p = _cmDspHandleToPtr(h);
  1210. return p->ctx.ctx->ss->args.srate;
  1211. }
  1212. cmJsonH_t cmDspSysPgmRsrcHandle( cmDspSysH_t h )
  1213. {
  1214. cmDsp_t* p = _cmDspHandleToPtr(h);
  1215. return p->ctx.rsrcJsH;
  1216. }
  1217. cmSymTblH_t cmDspSysSymbolTable( cmDspSysH_t h )
  1218. {
  1219. cmDsp_t* p = _cmDspHandleToPtr(h);
  1220. return p->ctx.stH;
  1221. }
  1222. cmSeH_t cmDspSysSerialPort( cmDspSysH_t h )
  1223. {
  1224. cmDsp_t* p = _cmDspHandleToPtr(h);
  1225. return p->serialPortH;
  1226. }
  1227. unsigned cmDspSysRegisterStaticSymbol( cmDspSysH_t h, const cmChar_t* symLabel )
  1228. { return cmSymTblRegisterStaticSymbol( cmDspSysSymbolTable(h), symLabel ); }
  1229. unsigned cmDspSysRegisterSymbol( cmDspSysH_t h, const cmChar_t* symLabel )
  1230. { return cmSymTblRegisterSymbol( cmDspSysSymbolTable(h), symLabel); }
  1231. cmCtx_t* cmDspSysPgmCtx( cmDspSysH_t h )
  1232. {
  1233. cmDsp_t* p = _cmDspHandleToPtr(h);
  1234. return &p->cmCtx;
  1235. }
  1236. cmLHeapH_t cmDspSysLHeap( cmDspSysH_t h )
  1237. {
  1238. cmDsp_t* p = _cmDspHandleToPtr(h);
  1239. return p->lhH;
  1240. }
  1241. unsigned cmDspSysNetNodeId( cmDspSysH_t h )
  1242. {
  1243. cmDsp_t* p = _cmDspHandleToPtr(h);
  1244. return cmUdpNetLocalNodeId(p->netH);
  1245. }
  1246. const cmChar_t* cmDspSysNetNodeLabel( cmDspSysH_t h )
  1247. {
  1248. cmDsp_t* p = _cmDspHandleToPtr(h);
  1249. return cmUdpNetLocalNodeLabel(p->netH);
  1250. }
  1251. const cmChar_t* cmDspSysNetNodeIdToLabel( cmDspSysH_t h, unsigned netNodeId )
  1252. {
  1253. cmDsp_t* p = _cmDspHandleToPtr(h);
  1254. return cmUdpNetNodeIdToLabel(p->netH,netNodeId);
  1255. }
  1256. unsigned cmDspSysNetNodeLabelToId( cmDspSysH_t h, const cmChar_t* netNodeLabel )
  1257. {
  1258. cmDsp_t* p = _cmDspHandleToPtr(h);
  1259. return cmUdpNetNodeLabelToId(p->netH,netNodeLabel);
  1260. }
  1261. cmDspInstSymId_t* _cmDspSysFindInstSymId( cmDsp_t* p, unsigned symId )
  1262. {
  1263. cmDspInstSymId_t* ip = p->symIdList;
  1264. for(; ip != NULL; ip=ip->link)
  1265. if( ip->symId == symId )
  1266. return ip;
  1267. return NULL;
  1268. }
  1269. unsigned cmDspSysRegisterInstAttrSymbol( cmDspSysH_t h, unsigned symId )
  1270. {
  1271. cmDsp_t* p = _cmDspHandleToPtr(h);
  1272. cmDspInstSymId_t* ip;
  1273. // if this symbol is already registered
  1274. if((ip = _cmDspSysFindInstSymId(p,symId)) != NULL )
  1275. return ip->symId;
  1276. // try to find an unused symbol
  1277. ip = p->symIdList;
  1278. for(; ip != NULL; ip=ip->link)
  1279. if( ip->symId == cmInvalidId )
  1280. break;
  1281. // if no unused symbols were found then allocate a new one
  1282. if( ip == NULL )
  1283. {
  1284. ip = cmLhAllocZ(p->ctx.lhH, cmDspInstSymId_t, 1 );
  1285. ip->link = p->symIdList;
  1286. p->symIdList = ip;
  1287. }
  1288. ip->symId = symId;
  1289. return ip->symId;
  1290. }
  1291. unsigned cmDspSysRegisterInstAttrSymbolStr( cmDspSysH_t h, const cmChar_t* symLabel )
  1292. {
  1293. cmDsp_t* p = _cmDspHandleToPtr(h);
  1294. unsigned symId;
  1295. if((symId = cmSymTblRegisterSymbol(p->ctx.stH,symLabel)) == cmInvalidId )
  1296. return cmErrMsg(&p->err,kSymTblFailDspRC,"The instance attribute symbol '%s' could not be registered.",cmStringNullGuard(symLabel));
  1297. return cmDspSysRegisterInstAttrSymbol(h,symId);
  1298. }
  1299. cmDspRC_t cmDspSysAssignInstAttrSymbol( cmDspSysH_t h, cmDspInst_t* inst, unsigned symId )
  1300. {
  1301. cmDsp_t* p = _cmDspHandleToPtr(h);
  1302. return cmDspInstRegisterAttrSym(&p->ctx, inst, symId) != kOkDspRC;
  1303. }
  1304. unsigned cmDspSysAssignInstAttrSymbolStr( cmDspSysH_t h, cmDspInst_t* inst, const cmChar_t* symLabel )
  1305. {
  1306. unsigned symId = cmDspSysRegisterSymbol(h,symLabel);
  1307. if( cmDspSysAssignInstAttrSymbol( h, inst, symId) != kOkDspRC )
  1308. return cmInvalidId;
  1309. return symId;
  1310. }
  1311. cmDspRC_t cmDspSysRemoveInstAttrSymbol( cmDspSysH_t h, unsigned symId )
  1312. {
  1313. cmDsp_t* p = _cmDspHandleToPtr(h);
  1314. cmDspInstSymId_t* ip;
  1315. // if this symbol is already registered
  1316. if((ip = _cmDspSysFindInstSymId(p,symId)) == NULL )
  1317. return cmErrMsg(&p->err,kOkDspRC,"The instance attribute symbol '%s' is could not be found to be removed.",cmStringNullGuard(cmSymTblLabel(p->ctx.stH,symId)));
  1318. // mark a symbol recd as inactive by setting the symbol id to cmInalidId
  1319. ip->symId = cmInvalidId;
  1320. return kOkDspRC;
  1321. }
  1322. cmDspRC_t cmDspSysRemoveInstAttrSymbolStr( cmDspSysH_t h, const cmChar_t* symLabel )
  1323. {
  1324. cmDsp_t* p = _cmDspHandleToPtr(h);
  1325. unsigned symId;
  1326. if( (symId = cmSymTblId(p->ctx.stH, symLabel )) == cmInvalidId )
  1327. return cmErrMsg(&p->err,kSymNotFoundDspRC,"The instance attribute symbol '%s' does not exist and therefore cannot be removed.",cmStringNullGuard(symLabel));
  1328. return cmDspSysRemoveInstAttrSymbol(h, symId );
  1329. }
  1330. cmDspRC_t cmDspSysBroadcastValue( cmDspSysH_t h, unsigned instAttrSymId, const cmDspValue_t* valuePtr )
  1331. {
  1332. cmDsp_t* p = _cmDspHandleToPtr(h);
  1333. _cmDspInst_t* ip = p->instList;
  1334. for(; ip != NULL; ip = ip->linkPtr )
  1335. if( (instAttrSymId==cmInvalidId) || cmDspInstHasAttrSym(ip->instPtr,instAttrSymId))
  1336. ip->instPtr->sysRecvFunc(&p->ctx,ip->instPtr,instAttrSymId,valuePtr);
  1337. return kOkDspRC;
  1338. }
  1339. cmDspInst_t* cmDspSysAllocLabel( cmDspSysH_t h, const cmChar_t* label, unsigned alignId )
  1340. {
  1341. return cmDspSysAllocInst(h,"Label", NULL, 2, label, alignId);
  1342. }
  1343. cmDspRC_t _cmDspGetRsrcReal( cmDspSysH_t h, const cmChar_t* label, const cmChar_t* rsrcPath, cmReal_t* valPtr )
  1344. {
  1345. const cmChar_t* errLabelPtr = NULL;
  1346. if( cmJsonPathValues( cmDspSysPgmRsrcHandle(h),NULL,NULL,&errLabelPtr, rsrcPath, kRealTId, valPtr, NULL ) != kOkJsRC )
  1347. {
  1348. cmDsp_t* p = _cmDspHandleToPtr(h);
  1349. return cmErrMsg(&p->err,kRsrcNotFoundDspRC,"DSP instance allocation failed for '%s' and the initial value resource path '%s'.", cmStringNullGuard(label),cmStringNullGuard(rsrcPath));
  1350. }
  1351. return kOkDspRC;
  1352. }
  1353. cmDspInst_t* _cmDspSysAllocScalar( cmDspSysH_t h, unsigned presetGrpSymId, const cmChar_t* instLabel, cmReal_t min, cmReal_t max, cmReal_t step, cmReal_t val, const cmChar_t* label )
  1354. {
  1355. cmDspInst_t* inst;
  1356. if((inst = cmDspSysAllocInstS(h,"Scalar", presetGrpSymId, instLabel, 6, kNumberDuiId, min, max, step, val, label )) == NULL)
  1357. {
  1358. cmDsp_t* p = _cmDspHandleToPtr(h);
  1359. cmErrMsg(&p->err,kAllocInstFailDspRC,"Scalar UI control allocation failed for '%s'.", cmStringNullGuard(instLabel));
  1360. }
  1361. return inst;
  1362. }
  1363. cmDspInst_t* cmDspSysAllocScalar( cmDspSysH_t h, const cmChar_t* label, cmReal_t min, cmReal_t max, cmReal_t step, cmReal_t val )
  1364. { return _cmDspSysAllocScalar(h,cmInvalidId,label,min,max,step,val,label); }
  1365. cmChar_t* _cmDspSysFormLabel( cmDspSysH_t h, unsigned presetGrpSymId, const cmChar_t* prefixLabel, const cmChar_t* label )
  1366. {
  1367. cmDsp_t* p = _cmDspHandleToPtr(h);
  1368. if( prefixLabel == NULL )
  1369. {
  1370. if(( prefixLabel = cmSymTblLabel(p->ctx.stH,presetGrpSymId)) == NULL )
  1371. cmErrMsg(&p->err,kInvalidArgDspRC,"The prefix label was not given for the DSP instance '%s'.",cmStringNullGuard(label));
  1372. }
  1373. if( label == NULL )
  1374. cmErrMsg(&p->err,kInvalidArgDspRC,"NULL was passed where a DSP instance label was expected.");
  1375. return cmTsPrintfH(cmDspSysLHeap(h),"%s-%s",cmStringNullGuard(prefixLabel),cmStringNullGuard(label));
  1376. }
  1377. cmDspInst_t* cmDspSysAllocScalarP( cmDspSysH_t h, unsigned presetGrpSymId, const cmChar_t* prefixLabel, const cmChar_t* label, cmReal_t min, cmReal_t max, cmReal_t step, cmReal_t val )
  1378. {
  1379. return _cmDspSysAllocScalar(h,presetGrpSymId,_cmDspSysFormLabel(h,presetGrpSymId,prefixLabel,label),min,max,step,val,label);
  1380. }
  1381. cmDspInst_t* cmDspSysAllocScalarRsrc( cmDspSysH_t h, const cmChar_t* label, cmReal_t min, cmReal_t max, cmReal_t step, const cmChar_t* rsrcPath )
  1382. {
  1383. cmReal_t val;
  1384. if(_cmDspGetRsrcReal(h,label,rsrcPath,&val ) != kOkDspRC )
  1385. return NULL;
  1386. return cmDspSysAllocScalar(h,label,min,max,step,val);
  1387. }
  1388. cmDspInst_t** cmDspSysAllocScalarA( cmDspSysH_t h, unsigned cnt, unsigned presetGroupSymId, const cmChar_t* prefixLabel, const cmChar_t* label, cmReal_t min, cmReal_t max, cmReal_t step, cmReal_t val )
  1389. {
  1390. cmChar_t* lbl = cmTsPrintfH( cmDspSysLHeap(h), "%s-%s",prefixLabel,label);
  1391. return cmDspSysAllocInstArrayS( h, cnt, presetGroupSymId, "Scalar", lbl, NULL, 5, kNumberDuiId, min, max, step, val);
  1392. }
  1393. cmDspInst_t* _cmDspSysAllocButton( cmDspSysH_t h, unsigned btnTypeId, unsigned presetGroupSymId, const cmChar_t* instLabel, const cmChar_t* label, cmReal_t val, unsigned valSymId )
  1394. {
  1395. cmDspInst_t* inst;
  1396. if((inst = cmDspSysAllocInstS( h, "Button", presetGroupSymId, instLabel, 4, btnTypeId, val, valSymId, label)) == NULL )
  1397. {
  1398. cmDsp_t* p = _cmDspHandleToPtr(h);
  1399. cmErrMsg(&p->err,kAllocInstFailDspRC,"Button UI control allocation failed for '%s'.", cmStringNullGuard(label));
  1400. }
  1401. return inst;
  1402. }
  1403. cmDspInst_t* cmDspSysAllocButtonP( cmDspSysH_t h, const cmChar_t* prefixLabel, const cmChar_t* label, cmReal_t val )
  1404. {
  1405. return cmDspSysAllocButton(h,_cmDspSysFormLabel(h,cmInvalidId,prefixLabel,label),val);
  1406. }
  1407. cmDspInst_t* _cmDspSysAllocButtonRsrc( cmDspSysH_t h, unsigned typeId, unsigned presetGroupSymId, const cmChar_t* label, const cmChar_t* rsrcPath )
  1408. {
  1409. cmReal_t val;
  1410. if(_cmDspGetRsrcReal(h,label,rsrcPath,&val) != kOkDspRC )
  1411. return NULL;
  1412. return _cmDspSysAllocButton(h,typeId,presetGroupSymId,label,label,val,cmInvalidId);
  1413. }
  1414. cmDspInst_t* cmDspSysAllocButton( cmDspSysH_t h, const cmChar_t* label, cmReal_t val )
  1415. { return _cmDspSysAllocButton(h,kButtonDuiId,cmInvalidId,label,label,val,cmInvalidId); }
  1416. cmDspInst_t* cmDspSysAllocButtonRsrc( cmDspSysH_t h, const cmChar_t* label, const cmChar_t* rsrcPath )
  1417. { return _cmDspSysAllocButtonRsrc( h,kButtonDuiId,cmInvalidId,label,rsrcPath); }
  1418. cmDspInst_t* _cmDspSysAllocCheck( cmDspSysH_t h, unsigned presetGroupSymId, const cmChar_t* instLabel, const cmChar_t* label, cmReal_t val )
  1419. { return _cmDspSysAllocButton(h,kCheckDuiId,presetGroupSymId,instLabel,label,val,cmInvalidId); }
  1420. cmDspInst_t* cmDspSysAllocCheck( cmDspSysH_t h, const cmChar_t* label, cmReal_t val )
  1421. { return _cmDspSysAllocCheck(h,cmInvalidId,label,label,val); }
  1422. cmDspInst_t* cmDspSysAllocCheckP( cmDspSysH_t h, unsigned presetGroupSymId, const cmChar_t* prefixLabel, const cmChar_t* label, cmReal_t val )
  1423. { return _cmDspSysAllocCheck(h,presetGroupSymId,_cmDspSysFormLabel(h,presetGroupSymId,prefixLabel,label),label,val); }
  1424. cmDspInst_t* cmDspSysAllocCheckRsrc( cmDspSysH_t h, const cmChar_t* label, const cmChar_t* rsrcPath )
  1425. { return _cmDspSysAllocButtonRsrc( h,kCheckDuiId, cmInvalidId, label,rsrcPath); }
  1426. cmDspInst_t* cmDspSysAllocMsgList( cmDspSysH_t h, const cmChar_t* fn, const cmChar_t* rsrcLabel, unsigned initSelIdx )
  1427. { return cmDspSysAllocInst( h, "MsgList", NULL, 3, rsrcLabel, fn, initSelIdx); }
  1428. cmDspInst_t* cmDspSysAllocMsgListP( cmDspSysH_t h, unsigned presetGroupSymId, const cmChar_t* preLabel, const cmChar_t* label, const cmChar_t* fn, const cmChar_t* rsrcLabel, unsigned initSelIdx )
  1429. {
  1430. cmDspInst_t* inst;
  1431. cmChar_t* lbl;
  1432. if((inst = cmDspSysAllocInstS( h, "MsgList", presetGroupSymId, lbl = _cmDspSysFormLabel(h,presetGroupSymId,preLabel,label), 3, rsrcLabel, fn, initSelIdx)) == NULL )
  1433. {
  1434. cmDsp_t* p = _cmDspHandleToPtr(h);
  1435. cmErrMsg(&p->err,kAllocInstFailDspRC,"Msg List UI control allocation failed for '%s'.", cmStringNullGuard(lbl));
  1436. }
  1437. return inst;
  1438. }
  1439. cmDspInst_t* cmDspSysAllocAudioIn( cmDspSysH_t h, unsigned chIdx, cmReal_t gain )
  1440. { return cmDspSysAllocInst( h, "AudioIn", NULL, 2, chIdx, gain ); }
  1441. const cmJsonNode_t* _cmDspSysFindAudioChMap( cmDspSysH_t h, const cmChar_t* rsrcLabel )
  1442. {
  1443. cmDsp_t* p = _cmDspHandleToPtr(h);
  1444. cmJsonH_t jsH = cmDspSysPgmRsrcHandle(h);
  1445. assert( cmJsonIsValid(jsH) );
  1446. const cmJsonNode_t* np = NULL;
  1447. if(( np = cmJsonFindValue( jsH, rsrcLabel, cmJsonRoot(jsH), kArrayTId )) == NULL )
  1448. {
  1449. cmErrMsg(&p->err,kRsrcNotFoundDspRC,"The audio channel map resource '%s' was not found.", cmStringNullGuard(rsrcLabel));
  1450. return NULL;
  1451. }
  1452. unsigned chCnt = cmJsonChildCount(np);
  1453. if( chCnt == 0 )
  1454. {
  1455. cmErrMsg(&p->err,kInvalidArgDspRC,"The audio channel map resource '%s' is empty.",cmStringNullGuard(rsrcLabel));
  1456. return NULL;
  1457. }
  1458. return np;
  1459. }
  1460. cmDspRC_t _cmDspSysReadAudioChMap( cmDspSysH_t h, const cmChar_t* rsrcLabel, const cmJsonNode_t* mapNodePtr, unsigned* map, unsigned mapCnt )
  1461. {
  1462. cmDsp_t* p = _cmDspHandleToPtr(h);
  1463. unsigned i;
  1464. for(i=0; i<mapCnt; ++i)
  1465. {
  1466. const cmJsonNode_t* np;
  1467. if((np = cmJsonArrayElementC(mapNodePtr,i)) == NULL )
  1468. return cmErrMsg(&p->err,kInvalidArgDspRC,"The audio map element at index %i could not be accessed in the audio map:'%s'.",i,cmStringNullGuard(rsrcLabel));
  1469. if( cmJsonUIntValue(np,map + i ) != kOkJsRC )
  1470. return cmErrMsg(&p->err,kInvalidArgDspRC,"The audio map element at index %i could not be read as an integer in the audio map:'%s'..",i,cmStringNullGuard(rsrcLabel));
  1471. }
  1472. return kOkDspRC;
  1473. }
  1474. cmDspInst_t** _cmDspSysAllocAudioRsrc( cmDspSysH_t h, const cmChar_t* classLabel, const cmChar_t* rsrcLabel, cmReal_t gain, unsigned* retChCntPtr )
  1475. {
  1476. cmDsp_t* p = _cmDspHandleToPtr(h);
  1477. const cmJsonNode_t* np;
  1478. if( retChCntPtr != NULL )
  1479. *retChCntPtr = 0;
  1480. //
  1481. if( rsrcLabel==NULL )
  1482. rsrcLabel = "audioInMap";
  1483. // find the map resource
  1484. if((np = _cmDspSysFindAudioChMap(h,rsrcLabel)) == NULL )
  1485. return NULL;
  1486. unsigned chCnt = cmJsonChildCount(np);
  1487. cmDspInst_t** a = cmLhAllocZ( p->lhH, cmDspInst_t*, chCnt );
  1488. unsigned chMap[ chCnt ];
  1489. // fill in the channel map - maps virtual channels to physical channels
  1490. if( _cmDspSysReadAudioChMap(h,rsrcLabel,np,chMap,chCnt) != kOkDspRC )
  1491. return NULL;
  1492. unsigned i;
  1493. for(i=0; i<chCnt; ++i)
  1494. if((a[i] = cmDspSysAllocInst( h, classLabel, NULL, 2, chMap[i], gain )) == NULL )
  1495. break;
  1496. if( i==chCnt )
  1497. {
  1498. if( retChCntPtr != NULL )
  1499. *retChCntPtr = chCnt;
  1500. return a;
  1501. }
  1502. return NULL;
  1503. }
  1504. cmDspInst_t** cmDspSysAllocAudioInAR( cmDspSysH_t h, const cmChar_t* rsrcLabel, cmReal_t gain, unsigned* retChCntPtr )
  1505. { return _cmDspSysAllocAudioRsrc(h,"AudioIn",rsrcLabel,gain,retChCntPtr); }
  1506. cmDspInst_t* cmDspSysAllocAudioOut(cmDspSysH_t h, unsigned chIdx, cmReal_t gain )
  1507. { return cmDspSysAllocInst( h, "AudioOut", NULL, 2, chIdx, gain ); }
  1508. cmDspInst_t** cmDspSysAllocAudioOutAR( cmDspSysH_t h, const cmChar_t* rsrcLabel, cmReal_t gain, unsigned* retChCntPtr )
  1509. { return _cmDspSysAllocAudioRsrc(h,"AudioOut",rsrcLabel,gain,retChCntPtr); }
  1510. cmDspRC_t cmDspSysInstallNetCb( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarLabel, const cmChar_t* dstNetNodeLabel, const cmChar_t* dstInstLabel, const cmChar_t* dstVarLabel )
  1511. {
  1512. cmDsp_t* p = _cmDspHandleToPtr(h);
  1513. cmDspRC_t rc = kOkDspRC;
  1514. cmDspInst_t* netSendInstPtr;
  1515. unsigned dstNetNodeId;
  1516. _cmDspSrcConn_t* srcConnPtr = NULL;
  1517. // get the dest. network node id
  1518. if( (dstNetNodeId = cmUdpNetNodeLabelToId(p->netH, dstNetNodeLabel )) == cmInvalidId )
  1519. return cmErrMsg(&p->err,kNetNodeNotFoundDspRC,"The destination network node label '%s' was not found.",cmStringNullGuard(dstNetNodeLabel));
  1520. if((srcConnPtr = _cmDspSysNetCreateSrcConn( p, dstNetNodeId, dstInstLabel, dstVarLabel)) == NULL )
  1521. return rc;
  1522. // allocate a network sender
  1523. if((netSendInstPtr = cmDspSysAllocInst(h, "NetSend", NULL, 1, srcConnPtr )) == NULL )
  1524. return cmErrMsg(&p->err,kNetSendAllocFailDspRC,"The network sender DSP instance allocation failed.");
  1525. return cmDspSysInstallCb(h, srcInstPtr, srcVarLabel, netSendInstPtr, "in", NULL );
  1526. }
  1527. cmDspRC_t cmDspSysInstallNetCb1N1N( cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, const cmChar_t* dstNetNodeLabel, const cmChar_t* dstInstLabel, const cmChar_t* dstVarPrefixStr, unsigned dstOffs, unsigned n )
  1528. {
  1529. cmDspRC_t rc = kOkDspRC;
  1530. unsigned i;
  1531. for(i=0; i<n; ++i)
  1532. {
  1533. const cmChar_t* label0 = srcVarPrefixStr;
  1534. const cmChar_t* label1 = dstVarPrefixStr;
  1535. if( n >= 2 )
  1536. {
  1537. label0 = cmDspSysPrintLabel( srcVarPrefixStr,i);
  1538. label1 = cmDspSysPrintLabel2(dstVarPrefixStr,dstOffs + i);
  1539. }
  1540. if((rc = cmDspSysInstallNetCb(h,srcInstPtr,label0,dstNetNodeLabel,dstInstLabel,label1)) != kOkDspRC )
  1541. break;
  1542. }
  1543. return rc;
  1544. }
  1545. cmDspRC_t cmDspSysInstallNetCb1N1NM(cmDspSysH_t h, cmDspInst_t* srcInstPtr, const cmChar_t* srcVarPrefixStr, unsigned srcCnt, const cmChar_t* dstNetNodeLabel, const cmChar_t* dstInstLabel, const cmChar_t* dstVarPrefixStr, unsigned dstCnt, const unsigned* map )
  1546. {
  1547. cmDspRC_t rc = kOkDspRC;
  1548. unsigned i;
  1549. for(i=0; i<dstCnt; ++i)
  1550. {
  1551. assert( map[i] < srcCnt );
  1552. const cmChar_t* label0 = cmDspSysPrintLabel( srcVarPrefixStr, map[i] );
  1553. const cmChar_t* label1 = cmDspSysPrintLabel2(dstVarPrefixStr, i );
  1554. if((rc = cmDspSysInstallNetCb(h,srcInstPtr,label0,dstNetNodeLabel,dstInstLabel,label1)) != kOkDspRC )
  1555. break;
  1556. }
  1557. return rc;
  1558. }
  1559. cmDspRC_t _cmDspRsrcPath( cmDspSysH_t h, cmChar_t** pathPtr, va_list vl )
  1560. {
  1561. unsigned i;
  1562. cmDspRC_t rc = kOkDspRC;;
  1563. cmDsp_t* p = _cmDspHandleToPtr(h);
  1564. cmChar_t* path = NULL;
  1565. unsigned maxArgCnt = 10;
  1566. *pathPtr = NULL;
  1567. for(i=0; i<maxArgCnt; ++i )
  1568. {
  1569. cmChar_t* str;
  1570. if((str = va_arg(vl,cmChar_t* )) == NULL )
  1571. break;
  1572. if( path != NULL )
  1573. path = cmTextAppendSS(path,"/");
  1574. path = cmTextAppendSS(path,str);
  1575. }
  1576. if( i >= maxArgCnt )
  1577. {
  1578. rc = cmErrMsg(&p->err,kJsonFailDspRC,"A resource path, beginning with '%25s', does not contain a terminating NULL.", cmStringNullGuard(path) );
  1579. goto errLabel;
  1580. }
  1581. // duplicate the string onto the program linked heap
  1582. *pathPtr = cmLhAllocStr( cmDspSysLHeap(h), path);
  1583. errLabel:
  1584. cmMemFree(path);
  1585. return rc;
  1586. }
  1587. cmDspRC_t _cmDspRsrcWritePath( cmDspSysH_t h, cmChar_t** pathStrRef, cmChar_t** varStrRef, va_list vl )
  1588. {
  1589. unsigned i;
  1590. cmDspRC_t rc = kOkDspRC;;
  1591. cmDsp_t* p = _cmDspHandleToPtr(h);
  1592. cmChar_t* path = NULL;
  1593. unsigned maxArgCnt = 10;
  1594. cmChar_t* prevStr = NULL;
  1595. *pathStrRef = NULL;
  1596. *varStrRef = NULL;
  1597. for(i=0; i<maxArgCnt; ++i )
  1598. {
  1599. cmChar_t* str;
  1600. if((str = va_arg(vl,cmChar_t* )) == NULL )
  1601. break;
  1602. if( prevStr != NULL )
  1603. {
  1604. if( path != NULL )
  1605. path = cmTextAppendSS(path,"/");
  1606. path = cmTextAppendSS(path,prevStr);
  1607. }
  1608. prevStr = str;
  1609. }
  1610. if( i >= maxArgCnt )
  1611. {
  1612. rc = cmErrMsg(&p->err,kJsonFailDspRC,"A resource path, beginning with '%25s', does not contain a terminating NULL.", cmStringNullGuard(path) );
  1613. goto errLabel;
  1614. }
  1615. // duplicate the string onto the program linked heap
  1616. if( path != NULL )
  1617. *pathStrRef = cmLhAllocStr( cmDspSysLHeap(h), path);
  1618. *varStrRef = prevStr;
  1619. errLabel:
  1620. cmMemFree(path);
  1621. return rc;
  1622. }
  1623. cmDspRC_t cmDspRsrcBoolV( cmDspSysH_t h, bool* vp, va_list vl )
  1624. {
  1625. assert(vp != NULL);
  1626. cmDsp_t* p = _cmDspHandleToPtr(h);
  1627. cmChar_t* path = NULL;
  1628. cmDspRC_t rc;
  1629. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1630. return rc;
  1631. if((rc = cmJsonPathToBool( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
  1632. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'bool' resource not found at path:'%s'.",cmStringNullGuard(path));
  1633. cmLhFree(cmDspSysLHeap(h),path);
  1634. return rc;
  1635. }
  1636. cmDspRC_t cmDspRsrcIntV( cmDspSysH_t h, int* vp, va_list vl )
  1637. {
  1638. assert(vp != NULL);
  1639. cmDsp_t* p = _cmDspHandleToPtr(h);
  1640. cmChar_t* path = NULL;
  1641. cmDspRC_t rc;
  1642. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1643. return rc;
  1644. if((rc = cmJsonPathToInt( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
  1645. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'int' resource not found at path:'%s'.",cmStringNullGuard(path));
  1646. cmLhFree(cmDspSysLHeap(h),path);
  1647. return rc;
  1648. }
  1649. cmDspRC_t cmDspRsrcUIntV( cmDspSysH_t h, unsigned* vp, va_list vl )
  1650. {
  1651. assert(vp != NULL);
  1652. cmDsp_t* p = _cmDspHandleToPtr(h);
  1653. cmChar_t* path = NULL;
  1654. cmDspRC_t rc;
  1655. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1656. return rc;
  1657. if((rc = cmJsonPathToUInt( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
  1658. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'uint' resource not found at path:'%s'.",cmStringNullGuard(path));
  1659. cmLhFree(cmDspSysLHeap(h),path);
  1660. return rc;
  1661. }
  1662. cmDspRC_t cmDspRsrcDblV( cmDspSysH_t h, double* vp, va_list vl )
  1663. {
  1664. assert(vp != NULL);
  1665. cmDsp_t* p = _cmDspHandleToPtr(h);
  1666. cmChar_t* path = NULL;
  1667. cmDspRC_t rc;
  1668. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1669. return rc;
  1670. if((rc = cmJsonPathToReal( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
  1671. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'real' resource not found at path:'%s'.",cmStringNullGuard(path));
  1672. cmLhFree(cmDspSysLHeap(h),path);
  1673. return rc;
  1674. }
  1675. cmDspRC_t cmDspRsrcRealV( cmDspSysH_t h, cmReal_t* vp, va_list vl )
  1676. {
  1677. assert(vp != NULL);
  1678. cmDsp_t* p = _cmDspHandleToPtr(h);
  1679. cmChar_t* path = NULL;
  1680. cmDspRC_t rc;
  1681. double dval;
  1682. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1683. return rc;
  1684. if((rc = cmJsonPathToReal( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, &dval )) != kOkJsRC )
  1685. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'real' resource not found at path:'%s'.",cmStringNullGuard(path));
  1686. else
  1687. *vp = dval;
  1688. cmLhFree(cmDspSysLHeap(h),path);
  1689. return rc;
  1690. }
  1691. cmDspRC_t cmDspRsrcStringV( cmDspSysH_t h, const cmChar_t** vp, va_list vl )
  1692. {
  1693. assert(vp != NULL);
  1694. cmDsp_t* p = _cmDspHandleToPtr(h);
  1695. cmChar_t* path = NULL;
  1696. cmDspRC_t rc;
  1697. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1698. return rc;
  1699. if((rc = cmJsonPathToString( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, vp )) != kOkJsRC )
  1700. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'string' resource not found at path:'%s'.",cmStringNullGuard(path));
  1701. cmLhFree(cmDspSysLHeap(h),path);
  1702. return rc;
  1703. }
  1704. cmDspRC_t cmDspRsrcArrayCountV( cmDspSysH_t h, unsigned *n, va_list vl )
  1705. {
  1706. assert(n != NULL );
  1707. cmDsp_t* p = _cmDspHandleToPtr(h);
  1708. cmChar_t* path = NULL;
  1709. cmJsonNode_t* np = NULL;
  1710. cmDspRC_t rc;
  1711. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1712. return rc;
  1713. if((rc = cmJsonPathToArray( cmDspSysPgmRsrcHandle(h), NULL, NULL, path, &np )) != kOkJsRC )
  1714. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'array' resource not found at path:'%s'.",cmStringNullGuard(path));
  1715. else
  1716. *n = cmJsonChildCount(np);
  1717. cmLhFree(cmDspSysLHeap(h),path);
  1718. return rc;
  1719. }
  1720. cmDspRC_t _cmDspRsrcArrayV( cmDspSysH_t h, unsigned* np, cmJsonNode_t** npp, cmChar_t** pathPtrPtr, va_list vl )
  1721. {
  1722. cmDsp_t* p = _cmDspHandleToPtr(h);
  1723. cmChar_t* path = NULL;
  1724. cmJsonH_t jsH = cmDspSysPgmRsrcHandle(h);
  1725. cmDspRC_t rc;
  1726. if((rc = _cmDspRsrcPath(h,&path,vl)) != kOkDspRC )
  1727. return rc;
  1728. if((rc = cmJsonPathToArray( jsH, NULL, NULL, path, npp )) != kOkJsRC )
  1729. rc = cmErrMsg(&p->err,kJsonFailDspRC,"'array' resource not found at path:'%s'.",cmStringNullGuard(path));
  1730. else
  1731. {
  1732. if((*np = cmJsonChildCount(*npp)) != 0 )
  1733. *pathPtrPtr = path;
  1734. }
  1735. cmLhFree(cmDspSysLHeap(h),path);
  1736. return rc;
  1737. }
  1738. cmDspRC_t cmDspRsrcBoolArrayV( cmDspSysH_t h, unsigned* np, bool** vpp, va_list vl )
  1739. {
  1740. assert(vpp!=NULL);
  1741. cmDsp_t* p = _cmDspHandleToPtr(h);
  1742. cmJsonNode_t* nodePtr = NULL;
  1743. unsigned n = 0;
  1744. cmChar_t* path = NULL;
  1745. unsigned i;
  1746. cmDspRC_t rc;
  1747. if(( rc = _cmDspRsrcArrayV(h,&n,&nodePtr,&path,vl)) != kOkDspRC )
  1748. return rc;
  1749. bool* vp = *vpp;
  1750. vp = cmLhResizeN(p->ctx.lhH,bool,vp,n);
  1751. for(i=0; i<n && rc == kOkDspRC; ++i)
  1752. if( cmJsonBoolValue( cmJsonArrayElementC(nodePtr,i), vp + i ) != kOkJsRC )
  1753. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Element at index '%i' in resource '%s' is invalid.",i,cmStringNullGuard(path));
  1754. *vpp = vp;
  1755. *np = n;
  1756. cmLhFree(cmDspSysLHeap(h),path);
  1757. return rc;
  1758. }
  1759. cmDspRC_t cmDspRsrcIntArrayV( cmDspSysH_t h, unsigned* np, int** vpp, va_list vl )
  1760. {
  1761. assert(vpp!=NULL);
  1762. cmDsp_t* p = _cmDspHandleToPtr(h);
  1763. cmJsonNode_t* nodePtr = NULL;
  1764. unsigned n = 0;
  1765. cmChar_t* path = NULL;
  1766. unsigned i;
  1767. cmDspRC_t rc;
  1768. if(( rc = _cmDspRsrcArrayV(h,&n,&nodePtr,&path,vl)) != kOkDspRC )
  1769. return rc;
  1770. int* vp = *vpp;
  1771. vp = cmLhResizeN(p->ctx.lhH,int,vp,n);
  1772. for(i=0; i<n && rc == kOkDspRC; ++i)
  1773. if( cmJsonIntValue( cmJsonArrayElementC(nodePtr,i), vp + i ) != kOkJsRC )
  1774. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Element at index '%i' in resource '%s' is invalid.",i,cmStringNullGuard(path));
  1775. *vpp = vp;
  1776. *np = n;
  1777. cmLhFree(cmDspSysLHeap(h),path);
  1778. return rc;
  1779. }
  1780. cmDspRC_t cmDspRsrcUIntArrayV( cmDspSysH_t h, unsigned* np, unsigned** vpp, va_list vl )
  1781. {
  1782. assert(vpp!=NULL);
  1783. cmDsp_t* p = _cmDspHandleToPtr(h);
  1784. cmJsonNode_t* nodePtr = NULL;
  1785. unsigned n = 0;
  1786. cmChar_t* path = NULL;
  1787. unsigned i;
  1788. cmDspRC_t rc;
  1789. if(( rc = _cmDspRsrcArrayV(h,&n,&nodePtr,&path,vl)) != kOkDspRC )
  1790. return rc;
  1791. unsigned* vp = *vpp;
  1792. vp = cmLhResizeN(p->ctx.lhH,unsigned,vp,n);
  1793. for(i=0; i<n && rc == kOkDspRC; ++i)
  1794. if( cmJsonUIntValue( cmJsonArrayElementC(nodePtr,i), vp + i ) != kOkJsRC )
  1795. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Element at index '%i' in resource '%s' is invalid.",i,cmStringNullGuard(path));
  1796. *vpp = vp;
  1797. *np = n;
  1798. cmLhFree(cmDspSysLHeap(h),path);
  1799. return rc;
  1800. }
  1801. cmDspRC_t cmDspRsrcDblArrayV( cmDspSysH_t h, unsigned* np, double** vpp, va_list vl )
  1802. {
  1803. assert(vpp!=NULL);
  1804. cmDsp_t* p = _cmDspHandleToPtr(h);
  1805. cmJsonNode_t* nodePtr = NULL;
  1806. unsigned n = 0;
  1807. cmChar_t* path = NULL;
  1808. unsigned i;
  1809. cmDspRC_t rc;
  1810. if(( rc = _cmDspRsrcArrayV(h,&n,&nodePtr,&path,vl)) != kOkDspRC )
  1811. return rc;
  1812. double* vp = *vpp;
  1813. vp = cmLhResizeN(p->ctx.lhH,double,vp,n);
  1814. for(i=0; i<n && rc == kOkDspRC; ++i)
  1815. if( cmJsonRealValue( cmJsonArrayElementC(nodePtr,i), vp + i ) != kOkJsRC )
  1816. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Element at index '%i' in resource '%s' is invalid.",i,cmStringNullGuard(path));
  1817. *vpp = vp;
  1818. *np = n;
  1819. cmLhFree(cmDspSysLHeap(h),path);
  1820. return rc;
  1821. }
  1822. cmDspRC_t cmDspRsrcRealArrayV( cmDspSysH_t h, unsigned* np, cmReal_t** vpp, va_list vl )
  1823. {
  1824. assert(vpp!=NULL);
  1825. cmDsp_t* p = _cmDspHandleToPtr(h);
  1826. cmJsonNode_t* nodePtr = NULL;
  1827. unsigned n = 0;
  1828. cmChar_t* path = NULL;
  1829. unsigned i;
  1830. cmDspRC_t rc;
  1831. if(( rc = _cmDspRsrcArrayV(h,&n,&nodePtr,&path,vl)) != kOkDspRC )
  1832. return rc;
  1833. cmReal_t* vp = *vpp;
  1834. vp = cmLhResizeN(p->ctx.lhH,cmReal_t,vp,n);
  1835. for(i=0; i<n && rc == kOkDspRC; ++i)
  1836. {
  1837. double v;
  1838. if( cmJsonRealValue( cmJsonArrayElementC(nodePtr,i), &v ) != kOkJsRC )
  1839. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Element at index '%i' in resource '%s' is invalid.",i,cmStringNullGuard(path));
  1840. vp[i] = v;
  1841. }
  1842. *vpp = vp;
  1843. *np = n;
  1844. cmLhFree(cmDspSysLHeap(h),path);
  1845. return rc;
  1846. }
  1847. cmDspRC_t cmDspRsrcStringArrayV(cmDspSysH_t h, unsigned* np, const cmChar_t*** vpp, va_list vl )
  1848. {
  1849. assert(vpp!=NULL);
  1850. cmDsp_t* p = _cmDspHandleToPtr(h);
  1851. cmJsonNode_t* nodePtr = NULL;
  1852. unsigned n = 0;
  1853. cmChar_t* path = NULL;
  1854. unsigned i;
  1855. cmDspRC_t rc;
  1856. if(( rc = _cmDspRsrcArrayV(h,&n,&nodePtr,&path,vl)) != kOkDspRC )
  1857. return rc;
  1858. const cmChar_t** vp = *vpp;
  1859. vp = cmLhResizeN(p->ctx.lhH,const cmChar_t*,vp,n);
  1860. for(i=0; i<n && rc == kOkDspRC; ++i)
  1861. if( cmJsonStringValue( cmJsonArrayElementC(nodePtr,i), vp + i ) != kOkJsRC )
  1862. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Element at index '%i' in resource '%s' is invalid.",i,cmStringNullGuard(path));
  1863. *vpp = vp;
  1864. *np = n;
  1865. cmLhFree(cmDspSysLHeap(h),path);
  1866. return rc;
  1867. }
  1868. cmDspRC_t cmDspRsrcInt( cmDspSysH_t h, int* vp, ... )
  1869. {
  1870. va_list vl;
  1871. va_start(vl,vp);
  1872. cmDspRC_t rc = cmDspRsrcIntV(h,vp,vl);
  1873. va_end(vl);
  1874. return rc;
  1875. }
  1876. cmDspRC_t cmDspRsrcUInt( cmDspSysH_t h, unsigned* vp, ... )
  1877. {
  1878. va_list vl;
  1879. va_start(vl,vp);
  1880. cmDspRC_t rc = cmDspRsrcUIntV(h,vp,vl);
  1881. va_end(vl);
  1882. return rc;
  1883. }
  1884. cmDspRC_t cmDspRsrcDbl( cmDspSysH_t h, double* vp, ... )
  1885. {
  1886. va_list vl;
  1887. va_start(vl,vp);
  1888. cmDspRC_t rc = cmDspRsrcDblV(h,vp,vl);
  1889. va_end(vl);
  1890. return rc;
  1891. }
  1892. cmDspRC_t cmDspRsrcReal( cmDspSysH_t h, cmReal_t* vp, ... )
  1893. {
  1894. va_list vl;
  1895. va_start(vl,vp);
  1896. cmDspRC_t rc = cmDspRsrcRealV(h,vp,vl);
  1897. va_end(vl);
  1898. return rc;
  1899. }
  1900. cmDspRC_t cmDspRsrcString( cmDspSysH_t h, const cmChar_t** vp, ... )
  1901. {
  1902. va_list vl;
  1903. va_start(vl,vp);
  1904. cmDspRC_t rc = cmDspRsrcStringV(h,vp,vl);
  1905. va_end(vl);
  1906. return rc;
  1907. }
  1908. cmDspRC_t cmDspRsrcArrayCount( cmDspSysH_t h, unsigned *np, ... )
  1909. {
  1910. va_list vl;
  1911. va_start(vl,np);
  1912. cmDspRC_t rc = cmDspRsrcArrayCountV(h,np,vl);
  1913. va_end(vl);
  1914. return rc;
  1915. }
  1916. cmDspRC_t cmDspRsrcBoolArray( cmDspSysH_t h, unsigned* np, bool** vpp, ... )
  1917. {
  1918. va_list vl;
  1919. va_start(vl,vpp);
  1920. cmDspRC_t rc = cmDspRsrcBoolArrayV(h,np,vpp,vl);
  1921. va_end(vl);
  1922. return rc;
  1923. }
  1924. cmDspRC_t cmDspRsrcIntArray( cmDspSysH_t h, unsigned* np, int** vpp, ... )
  1925. {
  1926. va_list vl;
  1927. va_start(vl,vpp);
  1928. cmDspRC_t rc = cmDspRsrcIntArrayV(h,np,vpp,vl);
  1929. va_end(vl);
  1930. return rc;
  1931. }
  1932. cmDspRC_t cmDspRsrcUIntArray( cmDspSysH_t h, unsigned* np, unsigned** vpp, ... )
  1933. {
  1934. va_list vl;
  1935. va_start(vl,vpp);
  1936. cmDspRC_t rc = cmDspRsrcUIntArrayV(h,np,vpp,vl);
  1937. va_end(vl);
  1938. return rc;
  1939. }
  1940. cmDspRC_t cmDspRsrcDblArray( cmDspSysH_t h, unsigned* np, double** vpp, ... )
  1941. {
  1942. va_list vl;
  1943. va_start(vl,vpp);
  1944. cmDspRC_t rc = cmDspRsrcDblArrayV(h,np,vpp,vl);
  1945. va_end(vl);
  1946. return rc;
  1947. }
  1948. cmDspRC_t cmDspRsrcRealArray( cmDspSysH_t h, unsigned* np, cmReal_t** vpp, ... )
  1949. {
  1950. va_list vl;
  1951. va_start(vl,vpp);
  1952. cmDspRC_t rc = cmDspRsrcRealArrayV(h,np,vpp,vl);
  1953. va_end(vl);
  1954. return rc;
  1955. }
  1956. cmDspRC_t cmDspRsrcStringArray( cmDspSysH_t h, unsigned* np, const cmChar_t*** vpp, ... )
  1957. {
  1958. va_list vl;
  1959. va_start(vl,vpp);
  1960. cmDspRC_t rc = cmDspRsrcStringArrayV(h,np,vpp,vl);
  1961. va_end(vl);
  1962. return rc;
  1963. }
  1964. cmDspRC_t _cmDspWritePathAndParent( cmDspSysH_t h, cmChar_t** pathRef, cmChar_t** varLabelRef, cmJsonNode_t** parentRef, va_list vl )
  1965. {
  1966. cmDsp_t* p = _cmDspHandleToPtr(h);
  1967. cmJsonH_t jsH = cmDspSysPgmRsrcHandle(h);
  1968. cmDspRC_t rc;
  1969. if((rc = _cmDspRsrcWritePath(h,pathRef,varLabelRef,vl)) != kOkDspRC )
  1970. goto errLabel;
  1971. if( *pathRef == NULL )
  1972. *parentRef = cmJsonRoot(jsH);
  1973. else
  1974. *parentRef = cmJsonFindPathValue( jsH, *pathRef, cmJsonRoot(jsH), kPairTId );
  1975. if( *parentRef == NULL )
  1976. {
  1977. rc = cmErrMsg(&p->err,kJsonFailDspRC,"The parent object '%s' for variable '%s' could not be found.",cmStringNullGuard(*pathRef),cmStringNullGuard(*varLabelRef));
  1978. goto errLabel;
  1979. }
  1980. errLabel:
  1981. return rc;
  1982. }
  1983. cmDspRC_t cmDspRsrcWriteStringV( cmDspSysH_t h, const cmChar_t* v, va_list vl )
  1984. {
  1985. cmDsp_t* p = _cmDspHandleToPtr(h);
  1986. cmJsonH_t jsH = cmDspSysPgmRsrcHandle(h);
  1987. cmChar_t* varStr = NULL;
  1988. cmChar_t* pathStr = NULL;
  1989. cmJsonNode_t* parentObjNodePtr = NULL;
  1990. cmDspRC_t rc;
  1991. if((rc = _cmDspWritePathAndParent(h, &pathStr, &varStr, &parentObjNodePtr, vl )) != kOkDspRC )
  1992. goto errLabel;
  1993. if( cmJsonInsertOrReplacePairString( jsH, parentObjNodePtr, varStr, kStringTId, v ) != kOkJsRC )
  1994. rc = cmErrMsg(&p->err,kJsonFailDspRC,"Write 'string' resource value failed for path '%s' and variable '%s'",cmStringNullGuard(pathStr),cmStringNullGuard(varStr));
  1995. errLabel:
  1996. if( pathStr != NULL )
  1997. cmLhFree(cmDspSysLHeap(h),pathStr);
  1998. return rc;
  1999. }
  2000. cmDspRC_t cmDspRsrcWriteString( cmDspSysH_t h, const cmChar_t* v, ... )
  2001. {
  2002. va_list vl;
  2003. va_start(vl,v);
  2004. cmDspRC_t rc = cmDspRsrcWriteStringV(h,v,vl);
  2005. va_end(vl);
  2006. return rc;
  2007. }