/[svn]/gigedit/trunk/src/gigedit/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3408 by schoenebeck, Fri Jan 19 19:17:41 2018 UTC revision 3471 by persson, Sat Feb 16 19:13:37 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2017 Andreas Persson   * Copyright (C) 2006-2019 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 457  MainWindow::MainWindow() : Line 457  MainWindow::MainWindow() :
457          m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);          m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
458      m_actionToggleRestoreWinDim =      m_actionToggleRestoreWinDim =
459          m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);          m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
460        m_actionToggleShowTooltips = m_actionGroup->add_action_bool(
461            "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),
462            Settings::singleton()->showTooltips
463        );
464      m_actionToggleSaveWithTempFile =      m_actionToggleSaveWithTempFile =
465          m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile);          m_actionGroup->add_action_bool("SaveWithTemporaryFile", sigc::mem_fun(*this, &MainWindow::on_save_with_temporary_file), Settings::singleton()->saveWithTemporaryFile);
466      m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all));      m_actionGroup->add_action("RefreshAll", sigc::mem_fun(*this, &MainWindow::on_action_refresh_all));
# Line 480  MainWindow::MainWindow() : Line 484  MainWindow::MainWindow() :
484                           *this, &MainWindow::on_auto_restore_win_dim));                           *this, &MainWindow::on_auto_restore_win_dim));
485    
486      toggle_action =      toggle_action =
487            Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));
488        toggle_action->set_active(Settings::singleton()->showTooltips);
489        actionGroup->add(
490            toggle_action,
491            sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips)
492        );
493    
494        toggle_action =
495          Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));          Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
496      toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);      toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
497      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 921  MainWindow::MainWindow() : Line 933  MainWindow::MainWindow() :
933          "          <attribute name='label' translatable='yes'>Statusbar</attribute>"          "          <attribute name='label' translatable='yes'>Statusbar</attribute>"
934          "          <attribute name='action'>AppMenu.Statusbar</attribute>"          "          <attribute name='action'>AppMenu.Statusbar</attribute>"
935          "        </item>"          "        </item>"
936            "        <item id='ShowTooltips'>"
937            "          <attribute name='label' translatable='yes'>Tooltips for Beginners</attribute>"
938            "          <attribute name='action'>AppMenu.ShowTooltips</attribute>"
939            "        </item>"
940          "        <item id='AutoRestoreWinDim'>"          "        <item id='AutoRestoreWinDim'>"
941          "          <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"          "          <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
942          "          <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"          "          <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
# Line 1151  MainWindow::MainWindow() : Line 1167  MainWindow::MainWindow() :
1167          "    </menu>"          "    </menu>"
1168          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
1169          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
1170            "      <menuitem action='ShowTooltips'/>"
1171          "      <menuitem action='AutoRestoreWinDim'/>"          "      <menuitem action='AutoRestoreWinDim'/>"
1172          "      <separator/>"          "      <separator/>"
1173          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
# Line 1339  MainWindow::MainWindow() : Line 1356  MainWindow::MainWindow() :
1356      m_TreeView.set_model(m_refTreeModelFilter);      m_TreeView.set_model(m_refTreeModelFilter);
1357    
1358      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1359      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      m_TreeView.set_has_tooltip(true);
1360        m_TreeView.signal_query_tooltip().connect(
1361            sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)
1362        );
1363      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1364          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1365      );      );
# Line 1496  MainWindow::MainWindow() : Line 1516  MainWindow::MainWindow() :
1516          sigc::hide(          sigc::hide(
1517              sigc::bind(              sigc::bind(
1518                  file_structure_to_be_changed_signal.make_slot(),                  file_structure_to_be_changed_signal.make_slot(),
1519    #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1520                    std::ref(this->file)
1521    #else
1522                  sigc::ref(this->file)                  sigc::ref(this->file)
1523    #endif
1524              )              )
1525          )          )
1526      );      );
# Line 1504  MainWindow::MainWindow() : Line 1528  MainWindow::MainWindow() :
1528          sigc::hide(          sigc::hide(
1529              sigc::bind(              sigc::bind(
1530                  file_structure_changed_signal.make_slot(),                  file_structure_changed_signal.make_slot(),
1531    #if SIGCXX_MAJOR_VERSION > 2 || (SIGCXX_MAJOR_VERSION == 2 && SIGCXX_MINOR_VERSION >= 8)
1532                    std::ref(this->file)
1533    #else
1534                  sigc::ref(this->file)                  sigc::ref(this->file)
1535    #endif
1536              )              )
1537          )          )
1538      );      );
# Line 1526  MainWindow::MainWindow() : Line 1554  MainWindow::MainWindow() :
1554          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
1555    
1556      m_searchText.signal_changed().connect(      m_searchText.signal_changed().connect(
1557          sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)          sigc::mem_fun(*m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1558      );      );
1559    
1560      file = 0;      file = 0;
# Line 1580  MainWindow::MainWindow() : Line 1608  MainWindow::MainWindow() :
1608          Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);          Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier);
1609          Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);          Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier);
1610          Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);          Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier);
1611            Gtk::AccelMap::add_entry("<Macros>/macro_12", GDK_KEY_F13, noModifier);
1612            Gtk::AccelMap::add_entry("<Macros>/macro_13", GDK_KEY_F14, noModifier);
1613            Gtk::AccelMap::add_entry("<Macros>/macro_14", GDK_KEY_F15, noModifier);
1614            Gtk::AccelMap::add_entry("<Macros>/macro_15", GDK_KEY_F16, noModifier);
1615            Gtk::AccelMap::add_entry("<Macros>/macro_16", GDK_KEY_F17, noModifier);
1616            Gtk::AccelMap::add_entry("<Macros>/macro_17", GDK_KEY_F18, noModifier);
1617            Gtk::AccelMap::add_entry("<Macros>/macro_18", GDK_KEY_F19, noModifier);
1618          Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);          Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey);
1619    
1620          Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();          Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
# Line 1602  MainWindow::MainWindow() : Line 1637  MainWindow::MainWindow() :
1637          Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);          Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
1638          Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);          Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
1639          Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);          Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
1640            Gtk::AccelMap::add_entry("<Scripts>/script_12", GDK_KEY_F13, Gdk::SHIFT_MASK);
1641            Gtk::AccelMap::add_entry("<Scripts>/script_13", GDK_KEY_F14, Gdk::SHIFT_MASK);
1642            Gtk::AccelMap::add_entry("<Scripts>/script_14", GDK_KEY_F15, Gdk::SHIFT_MASK);
1643            Gtk::AccelMap::add_entry("<Scripts>/script_15", GDK_KEY_F16, Gdk::SHIFT_MASK);
1644            Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);
1645            Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);
1646            Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);
1647            Gtk::AccelMap::add_entry("<Scripts>/DropAllScriptSlots", GDK_KEY_BackSpace, Gdk::SHIFT_MASK);
1648    
1649          Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();          Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1650          assign_scripts_menu->set_accel_group(accelGroup);          assign_scripts_menu->set_accel_group(accelGroup);
1651      }      }
1652    
1653        on_show_tooltips_changed();
1654    
1655      Glib::signal_idle().connect_once(      Glib::signal_idle().connect_once(
1656          sigc::mem_fun(*this, &MainWindow::bringToFront),          sigc::mem_fun(*this, &MainWindow::bringToFront),
1657          200          200
# Line 1847  void MainWindow::on_sel_change() Line 1892  void MainWindow::on_sel_change()
1892      }      }
1893  }  }
1894    
1895    
1896    LoaderSaverBase::LoaderSaverBase(const Glib::ustring filename, gig::File* gig) :
1897        filename(filename), gig(gig), thread(0), progress(0.f)
1898    {
1899    }
1900    
1901  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
1902  {  {
1903      Loader* loader = static_cast<Loader*>(progress->custom);      LoaderSaverBase* loader = static_cast<LoaderSaverBase*>(progress->custom);
1904      loader->progress_callback(progress->factor);      loader->progress_callback(progress->factor);
1905  }  }
1906    
1907  void Loader::progress_callback(float fraction)  void LoaderSaverBase::progress_callback(float fraction)
1908  {  {
1909      {      {
1910          Glib::Threads::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
# Line 1866  void Loader::progress_callback(float fra Line 1917  void Loader::progress_callback(float fra
1917  // make sure stack is 16-byte aligned for SSE instructions  // make sure stack is 16-byte aligned for SSE instructions
1918  __attribute__((force_align_arg_pointer))  __attribute__((force_align_arg_pointer))
1919  #endif  #endif
1920  void Loader::thread_function()  void LoaderSaverBase::thread_function()
1921  {  {
1922      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
1923             static_cast<void*>(Glib::Threads::Thread::self()));             static_cast<void*>(Glib::Threads::Thread::self()));
1924      printf("Start %s\n", filename.c_str());      printf("Start %s\n", filename.c_str());
1925      try {      try {
         RIFF::File* riff = new RIFF::File(filename);  
         gig = new gig::File(riff);  
1926          gig::progress_t progress;          gig::progress_t progress;
1927          progress.callback = loader_progress_callback;          progress.callback = loader_progress_callback;
1928          progress.custom = this;          progress.custom = this;
1929    
1930          gig->GetInstrument(0, &progress);          thread_function_sub(progress);
1931          printf("End\n");          printf("End\n");
1932          finished_dispatcher();          finished_dispatcher();
1933      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 1890  void Loader::thread_function() Line 1939  void Loader::thread_function()
1939      }      }
1940  }  }
1941    
1942  Loader::Loader(const char* filename)  void LoaderSaverBase::launch()
     : filename(filename), gig(0), thread(0), progress(0.f)  
 {  
 }  
   
 void Loader::launch()  
1943  {  {
1944  #ifdef OLD_THREADS  #ifdef OLD_THREADS
1945      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function), true);
1946  #else  #else
1947      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &LoaderSaverBase::thread_function));
1948  #endif  #endif
1949      printf("launch thread=%p\n", static_cast<void*>(thread));      printf("launch thread=%p\n", static_cast<void*>(thread));
1950  }  }
1951    
1952  float Loader::get_progress()  float LoaderSaverBase::get_progress()
1953  {  {
1954      float res;      Glib::Threads::Mutex::Lock lock(progressMutex);
1955      {      return progress;
         Glib::Threads::Mutex::Lock lock(progressMutex);  
         res = progress;  
     }  
     return res;  
1956  }  }
1957    
1958  Glib::Dispatcher& Loader::signal_progress()  Glib::Dispatcher& LoaderSaverBase::signal_progress()
1959  {  {
1960      return progress_dispatcher;      return progress_dispatcher;
1961  }  }
1962    
1963  Glib::Dispatcher& Loader::signal_finished()  Glib::Dispatcher& LoaderSaverBase::signal_finished()
1964  {  {
1965      return finished_dispatcher;      return finished_dispatcher;
1966  }  }
1967    
1968  Glib::Dispatcher& Loader::signal_error()  Glib::Dispatcher& LoaderSaverBase::signal_error()
1969  {  {
1970      return error_dispatcher;      return error_dispatcher;
1971  }  }
1972    
1973  void saver_progress_callback(gig::progress_t* progress)  void LoaderSaverBase::join() {
1974  {      thread->join();
     Saver* saver = static_cast<Saver*>(progress->custom);  
     saver->progress_callback(progress->factor);  
1975  }  }
1976    
1977  void Saver::progress_callback(float fraction)  
1978    Loader::Loader(const char* filename) :
1979        LoaderSaverBase(filename, 0)
1980  {  {
     {  
         Glib::Threads::Mutex::Lock lock(progressMutex);  
         progress = fraction;  
     }  
     progress_dispatcher.emit();  
1981  }  }
1982    
1983  #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))  void Loader::thread_function_sub(gig::progress_t& progress)
 // make sure stack is 16-byte aligned for SSE instructions  
 __attribute__((force_align_arg_pointer))  
 #endif  
 void Saver::thread_function()  
