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 8.0KB

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