/[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 3635 by schoenebeck, Thu Oct 24 11:16:26 2019 UTC revision 3918 by schoenebeck, Thu Jun 10 13:28:17 2021 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2019 Andreas Persson   * Copyright (C) 2006-2020 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 96  MainWindow::MainWindow() : Line 96  MainWindow::MainWindow() :
96    
97      if (!Settings::singleton()->autoRestoreWindowDimension) {      if (!Settings::singleton()->autoRestoreWindowDimension) {
98  #if GTKMM_MAJOR_VERSION >= 3  #if GTKMM_MAJOR_VERSION >= 3
99          set_default_size(960, 600);          set_default_size(1010, -1);
100  #else  #else
101          set_default_size(865, 600);          set_default_size(915, -1);
102  #endif  #endif
103          set_position(Gtk::WIN_POS_CENTER);          set_position(Gtk::WIN_POS_CENTER);
104      }      }
# Line 106  MainWindow::MainWindow() : Line 106  MainWindow::MainWindow() :
106      add(m_VBox);      add(m_VBox);
107    
108      // Handle selection      // Handle selection
109      m_TreeView.get_selection()->signal_changed().connect(      m_TreeViewInstruments.get_selection()->signal_changed().connect(
110          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
111    
112      // m_TreeView.set_reorderable();      // m_TreeViewInstruments.set_reorderable();
113    
114  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && (GTKMM_MINOR_VERSION > 91 || (GTKMM_MINOR_VERSION == 91 && GTKMM_MICRO_VERSION >= 2))) // GTKMM >= 3.91.2
115      m_TreeView.signal_button_press_event().connect(      m_TreeViewInstruments.signal_button_press_event().connect(
116          sigc::mem_fun(*this, &MainWindow::on_button_release));          sigc::mem_fun(*this, &MainWindow::on_button_release));
117  #else  #else
118      m_TreeView.signal_button_press_event().connect_notify(      m_TreeViewInstruments.signal_button_press_event().connect_notify(
119          sigc::mem_fun(*this, &MainWindow::on_button_release));          sigc::mem_fun(*this, &MainWindow::on_button_release));
120  #endif  #endif
121    
122      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
123      m_ScrolledWindow.add(m_TreeView);      m_ScrolledWindow.add(m_TreeViewInstruments);
124  //    m_ScrolledWindow.set_size_request(200, 600);  //    m_ScrolledWindow.set_size_request(200, 600);
125      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
126    
# Line 451  MainWindow::MainWindow() : Line 451  MainWindow::MainWindow() :
451          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);
452      m_actionToggleRestoreWinDim =      m_actionToggleRestoreWinDim =
453          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);
454        m_actionInstrDoubleClickOpensProps =
455            m_actionGroup->add_action_bool(
456                "OpenInstrPropsByDoubleClick",
457                sigc::mem_fun(*this, &MainWindow::on_instr_double_click_opens_props),
458                Settings::singleton()->instrumentDoubleClickOpensProps
459            );
460      m_actionToggleShowTooltips = m_actionGroup->add_action_bool(      m_actionToggleShowTooltips = m_actionGroup->add_action_bool(
461          "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),          "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),
462          Settings::singleton()->showTooltips          Settings::singleton()->showTooltips
# Line 478  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("OpenInstrPropsByDoubleClick", _("Instrument Properties by Double Click"));
488        toggle_action->set_active(Settings::singleton()->instrumentDoubleClickOpensProps);
489        actionGroup->add(toggle_action,
490                         sigc::mem_fun(
491                             *this, &MainWindow::on_instr_double_click_opens_props));
492    
493        toggle_action =
494          Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));          Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));
495      toggle_action->set_active(Settings::singleton()->showTooltips);      toggle_action->set_active(Settings::singleton()->showTooltips);
496      actionGroup->add(      actionGroup->add(
# Line 509  MainWindow::MainWindow() : Line 522  MainWindow::MainWindow() :
522          "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
523      );      );
524      m_actionGroup->add_action(      m_actionGroup->add_action(
525            "MoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_move_instr)
526        );
527        m_actionGroup->add_action(
528          "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)          "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
529      );      );
530      m_actionGroup->add_action(      m_actionGroup->add_action(
# Line 530  MainWindow::MainWindow() : Line 546  MainWindow::MainWindow() :
546          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
547      );      );
548      actionGroup->add(      actionGroup->add(
549            Gtk::Action::create("MoveInstrument", _("Move _Instrument To ...")),
550            Gtk::AccelKey(GDK_KEY_i, primaryModifierKey),
551            sigc::mem_fun(*this, &MainWindow::on_action_move_instr)
552        );
553        actionGroup->add(
554          Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),          Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
555          Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),          Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
556          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
# Line 885  MainWindow::MainWindow() : Line 906  MainWindow::MainWindow() :
906          "          <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"          "          <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
907          "          <attribute name='action'>AppMenu.DupInstrument</attribute>"          "          <attribute name='action'>AppMenu.DupInstrument</attribute>"
908          "        </item>"          "        </item>"
909            "        <item id='MoveInstrument'>"
910            "          <attribute name='label' translatable='yes'>Move Instrument To ...</attribute>"
911            "          <attribute name='action'>AppMenu.MoveInstrument</attribute>"
912            "        </item>"
913          "        <item id='CombInstruments'>"          "        <item id='CombInstruments'>"
914          "          <attribute name='label' translatable='yes'>Combine Instrument</attribute>"          "          <attribute name='label' translatable='yes'>Combine Instrument</attribute>"
915          "          <attribute name='action'>AppMenu.CombInstruments</attribute>"          "          <attribute name='action'>AppMenu.CombInstruments</attribute>"
# Line 935  MainWindow::MainWindow() : Line 960  MainWindow::MainWindow() :
960          "          <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"          "          <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
961          "          <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"          "          <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
962          "        </item>"          "        </item>"
963            "        <item id='OpenInstrPropsByDoubleClick'>"
964            "          <attribute name='label' translatable='yes'>Instrument Properties by Double Click</attribute>"
965            "          <attribute name='action'>AppMenu.OpenInstrPropsByDoubleClick</attribute>"
966            "        </item>"
967          "      </section>"          "      </section>"
968          "      <section>"          "      <section>"
969          "        <item id='RefreshAll'>"          "        <item id='RefreshAll'>"
# Line 1010  MainWindow::MainWindow() : Line 1039  MainWindow::MainWindow() :
1039          "        <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"          "        <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
1040          "        <attribute name='action'>AppMenu.DupInstrument</attribute>"          "        <attribute name='action'>AppMenu.DupInstrument</attribute>"
1041          "      </item>"          "      </item>"
1042            "      <item id='MoveInstrument'>"
1043            "        <attribute name='label' translatable='yes'>Move Instrument To ...</attribute>"
1044            "        <attribute name='action'>AppMenu.MoveInstrument</attribute>"
1045            "      </item>"
1046          "      <item id='CombInstruments'>"          "      <item id='CombInstruments'>"
1047          "        <attribute name='label' translatable='yes'>Combine Instruments</attribute>"          "        <attribute name='label' translatable='yes'>Combine Instruments</attribute>"
1048          "        <attribute name='action'>AppMenu.CombInstruments</attribute>"          "        <attribute name='action'>AppMenu.CombInstruments</attribute>"
# Line 1148  MainWindow::MainWindow() : Line 1181  MainWindow::MainWindow() :
1181          "      <menu action='AssignScripts'/>"          "      <menu action='AssignScripts'/>"
1182          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
1183          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
1184            "      <menuitem action='MoveInstrument'/>"
1185          "      <menuitem action='CombInstruments'/>"          "      <menuitem action='CombInstruments'/>"
1186          "      <separator/>"          "      <separator/>"
1187          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
# Line 1163  MainWindow::MainWindow() : Line 1197  MainWindow::MainWindow() :
1197          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
1198          "      <menuitem action='ShowTooltips'/>"          "      <menuitem action='ShowTooltips'/>"
1199          "      <menuitem action='AutoRestoreWinDim'/>"          "      <menuitem action='AutoRestoreWinDim'/>"
1200            "      <menuitem action='OpenInstrPropsByDoubleClick'/>"
1201          "      <separator/>"          "      <separator/>"
1202          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
1203          "    </menu>"          "    </menu>"
# Line 1186  MainWindow::MainWindow() : Line 1221  MainWindow::MainWindow() :
1221          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
1222          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
1223          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
1224            "    <menuitem action='MoveInstrument'/>"
1225          "    <menuitem action='CombInstruments'/>"          "    <menuitem action='CombInstruments'/>"
1226          "    <separator/>"          "    <separator/>"
1227          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
# Line 1286  MainWindow::MainWindow() : Line 1322  MainWindow::MainWindow() :
1322      }      }
1323      {      {
1324          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1325                uiManager->get_widget("/MenuBar/MenuView/OpenInstrPropsByDoubleClick"));
1326            item->set_tooltip_text(_("If checked, double clicking an instrument opens its properties dialog."));
1327        }
1328        {
1329            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1330              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1331          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1332      }      }
# Line 1342  MainWindow::MainWindow() : Line 1383  MainWindow::MainWindow() :
1383    
1384    
1385      // Create the Tree model:      // Create the Tree model:
1386      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refInstrumentsTreeModel = Gtk::ListStore::create(m_InstrumentsModel);
1387      m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);      m_refInstrumentsModelFilter = Gtk::TreeModelFilter::create(m_refInstrumentsTreeModel);
1388      m_refTreeModelFilter->set_visible_func(      m_refInstrumentsModelFilter->set_visible_func(
1389          sigc::mem_fun(*this, &MainWindow::instrument_row_visible)          sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
1390      );      );
1391      m_TreeView.set_model(m_refTreeModelFilter);      m_TreeViewInstruments.set_model(m_refInstrumentsModelFilter);
1392    
1393      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);      m_TreeViewInstruments.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1394      m_TreeView.set_has_tooltip(true);      m_TreeViewInstruments.set_has_tooltip(true);
1395      m_TreeView.signal_query_tooltip().connect(      m_TreeViewInstruments.signal_query_tooltip().connect(
1396          sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)          sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)
1397      );      );
1398      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refInstrumentsTreeModel->signal_row_changed().connect(
1399          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1400      );      );
1401    
1402      // Add the TreeView's view columns:      // Add the TreeView's view columns:
1403      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeViewInstruments.append_column(_("Nr"), m_InstrumentsModel.m_col_nr);
1404      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeViewInstruments.append_column_editable(_("Instrument"), m_InstrumentsModel.m_col_name);
1405      m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);      m_TreeViewInstruments.append_column(_("Scripts"), m_InstrumentsModel.m_col_scripts);
1406      m_TreeView.set_headers_visible(true);      m_TreeViewInstruments.set_headers_visible(true);
1407            
1408      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
1409      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
1410      {      {
1411          std::vector<Gtk::TargetEntry> drag_target_instrument;          std::vector<Gtk::TargetEntry> drag_target_instrument;
1412          drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));          drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
1413          m_TreeView.drag_source_set(drag_target_instrument);          m_TreeViewInstruments.drag_source_set(drag_target_instrument);
1414          m_TreeView.drag_dest_set(drag_target_instrument);          m_TreeViewInstruments.drag_dest_set(drag_target_instrument);
1415          m_TreeView.signal_drag_begin().connect(          m_TreeViewInstruments.signal_drag_begin().connect(
1416              sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)              sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
1417          );          );
1418          m_TreeView.signal_drag_data_get().connect(          m_TreeViewInstruments.signal_drag_data_get().connect(
1419              sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)              sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
1420          );          );
1421          m_TreeView.signal_drag_data_received().connect(          m_TreeViewInstruments.signal_drag_data_received().connect(
1422              sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)              sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
1423          );          );
1424      }      }
# Line 1484  MainWindow::MainWindow() : Line 1525  MainWindow::MainWindow() :
1525          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1526      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
1527          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1528      propDialog.signal_changed().connect(      sampleProps.signal_changed().connect(
1529            sigc::mem_fun(*this, &MainWindow::file_changed));
1530        fileProps.signal_changed().connect(
1531          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
1532      midiRules.signal_changed().connect(      midiRules.signal_changed().connect(
1533          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
# Line 1506  MainWindow::MainWindow() : Line 1549  MainWindow::MainWindow() :
1549          sigc::mem_fun(*this, &MainWindow::select_sample)          sigc::mem_fun(*this, &MainWindow::select_sample)
1550      );      );
1551    
1552        dimreg_edit.editScriptSlotsButton.signal_clicked().connect(
1553            sigc::mem_fun(*this, &MainWindow::show_script_slots)
1554        );
1555        // simply sending the same signal (pair) to the sampler on 'patch' variable
1556        // changes as the already existing signal (pair) when the user edits the
1557        // script's source code, because the sampler would reload the source code
1558        // and the 'patch' variables from the instrument on this signal anyway
1559        dimreg_edit.scriptVars.signal_vars_to_be_changed.connect(
1560            [this](gig::Instrument* instr) {
1561                for (int i = 0; i < instr->ScriptSlotCount(); ++i) {
1562                    gig::Script* script = instr->GetScriptOfSlot(i);
1563                    signal_script_to_be_changed.emit(script);
1564                }
1565            }
1566        );
1567        dimreg_edit.scriptVars.signal_vars_changed.connect(
1568            [this](gig::Instrument* instr) {
1569                for (int i = 0; i < instr->ScriptSlotCount(); ++i) {
1570                    gig::Script* script = instr->GetScriptOfSlot(i);
1571                    signal_script_changed.emit(script);
1572                }
1573            }
1574        );
1575        dimreg_edit.scriptVars.signal_edit_script.connect(
1576            [this](gig::Script* script) {
1577                editScript(script);
1578            }
1579        );
1580    
1581      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1582          sigc::hide(          sigc::hide(
1583              sigc::bind(              sigc::bind(
# Line 1548  MainWindow::MainWindow() : Line 1620  MainWindow::MainWindow() :
1620          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
1621    
1622      m_searchText.signal_changed().connect(      m_searchText.signal_changed().connect(
1623          sigc::mem_fun(*m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)          sigc::mem_fun(*m_refInstrumentsModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
1624      );      );
1625    
1626      file = 0;      file = 0;
# Line 1662  void MainWindow::bringToFront() { Line 1734  void MainWindow::bringToFront() {
1734      #endif      #endif
1735      raise();      raise();
1736      present();      present();
1737    
1738        // restore user specified splitter position
1739        if (Settings::singleton()->mainWindowSplitterPosX >= 0 &&
1740            Settings::singleton()->autoRestoreWindowDimension)
1741        {
1742            const int pos = Settings::singleton()->mainWindowSplitterPosX;
1743            printf("Restoring user's preferred splitter position=%d\n", pos);
1744            m_HPaned.set_position(pos);
1745        }
1746        // this signal handler is late-connected after the UI build-up has settled
1747        // to prevent the UI build-up from overwriting user's setting for splitter
1748        // position unintentionally
1749        m_HPaned.property_position().signal_changed().connect([this]{
1750            if (!Settings::singleton()->autoRestoreWindowDimension) return;
1751            const int pos = m_HPaned.get_position();
1752            printf("Saving user's preferred splitter position=%d\n", pos);
1753            Settings::singleton()->mainWindowSplitterPosX = pos;
1754        });
1755  }  }
1756    
1757  void MainWindow::updateMacroMenu() {  void MainWindow::updateMacroMenu() {
# Line 1792  void MainWindow::region_changed() Line 1882  void MainWindow::region_changed()
1882    
1883  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
1884  {  {
1885      gig::Instrument* instrument = 0;      gig::Instrument* instrument = NULL;
1886      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();  
1887        // get indeces of visual selection
1888        std::vector<Gtk::TreeModel::Path> rows = m_TreeViewInstruments.get_selection()->get_selected_rows();
1889      if (rows.empty()) return NULL;      if (rows.empty()) return NULL;
1890    
1891        // convert index of visual selection (i.e. if filtered) to index of model
1892        Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
1893        if (!path) return NULL;
1894    
1895      //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.      //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
1896      Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);      Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
1897      if (it) {      if (it) {
1898          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1899          instrument = row[m_Columns.m_col_instr];          instrument = row[m_InstrumentsModel.m_col_instr];
1900      }      }
1901      return instrument;      return instrument;
1902  }  }
# Line 1864  void MainWindow::on_sel_change() Line 1961  void MainWindow::on_sel_change()
1961  {  {
1962  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
1963      // select item in instrument menu      // select item in instrument menu
1964      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();      std::vector<Gtk::TreeModel::Path> rows = m_TreeViewInstruments.get_selection()->get_selected_rows();
1965      if (!rows.empty()) {      if (!rows.empty()) {
1966          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);          // convert index of visual selection (i.e. if filtered) to index of model
1967            Gtk::TreeModel::Path row = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
1968            Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(row);
1969          if (it) {          if (it) {
1970              Gtk::TreePath path(it);              Gtk::TreePath path(it);
1971              int index = path[0];              int index = path[0];
# Line 1879  void MainWindow::on_sel_change() Line 1978  void MainWindow::on_sel_change()
1978    
1979      updateScriptListOfMenu();      updateScriptListOfMenu();
1980    
1981      m_RegionChooser.set_instrument(get_instrument());      gig::Instrument* instr = get_instrument();
1982    
1983        m_RegionChooser.set_instrument(instr);
1984        dimreg_edit.scriptVars.setInstrument(instr, true/*force update*/);
1985    
1986      if (Settings::singleton()->syncSamplerInstrumentSelection) {      if (Settings::singleton()->syncSamplerInstrumentSelection) {
1987          switch_sampler_instrument_signal.emit(get_instrument());          switch_sampler_instrument_signal.emit(get_instrument());
# Line 2002  Loader::Loader(const char* filename) : Line 2104  Loader::Loader(const char* filename) :
2104  void Loader::thread_function_sub(gig::progress_t& progress)  void Loader::thread_function_sub(gig::progress_t& progress)
2105  {  {
2106      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
2107        // due to the multi-threaded scenario use separate file I/O handles for
2108        // each thread to avoid file I/O concurrency issues with .gig file
2109        riff->SetIOPerThread(true);
2110    
2111      gig = new gig::File(riff);      gig = new gig::File(riff);
2112    
2113      gig->GetInstrument(0, &progress);      gig->GetInstrument(0, &progress);
# Line 2071  void MainWindow::__clear() { Line 2177  void MainWindow::__clear() {
2177      // forget all samples that ought to be imported      // forget all samples that ought to be imported
2178      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
2179      // clear the samples and instruments tree views      // clear the samples and instruments tree views
2180      m_refTreeModel->clear();      m_refInstrumentsTreeModel->clear();
2181      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2182      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2183  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
# Line 2088  void MainWindow::__clear() { Line 2194  void MainWindow::__clear() {
2194    
2195  void MainWindow::__refreshEntireGUI() {  void MainWindow::__refreshEntireGUI() {
2196      // clear the samples and instruments tree views      // clear the samples and instruments tree views
2197      m_refTreeModel->clear();      m_refInstrumentsTreeModel->clear();
2198      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
2199      m_refScriptsTreeModel->clear();      m_refScriptsTreeModel->clear();
2200  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
# Line 2115  void MainWindow::on_action_file_new() Line 2221  void MainWindow::on_action_file_new()
2221      __clear();      __clear();
2222      // create a new .gig file (virtually yet)      // create a new .gig file (virtually yet)
2223      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
2224        // due to the multi-threaded scenario use separate file I/O handles for
2225        // each thread to avoid file I/O concurrency issues with .gig file
2226        RIFF::File* pRIFF = pFile->GetRiffFile();
2227        pRIFF->SetIOPerThread(true);
2228      // already add one new instrument by default      // already add one new instrument by default
2229      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
2230      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
# Line 2261  void MainWindow::load_instrument(gig::In Line 2371  void MainWindow::load_instrument(gig::In
2371      {      {
2372          if (instrument == instr) {          if (instrument == instr) {
2373              // select item in "instruments" tree view              // select item in "instruments" tree view
2374              m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));              m_TreeViewInstruments.get_selection()->select(Gtk::TreePath(ToString(i)));
2375              // make sure the selected item in the "instruments" tree view is              // make sure the selected item in the "instruments" tree view is
2376              // visible (scroll to it)              // visible (scroll to it)
2377              m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));              m_TreeViewInstruments.scroll_to_row(Gtk::TreePath(ToString(i)));
2378  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
2379              // select item in instrument menu              // select item in instrument menu
2380              {              {
# Line 2603  void MainWindow::__import_queued_samples Line 2713  void MainWindow::__import_queued_samples
2713    
2714  void MainWindow::on_action_file_properties()  void MainWindow::on_action_file_properties()
2715  {  {
2716      propDialog.show();      fileProps.show();
2717      propDialog.deiconify();      fileProps.deiconify();
2718  }  }
2719    
2720  void MainWindow::on_action_warn_user_on_extensions() {  void MainWindow::on_action_warn_user_on_extensions() {
# Line 2628  void MainWindow::on_show_tooltips_change Line 2738  void MainWindow::on_show_tooltips_change
2738      dimreg_stereo.set_has_tooltip(b);      dimreg_stereo.set_has_tooltip(b);
2739    
2740      // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell      // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell
2741      //m_TreeView.set_has_tooltip(b);      //m_TreeViewInstruments.set_has_tooltip(b);
2742    
2743      m_TreeViewSamples.set_has_tooltip(b);      m_TreeViewSamples.set_has_tooltip(b);
2744      m_TreeViewScripts.set_has_tooltip(b);      m_TreeViewScripts.set_has_tooltip(b);
# Line 2675  void MainWindow::on_action_help_about() Line 2785  void MainWindow::on_action_help_about()
2785      dialog.run();      dialog.run();
2786  }  }
2787    
2788  PropDialog::PropDialog()  FilePropDialog::FilePropDialog()
2789      : eFileFormat(_("File Format")),      : eFileFormat(_("File Format")),
2790        eName(_("Name")),        eName(_("Name")),
2791        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
# Line 2709  PropDialog::PropDialog() Line 2819  PropDialog::PropDialog()
2819      set_title(_("File Properties"));      set_title(_("File Properties"));
2820      eName.set_width_chars(50);      eName.set_width_chars(50);
2821    
2822      connect(eFileFormat, &PropDialog::set_FileFormat);      connect(eFileFormat, &FilePropDialog::set_FileFormat);
2823      connect(eName, &DLS::Info::Name);      connect(eName, &DLS::Info::Name);
2824      connect(eCreationDate, &DLS::Info::CreationDate);      connect(eCreationDate, &DLS::Info::CreationDate);
2825      connect(eComments, &DLS::Info::Comments);      connect(eComments, &DLS::Info::Comments);
# Line 2770  PropDialog::PropDialog() Line 2880  PropDialog::PropDialog()
2880      quitButton.set_can_default();      quitButton.set_can_default();
2881      quitButton.grab_focus();      quitButton.grab_focus();
2882      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
2883          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &FilePropDialog::hide));
2884    
2885      quitButton.show();      quitButton.show();
2886      vbox.show();      vbox.show();
# Line 2779  PropDialog::PropDialog() Line 2889  PropDialog::PropDialog()
2889  #endif  #endif
2890  }  }
2891    
2892  void PropDialog::set_file(gig::File* file)  void FilePropDialog::set_file(gig::File* file)
2893  {  {
2894      m_file = file;      m_file = file;
2895      update(file->pInfo);      update(file->pInfo);
# Line 2805  void PropDialog::set_file(gig::File* fil Line 2915  void PropDialog::set_file(gig::File* fil
2915      update_model--;      update_model--;
2916  }  }
2917    
2918  void PropDialog::set_FileFormat(int value)  void FilePropDialog::set_FileFormat(int value)
2919  {  {
2920      m_file->pVersion->major = value;      m_file->pVersion->major = value;
2921  }  }
# Line 2849  InstrumentProps::InstrumentProps() : Line 2959  InstrumentProps::InstrumentProps() :
2959      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
2960      eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
2961      eMIDIProgram(_("MIDI program")),      eMIDIProgram(_("MIDI program")),
2962      eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eAttenuation(_("Attenuation (dB)"), -96, +96, 0, 1),
     eGainPlus6(_("Gain +6dB"), eAttenuation, -6),  
2963      eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
2964      eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
2965      ePitchbendRange(_("Pitchbend range"), 0, 48),      ePitchbendRange(_("Pitchbend range (halftones)"), 0, 48),
2966      ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
2967      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2968      eDimensionKeyRangeHigh(_("Keyswitching range high")),      eDimensionKeyRangeHigh(_("Keyswitching range high")),
# Line 2899  InstrumentProps::InstrumentProps() : Line 3008  InstrumentProps::InstrumentProps() :
3008      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
3009      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
3010      connect(eAttenuation, &gig::Instrument::Attenuation);      connect(eAttenuation, &gig::Instrument::Attenuation);
     connect(eGainPlus6, &gig::Instrument::Attenuation);  
3011      connect(eEffectSend, &gig::Instrument::EffectSend);      connect(eEffectSend, &gig::Instrument::EffectSend);
3012      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
3013      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
# Line 2967  InstrumentProps::InstrumentProps() : Line 3075  InstrumentProps::InstrumentProps() :
3075      table.add(eMIDIBank);      table.add(eMIDIBank);
3076      table.add(eMIDIProgram);      table.add(eMIDIProgram);
3077      table.add(eAttenuation);      table.add(eAttenuation);
     table.add(eGainPlus6);  
3078      table.add(eEffectSend);      table.add(eEffectSend);
3079      table.add(eFineTune);      table.add(eFineTune);
3080      table.add(ePitchbendRange);      table.add(ePitchbendRange);
# Line 3064  void InstrumentProps::set_instrument(gig Line 3171  void InstrumentProps::set_instrument(gig
3171  }  }
3172    
3173    
3174    SampleProps::SampleProps() :
3175    #if HAS_GTKMM_STOCK
3176        quitButton(Gtk::Stock::CLOSE),
3177    #else
3178        quitButton(_("_Close")),
3179    #endif
3180        table(2,1),
3181        eName(_("Name")),
3182        eUnityNote(_("Unity Note")),
3183        eSampleGroup(_("Sample Group")),
3184        eSampleFormatInfo(_("Sample Format")),
3185        eSampleID("Sample ID"),
3186        eChecksum("Wave Data CRC-32"),
3187        eLoopsCount(_("Loops"), 0, 1), // we might support more than 1 loop in future
3188        eLoopStart(_("Loop start position"), 0, 9999999),
3189        eLoopLength(_("Loop size"), 0, 9999999),
3190        eLoopType(_("Loop type")),
3191        eLoopPlayCount(_("Playback count")),
3192        table2(2,1),
3193        eName2(_("Name")),
3194        eCreationDate(_("Creation date")),
3195        eComments(_("Comments")),
3196        eProduct(_("Product")),
3197        eCopyright(_("Copyright")),
3198        eArtists(_("Artists")),
3199        eGenre(_("Genre")),
3200        eKeywords(_("Keywords")),
3201        eEngineer(_("Engineer")),
3202        eTechnician(_("Technician")),
3203        eSoftware(_("Software")),
3204        eMedium(_("Medium")),
3205        eSource(_("Source")),
3206        eSourceForm(_("Source form")),
3207        eCommissioned(_("Commissioned")),
3208        eSubject(_("Subject"))
3209    {
3210        if (!Settings::singleton()->autoRestoreWindowDimension) {
3211            //set_default_size(470, 390);
3212            set_position(Gtk::WIN_POS_MOUSE);
3213        }
3214    
3215        set_title(_("Sample Properties"));
3216    
3217        tabs.append_page(vbox[1], _("Settings"));
3218        tabs.append_page(vbox[2], _("Info"));
3219    
3220        connect(eName, &SampleProps::set_Name);
3221        connect(eUnityNote, &gig::Sample::MIDIUnityNote);
3222        connect(eLoopsCount, &gig::Sample::Loops);
3223        connectLambda(eLoopStart, [this](uint32_t start){
3224            m->LoopStart = start;
3225            m->LoopEnd = start + m->LoopSize;
3226        });
3227        connectLambda(eLoopLength, [this](uint32_t length){
3228            m->LoopSize = length;
3229            m->LoopEnd = m->LoopStart + length;
3230        });
3231        {
3232            const char* choices[] = { _("normal"), _("bidirectional"), _("backward"), 0 };
3233            static const gig::loop_type_t values[] = {
3234                gig::loop_type_normal,
3235                gig::loop_type_bidirectional,
3236                gig::loop_type_backward
3237            };
3238            eLoopType.set_choices(choices, values);
3239        }
3240        connect(eLoopType, &gig::Sample::LoopType);
3241        connect(eLoopPlayCount, &gig::Sample::LoopPlayCount);
3242    
3243        eName.signal_value_changed().connect(sig_name_changed.make_slot());
3244    
3245        connect(eName2, &SampleProps::set_Name);
3246        connectLambda(eCreationDate, [this](gig::String s) {
3247            m->pInfo->CreationDate = s;
3248        });
3249        connectLambda(eComments, [this](gig::String s) {
3250            m->pInfo->Comments = s;
3251        });
3252        connectLambda(eProduct, [this](gig::String s) {
3253            m->pInfo->Product = s;
3254        });
3255        connectLambda(eCopyright, [this](gig::String s) {
3256            m->pInfo->Copyright = s;
3257        });
3258        connectLambda(eArtists, [this](gig::String s) {
3259            m->pInfo->Artists = s;
3260        });
3261        connectLambda(eGenre, [this](gig::String s) {
3262            m->pInfo->Genre = s;
3263        });
3264        connectLambda(eKeywords, [this](gig::String s) {
3265            m->pInfo->Keywords = s;
3266        });
3267        connectLambda(eEngineer, [this](gig::String s) {
3268            m->pInfo->Engineer = s;
3269        });
3270        connectLambda(eTechnician, [this](gig::String s) {
3271            m->pInfo->Technician = s;
3272        });
3273        connectLambda(eSoftware, [this](gig::String s) {
3274            m->pInfo->Software = s;
3275        });
3276        connectLambda(eMedium, [this](gig::String s) {
3277            m->pInfo->Medium = s;
3278        });
3279        connectLambda(eSource, [this](gig::String s) {
3280            m->pInfo->Source = s;
3281        });
3282        connectLambda(eSourceForm, [this](gig::String s) {
3283            m->pInfo->SourceForm = s;
3284        });
3285        connectLambda(eCommissioned, [this](gig::String s) {
3286            m->pInfo->Commissioned = s;
3287        });
3288        connectLambda(eSubject, [this](gig::String s) {
3289            m->pInfo->Subject = s;
3290        });
3291    
3292        // tab 1
3293    #if USE_GTKMM_GRID
3294        table.set_column_spacing(5);
3295    #else
3296        table.set_col_spacings(5);
3297    #endif
3298        table.add(eName);
3299        table.add(eUnityNote);
3300        table.add(eSampleGroup);
3301        table.add(eSampleFormatInfo);
3302        table.add(eSampleID);
3303        table.add(eChecksum);
3304        table.add(eLoopsCount);
3305        table.add(eLoopStart);
3306        table.add(eLoopLength);
3307        table.add(eLoopType);
3308        table.add(eLoopPlayCount);
3309    
3310        // tab 2
3311    #if USE_GTKMM_GRID
3312        table2.set_column_spacing(5);
3313    #else
3314        table2.set_col_spacings(5);
3315    #endif
3316        table2.add(eName2);
3317        table2.add(eCreationDate);
3318        table2.add(eComments);
3319        table2.add(eProduct);
3320        table2.add(eCopyright);
3321        table2.add(eArtists);
3322        table2.add(eGenre);
3323        table2.add(eKeywords);
3324        table2.add(eEngineer);
3325        table2.add(eTechnician);
3326        table2.add(eSoftware);
3327        table2.add(eMedium);
3328        table2.add(eSource);
3329        table2.add(eSourceForm);
3330        table2.add(eCommissioned);
3331        table2.add(eSubject);
3332    
3333        add(vbox[0]);
3334    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3335        table.set_margin(5);
3336    #else
3337        table.set_border_width(5);
3338    #endif
3339        vbox[1].pack_start(table);
3340        vbox[2].pack_start(table2);
3341        table.show();
3342        table2.show();
3343        vbox[0].pack_start(tabs);
3344        vbox[0].pack_start(buttonBox, Gtk::PACK_SHRINK);
3345        buttonBox.set_layout(Gtk::BUTTONBOX_END);
3346    #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3347        buttonBox.set_margin(5);
3348    #else
3349        buttonBox.set_border_width(5);
3350    #endif
3351        buttonBox.show();
3352        buttonBox.pack_start(quitButton);
3353        quitButton.set_can_default();
3354        quitButton.grab_focus();
3355    
3356        quitButton.signal_clicked().connect(
3357            sigc::mem_fun(*this, &SampleProps::hide));
3358    
3359        quitButton.show();
3360        vbox[0].show();
3361    #if HAS_GTKMM_SHOW_ALL_CHILDREN
3362        show_all_children();
3363    #endif
3364    }
3365    
3366    void SampleProps::set_sample(gig::Sample* sample)
3367    {
3368        update(sample);
3369    
3370        update_model++;
3371    
3372        // tab 1
3373        eName.set_value(sample->pInfo->Name);
3374        eUnityNote.set_value(sample->MIDIUnityNote);
3375        // show sample group name
3376        {
3377            Glib::ustring s = "---";
3378            if (sample && sample->GetGroup())
3379                s = sample->GetGroup()->Name;
3380            eSampleGroup.text.set_text(s);
3381        }
3382        // assemble sample format info string
3383        {
3384            Glib::ustring s;
3385            if (sample) {
3386                switch (sample->Channels) {
3387                    case 1: s = _("Mono"); break;
3388                    case 2: s = _("Stereo"); break;
3389                    default:
3390                        s = ToString(sample->Channels) + _(" audio channels");
3391                        break;
3392                }
3393                s += " " + ToString(sample->BitDepth) + " Bits";
3394                s += " " + ToString(sample->SamplesPerSecond/1000) + "."
3395                         + ToString((sample->SamplesPerSecond%1000)/100) + " kHz";
3396            } else {
3397                s = _("No sample assigned to this dimension region.");
3398            }
3399            eSampleFormatInfo.text.set_text(s);
3400        }
3401        // generate sample's memory address pointer string
3402        {
3403            Glib::ustring s;
3404            if (sample) {
3405                char buf[64] = {};
3406                snprintf(buf, sizeof(buf), "%p", sample);
3407                s = buf;
3408            } else {
3409                s = "---";
3410            }
3411            eSampleID.text.set_text(s);
3412        }
3413        // generate raw wave form data CRC-32 checksum string
3414        {
3415            Glib::ustring s = "---";
3416            if (sample) {
3417                char buf[64] = {};
3418                snprintf(buf, sizeof(buf), "%x", sample->GetWaveDataCRC32Checksum());
3419                s = buf;
3420            }
3421            eChecksum.text.set_text(s);
3422        }
3423        eLoopsCount.set_value(sample->Loops);
3424        eLoopStart.set_value(sample->LoopStart);
3425        eLoopLength.set_value(sample->LoopSize);
3426        eLoopType.set_value(sample->LoopType);
3427        eLoopPlayCount.set_value(sample->LoopPlayCount);
3428        // tab 2
3429        eName2.set_value(sample->pInfo->Name);
3430        eCreationDate.set_value(sample->pInfo->CreationDate);
3431        eComments.set_value(sample->pInfo->Comments);
3432        eProduct.set_value(sample->pInfo->Product);
3433        eCopyright.set_value(sample->pInfo->Copyright);
3434        eArtists.set_value(sample->pInfo->Artists);
3435        eGenre.set_value(sample->pInfo->Genre);
3436        eKeywords.set_value(sample->pInfo->Keywords);
3437        eEngineer.set_value(sample->pInfo->Engineer);
3438        eTechnician.set_value(sample->pInfo->Technician);
3439        eSoftware.set_value(sample->pInfo->Software);
3440        eMedium.set_value(sample->pInfo->Medium);
3441        eSource.set_value(sample->pInfo->Source);
3442        eSourceForm.set_value(sample->pInfo->SourceForm);
3443        eCommissioned.set_value(sample->pInfo->Commissioned);
3444        eSubject.set_value(sample->pInfo->Subject);
3445    
3446        update_model--;
3447    }
3448    
3449    void SampleProps::set_Name(const gig::String& name)
3450    {
3451        m->pInfo->Name = name;
3452    }
3453    
3454    void SampleProps::update_name()
3455    {
3456        update_model++;
3457        eName.set_value(m->pInfo->Name);
3458        update_model--;
3459    }
3460    
3461    
3462  void MainWindow::file_changed()  void MainWindow::file_changed()
3463  {  {
3464      if (file && !file_is_changed) {      if (file && !file_is_changed) {
# Line 3095  void MainWindow::updateSampleRefCountMap Line 3490  void MainWindow::updateSampleRefCountMap
3490    
3491  bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {  bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
3492      Gtk::TreeModel::iterator iter;      Gtk::TreeModel::iterator iter;
3493      if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) {      if (!m_TreeViewInstruments.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
3494          return false;          return false;
3495      }      }
3496      Gtk::TreeModel::Path path(iter);      Gtk::TreeModel::Path path(iter);
# Line 3105  bool MainWindow::onQueryTreeViewTooltip( Line 3500  bool MainWindow::onQueryTreeViewTooltip(
3500      {      {
3501          Gtk::TreeModel::Path path; // unused          Gtk::TreeModel::Path path; // unused
3502          int cellX, cellY; // unused          int cellX, cellY; // unused
3503          m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);          m_TreeViewInstruments.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
3504      }      }
3505      Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);      Gtk::TreeViewColumn* scriptsColumn = m_TreeViewInstruments.get_column(2);
3506      if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...      if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
3507          // show the script(s) assigned to the hovered instrument as tooltip          // show the script(s) assigned to the hovered instrument as tooltip
3508          tooltip->set_markup( row[m_Columns.m_col_tooltip] );          tooltip->set_markup( row[m_InstrumentsModel.m_col_tooltip] );
3509          m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);          m_TreeViewInstruments.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
3510      } else {      } else {
3511          // if beginners' tooltips is disabled then don't show the following one          // if beginners' tooltips is disabled then don't show the following one
3512          if (!Settings::singleton()->showTooltips)          if (!Settings::singleton()->showTooltips)
# Line 3121  bool MainWindow::onQueryTreeViewTooltip( Line 3516  bool MainWindow::onQueryTreeViewTooltip(
3516              "Right click here for actions on instruments & MIDI Rules. "              "Right click here for actions on instruments & MIDI Rules. "
3517              "Drag & drop to change the order of instruments."              "Drag & drop to change the order of instruments."
3518          ));          ));
3519          m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);          m_TreeViewInstruments.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
3520      }      }
3521      return true;      return true;
3522  }  }
# Line 3147  void MainWindow::load_gig(gig::File* gig Line 3542  void MainWindow::load_gig(gig::File* gig
3542      file = 0;      file = 0;
3543      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
3544    
3545        // assuming libgig's file-IO-per-thread feature is enabled: by default
3546        // the file stream is closed for individual threads (except of the original
3547        // thread having opened the gig file), so open the file stream for this
3548        // thread for being able to read the .gig file
3549        // (see libgig's RIFF::File::SetIOPerThread() for details)
3550        ::RIFF::File* riff = gig->GetRiffFile();
3551        if (!riff->IsNew() && riff->GetMode() == ::RIFF::stream_mode_closed) {
3552            try {
3553                riff->SetMode(::RIFF::stream_mode_read);
3554            } catch (...) {
3555                printf("Failed opening '%s' in read mode\n",
3556                       riff->GetFileName().c_str());
3557            }
3558        }
3559    
3560      this->filename =      this->filename =
3561          (filename && strlen(filename) > 0) ?          (filename && strlen(filename) > 0) ?
3562              filename : (!gig->GetFileName().empty()) ?              filename : (!gig->GetFileName().empty()) ?
# Line 3155  void MainWindow::load_gig(gig::File* gig Line 3565  void MainWindow::load_gig(gig::File* gig
3565      file_has_name = filename;      file_has_name = filename;
3566      file_is_changed = false;      file_is_changed = false;
3567    
3568      propDialog.set_file(gig);      fileProps.set_file(gig);
3569    
3570      instrument_name_connection.block();      instrument_name_connection.block();
3571      int index = 0;      int index = 0;
# Line 3164  void MainWindow::load_gig(gig::File* gig Line 3574  void MainWindow::load_gig(gig::File* gig
3574          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3575          const int iScriptSlots = instrument->ScriptSlotCount();          const int iScriptSlots = instrument->ScriptSlotCount();
3576    
3577          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refInstrumentsTreeModel->append();
3578          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
3579          row[m_Columns.m_col_nr] = index;          row[m_InstrumentsModel.m_col_nr] = index;
3580          row[m_Columns.m_col_name] = name;          row[m_InstrumentsModel.m_col_name] = name;
3581          row[m_Columns.m_col_instr] = instrument;          row[m_InstrumentsModel.m_col_instr] = instrument;
3582          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";          row[m_InstrumentsModel.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3583          row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);          row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
3584    
3585  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
3586          add_instrument_to_menu(name);          add_instrument_to_menu(name);
# Line 3232  void MainWindow::load_gig(gig::File* gig Line 3642  void MainWindow::load_gig(gig::File* gig
3642      file = gig;      file = gig;
3643    
3644      // select the first instrument      // select the first instrument
3645      m_TreeView.get_selection()->select(Gtk::TreePath("0"));      m_TreeViewInstruments.get_selection()->select(Gtk::TreePath("0"));
3646    
3647      instr_props_set_instrument();      instr_props_set_instrument();
3648      gig::Instrument* instrument = get_instrument();      gig::Instrument* instrument = get_instrument();
# Line 3245  bool MainWindow::instr_props_set_instrum Line 3655  bool MainWindow::instr_props_set_instrum
3655  {  {
3656      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
3657    
3658      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();      // get visual selection
3659        std::vector<Gtk::TreeModel::Path> rows = m_TreeViewInstruments.get_selection()->get_selected_rows();
3660      if (rows.empty()) {      if (rows.empty()) {
3661          instrumentProps.hide();          instrumentProps.hide();
3662          return false;          return false;
3663      }      }
3664    
3665        // convert index of visual selection (i.e. if filtered) to index of model
3666        Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
3667    
3668      //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.      //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3669      Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);      Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
3670      if (it) {      if (it) {
3671          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
3672          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
3673    
3674          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
3675    
# Line 3283  void MainWindow::show_instr_props() Line 3698  void MainWindow::show_instr_props()
3698  void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)  void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
3699  {  {
3700      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3701      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_InstrumentsModel.m_col_name];
3702    
3703      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
3704      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3705      if (gigname != name) {      if (gigname != name) {
3706          Gtk::TreeModel::Path path(*it);          Gtk::TreeModel::Path path(*it);
3707          const int index = path[0];          const int index = path[0];
3708          row[m_Columns.m_col_name] = gigname;          row[m_InstrumentsModel.m_col_name] = gigname;
3709          row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);          row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
3710        }
3711    }
3712    
3713    bool MainWindow::sample_props_set_sample()
3714    {
3715        sampleProps.signal_name_changed().clear();
3716    
3717        std::vector<Gtk::TreeModel::Path> rows = m_TreeViewSamples.get_selection()->get_selected_rows();
3718        if (rows.empty()) {
3719            sampleProps.hide();
3720            return false;
3721        }
3722        //NOTE: was const_iterator before, which did not compile with GTKMM4 development branch, probably going to be fixed before final GTKMM4 release though.
3723        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3724        if (it) {
3725            Gtk::TreeModel::Row row = *it;
3726            gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3727    
3728            sampleProps.set_sample(sample);
3729    
3730            // make sure sample tree is updated when user changes the
3731            // sample name in sample properties window
3732            sampleProps.signal_name_changed().connect(
3733                sigc::bind(
3734                    sigc::mem_fun(*this,
3735                        &MainWindow::sample_name_changed_by_sample_props
3736                    ), it
3737                )
3738            );
3739        } else {
3740            sampleProps.hide();
3741        }
3742        //NOTE: explicit boolean cast required for GTKMM4 development branch here
3743        return it ? true : false;
3744    }
3745    
3746    void MainWindow::show_sample_props()
3747    {
3748        if (sample_props_set_sample()) {
3749            sampleProps.show();
3750            sampleProps.deiconify();
3751        }
3752    }
3753    
3754    void MainWindow::sample_name_changed_by_sample_props(Gtk::TreeModel::iterator& it)
3755    {
3756        Gtk::TreeModel::Row row = *it;
3757        Glib::ustring name = row[m_SamplesModel.m_col_name];
3758    
3759        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
3760        Glib::ustring gigname(gig_to_utf8(sample->pInfo->Name));
3761        if (gigname != name) {
3762            Gtk::TreeModel::Path path(*it);
3763            row[m_SamplesModel.m_col_name] = gigname;
3764      }      }
3765  }  }
3766    
# Line 3307  void MainWindow::show_midi_rules() Line 3776  void MainWindow::show_midi_rules()
3776    
3777  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
3778      if (!file) return;      if (!file) return;
3779    
3780      // get selected instrument      // get selected instrument
3781      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();      gig::Instrument* instrument = get_instrument();
     if (rows.empty()) return;  
     Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);  
     if (!it) return;  
     Gtk::TreeModel::Row row = *it;  
     gig::Instrument* instrument = row[m_Columns.m_col_instr];  
3782      if (!instrument) return;      if (!instrument) return;
3783    
3784      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
# Line 3329  void MainWindow::onScriptSlotsModified(g Line 3794  void MainWindow::onScriptSlotsModified(g
3794      if (!pInstrument) return;      if (!pInstrument) return;
3795      const int iScriptSlots = pInstrument->ScriptSlotCount();      const int iScriptSlots = pInstrument->ScriptSlotCount();
3796    
3797      //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!      //NOTE: This is a big mess! Sometimes GTK requires m_TreeViewInstruments.get_model(), here we need m_refInstrumentsModelFilter->get_model(), otherwise accessing children below causes an error!
3798      //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      //Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewInstruments.get_model();
3799      Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_refInstrumentsModelFilter->get_model();
3800    
3801      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
3802          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
3803          if (row[m_Columns.m_col_instr] != pInstrument) continue;          if (row[m_InstrumentsModel.m_col_instr] != pInstrument) continue;
3804          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";          row[m_InstrumentsModel.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3805          row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);          row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
3806          break;          break;
3807      }      }
3808    
3809      // causes the sampler to reload the instrument with the new script      // causes the sampler to reload the instrument with the new script
3810      on_sel_change();      on_sel_change();
3811    
3812        // force script 'patch' variables editor ("Script" tab) to be refreshed
3813        dimreg_edit.scriptVars.setInstrument(pInstrument, true/*force update*/);
3814  }  }
3815    
3816  void MainWindow::assignScript(gig::Script* pScript) {  void MainWindow::assignScript(gig::Script* pScript) {
# Line 3423  void MainWindow::on_auto_restore_win_dim Line 3891  void MainWindow::on_auto_restore_win_dim
3891  #endif  #endif
3892  }  }
3893    
3894    void MainWindow::on_instr_double_click_opens_props() {
3895    #if USE_GLIB_ACTION
3896        bool active = false;
3897        m_actionInstrDoubleClickOpensProps->get_state(active);
3898        // for some reason toggle state does not change automatically
3899        active = !active;
3900        m_actionInstrDoubleClickOpensProps->change_state(active);
3901        Settings::singleton()->instrumentDoubleClickOpensProps = active;
3902    #else
3903        Gtk::CheckMenuItem* item =
3904            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/OpenInstrPropsByDoubleClick"));
3905        if (!item) {
3906            std::cerr << "/MenuBar/MenuView/OpenInstrPropsByDoubleClick == NULL\n";
3907            return;
3908        }
3909        Settings::singleton()->instrumentDoubleClickOpensProps = item->get_active();
3910    #endif
3911    }
3912    
3913  void MainWindow::on_save_with_temporary_file() {  void MainWindow::on_save_with_temporary_file() {
3914  #if USE_GLIB_ACTION  #if USE_GLIB_ACTION
3915      bool active = false;      bool active = false;
# Line 3497  bool MainWindow::on_button_release(Gdk:: Line 3984  bool MainWindow::on_button_release(Gdk::
3984  void MainWindow::on_button_release(GdkEventButton* button) {  void MainWindow::on_button_release(GdkEventButton* button) {
3985  #endif  #endif
3986      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
3987          show_instr_props();          if (Settings::singleton()->instrumentDoubleClickOpensProps)
3988                show_instr_props();
3989      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3990          // gig v2 files have no midi rules          // gig v2 files have no midi rules
3991          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
# Line 3529  void MainWindow::on_instrument_selection Line 4017  void MainWindow::on_instrument_selection
4017              find(children.begin(), children.end(), item);              find(children.begin(), children.end(), item);
4018          if (it != children.end()) {          if (it != children.end()) {
4019              int index = it - children.begin();              int index = it - children.begin();
4020              m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));  
4021                // convert index of model to index of visual presentation (i.e. if filtered)
4022                Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_child_path_to_path(Gtk::TreePath(ToString(index)));
4023    
4024                if (path)
4025                    m_TreeViewInstruments.get_selection()->select(path);
4026                else
4027                    m_TreeViewInstruments.get_selection()->unselect_all();
4028    
4029              m_RegionChooser.set_instrument(file->GetInstrument(index));              m_RegionChooser.set_instrument(file->GetInstrument(index));
4030          }          }
# Line 3537  void MainWindow::on_instrument_selection Line 4032  void MainWindow::on_instrument_selection
4032  }  }
4033  #endif  #endif
4034    
4035    void MainWindow::on_action_move_instr() {
4036        gig::Instrument* instr = get_instrument();
4037        if (!instr) return;
4038    
4039        int currentIndex = getIndexOf(instr);
4040    
4041        Gtk::Dialog dialog(_("Move Instrument"), true /*modal*/);
4042    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
4043        Gtk::Adjustment adjustment(
4044            currentIndex,
4045            0 /*min*/, file->CountInstruments() - 1 /*max*/
4046        );
4047        Gtk::SpinButton spinBox(adjustment);
4048    #else
4049        Gtk::SpinButton spinBox(
4050            Gtk::Adjustment::create(
4051                currentIndex,
4052                0 /*min*/, file->CountInstruments() - 1 /*max*/
4053            )
4054        );
4055    #endif
4056    #if USE_GTKMM_BOX
4057        dialog.get_content_area()->pack_start(spinBox);
4058    #else
4059        dialog.get_vbox()->pack_start(spinBox);
4060    #endif
4061    #if HAS_GTKMM_STOCK
4062        Gtk::Button* okButton = dialog.add_button(Gtk::Stock::OK, 0);
4063        dialog.add_button(Gtk::Stock::CANCEL, 1);
4064    #else
4065        Gtk::Button* okButton = dialog.add_button(_("_OK"), 0);
4066        dialog.add_button(_("_Cancel"), 1);
4067    #endif
4068        okButton->set_sensitive(false);
4069        // show the dialog at a reasonable screen position
4070        dialog.set_position(Gtk::WIN_POS_MOUSE);
4071        // only enable the 'OK' button if entered new index is not instrument's
4072        // current index already
4073        spinBox.signal_value_changed().connect([&]{
4074            okButton->set_sensitive( spinBox.get_value_as_int() != currentIndex );
4075        });
4076        // usability acceleration: if user hits enter key on the text entry field
4077        // then auto trigger the 'OK' button
4078        spinBox.signal_activate().connect([&]{
4079            if (okButton->get_sensitive())
4080                okButton->clicked();
4081        });
4082    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4083        dialog.show_all_children();
4084    #endif
4085        if (!dialog.run()) { // 'OK' selected ...
4086            int newIndex = spinBox.get_value_as_int();
4087            printf("MOVE TO %d\n", newIndex);
4088            gig::Instrument* dst = file->GetInstrument(newIndex);
4089            instr->MoveTo(dst);
4090            __refreshEntireGUI();
4091            select_instrument(instr);
4092        }
4093    }
4094    
4095  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
4096      if (!instrument) return;      if (!instrument) return;
4097    
4098      //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!      //NOTE: This is a big mess! Sometimes GTK requires m_refInstrumentsModelFilter->get_model(), here we need m_TreeViewInstruments.get_model(), otherwise treeview selection below causes an error!
4099      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewInstruments.get_model();
4100      //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();      //Glib::RefPtr<Gtk::TreeModel> model = m_refInstrumentsModelFilter->get_model();
4101    
4102      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
4103          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
4104          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_InstrumentsModel.m_col_instr] == instrument) {
4105              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
4106              show_intruments_tab();              show_intruments_tab();
4107              m_TreeView.get_selection()->unselect_all();              m_TreeViewInstruments.get_selection()->unselect_all();
4108                            
4109  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
4110              auto iterSel = model->children()[i].get_iter();              auto iterSel = model->children()[i].get_iter();
4111              m_TreeView.get_selection()->select(iterSel);              m_TreeViewInstruments.get_selection()->select(iterSel);
4112  #else  #else
4113              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeViewInstruments.get_selection()->select(model->children()[i]);
4114  #endif  #endif
4115              std::vector<Gtk::TreeModel::Path> rows =              std::vector<Gtk::TreeModel::Path> rows =
4116                  m_TreeView.get_selection()->get_selected_rows();                  m_TreeViewInstruments.get_selection()->get_selected_rows();
4117              if (!rows.empty())              if (!rows.empty())
4118                  m_TreeView.scroll_to_row(rows[0]);                  m_TreeViewInstruments.scroll_to_row(rows[0]);
4119              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
4120          }          }
4121      }      }
# Line 3571  bool MainWindow::select_dimension_region Line 4126  bool MainWindow::select_dimension_region
4126      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
4127      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
4128    
4129      //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!      //NOTE: This is a big mess! Sometimes GTK requires m_refInstrumentsModelFilter->get_model(), here we need m_TreeViewInstruments.get_model(), otherwise treeview selection below causes an error!
4130      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewInstruments.get_model();
4131      //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();      //Glib::RefPtr<Gtk::TreeModel> model = m_refInstrumentsModelFilter->get_model();
4132    
4133      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
4134          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
4135          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_InstrumentsModel.m_col_instr] == pInstrument) {
4136              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
4137              show_intruments_tab();              show_intruments_tab();
4138              m_TreeView.get_selection()->unselect_all();              m_TreeViewInstruments.get_selection()->unselect_all();
4139  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
4140              auto iterSel = model->children()[i].get_iter();              auto iterSel = model->children()[i].get_iter();
4141              m_TreeView.get_selection()->select(iterSel);              m_TreeViewInstruments.get_selection()->select(iterSel);
4142  #else  #else
4143              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeViewInstruments.get_selection()->select(model->children()[i]);
4144  #endif  #endif
4145              std::vector<Gtk::TreeModel::Path> rows =              std::vector<Gtk::TreeModel::Path> rows =
4146                  m_TreeView.get_selection()->get_selected_rows();                  m_TreeViewInstruments.get_selection()->get_selected_rows();
4147              if (!rows.empty())              if (!rows.empty())
4148                  m_TreeView.scroll_to_row(rows[0]);                  m_TreeViewInstruments.scroll_to_row(rows[0]);
4149              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
4150    
4151              // select respective region in the region selector              // select respective region in the region selector
# Line 3875  void MainWindow::add_instrument(gig::Ins Line 4430  void MainWindow::add_instrument(gig::Ins
4430    
4431      // update instrument tree view      // update instrument tree view
4432      instrument_name_connection.block();      instrument_name_connection.block();
4433      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refInstrumentsTreeModel->append();
4434      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
4435      const int index = m_refTreeModel->children().size() - 1;      const int index = m_refInstrumentsTreeModel->children().size() - 1;
4436      rowInstr[m_Columns.m_col_nr] = index;      const int iScriptSlots = instrument->ScriptSlotCount();
4437      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_InstrumentsModel.m_col_nr] = index;
4438      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_InstrumentsModel.m_col_name] = name;
4439      rowInstr[m_Columns.m_col_scripts] = "";      rowInstr[m_InstrumentsModel.m_col_instr] = instrument;
4440      rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);      rowInstr[m_InstrumentsModel.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
4441        rowInstr[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
4442      instrument_name_connection.unblock();      instrument_name_connection.unblock();
4443    
4444  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
# Line 3908  void MainWindow::on_action_duplicate_ins Line 4464  void MainWindow::on_action_duplicate_ins
4464    
4465      // retrieve the currently selected instrument      // retrieve the currently selected instrument
4466      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
4467      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.get_selection();
4468      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
4469      for (int r = 0; r < rows.size(); ++r) {      for (int r = 0; r < rows.size(); ++r) {
4470          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);          // convert index of visual selection (i.e. if filtered) to index of model
4471            Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[r]);
4472            Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
4473          if (it) {          if (it) {
4474              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
4475              gig::Instrument* instrOrig = row[m_Columns.m_col_instr];              gig::Instrument* instrOrig = row[m_InstrumentsModel.m_col_instr];
4476              if (instrOrig) {              if (instrOrig) {
4477                  // duplicate the orginal instrument                  // duplicate the orginal instrument
4478                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
# Line 3941  void MainWindow::on_action_remove_instru Line 4499  void MainWindow::on_action_remove_instru
4499          return;          return;
4500      }      }
4501    
4502      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.get_selection();
4503      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();      std::vector<Gtk::TreeModel::Path> rowsVisual = sel->get_selected_rows();
4504    
4505        // convert indeces of visual selection (i.e. if filtered) to indeces of model
4506        std::vector<Gtk::TreeModel::Path> rows;
4507        for (int rv = 0; rv < rowsVisual.size(); ++rv) {
4508            Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rowsVisual[rv]);
4509            if (path)
4510                rows.push_back(path);
4511        }
4512    
4513      for (int r = rows.size() - 1; r >= 0; --r) {      for (int r = rows.size() - 1; r >= 0; --r) {
4514          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);          Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[r]);
4515          if (!it) continue;          if (!it) continue;
4516          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
4517          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_InstrumentsModel.m_col_instr];
4518          try {          try {
4519              Gtk::TreePath path(it);              Gtk::TreePath path(it);
4520              int index = path[0];              int index = path[0];
# Line 3961  void MainWindow::on_action_remove_instru Line 4528  void MainWindow::on_action_remove_instru
4528  #endif  #endif
4529    
4530              // remove row from instruments tree view              // remove row from instruments tree view
4531              m_refTreeModel->erase(it);              m_refInstrumentsTreeModel->erase(it);
4532              // update "Nr" column of all instrument rows              // update "Nr" column of all instrument rows
4533              {              {
4534                  int index = 0;                  int index = 0;
4535                  for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();                  for (Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->children().begin();
4536                       it != m_refTreeModel->children().end(); ++it, ++index)                       it != m_refInstrumentsTreeModel->children().end(); ++it, ++index)
4537                  {                  {
4538                      Gtk::TreeModel::Row row = *it;                      Gtk::TreeModel::Row row = *it;
4539                      gig::Instrument* instrument = row[m_Columns.m_col_instr];                      gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
4540                      row[m_Columns.m_col_nr] = index;                      row[m_InstrumentsModel.m_col_nr] = index;
4541                      row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);                      row[m_InstrumentsModel.m_col_tooltip] = scriptTooltipFor(instrument, index);
4542                  }                  }
4543              }              }
4544    
4545  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
4546              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
4547              // automatically)              // automatically)
4548              if (!m_refTreeModel->children().empty()) {              if (!m_refInstrumentsTreeModel->children().empty()) {
4549                  if (index == m_refTreeModel->children().size()) {                  if (index == m_refInstrumentsTreeModel->children().size()) {
4550                      index--;                      index--;
4551                  }                  }
4552                  m_TreeView.get_selection()->select(                  m_TreeViewInstruments.get_selection()->select(
4553                      Gtk::TreePath(ToString(index)));                      Gtk::TreePath(ToString(index)));
4554              }              }
4555  #endif  #endif
# Line 4001  void MainWindow::on_action_remove_instru Line 4568  void MainWindow::on_action_remove_instru
4568  }  }
4569    
4570  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
4571      //TODO: show a dialog where the selected sample's properties can be edited      show_sample_props();
     Gtk::MessageDialog msg(  
         *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO  
     );  
     msg.run();  
