# data file for the Fltk User Interface Designer (fluid)
version 1.0109 
do_not_include_H_from_C 
header_name {.hpp} 
code_name {.cpp}
decl {\#include "ep128emu.hpp"} {selected
} 

decl {\#include "system.hpp"} {} 

decl {\#include "tapeio.hpp"} {} 

decl {\#include <FL/Fl_Hold_Browser.H>} {} 

decl {\#include <FL/Fl_File_Chooser.H>} {} 

decl {\#include <FL/Fl_Native_File_Chooser.H>} {} 

decl {\#include <FL/Fl_Text_Buffer.H>} {} 

decl {\#include "tapeedit_fl.hpp"} {} 

decl {\#include "guicolor.hpp"} {} 

class TapeEditorGUI {open
} {
  decl {int fileSelected;} {public
  }
  decl {Ep128Emu::TapeFiles fileList;} {public
  }
  decl {bool overwriteFlag;} {public
  }
  decl {bool exitFlag;} {public
  }
  decl {bool busyFlag;} {public
  }
  decl {bool updateFlag;} {public
  }
  decl {int soundFileChannel;} {public
  }
  decl {float soundFileMinFreq;} {public
  }
  decl {float soundFileMaxFreq;} {public
  }
  decl {std::string tapeDir;} {public
  }
  decl {std::string fileDir;} {public
  }
  decl {Fl_Text_Buffer *copyrightText;} {public
  }
  Function {updateDisplay()} {open return_type void
  } {
    code {{
  if (fileSelected >= int(fileList.getFileCnt()))
    fileSelected = int(fileList.getFileCnt()) - 1;
  if (fileSelected >= 0) {
    fileNameInput->clear_output();
    fileNameInput->labelcolor(Fl_Color(54));
    copyProtectCheckBox->clear_output();
    copyProtectCheckBox->labelcolor(Fl_Color(54));
    duplicateButton->clear_output();
    duplicateButton->labelcolor(Fl_Color(54));
    removeButton->clear_output();
    removeButton->labelcolor(Fl_Color(54));
    moveUpButton->clear_output();
    moveUpButton->labelcolor(Fl_Color(54));
    moveDownButton->clear_output();
    moveDownButton->labelcolor(Fl_Color(54));
    exportButton->clear_output();
    exportButton->labelcolor(Fl_Color(54));
  }
  else {
    fileNameInput->set_output();
    fileNameInput->labelcolor(Fl_Color(53));
    fileNameInput->value("");
    copyProtectCheckBox->set_output();
    copyProtectCheckBox->labelcolor(Fl_Color(53));
    copyProtectCheckBox->value(0);
    hasErrorsCheckBox->value(0);
    isCompleteCheckBox->value(0);
    fileLengthDisplay->value(0.0);
    duplicateButton->set_output();
    duplicateButton->labelcolor(Fl_Color(52));
    removeButton->set_output();
    removeButton->labelcolor(Fl_Color(52));
    moveUpButton->set_output();
    moveUpButton->labelcolor(Fl_Color(52));
    moveDownButton->set_output();
    moveDownButton->labelcolor(Fl_Color(52));
    exportButton->set_output();
    exportButton->labelcolor(Fl_Color(52));
  }
  int   n = int(fileList.getFileCnt()) - fileListBrowser->size();
  if (n > 0) {
    do {
      fileListBrowser->add("", (void *) 0);
    } while (--n);
  }
  else if (n < 0) {
    do {
      fileListBrowser->remove(fileListBrowser->size());
    } while (++n);
  }
  for (int i = 0; i < int(fileList.getFileCnt()); i++) {
    std::string fileName("");
    if (fileList[i]->hasErrors || !fileList[i]->isComplete)
      fileName = "@C171@.";
    std::string tmp(fileList[i]->getFileName());
    if (i == fileSelected) {
      fileNameInput->value(tmp.c_str());
      hasErrorsCheckBox->value(fileList[i]->hasErrors ? 1 : 0);
      isCompleteCheckBox->value(fileList[i]->isComplete ? 1 : 0);
      copyProtectCheckBox->value(fileList[i]->isCopyProtected ? 1 : 0);
      fileLengthDisplay->value(double(long(fileList[i]->fileData.size())));
    }
    fileName += tmp;
    fileListBrowser->text(i + 1, fileName.c_str());
  }
  if (fileSelected >= 0)
    fileListBrowser->select(fileSelected + 1);
  else
    fileListBrowser->deselect();
  mainWindow->redraw();
  updateFlag = false;
}} {}
  }
  Function {browseFile(std::string& fileName, std::string& dirName, const char *pattern = (char *) 0, bool createFlag = false, const char *title = (char *) 0)} {open return_type bool
  } {
    code {{
  bool    retval = false;
  if (!title)
    title = "Select file";
  Fl_Native_File_Chooser  *w = new Fl_Native_File_Chooser();
  try {
    w->type(createFlag ? Fl_Native_File_Chooser::BROWSE_SAVE_FILE
                         : Fl_Native_File_Chooser::BROWSE_FILE);
    w->title(title);
    if (pattern)
      w->filter(pattern);
    w->directory(dirName.c_str());
    {
      std::string tmp;
      std::string tmp2;
      Ep128Emu::splitPath(fileName, tmp2, tmp);
\#if !(defined(WIN32) || defined(__APPLE__))
      if (dirName.length() > 0) {
        tmp2 = dirName;
        if (dirName[dirName.length() - 1] != '/' &&
            dirName[dirName.length() - 1] != '\\\\') {
          tmp2 += '/';
        }
        tmp2 += tmp;
        tmp = tmp2;
      }
\#endif
      w->preset_file(tmp.c_str());
    }
    fileName.clear();
    if (w->show() == 0) {
      const char  *s = w->filename();
      if (s != (char *) 0) {
        fileName = s;
        Ep128Emu::stripString(fileName);
        std::string tmp;
        Ep128Emu::splitPath(fileName, dirName, tmp);
        retval = true;
      }
    }
  }
  catch (...) {
    delete w;
    throw;
  }
  delete w;
  return retval;
}} {}
  }
  Function {TapeEditorGUI()} {open
  } {
    code {{
  fileSelected = -1;
  overwriteFlag = false;
  exitFlag = true;
  busyFlag = false;
  updateFlag = true;
  soundFileChannel = 0;
  soundFileMinFreq = 600.0f;
  soundFileMaxFreq = 3000.0f;
  tapeDir = ".";
  fileDir = ".";
  copyrightText = new Fl_Text_Buffer;
  copyrightText->append("ep128emu -- portable Enterprise 128 emulator\\n");
  copyrightText->append("Copyright \\302\\251 2003-2017 Istvan Varga <istvanv@users.sourceforge.net>\\n");
  copyrightText->append("  https://github.com/istvan-v/ep128emu/\\n");
  copyrightText->append("Z80 emulation copyright \\302\\251 1999-2003 by Kevin Thacker and Vincze B\\303\\251la\\n");
  copyrightText->append("Gy\\303\\266rgy. dotconf 1.3 \\302\\251 by Lukas Schr\\303\\266der and William Hubbs. reSID 1.0\\n");
  copyrightText->append("\\302\\251 2010 by Dag Lem.\\n");
  copyrightText->append("\\n");
  copyrightText->append("This program is free software; you can redistribute it and/or modify\\n");
  copyrightText->append("it under the terms of the GNU General Public License as published by\\n");
  copyrightText->append("the Free Software Foundation; either version 2 of the License, or\\n");
  copyrightText->append("(at your option) any later version.\\n");
  copyrightText->append("\\n");
  copyrightText->append("This program is distributed in the hope that it will be useful,\\n");
  copyrightText->append("but WITHOUT ANY WARRANTY; without even the implied warranty of\\n");
  copyrightText->append("MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\\n");
  copyrightText->append("GNU General Public License for more details.\\n");
  copyrightText->append("\\n");
  copyrightText->append("You should have received a copy of the GNU General Public License\\n");
  copyrightText->append("along with this program; if not, write to the Free Software\\n");
  copyrightText->append("Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307\\n");
  copyrightText->append("USA\\n");
}} {}
    Fl_Window overwriteWindow {
      label {Confirm file overwrite} open
      xywh {402 416 200 90} type Double color 48
      code0 {o->hide();}
      code1 {o->set_modal();} visible
    } {
      Fl_Box {} {
        label {Overwrite file ?}
        xywh {10 15 180 25} labelsize 13
      }
      Fl_Button {} {
        label OK
        callback {{
  overwriteFlag = true;
  overwriteWindow->hide();
}}
        xywh {30 55 60 25} selection_color 50 labelsize 13
      }
      Fl_Button {} {
        label Cancel
        callback {{
  overwriteFlag = false;
  overwriteWindow->hide();
}}
        xywh {110 55 60 25} selection_color 50 labelsize 13
      }
    }
    Fl_Window quitWindow {
      label {Confirm quit} open
      xywh {488 554 200 90} type Double color 48
      code0 {o->hide();}
      code1 {o->set_modal();} visible
    } {
      Fl_Box {} {
        label {Quit without saving tape ?}
        xywh {10 15 180 25} labelsize 13
      }
      Fl_Button {} {
        label OK
        callback {{
  exitFlag = true;
  quitWindow->hide();
}}
        xywh {30 55 60 25} selection_color 50 labelsize 13
      }
      Fl_Button {} {
        label Cancel
        callback {{
  exitFlag = false;
  quitWindow->hide();
}}
        xywh {110 55 60 25} selection_color 50 labelsize 13
      }
    }
    Fl_Window errorWindow {
      label Error open
      xywh {437 510 240 90} type Double color 48
      code0 {o->hide();}
      code1 {o->set_modal();} visible
    } {
      Fl_Box errorMessage {
        label Error
        xywh {5 15 230 25} labelsize 13
      }
      Fl_Button {} {
        label OK
        callback {errorWindow->hide();}
        xywh {85 55 70 25} selection_color 50 labelsize 13
      }
    }
    Fl_Window progressWindow {
      label {Loading tape image} open
      xywh {281 431 220 55} type Double color 48
      code0 {o->hide();}
      code1 {o->set_modal();} visible
    } {
      Fl_Progress progressDisplay {
        xywh {10 15 200 25} box THIN_DOWN_BOX selection_color 15
      }
    }
    Fl_Window soundFileOptionsWindow {
      label {Sound file read options} open
      xywh {439 402 270 170} type Double color 48
      code0 {o->hide();} visible
    } {
      Fl_Group {} {open
        xywh {10 10 250 115} box THIN_UP_BOX
      } {
        Fl_Counter {} {
          label {Channel number}
          callback {soundFileChannel = int(o->value() + 0.5);}
          tooltip {Channel to read (counting from zero) from multichannel files} xywh {20 21 115 25} color 50 selection_color 52 labelsize 13 align 8 minimum 0 maximum 255 step 1 textsize 13
          code0 {o->value(double(soundFileChannel));}
        }
        Fl_Value_Slider {} {
          label {Minimum frequency}
          callback {soundFileMinFreq = float(o->value());}
          tooltip {Cutoff frequency of FIR highpass filter, in Hz} xywh {20 57 115 23} type Horizontal color 47 selection_color 52 labelsize 13 align 8 minimum 50 maximum 1200 step 10 value 600
          code0 {o->value(double(soundFileMinFreq));}
        }
        Fl_Value_Slider {} {
          label {Maximum frequency}
          callback {soundFileMaxFreq = float(o->value());}
          tooltip {Cutoff frequency of FIR lowpass filter, in Hz} xywh {20 91 115 23} type Horizontal color 47 selection_color 52 labelsize 13 align 8 minimum 1500 maximum 12000 step 100 value 3000
          code0 {o->value(double(soundFileMaxFreq));}
        }
      }
      Fl_Button {} {
        label OK
        callback {soundFileOptionsWindow->hide();}
        xywh {200 135 60 25} selection_color 50 labelsize 13
      }
    }
    Fl_Window aboutWindow {
      label {Copyright information} open
      xywh {333 349 520 360} type Double color 48 visible
    } {
      Fl_Text_Display {} {
        xywh {10 10 500 305} box DOWN_BOX labelsize 13 textfont 4 textsize 13
        code0 {o->buffer(copyrightText);}
      }
      Fl_Button {} {
        label OK
        callback {aboutWindow->hide();}
        xywh {450 325 60 25} selection_color 50 labelsize 13
      }
    }
    Fl_Window mainWindow {
      label {ep128emu tape editor}
      callback {if (!busyFlag) {
  if (!exitFlag) {
    quitWindow->show();
    do {
      Fl::wait(0.05);
    } while (quitWindow->shown());
  }
  if (exitFlag)
    o->hide();
}} open
      xywh {432 204 360 415} type Double color 48 align 80 visible
    } {
      Fl_Browser fileListBrowser {
        callback {{
  fileSelected = o->value() - 1;
  updateFlag = true;
}}
        xywh {10 10 260 270} selection_color 216 labelsize 13 textfont 13 textsize 13 textcolor 207
        class Fl_Hold_Browser
      }
      Fl_Group {} {open
        xywh {10 290 340 115} box THIN_UP_BOX
      } {
        Fl_Input fileNameInput {
          label {File name}
          callback {if (!busyFlag) {
  if (fileSelected >= 0 && fileSelected < int(fileList.getFileCnt())) {
    fileList[fileSelected]->setFileName(o->value());
    exitFlag = false;
  }
  updateFlag = true;
}}
          xywh {80 300 260 25} box THIN_DOWN_BOX labelsize 13 labelcolor 53 textsize 13
          code0 {o->cursor_color(Fl_Color(3));}
          code1 {o->set_output();}
        }
        Fl_Check_Button hasErrorsCheckBox {
          label {Has errors}
          xywh {80 370 25 25} down_box DOWN_BOX labelsize 13 labelcolor 53 align 4
          code0 {o->set_output();}
        }
        Fl_Check_Button isCompleteCheckBox {
          label {Is complete}
          xywh {180 370 25 25} down_box DOWN_BOX labelsize 13 labelcolor 53 align 4
          code0 {o->set_output();}
        }
        Fl_Check_Button copyProtectCheckBox {
          label {Copy protected}
          callback {if (!busyFlag) {
  if (fileSelected >= 0 && fileSelected < int(fileList.getFileCnt())) {
    fileList[fileSelected]->isCopyProtected = (o->value() == 0 ? false : true);
    exitFlag = false;
  }
  updateFlag = true;
}}
          xywh {315 370 25 25} down_box DOWN_BOX labelsize 13 labelcolor 53 align 4
          code0 {o->set_output();}
        }
        Fl_Value_Output fileLengthDisplay {
          label {File length}
          xywh {80 335 60 25} box THIN_DOWN_BOX color 7 selection_color 15 labelsize 13 labelcolor 53 maximum 1e+07 step 1 textsize 13
          code0 {o->set_output();}
        }
        Fl_Box {} {
          label bytes
          xywh {140 335 60 25} labelsize 13 labelcolor 53 align 20
        }
      }
      Fl_Button {} {
        label {Load...}
        callback {if (!busyFlag) {
  busyFlag = true;
  std::string fname;
  if (browseFile(fname, tapeDir, (char *) 0, false, "Select tape image file")) {
    progressWindow->show();
    exitFlag = false;
    try {
      fileList.readTapeImage(fname.c_str(),
                             progressDisplay,
                             soundFileChannel,
                             soundFileMinFreq,
                             soundFileMaxFreq);
    }
    catch (std::exception& e) {
      errorMessage->label(e.what());
      errorWindow->show();
      do {
        Fl::wait(0.05);
      } while (errorWindow->shown());
      errorMessage->label("");
    }
    progressWindow->hide();
    updateDisplay();
  }
  busyFlag = false;
}}
        tooltip {Load files from tape image (ep128emu tape file, sound file, or EPTE/TAPir tape file)} xywh {280 10 70 20} selection_color 50 labelsize 13
      }
      Fl_Button {} {
        label {Import...}
        callback {if (!busyFlag) {
  busyFlag = true;
  std::string fname;
  if (browseFile(fname, fileDir, (char *) 0, false, "Select file")) {
    exitFlag = false;
    try {
      fileList.importFile(fname.c_str());
    }
    catch (std::exception& e) {
      errorMessage->label(e.what());
      errorWindow->show();
      do {
        Fl::wait(0.05);
      } while (errorWindow->shown());
      errorMessage->label("");
    }
    updateDisplay();
  }
  busyFlag = false;
}}
        tooltip {Add a file to the tape from disk} xywh {280 35 70 20} selection_color 50 labelsize 13
      }
      Fl_Button duplicateButton {
        label Duplicate
        callback {if (fileSelected >= 0 && !busyFlag) {
  busyFlag = true;
  exitFlag = false;
  try {
    fileList.duplicateFile(fileSelected);
    fileSelected = int(fileList.getFileCnt()) - 1;
  }
  catch (std::exception& e) {
    errorMessage->label(e.what());
    errorWindow->show();
    do {
      Fl::wait(0.05);
    } while (errorWindow->shown());
    errorMessage->label("");
  }
  updateDisplay();
  busyFlag = false;
}}
        tooltip {Make a copy of the currently selected file at the end of the tape} xywh {280 60 70 20} selection_color 50 labelsize 13 labelcolor 52
        code0 {o->set_output();}
      }
      Fl_Button removeButton {
        label Remove
        callback {if (fileSelected >= 0 && !busyFlag) {
  busyFlag = true;
  exitFlag = false;
  try {
    fileList.removeFile(fileSelected);
  }
  catch (std::exception& e) {
    errorMessage->label(e.what());
    errorWindow->show();
    do {
      Fl::wait(0.05);
    } while (errorWindow->shown());
    errorMessage->label("");
  }
  updateDisplay();
  busyFlag = false;
}}
        tooltip {Delete currently selected file from tape} xywh {280 85 70 20} selection_color 50 labelsize 13 labelcolor 52
        code0 {o->set_output();}
      }
      Fl_Button moveUpButton {
        label {@8->}
        callback {if (fileSelected >= 1 && !busyFlag) {
  int   n = fileSelected;
  busyFlag = true;
  exitFlag = false;
  try {
    fileList.moveFile(n, false);
    fileSelected = n - 1;
  }
  catch (std::exception& e) {
    errorMessage->label(e.what());
    errorWindow->show();
    do {
      Fl::wait(0.05);
    } while (errorWindow->shown());
    errorMessage->label("");
  }
  updateDisplay();
  busyFlag = false;
}}
        tooltip {Move currently selected file towards the beginning of the tape} xywh {280 110 70 20} selection_color 50 labelsize 13 labelcolor 52
        code0 {o->set_output();}
      }
      Fl_Button moveDownButton {
        label {@2->}
        callback {if (fileSelected < (int(fileList.getFileCnt()) - 1) && !busyFlag) {
  int   n = fileSelected;
  busyFlag = true;
  exitFlag = false;
  try {
    fileList.moveFile(n, true);
    fileSelected = n + 1;
  }
  catch (std::exception& e) {
    errorMessage->label(e.what());
    errorWindow->show();
    do {
      Fl::wait(0.05);
    } while (errorWindow->shown());
    errorMessage->label("");
  }
  updateDisplay();
  busyFlag = false;
}}
        tooltip {Move currently selected file towards the end of the tape} xywh {280 135 70 20} selection_color 50 labelsize 13 labelcolor 52
        code0 {o->set_output();}
      }
      Fl_Button exportButton {
        label {Export...}
        callback {if (fileSelected >= 0 && fileSelected < int(fileList.getFileCnt()) && !busyFlag) {
  int   n = fileSelected;
  busyFlag = true;
  try {
    std::string fname = fileList[n]->getFileName();
    if (browseFile(fname, fileDir, (char *) 0, true, "Select output file")) {
      if (!fileList.exportFile(n, fname.c_str(), false)) {
        overwriteFlag = false;
        overwriteWindow->show();
        do {
          Fl::wait(0.05);
        } while (overwriteWindow->shown());
        if (overwriteFlag) {
          fileList.exportFile(n, fname.c_str(), true);
        }
      }
    }
  }
  catch (std::exception& e) {
    errorMessage->label(e.what());
    errorWindow->show();
    do {
      Fl::wait(0.05);
    } while (errorWindow->shown());
    errorMessage->label("");
  }
  busyFlag = false;
}}
        tooltip {Save currently selected file to disk} xywh {280 160 70 20} selection_color 50 labelsize 13 labelcolor 52
        code0 {o->set_output();}
      }
      Fl_Button {} {
        label {Save...}
        callback {if (!busyFlag) {
  busyFlag = true;
  std::string fname;
  if (browseFile(fname, tapeDir, (char *) 0, true, "Select tape image file")) {
    try {
      if (!fileList.writeTapeImage(fname.c_str(), false)) {
        overwriteFlag = false;
        overwriteWindow->show();
        do {
          Fl::wait(0.05);
        } while (overwriteWindow->shown());
        if (overwriteFlag) {
          fileList.writeTapeImage(fname.c_str(), true);
          exitFlag = true;
        }
      }
      else
        exitFlag = true;
    }
    catch (std::exception& e) {
      errorMessage->label(e.what());
      errorWindow->show();
      do {
        Fl::wait(0.05);
      } while (errorWindow->shown());
      errorMessage->label("");
    }
  }
  busyFlag = false;
}}
        tooltip {Save all files to tape image} xywh {280 185 70 20} selection_color 50 labelsize 13
      }
      Fl_Button {} {
        label {Options...}
        callback {soundFileOptionsWindow->show();}
        tooltip {Set options} xywh {280 210 70 20} selection_color 50 labelsize 13
      }
      Fl_Button {} {
        label {About...}
        callback {aboutWindow->show();}
        tooltip {Display copyright information} xywh {280 235 70 20} selection_color 50 labelsize 13
      }
      Fl_Button {} {
        label Quit
        callback {if (!busyFlag) {
  if (!exitFlag) {
    quitWindow->show();
    do {
      Fl::wait(0.05);
    } while (quitWindow->shown());
  }
  if (exitFlag)
    mainWindow->hide();
}}
        tooltip {Exit tape editor} xywh {280 260 70 20} selection_color 50 labelsize 13
      }
    }
  }
  Function {~TapeEditorGUI()} {open
  } {
    code {{
  Fl::wait(0.0);
  overwriteWindow->hide();
  quitWindow->hide();
  errorWindow->hide();
  progressWindow->hide();
  soundFileOptionsWindow->hide();
  aboutWindow->hide();
  mainWindow->hide();
  Fl::wait(0.0);
  delete mainWindow;
  delete aboutWindow;
  delete soundFileOptionsWindow;
  delete progressWindow;
  delete errorWindow;
  delete quitWindow;
  delete overwriteWindow;
  delete copyrightText;
}} {}
  }
} 

Function {main(int argc, char **argv)} {open return_type int
} {
  code {{
  Fl::lock();
  Ep128Emu::setGUIColorScheme();
  TapeEditorGUI *w = new TapeEditorGUI;
  Ep128Emu::setWindowIcon(w->mainWindow, 0);
  try {
    w->mainWindow->show();
    for (int i = 1; i < argc; i++) {
      if (!w->busyFlag) {
        w->busyFlag = true;
        if (argv[i] != (char *) 0 && argv[i][0] != '\\0') {
          std::string tmp;
          Ep128Emu::splitPath(std::string(argv[i]), w->tapeDir, tmp);
          w->progressWindow->show();
          w->exitFlag = false;
          try {
            w->fileList.readTapeImage(argv[i],
                                      w->progressDisplay,
                                      w->soundFileChannel,
                                      w->soundFileMinFreq,
                                      w->soundFileMaxFreq);
          }
          catch (std::exception& e) {
            w->errorMessage->label(e.what());
            w->errorWindow->show();
            do {
              Fl::wait(0.05);
            } while (w->errorWindow->shown());
            w->errorMessage->label("");
          }
          w->progressWindow->hide();
          w->updateDisplay();
        }
        w->busyFlag = false;
      }
    }
    do {
      if (w->updateFlag)
        w->updateDisplay();
      Fl::wait(0.05);
    } while (w->mainWindow->shown());
  }
  catch (...) {
  }
  delete w;
  return 0;
}} {}
} 
