Programmable real-time audio signal processing application
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

kcMain.cpp 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //| Copyright: (C) 2019-2020 Kevin Larke <contact AT larke DOT org>
  2. //| License: GNU GPL version 3.0 or above. See the accompanying LICENSE file.
  3. #include <FL/Fl.H>
  4. #include <FL/Fl_Double_Window.H>
  5. #include <FL/Fl_Menu_Item.H>
  6. #include <Fl/Fl_Menu_Bar.H>
  7. #include <Fl/Fl_Button.H>
  8. #include <Fl/Fl_Text_Buffer.H>
  9. #include <Fl/Fl_Text_Display.H>
  10. #include <Fl/Fl_Tabs.H>
  11. #include <Fl/Fl_File_Chooser.H>
  12. #include "Fl_Splitter.h"
  13. #include "cmGlobal.h"
  14. #include "cmFloatTypes.h"
  15. #include "cmRpt.h"
  16. #include "cmErr.h"
  17. #include "cmCtx.h"
  18. #include "cmMem.h"
  19. #include "cmMallocDebug.h"
  20. #include "cmLinkedHeap.h"
  21. #include "cmJson.h"
  22. #include "cmThread.h"
  23. #include "cmText.h"
  24. #include "cmFileSys.h"
  25. #include "cmPrefs.h"
  26. #include "cmSymTbl.h"
  27. #include "cmDspValue.h"
  28. #include "cmMsgProtocol.h"
  29. #include "cmAudDspIF.h"
  30. #include "cmAudDspLocal.h"
  31. #include "cmAudioFile.h"
  32. #include "cmAudioFileMgr.h"
  33. #include "cmTime.h"
  34. #include "cmMidi.h"
  35. #include "cmMidiFile.h"
  36. #include "cmTimeLine.h"
  37. #include "cmScore.h"
  38. #include "cmdIf.h"
  39. #include "tlCtl.h"
  40. #include "kcApp.h"
  41. enum
  42. {
  43. kAppWndW = 1600,
  44. kAppWndH = 750,
  45. kAppWndX = 10,
  46. kAppWndY = 10
  47. };
  48. kcApp* kcAppPtr = NULL;
  49. void print( void*, const cmChar_t* text)
  50. { puts(text); }
  51. cmRC_t print_queue_cb(void* userCbPtr, unsigned msgByteCnt, const void* msgDataPtr )
  52. {
  53. print(NULL,(const char*)msgDataPtr);
  54. return cmOkRC;
  55. }
  56. cmRC_t handleSsInitMsg( void* cbDataPtr, const cmAudioSysSsInitMsg_t* r, const char* iDevLabel, const char* oDevLabel )
  57. { kcAppPtr->_handleSsInitMsg(r,iDevLabel,oDevLabel); return cmOkRC; }
  58. cmRC_t handleStatusMsg( void* cbDataPtr, const cmAudioSysStatus_t* r, const double* iMeterArray, const double* oMeterArray )
  59. { kcAppPtr->_handleStatusMsg(r,iMeterArray,oMeterArray); return cmOkRC;}
  60. cmRC_t handleUiMsg( void* cbDataPtr, const cmDspUiHdr_t* r )
  61. { kcAppPtr->_handleUiMsg(r); return cmOkRC;}
  62. cmPrRC_t kcInitPrefs( cmCtx_t* ctx, cmPrH_t* prH )
  63. {
  64. cmPrRC_t rc = kOkPrRC;
  65. if((rc = cmPrefsInit(ctx, prH, NULL, NULL, NULL, NULL, NULL )) != kOkPrRC )
  66. return rc;
  67. unsigned flags = 0;
  68. cmPrefsCreateInt(*prH, 1, "appWndW", flags, kAppWndW );
  69. cmPrefsCreateInt(*prH, 2, "appWndH", flags, kAppWndH );
  70. cmPrefsCreateInt(*prH, 3, "appWndX", flags, kAppWndX );
  71. cmPrefsCreateInt(*prH, 4, "appWndY", flags, kAppWndY );
  72. return cmPrefsRC(*prH);
  73. }
  74. int main( int argc, char* argv[] )
  75. {
  76. cmCtx_t ctx;
  77. cmTsMp1cH_t printqH = cmTsMp1cNullHandle;
  78. const char* appPrefDir = "kc";
  79. const char* appTitle = "KC Console";
  80. bool memDebugFl = false; //cmDEBUG_FL;
  81. unsigned memPadByteCnt = memDebugFl ? 8 : 0;
  82. unsigned memAlignByteCnt = 16;
  83. unsigned memFlags = memDebugFl ? (kTrackMmFl | kDeferFreeMmFl | kFillUninitMmFl) : 0;
  84. cmAdlH_t adlH = cmAdlNullHandle;
  85. cmAiH_t aiH = cmAiNullHandle;
  86. cmPrH_t prH = cmPrNullHandle;
  87. cmAdIfDispatch_t r;
  88. cmCtxSetup(&ctx,appTitle,print,print,NULL,memPadByteCnt,memAlignByteCnt,memFlags);
  89. // initialize the memory mgr
  90. if(cmMdInitialize( memPadByteCnt, memAlignByteCnt, memFlags, &ctx.rpt ) != kOkMmRC )
  91. {
  92. cmErrMsg(&ctx.err,kMemFailKmRC,"Heap initialization failed.");
  93. goto errLabel;
  94. }
  95. // initialize the file system
  96. if( cmFsInitialize( &ctx, appPrefDir ) != kOkFsRC )
  97. cmErrMsg(&ctx.err,kFileSysFailKmRC,"File system initialization failed.");
  98. // initialize the text system
  99. if( cmTsInitialize(&ctx) != kOkTxRC )
  100. cmErrMsg(&ctx.err,kTextSysFailKmRC,"Text system initialization failed.");
  101. // iniitalize the preferences
  102. if( kcInitPrefs(&ctx,&prH) != kOkPrRC )
  103. cmErrMsg(&ctx.err,kPrefsFailKmRC,"Preference initializatkion failed.");
  104. // create the print queue
  105. if( cmTsMp1cCreate( &printqH, 8192, print_queue_cb, NULL, NULL ) != kOkThRC )
  106. cmErrMsg(&ctx.err,kQueueFailKmRC,"Print queue creation failed.");
  107. r.cbDataPtr = NULL;
  108. r.ssInitFunc = handleSsInitMsg;
  109. r.statusFunc = handleStatusMsg;
  110. r.uiFunc = handleUiMsg;
  111. // initialize the audio engine
  112. if( cmAudDspLocalAllocate(&ctx,&adlH,&r) != kOkAdlRC )
  113. cmErrMsg(&ctx.err,kEngFailKmRC,"The audio DSP local server allocation failed.");
  114. else
  115. if(cmAdIfIsValid(aiH = cmAudDspLocalIF_Handle(adlH)) == false )
  116. cmErrMsg(&ctx.err,kEngFailKmRC,"The audio DSP interface handle is not valid.");
  117. if( cmErrLastRC(&ctx.err) == kOkKmRC )
  118. {
  119. int appWndW = cmPrefsIntDef(prH,"appWndW", kAppWndW);
  120. int appWndH = cmPrefsIntDef(prH,"appWndH", kAppWndH);
  121. int appWndX = cmPrefsIntDef(prH,"appWndX", kAppWndX);
  122. int appWndY = cmPrefsIntDef(prH,"appWndY", kAppWndY);
  123. kcAppPtr = new kcApp(&ctx, prH, printqH, appWndW, appWndH, appTitle, aiH, argc, argv);
  124. kcAppPtr->resize(appWndX,appWndY,appWndW,appWndH);
  125. cmAudDspLocalSendSetup(adlH);
  126. Fl::run();
  127. delete kcAppPtr;
  128. kcAppPtr=NULL;
  129. // reset the pgm context and print queue console output to stdout
  130. cmRptSetup(&ctx.rpt,print,print,NULL);
  131. cmTsMp1cSetCbFunc(printqH, print_queue_cb, NULL );
  132. }
  133. // empty any pending text to stdout
  134. while( cmTsMp1cMsgWaiting(printqH) )
  135. if( cmTsMp1cDequeueMsg(printqH, NULL, 0) != kOkThRC )
  136. cmErrMsg(&ctx.err,kQueueFailKmRC,"Print dequeue failed.");
  137. // release the engine
  138. if( cmAudDspLocalFree(&adlH) != kOkAdlRC )
  139. cmErrMsg(&ctx.err,kEngFailKmRC,"Audio DSP release failed.");
  140. // destroy the print queue
  141. if( cmTsMp1cDestroy(&printqH) != kOkThRC )
  142. cmErrMsg(&ctx.err,kQueueFailKmRC,"Print queue destroy failed.");
  143. // write the preferences file
  144. if( cmPrefsIsDirty(prH) )
  145. if( cmPrefsWrite(prH,cmPrefsFileName(prH)) != kOkPrRC )
  146. cmErrMsg(&ctx.err,kPrefsFailKmRC,"Preferences save failed.");
  147. // finalize the preferences file
  148. if( cmPrefsFinalize(&prH) != kOkPrRC )
  149. cmErrMsg(&ctx.err,kPrefsFailKmRC,"Preference finalize failed.");
  150. // finalize the text system
  151. if( cmTsFinalize() != kOkTxRC )
  152. cmErrMsg(&ctx.err,kTextSysFailKmRC,"Text system finalization failed.");
  153. // finalize the file system
  154. if( cmFsFinalize() != kOkFsRC )
  155. cmErrMsg(&ctx.err,kFileSysFailKmRC,"File system finalize failed.");
  156. // report memory mgr errors
  157. if( cmMdIsValid() )
  158. cmMdReport( kIgnoreNormalMmFl );
  159. // finalize the memory manager
  160. if( cmMdFinalize() != kOkMmRC )
  161. cmErrMsg(&ctx.err,kMemFailKmRC,"Heap finalization failed.");
  162. errLabel:
  163. return 0;
  164. }