4572  }  }
4573    
4574  void MainWindow::on_action_add_script_group() {  void MainWindow::on_action_add_script_group() {
# Line 4068  void MainWindow::on_action_edit_script() Line 4631  void MainWindow::on_action_edit_script()
4631      if (!it) return;      if (!it) return;
4632      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
4633      gig::Script* script = row[m_ScriptsModel.m_col_script];      gig::Script* script = row[m_ScriptsModel.m_col_script];
4634      if (!script) return;      editScript(script);
4635    }
4636    
4637    void MainWindow::editScript(gig::Script* script) {
4638        if (!script) return;
4639      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
4640      editor->signal_script_to_be_changed.connect(      editor->signal_script_to_be_changed.connect(
4641          signal_script_to_be_changed.make_slot()          signal_script_to_be_changed.make_slot()
4642      );      );
4643      editor->signal_script_changed.connect(      editor->signal_script_changed.connect([this](gig::Script* script) {
4644          signal_script_changed.make_slot()          // signal to sampler (which will reload the script due to this)
4645      );          signal_script_changed.emit(script);
4646            // force script 'patch' variables editor ("Script" tab) to be refreshed
4647            gig::Instrument* instr = get_instrument();
4648            dimreg_edit.scriptVars.setInstrument(instr, true/*force update*/);
4649        });
4650      editor->setScript(script);      editor->setScript(script);
4651      //editor->reparent(*this);      //editor->reparent(*this);
4652      editor->show();      editor->show();
# Line 4534  void MainWindow::on_action_remove_unused Line 5104  void MainWindow::on_action_remove_unused
5104      if (!file) return;      if (!file) return;
5105    
5106      // collect all samples that are not referenced by any instrument      // collect all samples that are not referenced by any instrument
5107      std::list<gig::Sample*> lsamples;      std::list<gig::Sample*> lsamples = unusedSamples(file);
     for (int iSample = 0; file->GetSample(iSample); ++iSample) {  
         gig::Sample* sample = file->GetSample(iSample);  
         bool isUsed = false;  
         for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;  
                               instrument = file->GetNextInstrument())  
         {  
             for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;  
                               rgn = instrument->GetNextRegion())  
             {  
                 for (int i = 0; i < 256; ++i) {  
                     if (!rgn->pDimensionRegions[i]) continue;  
                     if (rgn->pDimensionRegions[i]->pSample != sample) continue;  
                     isUsed = true;  
                     goto endOfRefSearch;  
                 }  
             }  
         }  
         endOfRefSearch:  
         if (!isUsed) lsamples.push_back(sample);  
     }  
   
