Browse Source

Used libcmpp and put cm startup in kcMain.cpp.

master
kpl 11 years ago
parent
commit
e1593195ea
5 changed files with 220 additions and 298 deletions
  1. 1
    2
      .gitignore
  2. 7
    13
      Makefile.am
  3. 55
    232
      src/kc/kcApp.cpp
  4. 27
    43
      src/kc/kcApp.h
  5. 130
    8
      src/kc/kcMain.cpp

+ 1
- 2
.gitignore View File

@@ -1,7 +1,6 @@
1 1
 # directories to ignore
2 2
 libcm
3
-libgm
4
-libkplfltk
3
+libcmpp
5 4
 tlCtl
6 5
 
7 6
 .deps

+ 7
- 13
Makefile.am View File

@@ -12,12 +12,12 @@ include_HEADERS=
12 12
 
13 13
 
14 14
 AM_CPPFLAGS  = -D _GNU_SOURCE  -I.. -I$(srcdir)/src/libcm  -I$(srcdir)/src/libcm/dsp  -I$(srcdir)/src/libcm/vop  -I$(srcdir)/src/libcm/app
15
-AM_CPPFLAGS +=  -I$(srcdir)/src/libkplfltk -I$(srcdir)/src/libgm -I$(srcdir)/src/tlCtl 
15
+AM_CPPFLAGS +=  -I$(srcdir)/src/libcmpp -I$(srcdir)/src/libcmpp/fltk -I$(srcdir)/src/tlCtl 
16 16
 AM_CFLAGS    = -Wno-multichar 
17 17
 AM_CXXFLAGS  = 
18 18
 AM_LDFLAGS   =  
19
-MYLIBS       = -lpthread  -lfftw3f -lfftw3 -lfltk -lcairo -lX11
20
-CMLIBS       = src/libcm/libcm.la  src/libgm/libgm.la src/libkplfltk/libkplfltk.la # autoconfig manual recommends storing direct referenes to non-3rd party libraries rather than using -L and -l
19
+MYLIBS       = -lpthread  -lfftw3f -lfftw3 -lfltk -lX11
20
+CMLIBS       = src/libcm/libcm.la  src/libcmpp/libcmpp.la # autoconfig manual recommends storing direct referenes to non-3rd party libraries rather than using -L and -l
21 21
 
22 22
 
23 23
 # debug/release switches
@@ -56,22 +56,16 @@ src_libcm_libcm_la_SOURCES   = $(cmSRC) $(cmHDR)
56 56
 include_HEADERS += $(cmHDR)
57 57
 lib_LTLIBRARIES += src/libcm/libcm.la
58 58
 
59
-include src/libkplfltk/Makefile.am
60
-src_libkplfltk_libkplfltk_la_SOURCES = $(kplfltkSRC) $(kplfltkHDR)
61
-include_HEADERS                     += $(kplfltkHDR)
62
-lib_LTLIBRARIES                     += src/libkplfltk/libkplfltk.la
63
-
64
-include src/libgm/Makefile.am
65
-src_libgm_libgm_la_SOURCES  = $(gmSRC) $(gmHDR)
66
-include_HEADERS            += $(gmHDR)
67
-lib_LTLIBRARIES 	   += src/libgm/libgm.la
59
+include src/libcmpp/Makefile.am
60
+src_libcmpp_libcmpp_la_SOURCES = $(cmppSRC) $(cmppHDR)
61
+include_HEADERS                     += $(cmppHDR)
62
+lib_LTLIBRARIES                     += src/libcmpp/libcmpp.la
68 63
 
69 64
 include src/tlCtl/Makefile.am
70 65
 src_kc_kc_SOURCES  = $(tlCtlSRC)
71 66
 
72 67
 src_kc_kc_SOURCES += src/kc/kcMain.cpp 
73 68
 src_kc_kc_SOURCES += src/kc/kcApp.h          src/kc/kcApp.cpp 
74
-# src_kc_kc_SOURCES += src/kc/Fl_Splitter.h    src/kc/Fl_Splitter.cpp
75 69
 src_kc_kc_SOURCES += src/kc/Fl_File_Btn.h    src/kc/Fl_Vert_Progress.h
76 70
 src_kc_kc_SOURCES += src/kc/Fl_File_Btn.cpp  src/kc/Fl_Vert_Progress.cpp
77 71
 

+ 55
- 232
src/kc/kcApp.cpp View File

@@ -40,44 +40,35 @@
40 40
 #include "cmMsgProtocol.h"
41 41
 #include "cmAudDspIF.h"
42 42
 #include "cmAudDspLocal.h"
43
-#include "kcApp.h"
44
-
45 43
 #include "cmAudioFile.h"
46 44
 #include "cmAudioFileMgr.h"
47
-
48 45
 #include "cmMidi.h"
49 46
 #include "cmMidiFile.h"
50 47
 #include "cmTimeLine.h"
51 48
 #include "cmScore.h"
49
+#include "cmdIf.h"
50
+#include "tlCtl.h"
51
+#include "kcApp.h"
52
+
53
+
52 54
 #include "cmGr.h"
53 55
 #include "cmGrDevCtx.h"
54 56
 #include "cmGrPlot.h"
55 57
 #include "cmGrPage.h"
56
-#include "cmGrDevDrvFltk.h"
57
-#include "cmGrDevDrvCairoFltk.h"
58
-#include "cmGrWidgetFltk.h"
59
-
60
-#include "Fl_CbLinker.h"
58
+#include "cmGrFltk.h"
61 59
 
