00001
00095 #include "Defs.h"
00096
00097 #include "Global.h"
00098
00099 #include "Hilfs.h"
00100 #include "GrafKern.h"
00101
00102 #include "Runtime.h"
00103 #include "Execute.h"
00104
00105 #include <setjmp.h>
00106
00107 #include "Device.h"
00108 #include "DevGIS.h"
00109 #include "DevMidi.h"
00110 #include "DevMidF.h"
00111
00112 #ifdef __cplusplus
00113 extern "C"
00114 {
00115 #endif
00116 bool RealTime = false;
00117
00118 jmp_buf weiter_gehts_nach_compilerfehler;
00119
00120 char pascal _export Compile(CompDlg *compDia, const wxChar *name) {
00121 InitCompDia(compDia, name);
00122
00123 if (!setjmp(weiter_gehts_nach_compilerfehler)) {
00124 loesche_syntax_speicher();
00125 init_yylex ();
00126
00127 mutabor_programm_einlesen ( name );
00128
00129 calc_declaration_numbers();
00130
00131 compDia->SetStatus(sd1,sd2,sd3,sd4,sd5,sd6);
00132
00133
00134
00135 compDia->SetButtonText(_("Generating tables"));
00136 compDia->Refresh();
00137
00138 mutabor_tabellen_generator();
00139
00140
00141 compDia->SetButtonText(_("Translation successful !"));
00142 compDia->SetMessage(_("No error occured !"));
00143 compDia->Refresh();
00144
00145 return 1;
00146 } else {
00147
00148 compDia->SetButtonText(_("Translation interrupted !"));
00149
00150 compDia->SetMessage(Fmeldung);
00151 compDia->Refresh();
00152
00153 return 0;
00154 }
00155 }
00156
00157 UpdateCallback* updatecallback;
00158
00159 bool pascal _export Activate(bool realTime, UpdateCallback* callback) {
00160 RealTime = realTime;
00161 GlobalReset();
00162 AktionenInit();
00163 updatecallback = callback;
00164 #if !defined(WX) || defined(__WXMSW__)
00165
00166 if ( RealTime )
00167 timeBeginPeriod(1);
00168
00169 #endif
00170 bool ok = OutOpen();
00171
00172 if ( ok && !InOpen() ) {
00173 ok = false;
00174 OutClose();
00175 }
00176
00177 if ( !ok ) {
00178 #if !defined(WX) || defined(__WXMSW__)
00179 if ( RealTime )
00180 timeEndPeriod(1);
00181 #endif
00182 wxMessageBox(Fmeldung, _("Activation error"), wxOK | wxICON_ASTERISK );
00183 return false;
00184 }
00185
00186 if ( RealTime )
00187 StartCurrentTime();
00188 else
00189 CurrentTime = 0;
00190 return true;
00191 }
00192
00193 void pascal _export Stop() {
00194 if ( RealTime )
00195 StopCurrentTime();
00196
00197 InClose();
00198
00199 OutClose();
00200
00201 #if !defined(WX) || defined(__WXMSW__)
00202 if ( RealTime )
00203 timeEndPeriod(1);
00204
00205 #endif
00206 GlobalReset();
00207 }
00208
00209
00210
00211
00212 void NRT_Play() {
00213
00214
00215 for (InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext())
00216 In->Play();
00217
00218
00219 bool Working = true;
00220
00221 while ( Working ) {
00222 Working = false;
00223
00224 for (InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext())
00225 if ( In->GetMode() == 1 && In->GetType() == DTMidiFile ) {
00226 ((InMidiFile*)In)->IncDelta();
00227 Working = true;
00228 }
00229
00230 CurrentTime.Notify();
00231 }
00232
00233
00234 for (InDevice *In1 = InDevice::GetDeviceList(); In1; In1 = In1->GetNext())
00235 In1->Stop();
00236
00237 InDevChanged = 1;
00238 }
00239
00240 void pascal _export InDeviceAction(int inDevNr, enum MutaborModeType action) {
00241
00242
00243 if ( !RealTime ) {
00244 NRT_Play();
00245 return;
00246 }
00247
00248 InDevice *In = InDevice::GetDeviceList();
00249
00250 while ( In && inDevNr ) {
00251 In = In->GetNext();
00252 inDevNr--;
00253 }
00254
00255 if ( !In || In->GetMode() == MutaborDeviceCompileError ) return;
00256 switch ( action ) {
00257
00258 case MutaborDeviceStop:
00259 In->Stop();
00260 break;
00261
00262 case MutaborDevicePlay:
00263 In->Play();
00264 break;
00265
00266 case MutaborDevicePause:
00267 In->Pause();
00268 break;
00269
00270 case MutaborDeviceUnregistered:
00271 std::cerr << "Device is unregistered. Aborting.";
00272 abort();
00273
00274 case MutaborDeviceCompileError:
00275 std::cerr << "Unhandled compile error. Aborting.";
00276 abort();
00277
00278 case MutaborDeviceTimingError:
00279 std::cerr << "Unhandled timing error. Aborting.";
00280 abort();
00281 }
00282 }
00283
00284 void pascal _export Panic() {
00285 OutDevice *Out = OutDevice::GetDeviceList();
00286 while ( Out ) {
00287 Out->Panic();
00288 Out = Out->GetNext();
00289 }
00290 MutResetKeys();
00291 for (int i = 0; i<MAX_BOX ; i++)
00292 {
00293 updatecallback(i,false);
00294 }
00295 }
00296
00297 bool pascal _export CheckNeedsRealTime() {
00298 return NeedsRealTime();
00299 }
00300
00301 struct keyboard_ereignis *last;
00302
00303 char pascal _export GetMutTag(char &isLogic, char *text, char *einsttext, char &key, int box) {
00304 if ( box != -1 )
00305 last = first_keyboard[box];
00306 else
00307 if ( last ) last = last->next;
00308
00309 if ( !last ) return 0;
00310
00311 key = last->taste;
00312
00313 strncpy(text, last->aktion->name, 20);
00314
00315 isLogic = ( last->the_logik_to_expand != NULL );
00316
00317 if ( isLogic && last->the_logik_to_expand->einstimmungs_name )
00318 strncpy(einsttext, last->the_logik_to_expand->einstimmungs_name, 20);
00319 else
00320 strcpy(einsttext, "");
00321
00322 return 1;
00323 }
00324
00325 char pascal _export IsLogicKey(char key) {
00326
00327 struct keyboard_ereignis *last = first_keyboard[aktuelle_keyboard_box];
00328
00329 while ( last ) {
00330 if ( key == last->taste )
00331 return last->the_logik_to_expand != NULL;
00332
00333 last = last->next;
00334 }
00335
00336 return 2;
00337 }
00338
00339 bool pascal _export KeyChanged(int box) {
00340 int flag = keys_changed[box];
00341 keys_changed[box] = 0;
00342 return flag;
00343 }
00344
00345 tone_system last_tonsystem[MAX_BOX];
00346
00347 bool pascal _export TSChanged(int box) {
00348 int flag = memcmp(&(last_tonsystem[box]),
00349 mut_box[box].tonesystem,
00350 (2*sizeof(int)) + sizeof(long) +
00351 (mut_box[box].tonesystem->breite*
00352 sizeof(long)) );
00353 last_tonsystem[box] = *(mut_box[box].tonesystem);
00354 return flag;
00355 }
00356
00357 bool pascal _export InDevicesChanged() {
00358 char flag = InDevChanged;
00359 InDevChanged = 0;
00360 return flag;
00361 }
00362
00363 void pascal _export GetInDevicesMode(enum MutaborModeType *mode) {
00364 int nr = 0;
00365
00366 for (InDevice *In = InDevice::GetDeviceList(); In; In = In->GetNext(),nr++)
00367 mode[nr] = In->GetMode();
00368 }
00369
00370 struct instrument * lauf_instrument;
00371
00372 char pascal _export GetChannels(char start, int &base, int &from, int &to, int &thru) {
00373 if ( start )
00374 lauf_instrument = list_of_config_instrumente;
00375 else if ( lauf_instrument )
00376 lauf_instrument = lauf_instrument -> next;
00377
00378 if ( !lauf_instrument ) return 0;
00379
00380 base = lauf_instrument -> midi_in;
00381
00382 from = lauf_instrument -> midi_von;
00383
00384 to = lauf_instrument -> midi_bis;
00385
00386 thru = lauf_instrument -> midi_umleit;
00387
00388 return 1;
00389 }
00390
00391 void pascal _export SetChannels(int base, int from, int to, int thru) {
00392 get_instrument_dekl (base, from, to, thru, &list_of_config_instrumente);
00393 }
00394
00395 void pascal _export SetAktuellesKeyboardInstrument(int instr) {
00396 aktuelle_keyboard_box = instr;
00397 }
00398
00399 int pascal _export GetAktuellesKeyboardInstrument() {
00400 return aktuelle_keyboard_box;
00401 }
00402
00403
00404
00405 bool GetELine(const wxString& p, size_t& i, wxString &s);
00406
00407 DevType Str2DT(const wxString& type);
00408
00409
00410 bool GetLine(char **p, char *s) {
00411 if ( !p || !(*p)[0] )
00412 return FALSE;
00413
00414 while ( (*p)[0] == ' ' || (*p)[0] == '\n' || (*p)[0] == '\r' )
00415 *p = &(*p)[1];
00416
00417 if ( !(*p)[0] )
00418 return FALSE;
00419
00420 char *p1 = *p;
00421
00422 *p = strchr(p1, '\n');
00423
00424 if ( !p )
00425 *p = &p1[strlen(p1)];
00426
00427 int i = (*p)-p1;
00428
00429 strncpy(s, p1, i);
00430
00431 s[i] = 0;
00432
00433 return TRUE;
00434 }
00435
00436 #define GETLINE \
00437 if ( !GetELine(config, i, s) ) \
00438 return
00439
00440
00441
00442
00443 OutDevice *GetOut(int nr) {
00444 DEBUGLOG2(other,_T("Nr.: %d"),nr);
00445
00446 if ( nr < 0 )
00447 return 0;
00448
00449 OutDevice *Out = OutDevice::GetDeviceList();
00450
00451 while ( Out ) {
00452 if (Out->GetDevId() == nr) break;
00453
00454 Out = Out->GetNext();
00455
00456 DEBUGLOG2(other,_T("Nr.: %d, Out: %x"),nr, Out);
00457 }
00458
00459 return Out;
00460 }
00461
00462 #if 0
00463
00464 void pascal _export ScanDevices(const wxString &config) {
00465
00466
00467 if ( InDevice::GetDeviceList() ) {
00468 delete InDevice::GetDeviceList();
00469 }
00470
00471 if ( OutDevices ) {
00472 delete OutDevices;
00473 OutDevices = 0;
00474 }
00475
00476
00477 wxString s;
00478
00479 size_t i = 0;
00480
00481 GETLINE;
00482
00483 while ( !s.StartsWith(_T("OUTPUT" ))) {
00484 GETLINE;
00485 }
00486
00487 GETLINE;
00488
00489
00490 OutDevice **PreOut = &OutDevices;
00491
00492 while ( !s.StartsWith(_T("INPUT") )) {
00493 wxChar Type[80], Name[400];
00494 int DevId, BendingRange;
00495 #if (wxUSE_UNICODE || wxUSE_WCHAR_T)
00496 int test = SSCANF (s, _T("%ls \"%l[^\"]\" %d %d"), Type, Name, &DevId, &BendingRange);
00497
00498 if ( test < 2 )
00499 test = SSCANF (s, _T("%ls %ls %d %d"), Type, Name, &DevId, &BendingRange);
00500
00501 #else
00502 int test = SSCANF (s, _T("%s \"%[^\"]\" %d %d"), Type, Name, &DevId, &BendingRange);
00503
00504 if ( test < 2 )
00505 test = SSCANF (s, _T("%s %s %d %d"), Type, Name, &DevId, &BendingRange);
00506
00507 #endif
00508 if ( test < 2 ) {
00509
00510 }
00511
00512 OutDevice *Out;
00513
00514 switch ( Str2DT(Type) ) {
00515
00516 case DTUnknown:
00517 std::cerr << "Unknown device: " << Type << std::endl;
00518
00519
00520
00521 case DTGis:
00522 Out = new OutGis(Name);
00523
00524 break;
00525
00526 case DTMidiPort:
00527 Out = new OutMidiPort(Name, DevId, BendingRange);
00528
00529 break;
00530
00531 case DTMidiFile:
00532 Out = new OutMidiFile(Name, DevId, BendingRange);
00533
00534 break;
00535 }
00536
00537 *PreOut = Out;
00538
00539 PreOut = &(Out->Next);
00540 GETLINE;
00541 }
00542
00543 GETLINE;
00544
00545
00546
00547 while ( 1 ) {
00548
00549 wxChar Type[80], Name[400];
00550 int DevId = -1;
00551 #if (wxUSE_UNICODE || wxUSE_WCHAR_T)
00552 int test = SSCANF (s, _T("%ls \"%l[^\"]\" %d"), Type, Name, &DevId);
00553
00554 if ( test < 2 )
00555 test = SSCANF (s, _T("%ls %ls %d"), Type, Name, &DevId);
00556
00557 #else
00558 int test = SSCANF (s, _T("%s \"%[^\"]\" %d"), Type, Name, &DevId);
00559
00560 if ( test < 2 )
00561 test = SSCANF (s, _T("%s %s %d"), Type, Name, &DevId);
00562
00563 #endif
00564 if ( test < 2 ) {
00565
00566 }
00567
00568 InDevice *In;
00569
00570 switch ( Str2DT(muT(Type)) ) {
00571
00572 case DTUnknown:
00573
00574
00575 case DTGis:
00576 In = new InGis(Name, _T("GIS"));
00577
00578 break;
00579
00580 case DTMidiPort:
00581 In = new InMidiPort(Name, DevId);
00582
00583 break;
00584
00585 case DTMidiFile:
00586 In = new InMidiFile(Name, 0);
00587
00588 break;
00589 }
00590
00591
00592 GETLINE;
00593
00594
00595 while ( Str2DT(s) == DTUnknown ) {
00596
00597 wxChar Type[40];
00598 int IFrom = 0, ITo = 0, Box = 0, BoxActive = 0, OutDev = -1, OFrom = -1, OTo = -1, ONoDrum = 1;
00599 #if (wxUSE_UNICODE || wxUSE_WCHAR_T)
00600 test = SSCANF(s, _("%ls %d %d %d %d %d %d %d %d"),
00601 Type, &IFrom, &ITo, &Box, &BoxActive, &OutDev, &OFrom, &OTo, &ONoDrum);
00602 #else
00603 test = SSCANF(s, _("%s %d %d %d %d %d %d %d %d"),
00604 Type, &IFrom, &ITo, &Box, &BoxActive, &OutDev, &OFrom, &OTo, &ONoDrum);
00605 #endif
00606
00607 if ( test < 2 ) {
00608
00609 }
00610
00611 if ( Box == -2 )
00612 BoxActive = 0;
00613
00614 In->AddRoute(new Route(Str2RT(Type), IFrom, ITo, Box, BoxActive, GetOut(OutDev), OFrom, OTo, ONoDrum));
00615
00616 GETLINE;
00617 }
00618 }
00619 }
00620
00621 #endif
00622
00623
00624 void pascal _export GetTimerData(UINT &min, UINT &max) {
00625 #if !defined(WX) || defined(__WXMSW__)
00626 TIMECAPS TimeCaps;
00627 timeGetDevCaps(&TimeCaps, sizeof(TIMECAPS));
00628 min = TimeCaps.wPeriodMin;
00629 max = TimeCaps.wPeriodMax;
00630 #else
00631
00632 #endif
00633 }
00634
00635 }
00636
00637