5108      if (lsamples.empty()) return;      if (lsamples.empty()) return;
5109    
5110      // notify everybody that we're going to remove these samples      // notify everybody that we're going to remove these samples
# Line 4631  void MainWindow::on_instruments_treeview Line 5180  void MainWindow::on_instruments_treeview
5180      // get selected source instrument      // get selected source instrument
5181      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
5182      {      {
5183          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.get_selection();
5184          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
5185          if (!rows.empty()) {          if (!rows.empty()) {
5186              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);              // convert index of visual selection (i.e. if filtered) to index of model
5187                Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[0]);
5188                Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
5189              if (it) {              if (it) {
5190                  Gtk::TreeModel::Row row = *it;                  Gtk::TreeModel::Row row = *it;
5191                  src = row[m_Columns.m_col_instr];                  src = row[m_InstrumentsModel.m_col_instr];
5192              }              }
5193          }          }
5194      }      }
# Line 4659  void MainWindow::on_instruments_treeview Line 5210  void MainWindow::on_instruments_treeview
5210      gig::Instrument* dst = NULL;      gig::Instrument* dst = NULL;
5211      {      {
5212          Gtk::TreeModel::Path path;          Gtk::TreeModel::Path path;
5213          const bool found = m_TreeView.get_path_at_pos(x, y, path);          const bool found = m_TreeViewInstruments.get_path_at_pos(x, y, path);
5214          if (!found) return;          if (!found) return;
5215    
5216          Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);          // convert index of visual selection (i.e. if filtered) to index of model
5217            path = m_refInstrumentsModelFilter->convert_path_to_child_path(path);
5218            if (!path) return;
5219    
5220            Gtk::TreeModel::iterator iter = m_refInstrumentsTreeModel->get_iter(path);
5221          if (!iter) return;          if (!iter) return;
5222          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
5223          dst = row[m_Columns.m_col_instr];          dst = row[m_InstrumentsModel.m_col_instr];
5224      }      }
5225      if (!dst) return;      if (!dst) return;
5226    
# Line 4804  void MainWindow::sample_name_changed(con Line 5359  void MainWindow::sample_name_changed(con
5359              file_changed();              file_changed();
5360          }          }
5361      }      }
5362        // change name in the sample properties window
5363        if (sampleProps.get_sample() == sample && sample) {
5364            sampleProps.set_sample(sample);
5365        }
5366  }  }
5367    
5368  void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
# Line 4836  void MainWindow::script_double_clicked(c Line 5395  void MainWindow::script_double_clicked(c
5395      if (!iter) return;      if (!iter) return;
5396      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
5397      gig::Script* script = row[m_ScriptsModel.m_col_script];      gig::Script* script = row[m_ScriptsModel.m_col_script];
5398      if (!script) return;      editScript(script);
   
     ScriptEditor* editor = new ScriptEditor;  
     editor->signal_script_to_be_changed.connect(  
         signal_script_to_be_changed.make_slot()  
     );  
     editor->signal_script_changed.connect(  
         signal_script_changed.make_slot()  
     );  
     editor->setScript(script);  
     //editor->reparent(*this);  
     editor->show();  