62
-#include "cmGrPlotPageFltk.h"
63
-#include "cmGrPlotCtlrFltk.h"
64
-#include "gvHashFunc.h"
65
-#include "cmGrTlCtlrFltk.h"
66
-#include "cmGrScCtlrFltk.h"
67
-
68
-#include "cmdIf.h"
69
-#include "tlCtl.h"
70 60
 
71 61
 #define TIMER_PERIOD (1.0/20.0)   // 50ms
72 62
 
73 63
 
74
-kcApp::kcApp(int w, int h, const char *l, int argc, char *argv[])
75
-  : Fl_Double_Window(w, h, l),
76
-    splt(NULL),_menu(NULL),
77
-    _adlH(cmAdlNullHandle),_aiH(cmAiNullHandle),
78
-    _statIdx(0),_pageList(NULL),_ctlList(NULL),_prH(cmPrNullHandle),_prefsFn(NULL),
79
-    _stopTimerFl(false),_jsH(cmJsonNullHandle),_newPageFl(true),_incrColW(0),_colW(0),_horzBordFl(false),_horzBord(0),
80
-    _closeCnt(0),_ssCnt(0),_ssArray(0),_ssPhase(0),_ssUpdateFl(false),_printqH(cmTsQueueNullHandle),
64
+kcApp::kcApp(cmCtx_t* ctx, cmTsMp1cH_t printqH, int w, int h, const cmChar_t* title, cmAiH_t aiH, int argc, char* argv[] )
65
+  : Fl_Double_Window(w, h,title),
66
+    splt(NULL),_menu(NULL),_aiH(aiH),
67
+    _statIdx(0),_pageList(NULL),_ctlList(NULL),
68
+    _stopTimerFl(false),_newPageFl(true),
69
+    _incrColW(0),_colW(0),_horzBordFl(false),_horzBord(0),
70
+    _closeCnt(0),_ssCnt(0),_ssArray(0),_ssPhase(0),_ssUpdateFl(false),
71
+    _printqH(printqH),_printFl(0),
81 72
     _tlCtl(NULL)
82 73
 {
83 74
   // install a callback to cleanup when the app window closes
@@ -91,8 +82,7 @@ kcApp::kcApp(int w, int h, const char *l, int argc, char *argv[])
91 82
   splt = new Fl_HSplitter(0, kMenuH, w, h-kStatusH-kMenuH, h-kStatusH-kMenuH-100);
92 83
   end();
93 84
 
94
-  // Create a text display object for console output and
95
-  // add it to the lower splitter area
85
+  // Create a text display object for console output andvadd it to the lower splitter area
96 86
   buf = new Fl_Text_Buffer();
97 87
   con = new Fl_Text_Display(splt->container2->x(),splt->container2->y(),splt->container2->w(),splt->container2->h());
98 88
   con->buffer(buf);
@@ -101,39 +91,26 @@ kcApp::kcApp(int w, int h, const char *l, int argc, char *argv[])
101 91
   // Create a tab view and added it to the upper splitter area
102 92
   tabs = new Fl_Tabs(splt->container1->x(),splt->container1->y(),splt->container1->w(),splt->container1->h());
103 93
   tabs->callback(_s_tab_cb,this);
104
-  
94
+  tabs->end();
105 95
   splt->container1->add(tabs);
106 96
 
107 97
   int tx,ty,th,tw;
108 98
   tabs->client_area(tx,ty,tw,th);
109 99
 
110 100
   // Create the 'Setup' tab group
111
-  tabs->begin();  
112 101
   Fl_Group* setup_grp = new Fl_Group(tx,ty,tw,th,"Setup");
102
+  tabs->add(setup_grp);
113 103
   _createSetupDlg(setup_grp);
114
-  tabs->end();
115 104
 
105
+  // Create the master group
106
+  tabs->add(mstr_grp  = new Fl_Group(tx,ty,tw,th,"Master"));
116 107
 
117
-  tabs->begin();
118
-  mstr_grp  = new Fl_Group(tx,ty,tw,th,"Master");
119
-  tabs->end();
120
-
121
-  // Create the 'Controls' tab group
122
-  /*
123
-  tabs->begin();
124
-  ctl_grp = new Fl_Group(tx,ty,tw,th,"Controls");  
125
-  ctl_grp->begin();
126
-  Fl_Box* bx = new Fl_Box(FL_NO_BOX,ctl_grp->x()+ctl_grp->w(),ctl_grp->y()+ctl_grp->h(),1,1,NULL);
127
-  ctl_grp->resizable(bx); 
128
-  ctl_grp->end();  tabs->end();
129
-  */
130 108
 
131 109
   // Create an empty tab group and make it resizable 
132 110
   // to prevent the other tab groups from being resizable.
133
-  tabs->begin();
134 111
   Fl_Group* wdgt = new Fl_Group(tx,ty+30,1,1);
112
+  tabs->add(wdgt);
135 113
   tabs->resizable(wdgt);  // make other tabs non-resizable
136
-  tabs->end();
137 114
 
138 115
 
139 116
   // make the splitter the resizable group element (thereby making the menu non-resizable).
@@ -142,13 +119,13 @@ kcApp::kcApp(int w, int h, const char *l, int argc, char *argv[])
142 119
   show(argc, argv);
143 120
 
144 121
 
145
-  // initialize the audio DSP system
146
-  audioDspInitialize(&_ctx,_s_print,this);
122
+  // direct all output to the console window
123
+  cmRptSetup(&_ctx.rpt,_s_print,_s_print, this);
124
+  cmTsMp1cSetCbFunc(_printqH, _s_print_queue_cb, this );
147 125
 
148 126
   // install a timer to check for messages from the engine
149 127
   Fl::add_timeout(TIMER_PERIOD,_s_status_timeout_cb,this);
150 128
 
151
-
152 129
 }