1984  {  {
1985      printf("thread_function self=%p\n",      RIFF::File* riff = new RIFF::File(filename);
1986             static_cast<void*>(Glib::Threads::Thread::self()));      gig = new gig::File(riff);
     printf("Start %s\n", filename.c_str());  
     try {  
         gig::progress_t progress;  
         progress.callback = saver_progress_callback;  
         progress.custom = this;  
   
         // if no filename was provided, that means "save", if filename was provided means "save as"  
         if (filename.empty()) {  
             if (!Settings::singleton()->saveWithTemporaryFile) {  
                 // save directly over the existing .gig file  
                 // (requires less disk space than solution below  
                 // but may be slower)  
                 gig->Save(&progress);  
             } else {  
                 // save the file as separate temporary file first,  
                 // then move the saved file over the old file  
                 // (may result in performance speedup during save)  
                 gig::String tmpname = filename + ".TMP";  
                 gig->Save(tmpname, &progress);  
                 #if defined(WIN32)  
                 if (!DeleteFile(filename.c_str())) {  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");  
                 }  
                 #else // POSIX ...  
                 if (unlink(filename.c_str())) {  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));  
                 }  
                 #endif  
                 if (rename(tmpname.c_str(), filename.c_str())) {  
                     #if defined(WIN32)  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");  
                     #else  
                     throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));  
                     #endif  
                 }  
             }  
         } else {  
             gig->Save(filename, &progress);  
         }  
