12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207 |
- #include <FL/Fl.H>
- #include <FL/Fl_Double_Window.H>
- #include <FL/Fl_Menu_Item.H>
- #include <Fl/Fl_Menu_Bar.H>
- #include <Fl/Fl_Button.H>
- #include <Fl/Fl_Check_Button.H>
- #include <Fl/Fl_Text_Buffer.H>
- #include <Fl/Fl_Text_Display.H>
- #include <Fl/Fl_Box.H>
- #include <Fl/Fl_Tabs.H>
- #include <Fl/Fl_File_Chooser.H>
- #include <Fl/Fl_Value_Slider.H>
- #include <Fl/Fl_Menu_Button.H>
- #include <Fl/Fl_Select_Browser.H>
- #include <Fl/Fl_Value_Input.H>
- #include <Fl/Fl_Progress.H>
-
- #include "Fl_Vert_Progress.h"
- #include "Fl_File_Btn.h"
- #include "Fl_Splitter.h"
-
- #include "cmGlobal.h"
- #include "cmFloatTypes.h"
- #include "cmRpt.h"
- #include "cmErr.h"
- #include "cmCtx.h"
- #include "cmMem.h"
- #include "cmMallocDebug.h"
- #include "cmLinkedHeap.h"
- #include "cmText.h"
- #include "cmSymTbl.h"
- #include "cmJson.h"
- #include "cmFileSys.h"
- #include "cmPrefs.h"
- #include "cmAudioFile.h"
- #include "cmThread.h"
- #include "cmProcTest.h"
-
- #include "cmDspValue.h"
- #include "cmMsgProtocol.h"
- #include "cmAudDspIF.h"
- #include "cmAudDspLocal.h"
- #include "kcApp.h"
-
- #include "cmAudioFile.h"
- #include "cmAudioFileMgr.h"
-
- #include "cmMidi.h"
- #include "cmMidiFile.h"
- #include "cmTimeLine.h"
- #include "cmScore.h"
- #include "cmGr.h"
- #include "cmGrDevCtx.h"
- #include "cmGrPlot.h"
- #include "cmGrPage.h"
- #include "cmGrDevDrvFltk.h"
- #include "cmGrDevDrvCairoFltk.h"
- #include "cmGrWidgetFltk.h"
-
- #include "Fl_CbLinker.h"
-
- #include "cmGrPlotPageFltk.h"
- #include "cmGrPlotCtlrFltk.h"
- #include "gvHashFunc.h"
- #include "cmGrTlCtlrFltk.h"
- #include "cmGrScCtlrFltk.h"
-
- #include "cmdIf.h"
- #include "tlCtl.h"
-
- #define TIMER_PERIOD (1.0/20.0) // 50ms
-
-
- kcApp::kcApp(int w, int h, const char *l, int argc, char *argv[])
- : Fl_Double_Window(w, h, l),
- splt(NULL),_menu(NULL),
- _adlH(cmAdlNullHandle),_aiH(cmAiNullHandle),
- _statIdx(0),_pageList(NULL),_ctlList(NULL),_prH(cmPrNullHandle),_prefsFn(NULL),
- _stopTimerFl(false),_jsH(cmJsonNullHandle),_newPageFl(true),_incrColW(0),_colW(0),_horzBordFl(false),_horzBord(0),
- _closeCnt(0),_ssCnt(0),_ssArray(0),_ssPhase(0),_ssUpdateFl(false),_printqH(cmTsQueueNullHandle)
- {
- // install a callback to cleanup when the app window closes
- // (the btn callbacks and _getApp() rely on a pointer to 'this' being found in kcApp.user_data())
- callback(_s_callback,this);
-
- // the main window is divided between the menu bar on top
- // and a horizontal splitter on the bottom
- begin();
- _createMenu(w,kMenuH);
- splt = new Fl_HSplitter(0, kMenuH, w, h-kStatusH-kMenuH, h-kStatusH-kMenuH-100);
- end();
-
- // Create a text display object for console output and
- // add it to the lower splitter area
- buf = new Fl_Text_Buffer();
- con = new Fl_Text_Display(splt->container2->x(),splt->container2->y(),splt->container2->w(),splt->container2->h());
- con->buffer(buf);
- splt->container2->add(con);
-
- // Create a tab view and added it to the upper splitter area
- tabs = new Fl_Tabs(splt->container1->x(),splt->container1->y(),splt->container1->w(),splt->container1->h());
- tabs->callback(_s_tab_cb,this);
-
- splt->container1->add(tabs);
-
- int tx,ty,th,tw;
- tabs->client_area(tx,ty,tw,th);
-
- // Create the 'Setup' tab group
- tabs->begin();
- Fl_Group* setup_grp = new Fl_Group(tx,ty,tw,th,"Setup");
- _createSetupDlg(setup_grp);
- tabs->end();
-
-
- tabs->begin();
- mstr_grp = new Fl_Group(tx,ty,tw,th,"Master");
- tabs->end();
-
- // Create the 'Controls' tab group
- /*
- tabs->begin();
- ctl_grp = new Fl_Group(tx,ty,tw,th,"Controls");
- ctl_grp->begin();
- Fl_Box* bx = new Fl_Box(FL_NO_BOX,ctl_grp->x()+ctl_grp->w(),ctl_grp->y()+ctl_grp->h(),1,1,NULL);
- ctl_grp->resizable(bx);
- ctl_grp->end(); tabs->end();
- */
-
- // Create an empty tab group and make it resizable
- // to prevent the other tab groups from being resizable.
- tabs->begin();
- Fl_Group* wdgt = new Fl_Group(tx,ty+30,1,1);
- tabs->resizable(wdgt); // make other tabs non-resizable
- tabs->end();
-
-
- // make the splitter the resizable group element (thereby making the menu non-resizable).
- // see:http://fltk.org/articles.php?L415+I0+T+M1000+P1
- resizable(splt);
- show(argc, argv);
-
-
- // initialize the audio DSP system
- audioDspInitialize(&_ctx,_s_print,this);
-
- // install a timer to check for messages from the engine
- Fl::add_timeout(TIMER_PERIOD,_s_status_timeout_cb,this);
-
-
- }
-
- kcApp::~kcApp()
- {
- _clearCtlList(true);
- _clearSsArray();
- }
-
-
- // this function is only called from the constructor
- kcApp::kcKmRC_t kcApp::audioDspInitialize(cmCtx_t* ctx, cmRptPrintFunc_t printFunc, void* printFuncArg)
- {
- kcKmRC_t rc = kOkKmRC;
-
- // initialize the heap check library
- bool memDebugFl = cmDEBUG_FL;
- unsigned memPadByteCnt = memDebugFl ? 8 : 0;
- unsigned memAlignByteCnt = 16;
- unsigned memFlags = memDebugFl ? (kTrackMmFl | kDeferFreeMmFl | kFillUninitMmFl) : 0;
-
- cmCtxSetup(ctx,"KC Main",printFunc,printFunc,printFuncArg,memPadByteCnt,memAlignByteCnt,memFlags);
-
- cmMdInitialize( memPadByteCnt, memAlignByteCnt, memFlags, &ctx->rpt );
-
- cmTsInitialize(ctx);
-
- cmFsInitialize( ctx, "kc" );
-
- cmJsonInitialize(&_jsH,&_ctx);
-
- //_loadPrefs(ctx);
-
- // create the print queue
- if( cmTsQueueCreate( &_printqH, 4*8192, kcApp::_s_print_queue_cb, this, &_ctx.rpt ) != kOkThRC )
- cmErrMsg(&ctx->err,kPrintQueFailKmRC,"Print queue creation failed.");
-
- cmAdIfDispatch_t r;
- r.cbDataPtr = this;
- r.ssInitFunc = _s_handleSsInitMsg;
- r.statusFunc = _s_handleStatusMsg;
- r.uiFunc = _s_handleUiMsg;
-
- if( cmAudDspLocalAllocate(ctx,&_adlH,&r) != kOkAdlRC )
- {
- rc = cmErrMsg(&ctx->err,kEngFailKmRC,"The audio DSP local server allocation failed.");
- goto errLabel;
- }
-
- if(cmAdIfIsValid(_aiH = cmAudDspLocalIF_Handle(_adlH)) == false )
- {
- rc = cmErrMsg(&ctx->err,kEngFailKmRC,"The audio DSP interface handle is not valid.");
- goto errLabel;
- }
-
- errLabel:
- return rc;
- }
-
- bool kcApp::audioDspIsValid()
- { return cmAudDspLocalIsValid(_adlH) && cmAdIfIsValid(_aiH); }
-
- kcApp::kcKmRC_t kcApp::audioDspFinalize()
- {
- kcKmRC_t rc = kOkKmRC;
-
- _stopTimerFl = true;
-
- if( cmJsonFinalize(&_jsH) != kOkJsRC )
- rc = cmErrMsg(&_ctx.err,kJsonFailKmRC,"JSON object finalization failed.");
-
- // If the preferences are dirty or the prefs file does not exist then write them
- if( cmPrefsIsValid(_prH) )
- {
-
- if( _prefsFn != NULL && (cmPrefsIsValid(_prH) && (cmPrefsIsDirty(_prH) || cmFsIsFile(_prefsFn)==false)) )
- if( cmPrefsWrite(_prH,_prefsFn) != kOkPrRC )
- rc = cmErrMsg(&_ctx.err,kPrefWriteFailKmRC,"Preference save failed on file '%s'.",_prefsFn);
-
- if( cmPrefsFinalize(&_prH) != kOkPrRC )
- rc = cmErrMsg(&_ctx.err,kPrefFailKmRC,"Prefrence finalization failed.");
-
- }
-
- // finalize the real-time system
- //rc = stopEngine(_ctx,*hp);
-
- // release the engine
- if( cmAudDspLocalFree(&_adlH) != kOkAdlRC )
- rc = cmErrMsg(&_ctx.err,kEngFailKmRC,"Audio DSP release failed.");
-
- // print any pending text in the print queue
- _checkPrintQueue();
-
- // the app threads are stopped so it is safe to stop using the print queue
- if( cmTsQueueDestroy(&_printqH) == kOkThRC )
- _printqH = cmTsQueueNullHandle;
- else
- cmErrMsg(&_ctx.err,kPrintQueFailKmRC,"Print queue destroy failed.");
-
- // finalize the file system
- cmFsFinalize();
-
- cmTsFinalize();
-
- // report memory mgr errors
- if( cmMdReport( kIgnoreNormalMmFl ) != kOkMmRC )
- rc = kMemFailKmRC;
-
- // finalize the memory manager
- if( cmMdFinalize() != kOkMmRC )
- rc = kMemFailKmRC;
-
- return rc;
- }
-
-
- void kcApp::resize(int x, int y, int w, int h)
- {
- Fl_Double_Window::resize(x, y, w, h);
- splt->resize(0, kMenuH, w, h-kStatusH);
- }
-
-
- void kcApp::_createSetupDlg( Fl_Group* grp )
- {
- int ctl_width = 200;
- int vBord = 5;
- int xx = grp->x() + 5;
- int yy = grp->y() + vBord;
-
- grp->begin();
-
- Fl_Button* btn = new Fl_Button(xx,yy,200,kMenuH,"Audio Device Report");
- btn->callback( _s_btn_cb, kAudDevRptBtnId );
- yy += btn->h() + vBord;
-
- as_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Audio System Cfg");
- as_btn->callback( _s_btn_cb, kAudioSysCfgBtnId);
- yy += as_btn->h() + vBord;
-
- ai_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Audio Input Devices");
- ai_btn->callback( _s_btn_cb, kInAudDevBtnId);
- yy += ai_btn->h() + vBord;
-
- ao_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Audio Output Devices");
- ao_btn->callback( _s_btn_cb, kOutAudDevBtnId);
- yy += ao_btn->h() + vBord;
-
- pgm_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Programs");
- pgm_btn->callback( _s_btn_cb, kPgmBtnId);
- yy += pgm_btn->h() + vBord;
-
- ss_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Sub-System");
- ss_btn->callback( _s_btn_cb, kSubSystemIdxBtnId);
- yy += ss_btn->h() + vBord;
-
- sr_btn = new Fl_Menu_Button(xx,yy,ctl_width,kMenuH,"Sample Rate");
- sr_btn->callback( _s_btn_cb, kSrateBtnId);
- sr_btn->add("44100",0,NULL,(void*)44100,0);
- sr_btn->add("48000",0,NULL,(void*)48000,0);
- sr_btn->add("96000",0,NULL,(void*)96000,0);
-
- yy += sr_btn->h() + vBord;
-
- btn = new Fl_Button(xx,yy,ctl_width,kMenuH,"Test");
- btn->callback( _s_btn_cb, kTestBtnId );
- yy += btn->h() + vBord;
-
- ena_chk = new Fl_Check_Button(xx,yy,ctl_width,kMenuH,"Enable Audio");
- ena_chk->callback( _s_btn_cb, kEnableBtnId );
- yy += ena_chk->h() + vBord;
-
- // place this ctrl in the lower left corner to prevent the other controls from resizing
- Fl_Box* bx = new Fl_Box(FL_NO_BOX,xx+ctl_width,yy,10,10,NULL);
- grp->resizable(bx);
-
- grp->end();
- }
-
-
- void kcApp::_createMenu(int w, int h)
- {
- Fl_Menu_Item items[] =
- {
- { "&File", 0, 0, 0, FL_SUBMENU },
- { "&New File", 0, (Fl_Callback*)_s_file_new_cb },
- { "&Open File", FL_COMMAND + 'o', (Fl_Callback*)_s_file_open_cb },
- { 0 },
- { "&Edit", 0, 0, 0, FL_SUBMENU },
- { "&Copy", FL_COMMAND + 'c', (Fl_Callback*)_s_edit_copy_cb },
- { "&Paste", FL_COMMAND + 'v', (Fl_Callback*)_s_edit_paste_cb },
- { 0 },
- { 0 }
- };
-
- _menu = new Fl_Menu_Bar(0,0,w,h);
- _menu->copy(items);
- }
-
- void kcApp::_createPage( const char* title )
- {
- int tx,ty,th,tw;
- tabs->client_area(tx,ty,tw,th);
-
- page_t* page = new page_t;
- page->link = _pageList;
- _pageList = page;
-
- _newPageFl = true;
-
- // Create the 'Controls' tab group
- tabs->begin();
- page->grp = new Fl_Group(tx,ty,tw,th,title);
- page->grp->begin();
- Fl_Box* bx = new Fl_Box(FL_NO_BOX,page->grp->x()+page->grp->w(),page->grp->y()+page->grp->h(),1,1,NULL);
- page->grp->resizable(bx);
- page->grp->end();
- tabs->end();
-
- }
-
- // return the count of engine ctls
- unsigned kcApp::_getCtlCount() const
- {
- unsigned cnt = 0;
- ctl_t* cp = _ctlList;
- for(; cp!=NULL; cp=cp->linkPtr)
- ++cnt;
- return cnt;
- }
-
- // delete all engine ctls - (except maybe the master ctrl's)
- void kcApp::_clearCtlList(bool mstrFl)
- {
- ctl_t* ncl = NULL;
- ctl_t* cp = _ctlList;
-
- while( cp != NULL )
- {
- ctl_t* np = cp->linkPtr;
-
- // delete the ctrl unless it is a master ctl and the mstrFl is set
- if( cp->mstrFl==false || mstrFl )
- {
- delete cp;
- }
- else
- {
- // append the master ctl to the new ctl list
- cp->linkPtr = ncl;
- ncl = cp;
- }
-
- cp = np;
- }
-
- // clear the page groups and pages
- page_t* pg = _pageList;
- while( pg != NULL )
- {
- page_t* np = pg->link;
- pg->grp->clear();
- delete pg->grp;
- delete pg;
- pg = np;
- }
- _pageList = NULL;
-
- //ctl_grp->clear();
- _ctlList = ncl; // make the new ctl list the current ctl list
-
- if( mstrFl )
- mstr_grp->clear();
-
- }
-
-
- void kcApp::_clearSsArray()
- {
- if( _ssArray != NULL )
- {
- delete[] _ssArray;
- _ssArray = NULL;
- }
-
- _ssCnt = 0;
-
- }
-
- // find a engine ui ctl given a dsp instance id
- kcApp::ctl_t* kcApp::_findCtl( unsigned instId, unsigned asSubIdx, unsigned mstrFl )
- {
- ctl_t* cp = _ctlList;
- for(; cp!=NULL; cp=cp->linkPtr)
- if( cp->instId == instId && cp->asSubIdx==asSubIdx && cp->mstrFl==mstrFl )
- return cp;
-
- //printf("not found:0x%x ssi:%i mstr:%i\n",instId,asSubIdx,mstrFl);
-
- return NULL;
- }
-
- // calc. the position and size of a new ctl being created
- // at the request of the engine
- void kcApp::_getNewCtlPosn( const cmDspUiHdr_t* m, int& x, int& y, int& w, int& h )
- {
- enum { kPageH=700, kCtlH=30, kCtlW=200, kHBord=2, kVBord=2 };
-
- // if this is control is being placed in the 'master' group
- if( m->uiId == cmInvalidId )
- {
-
- //unsigned devIdx = cmAudioSysUiInstIdToDevIndex(m->instId);
- unsigned chIdx = cmAudioSysUiInstIdToChIndex(m->instId);
- unsigned outFl = !cmAudioSysUiInstIdToInFlag(m->instId);
- unsigned ctlId = cmAudioSysUiInstIdToCtlId(m->instId);
-
-
- int xOffs = 20;
- int yOffs = 100;
- int chH = 205;
- int chW = 44;
- int sldrH = 120;
- int sldrW = 20;
- int chkH = 20;
- int chkW = 35;
-
- x = xOffs + (chIdx * chW);
- y = yOffs + (m->asSubIdx * 2 * chH) + (outFl * chH);
-
- switch( ctlId )
- {
- // slider
- case kSliderUiAsId: w=sldrW; h=sldrH; break;
-
- // meter
- case kMeterUiAsId: w=sldrW; h=sldrH; x+=sldrW; break;
-
- // mute
- case kMuteUiAsId: w=chkW; h=chkH; y+=sldrH + 2; break;
-
- // tone
- case kToneUiAsId: w=chkW; h=chkH; y+=sldrH + chkH + 4; break;
-
- // pass
- case kPassUiAsId: w=chkW; h=chkH; y+=sldrH + 2*chkH + 6; break;
-
- default:
- { assert(0); }
- }
-
- return;
- }
-
- // if this control is being placed in the 'controls' group
- ctl_t* cp = _ctlList;
-
- if( w == 0 )
- {
- if( _colW == 0 )
- _colW = kCtlW;
-
- w = _colW;
- }
-
- if( h == 0 )
- h = kCtlH;
-
- // skip over controls that are assigned to the 'master' group
- while(cp != NULL && cp->mstrFl )
- cp = cp->linkPtr;
-
- // if the page list is empty - create a default blank page
- if( _pageList == NULL )
- _createPage("Controls");
-
- Fl_Group* ctl_grp = _pageList->grp;
-
- // if the ctl list is empty
- if( cp == NULL || _newPageFl )
- {
- _newPageFl = false;
- x = kHBord + ctl_grp->x();
- y = kVBord + ctl_grp->y();
- _horzBord = y;
- }
- else
- {
- // if a new horizontal - upper border was requested
- if( _horzBordFl )
- {
- _horzBordFl = false;
-
- // locate the current control with the max bottom coordinate
- ctl_t* tp = cp;
- if( tp != NULL )
- {
- int maxY = tp->wdgtPtr->y() + tp->wdgtPtr->h();
-
- while(tp!=NULL)
- {
- if( tp->mstrFl == false && (tp->wdgtPtr->y() + tp->wdgtPtr->h()) > maxY )
- maxY = tp->wdgtPtr->y() + tp->wdgtPtr->h();
-
- tp = tp->linkPtr;
- }
- // set the new upper boundary to just below the bottom of
- // the lowest control
- _horzBord = maxY + kVBord*2;
-
- }
-
-
- x = kHBord + ctl_grp->x();
- y = _horzBord;
-
- }
- else
- {
- // use the last ctl inserted in the list
- // (the first ctl in the list)
- // to position the next ctl
- x = cp->wdgtPtr->x();
- y = cp->wdgtPtr->y() + cp->wdgtPtr->h() + kVBord;
-
- // if this control goes off the page or a new col was requested
- if( y+h > kPageH || _incrColW )
- {
-
- x += _colW + kHBord;
- _colW = _incrColW;
- _incrColW = 0;
- y = _horzBord;
- }
-
- }
- }
- }
-
- kcApp::ctl_t* kcApp::_createCtl( const cmDspUiHdr_t* m, unsigned typeId, int& x, int& y, int& w, int& h, bool posnFl )
- {
- ctl_t* cp = new ctl_t;
-
- cp->thisPtr = this;
- cp->asSubIdx = m->asSubIdx;
- cp->instId = m->instId;
- cp->typeId = typeId;
- cp->mstrFl = m->uiId == cmInvalidId;
-
- if( posnFl )
- _getNewCtlPosn(m,x,y,w,h);
-
- return cp;
- }
-
- void kcApp::_insertNewCtl( ctl_t* cp, const cmDspUiHdr_t* m, Fl_Widget* wdgt, unsigned* varIdArray, unsigned varIdCnt )
- {
- unsigned i;
-
- // _genNewCtlPosn() should have been called before this - where a new page list would have been created.
- assert( cp->mstrFl || (cp->mstrFl==false && _pageList != NULL) );
-
- Fl_Group* grp = cp->mstrFl ? mstr_grp : _pageList->grp;
-
- cp->wdgtPtr = wdgt;
- cp->wdgtPtr->callback(_s_ctl_cb, cp );
- grp->add(cp->wdgtPtr);
-
- const unsigned* srcVarIdArray = cmDsvUIntCMtx(&m->value);
-
- assert( varIdArray != NULL && cmDsvEleCount(&m->value)==varIdCnt);
-
- for(i=0; i<varIdCnt; ++i)
- varIdArray[i] = srcVarIdArray[i];
-
- cp->linkPtr = _ctlList;
- _ctlList = cp;
- }
-
- // create a slider ctl at the request of the engine
- void kcApp::_createSlider( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=0;
- ctl_t* cp = _createCtl(m, m->selId==kSliderDuiId? kSldrTypeId : kNumbTypeId, x,y,w,h );
-
- switch(m->selId)
- {
- case kSliderDuiId:
- cp->u.sldr.u.sldr = new Fl_Value_Slider(x,y,w,h);
- cp->u.sldr.val = static_cast<Fl_Valuator*>(cp->u.sldr.u.sldr);
- cp->u.sldr.u.sldr->type(cp->mstrFl ? FL_VERT_NICE_SLIDER : FL_HOR_NICE_SLIDER);
- break;
-
- case kNumberDuiId:
- cp->u.sldr.u.numb = new Fl_Value_Input(x,y,w/2,h);
- cp->u.sldr.u.numb->when(FL_WHEN_ENTER_KEY | FL_WHEN_RELEASE );
- cp->u.sldr.val = static_cast<Fl_Valuator*>(cp->u.sldr.u.numb);
-
- break;
- }
-
- _insertNewCtl(cp, m, cp->u.sldr.val, cp->u.sldr.varIdArray, kSldrVarCnt );
- }
-
-
- // handle slider value msg's arriving from the engine
- void kcApp::_setSldrValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i=0;
- Fl_Valuator* sp = cp->u.sldr.val;
-
- for(i=0; i<kSldrVarCnt; ++i)
- if( cp->u.sldr.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kSldrMinArgIdx:
- sp->minimum(cmDsvGetDouble(vp));
- //sp->step((sp->maximum()-sp->minimum())/sp->w());
- break;
-
- case kSldrMaxArgIdx:
- sp->maximum(cmDsvGetDouble(vp));
- //sp->step((sp->maximum()-sp->minimum())/sp->w());
- break;
-
- case kSldrStpArgIdx:
- sp->step(cmDsvGetDouble(vp));
- break;
-
- case kSldrValArgIdx:
- sp->value(cmDsvGetDouble(vp));
- break;
-
- case kSldrLblArgIdx:
- {
- int ww=0,hh=0;
- if( cmDsvStrcz(vp) == NULL )
- {
- sp->label(NULL);
- sp->align(FL_ALIGN_INSIDE | FL_ALIGN_CENTER );
- }
- else
- {
- sp->copy_label( cmDsvStrcz(vp) );
- sp->align(FL_ALIGN_RIGHT);
- }
-
- if( cp->typeId == kSldrTypeId )
- {
- sp->measure_label(ww,hh);
- sp->resize( sp->x(), sp->y(), sp->w() - ww, sp->h());
- sp->redraw();
- }
- }
-
- break;
-
- default:
- { assert(0); }
- }
-
- break;
- }
- }
-
- void kcApp::_createText( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=0;
- ctl_t* cp = _createCtl(m, kTextTypeId, x,y,w,h );
-
- cp->u.text.text = new Fl_Input(x,y,w,h);
-
- _insertNewCtl(cp, m, cp->u.text.text, cp->u.text.varIdArray, kTextVarCnt );
- }
-
- void kcApp::_setTextValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i=0;
- Fl_Input* tp = cp->u.text.text;
-
- for(i=0; i<kTextVarCnt; ++i)
- if( cp->u.text.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kTextValArgIdx:
- tp->value( cmDsvStrcz(vp));
- break;
-
- case kTextLblArgIdx:
- {
- const char* lbl = cmDsvStrcz(vp);
- if( lbl == NULL )
- tp->label(NULL);
- else
- tp->copy_label( lbl );
-
- tp->align(FL_ALIGN_RIGHT);
- tp->resize( tp->x(), tp->y(), tp->w()/2, tp->h());
- tp->redraw();
-
- }
- break;
-
- default:
- { assert(0); }
- }
- }
- }
-
-
-
- void kcApp::_createFnameCtl( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=0;
- ctl_t* cp = _createCtl(m, kFnamTypeId, x,y,w,h );
-
- cp->u.fnam.fnam = new Fl_File_Btn(x,y,w,h);
-
- _insertNewCtl(cp, m, cp->u.fnam.fnam, cp->u.fnam.varIdArray, kFnamVarCnt );
- }
-
- void kcApp::_setFnamValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i=0;
- Fl_File_Btn* bp = cp->u.fnam.fnam;
-
- for(i=0; i<kFnamVarCnt; ++i)
- if( cp->u.fnam.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kFnamValArgIdx:
- assert( cmDsvIsType( vp, kStrzDsvFl ) );
- bp->filename( cmDsvStrcz(vp) );
- bp->redraw();
- break;
-
- case kFnamPatArgIdx:
- assert( cmDsvIsType( vp, kStrzDsvFl ) );
- bp->pattern_string( cmDsvStrcz(vp) );
- break;
-
- case kFnamDirArgIdx:
- bp->type( cmDsvBool(vp) ? Fl_File_Btn::kDir_Type_Id : Fl_File_Btn::kFile_Type_Id );
- break;
-
- default:
- { assert(0); }
- }
- }
- }
-
-
- void kcApp::_createMlistCtl( const cmDspUiHdr_t* m )
- {
- const unsigned* varIdArray = cmDsvUIntCMtx(&m->value);
-
- assert( varIdArray != NULL && cmDsvEleCount(&m->value)==kMlstVarCnt);
-
- int x,y,w=0;
- int h = varIdArray[kMlstHgtArgIdx];
- bool menuBtnFl = h==0;
-
- h = menuBtnFl ? kMenuH : kMenuH * h;
-
- ctl_t* cp = _createCtl(m, kMlstTypeId, x,y,w,h );
-
- Fl_Widget* wdgt;
-
- if(menuBtnFl)
- {
- cp->u.mlst.mlst = NULL;
- wdgt = cp->u.mlst.mbtn = new Fl_Menu_Button(x,y,w,h);
- }
- else
- {
- cp->u.mlst.mbtn = NULL;
- wdgt = cp->u.mlst.mlst = new Fl_Select_Browser(x,y,w,h);
- }
-
- _insertNewCtl(cp, m, wdgt, cp->u.mlst.varIdArray, kMlstVarCnt );
- }
-
- kcApp::kcKmRC_t kcApp::_loadMlist( ctl_t* cp, const cmJsonNode_t* np )
- {
- assert( cmJsonIsArray(np) );
-
- kcKmRC_t rc = kOkKmRC;
- unsigned n = cmJsonChildCount(np);
- unsigned ri = 0;
-
- // empty the ctl data list
- if( cp->u.mlst.mbtn == NULL )
- cp->u.mlst.mlst->clear();
- else
- cp->u.mlst.mbtn->clear();
-
- // for each element (row) in the JSON array
- for(ri=0; ri<n && rc==kOkKmRC; ++ri)
- {
- const cmJsonNode_t* cnp = cmJsonArrayElementC(np,ri);
- unsigned m = cmJsonChildCount(cnp);
- unsigned bufCharCnt = 511;
- cmChar_t buf[ bufCharCnt + 1 ]; // buffer to hold one row of text
- cmChar_t* bbp = buf;
- cmChar_t* bep = bbp + bufCharCnt;
- unsigned j;
-
- buf[0] = 0;
-
- // for each element (column) of row i
- for(j=0; j<m; ++j)
- {
- const cmJsonNode_t* ep = cmJsonArrayElementC(cnp,j);
- cmJsRC_t jsRC;
-
- // convert the element to a string
- if( (jsRC = cmJsonLeafToString( ep, bbp, bep - bbp )) != kOkJsRC )
- {
- switch(jsRC)
- {
- case kBufTooSmallJsRC:
- rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"The msg list line character buffer is too small at JSON array element index %i.",ri);
- break;
-
- case kInvalidNodeTypeJsRC:
- rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"The msg list array element at index %i is not a JSON leaf node.",ri);
- break;
-
- default:
- rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"JSON to msg list text conversion failed on array element %i.",ri);
- break;
- }
- break;
- }
-
-
- bbp = buf + strlen(buf);
- assert(bbp <= bep);
-
- // add the tab column marker
- if( j+1 < m )
- {
- if( bep - bbp < 1 )
- rc = cmErrMsg(&_ctx.err,kMlistLoadFailKmRC,"The msg list line buffer is too small.");
- else
- {
- *bbp++ = '\t';
- *bbp = 0;
- }
- }
- }
-
- // insert the text for row i and skip the title row
- // See the _setMListValue() and _ctl_cb() for the associated index incr/decr.
- // so that the engine list indexes and UI list indexes match
- if( rc == kOkKmRC && ri > 0)
- {
- if( cp->u.mlst.mbtn==NULL)
- cp->u.mlst.mlst->add(buf);
- else
- cp->u.mlst.mbtn->add(buf);
- }
- }
-
- if( rc == kOkKmRC )
- if( cp->u.mlst.mbtn != NULL )
- {
- if( cp->u.mlst.sel < cp->u.mlst.mbtn->size() )
- cp->u.mlst.mbtn->label(cp->u.mlst.mbtn->text(cp->u.mlst.sel));;
- }
- return rc;
- }
-
- void kcApp::_setMlistValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i=0;
-
- for(i=0; i<kMlstVarCnt; ++i)
- if( cp->u.mlst.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kMlstHgtArgIdx:
- break;
-
- case kMlstSelArgIdx:
- {
- unsigned idx = cmDsvUInt(vp);
-
- // decr. to account for skipping title row
- // (see the complementary incrementn in _ctl_cb())
- if( idx > 0 )
- --idx;
-
- if( cp->u.mlst.mbtn==NULL)
- cp->u.mlst.mlst->value(idx);
- else
- {
- cp->u.mlst.sel = idx;
-
- if( cp->u.mlst.sel < cp->u.mlst.mbtn->size() )
- {
- cp->u.mlst.mbtn->value(cp->u.mlst.sel);
- cp->u.mlst.mbtn->label( cp->u.mlst.mbtn->text(cp->u.mlst.sel) );
- }
- }
- cp->wdgtPtr->redraw();
- }
- break;
-
- case kMlstLstArgIdx:
- _loadMlist( cp, cmDsvJson(vp) );
- break;
-
-
- default:
- { assert(0); }
- }
- }
- }
-
- // create a meter ctl at the request of the engine
- void kcApp::_createMeter( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=15;
- ctl_t* cp = _createCtl(m,kMetrTypeId, x,y,w,h);
-
- if( cp->mstrFl )
- cp->u.metr.prog = new Fl_Vert_Progress(x,y,w,h);
- else
- cp->u.metr.prog = new Fl_Progress(x,y,w,h);
-
- cp->u.metr.prog->color( fl_rgb_color((unsigned char)256),fl_rgb_color((unsigned char)128));
-
- _insertNewCtl(cp,m,cp->u.metr.prog,cp->u.metr.varIdArray,kMetrVarCnt);
- }
-
-
- // handle meter value msg's arriving from the engine
- void kcApp::_setMeterValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i = 0;
- Fl_Progress* sp = cp->u.metr.prog;
- bool redrawFl = false;
-
- for(i=0; i<kMetrVarCnt; ++i)
- if( cp->u.metr.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kMetrMinArgIdx:
- sp->minimum(cmDsvGetDouble(vp));
- redrawFl = true;
- break;
-
- case kMetrMaxArgIdx:
- sp->maximum(cmDsvGetDouble(vp));
- redrawFl = true;
- break;
-
- case kMetrValArgIdx:
- {
- double v = cmDsvGetDouble(vp);
-
- if( sp->value() != v )
- {
- sp->value(v);
- redrawFl = true;
- }
- break;
- }
-
- case kMetrLblArgIdx:
- {
- int ww=0,hh=0;
- sp->copy_label( cmDsvStrcz(vp) );
- sp->align(FL_ALIGN_RIGHT);
-
- sp->measure_label(ww,hh);
- sp->resize( sp->x(), sp->y(), sp->w() - ww, sp->h());
- redrawFl = true;
- }
-
- break;
-
- default:
- { assert(0); }
- }
-
- break;
- }
-
- if( redrawFl )
- sp->redraw();
- }
-
- // create a button ctl at the request of the engine
- void kcApp::_createButton( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=0;
- ctl_t* cp = _createCtl(m,kButnTypeId, x,y,w,h);
-
- cp->u.butn.butn = new Fl_Button(x,y,w,h);
-
- _insertNewCtl(cp,m,cp->u.butn.butn,cp->u.butn.varIdArray,kButnVarCnt);
-
- }
-
- // handle button value msg's arriving from the engine
- void kcApp::_setButtonValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i = 0;
- Fl_Button* sp = cp->u.butn.butn;
- bool redrawFl = false;
-
- for(i=0; i<kButnVarCnt; ++i)
- if( cp->u.butn.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kButnValArgIdx:
- cp->u.butn.val = cmDsvGetDouble(vp);
- break;
-
- case kButnLblArgIdx:
- {
- sp->copy_label( cmDsvStrcz(vp) );
- redrawFl = true;
- }
-
- break;
-
- default:
- { assert(0); }
- }
-
- break;
- }
-
- if( redrawFl )
- sp->redraw();
-
- }
-
- // create a button ctl at the request of the engine
- void kcApp::_createCheck( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=0;
- ctl_t* cp = _createCtl(m,kChckTypeId, x,y,w,h);
-
- cp->u.chck.chck = new Fl_Check_Button(x,y,w,h);
-
- _insertNewCtl(cp,m,cp->u.chck.chck,cp->u.chck.varIdArray,kChckVarCnt);
- }
-
- // handle check button value msg's arriving from the engine
- void kcApp::_setCheckValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i = 0;
- Fl_Button* sp = cp->u.chck.chck;
- bool redrawFl = false;
-
- for(i=0; i<kChckVarCnt; ++i)
- if( cp->u.chck.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kChckValArgIdx:
- cp->u.chck.val = cmDsvGetDouble(vp);
- cp->u.chck.chck->value(cmDsvGetDouble(vp)>0);
- break;
-
- case kChckLblArgIdx:
- {
- int ww=0,hh=0;
- sp->copy_label( cmDsvStrcz(vp) );
- sp->align(FL_ALIGN_RIGHT);
-
- sp->measure_label(ww,hh);
- sp->resize( sp->x(), sp->y(), sp->w() - ww, sp->h());
- redrawFl = true;
-
- }
-
- break;
-
- default:
- { assert(0); }
- }
-
- break;
- }
-
- if( redrawFl )
- sp->redraw();
-
- }
-
- void kcApp::_createLabel( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=0;
- ctl_t* cp = _createCtl(m,kLablTypeId, x,y,w,h);
-
- cp->u.labl.box = new Fl_Box(x,y,w,h);
-
- _insertNewCtl(cp,m,cp->u.labl.box,cp->u.labl.varIdArray,kLablVarCnt);
-
- }
-
- void kcApp::_setLabelValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i = 0;
- Fl_Box* sp = cp->u.labl.box;
- bool redrawFl = false;
-
- for(i=0; i<kLablVarCnt; ++i)
- if( cp->u.labl.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kLablValArgIdx:
- sp->copy_label(cmDsvStrcz(vp));
- redrawFl = true;
- break;
-
- case kLablAlignArgIdx:
- switch( cmDsvUInt(vp) )
- {
- case kRightAlignDuiId:
- sp->align(FL_ALIGN_RIGHT | FL_ALIGN_INSIDE);
- break;
-
- case kLeftAlignDuiId:
- sp->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
- break;
-
- case kCenterAlignDuiId:
- sp->align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE);
- break;
-
- default:
- { assert(0); }
- }
- redrawFl = true;
- break;
-
-
- default:
- {assert(0);}
- }
- }
-
- if( redrawFl )
- sp->redraw();
- }
-
-
- void kcApp::_createTmln( const cmDspUiHdr_t* m )
- {
- int x,y,w=0,h=0;
- ctl_t* cp = _createCtl(m, kTmlnTypeId, x,y,w,h, false );
-
- cp->u.tmln.tlctl = new tlCtl(&_ctx,NULL);
-
- _createPage("TimeLine");
-
- cp->u.tmln.tlctl->initScoreCtlr(this, _pageList->grp, _menu );
- }
-
- void kcApp::_setTmlnValue( ctl_t* cp, unsigned instVarId, const cmDspValue_t* vp )
- {
- unsigned i=0;
- //tlCtl* tp = cp->u.tmln.tlctl;
-
- for(i=0; i<kTmlnVarCnt; ++i)
- if( cp->u.tmln.varIdArray[i] == instVarId )
- {
- switch(i)
- {
- case kTmlnValArgIdx:
- //tp->value( cmDsvStrcz(vp));
- break;
-
- case kTmlnLblArgIdx:
- {
- const char* lbl = cmDsvStrcz(vp);
- }
- break;
-
- case kTmlnFileArgIdx:
- {
- const char* fn;
- if((fn = cmDsvStrcz(vp)) != NULL )
- {
- cp->u.tmln.tlctl->openTlFile(fn);
- //cp->u.tmln.tlctl->redraw();
- }
- }
- break;
-
- case kTmlnPathArgIdx:
- {
- const char* path;
- if((path = cmDsvStrcz(vp)) != NULL )
- {
- cp->u.tmln.tlctl->setAudioFilePath(path);
- //cp->u.tmln.tlctl->redraw();
- }
- }
- break;
-
- default:
- { assert(0); }
- }
- }
- }
-
-
- void kcApp::_newColumn( const cmDspUiHdr_t* m )
- {
- _incrColW = cmDsvGetUInt(&m->value);
-
- if( _incrColW == 0 )
- _incrColW = 200;
- }
-
- void kcApp::_insertAudioSysCfgLabel(unsigned long idx, const char* label)
- {
- if( idx == 0 )
- as_btn->clear();
-
- as_btn->add(label,0,NULL,(void*)idx,0);
- }
-
- void kcApp::_insertDeviceLabel( unsigned long devIdx, bool inputFl, const cmChar_t* label )
- {
- Fl_Menu_Button* bp = inputFl ? ai_btn : ao_btn;
-
- // ??? if( idx == 0 )
- // bp->clear();
-
-
- bp->add(label,0,NULL,(void*)devIdx,0);
- }
-
- void kcApp::_insertProgramLabel( unsigned long idx, const cmChar_t* label )
- {
- if( idx == 0 )
- pgm_btn->clear();
-
- pgm_btn->add(label,0,NULL,(void*)idx,0);
- }
-
- void kcApp::_insertSubSysCnt( unsigned long subSysCnt )
- {
- long unsigned i;
- int bufByteCnt = 15;
- char buf[bufByteCnt+1];
-
- for(i=0; i<subSysCnt+1; ++i)
- {
- const char* label;
- unsigned long id;
-
- if( i==0 )
- {
- label = "All";
- id = cmInvalidIdx;
- }
- else
- {
- snprintf(buf,bufByteCnt,"%li",i);
- label = buf;
- id = i-1;
- }
-
- ss_btn->add(label,0,NULL,(void*)id);
- }
-
- ss_btn->value(0);
- ss_btn->copy_label( ss_btn->mvalue()->label() );
- }
-
- unsigned kcApp::_getCurAudioSubSysIdx()
- {
- const Fl_Menu_Item* mip;
- unsigned retVal = 0;
-
- if( (mip = ss_btn->mvalue()) != NULL)
- retVal = mip->argument();
-
- return retVal;
- }
-
- void kcApp::_setMenuButton( Fl_Menu_Button* b, unsigned value, const char* dfltLabel )
- {
- const Fl_Menu_Item* mip;
- bool fl = value != cmInvalidIdx;
-
- // if value is a valid menu index then make it the current menu selection
- if( fl )
- b->value(value);
-
- // get the new current menu item and set its label
- if( (mip = b->mvalue()) != NULL )
- b->copy_label( fl ? mip->label() : dfltLabel );
- }
-
- void kcApp::_setDeviceMenuButton( unsigned asSubIdx, bool inputFl, unsigned devIdx )
- {
-
- // don't set the device name if the currenly selected sub-system is not the
- // same as the one the device is assigned to
- if( _getCurAudioSubSysIdx() != asSubIdx )
- return;
-
- Fl_Menu_Button* mbp = inputFl ? ai_btn : ao_btn;
-
- const Fl_Menu_Item* map = mbp->menu();
- unsigned n = mbp->size();
- unsigned i;
- void* di = (void*)devIdx;
- for(i=0; i<n; ++i)
- if( map[i].user_data() == di )
- break;
-
- if( i < n )
- {
- _setMenuButton(mbp,i,"<not found>");
- }
-
-
- }
-
- void kcApp::_setSampleRateBtn( unsigned value )
- {
- unsigned i;
- unsigned n = sr_btn->size();
- for(i=0; i<n-1; ++i)
- {
- if( sr_btn->menu()[i].argument() == value )
- {
- sr_btn->value(i);
- sr_btn->copy_label( sr_btn->mvalue()->label() );
- return;
- }
- }
-
- sr_btn->copy_label("Sample Rate?");
- }
-
-
- void kcApp::_updateMeters( unsigned asSubIdx, unsigned devIdx, unsigned inFl, const double* meterArray, unsigned meterCnt )
- {
- unsigned i;
- for(i=0; i<meterCnt; ++i)
- {
- ctl_t* cp;
- cmDspValue_t v;
- unsigned instId = cmAudioSysFormUiInstId(devIdx,i,inFl,kMeterUiAsId);
-
- if((cp = _findCtl(instId,asSubIdx,true)) != NULL )
- {
- cmDsvSetDouble(&v,meterArray[i]);
- _setMeterValue(cp, kMetrValArgIdx, &v);
- }
- }
- }
-
- void kcApp::_printStatusCounts()
- {
- const ss_t* ssp = _ssArray;
- printf("Upd:%i Wake:%i Msg:%i Audio:%i\n",ssp->cnt[kUpdateSsIdx],ssp->cnt[kWakeupSsIdx],ssp->cnt[kMsgSsIdx],ssp->cnt[kAudioCbSsIdx]);
- }
-
- void kcApp::_updateSsStatusIndicator( unsigned asSubIdx, unsigned indicatorIdx, unsigned cnt )
- {
- ss_t* ss = _ssArray + asSubIdx;
- float val = ss->cnt[indicatorIdx] != cnt;
-
- ss->cnt[indicatorIdx] = cnt;
-
- if( ss->prog[indicatorIdx]->value() != val )
- {
- ss->prog[indicatorIdx]->value(val);
- ss->prog[indicatorIdx]->redraw();
- }
- }
-
-
- void kcApp::_handleStatusMsg(const cmAudioSysStatus_t* st, const double* iMeterArray, const double* oMeterArray )
- {
- //unsigned asSubIdx = ((const unsigned*)msgBuf)[0];
- //const cmAudioSysStatus_t* st = (const cmAudioSysStatus_t*)(msgBuf + (2 * sizeof(unsigned)));
- //const double* iMeterArray = (const double*)(st + 1);
- //const double* oMeterArray = iMeterArray + st->iMeterCnt;
-
- _updateMeters(st->asSubIdx, st->iDevIdx,1,iMeterArray,st->iMeterCnt);
- _updateMeters(st->asSubIdx, st->oDevIdx,0,oMeterArray,st->oMeterCnt);
-
- assert( st->asSubIdx < _ssCnt );
-
- _updateSsStatusIndicator(st->asSubIdx, kUpdateSsIdx, st->updateCnt );
- _updateSsStatusIndicator(st->asSubIdx, kWakeupSsIdx, st->wakeupCnt );
- _updateSsStatusIndicator(st->asSubIdx, kMsgSsIdx, st->msgCbCnt );
- _updateSsStatusIndicator(st->asSubIdx, kAudioCbSsIdx,st->audioCbCnt );
- }
-
- void kcApp::_clearStatusIndicators()
- {
- for(unsigned i=0; i<_ssCnt; ++i)
- {
- _updateSsStatusIndicator(i, kUpdateSsIdx, _ssArray[i].cnt[kUpdateSsIdx] );
- _updateSsStatusIndicator(i, kWakeupSsIdx, _ssArray[i].cnt[kWakeupSsIdx] );
- _updateSsStatusIndicator(i, kMsgSsIdx, _ssArray[i].cnt[kMsgSsIdx] );
- _updateSsStatusIndicator(i, kAudioCbSsIdx,_ssArray[i].cnt[kAudioCbSsIdx] );
-
- }
- }
-
- // Create a master control UI msg and send it to _handleUiMsg(). This function is intended to
- // mimic the reception of a cmDspUiHdr_t msg from the audio system. It is used to create
- // and send values to the controls on the master page.
- void kcApp::_sendMasterUiMsg( unsigned asSubIdx, unsigned selId, unsigned instId, unsigned instVarId, const cmDspValue_t* vp )
- {
- // Determine the size of the message buffer
- unsigned valByteCnt = cmDsvSerialDataByteCount(vp);
- unsigned bufByteCnt = sizeof(cmDspUiHdr_t) + valByteCnt;
-
- char buf[ bufByteCnt ];
- cmDspUiHdr_t* h = (cmDspUiHdr_t*)buf;
-
- h->asSubIdx = asSubIdx;
- h->uiId = cmInvalidId; // the uiId field of master controls is always set to cmInvalidId
- h->selId = selId;
- h->flags = 0;
- h->instId = instId;
- h->instVarId = instVarId;
-
- // Serialize 'v' into the buffer beginning at the address of h->value.
- // (this function relies on the 'hdr.value' field being the last field in 'h')
- cmDsvSerialize( vp, &h->value, sizeof(cmDspValue_t) + valByteCnt);
-
- _handleUiMsg(h);
-
- }
-
- // Send a value to a control on the master page.
- void kcApp::_sendMasterUiValue( unsigned asSubIdx, unsigned instId, const double* v, unsigned vn, const cmChar_t* text )
- {
- cmDspValue_t val;
- unsigned i;
-
- for(i=0; i<vn; ++i)
- {
- cmDsvSetDouble(&val,v[i]);
- _sendMasterUiMsg(asSubIdx, kValueDuiId, instId, i, &val );
- }
-
- if( text != NULL )
- {
- cmDsvSetStrcz(&val,text);
- _sendMasterUiMsg(asSubIdx, kValueDuiId, instId, i, &val );
- }
-
- }
-
- // Create a control on the master page.
- void kcApp::_createMasterCtl( unsigned asSubIdx, unsigned selId, unsigned instId, unsigned varCnt, const double* dv, unsigned dn, const cmChar_t* label)
- {
-
- // Create the control variable id array.
- // This array gives the id's used to identify each control variable.
- unsigned varIdArray[ varCnt ];
- unsigned i;
- cmDspValue_t v;
-
- // Set the var id's for master controls to be the same as the var indexes.
- for(i=0; i<varCnt; ++i)
- varIdArray[i] = i;
-
- // Encode varIdArray[] as a cmDsvValue.
- cmDsvSetUIntMtx(&v,varIdArray,varCnt,1);
-
- // create the control
- _sendMasterUiMsg(asSubIdx, selId, instId, cmInvalidId, &v );
-
- // set the controls initial configuration
- _sendMasterUiValue(asSubIdx, instId, dv, dn, label );
-
- }
-
- void kcApp::_handleSsInitMsg( const cmAudioSysSsInitMsg_t* m, const cmChar_t* inDevLabel, const cmChar_t* outDevLabel )
- {
- unsigned i,j;
-
- if( _ssCnt == 0 )
- {
- _clearSsArray();
- _ssCnt = m->asSubCnt;
- _ssArray = new ss_t[ _ssCnt ];
- }
-
- assert( m->asSubIdx < _ssCnt );
-
- ss_t* ss = _ssArray + m->asSubIdx;
-
- int x = 20;
- int y = 30;
- int w = 80;
- int h = 20;
- char lblArray[][10] = { "Update","Wakeup","Mesg","Audio" };
-
- // create the sub-system status indicators
- for(i=0; i<kProgSsCnt; ++i)
- {
- Fl_Progress* prog = new Fl_Progress(x,y,w,h,NULL);
- prog->color( FL_RED, FL_GREEN );
- prog->minimum(0);
- prog->maximum(1);
- prog->copy_label(lblArray[i]);
- mstr_grp->add(prog);
-
- ss->cnt[i] = 0;
- ss->prog[i] = prog;
-
- x += ss->prog[i]->w() + 4;
- }
-
-
- for(i=0; i<2; ++i)
- {
- unsigned inFl = i==0;
- unsigned chCnt = inFl ? m->inChCnt : m->outChCnt;
- unsigned devIdx = inFl ? m->inDevIdx : m->outDevIdx;
- double zero = 0;
-
- for(j=0; j<chCnt; ++j)
- {
- // 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.
- assert( devIdx < 0xffff && j < 0x0fff);
-
- unsigned instId = cmAudioSysFormUiInstId(devIdx,j,inFl,0);
-
- //printf("ssi:%i instId:0x%x\n",m->asSubIdx,instId+kMeterUiAsId);
-
- // create the volume slider
- double sv[] = { 3, 0, 0.01, 1 };
- unsigned sn = sizeof(sv)/sizeof(sv[0]);
- _createMasterCtl( m->asSubIdx, kSliderDuiId, instId + kSliderUiAsId, kSldrVarCnt, sv, sn, NULL);
-
- // create the meter
- double mv[] = { 0, 1.0, 0 };
- unsigned mn = sizeof(mv)/sizeof(mv[0]);
- _createMasterCtl( m->asSubIdx, kMeterDuiId, instId + kMeterUiAsId, kMetrVarCnt, mv, mn, NULL);
-
- // create the mute button
- _createMasterCtl( m->asSubIdx, kCheckDuiId, instId + kMuteUiAsId, kChckVarCnt, &zero, 1, "M");
-
- // create the tone button
- _createMasterCtl( m->asSubIdx, kCheckDuiId, instId + kToneUiAsId, kChckVarCnt, &zero, 1, "T");
-
- // create the pass button
- _createMasterCtl( m->asSubIdx, kCheckDuiId, instId + kPassUiAsId, kChckVarCnt, &zero, 1, "P");
-
-
- }
- }
-
- }
-
- // handle kValueDuiId messages coming from the engine
- void kcApp::_onRecvValue( const cmDspUiHdr_t* m )
- {
- ctl_t* cp;
-
- if((cp = _findCtl(m->instId,m->asSubIdx,m->uiId==cmInvalidId)) == NULL )
- return;
-
- switch( cp->typeId )
- {
- case kNumbTypeId:
- case kSldrTypeId:
- _setSldrValue(cp, m->instVarId, &m->value );
- break;
-
- case kTextTypeId:
- _setTextValue(cp, m->instVarId, &m->value );
- break;
-
- case kButnTypeId:
- _setButtonValue(cp, m->instVarId, &m->value);
- break;
-
- case kChckTypeId:
- _setCheckValue(cp, m->instVarId, &m->value);
- break;
-
- case kLablTypeId:
- _setLabelValue(cp, m->instVarId, &m->value);
- break;
-
- case kFnamTypeId:
- _setFnamValue(cp, m->instVarId, &m->value);
- break;
-
- case kMlstTypeId:
- _setMlistValue(cp, m->instVarId, &m->value);
- break;
-
- case kMetrTypeId:
- _setMeterValue(cp, m->instVarId, &m->value);
- break;
-
- case kTmlnTypeId:
- _setTmlnValue(cp, m->instVarId, &m->value);
- break;
-
- default:
- assert(0);
- }
- }
-
-
- // This is the main UI<-Engine msg handler/dispatch function
- void kcApp::_handleUiMsg( const cmDspUiHdr_t* m )
- {
-
- switch( m->selId )
- {
- case kPrintDuiId:
- cmDsvPrint(&m->value,NULL,&_ctx.rpt);
- break;
-
- case kNumberDuiId:
- case kSliderDuiId:
- _createSlider(m);
- break;
-
- case kTextDuiId:
- _createText(m);
- break;
-
- case kButtonDuiId:
- _createButton(m);
- break;
-
- case kLabelDuiId:
- _createLabel(m);
- break;
-
- case kCheckDuiId:
- _createCheck(m);
- break;
-
- case kFnameDuiId:
- _createFnameCtl(m);
- break;
-
- case kMsgListDuiId:
- _createMlistCtl(m);
- break;
-
- case kMeterDuiId:
- _createMeter(m);
- break;
-
- case kTimeLineDuiId:
- _createTmln(m);
- break;
-
- case kValueDuiId:
- _onRecvValue(m);
- break;
-
- case kColumnDuiId:
- _newColumn(m);
- break;
-
- case kHBorderDuiId:
- _horzBordFl = true;
- break;
-
- case kPageDuiId:
- _createPage(cmDsvStrcz(&m->value));
- break;
-
- case kAudioSysCfgDuiId:
- _insertAudioSysCfgLabel(m->instId,cmDsvStrcz(&m->value));
- break;
-
- case kDeviceDuiId:
- _insertDeviceLabel(m->instId,m->flags,cmDsvStrcz(&m->value));
- break;
-
- case kProgramDuiId:
- _insertProgramLabel(m->instId,cmDsvStrcz(&m->value));
- break;
-
- // the below codes are used to notify the application
- // of changes in state of the audio DSP system
-
- case kSubSysCntDuiId:
- _insertSubSysCnt(cmDsvUInt(&m->value));
- break;
-
- case kSetAudioCfgDuiId:
- _setMenuButton(as_btn,cmDsvUInt(&m->value),"Audio System Cfg");
- break;
-
- case kSetAudioDevDuiId:
- _setDeviceMenuButton( m->asSubIdx, m->flags, cmDsvUInt(&m->value) );
- break;
-
- case kSetSampleRateDuiId:
- _setSampleRateBtn(cmDsvUInt(&m->value));
- break;
-
- case kSetPgmDuiId:
- _setMenuButton(pgm_btn,cmDsvUInt(&m->value),"Program?");
- _clearCtlList(false);
- break;
-
- case kEnableDuiId:
- ena_chk->value(m->flags);
- break;
-
- }
- }
-
- cmRC_t kcApp::_s_handleSsInitMsg( void* cbDataPtr, const cmAudioSysSsInitMsg_t* r, const char* iDevLabel, const char* oDevLabel )
- {
- kcApp* p = (kcApp*)cbDataPtr;
- p->_handleSsInitMsg(r,iDevLabel,oDevLabel);
- return cmOkRC;
- }
-
- cmRC_t kcApp::_s_handleStatusMsg( void* cbDataPtr, const cmAudioSysStatus_t* r, const double* iMeterArray, const double* oMeterArray )
- {
- kcApp* p = (kcApp*)cbDataPtr;
- p->_handleStatusMsg(r,iMeterArray,oMeterArray);
- return cmOkRC;
- }
-
- cmRC_t kcApp::_s_handleUiMsg( void* cbDataPtr, const cmDspUiHdr_t* r )
- {
- kcApp* p = (kcApp*)cbDataPtr;
- p->_handleUiMsg(r);
- return cmOkRC;
- }
-
-
-
- // Check for and forward any messages sent to the UI
- // that are waiting in the audio DSP msg queue.
- void kcApp::_getEngMsg()
- {
-
-
- if( audioDspIsValid() )
- {
- unsigned i;
-
- for(i=0; i<10; ++i)
- {
- cmAiRC_t aiRC;
-
- // cmAdIfDispatchMsgToHost() results in calls to
- // the _s_handleXXX() message handlers
- if((aiRC = cmAdIfDispatchMsgToHost(_aiH)) != kOkAiRC)
- {
- if( aiRC == kNoMsgAiRC )
- break;
-
- cmErrMsg(&_ctx.err,kEngFailKmRC,"Audio DSP dispatch message request failed.");
- break;
- }
- }
- }
- }
-
-
- kcApp* kcApp::_getApp( Fl_Widget* w )
- {
- // walk up the widget tree until the top widget is found
- Fl_Group* gp = w->parent();
- while( gp->parent() != NULL )
- gp=gp->parent();
-
- // the user data for the top widget is a pointer kcApp()
- return (kcApp*)gp->user_data();
- }
-
-
-
- void kcApp::_testStub()
- {
- /*
- cmAudioFileTest(
- // "/Users/kevin/media/audio/20100819-Kreisberg/fragments/Bass End_21a.wav",
- "/Users/kevin/media/audio/McGill-1/1 Audio Track.aiff",
- "/Users/kevin/src/octave/cm_audio_file_test.m",_ctx.err.rpt );
- */
-
- //cmSymTblTest(&_ctx);
-
- //_kcTranslateFile("/Users/kevin/src/kc/src/data/Sec1_14.txt","/Users/kevin/src/kc/src/data/Sec1_14_out.txt",&_ctx);
- //_kcTranslateFile("/Users/kevin/src/kc/src/data/Mix_17-20.txt","/Users/kevin/src/kc/src/data/Mix_17-20_out.txt",&_ctx);
-
- /*
- ctl_t* cp = _ctlList;
- for(; cp!=NULL; cp=cp->linkPtr)
- printf("%i %i %i\n", cp->instId,cp->asSubIdx,cp->mstrFl );
- */
-
- _printStatusCounts();
-
- //cmProcTestNoInit(&_ctx);
-
- }
-
-
- void kcApp::_s_callback(Fl_Widget* wp, void* data)
- { ((kcApp*)data)->_callback(NULL); }
-
- // this callback is called when the window is closing
- void kcApp::_callback(void* data)
- {
- if( Fl::event() == FL_CLOSE )
- {
- unsigned cc = _closeCnt;
-
- // attempt to shut down the pgm
- if( audioDspFinalize() != kOkKmRC )
- ++_closeCnt;
-
- // the first time the pgm fails to shut down
- // do not allow the pgm to close the main window
- // this will give a chance for the error messages
- // to be diplayed in the console - all successive
- // times the return value from finalizePgm() is
- // ignored and the program is terminated.
- if( _closeCnt == 1 && cc==0)
- {
- deactivate(); // send a strong hint that a problem occurred
- return;
- }
-
- ctl_t* cp = _ctlList;
- for(; cp!=NULL; cp=cp->linkPtr)
- if( cp->typeId == kTmlnTypeId )
- delete cp->u.tmln.tlctl;
-
- // When all windows are windows are closed then the app.
- // will close - so hiding the application window
- // causes the program to close.
- //
- // Note that simply returning from this callback will
- // prevent the application from closing. Because the existence
- // of the callback alone is enough to disable default
- // event handling.
- hide();
- }
-
- }
-
-
- void kcApp::_s_on_idle(void *data)
- { ((kcApp*)data)->_on_idle(); }
-
- void kcApp::_on_idle()
- {
- //_getEngMsg();
- //_getEngStatus();
- }
-
- void kcApp::_s_status_timeout_cb(void* userPtr)
- {
- if( ((kcApp*)userPtr)->_status_timeout_cb() )
- Fl::repeat_timeout(TIMER_PERIOD,_s_status_timeout_cb,userPtr);
- }
-
- bool kcApp::_status_timeout_cb()
- {
- if( cmTsQueueIsValid(_printqH) )
- _checkPrintQueue();
-
- if( !_stopTimerFl )
- _getEngMsg();
-
- if( _ssUpdateFl )
- {
- ++_ssPhase;
- if( _ssPhase >= kSsPhaseMax )
- {
- _clearStatusIndicators();
- _ssPhase = 0;
- }
- }
-
- if( _stopTimerFl==false && cmAdIfIsValid(_aiH) )
- cmAdIfDispatchMsgToHost(_aiH);
-
- //if( !_stopTimerFl )
- // _getEngStatus();
-
- return _stopTimerFl==false || cmTsQueueIsValid(_printqH);
- }
-
-
-
-
- void kcApp::_s_file_new_cb(Fl_Widget *w, void *data)
- { ((kcApp*)data)->_file_new_cb(w); }
-
- void kcApp::_file_new_cb(Fl_Widget *w)
- { }
-
-
- void kcApp::_s_file_open_cb(Fl_Widget *w, void *data)
- { ((kcApp*)data)->_file_open_cb(w); }
-
- void kcApp::_file_open_cb(Fl_Widget *w)
- { }
-
-
- void kcApp::_s_edit_copy_cb(Fl_Widget *w, void *data)
- { ((kcApp*)data)->_edit_copy_cb(w); }
-
- void kcApp::_edit_copy_cb(Fl_Widget *w)
- { }
-
-
- void kcApp::_s_edit_paste_cb(Fl_Widget *w, void *data)
- { ((kcApp*)data)->_edit_paste_cb(w); }
-
- void kcApp::_edit_paste_cb(Fl_Widget *w)
- { }
-
-
- void kcApp::_s_tab_cb(Fl_Widget* w, void* data)
- { ((kcApp*)data)->_tab_cb(w); }
-
- void kcApp::_tab_cb(Fl_Widget*)
- {
- Fl_Widget* w = tabs->value();
- _ssUpdateFl = w == (Fl_Widget*)mstr_grp;
- _ssPhase = kSsPhaseMax;
- if( audioDspIsValid() )
- {
- if( cmAdIfEnableStatusNotify(_aiH, _ssUpdateFl ) != kOkAiRC )
- cmErrMsg(&_ctx.err,kEngFailKmRC,"A request to enable/disable status notification failed.");
- }
- }
-
- void kcApp::_s_btn_cb(Fl_Widget* w, long data)
- {
- _getApp(w)->_btn_cb(w,data);
- }
-
- void kcApp::_btn_cb(Fl_Widget* w, long data)
- {
- unsigned arg = w->argument();
- switch( arg )
- {
- case kAudDevRptBtnId:
- cmAdIfDeviceReport(_aiH);
- break;
-
- case kEnableBtnId:
- cmAdIfEnableAudio(_aiH,static_cast<Fl_Check_Button*>(w)->value()!=0);
- break;
-
- case kAudioSysCfgBtnId:
- cmAdIfSetAudioSysCfg(_aiH,static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
- break;
-
- case kInAudDevBtnId:
- cmAdIfSetAudioDevice(_aiH,_getCurAudioSubSysIdx(),true,static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
- break;
-
- case kOutAudDevBtnId:
- cmAdIfSetAudioDevice(_aiH,_getCurAudioSubSysIdx(),false,static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
- break;
-
- case kPgmBtnId:
- cmAdIfLoadProgram(_aiH,_getCurAudioSubSysIdx(),static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
- break;
-
- case kSubSystemIdxBtnId:
- // TODO: change device and sample rate menu's to reflect the device and srate assigned to this asSubIdx.
- break;
-
- case kSrateBtnId:
- cmAdIfSetSampleRate(_aiH,_getCurAudioSubSysIdx(),static_cast<Fl_Menu_Button*>(w)->mvalue()->argument());
- break;
-
- case kTestBtnId:
- _testStub();
- break;
-
- default:
- { assert(0); }
- }
- }
-
- void kcApp::_s_ctl_cb(Fl_Widget* w, void* data)
- {
- ctl_t* cp = ((ctl_t*)data);
- cp->thisPtr->_ctl_cb(cp);
- }
-
- void kcApp::_ctl_cb(ctl_t* cp)
- {
- cmDspValue_t value = cmDspNullValue;
- unsigned instVarId = cmInvalidId;
-
- switch( cp->typeId )
- {
- case kNumbTypeId:
- case kSldrTypeId:
- instVarId = cp->u.sldr.varIdArray[ kSldrValArgIdx ];
- cmDsvSetDouble(&value,cp->u.sldr.val->value());
- break;
-
- case kTextTypeId:
- instVarId = cp->u.text.varIdArray[ kTextValArgIdx ];
- cmDsvSetStrz(&value,(cmChar_t*)cp->u.text.text->value());
- break;
-
- case kButnTypeId:
- instVarId = cp->u.butn.varIdArray[ kButnValArgIdx ];
- cmDsvSetDouble(&value,cp->u.butn.val);
- break;
-
- case kChckTypeId:
- {
- bool fl = cp->u.chck.chck->value();
- instVarId = cp->u.chck.varIdArray[ kChckValArgIdx ];
- cmDsvSetDouble(&value, fl ? 1.0 : 0.0 );
- }
- break;
-
- case kFnamTypeId:
- instVarId = cp->u.fnam.varIdArray[ kFnamValArgIdx ];
- cmDsvSetStrz( &value, (cmChar_t*)cp->u.fnam.fnam->filename());
- break;
-
- case kMlstTypeId:
- instVarId = cp->u.mlst.varIdArray[ kMlstSelArgIdx ];
-
- // add one to the selected index to account for skipping title row
- if( cp->u.mlst.mbtn==NULL)
- {
- unsigned idx = cp->u.mlst.mlst->value();
- //printf("list:%i\n",idx);
- cmDsvSetUInt( &value, idx);
- }
- else
- {
- unsigned idx = cp->u.mlst.mbtn->value();
- //printf("mbtn:%i\n",idx);
- cmDsvSetUInt( &value, idx + 1);
- cp->u.mlst.mbtn->label( cp->u.mlst.mbtn->text(idx) );
- }
- break;
-
- case kTmlnTypeId:
- //instVarId = cp->u.text.varIdArray[ kTmlnValArgIdx ];
- //cmDsvSetStrz(&value,(cmChar_t*)cp->u.tmln.text->value());
- break;
-
- default:
- {assert(0);}
-
- }
-
- if( cmAdIfSendMsgToAudioDSP(
- _aiH,
- cp->asSubIdx,
- cp->mstrFl ? kUiMstrSelAsId : kUiSelAsId,
- kValueDuiId,
- 0,
- cp->instId,
- instVarId,
- &value) != kOkAiRC)
- {
- cmErrMsg(&_ctx.err,kEngFailKmRC,"An attempt to send a UI message to the audio DSP interface failed.");
- }
-
- }
-
-
- void kcApp::vprint(const char* fmt, va_list vl )
- {
- int bufCharCnt = 511;
- char buf[bufCharCnt+1];
-
- int n = vsnprintf(buf,bufCharCnt,fmt,vl);
-
- if( n > 0 )
- {
- // if the print queue exists (it might not during startup or shutdown) ...
- if( cmTsQueueIsValid(_printqH) )
- {
- // ... enqueue the text to print
- if( cmTsQueueEnqueueMsg(_printqH,buf,n+1) != kOkThRC )
- {
- printf("Print enqueue failed on msg:%s\n",buf);
- // we can't call an error here because it would generate an error
- // msg which would possibly fail at this same point resulting in
- // a recursion which would eventually overflow the stack.
-
- }
- }
- else
- _print(buf); // ... otherwise just send the text directly to the output console
- }
-
- }
-
- void kcApp::print( const char* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- vprint(fmt,vl);
- va_end(vl);
- }
-
- void kcApp::_s_print( void* userPtr, const char* text )
- { ((kcApp*)userPtr)->print(text); }
-
- cmRC_t kcApp::_s_print_queue_cb(void* userCbPtr, unsigned msgByteCnt, const void* msgDataPtr )
- {
- kcApp* ap = (kcApp*)userCbPtr;
- ap->_print((const char*)msgDataPtr);
- return cmOkRC;
- }
-
- void kcApp::_checkPrintQueue()
- {
- while( cmTsQueueMsgWaiting(_printqH) )
- if( cmTsQueueDequeueMsg(_printqH, NULL, 0) != kOkThRC )
- cmErrMsg(&_ctx.err,kPrintQueFailKmRC,"Print dequeue failed.");
- }
-
- void kcApp::_print( const char* text )
- {
- if( con != NULL )
- con->insert(text);
- #ifndef NDEBUG
- fputs(text,stdout);
- #endif
- }
|