153 130
 
154 131
 kcApp::~kcApp()
@@ -158,119 +135,18 @@ kcApp::~kcApp()
158 135
 }
159 136
 
160 137
 
161
-// this function is only called from the constructor
162
-kcApp::kcKmRC_t kcApp::audioDspInitialize(cmCtx_t* ctx, cmRptPrintFunc_t printFunc, void* printFuncArg)
163
-{
164
-  kcKmRC_t rc = kOkKmRC;
165
-
166
-  // initialize the heap check library
167
-  bool       memDebugFl          = cmDEBUG_FL;
168
-  unsigned   memPadByteCnt       = memDebugFl ? 8 : 0;
169
-  unsigned   memAlignByteCnt     = 16;
170
-  unsigned   memFlags            = memDebugFl ? (kTrackMmFl | kDeferFreeMmFl | kFillUninitMmFl) : 0;
171
-
172
-  cmCtxSetup(ctx,"KC Main",printFunc,printFunc,printFuncArg,memPadByteCnt,memAlignByteCnt,memFlags);
173
-
174
-  cmMdInitialize( memPadByteCnt, memAlignByteCnt, memFlags, &ctx->rpt );
175
-
176
-  cmTsInitialize(ctx);
177
-
178
-  cmFsInitialize( ctx, "kc" );
179
-
180
-  cmJsonInitialize(&_jsH,&_ctx);
181
-
182
-  //_loadPrefs(ctx);
183
-
184
-  // create the print queue
185
-  if( cmTsQueueCreate( &_printqH, 4*8192, kcApp::_s_print_queue_cb, this, &_ctx.rpt ) != kOkThRC )
186
-    cmErrMsg(&ctx->err,kPrintQueFailKmRC,"Print queue creation failed.");
187
-
188
-  cmAdIfDispatch_t r;
189
-  r.cbDataPtr     = this;
190
-  r.ssInitFunc    = _s_handleSsInitMsg;
191
-  r.statusFunc    = _s_handleStatusMsg;
192
-  r.uiFunc        = _s_handleUiMsg;
193
-    
194
-  if( cmAudDspLocalAllocate(ctx,&_adlH,&r) != kOkAdlRC )
195
-  {
196
-    rc = cmErrMsg(&ctx->err,kEngFailKmRC,"The audio DSP local server allocation failed.");
197
-    goto errLabel;
198
-  }
199
-
200
-  if(cmAdIfIsValid(_aiH = cmAudDspLocalIF_Handle(_adlH)) == false )
201
-  {
202
-    rc = cmErrMsg(&ctx->err,kEngFailKmRC,"The audio DSP interface handle is not valid.");
203
-    goto errLabel;
204
-  }
205
-
206
- errLabel:
207
-  return rc;
208
-}
209
-
210
-bool kcApp::audioDspIsValid()
211
-{  return cmAudDspLocalIsValid(_adlH) && cmAdIfIsValid(_aiH); }
212
-
213
-kcApp::kcKmRC_t kcApp::audioDspFinalize()
214
-{
215
-  kcKmRC_t rc = kOkKmRC;
216
-
217
-  _stopTimerFl = true;
218
-
219
-  if( cmJsonFinalize(&_jsH) != kOkJsRC )
220
-    rc = cmErrMsg(&_ctx.err,kJsonFailKmRC,"JSON object finalization failed.");
221
-
222
-  // If the preferences are dirty or the prefs file does not exist then write them
223
-  if( cmPrefsIsValid(_prH) )
224
-  {
225
-    
226
-    if( _prefsFn != NULL && (cmPrefsIsValid(_prH) && (cmPrefsIsDirty(_prH) || cmFsIsFile(_prefsFn)==false)) )
227
-      if( cmPrefsWrite(_prH,_prefsFn) != kOkPrRC )
228
-        rc = cmErrMsg(&_ctx.err,kPrefWriteFailKmRC,"Preference save failed on file '%s'.",_prefsFn);
229
-
230
-    if( cmPrefsFinalize(&_prH) != kOkPrRC )
231
-      rc = cmErrMsg(&_ctx.err,kPrefFailKmRC,"Prefrence finalization failed.");
232
-    
233
-  }
234
-
235
-  // finalize the real-time system
236
-  //rc = stopEngine(_ctx,*hp);
237
-
238
-  // release the engine
239
-  if( cmAudDspLocalFree(&_adlH) != kOkAdlRC )
240
-    rc = cmErrMsg(&_ctx.err,kEngFailKmRC,"Audio DSP release failed.");
241
-
242
-  // print any pending text in the print queue
243
-  _checkPrintQueue();
244
-
245
-  // the app threads are stopped so it is safe to stop using the print queue
246
-  if( cmTsQueueDestroy(&_printqH) == kOkThRC )
247
-    _printqH = cmTsQueueNullHandle;
248
-  else
249
-    cmErrMsg(&_ctx.err,kPrintQueFailKmRC,"Print queue destroy failed.");
250
-
251
-  // finalize the file system
252
-  cmFsFinalize();
253
-
254
-  cmTsFinalize();
255
-
256
-  // report memory mgr errors
257
-  if( cmMdReport( kIgnoreNormalMmFl ) != kOkMmRC )
258
-    rc = kMemFailKmRC;
259
-
260
-  // finalize the memory manager
261
-  if( cmMdFinalize() != kOkMmRC )
262
-    rc = kMemFailKmRC;
263
-
264
-  return rc;
265
-}
266
-
267
-
268 138
 void kcApp::resize(int x, int y, int w, int h)