1987    
1988          printf("End\n");      gig->GetInstrument(0, &progress);
         finished_dispatcher.emit();  
     } catch (RIFF::Exception e) {  
         error_message = e.Message;  
         error_dispatcher.emit();  
     } catch (...) {  
         error_message = _("Unknown exception occurred");  
         error_dispatcher.emit();  
     }  
1989  }  }
1990    
1991  Saver::Saver(gig::File* file, Glib::ustring filename)  
1992      : gig(file), filename(filename), thread(0), progress(0.f)  Saver::Saver(gig::File* file, Glib::ustring filename) :
1993        LoaderSaverBase(filename, file)
1994  {  {
1995  }  }
1996    
1997  void Saver::launch()  void Saver::thread_function_sub(gig::progress_t& progress)
1998  {  {
1999  #ifdef OLD_THREADS      // if no filename was provided, that means "save", if filename was provided means "save as"
2000      thread = Glib::Thread::create(sigc::mem_fun(*this, &Saver::thread_function), true);      if (filename.empty()) {
2001            if (!Settings::singleton()->saveWithTemporaryFile) {
2002                // save directly over the existing .gig file
2003                // (requires less disk space than solution below
2004                // but may be slower)
2005                gig->Save(&progress);
2006            } else {
2007                // save the file as separate temporary file first,
2008                // then move the saved file over the old file
2009                // (may result in performance speedup during save)
2010                gig::String tmpname = filename + ".TMP";
2011                gig->Save(tmpname, &progress);
2012    #if defined(WIN32)
2013                if (!DeleteFile(filename.c_str())) {
2014                    throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
2015                }
2016    #else // POSIX ...
2017                if (unlink(filename.c_str())) {
2018                    throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
2019                }
2020    #endif
2021                if (rename(tmpname.c_str(), filename.c_str())) {
2022    #if defined(WIN32)
2023                    throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
2024  #else  #else
2025      thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Saver::thread_function));                  throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
2026  #endif  #endif
2027      printf("launch thread=%p\n", static_cast<void*>(thread));              }
2028  }          }
2029        } else {
2030  float Saver::get_progress()          gig->Save(filename, &progress);
 {  
     float res;  
     {  
         Glib::Threads::Mutex::Lock lock(progressMutex);  
         res = progress;  
2031      }      }
     return res;  
 }  
   
 Glib::Dispatcher& Saver::signal_progress()  
 {  
     return progress_dispatcher;  
 }  
   
 Glib::Dispatcher& Saver::signal_finished()  
 {  
     return finished_dispatcher;  
2032  }  }
2033    
 Glib::Dispatcher& Saver::signal_error()  
 {  
     return error_dispatcher;  
 }  
