Programmable real-time audio signal processing application
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tlCtl.cpp 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. #include <FL/Fl.H>
  2. #include <FL/Fl_Widget.H>
  3. #include <FL/Fl_Window.H>
  4. #include <FL/Fl_Menu_Bar.H>
  5. #include <FL/Fl_Group.H>
  6. #include <FL/fl_draw.H>
  7. #include <vector>
  8. #include "Fl_Splitter.h"
  9. #include "Fl_CbLinker.h"
  10. #include "cmPrefix.h"
  11. #include "cmGlobal.h"
  12. #include "cmFloatTypes.h"
  13. #include "cmRpt.h"
  14. #include "cmErr.h"
  15. #include "cmCtx.h"
  16. #include "cmMem.h"
  17. #include "cmMallocDebug.h"
  18. #include "cmLinkedHeap.h"
  19. #include "cmFileSys.h"
  20. #include "cmThread.h"
  21. #include "cmText.h"
  22. #include "cmPrefs.h"
  23. #include "cmSymTbl.h"
  24. #include "cmTime.h"
  25. #include "cmMidi.h"
  26. #include "cmMidiFile.h"
  27. #include "cmAudioFile.h"
  28. #include "cmAudioFileMgr.h"
  29. #include "cmTimeLine.h"
  30. #include "cmScore.h"
  31. #include "cmTakeSeqBldr.h"
  32. #include "cmGr.h"
  33. #include "cmGrDevCtx.h"
  34. #include "cmGrPlot.h"
  35. #include "cmGrPage.h"
  36. #include "cmGrFltk.h"
  37. #include "gvHashFunc.h"
  38. #include "cmGrTlFltk.h"
  39. #include "cmGrScFltk.h"
  40. #include "cmGrTksbFltk.h"
  41. #include "cmGrTksrFltk.h"
  42. #include "cmGr2dFltk.h"
  43. #include "cmdIf.h"
  44. #include "tlCtl.h"
  45. //----------------------------------------------------------------------------------------------------
  46. //----------------------------------------------------------------------------------------------------
  47. //----------------------------------------------------------------------------------------------------
  48. class tlStatusWnd : public Fl_Window
  49. {
  50. public:
  51. tlStatusWnd(int w, int h, const char* label);
  52. virtual ~tlStatusWnd();
  53. void display( const char* msg );
  54. virtual void draw();
  55. private:
  56. char* _msg;
  57. enum { kBorder = 10 };
  58. };
  59. tlStatusWnd::tlStatusWnd(int w, int h, const char* label)
  60. : Fl_Window(w,h,label),_msg(NULL)
  61. {
  62. end();
  63. clear_border();
  64. }
  65. tlStatusWnd:: ~tlStatusWnd()
  66. {
  67. cmMemFree(_msg);
  68. }
  69. void tlStatusWnd::display( const char* msg )
  70. {
  71. bool fl = false;
  72. int border = 2*kBorder;
  73. // store the string
  74. _msg = cmMemResizeStr(_msg,msg);
  75. // The offscreen drawing context is probably not necesary.
  76. // However if a font change was applied then it would guarantee that
  77. // fl_measure() used the correct font.
  78. Fl_Offscreen os = fl_create_offscreen(w(),h());
  79. fl_begin_offscreen(os);
  80. // BEWARE: fl_measure uses 'ww' on input.
  81. int ww=0,hh=0;
  82. fl_measure(_msg,ww,hh,0);
  83. fl_end_offscreen();
  84. fl_delete_offscreen(os);
  85. if( ww+border < w() )
  86. ww = w();
  87. else
  88. {
  89. ww += border;
  90. fl = true;
  91. }
  92. if( hh+border < h() )
  93. hh = h();
  94. else
  95. {
  96. hh = hh+border;
  97. fl = true;
  98. }
  99. if(fl)
  100. size(ww,hh);
  101. int xx = parent()->w()/2 - ww/2;
  102. int yy = parent()->h()/2 - hh/2;
  103. position(xx,yy);
  104. set_modal();
  105. show();
  106. }
  107. void tlStatusWnd::draw()
  108. {
  109. // BEWARE: fl_measure uses 'ww' on input.
  110. int ww=0,hh=0;
  111. fl_measure(_msg,ww,hh,0);
  112. int xx = w()/2 - ww/2;
  113. int yy = h()/2;
  114. fl_rect(0,0,w(),h());
  115. fl_draw(_msg,xx,yy);
  116. }
  117. //----------------------------------------------------------------------------------------------------
  118. //----------------------------------------------------------------------------------------------------
  119. //----------------------------------------------------------------------------------------------------
  120. tlCtl::tlCtl( cmCtx_t* ctx, Fl_Window* app, Fl_Menu_Bar* menuBar, tlCtlRspdr* rspdr )
  121. : _ctx(ctx),_rspdr(rspdr),
  122. _cmdIf(NULL),_tlCtlr(NULL),_scCtlr(NULL),_tksbCtlr(NULL),_tksrCtlr(NULL),_2dCtlr(NULL),
  123. _statusWnd(NULL),_menu(menuBar)
  124. {
  125. cmErrSetup(&_err,&ctx->rpt,"tlCtl");
  126. _cmdIf = new cmdIf( ctx,this );
  127. app->add(_statusWnd = new tlStatusWnd(app->w()/2,app->h()/2,"Status"));
  128. }
  129. tlCtl::~tlCtl()
  130. {
  131. delete _cmdIf;
  132. delete _tlCtlr;
  133. delete _scCtlr;
  134. delete _tksbCtlr;
  135. delete _tksrCtlr;
  136. delete _2dCtlr;
  137. delete _statusWnd;
  138. }
  139. Fl_Widget* tlCtl::initTimeLineCtlr( int x, int y, int w, int h )
  140. {
  141. delete _tlCtlr;
  142. _tlCtlr = NULL;
  143. return _tlCtlr = new cmGrTlFltk(_ctx,_cmdIf,_menu,x,y,w,h);
  144. }
  145. Fl_Widget* tlCtl::initScoreCtlr( int x, int y, int w, int h )
  146. {
  147. delete _scCtlr;
  148. _scCtlr = NULL;
  149. return _scCtlr = new cmGrScFltk(_ctx,_cmdIf,_menu,x,y,w,h);
  150. }
  151. Fl_Widget* tlCtl::initTakeSeqBldrCtlr( int x, int y, int w, int h )
  152. {
  153. delete _tksbCtlr;
  154. _tksbCtlr = NULL;
  155. return _tksbCtlr = new cmGrTksbFltk(_ctx,_cmdIf,_menu,x,y,w,h);
  156. }
  157. Fl_Widget* tlCtl::initTakeSeqRendCtlr( int x, int y, int w, int h )
  158. {
  159. delete _tksrCtlr;
  160. _tksrCtlr = NULL;
  161. return _tksrCtlr = new cmGrTksrFltk(_ctx,_cmdIf,_menu,x,y,w,h);
  162. }
  163. Fl_Widget* tlCtl::init2dCtlr( int x, int y, int w, int h )
  164. {
  165. delete _2dCtlr;
  166. _2dCtlr = NULL;
  167. return _2dCtlr = new cmGr2dFltk(_ctx,_menu,x,y,w,h);
  168. }
  169. void tlCtl::openTlFile( const cmChar_t* fn )
  170. {
  171. if( fn!=NULL && _tlCtlr != NULL )
  172. _cmdIf->open(fn);
  173. }
  174. void tlCtl::openScoreFile( const cmChar_t* fn )
  175. {
  176. if( fn!=NULL && _scCtlr != NULL )
  177. _cmdIf->setScore(fn);
  178. }
  179. void tlCtl::openTakeSeqBldr( void* v )
  180. {
  181. if( v!=NULL && _tksbCtlr != NULL )
  182. _tksbCtlr->setTksbHandle(v);
  183. }
  184. void tlCtl::openTakeSeqRend( void* v )
  185. {
  186. if( v!=NULL && _tksrCtlr != NULL )
  187. _tksrCtlr->setTksbHandle(v);
  188. }
  189. void tlCtl::setAudioFilePath( const cmChar_t* path )
  190. {
  191. if( path!=NULL )
  192. _cmdIf->setAudioFilePath(path);
  193. }
  194. void tlCtl::setAudioFileCursor( unsigned smpIdx )
  195. {
  196. if( _tlCtlr != NULL )
  197. _tlCtlr->setAudioFileCursor(smpIdx);
  198. }
  199. void tlCtl::setTimeLineSelectBar( unsigned barNumb )
  200. {
  201. if( _tlCtlr != NULL )
  202. _tlCtlr->selectBar(barNumb);
  203. }
  204. void tlCtl::setScoreSelectBar( unsigned barNumb )
  205. {
  206. if( _scCtlr != NULL )
  207. _scCtlr->selectBar(barNumb);
  208. }
  209. void tlCtl::setScoreLocation( unsigned locIdx, unsigned smpIdx, unsigned pitch, unsigned vel )
  210. {
  211. _cmdIf->setScoreLocation( locIdx, smpIdx, pitch, vel );
  212. }
  213. void tlCtl::setScoreVarValue( unsigned locIdx, unsigned varId, double value )
  214. {
  215. _cmdIf->setScoreVarValue( locIdx, varId, value );
  216. }
  217. void tlCtl::setScoreDynLevel( unsigned evtIdx, unsigned dynLvl )
  218. {
  219. _cmdIf->setScoreDynLevel(evtIdx,dynLvl);
  220. }
  221. void tlCtl::refreshTakeSeqRend()
  222. {
  223. if( _tksrCtlr != NULL )
  224. _tksrCtlr->refresh();
  225. }
  226. void tlCtl::onIdle()
  227. { _cmdIf->onIdle(); }
  228. void tlCtl::cmdIfShowStatusMsg( const char* msg )
  229. {
  230. _statusWnd->display(msg);
  231. }
  232. void tlCtl::cmdIfHideStatus()
  233. {
  234. _statusWnd->hide();
  235. _statusWnd->set_non_modal();
  236. }
  237. void tlCtl::cmdIfErrorMsg( const char* msg )
  238. {
  239. cmErrMsg(&_err,1,"%s",msg);
  240. }
  241. void tlCtl::cmdIfTimeLineMsg( const void* msg, unsigned msgByteCnt )
  242. {
  243. switch( _tlCtlr->recvTimeLineMsg(msg,msgByteCnt) )
  244. {
  245. case kInitMsgTlId:
  246. if( _rspdr!= NULL && _cmdIf->tlFileName() != NULL )
  247. _rspdr->tlCtlNewTimeLineFile(this,_cmdIf->tlFileName());
  248. break;
  249. case kDoneMsgTlId:
  250. if( _scCtlr != NULL && _tlCtlr != NULL )
  251. _scCtlr->setSampleRate( _tlCtlr->sampleRate() );
  252. _menu->parent()->redraw();
  253. break;
  254. default:
  255. break;
  256. }
  257. }
  258. void tlCtl::cmdIfAudioFileLoad( unsigned fileId )
  259. {
  260. _tlCtlr->recvAudioFileLoad(fileId);
  261. }
  262. void tlCtl::cmdIfScoreMsg( const void* msg, unsigned msgByteCnt )
  263. {
  264. assert( _scCtlr != NULL );
  265. switch( _scCtlr->recvScoreMsg(msg,msgByteCnt) )
  266. {
  267. case kBeginMsgScId:
  268. if( _rspdr!= NULL && _cmdIf->scoreFileName() != NULL )
  269. _rspdr->tlCtlNewScoreFile(this,_cmdIf->scoreFileName());
  270. break;
  271. case kEndMsgScId:
  272. _scCtlr->setSampleRate( _tlCtlr->sampleRate() );
  273. _scCtlr->redraw();
  274. break;
  275. _menu->parent()->redraw();
  276. default:
  277. break;
  278. }
  279. }
  280. void tlCtl::cmdIfOnTimeLineMarkerSelect( unsigned markerId )
  281. {
  282. }
  283. void tlCtl::cmdIfOnTimeLineMidiEvtSelect( unsigned midiEvtId )
  284. {
  285. }
  286. void tlCtl::cmdIfOnScoreBarSelect( unsigned scoreIndex )
  287. {
  288. }
  289. unsigned tlCtl::timeLineSelectedMarkerId() const
  290. {
  291. if( _tlCtlr==NULL)
  292. return cmInvalidId;
  293. return _tlCtlr->timeLineSelectedMarkerId();
  294. }
  295. unsigned tlCtl::scoreSelectedEleIndex() const
  296. {
  297. if(_scCtlr==NULL)
  298. return cmInvalidId;
  299. return _scCtlr->scoreSelectedEleIndex();
  300. }
  301. unsigned tlCtl::tksbSelectedEleIndex() const
  302. {
  303. if(_tksbCtlr==NULL)
  304. return cmInvalidId;
  305. return _tksbCtlr->scoreSelectedEleIndex();
  306. }
  307. void tlCtl::testStub()
  308. {
  309. _cmdIf->testStub();
  310. }