269 139
 {
270 140
   Fl_Double_Window::resize(x, y, w, h);
271 141
   splt->resize(0, kMenuH, w, h-kStatusH);
272 142
 }
273 143
 
144
+void kcApp::tlCtlNewTimeLineFile( tlCtl* tlCtl, const cmChar_t* fn )
145
+{}
146
+
147
+void kcApp::tlCtlNewScoreFile(    tlCtl* tlCtl, const cmChar_t* fn )
148
+{}
149
+
274 150
 
275 151
 void kcApp::_createSetupDlg( Fl_Group* grp )
276 152
 {
@@ -334,12 +210,7 @@ void kcApp::_createMenu(int w, int h)
334 210
   Fl_Menu_Item items[] =
335 211
   {
336 212
     { "&File", 0, 0, 0, FL_SUBMENU },
337
-    { "&New File", 0, (Fl_Callback*)_s_file_new_cb },
338
-    { "&Open File", FL_COMMAND + 'o', (Fl_Callback*)_s_file_open_cb },
339
-    { 0 },
340
-    { "&Edit", 0, 0, 0, FL_SUBMENU },
341
-    { "&Copy",  FL_COMMAND + 'c', (Fl_Callback*)_s_edit_copy_cb },
342
-    { "&Paste", FL_COMMAND + 'v', (Fl_Callback*)_s_edit_paste_cb },
213
+    { "&New File", 0, (Fl_Callback*)_s_menu_cb },
343 214
     { 0 },
344 215
     { 0 }
345 216
   };
@@ -1222,7 +1093,7 @@ void kcApp::_createTmln(  const cmDspUiHdr_t* m )
1222 1093
   w = pg->grp->w();
1223 1094
   h = pg->grp->h();
1224 1095
 
1225
-  cp->u.tmln.tlctl = new tlCtl(&_ctx,this,NULL);
1096
+  cp->u.tmln.tlctl = new tlCtl(&_ctx,this,_menu,this);
1226 1097
 
1227 1098
   // currently we only support one time-line control because
1228 1099
   // we have not yet implmenented a method of providing
@@ -1230,7 +1101,7 @@ void kcApp::_createTmln(  const cmDspUiHdr_t* m )
1230 1101
   assert( _tlCtl == NULL ); 
1231 1102
   _tlCtl = cp->u.tmln.tlctl;
1232 1103
 
1233
-  Fl_Widget* wdgt = cp->u.tmln.tlctl->initTimeLineCtlr(_menu,x,y,w,h);
1104
+  Fl_Widget* wdgt = cp->u.tmln.tlctl->initTimeLineCtlr(x,y,w,h);
1234 1105
 
1235 1106
   _insertNewCtl(cp,m,wdgt,cp->u.tmln.varIdArray,kTmlnVarCnt);
1236 1107
 
@@ -1570,7 +1441,7 @@ void kcApp::_handleSsInitMsg( const cmAudioSysSsInitMsg_t* m, const cmChar_t* in
1570 1441
   ss_t* ss = _ssArray + m->asSubIdx;
1571 1442
   
1572 1443
   int x = 20;
1573
-  int y = 30;
1444
+  int y = 30 + kMenuH;
1574 1445
   int w = 80;
1575 1446
   int h = 20;
1576 1447
   char lblArray[][10] = { "Update","Wakeup","Mesg","Audio" };
@@ -1792,28 +1663,6 @@ void kcApp::_handleUiMsg( const cmDspUiHdr_t* m )
1792 1663
   }
1793 1664
 }
1794 1665
 
1795
-cmRC_t kcApp::_s_handleSsInitMsg( void* cbDataPtr, const cmAudioSysSsInitMsg_t* r, const char* iDevLabel, const char* oDevLabel )
1796
-{
1797
-  kcApp* p = (kcApp*)cbDataPtr;
1798
-  p->_handleSsInitMsg(r,iDevLabel,oDevLabel);
1799
-  return cmOkRC;
1800
-}
1801
-
1802
-cmRC_t kcApp::_s_handleStatusMsg( void* cbDataPtr, const cmAudioSysStatus_t* r, const double* iMeterArray, const double* oMeterArray )
1803
-{
1804
-  kcApp* p = (kcApp*)cbDataPtr;
1805
-  p->_handleStatusMsg(r,iMeterArray,oMeterArray);
1806
-  return cmOkRC;
1807
-}
1808
-
1809
-cmRC_t kcApp::_s_handleUiMsg(     void* cbDataPtr, const cmDspUiHdr_t* r )
1810
-{
1811
-  kcApp* p = (kcApp*)cbDataPtr;
1812
-  p->_handleUiMsg(r);  
1813
-  return cmOkRC;
1814
-}
1815
-
1816
-
1817 1666
 
1818 1667
 // Check for and forward any messages sent to the UI 
1819 1668
 // that are waiting in the audio DSP msg queue.