2034    
2035  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)  ProgressDialog::ProgressDialog(const Glib::ustring& title, Gtk::Window& parent)
2036      : Gtk::Dialog(title, parent, true)      : Gtk::Dialog(title, parent, true)
# Line 2274  void MainWindow::on_loader_progress() Line 2262  void MainWindow::on_loader_progress()
2262    
2263  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
2264  {  {
2265        loader->join();
2266      printf("Loader finished!\n");      printf("Loader finished!\n");
2267      printf("on_loader_finished self=%p\n",      printf("on_loader_finished self=%p\n",
2268             static_cast<void*>(Glib::Threads::Thread::self()));             static_cast<void*>(Glib::Threads::Thread::self()));
# Line 2283  void MainWindow::on_loader_finished() Line 2272  void MainWindow::on_loader_finished()
2272    
2273  void MainWindow::on_loader_error()  void MainWindow::on_loader_error()
2274  {  {
2275        loader->join();
2276      Glib::ustring txt = _("Could not load file: ") + loader->error_message;      Glib::ustring txt = _("Could not load file: ") + loader->error_message;
2277      Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);      Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2278      msg.run();      msg.run();
# Line 2353  void MainWindow::on_saver_progress() Line 2343  void MainWindow::on_saver_progress()
2343    
2344  void MainWindow::on_saver_error()  void MainWindow::on_saver_error()
2345  {  {
2346        saver->join();
2347      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
2348      Glib::ustring txt = _("Could not save file: ") + saver->error_message;      Glib::ustring txt = _("Could not save file: ") + saver->error_message;
2349      Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);      Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 2361  void MainWindow::on_saver_error() Line 2352  void MainWindow::on_saver_error()
2352    
2353  void MainWindow::on_saver_finished()  void MainWindow::on_saver_finished()
2354  {  {
2355        saver->join();
2356      this->file = saver->gig;      this->file = saver->gig;
2357      this->filename = saver->filename;      this->filename = saver->filename;
2358      current_gig_dir = Glib::path_get_dirname(filename);      current_gig_dir = Glib::path_get_dirname(filename);
# Line 2589  void MainWindow::on_action_warn_user_on_ Line 2581  void MainWindow::on_action_warn_user_on_
2581          !Settings::singleton()->warnUserOnExtensions;          !Settings::singleton()->warnUserOnExtensions;
2582  }  }
2583    
2584    void MainWindow::on_action_show_tooltips() {
2585        Settings::singleton()->showTooltips =
2586            !Settings::singleton()->showTooltips;
2587    
2588        on_show_tooltips_changed();
2589    }
2590    
2591    void MainWindow::on_show_tooltips_changed() {
2592        const bool b = Settings::singleton()->showTooltips;
2593    
2594        dimreg_label.set_has_tooltip(b);
2595        dimreg_all_regions.set_has_tooltip(b);
2596        dimreg_all_dimregs.set_has_tooltip(b);
2597        dimreg_stereo.set_has_tooltip(b);
2598    
2599        // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell
2600        //m_TreeView.set_has_tooltip(b);
2601    
2602        m_TreeViewSamples.set_has_tooltip(b);
2603        m_TreeViewScripts.set_has_tooltip(b);
2604    
2605        set_has_tooltip(b);
2606    }
2607    
2608  void MainWindow::on_action_sync_sampler_instrument_selection() {  void MainWindow::on_action_sync_sampler_instrument_selection() {
2609      Settings::singleton()->syncSamplerInstrumentSelection =      Settings::singleton()->syncSamplerInstrumentSelection =
2610          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
# Line 2608  void MainWindow::on_action_help_about() Line 2624  void MainWindow::on_action_help_about()
2624      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
2625  #endif  #endif
2626      dialog.set_version(VERSION);      dialog.set_version(VERSION);
2627      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2019 Andreas Persson");
2628      const std::string sComment =      const std::string sComment =
2629          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
2630          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 2662  PropDialog::PropDialog() Line 2678  PropDialog::PropDialog()
2678      set_title(_("File Properties"));      set_title(_("File Properties"));
2679      eName.set_width_chars(50);      eName.set_width_chars(50);
2680    
2681        connect(eFileFormat, &PropDialog::set_FileFormat);
2682      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
2683      connect(eCreationDate, &DLS::Info::CreationDate);      connect(eCreationDate, &DLS::Info::CreationDate);
2684      connect(eComments, &DLS::Info::Comments);      connect(eComments, &DLS::Info::Comments);
# Line 2704  PropDialog::PropDialog() Line 2721  PropDialog::PropDialog()
2721  #endif  #endif
2722    
2723      add(vbox);      add(vbox);
2724  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2725      table.set_margin(5);      table.set_margin(5);
2726  #else  #else
2727      table.set_border_width(5);      table.set_border_width(5);
# Line 2712  PropDialog::PropDialog() Line 2729  PropDialog::PropDialog()
2729      vbox.add(table);      vbox.add(table);
2730      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2731      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2732  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2733      buttonBox.set_margin(5);      buttonBox.set_margin(5);
2734  #else  #else
2735      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
# Line 2723  PropDialog::PropDialog() Line 2740  PropDialog::PropDialog()
2740      quitButton.grab_focus();      quitButton.grab_focus();
2741      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
2742          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
     eFileFormat.signal_value_changed().connect(  
         sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));  
2743    
2744      quitButton.show();      quitButton.show();
2745      vbox.show();      vbox.show();
# Line 2736  PropDialog::PropDialog() Line 2751  PropDialog::PropDialog()
2751  void PropDialog::set_file(gig::File* file)  void PropDialog::set_file(gig::File* file)
2752  {  {
2753      m_file = file;      m_file = file;
2754        update(file->pInfo);
2755    
2756      // update file format version combo box      // update file format version combo box
2757      const std::string sGiga = "Gigasampler/GigaStudio v";      const std::string sGiga = "Gigasampler/GigaStudio v";
# Line 2743  void PropDialog::set_file(gig::File* fil Line 2759  void PropDialog::set_file(gig::File* fil
2759      std::vector<std::string> txts;      std::vector<std::string> txts;
2760      std::vector<int> values;      std::vector<int> values;
2761      txts.push_back(sGiga + "2"); values.push_back(2);      txts.push_back(sGiga + "2"); values.push_back(2);
2762      txts.push_back(sGiga + "3/v4"); values.push_back(3);      txts.push_back(sGiga + "3"); values.push_back(3);
2763      if (major != 2 && major != 3) {      txts.push_back(sGiga + "4"); values.push_back(4);
2764        if (major < 2 || major > 4) {
2765          txts.push_back(sGiga + ToString(major)); values.push_back(major);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
2766      }      }
2767      std::vector<const char*> texts;      std::vector<const char*> texts;
2768      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
2769      texts.push_back(NULL); values.push_back(0);      texts.push_back(NULL); values.push_back(0);
2770    
2771        update_model++;
2772      eFileFormat.set_choices(&texts[0], &values[0]);      eFileFormat.set_choices(&texts[0], &values[0]);
2773      eFileFormat.set_value(major);      eFileFormat.set_value(major);
2774        update_model--;
2775  }  }
2776    
2777  void PropDialog::onFileFormatChanged() {  void PropDialog::set_FileFormat(int value)
     const int major = eFileFormat.get_value();  
     if (m_file) m_file->pVersion->major = major;  
 }  
   
 void PropDialog::set_info(DLS::Info* info)  
2778  {  {
2779      update(info);      m_file->pVersion->major = value;
2780  }  }
2781    
2782    
# Line 2863  InstrumentProps::InstrumentProps() : Line 2878  InstrumentProps::InstrumentProps() :
2878      table.add(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
2879    
2880      add(vbox);      add(vbox);
2881  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2882      table.set_margin(5);      table.set_margin(5);
2883  #else  #else
2884      table.set_border_width(5);      table.set_border_width(5);
# Line 2872  InstrumentProps::InstrumentProps() : Line 2887  InstrumentProps::InstrumentProps() :
2887      table.show();      table.show();
2888      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2889      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2890  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2891      buttonBox.set_margin(5);      buttonBox.set_margin(5);
2892  #else  #else
2893      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
# Line 2934  void MainWindow::updateSampleRefCountMap Line 2949  void MainWindow::updateSampleRefCountMap
2949      }      }
2950  }  }
2951    
2952    bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
2953        Gtk::TreeModel::iterator iter;
2954        if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
2955            return false;
2956        }
2957        Gtk::TreeModel::Path path(iter);
2958        Gtk::TreeModel::Row row = *iter;
2959        Gtk::TreeViewColumn* pointedColumn = NULL;
2960        // resolve the precise table column the mouse points to
2961        {
2962            Gtk::TreeModel::Path path; // unused
2963            int cellX, cellY; // unused
2964            m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
2965        }
2966        Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);
2967        if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
2968            // show the script(s) assigned to the hovered instrument as tooltip
2969            tooltip->set_markup( row[m_Columns.m_col_tooltip] );
2970            m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
2971        } else {
2972            // if beginners' tooltips is disabled then don't show the following one
2973            if (!Settings::singleton()->showTooltips)
2974                return false;
2975            // yeah, a beginners tooltip
2976            tooltip->set_text(_(
2977                "Right click here for actions on instruments & MIDI Rules. "
2978                "Drag & drop to change the order of instruments."
2979            ));
2980            m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
2981        }
2982        return true;
2983    }
2984    
2985    static Glib::ustring scriptTooltipFor(gig::Instrument* instrument, int index) {
2986        Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2987        const int iScriptSlots = instrument->ScriptSlotCount();
2988        Glib::ustring tooltip = "<u>(" + ToString(index) + ") “"  + name + "”</u>\n\n";
2989        if (!iScriptSlots)
2990            tooltip += "<span foreground='red'><i>No script assigned</i></span>";
2991        else {
2992            for (int i = 0; i < iScriptSlots; ++i) {
2993                tooltip += "• " + ToString(i+1) + ". Script: “<span foreground='#46DEFF'><b>" +
2994                           instrument->GetScriptOfSlot(i)->Name + "</b></span>”";
2995                if (i + 1 < iScriptSlots) tooltip += "\n\n";
2996            }
2997        }
2998        return tooltip;
2999    }
3000    
3001  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
3002  {  {
3003      file = 0;      file = 0;
# Line 2948  void MainWindow::load_gig(gig::File* gig Line 3012  void MainWindow::load_gig(gig::File* gig
3012      file_is_changed = false;      file_is_changed = false;
3013    
3014      propDialog.set_file(gig);      propDialog.set_file(gig);
     propDialog.set_info(gig->pInfo);  
3015    
3016      instrument_name_connection.block();      instrument_name_connection.block();
3017      int index = 0;      int index = 0;
# Line 2963  void MainWindow::load_gig(gig::File* gig Line 3026  void MainWindow::load_gig(gig::File* gig
3026          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
3027          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
3028          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3029            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3030    
3031  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
3032          add_instrument_to_menu(name);          add_instrument_to_menu(name);
# Line 3080  void MainWindow::instr_name_changed_by_i Line 3144  void MainWindow::instr_name_changed_by_i
3144      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
3145      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3146      if (gigname != name) {      if (gigname != name) {
3147            Gtk::TreeModel::Path path(*it);
3148            const int index = path[0];
3149          row[m_Columns.m_col_name] = gigname;          row[m_Columns.m_col_name] = gigname;
3150            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3151      }      }
3152  }  }
3153    
# Line 3126  void MainWindow::onScriptSlotsModified(g Line 3193  void MainWindow::onScriptSlotsModified(g
3193          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
3194          if (row[m_Columns.m_col_instr] != pInstrument) continue;          if (row[m_Columns.m_col_instr] != pInstrument) continue;
3195          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3196            row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
3197          break;          break;
3198      }      }
3199    
# Line 3151  void MainWindow::assignScript(gig::Scrip Line 3219  void MainWindow::assignScript(gig::Scrip
3219      onScriptSlotsModified(pInstrument);      onScriptSlotsModified(pInstrument);
3220  }  }
3221    
3222    void MainWindow::dropAllScriptSlots() {
3223        gig::Instrument* pInstrument = get_instrument();
3224        if (!pInstrument) {
3225            printf("!instrument\n");
3226            return;
3227        }
3228    
3229        const int iScriptSlots = pInstrument->ScriptSlotCount();
3230        for (int i = iScriptSlots - 1; i >= 0; --i)
3231            pInstrument->RemoveScriptSlot(i);
3232    
3233        onScriptSlotsModified(pInstrument);
3234    }
3235    
3236  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
3237      __refreshEntireGUI();      __refreshEntireGUI();
3238  }  }
# Line 3325  void MainWindow::select_instrument(gig:: Line 3407  void MainWindow::select_instrument(gig::
3407              show_intruments_tab();              show_intruments_tab();
3408              m_TreeView.get_selection()->unselect_all();              m_TreeView.get_selection()->unselect_all();
3409                            
3410  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3411              auto iterSel = model->children()[i].get_iter();              auto iterSel = model->children()[i].get_iter();
3412              m_TreeView.get_selection()->select(iterSel);              m_TreeView.get_selection()->select(iterSel);
3413  #else  #else
# Line 3355  bool MainWindow::select_dimension_region Line 3437  bool MainWindow::select_dimension_region
3437              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
3438              show_intruments_tab();              show_intruments_tab();
3439              m_TreeView.get_selection()->unselect_all();              m_TreeView.get_selection()->unselect_all();
3440  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3441              auto iterSel = model->children()[i].get_iter();              auto iterSel = model->children()[i].get_iter();
3442              m_TreeView.get_selection()->select(iterSel);              m_TreeView.get_selection()->select(iterSel);
3443  #else  #else
# Line 3391  void MainWindow::select_sample(gig::Samp Line 3473  void MainWindow::select_sample(gig::Samp
3473              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3474                  show_samples_tab();                  show_samples_tab();
3475                  m_TreeViewSamples.get_selection()->unselect_all();                  m_TreeViewSamples.get_selection()->unselect_all();
3476  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3477                  auto iterSel = rowGroup.children()[s].get_iter();                  auto iterSel = rowGroup.children()[s].get_iter();
3478                  m_TreeViewSamples.get_selection()->select(iterSel);                  m_TreeViewSamples.get_selection()->select(iterSel);
3479  #else  #else
# Line 3591  void MainWindow::updateScriptListOfMenu( Line 3673  void MainWindow::updateScriptListOfMenu(
3673          assign_scripts_menu->append(*item);          assign_scripts_menu->append(*item);
3674      }      }
3675    
3676        // add separator line to menu
3677        assign_scripts_menu->append(*new Gtk::SeparatorMenuItem);
3678    
3679        {
3680            Gtk::MenuItem* item = new Gtk::MenuItem(_("Unassign All Scripts"));
3681            item->signal_activate().connect(
3682                sigc::mem_fun(*this, &MainWindow::dropAllScriptSlots)
3683            );
3684            assign_scripts_menu->append(*item);
3685            item->set_accel_path("<Scripts>/DropAllScriptSlots");
3686        }
3687    
3688  #if HAS_GTKMM_SHOW_ALL_CHILDREN  #if HAS_GTKMM_SHOW_ALL_CHILDREN
3689      assign_scripts_menu->show_all_children();      assign_scripts_menu->show_all_children();
3690  #endif  #endif
# Line 3639  void MainWindow::add_instrument(gig::Ins Line 3733  void MainWindow::add_instrument(gig::Ins
3733      instrument_name_connection.block();      instrument_name_connection.block();
3734      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
3735      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
3736      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      const int index = m_refTreeModel->children().size() - 1;
3737        rowInstr[m_Columns.m_col_nr] = index;
3738      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
3739      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
3740      rowInstr[m_Columns.m_col_scripts] = "";      rowInstr[m_Columns.m_col_scripts] = "";
3741        rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3742      instrument_name_connection.unblock();      instrument_name_connection.unblock();
3743    
3744  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
# Line 3729  void MainWindow::on_action_remove_instru Line 3825  void MainWindow::on_action_remove_instru
3825                       it != m_refTreeModel->children().end(); ++it, ++index)                       it != m_refTreeModel->children().end(); ++it, ++index)
3826                  {                  {
3827                      Gtk::TreeModel::Row row = *it;                      Gtk::TreeModel::Row row = *it;
3828                        gig::Instrument* instrument = row[m_Columns.m_col_instr];
3829                      row[m_Columns.m_col_nr] = index;                      row[m_Columns.m_col_nr] = index;
3830                        row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3831                  }                  }
3832              }              }
3833    
# Line 4650  bool MainWindow::instrument_row_visible( Line 4748  bool MainWindow::instrument_row_visible(
4748      trim(pattern);      trim(pattern);
4749      if (pattern.empty()) return true;      if (pattern.empty()) return true;
4750    
4751  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
4752      //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.      //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
4753      Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);      Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
4754  #else  #else

Legend:
Removed from v.3408  
changed lines
  Added in v.3471

  ViewVC Help
Powered by ViewVC