5399  }  }
5400    
5401  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
5402                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
5403      if (!iter) return;      if (!iter) return;
5404      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
5405      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_InstrumentsModel.m_col_name];
5406    
5407  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
5408      // change name in instrument menu      // change name in instrument menu
# Line 4872  void MainWindow::instrument_name_changed Line 5420  void MainWindow::instrument_name_changed
5420  #endif  #endif
5421    
5422      // change name in gig      // change name in gig
5423      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_InstrumentsModel.m_col_instr];
5424      gig::String gigname(gig_from_utf8(name));      gig::String gigname(gig_from_utf8(name));
5425      if (instrument && instrument->pInfo->Name != gigname) {      if (instrument && instrument->pInfo->Name != gigname) {
5426          instrument->pInfo->Name = gigname;          instrument->pInfo->Name = gigname;
# Line 4900  bool MainWindow::instrument_row_visible( Line 5448  bool MainWindow::instrument_row_visible(
5448  #else  #else
5449      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
5450  #endif  #endif
5451      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_InstrumentsModel.m_col_name];
5452      name = name.lowercase();      name = name.lowercase();
5453    
5454      std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);      std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
# Line 4918  void MainWindow::on_action_combine_instr Line 5466  void MainWindow::on_action_combine_instr
5466      // list view as pre-selection      // list view as pre-selection
5467      std::set<int> indeces;      std::set<int> indeces;
5468      {      {
5469          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.get_selection();
5470          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
5471          for (int r = 0; r < rows.size(); ++r) {          for (int r = 0; r < rows.size(); ++r) {
5472              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);              // convert index of visual selection (i.e. if filtered) to index of model
5473                Gtk::TreeModel::Path path = m_refInstrumentsModelFilter->convert_path_to_child_path(rows[r]);
5474                Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(path);
5475              if (it) {              if (it) {
5476                  Gtk::TreeModel::Row row = *it;                  Gtk::TreeModel::Row row = *it;
5477                  int index = row[m_Columns.m_col_nr];                  int index = row[m_InstrumentsModel.m_col_nr];
5478                  indeces.insert(index);                  indeces.insert(index);
5479              }              }
5480          }          }

Legend:
Removed from v.3635  
changed lines
  Added in v.3918

  ViewVC Help
Powered by ViewVC