@@ -1821,7 +1670,7 @@ void kcApp::_getEngMsg()
1821 1670
 {
1822 1671
 
1823 1672
 
1824
-  if( audioDspIsValid() )
1673
+  if( cmAdIfIsValid(_aiH) )
1825 1674
   {
1826 1675
     unsigned i;
1827 1676
 
@@ -1892,16 +1741,18 @@ void kcApp::_callback(void* data)
1892 1741
 {
1893 1742
   if( Fl::event() == FL_CLOSE )
1894 1743
   {
1895
-    unsigned cc = _closeCnt;
1744
+    //unsigned cc = _closeCnt;
1896 1745
 
1897 1746
     ctl_t* cp = _ctlList;
1898 1747
     for(; cp!=NULL; cp=cp->linkPtr)
1899 1748
       if( cp->typeId == kTmlnTypeId )
1900 1749
         delete cp->u.tmln.tlctl;
1901 1750
 
1751
+    _stopTimerFl = true;
1752
+
1902 1753
     // attempt to shut down the pgm
1903
-    if( audioDspFinalize() != kOkKmRC )
1904
-      ++_closeCnt;
1754
+    //if( audioDspFinalize() != kOkKmRC )
1755
+    //  ++_closeCnt;
1905 1756
 
1906 1757
     // the first time the pgm fails to shut down 
1907 1758
     // do not allow the pgm to close the main window
@@ -1931,14 +1782,6 @@ void kcApp::_callback(void* data)
1931 1782
 }
1932 1783
 
1933 1784
 
1934
-void kcApp::_s_on_idle(void *data)
1935
-{ ((kcApp*)data)->_on_idle(); }
1936
-
1937
-void kcApp::_on_idle()
1938
-{ 
1939
-  //_getEngMsg();
1940
-  //_getEngStatus();
1941
-}
1942 1785
 
1943 1786
 void kcApp::_s_status_timeout_cb(void* userPtr)
1944 1787
 { 
@@ -1948,7 +1791,7 @@ void kcApp::_s_status_timeout_cb(void* userPtr)
1948 1791
 
1949 1792
 bool kcApp::_status_timeout_cb()
1950 1793
 {
1951
-  if( cmTsQueueIsValid(_printqH) )
1794
+  if( cmTsMp1cIsValid(_printqH) )
1952 1795
     _checkPrintQueue();
1953 1796
 
1954 1797
   if( !_stopTimerFl )
@@ -1974,37 +1817,13 @@ bool kcApp::_status_timeout_cb()
1974 1817
   //if( !_stopTimerFl )
1975 1818
   //  _getEngStatus();
1976 1819
 
1977
-  return _stopTimerFl==false || cmTsQueueIsValid(_printqH);
1820
+  return _stopTimerFl==false || cmTsMp1cIsValid(_printqH);
1978 1821
 }
1979 1822
 
1980 1823
 
1981 1824
 
1982 1825
 
1983
-void kcApp::_s_file_new_cb(Fl_Widget *w, void *data) 
1984
-{ ((kcApp*)data)->_file_new_cb(w); }
1985
-
1986
-void kcApp::_file_new_cb(Fl_Widget *w) 
1987
-{ }
1988
-
1989
-
1990
-void kcApp::_s_file_open_cb(Fl_Widget *w, void *data) 
1991
-{ ((kcApp*)data)->_file_open_cb(w); }
1992
-
1993
-void kcApp::_file_open_cb(Fl_Widget *w) 
1994
-{ }
1995
-
1996
-
1997
-void kcApp::_s_edit_copy_cb(Fl_Widget *w, void *data) 
1998
-{ ((kcApp*)data)->_edit_copy_cb(w); }
1999
-
2000
-void kcApp::_edit_copy_cb(Fl_Widget *w) 
2001
-{ }
2002
-
2003
-
2004
-void kcApp::_s_edit_paste_cb(Fl_Widget *w, void *data) 
2005
-{ ((kcApp*)data)->_edit_paste_cb(w); }
2006
-
2007
-void kcApp::_edit_paste_cb(Fl_Widget *w) 
1826
+void kcApp::_s_menu_cb(Fl_Widget *w, void *data) 
2008 1827
 { }
2009 1828
 
2010 1829
 
@@ -2016,7 +1835,7 @@ void kcApp::_tab_cb(Fl_Widget*)
2016 1835
   Fl_Widget* w = tabs->value();
2017 1836
   _ssUpdateFl = w == (Fl_Widget*)mstr_grp;
2018 1837
   _ssPhase    = kSsPhaseMax;
2019
-  if( audioDspIsValid() )
1838
+  if( cmAdIfIsValid(_aiH) )
2020 1839
   {
2021 1840
     if( cmAdIfEnableStatusNotify(_aiH, _ssUpdateFl ) != kOkAiRC )
2022 1841
       cmErrMsg(&_ctx.err,kEngFailKmRC,"A request to enable/disable status notification failed.");
@@ -2174,15 +1993,15 @@ void kcApp::vprint(const char* fmt, va_list vl )
2174 1993
   if( n > 0 )
2175 1994
   {
2176 1995
     // if the print queue exists (it might not during startup or shutdown) ...
2177
-    if( cmTsQueueIsValid(_printqH) )
1996
+    if( cmTsMp1cIsValid(_printqH) )
2178 1997
     {
2179 1998
       // ... enqueue the text to print 
2180
-      if( cmTsQueueEnqueueMsg(_printqH,buf,n+1) != kOkThRC )
1999
+      if( cmTsMp1cEnqueueMsg(_printqH,buf,n+1) != kOkThRC && _printFl==0 )
2181 2000
       {
2182
-        printf("Print enqueue failed on msg:%s\n",buf);
2183
-        // we can't call an error here because it would  generate an error
2184
-        // msg which would possibly fail at this same point resulting in
2185
-        // a recursion which would eventually overflow the stack.
2001
+        // use _printFl to guard against recursion which would eventually overflow the stack.
2002
+        ++_printFl;
2003
+        cmErrMsg(&_ctx.err,kQueueFailKmRC,"Print enqueue failed on msg:%s.",buf);
2004
+        --_printFl;
2186 2005
 
2187 2006
       }
2188 2007
     }
@@ -2212,9 +2031,13 @@ cmRC_t kcApp::_s_print_queue_cb(void* userCbPtr, unsigned msgByteCnt, const void
2212 2031
 
2213 2032
 void kcApp::_checkPrintQueue()
2214 2033
 {
2215
-  while( cmTsQueueMsgWaiting(_printqH) )
2216
-    if( cmTsQueueDequeueMsg(_printqH, NULL, 0) != kOkThRC )
2034
+  while( cmTsMp1cMsgWaiting(_printqH) )
2035
+    if( cmTsMp1cDequeueMsg(_printqH, NULL, 0) != kOkThRC && _printFl==0 )
2036
+    {
2037
+      ++_printFl;
2217 2038
       cmErrMsg(&_ctx.err,kPrintQueFailKmRC,"Print dequeue failed.");
2039
+      --_printFl;
2040
+    }
2218 2041
 }
2219 2042
 
2220 2043
 void kcApp::_print( const char* text )

+ 27
- 43
src/kc/kcApp.h View File

@@ -17,19 +17,16 @@ class Fl_Select_Browser;
17 17
 class Fl_Valuator;
18 18
 class Fl_Value_Input;
19 19
 class Fl_Progress;
20
-class tlCtl;
21
-
22
-class kcApp : public Fl_Double_Window
23
-{
24
-public:
25
-  typedef unsigned kcKmRC_t;
26
-
27 20
 
28 21
   enum
29 22
   {
30 23
     kOkKmRC,
31 24
     kEngFailKmRC,
32 25
     kMemFailKmRC,
26
+    kFileSysFailKmRC,
27
+    kQueueFailKmRC,
28
+    kTextSysFailKmRC,
29
+    
33 30
     kPrefsNotFoundKmRC,
34 31
     kPrefWriteFailKmRC,
35 32
     kPrefLoadFailKmRC,
@@ -42,13 +39,22 @@ public:
42 39
   
43 40
   };
44 41
 
42
+class kcApp : public Fl_Double_Window, public tlCtlRspdr
43
+{
44
+public:
45
+  typedef unsigned kcKmRC_t;
46
+
45 47
 
46
-  kcApp(int w, int h, const char *l, int argc, char *argv[]);
48
+
49
+
50
+  kcApp(cmCtx_t* ctx, cmTsMp1cH_t printQH, int w, int h, const cmChar_t* title, cmAiH_t aiH, int argc, char* argv[] );
47 51
   virtual ~kcApp();
48 52
 
49
-  kcKmRC_t audioDspInitialize( cmCtx_t* ctx, cmRptPrintFunc_t printFunc, void* printFuncArg );
50
-  kcKmRC_t audioDspFinalize();
51
-  bool     audioDspIsValid();
53
+  void resize(int x, int y, int w, int h);
54
+
55
+  virtual void tlCtlNewTimeLineFile( tlCtl* tlCtl, const cmChar_t* fn );
56
+  virtual void tlCtlNewScoreFile(    tlCtl* tlCtl, const cmChar_t* fn );
57
+
52 58
 
53 59
   void print( const char* fmt, ... );
54 60
   void vprint( const char* fmt, va_list vl );
@@ -281,16 +287,11 @@ private:
281 287
 
282 288
   cmCtx_t         _ctx;
283 289
   Fl_Menu_Bar*    _menu;
284
-  cmAdlH_t        _adlH;
285 290
   cmAiH_t         _aiH;
286 291
   unsigned        _statIdx;
287 292
   page_t*         _pageList;
288 293
   ctl_t*          _ctlList;
289
-  const cmChar_t* _prefFn;
290
-  cmPrH_t         _prH;
291
-  const cmChar_t* _prefsFn;
292 294
   bool            _stopTimerFl;
293
-  cmJsonH_t       _jsH;
294 295
   bool            _newPageFl;
295 296
   unsigned        _incrColW;
296 297
   unsigned        _colW;
@@ -301,11 +302,10 @@ private:
301 302
   ss_t*           _ssArray;
302 303
   int             _ssPhase;
303 304
   bool            _ssUpdateFl; 
304
-  cmTsQueueH_t    _printqH; // thread-safe queue for controlling access to the output console from multiple threads
305
+  cmTsMp1cH_t    _printqH; // thread-safe queue for controlling access to the output console from multiple threads
306
+  int             _printFl;
305 307
   tlCtl*          _tlCtl;
306 308
 
307
-  void resize(int x, int y, int w, int h);
308
-
309 309
   void          _createSetupDlg(Fl_Group* grp);
310 310
   void          _createMenu( int w, int h );
311 311
   page_t*       _createPage( const char* title );
@@ -351,24 +351,23 @@ private:
351 351
   void          _updateMeters( unsigned asSubIdx, unsigned devIdx, unsigned inFl, const double* meterArray, unsigned meterCnt );
352 352
   void          _updateSsStatusIndicator( unsigned asSubIdx, unsigned indicatorIdx, unsigned cnt );
353 353
   void          _printStatusCounts();
354
-  void          _handleStatusMsg( const cmAudioSysStatus_t* st, const double* iMeterArray, const double* oMeterArray );
355 354
   void          _clearStatusIndicators();
356 355
 
357 356
   void          _sendMasterUiMsg(  unsigned asSubIdx, unsigned selId, unsigned instId, unsigned instVarId, const cmDspValue_t* v );
358 357
   void          _sendMasterUiValue(unsigned asSubIdx, unsigned instId, const double* v, unsigned vn, const cmChar_t* text );
359 358
   void          _createMasterCtl(  unsigned asSubIdx, unsigned selId, unsigned instId, unsigned varCnt, const double* dv, unsigned dn, const cmChar_t* label);
360
-  void          _handleSsInitMsg(  const cmAudioSysSsInitMsg_t* m, const cmChar_t* inDevLabel, const cmChar_t* outDevLabel );
359
+  
361 360
   void          _onRecvValue( const cmDspUiHdr_t* m );
362
-  void          _handleUiMsg( const cmDspUiHdr_t* m );
363 361
   void          _getEngMsg();
364 362
 
365
-  static cmRC_t _s_handleSsInitMsg( void* cbDataPtr, const cmAudioSysSsInitMsg_t* r, const char* iDevLabel, const char* oDevLabel );
366
-  static cmRC_t _s_handleStatusMsg( void* cbDataPtr, const cmAudioSysStatus_t* r, const double* iMeterArray, const double* oMeterArray );
367
-  static cmRC_t _s_handleUiMsg(     void* cbDataPtr, const cmDspUiHdr_t* r );
363
+ public:
364
+   void          _handleStatusMsg( const cmAudioSysStatus_t* st, const double* iMeterArray, const double* oMeterArray );
365
+   void          _handleSsInitMsg(  const cmAudioSysSsInitMsg_t* m, const cmChar_t* inDevLabel, const cmChar_t* outDevLabel );
366
+   void          _handleUiMsg( const cmDspUiHdr_t* m );
368 367
 
369
-  static kcApp* _getApp( Fl_Widget* w );
368
+ private:
370 369
 
371
-  kcKmRC_t      _restartEngine();
370
+  static kcApp* _getApp( Fl_Widget* w );
372 371
 
373 372
   void          _testStub();
374 373
 
@@ -376,26 +375,11 @@ private:
376 375
   static void _s_callback(Fl_Widget* wp, void* data);
377 376
   void _callback(void* data);
378 377
 
379
-  // idle callback
380
-  static void _s_on_idle(void* data);
381
-  void _on_idle();
382
-
383
-
384 378
   // timer callback
385 379
   static void _s_status_timeout_cb(void* userPtr);
386 380
   bool _status_timeout_cb();
387 381
 
388
-  static void _s_file_new_cb(Fl_Widget *w, void *data); 
389
-  void _file_new_cb(Fl_Widget *w); 
390
-
391
-  static void _s_file_open_cb(Fl_Widget *w, void *data); 
392
-  void _file_open_cb(Fl_Widget *w); 
393
-
394
-  static void _s_edit_copy_cb(Fl_Widget *w, void *data); 
395
-  void _edit_copy_cb(Fl_Widget *w); 
396
-
397
-  static void _s_edit_paste_cb(Fl_Widget *w, void *data); 
398
-  void _edit_paste_cb(Fl_Widget *w); 
382
+  static void _s_menu_cb(Fl_Widget *w, void *data); 
399 383
 
400 384
   static void _s_btn_cb(Fl_Widget* w, long data);
401 385
   void _btn_cb(Fl_Widget* w,  long arg);

+ 130
- 8
src/kc/kcMain.cpp View File

@@ -15,25 +15,147 @@
15 15
 #include "cmRpt.h"
16 16
 #include "cmErr.h"
17 17
 #include "cmCtx.h"
18
-#include "cmPrefs.h"
18
+#include "cmMem.h"
19
+#include "cmMallocDebug.h"
20
+#include "cmLinkedHeap.h"
19 21
 #include "cmJson.h"
20 22
 #include "cmThread.h"
23
+#include "cmText.h"
24
+#include "cmFileSys.h"
21 25
 #include "cmDspValue.h"
22 26
 #include "cmMsgProtocol.h"
23 27
 #include "cmAudDspIF.h"
24 28
 #include "cmAudDspLocal.h"
29
+#include "cmAudioFile.h"
30
+#include "cmAudioFileMgr.h"
31
+#include "cmMidi.h"
32
+#include "cmMidiFile.h"
33
+#include "cmTimeLine.h"
34
+#include "cmScore.h"
35
+#include "cmdIf.h"
36
+#include "tlCtl.h"
25 37
 #include "kcApp.h"
26 38
 
39
+kcApp* kcAppPtr = NULL;
27 40
 
28
-void print(void* cmRptUserPtr, const char* text)
29
-{ printf("%s",text); }
30 41
 
31
-int main(int argc, char* argv[] )
42
+void print( void*, const cmChar_t* text)
43
+{ puts(text); }
44
+
45
+cmRC_t  print_queue_cb(void* userCbPtr, unsigned msgByteCnt, const void* msgDataPtr )
46
+{
47
+  print(NULL,(const char*)msgDataPtr);
48
+  return cmOkRC;
49
+}
50
+
51
+cmRC_t handleSsInitMsg( void* cbDataPtr, const cmAudioSysSsInitMsg_t* r, const char* iDevLabel, const char* oDevLabel )
52
+{ kcAppPtr->_handleSsInitMsg(r,iDevLabel,oDevLabel); return cmOkRC; }
53
+
54
+cmRC_t handleStatusMsg( void* cbDataPtr, const cmAudioSysStatus_t* r, const double* iMeterArray, const double* oMeterArray )
55
+{  kcAppPtr->_handleStatusMsg(r,iMeterArray,oMeterArray);  return cmOkRC;}
56
+
57
+cmRC_t handleUiMsg(     void* cbDataPtr, const cmDspUiHdr_t* r )
58
+{ kcAppPtr->_handleUiMsg(r);  return cmOkRC;}
59
+
60
+int main( int argc, char* argv[] )
32 61
 {
33
-  kcApp myApp(1600, 750, "Console", argc, argv);
34
-  Fl::run();
35
- 
36
-  //test();
62
+  cmCtx_t     ctx;
63
+  cmTsMp1cH_t printqH         = cmTsMp1cNullHandle;
64
+  int         appWndW         = 1600;
65
+  int         appWndH         = 750;
66
+  const char* appPrefDir      = "kc";
67
+  const char* appTitle        = "KC Console";
68
+  bool        memDebugFl      = cmDEBUG_FL;
69
+  unsigned    memPadByteCnt   = memDebugFl ? 8 : 0;
70
+  unsigned    memAlignByteCnt = 16;
71
+  unsigned    memFlags        = memDebugFl ? (kTrackMmFl | kDeferFreeMmFl | kFillUninitMmFl) : 0;
72
+  cmAdlH_t    adlH            = cmAdlNullHandle;
73
+  cmAiH_t     aiH             = cmAiNullHandle;
74
+  cmAdIfDispatch_t r;
75
+
76
+  cmCtxSetup(&ctx,appTitle,print,print,NULL,memPadByteCnt,memAlignByteCnt,memFlags);
77
+
78
+  // initialize the memory mgr
79
+  if(cmMdInitialize( memPadByteCnt, memAlignByteCnt, memFlags, &ctx.rpt ) != kOkMmRC )
80
+  {
81
+    cmErrMsg(&ctx.err,kMemFailKmRC,"Heap initialization failed.");
82
+    goto errLabel;
83
+  }
84
+
85
+  // initialize the file system
86
+  if( cmFsInitialize( &ctx, appPrefDir ) != kOkFsRC )
87
+    cmErrMsg(&ctx.err,kFileSysFailKmRC,"File system initialization failed.");
88
+
89
+  // initialize the text system
90
+  if( cmTsInitialize(&ctx) != kOkTxRC )
91
+    cmErrMsg(&ctx.err,kTextSysFailKmRC,"Text system initialization failed.");
92
+
93
+  // create the print queue
94
+  if( cmTsMp1cCreate( &printqH, 8192, print_queue_cb, NULL, NULL ) != kOkThRC )
95
+    cmErrMsg(&ctx.err,kQueueFailKmRC,"Print queue creation failed.");
96
+
97
+  r.cbDataPtr     = NULL;
98
+  r.ssInitFunc    = handleSsInitMsg;
99
+  r.statusFunc    = handleStatusMsg;
100
+  r.uiFunc        = handleUiMsg;
101
+
102
+  // initialize the audio engine
103
+  if(  cmAudDspLocalAllocate(&ctx,&adlH,&r) != kOkAdlRC )
104
+      cmErrMsg(&ctx.err,kEngFailKmRC,"The audio DSP local server allocation failed.");
105
+  else
106
+    if(cmAdIfIsValid(aiH = cmAudDspLocalIF_Handle(adlH)) == false )
107
+      cmErrMsg(&ctx.err,kEngFailKmRC,"The audio DSP interface handle is not valid.");
108
+
109
+  if( cmErrLastRC(&ctx.err) == kOkKmRC )
110
+  {
111
+
112
+    kcAppPtr = new kcApp(&ctx, printqH, appWndW, appWndH, appTitle, aiH, argc, argv);
113
+    
114
+    cmAudDspLocalSendSetup(adlH);
115
+
116
+    Fl::run();
117
+
118
+    delete kcAppPtr;
119
+    kcAppPtr=NULL;
120
+
121
+    // reset the pgm context and print queue  console output to stdout
122
+    cmRptSetup(&ctx.rpt,print,print,NULL);
123
+    cmTsMp1cSetCbFunc(printqH, print_queue_cb, NULL );
124
+
125
+  }
126
+
127
+  // empty any pending text to stdout
128
+  while( cmTsMp1cMsgWaiting(printqH) )
129
+    if( cmTsMp1cDequeueMsg(printqH, NULL, 0) != kOkThRC )
130
+      cmErrMsg(&ctx.err,kQueueFailKmRC,"Print dequeue failed.");
131
+
132
+
133
+  // release the engine
134
+  if( cmAudDspLocalFree(&adlH) != kOkAdlRC )
135
+    cmErrMsg(&ctx.err,kEngFailKmRC,"Audio DSP release failed.");
136
+
137
+
138
+  // destroy the print queue
139
+  if( cmTsMp1cDestroy(&printqH) != kOkThRC )
140
+    cmErrMsg(&ctx.err,kQueueFailKmRC,"Print queue destroy failed.");
141
+
142
+  // finalize the text system
143
+  if( cmTsFinalize() != kOkTxRC )
144
+    cmErrMsg(&ctx.err,kTextSysFailKmRC,"Text system finalization failed.");
145
+
146
+  // finalize the file system
147
+  if( cmFsFinalize() != kOkFsRC )
148
+    cmErrMsg(&ctx.err,kFileSysFailKmRC,"File system finalize failed.");
149
+
150
+  // report memory mgr errors
151
+  if( cmMdIsValid() )
152
+    cmMdReport( kIgnoreNormalMmFl );
153
+
154
+  // finalize the memory manager
155
+  if( cmMdFinalize() != kOkMmRC )
156
+    cmErrMsg(&ctx.err,kMemFailKmRC,"Heap finalization failed.");
157
+
158
+ errLabel:
37 159
 
38 160
   return 0;
39 161
 }

Loading…
Cancel
Save