Programmable real-time audio signal processing application
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

kcApp.cpp 49KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050
  1. #include <FL/Fl.H>
  2. #include <FL/Fl_Double_Window.H>
  3. #include <FL/Fl_Menu_Item.H>
  4. #include <Fl/Fl_Menu_Bar.H>
  5. #include <Fl/Fl_Button.H>
  6. #include <Fl/Fl_Check_Button.H>
  7. #include <Fl/Fl_Text_Buffer.H>
  8. #include <Fl/Fl_Text_Display.H>
  9. #include <Fl/Fl_Box.H>
  10. #include <Fl/Fl_Tabs.H>
  11. #include <Fl/Fl_File_Chooser.H>
  12. #include <Fl/Fl_Value_Slider.H>
  13. #include <Fl/Fl_Menu_Button.H>
  14. #include <Fl/Fl_Select_Browser.H>
  15. #include <Fl/Fl_Value_Input.H>
  16. #include <Fl/Fl_Progress.H>
  17. #include "Fl_Vert_Progress.h"
  18. #include "Fl_File_Btn.h"
  19. #include "Fl_Splitter.h"
  20. #include "cmGlobal.h"
  21. #include "cmFloatTypes.h"
  22. #include "cmRpt.h"
  23. #include "cmErr.h"
  24. #include "cmCtx.h"
  25. #include "cmMem.h"
  26. #include "cmMallocDebug.h"
  27. #include "cmLinkedHeap.h"
  28. #include "cmText.h"
  29. #include "cmSymTbl.h"
  30. #include "cmJson.h"
  31. #include "cmFileSys.h"
  32. #include "cmPrefs.h"
  33. #include "cmAudioFile.h"
  34. #include "cmThread.h"
  35. #include "cmProcTest.h"
  36. #include "cmDspValue.h"
  37. #include "cmMsgProtocol.h"
  38. #include "cmAudDspIF.h"
  39. #include "cmAudDspLocal.h"
  40. #include "cmAudioFile.h"
  41. #include "cmAudioFileMgr.h"
  42. #include "cmMidi.h"
  43. #include "cmMidiFile.h"
  44. #include "cmTimeLine.h"
  45. #include "cmScore.h"
  46. #include "cmdIf.h"
  47. #include "tlCtl.h"
  48. #include "kcApp.h"
  49. #include "cmGr.h"
  50. #include "cmGrDevCtx.h"
  51. #include "cmGrPlot.h"
  52. #include "cmGrPage.h"
  53. #include "cmGrFltk.h"
  54. #define TIMER_PERIOD (1.0/20.0) // 50ms
  55. kcApp::kcApp(cmCtx_t* ctx, cmTsMp1cH_t printqH, int w, int h, const cmChar_t* title, cmAiH_t aiH, int argc, char* argv[] )
  56. : Fl_Double_Window(w, h,title),
  57. splt(NULL),_menu(NULL),_aiH(aiH),
  58. _statIdx(0),_pageList(NULL),_ctlList(NULL),
  59. _stopTimerFl(false),_newPageFl(true),
  60. _incrColW(0),_colW(0),_horzBordFl(false),_horzBord(0),
  61. _closeCnt(0),_ssCnt(0),_ssArray(0),_ssPhase(0),_ssUpdateFl(false),
  62. _printqH(printqH),_printFl(0),
  63. _tlCtl(NULL)
  64. {
  65. // install a callback to cleanup when the app window closes
  66. // (the btn callbacks and _getApp() rely on a pointer to 'this' being found in kcApp.user_data())
  67. callback(_s_callback,this);
  68. // the main window is divided between the menu bar on top
  69. // and a horizontal splitter on the bottom
  70. begin();
  71. _createMenu(w,kMenuH);
  72. splt = new Fl_HSplitter(0, kMenuH, w, h-kStatusH-kMenuH, h-kStatusH-kMenuH-100);
  73. end();
  74. // Create a text display object for console output andvadd it to the lower splitter area
  75. buf = new Fl_Text_Buffer();
  76. con = new Fl_Text_Display(splt->container2->x(),splt->container2->y(),splt->container2->w(),splt->container2->h());
  77. con->buffer(buf);
  78. splt->container2->add(con);
  79. // Create a tab view and added it to the upper splitter area
  80. tabs = new Fl_Tabs(splt->container1->x(),splt->container1->y(),splt->container1->w(),splt->container1->h());
  81. tabs->callback(_s_tab_cb,this);
  82. tabs->end();
  83. splt->container1->add(tabs);
  84. int tx,ty,th,tw;
  85. tabs->client_area(tx,ty,tw,th);
  86. // Create the 'Setup' tab group
  87. Fl_Group* setup_grp = new Fl_Group(tx,ty,tw,th,"Setup");
  88. tabs->add(setup_grp);
  89. _createSetupDlg(setup_grp);
  90. // Create the master group
  91. tabs->add(mstr_grp = new Fl_Group(tx,ty,tw,th,"Master"));
  92. // Create an empty tab group and make it resizable
  93. // to prevent the other tab groups from being resizable.
  94. Fl_Group* wdgt = new Fl_Group(tx,ty+30,1,1);
  95. tabs->add(wdgt);
  96. tabs->resizable(wdgt); // make other tabs non-resizable
  97. // make the splitter the resizable group element (thereby making the menu non-resizable).
  98. // see:http://fltk.org/articles.php?L415+I0+T+M1000+P1
  99. resizable(splt);
  100. show(argc, argv);
  101. // direct all output to the console window
  102. cmRptSetup(&_ctx.rpt,_s_print,_s_print, this);
  103. cmTsMp1cSetCbFunc(_printqH, _s_print_queue_cb, this );
  104. // install a timer to check for messages from the engine
  105. Fl::add_timeout(TIMER_PERIOD,_s_status_timeout_cb,this);
  106. }
  107. kcApp::~kcApp()
  108. {
  109. _clearCtlList(true);
  110. _clearSsArray();
  111. }
  112. void kcApp::resize(int x, int y, int w, int h)
  113. {
  114. Fl_Double_Window::resize(x, y, w, h);
  115. splt->resize(0, kMenuH, w, h-kStatusH);
  116. }
  117. void kcApp::tlCtlNewTimeLineFile( tlCtl* tlCtl, const cmChar_t* fn )
  118. {}
  119. void kcApp::tlCtlNewScoreFile( tlCtl* tlCtl, const cmChar_t* fn )
  120. {}
  121. void kcApp::_createSetupDlg( Fl_Group* grp )
  122. {
  123. int ctl_width = 200;
  124. int vBord = 5;
  125. int xx = grp->x() + 5;
  126. int yy = grp->y() + vBord;
  127. grp->begin();
  128. Fl_Button* btn = new Fl_Button(xx,yy,200,kMenuH,"Audio Device Report");
  129. btn->callback( _s_btn_cb, kAudDevRptBtnId );
  130. yy += btn->h() + vBord;
  131. as_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Audio System Cfg");
  132. as_btn->callback( _s_btn_cb, kAudioSysCfgBtnId);
  133. yy += as_btn->h() + vBord;
  134. ai_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Audio Input Devices");
  135. ai_btn->callback( _s_btn_cb, kInAudDevBtnId);
  136. yy += ai_btn->h() + vBord;
  137. ao_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Audio Output Devices");
  138. ao_btn->callback( _s_btn_cb, kOutAudDevBtnId);
  139. yy += ao_btn->h() + vBord;
  140. pgm_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Programs");
  141. pgm_btn->callback( _s_btn_cb, kPgmBtnId);
  142. yy += pgm_btn->h() + vBord;
  143. ss_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Sub-System");
  144. ss_btn->callback( _s_btn_cb, kSubSystemIdxBtnId);
  145. yy += ss_btn->h() + vBord;
  146. sr_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Sample Rate");
  147. sr_btn->callback( _s_btn_cb, kSrateBtnId);
  148. sr_btn->add("44100",0,NULL,(void*)44100,0);
  149. sr_btn->add("48000",0,NULL,(void*)48000,0);
  150. sr_btn->add("96000",0,NULL,(void*)96000,0);
  151. yy += sr_btn->h() + vBord;
  152. btn = new Fl_Button(xx,yy,ctl_width,kMenuH,"Test");
  153. btn->callback( _s_btn_cb, kTestBtnId );
  154. yy += btn->h() + vBord;
  155. ena_chk = new Fl_Check_Button(xx,yy,ctl_width,kMenuH,"Enable Audio");
  156. ena_chk->callback( _s_btn_cb, kEnableBtnId );
  157. yy += ena_chk->h() + vBord;
  158. // place this ctrl in the lower left corner to prevent the other controls from resizing
  159. Fl_Box* bx = new Fl_Box(FL_NO_BOX,xx+ctl_width,yy,10,10,NULL);
  160. grp->resizable(bx);
  161. grp->end();
  162. }
  163. void kcApp::_createMenu(int w, int h)
  164. {
  165. Fl_Menu_Item items[] =
  166. {
  167. { "&File", 0, 0, 0, FL_SUBMENU },
  168. { "&New File", 0, (Fl_Callback*)_s_menu_cb },
  169. { 0 },
  170. { 0 }
  171. };
  172. _menu = new Fl_Menu_Bar(0,0,w,h);
  173. _menu->copy(items);
  174. }
  175. kcApp::page_t* kcApp::_createPage( const char* title )
  176. {
  177. int tx,ty,th,tw;
  178. tabs->client_area(tx,ty,tw,th);
  179. page_t* page = new page_t;
  180. page->link = _pageList;
  181. _pageList = page;
  182. _newPageFl = true;
  183. // Create the 'Controls' tab group
  184. tabs->begin();
  185. page->grp = new Fl_Group(tx,ty,tw,th,title);
  186. page->grp->begin();
  187. Fl_Box* bx = new Fl_Box(FL_NO_BOX,page->grp->x()+page->grp->w(),page->grp->y()+page->grp->h(),1,1,NULL);
  188. page->grp->resizable(bx);
  189. page->grp->end();
  190. tabs->end();
  191. return page;
  192. }
  193. // return the count of engine ctls
  194. unsigned kcApp::_getCtlCount() const
  195. {
  196. unsigned cnt = 0;
  197. ctl_t* cp = _ctlList;
  198. for(; cp!=NULL; cp=cp->linkPtr)
  199. ++cnt;
  200. return cnt;
  201. }
  202. // delete all engine ctls - (except maybe the master ctrl's)
  203. void kcApp::_clearCtlList(bool mstrFl)
  204. {
  205. ctl_t* ncl = NULL;
  206. ctl_t* cp = _ctlList;
  207. while( cp != NULL )
  208. {
  209. ctl_t* np = cp->linkPtr;
  210. // delete the ctrl unless it is a master ctl and the mstrFl is set
  211. if( cp->mstrFl==false || mstrFl )
  212. {
  213. delete cp;
  214. }
  215. else
  216. {
  217. // append the master ctl to the new ctl list
  218. cp->linkPtr = ncl;
  219. ncl = cp;
  220. }
  221. cp = np;
  222. }
  223. // clear the page groups and pages
  224. page_t* pg = _pageList;
  225. while( pg != NULL )
  226. {
  227. page_t* np = pg->link;
  228. pg->grp->clear();
  229. delete pg->grp;
  230. delete pg;
  231. pg = np;
  232. }
  233. _pageList = NULL;
  234. //ctl_grp->clear();
  235. _ctlList = ncl; // make the new ctl list the current ctl list
  236. if( mstrFl )
  237. mstr_grp->clear();
  238. _tlCtl = NULL;
  239. }
  240. void kcApp::_clearSsArray()
  241. {
  242. if( _ssArray != NULL )
  243. {
  244. delete[] _ssArray;
  245. _ssArray = NULL;
  246. }
  247. _ssCnt = 0;
  248. }
  249. // find a engine ui ctl given a dsp instance id
  250. kcApp::ctl_t* kcApp::_findCtl( unsigned instId, unsigned asSubIdx, unsigned mstrFl )
  251. {
  252. ctl_t* cp = _ctlList;
  253. for(; cp!=NULL; cp=cp->linkPtr)
  254. if( cp->instId == instId && cp->asSubIdx==asSubIdx && cp->mstrFl==mstrFl )
  255. return cp;
  256. //printf("not found:0x%x ssi:%i mstr:%i\n",instId,asSubIdx,mstrFl);
  257. return NULL;
  258. }
  259. // calc. the position and size of a new ctl being created
  260. // at the request of the engine
  261. void kcApp::_getNewCtlPosn( const cmDspUiHdr_t* m, int& x, int& y, int& w, int& h )
  262. {
  263. enum { kPageH=700, kCtlH=30, kCtlW=200, kHBord=2, kVBord=2 };
  264. // if this is control is being placed in the 'master' group
  265. if( m->uiId == cmInvalidId )
  266. {
  267. //unsigned devIdx = cmAudioSysUiInstIdToDevIndex(m->instId);
  268. unsigned chIdx = cmAudioSysUiInstIdToChIndex(m->instId);
  269. unsigned outFl = !cmAudioSysUiInstIdToInFlag(m->instId);
  270. unsigned ctlId = cmAudioSysUiInstIdToCtlId(m->instId);
  271. int xOffs = 20;
  272. int yOffs = 100;
  273. int chH = 205;
  274. int chW = 44;
  275. int sldrH = 120;
  276. int sldrW = 20;
  277. int chkH = 20;
  278. int chkW = 35;
  279. x = xOffs + (chIdx * chW);
  280. y = yOffs + (m->asSubIdx * 2 * chH) + (outFl * chH);
  281. switch( ctlId )
  282. {
  283. // slider
  284. case kSliderUiAsId: w=sldrW; h=sldrH; break;
  285. // meter
  286. case kMeterUiAsId: w=sldrW; h=sldrH; x+=sldrW; break;
  287. // mute
  288. case kMuteUiAsId: w=chkW; h=chkH; y+=sldrH + 2; break;
  289. // tone
  290. case kToneUiAsId: w=chkW; h=chkH; y+=sldrH + chkH + 4; break;
  291. // pass
  292. case kPassUiAsId: w=chkW; h=chkH; y+=sldrH + 2*chkH + 6; break;
  293. default:
  294. { assert(0); }
  295. }
  296. return;
  297. }
  298. // if this control is being placed in the 'controls' group
  299. ctl_t* cp = _ctlList;
  300. if( w == 0 )
  301. {
  302. if( _colW == 0 )
  303. _colW = kCtlW;
  304. w = _colW;
  305. }
  306. if( h == 0 )
  307. h = kCtlH;
  308. // skip over controls that are assigned to the 'master' group
  309. while(cp != NULL && cp->mstrFl )
  310. cp = cp->linkPtr;
  311. // if the page list is empty - create a default blank page
  312. if( _pageList == NULL )
  313. _createPage("Controls");
  314. Fl_Group* ctl_grp = _pageList->grp;
  315. // if the ctl list is empty
  316. if( cp == NULL || _newPageFl )
  317. {
  318. _newPageFl = false;
  319. x = kHBord + ctl_grp->x();
  320. y = kVBord + ctl_grp->y();
  321. _horzBord = y;
  322. }
  323. else
  324. {
  325. // if a new horizontal - upper border was requested
  326. if( _horzBordFl )
  327. {
  328. _horzBordFl = false;
  329. // locate the current control with the max bottom coordinate
  330. ctl_t* tp = cp;
  331. if( tp != NULL )
  332. {
  333. int maxY = tp->wdgtPtr->y() + tp->wdgtPtr->h();
  334. while(tp!=NULL)
  335. {
  336. if( tp->mstrFl == false && (tp->wdgtPtr->y() + tp->wdgtPtr->h()) > maxY )
  337. maxY = tp->wdgtPtr->y() + tp->wdgtPtr->h();
  338. tp = tp->linkPtr;
  339. }
  340. // set the new upper boundary to just below the bottom of
  341. // the lowest control
  342. _horzBord = maxY + kVBord*2;
  343. }
  344. x = kHBord + ctl_grp->x();
  345. y = _horzBord;
  346. }
  347. else
  348. {
  349. // use the last ctl inserted in the list
  350. // (the first ctl in the list)
  351. // to position the next ctl
  352. x = cp->wdgtPtr->x();
  353. y = cp->wdgtPtr->y() + cp->wdgtPtr->h() + kVBord;
  354. // if this control goes off the page or a new col was requested
  355. if( y+h > kPageH || _incrColW )
  356. {
  357. x += _colW + kHBord;
  358. _colW = _incrColW;
  359. _incrColW = 0;
  360. y = _horzBord;
  361. }
  362. }
  363. }
  364. }
  365. kcApp::ctl_t* kcApp::_createCtl( const cmDspUiHdr_t* m, unsigned typeId, int& x, int& y, int& w, int& h, bool posnFl )
  366. {
  367. ctl_t* cp = new ctl_t;
  368. cp->thisPtr = this;
  369. cp->asSubIdx = m->asSubIdx;
  370. cp->instId = m->instId;
  371. cp->typeId = typeId;
  372. cp->mstrFl = m->uiId == cmInvalidId;
  373. if( posnFl )
  374. _getNewCtlPosn(m,x,y,w,h);
  375. return cp;
  376. }
  377. void kcApp::_insertNewCtl( ctl_t* cp, const cmDspUiHdr_t* m, Fl_Widget* wdgt, unsigned* varIdArray, unsigned varIdCnt )
  378. {
  379. unsigned i;
  380. // _genNewCtlPosn() should have been called before this - where a new page list would have been created.
  381. assert( cp->mstrFl || (cp->mstrFl==false && _pageList != NULL) );
  382. Fl_Group* grp = cp->mstrFl ? mstr_grp : _pageList->grp;
  383. cp->wdgtPtr = wdgt;
  384. cp->wdgtPtr->callback(_s_ctl_cb, cp );
  385. grp->add(cp->wdgtPtr);
  386. const unsigned* srcVarIdArray = cmDsvUIntCMtx(&m->value);
  387. assert( varIdArray != NULL && cmDsvEleCount(&m->value)==varIdCnt);
  388. for(i=0; i<varIdCnt; ++i)
  389. varIdArray[i] = srcVarIdArray[i];
  390. cp->linkPtr = _ctlList;
  391. _ctlList = cp;
  392. }
  393. // create a slider ctl at the request of the engine
  394. void kcApp::_createSlider( const cmDspUiHdr_t* m )
  395. {
  396. int x,y,w=0,h=0;
  397. ctl_t* cp = _createCtl(m, m->selId==kSliderDuiId? kSldrTypeId : kNumbTypeId, x,y,w,h );
  398. switch(m->selId)
  399. {
  400. case kSliderDuiId:
  401. cp->u.sldr.u.sldr = new Fl_Value_Slider(x,y,w,h);
  402. cp->u.sldr.val = static_cast<Fl_Valuator*>(cp->u.sldr.u.sldr);
  403. cp->u.sldr.u.sldr->type(cp->mstrFl ? FL_VERT_NICE_SLIDER : FL_HOR_NICE_SLIDER);
  404. break;
  405. case kNumberDuiId:
  406. cp->u.sldr.u.numb = new Fl_Value_Input(x,y,w/2,h);
  407. cp->u.sldr.u.numb->when(FL_WHEN_ENTER_KEY | FL_WHEN_RELEASE );
  408. cp->u.sldr.val = static_cast<Fl_Valuator*>(cp->u.sldr.u.numb);
  409. break;
  410. }
  411. _insertNewCtl(cp, m, cp->u.sldr.val, cp->u.sldr.varIdArray, kSldrVarCnt );
  412. }
  413. // handle slider value msg's arriving from the engine
  414. void kcApp::_setSldrValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  415. {
  416. unsigned i=0;
  417. Fl_Valuator* sp = cp->u.sldr.val;
  418. for(i=0; i<kSldrVarCnt; ++i)
  419. if( cp->u.sldr.varIdArray[i] == instVarId )
  420. {
  421. switch(i)
  422. {
  423. case kSldrMinArgIdx:
  424. sp->minimum(cmDsvGetDouble(vp));
  425. //sp->step((sp->maximum()-sp->minimum())/sp->w());
  426. break;
  427. case kSldrMaxArgIdx:
  428. sp->maximum(cmDsvGetDouble(vp));
  429. //sp->step((sp->maximum()-sp->minimum())/sp->w());
  430. break;
  431. case kSldrStpArgIdx:
  432. sp->step(cmDsvGetDouble(vp));
  433. break;
  434. case kSldrValArgIdx:
  435. sp->value(cmDsvGetDouble(vp));
  436. break;
  437. case kSldrLblArgIdx:
  438. {
  439. int ww=0,hh=0;
  440. if( cmDsvStrcz(vp) == NULL )
  441. {
  442. sp->label(NULL);
  443. sp->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER );
  444. }
  445. else
  446. {
  447. sp->copy_label( cmDsvStrcz(vp) );
  448. sp->align(FL_ALIGN_RIGHT);
  449. }
  450. if( cp->typeId == kSldrTypeId )
  451. {
  452. sp->measure_label(ww,hh);
  453. sp->resize( sp->x(), sp->y(), sp->w() - ww, sp->h());
  454. sp->redraw();
  455. }
  456. }
  457. break;
  458. default:
  459. { assert(0); }
  460. }
  461. break;
  462. }
  463. }
  464. void kcApp::_createText( const cmDspUiHdr_t* m )
  465. {
  466. int x,y,w=0,h=0;
  467. ctl_t* cp = _createCtl(m, kTextTypeId, x,y,w,h );
  468. cp->u.text.text = new Fl_Input(x,y,w,h);
  469. _insertNewCtl(cp, m, cp->u.text.text, cp->u.text.varIdArray, kTextVarCnt );
  470. }
  471. void kcApp::_setTextValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  472. {
  473. unsigned i=0;
  474. Fl_Input* tp = cp->u.text.text;
  475. for(i=0; i<kTextVarCnt; ++i)
  476. if( cp->u.text.varIdArray[i] == instVarId )
  477. {
  478. switch(i)
  479. {
  480. case kTextValArgIdx:
  481. tp->value( cmDsvStrcz(vp));
  482. break;
  483. case kTextLblArgIdx:
  484. {
  485. const char* lbl = cmDsvStrcz(vp);
  486. if( lbl == NULL )
  487. tp->label(NULL);
  488. else
  489. tp->copy_label( lbl );
  490. tp->align(FL_ALIGN_RIGHT);
  491. tp->resize( tp->x(), tp->y(), tp->w()/2, tp->h());
  492. tp->redraw();
  493. }
  494. break;
  495. default:
  496. { assert(0); }
  497. }
  498. }
  499. }
  500. void kcApp::_createFnameCtl( const cmDspUiHdr_t* m )
  501. {
  502. int x,y,w=0,h=0;
  503. ctl_t* cp = _createCtl(m, kFnamTypeId, x,y,w,h );
  504. cp->u.fnam.fnam = new Fl_File_Btn(x,y,w,h);
  505. _insertNewCtl(cp, m, cp->u.fnam.fnam, cp->u.fnam.varIdArray, kFnamVarCnt );
  506. }
  507. void kcApp::_setFnamValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  508. {
  509. unsigned i=0;
  510. Fl_File_Btn* bp = cp->u.fnam.fnam;
  511. for(i=0; i<kFnamVarCnt; ++i)
  512. if( cp->u.fnam.varIdArray[i] == instVarId )
  513. {
  514. switch(i)
  515. {
  516. case kFnamValArgIdx:
  517. assert( cmDsvIsType( vp, kStrzDsvFl ) );
  518. bp->filename( cmDsvStrcz(vp) );
  519. bp->redraw();
  520. break;
  521. case kFnamPatArgIdx:
  522. assert( cmDsvIsType( vp, kStrzDsvFl ) );
  523. bp->pattern_string( cmDsvStrcz(vp) );
  524. break;
  525. case kFnamDirArgIdx:
  526. bp->type( cmDsvBool(vp) ? Fl_File_Btn::kDir_Type_Id : Fl_File_Btn::kFile_Type_Id );
  527. break;
  528. default:
  529. { assert(0); }
  530. }
  531. }
  532. }
  533. void kcApp::_createMlistCtl( const cmDspUiHdr_t* m )
  534. {
  535. const unsigned* varIdArray = cmDsvUIntCMtx(&m->value);
  536. assert( varIdArray != NULL && cmDsvEleCount(&m->value)==kMlstVarCnt);
  537. int x,y,w=0;
  538. int h = varIdArray[kMlstHgtArgIdx];
  539. bool menuBtnFl = h==0;
  540. h = menuBtnFl ? kMenuH : kMenuH * h;
  541. ctl_t* cp = _createCtl(m, kMlstTypeId, x,y,w,h );
  542. Fl_Widget* wdgt;
  543. if(menuBtnFl)
  544. {
  545. cp->u.mlst.mlst = NULL;
  546. wdgt = cp->u.mlst.mbtn = new Fl_Menu_Button(x,y,w,h);
  547. }
  548. else
  549. {
  550. cp->u.mlst.mbtn = NULL;
  551. wdgt = cp->u.mlst.mlst = new Fl_Select_Browser(x,y,w,h);
  552. }
  553. _insertNewCtl(cp, m, wdgt, cp->u.mlst.varIdArray, kMlstVarCnt );
  554. }
  555. kcApp::kcKmRC_t kcApp::_loadMlist( ctl_t* cp, const cmJsonNode_t* np )
  556. {
  557. assert( cmJsonIsArray(np) );
  558. kcKmRC_t rc = kOkKmRC;
  559. unsigned n = cmJsonChildCount(np);
  560. unsigned ri = 0;
  561. // empty the ctl data list
  562. if( cp->u.mlst.mbtn == NULL )
  563. cp->u.mlst.mlst->clear();
  564. else
  565. cp->u.mlst.mbtn->clear();
  566. // for each element (row) in the JSON array
  567. for(ri=0; ri<n && rc==kOkKmRC; ++ri)
  568. {
  569. const cmJsonNode_t* cnp = cmJsonArrayElementC(np,ri);
  570. unsigned m = cmJsonChildCount(cnp);
  571. unsigned bufCharCnt = 511;
  572. cmChar_t buf[ bufCharCnt + 1 ]; // buffer to hold one row of text
  573. cmChar_t* bbp = buf;
  574. cmChar_t* bep = bbp + bufCharCnt;
  575. unsigned j;
  576. buf[0] = 0;
  577. // for each element (column) of row i
  578. for(j=0; j<m; ++j)
  579. {
  580. const cmJsonNode_t* ep = cmJsonArrayElementC(cnp,j);
  581. cmJsRC_t jsRC;
  582. // convert the element to a string
  583. if( (jsRC = cmJsonLeafToString( ep, bbp, bep - bbp )) != kOkJsRC )
  584. {
  585. switch(jsRC)
  586. {
  587. case kBufTooSmallJsRC:
  588. rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"The msg list line character buffer is too small at JSON array element index %i.",ri);
  589. break;
  590. case kInvalidNodeTypeJsRC:
  591. rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"The msg list array element at index %i is not a JSON leaf node.",ri);
  592. break;
  593. default:
  594. rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"JSON to msg list text conversion failed on array element %i.",ri);
  595. break;
  596. }
  597. break;
  598. }
  599. bbp = buf + strlen(buf);
  600. assert(bbp <= bep);
  601. // add the tab column marker
  602. if( j+1 < m )
  603. {
  604. if( bep - bbp < 1 )
  605. rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"The msg list line buffer is too small.");
  606. else
  607. {
  608. *bbp++ = '\t';
  609. *bbp = 0;
  610. }
  611. }
  612. }
  613. // insert the text for row i and skip the title row
  614. // See the _setMListValue() and _ctl_cb() for the associated index incr/decr.
  615. // so that the engine list indexes and UI list indexes match
  616. if( rc == kOkKmRC && ri > 0)
  617. {
  618. if( cp->u.mlst.mbtn==NULL)
  619. cp->u.mlst.mlst->add(buf);
  620. else
  621. cp->u.mlst.mbtn->add(buf);
  622. }
  623. }
  624. if( rc == kOkKmRC )
  625. if( cp->u.mlst.mbtn != NULL )
  626. {
  627. if( cp->u.mlst.sel < cp->u.mlst.mbtn->size() )
  628. cp->u.mlst.mbtn->label(cp->u.mlst.mbtn->text(cp->u.mlst.sel));;
  629. }
  630. return rc;
  631. }
  632. void kcApp::_setMlistValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  633. {
  634. unsigned i=0;
  635. for(i=0; i<kMlstVarCnt; ++i)
  636. if( cp->u.mlst.varIdArray[i] == instVarId )
  637. {
  638. switch(i)
  639. {
  640. case kMlstHgtArgIdx:
  641. break;
  642. case kMlstSelArgIdx:
  643. {
  644. unsigned idx = cmDsvUInt(vp);
  645. // decr. to account for skipping title row
  646. // (see the complementary incrementn in _ctl_cb())
  647. if( idx > 0 )
  648. --idx;
  649. if( cp->u.mlst.mbtn==NULL)
  650. cp->u.mlst.mlst->value(idx);
  651. else
  652. {
  653. cp->u.mlst.sel = idx;
  654. if( cp->u.mlst.sel < cp->u.mlst.mbtn->size() )
  655. {
  656. cp->u.mlst.mbtn->value(cp->u.mlst.sel);
  657. cp->u.mlst.mbtn->label( cp->u.mlst.mbtn->text(cp->u.mlst.sel) );
  658. }
  659. }
  660. cp->wdgtPtr->redraw();
  661. }
  662. break;
  663. case kMlstLstArgIdx:
  664. _loadMlist( cp, cmDsvJson(vp) );
  665. break;
  666. default:
  667. { assert(0); }
  668. }
  669. }
  670. }
  671. // create a meter ctl at the request of the engine
  672. void kcApp::_createMeter( const cmDspUiHdr_t* m )
  673. {
  674. int x,y,w=0,h=15;
  675. ctl_t* cp = _createCtl(m,kMetrTypeId, x,y,w,h);
  676. if( cp->mstrFl )
  677. cp->u.metr.prog = new Fl_Vert_Progress(x,y,w,h);
  678. else
  679. cp->u.metr.prog = new Fl_Progress(x,y,w,h);
  680. cp->u.metr.prog->color( fl_rgb_color((unsigned char)256),fl_rgb_color((unsigned char)128));
  681. _insertNewCtl(cp,m,cp->u.metr.prog,cp->u.metr.varIdArray,kMetrVarCnt);
  682. }
  683. // handle meter value msg's arriving from the engine
  684. void kcApp::_setMeterValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  685. {
  686. unsigned i = 0;
  687. Fl_Progress* sp = cp->u.metr.prog;
  688. bool redrawFl = false;
  689. for(i=0; i<kMetrVarCnt; ++i)
  690. if( cp->u.metr.varIdArray[i] == instVarId )
  691. {
  692. switch(i)
  693. {
  694. case kMetrMinArgIdx:
  695. sp->minimum(cmDsvGetDouble(vp));
  696. redrawFl = true;
  697. break;
  698. case kMetrMaxArgIdx:
  699. sp->maximum(cmDsvGetDouble(vp));
  700. redrawFl = true;
  701. break;
  702. case kMetrValArgIdx:
  703. {
  704. double v = cmDsvGetDouble(vp);
  705. if( sp->value() != v )
  706. {
  707. sp->value(v);
  708. redrawFl = true;
  709. }
  710. break;
  711. }
  712. case kMetrLblArgIdx:
  713. {
  714. int ww=0,hh=0;
  715. sp->copy_label( cmDsvStrcz(vp) );
  716. sp->align(FL_ALIGN_RIGHT);
  717. sp->measure_label(ww,hh);
  718. sp->resize( sp->x(), sp->y(), sp->w() - ww, sp->h());
  719. redrawFl = true;
  720. }
  721. break;
  722. default:
  723. { assert(0); }
  724. }
  725. break;
  726. }
  727. if( redrawFl )
  728. sp->redraw();
  729. }
  730. // create a button ctl at the request of the engine
  731. void kcApp::_createButton( const cmDspUiHdr_t* m )
  732. {
  733. int x,y,w=0,h=0;
  734. ctl_t* cp = _createCtl(m,kButnTypeId, x,y,w,h);
  735. cp->u.butn.butn = new Fl_Button(x,y,w,h);
  736. _insertNewCtl(cp,m,cp->u.butn.butn,cp->u.butn.varIdArray,kButnVarCnt);
  737. }
  738. // handle button value msg's arriving from the engine
  739. void kcApp::_setButtonValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  740. {
  741. unsigned i = 0;
  742. Fl_Button* sp = cp->u.butn.butn;
  743. bool redrawFl = false;
  744. for(i=0; i<kButnVarCnt; ++i)
  745. if( cp->u.butn.varIdArray[i] == instVarId )
  746. {
  747. switch(i)
  748. {
  749. case kButnValArgIdx:
  750. cp->u.butn.val = cmDsvGetDouble(vp);
  751. break;
  752. case kButnLblArgIdx:
  753. {
  754. sp->copy_label( cmDsvStrcz(vp) );
  755. redrawFl = true;
  756. }
  757. break;
  758. default:
  759. { assert(0); }
  760. }
  761. break;
  762. }
  763. if( redrawFl )
  764. sp->redraw();
  765. }
  766. // create a button ctl at the request of the engine
  767. void kcApp::_createCheck( const cmDspUiHdr_t* m )
  768. {
  769. int x,y,w=0,h=0;
  770. ctl_t* cp = _createCtl(m,kChckTypeId, x,y,w,h);
  771. cp->u.chck.chck = new Fl_Check_Button(x,y,w,h);
  772. _insertNewCtl(cp,m,cp->u.chck.chck,cp->u.chck.varIdArray,kChckVarCnt);
  773. }
  774. // handle check button value msg's arriving from the engine
  775. void kcApp::_setCheckValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  776. {
  777. unsigned i = 0;
  778. Fl_Button* sp = cp->u.chck.chck;
  779. bool redrawFl = false;
  780. for(i=0; i<kChckVarCnt; ++i)
  781. if( cp->u.chck.varIdArray[i] == instVarId )
  782. {
  783. switch(i)
  784. {
  785. case kChckValArgIdx:
  786. cp->u.chck.val = cmDsvGetDouble(vp);
  787. cp->u.chck.chck->value(cmDsvGetDouble(vp)>0);
  788. break;
  789. case kChckLblArgIdx:
  790. {
  791. int ww=0,hh=0;
  792. sp->copy_label( cmDsvStrcz(vp) );
  793. sp->align(FL_ALIGN_RIGHT);
  794. sp->measure_label(ww,hh);
  795. sp->resize( sp->x(), sp->y(), sp->w() - ww, sp->h());
  796. redrawFl = true;
  797. }
  798. break;
  799. default:
  800. { assert(0); }
  801. }
  802. break;
  803. }
  804. if( redrawFl )
  805. sp->redraw();
  806. }
  807. void kcApp::_createLabel( const cmDspUiHdr_t* m )
  808. {
  809. int x,y,w=0,h=0;
  810. ctl_t* cp = _createCtl(m,kLablTypeId, x,y,w,h);
  811. cp->u.labl.box = new Fl_Box(x,y,w,h);
  812. _insertNewCtl(cp,m,cp->u.labl.box,cp->u.labl.varIdArray,kLablVarCnt);
  813. }
  814. void kcApp::_setLabelValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  815. {
  816. unsigned i = 0;
  817. Fl_Box* sp = cp->u.labl.box;
  818. bool redrawFl = false;
  819. for(i=0; i<kLablVarCnt; ++i)
  820. if( cp->u.labl.varIdArray[i] == instVarId )
  821. {
  822. switch(i)
  823. {
  824. case kLablValArgIdx:
  825. sp->copy_label(cmDsvStrcz(vp));
  826. redrawFl = true;
  827. break;
  828. case kLablAlignArgIdx:
  829. switch( cmDsvUInt(vp) )
  830. {
  831. case kRightAlignDuiId:
  832. sp->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE);
  833. break;
  834. case kLeftAlignDuiId:
  835. sp->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
  836. break;
  837. case kCenterAlignDuiId:
  838. sp->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE);
  839. break;
  840. default:
  841. { assert(0); }
  842. }
  843. redrawFl = true;
  844. break;
  845. default:
  846. {assert(0);}
  847. }
  848. }
  849. if( redrawFl )
  850. sp->redraw();
  851. }
  852. void kcApp::_createTmln( const cmDspUiHdr_t* m )
  853. {
  854. int x,y,w=0,h=0;
  855. page_t* pg = _createPage("TimeLine");
  856. ctl_t* cp = _createCtl(m, kTmlnTypeId, x,y,w,h, true );
  857. w = pg->grp->w();
  858. h = pg->grp->h();
  859. cp->u.tmln.tlctl = new tlCtl(&_ctx,this,_menu,this);
  860. // currently we only support one time-line control because
  861. // we have not yet implmenented a method of providing
  862. // timer callbacks to a list of UI controls
  863. assert( _tlCtl == NULL );
  864. _tlCtl = cp->u.tmln.tlctl;
  865. Fl_Widget* wdgt = cp->u.tmln.tlctl->initTimeLineCtlr(x,y,w,h);
  866. _insertNewCtl(cp,m,wdgt,cp->u.tmln.varIdArray,kTmlnVarCnt);
  867. }
  868. void kcApp::_setTmlnValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
  869. {
  870. unsigned i=0;
  871. //tlCtl* tp = cp->u.tmln.tlctl;
  872. for(i=0; i<kTmlnVarCnt; ++i)
  873. if( cp->u.tmln.varIdArray[i] == instVarId )
  874. {
  875. switch(i)
  876. {
  877. case kTmlnSelArgIdx:
  878. //tp->value( cmDsvStrcz(vp));
  879. break;
  880. case kTmlnFileArgIdx:
  881. {
  882. const char* fn;
  883. if((fn = cmDsvStrcz(vp)) != NULL )
  884. {
  885. cp->u.tmln.tlctl->openTlFile(fn);
  886. //cp->u.tmln.tlctl->redraw();
  887. }
  888. }
  889. break;
  890. case kTmlnPathArgIdx:
  891. {
  892. const char* path;
  893. if((path = cmDsvStrcz(vp)) != NULL )
  894. {
  895. cp->u.tmln.tlctl->setAudioFilePath(path);
  896. //cp->u.tmln.tlctl->redraw();
  897. }
  898. }
  899. break;
  900. default:
  901. { assert(0); }
  902. }
  903. }
  904. }
  905. void kcApp::_newColumn( const cmDspUiHdr_t* m )
  906. {
  907. _incrColW = cmDsvGetUInt(&m->value);
  908. if( _incrColW == 0 )
  909. _incrColW = 200;
  910. }
  911. void kcApp::_insertAudioSysCfgLabel(unsigned long idx, const char* label)
  912. {
  913. if( idx == 0 )
  914. as_btn->clear();
  915. as_btn->add(label,0,NULL,(void*)idx,0);
  916. }
  917. void kcApp::_insertDeviceLabel( unsigned long devIdx, bool inputFl, const cmChar_t* label )
  918. {
  919. Fl_Menu_Button* bp = inputFl ? ai_btn : ao_btn;
  920. // ??? if( idx == 0 )
  921. // bp->clear();
  922. bp->add(label,0,NULL,(void*)devIdx,0);
  923. }
  924. void kcApp::_insertProgramLabel( unsigned long idx, const cmChar_t* label )
  925. {
  926. if( idx == 0 )
  927. pgm_btn->clear();
  928. pgm_btn->add(label,0,NULL,(void*)idx,0);
  929. }
  930. void kcApp::_insertSubSysCnt( unsigned long subSysCnt )
  931. {
  932. long unsigned i;
  933. int bufByteCnt = 15;
  934. char buf[bufByteCnt+1];
  935. for(i=0; i<subSysCnt+1; ++i)
  936. {
  937. const char* label;
  938. unsigned long id;
  939. if( i==0 )
  940. {
  941. label = "All";
  942. id = cmInvalidIdx;
  943. }
  944. else
  945. {
  946. snprintf(buf,bufByteCnt,"%li",i);
  947. label = buf;
  948. id = i-1;
  949. }
  950. ss_btn->add(label,0,NULL,(void*)id);
  951. }
  952. ss_btn->value(0);
  953. ss_btn->copy_label( ss_btn->mvalue()->label() );
  954. }
  955. unsigned kcApp::_getCurAudioSubSysIdx()
  956. {
  957. const Fl_Menu_Item* mip;
  958. unsigned retVal = 0;
  959. if( (mip = ss_btn->mvalue()) != NULL)
  960. retVal = mip->argument();
  961. return retVal;
  962. }
  963. void kcApp::_setMenuButton( Fl_Menu_Button* b, unsigned value, const char* dfltLabel )
  964. {
  965. const Fl_Menu_Item* mip;
  966. bool fl = value != cmInvalidIdx;
  967. // if value is a valid menu index then make it the current menu selection
  968. if( fl )
  969. b->value(value);
  970. // get the new current menu item and set its label
  971. if( (mip = b->mvalue()) != NULL )
  972. b->copy_label( fl ? mip->label() : dfltLabel );
  973. }
  974. void kcApp::_setDeviceMenuButton( unsigned asSubIdx, bool inputFl, unsigned devIdx )
  975. {
  976. // don't set the device name if the currenly selected sub-system is not the
  977. // same as the one the device is assigned to
  978. if( _getCurAudioSubSysIdx() != asSubIdx )
  979. return;
  980. Fl_Menu_Button* mbp = inputFl ? ai_btn : ao_btn;
  981. const Fl_Menu_Item* map = mbp->menu();
  982. unsigned n = mbp->size();
  983. unsigned i;
  984. void* di = (void*)devIdx;
  985. for(i=0; i<n; ++i)
  986. if( map[i].user_data() == di )
  987. break;
  988. if( i < n )
  989. {
  990. _setMenuButton(mbp,i,"<not found>");
  991. }
  992. }
  993. void kcApp::_setSampleRateBtn( unsigned value )
  994. {
  995. unsigned i;
  996. unsigned n = sr_btn->size();
  997. for(i=0; i<n-1; ++i)
  998. {
  999. if( sr_btn->menu()[i].argument() == value )
  1000. {
  1001. sr_btn->value(i);
  1002. sr_btn->copy_label( sr_btn->mvalue()->label() );
  1003. return;
  1004. }
  1005. }
  1006. sr_btn->copy_label("Sample Rate?");
  1007. }
  1008. void kcApp::_updateMeters( unsigned asSubIdx, unsigned devIdx, unsigned inFl, const double* meterArray, unsigned meterCnt )
  1009. {
  1010. unsigned i;
  1011. for(i=0; i<meterCnt; ++i)
  1012. {
  1013. ctl_t* cp;
  1014. cmDspValue_t v;
  1015. unsigned instId = cmAudioSysFormUiInstId(devIdx,i,inFl,kMeterUiAsId);
  1016. if((cp = _findCtl(instId,asSubIdx,true)) != NULL )
  1017. {
  1018. cmDsvSetDouble(&v,meterArray[i]);
  1019. _setMeterValue(cp, kMetrValArgIdx, &v);
  1020. }
  1021. }
  1022. }
  1023. void kcApp::_printStatusCounts()
  1024. {
  1025. const ss_t* ssp = _ssArray;
  1026. printf("Upd:%i Wake:%i Msg:%i Audio:%i\n",ssp->cnt[kUpdateSsIdx],ssp->cnt[kWakeupSsIdx],ssp->cnt[kMsgSsIdx],ssp->cnt[kAudioCbSsIdx]);
  1027. }
  1028. void kcApp::_updateSsStatusIndicator( unsigned asSubIdx, unsigned indicatorIdx, unsigned cnt )
  1029. {
  1030. ss_t* ss = _ssArray + asSubIdx;
  1031. float val = ss->cnt[indicatorIdx] != cnt;
  1032. ss->cnt[indicatorIdx] = cnt;
  1033. if( ss->prog[indicatorIdx]->value() != val )
  1034. {
  1035. ss->prog[indicatorIdx]->value(val);
  1036. ss->prog[indicatorIdx]->redraw();
  1037. }
  1038. }
  1039. void kcApp::_handleStatusMsg(const cmAudioSysStatus_t* st, const double* iMeterArray, const double* oMeterArray )
  1040. {
  1041. //unsigned asSubIdx = ((const unsigned*)msgBuf)[0];
  1042. //const cmAudioSysStatus_t* st = (const cmAudioSysStatus_t*)(msgBuf + (2 * sizeof(unsigned)));
  1043. //const double* iMeterArray = (const double*)(st + 1);
  1044. //const double* oMeterArray = iMeterArray + st->iMeterCnt;
  1045. _updateMeters(st->asSubIdx, st->iDevIdx,1,iMeterArray,st->iMeterCnt);
  1046. _updateMeters(st->asSubIdx, st->oDevIdx,0,oMeterArray,st->oMeterCnt);
  1047. assert( st->asSubIdx < _ssCnt );
  1048. _updateSsStatusIndicator(st->asSubIdx, kUpdateSsIdx, st->updateCnt );
  1049. _updateSsStatusIndicator(st->asSubIdx, kWakeupSsIdx, st->wakeupCnt );
  1050. _updateSsStatusIndicator(st->asSubIdx, kMsgSsIdx, st->msgCbCnt );
  1051. _updateSsStatusIndicator(st->asSubIdx, kAudioCbSsIdx,st->audioCbCnt );
  1052. }
  1053. void kcApp::_clearStatusIndicators()
  1054. {
  1055. for(unsigned i=0; i<_ssCnt; ++i)
  1056. {
  1057. _updateSsStatusIndicator(i, kUpdateSsIdx, _ssArray[i].cnt[kUpdateSsIdx] );
  1058. _updateSsStatusIndicator(i, kWakeupSsIdx, _ssArray[i].cnt[kWakeupSsIdx] );
  1059. _updateSsStatusIndicator(i, kMsgSsIdx, _ssArray[i].cnt[kMsgSsIdx] );
  1060. _updateSsStatusIndicator(i, kAudioCbSsIdx,_ssArray[i].cnt[kAudioCbSsIdx] );
  1061. }
  1062. }
  1063. // Create a master control UI msg and send it to _handleUiMsg(). This function is intended to
  1064. // mimic the reception of a cmDspUiHdr_t msg from the audio system. It is used to create
  1065. // and send values to the controls on the master page.
  1066. void kcApp::_sendMasterUiMsg( unsigned asSubIdx, unsigned selId, unsigned instId, unsigned instVarId, const cmDspValue_t* vp )
  1067. {
  1068. // Determine the size of the message buffer
  1069. unsigned valByteCnt = cmDsvSerialDataByteCount(vp);
  1070. unsigned bufByteCnt = sizeof(cmDspUiHdr_t) + valByteCnt;
  1071. char buf[ bufByteCnt ];
  1072. cmDspUiHdr_t* h = (cmDspUiHdr_t*)buf;
  1073. h->asSubIdx = asSubIdx;
  1074. h->uiId = cmInvalidId; // the uiId field of master controls is always set to cmInvalidId
  1075. h->selId = selId;
  1076. h->flags = 0;
  1077. h->instId = instId;
  1078. h->instVarId = instVarId;
  1079. // Serialize 'v' into the buffer beginning at the address of h->value.
  1080. // (this function relies on the 'hdr.value' field being the last field in 'h')
  1081. cmDsvSerialize( vp, &h->value, sizeof(cmDspValue_t) + valByteCnt);
  1082. _handleUiMsg(h);
  1083. }
  1084. // Send a value to a control on the master page.
  1085. void kcApp::_sendMasterUiValue( unsigned asSubIdx, unsigned instId, const double* v, unsigned vn, const cmChar_t* text )
  1086. {
  1087. cmDspValue_t val;
  1088. unsigned i;
  1089. for(i=0; i<vn; ++i)
  1090. {
  1091. cmDsvSetDouble(&val,v[i]);
  1092. _sendMasterUiMsg(asSubIdx, kValueDuiId, instId, i, &val );
  1093. }
  1094. if( text != NULL )
  1095. {
  1096. cmDsvSetStrcz(&val,text);
  1097. _sendMasterUiMsg(asSubIdx, kValueDuiId, instId, i, &val );
  1098. }
  1099. }
  1100. // Create a control on the master page.
  1101. void kcApp::_createMasterCtl( unsigned asSubIdx, unsigned selId, unsigned instId, unsigned varCnt, const double* dv, unsigned dn, const cmChar_t* label)
  1102. {
  1103. // Create the control variable id array.
  1104. // This array gives the id's used to identify each control variable.
  1105. unsigned varIdArray[ varCnt ];
  1106. unsigned i;
  1107. cmDspValue_t v;
  1108. // Set the var id's for master controls to be the same as the var indexes.
  1109. for(i=0; i<varCnt; ++i)
  1110. varIdArray[i] = i;
  1111. // Encode varIdArray[] as a cmDsvValue.
  1112. cmDsvSetUIntMtx(&v,varIdArray,varCnt,1);
  1113. // create the control
  1114. _sendMasterUiMsg(asSubIdx, selId, instId, cmInvalidId, &v );
  1115. // set the controls initial configuration
  1116. _sendMasterUiValue(asSubIdx, instId, dv, dn, label );
  1117. }
  1118. void kcApp::_handleSsInitMsg( const cmAudioSysSsInitMsg_t* m, const cmChar_t* inDevLabel, const cmChar_t* outDevLabel )
  1119. {
  1120. unsigned i,j;
  1121. if( _ssCnt == 0 )
  1122. {
  1123. _clearSsArray();
  1124. _ssCnt = m->asSubCnt;
  1125. _ssArray = new ss_t[ _ssCnt ];
  1126. }
  1127. assert( m->asSubIdx < _ssCnt );
  1128. ss_t* ss = _ssArray + m->asSubIdx;
  1129. int x = 20;
  1130. int y = 30 + kMenuH;
  1131. int w = 80;
  1132. int h = 20;
  1133. char lblArray[][10] = { "Update","Wakeup","Mesg","Audio" };
  1134. // create the sub-system status indicators
  1135. for(i=0; i<kProgSsCnt; ++i)
  1136. {
  1137. Fl_Progress* prog = new Fl_Progress(x,y,w,h,NULL);
  1138. prog->color( FL_RED, FL_GREEN );
  1139. prog->minimum(0);
  1140. prog->maximum(1);
  1141. prog->copy_label(lblArray[i]);
  1142. mstr_grp->add(prog);
  1143. ss->cnt[i] = 0;
  1144. ss->prog[i] = prog;
  1145. x += ss->prog[i]->w() + 4;
  1146. }
  1147. for(i=0; i<2; ++i)
  1148. {
  1149. unsigned inFl = i==0;
  1150. unsigned chCnt = inFl ? m->inChCnt : m->outChCnt;
  1151. unsigned devIdx = inFl ? m->inDevIdx : m->outDevIdx;
  1152. double zero = 0;
  1153. for(j=0; j<chCnt; ++j)
  1154. {
  1155. // there are limits on the ranges of the dev and ch due to the need to pack dev/ch/infl/ctl into a 32 bit int.
  1156. assert( devIdx < 0xffff && j < 0x0fff);
  1157. unsigned instId = cmAudioSysFormUiInstId(devIdx,j,inFl,0);
  1158. //printf("ssi:%i instId:0x%x\n",m->asSubIdx,instId+kMeterUiAsId);
  1159. // create the volume slider
  1160. double sv[] = { 3, 0, 0.01, 1 };
  1161. unsigned sn = sizeof(sv)/sizeof(sv[0]);
  1162. _createMasterCtl( m->asSubIdx, kSliderDuiId, instId + kSliderUiAsId, kSldrVarCnt, sv, sn, NULL);
  1163. // create the meter
  1164. double mv[] = { 0, 1.0, 0 };
  1165. unsigned mn = sizeof(mv)/sizeof(mv[0]);
  1166. _createMasterCtl( m->asSubIdx, kMeterDuiId, instId + kMeterUiAsId, kMetrVarCnt, mv, mn, NULL);
  1167. // create the mute button
  1168. _createMasterCtl( m->asSubIdx, kCheckDuiId, instId + kMuteUiAsId, kChckVarCnt, &zero, 1, "M");
  1169. // create the tone button
  1170. _createMasterCtl( m->asSubIdx, kCheckDuiId, instId + kToneUiAsId, kChckVarCnt, &zero, 1, "T");
  1171. // create the pass button
  1172. _createMasterCtl( m->asSubIdx, kCheckDuiId, instId + kPassUiAsId, kChckVarCnt, &zero, 1, "P");
  1173. }
  1174. }
  1175. }
  1176. // handle kValueDuiId messages coming from the engine
  1177. void kcApp::_onRecvValue( const cmDspUiHdr_t* m )
  1178. {
  1179. ctl_t* cp;
  1180. if((cp = _findCtl(m->instId,m->asSubIdx,m->uiId==cmInvalidId)) == NULL )
  1181. return;
  1182. switch( cp->typeId )
  1183. {
  1184. case kNumbTypeId:
  1185. case kSldrTypeId:
  1186. _setSldrValue(cp, m->instVarId, &m->value );
  1187. break;
  1188. case kTextTypeId:
  1189. _setTextValue(cp, m->instVarId, &m->value );
  1190. break;
  1191. case kButnTypeId:
  1192. _setButtonValue(cp, m->instVarId, &m->value);
  1193. break;
  1194. case kChckTypeId:
  1195. _setCheckValue(cp, m->instVarId, &m->value);
  1196. break;
  1197. case kLablTypeId:
  1198. _setLabelValue(cp, m->instVarId, &m->value);
  1199. break;
  1200. case kFnamTypeId:
  1201. _setFnamValue(cp, m->instVarId, &m->value);
  1202. break;
  1203. case kMlstTypeId:
  1204. _setMlistValue(cp, m->instVarId, &m->value);
  1205. break;
  1206. case kMetrTypeId:
  1207. _setMeterValue(cp, m->instVarId, &m->value);
  1208. break;
  1209. case kTmlnTypeId:
  1210. _setTmlnValue(cp, m->instVarId, &m->value);
  1211. break;
  1212. default:
  1213. assert(0);
  1214. }
  1215. }
  1216. // This is the main UI<-Engine msg handler/dispatch function
  1217. void kcApp::_handleUiMsg( const cmDspUiHdr_t* m )
  1218. {
  1219. switch( m->selId )
  1220. {
  1221. case kPrintDuiId:
  1222. cmDsvPrint(&m->value,NULL,&_ctx.rpt);
  1223. break;
  1224. case kNumberDuiId:
  1225. case kSliderDuiId:
  1226. _createSlider(m);
  1227. break;
  1228. case kTextDuiId:
  1229. _createText(m);
  1230. break;
  1231. case kButtonDuiId:
  1232. _createButton(m);
  1233. break;
  1234. case kLabelDuiId:
  1235. _createLabel(m);
  1236. break;
  1237. case kCheckDuiId:
  1238. _createCheck(m);
  1239. break;
  1240. case kFnameDuiId:
  1241. _createFnameCtl(m);
  1242. break;
  1243. case kMsgListDuiId:
  1244. _createMlistCtl(m);
  1245. break;
  1246. case kMeterDuiId:
  1247. _createMeter(m);
  1248. break;
  1249. case kTimeLineDuiId:
  1250. _createTmln(m);
  1251. break;
  1252. case kValueDuiId:
  1253. _onRecvValue(m);
  1254. break;
  1255. case kColumnDuiId:
  1256. _newColumn(m);
  1257. break;
  1258. case kHBorderDuiId:
  1259. _horzBordFl = true;
  1260. break;
  1261. case kPageDuiId:
  1262. _createPage(cmDsvStrcz(&m->value));
  1263. break;
  1264. case kAudioSysCfgDuiId:
  1265. _insertAudioSysCfgLabel(m->instId,cmDsvStrcz(&m->value));
  1266. break;
  1267. case kDeviceDuiId:
  1268. _insertDeviceLabel(m->instId,m->flags,cmDsvStrcz(&m->value));
  1269. break;
  1270. case kProgramDuiId:
  1271. _insertProgramLabel(m->instId,cmDsvStrcz(&m->value));
  1272. break;
  1273. // the below codes are used to notify the application
  1274. // of changes in state of the audio DSP system
  1275. case kSubSysCntDuiId:
  1276. _insertSubSysCnt(cmDsvUInt(&m->value));
  1277. break;
  1278. case kSetAudioCfgDuiId:
  1279. _setMenuButton(as_btn,cmDsvUInt(&m->value),"Audio System Cfg");
  1280. break;
  1281. case kSetAudioDevDuiId:
  1282. _setDeviceMenuButton( m->asSubIdx, m->flags, cmDsvUInt(&m->value) );
  1283. break;
  1284. case kSetSampleRateDuiId:
  1285. _setSampleRateBtn(cmDsvUInt(&m->value));
  1286. break;
  1287. case kSetPgmDuiId:
  1288. _setMenuButton(pgm_btn,cmDsvUInt(&m->value),"Program?");
  1289. _clearCtlList(false);
  1290. break;
  1291. case kEnableDuiId:
  1292. ena_chk->value(m->flags);
  1293. break;
  1294. }
  1295. }
  1296. // Check for and forward any messages sent to the UI
  1297. // that are waiting in the audio DSP msg queue.
  1298. void kcApp::_getEngMsg()
  1299. {
  1300. if( cmAdIfIsValid(_aiH) )
  1301. {
  1302. unsigned i;
  1303. for(i=0; i<10; ++i)
  1304. {
  1305. cmAiRC_t aiRC;
  1306. // cmAdIfDispatchMsgToHost() results in calls to
  1307. // the _s_handleXXX() message handlers
  1308. if((aiRC = cmAdIfDispatchMsgToHost(_aiH)) != kOkAiRC)
  1309. {
  1310. if( aiRC == kNoMsgAiRC )
  1311. break;
  1312. cmErrMsg(&_ctx.err,kEngFailKmRC,"Audio DSP dispatch message request failed.");
  1313. break;
  1314. }
  1315. }
  1316. }
  1317. }
  1318. kcApp* kcApp::_getApp( Fl_Widget* w )
  1319. {
  1320. // walk up the widget tree until the top widget is found
  1321. Fl_Group* gp = w->parent();
  1322. while( gp->parent() != NULL )
  1323. gp=gp->parent();
  1324. // the user data for the top widget is a pointer kcApp()
  1325. return (kcApp*)gp->user_data();
  1326. }
  1327. void kcApp::_testStub()
  1328. {
  1329. /*
  1330. cmAudioFileTest(
  1331. // "/Users/kevin/media/audio/20100819-Kreisberg/fragments/Bass End_21a.wav",
  1332. "/Users/kevin/media/audio/McGill-1/1 Audio Track.aiff",
  1333. "/Users/kevin/src/octave/cm_audio_file_test.m",_ctx.err.rpt );
  1334. */
  1335. //cmSymTblTest(&_ctx);
  1336. //_kcTranslateFile("/Users/kevin/src/kc/src/data/Sec1_14.txt","/Users/kevin/src/kc/src/data/Sec1_14_out.txt",&_ctx);
  1337. //_kcTranslateFile("/Users/kevin/src/kc/src/data/Mix_17-20.txt","/Users/kevin/src/kc/src/data/Mix_17-20_out.txt",&_ctx);
  1338. /*
  1339. ctl_t* cp = _ctlList;
  1340. for(; cp!=NULL; cp=cp->linkPtr)
  1341. printf("%i %i %i\n", cp->instId,cp->asSubIdx,cp->mstrFl );
  1342. */
  1343. _printStatusCounts();
  1344. //cmProcTestNoInit(&_ctx);
  1345. }
  1346. void kcApp::_s_callback(Fl_Widget* wp, void* data)
  1347. { ((kcApp*)data)->_callback(NULL); }
  1348. // this callback is called when the window is closing
  1349. void kcApp::_callback(void* data)
  1350. {
  1351. if( Fl::event() == FL_CLOSE )
  1352. {
  1353. //unsigned cc = _closeCnt;
  1354. ctl_t* cp = _ctlList;
  1355. for(; cp!=NULL; cp=cp->linkPtr)
  1356. if( cp->typeId == kTmlnTypeId )
  1357. delete cp->u.tmln.tlctl;
  1358. _stopTimerFl = true;
  1359. // attempt to shut down the pgm
  1360. //if( audioDspFinalize() != kOkKmRC )
  1361. // ++_closeCnt;
  1362. // the first time the pgm fails to shut down
  1363. // do not allow the pgm to close the main window
  1364. // this will give a chance for the error messages
  1365. // to be diplayed in the console - all successive
  1366. // times the return value from finalizePgm() is
  1367. // ignored and the program is terminated.
  1368. /*
  1369. if( _closeCnt == 1 && cc==0)
  1370. {
  1371. deactivate(); // send a strong hint that a problem occurred
  1372. return;
  1373. }
  1374. */
  1375. // When all windows are windows are closed then the app.
  1376. // will close - so hiding the application window
  1377. // causes the program to close.
  1378. //
  1379. // Note that simply returning from this callback will
  1380. // prevent the application from closing. Because the existence
  1381. // of the callback alone is enough to disable default
  1382. // event handling.
  1383. hide();
  1384. }
  1385. }
  1386. void kcApp::_s_status_timeout_cb(void* userPtr)
  1387. {
  1388. if( ((kcApp*)userPtr)->_status_timeout_cb() )
  1389. Fl::repeat_timeout(TIMER_PERIOD,_s_status_timeout_cb,userPtr);
  1390. }
  1391. bool kcApp::_status_timeout_cb()
  1392. {
  1393. if( cmTsMp1cIsValid(_printqH) )
  1394. _checkPrintQueue();
  1395. if( !_stopTimerFl )
  1396. {
  1397. _getEngMsg();
  1398. if( _tlCtl != NULL )
  1399. _tlCtl->onIdle();
  1400. }
  1401. if( _ssUpdateFl )
  1402. {
  1403. ++_ssPhase;
  1404. if( _ssPhase >= kSsPhaseMax )
  1405. {
  1406. _clearStatusIndicators();
  1407. _ssPhase = 0;
  1408. }
  1409. }
  1410. if( _stopTimerFl==false && cmAdIfIsValid(_aiH) )
  1411. cmAdIfDispatchMsgToHost(_aiH);
  1412. //if( !_stopTimerFl )
  1413. // _getEngStatus();
  1414. return _stopTimerFl==false || cmTsMp1cIsValid(_printqH);
  1415. }
  1416. void kcApp::_s_menu_cb(Fl_Widget *w, void *data)
  1417. { }
  1418. void kcApp::_s_tab_cb(Fl_Widget* w, void* data)
  1419. { ((kcApp*)data)->_tab_cb(w); }
  1420. void kcApp::_tab_cb(Fl_Widget*)
  1421. {
  1422. Fl_Widget* w = tabs->value();
  1423. _ssUpdateFl = w == (Fl_Widget*)mstr_grp;
  1424. _ssPhase = kSsPhaseMax;
  1425. if( cmAdIfIsValid(_aiH) )
  1426. {
  1427. if( cmAdIfEnableStatusNotify(_aiH, _ssUpdateFl ) != kOkAiRC )
  1428. cmErrMsg(&_ctx.err,kEngFailKmRC,"A request to enable/disable status notification failed.");
  1429. }
  1430. }
  1431. void kcApp::_s_btn_cb(Fl_Widget* w, long data)
  1432. {
  1433. _getApp(w)->_btn_cb(w,data);
  1434. }
  1435. void kcApp::_btn_cb(Fl_Widget* w, long data)
  1436. {
  1437. unsigned arg = w->argument();
  1438. switch( arg )
  1439. {
  1440. case kAudDevRptBtnId:
  1441. cmAdIfDeviceReport(_aiH);
  1442. break;
  1443. case kEnableBtnId:
  1444. cmAdIfEnableAudio(_aiH,static_cast<Fl_Check_Button*>(w)->value()!=0);
  1445. break;
  1446. case kAudioSysCfgBtnId:
  1447. cmAdIfSetAudioSysCfg(_aiH,static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
  1448. break;
  1449. case kInAudDevBtnId:
  1450. cmAdIfSetAudioDevice(_aiH,_getCurAudioSubSysIdx(),true,static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
  1451. break;
  1452. case kOutAudDevBtnId:
  1453. cmAdIfSetAudioDevice(_aiH,_getCurAudioSubSysIdx(),false,static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
  1454. break;
  1455. case kPgmBtnId:
  1456. cmAdIfLoadProgram(_aiH,_getCurAudioSubSysIdx(),static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
  1457. break;
  1458. case kSubSystemIdxBtnId:
  1459. // TODO: change device and sample rate menu's to reflect the device and srate assigned to this asSubIdx.
  1460. break;
  1461. case kSrateBtnId:
  1462. cmAdIfSetSampleRate(_aiH,_getCurAudioSubSysIdx(),static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
  1463. break;
  1464. case kTestBtnId:
  1465. _testStub();
  1466. break;
  1467. default:
  1468. { assert(0); }
  1469. }
  1470. }
  1471. void kcApp::_s_ctl_cb(Fl_Widget* w, void* data)
  1472. {
  1473. ctl_t* cp = ((ctl_t*)data);
  1474. cp->thisPtr->_ctl_cb(cp);
  1475. }
  1476. void kcApp::_ctl_cb(ctl_t* cp)
  1477. {
  1478. cmDspValue_t value = cmDspNullValue;
  1479. unsigned instVarId = cmInvalidId;
  1480. switch( cp->typeId )
  1481. {
  1482. case kNumbTypeId:
  1483. case kSldrTypeId:
  1484. instVarId = cp->u.sldr.varIdArray[ kSldrValArgIdx ];
  1485. cmDsvSetDouble(&value,cp->u.sldr.val->value());
  1486. break;
  1487. case kTextTypeId:
  1488. instVarId = cp->u.text.varIdArray[ kTextValArgIdx ];
  1489. cmDsvSetStrz(&value,(cmChar_t*)cp->u.text.text->value());
  1490. break;
  1491. case kButnTypeId:
  1492. instVarId = cp->u.butn.varIdArray[ kButnValArgIdx ];
  1493. cmDsvSetDouble(&value,cp->u.butn.val);
  1494. break;
  1495. case kChckTypeId:
  1496. {
  1497. bool fl = cp->u.chck.chck->value();
  1498. instVarId = cp->u.chck.varIdArray[ kChckValArgIdx ];
  1499. cmDsvSetDouble(&value, fl ? 1.0 : 0.0 );
  1500. }
  1501. break;
  1502. case kFnamTypeId:
  1503. instVarId = cp->u.fnam.varIdArray[ kFnamValArgIdx ];
  1504. cmDsvSetStrz( &value, (cmChar_t*)cp->u.fnam.fnam->filename());
  1505. break;
  1506. case kMlstTypeId:
  1507. instVarId = cp->u.mlst.varIdArray[ kMlstSelArgIdx ];
  1508. // add one to the selected index to account for skipping title row
  1509. if( cp->u.mlst.mbtn==NULL)
  1510. {
  1511. unsigned idx = cp->u.mlst.mlst->value();
  1512. //printf("list:%i\n",idx);
  1513. cmDsvSetUInt( &value, idx);
  1514. }
  1515. else
  1516. {
  1517. unsigned idx = cp->u.mlst.mbtn->value();
  1518. //printf("mbtn:%i\n",idx);
  1519. cmDsvSetUInt( &value, idx + 1);
  1520. cp->u.mlst.mbtn->label( cp->u.mlst.mbtn->text(idx) );
  1521. }
  1522. break;
  1523. case kTmlnTypeId:
  1524. {
  1525. instVarId = cp->u.text.varIdArray[ kTmlnSelArgIdx ];
  1526. unsigned selMarkerId = cp->u.tmln.tlctl->timeLineSelectedMarkerId();
  1527. cmDsvSetUInt(&value, selMarkerId );
  1528. }
  1529. break;
  1530. default:
  1531. {assert(0);}
  1532. }
  1533. if( cmAdIfSendMsgToAudioDSP(
  1534. _aiH,
  1535. cp->asSubIdx,
  1536. cp->mstrFl ? kUiMstrSelAsId : kUiSelAsId,
  1537. kValueDuiId,
  1538. 0,
  1539. cp->instId,
  1540. instVarId,
  1541. &value) != kOkAiRC)
  1542. {
  1543. cmErrMsg(&_ctx.err,kEngFailKmRC,"An attempt to send a UI message to the audio DSP interface failed.");
  1544. }
  1545. }
  1546. void kcApp::vprint(const char* fmt, va_list vl )
  1547. {
  1548. int bufCharCnt = 511;
  1549. char buf[bufCharCnt+1];
  1550. int n = vsnprintf(buf,bufCharCnt,fmt,vl);
  1551. if( n > 0 )
  1552. {
  1553. // if the print queue exists (it might not during startup or shutdown) ...
  1554. if( cmTsMp1cIsValid(_printqH) )
  1555. {
  1556. // ... enqueue the text to print
  1557. if( cmTsMp1cEnqueueMsg(_printqH,buf,n+1) != kOkThRC && _printFl==0 )
  1558. {
  1559. // use _printFl to guard against recursion which would eventually overflow the stack.
  1560. ++_printFl;
  1561. cmErrMsg(&_ctx.err,kQueueFailKmRC,"Print enqueue failed on msg:%s.",buf);
  1562. --_printFl;
  1563. }
  1564. }
  1565. else
  1566. _print(buf); // ... otherwise just send the text directly to the output console
  1567. }
  1568. }
  1569. void kcApp::print( const char* fmt, ... )
  1570. {
  1571. va_list vl;
  1572. va_start(vl,fmt);
  1573. vprint(fmt,vl);
  1574. va_end(vl);
  1575. }
  1576. void kcApp::_s_print( void* userPtr, const char* text )
  1577. { ((kcApp*)userPtr)->print(text); }
  1578. cmRC_t kcApp::_s_print_queue_cb(void* userCbPtr, unsigned msgByteCnt, const void* msgDataPtr )
  1579. {
  1580. kcApp* ap = (kcApp*)userCbPtr;
  1581. ap->_print((const char*)msgDataPtr);
  1582. return cmOkRC;
  1583. }
  1584. void kcApp::_checkPrintQueue()
  1585. {
  1586. while( cmTsMp1cMsgWaiting(_printqH) )
  1587. if( cmTsMp1cDequeueMsg(_printqH, NULL, 0) != kOkThRC && _printFl==0 )
  1588. {
  1589. ++_printFl;
  1590. cmErrMsg(&_ctx.err,kPrintQueFailKmRC,"Print dequeue failed.");
  1591. --_printFl;
  1592. }
  1593. }
  1594. void kcApp::_print( const char* text )
  1595. {
  1596. if( con != NULL )
  1597. con->insert(text);
  1598. #ifndef NDEBUG
  1599. fputs(text,stdout);
  1600. #endif
  1601. }