/[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 2967 by schoenebeck, Mon Jul 18 11:22:38 2016 UTC revision 3106 by schoenebeck, Sat Feb 11 17:04:48 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2016 Andreas Persson   * Copyright (C) 2006-2017 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 57  Line 57 
57  #include "ReferencesView.h"  #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    #include "gfx/builtinpix.h"
61    
62  MainWindow::MainWindow() :  MainWindow::MainWindow() :
63      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
64      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
65      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
66      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
67      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
68        labelNoSample(_(" No Sample")),
69        labelMissingSample(_(" Missing some Sample(s)")),
70        labelLooped(_(" Looped")),
71        labelSomeLoops(_(" Some Loop(s)"))
72  {  {
73        loadBuiltInPix();
74    
75  //    set_border_width(5);  //    set_border_width(5);
76  //    set_default_size(400, 200);  //    set_default_size(400, 200);
77    
   
78      add(m_VBox);      add(m_VBox);
79    
80      // Handle selection      // Handle selection
# Line 103  MainWindow::MainWindow() : Line 108  MainWindow::MainWindow() :
108      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
109      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
110      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
111        {
112            imageNoSample.set(redDot);
113            imageNoSample.set_alignment(Gtk::ALIGN_RIGHT);
114            labelNoSample.set_alignment(Gtk::ALIGN_LEFT);
115            legend_hbox.add(imageNoSample);
116            legend_hbox.add(labelNoSample);
117    
118            imageMissingSample.set(yellowDot);
119            imageMissingSample.set_alignment(Gtk::ALIGN_RIGHT);
120            labelMissingSample.set_alignment(Gtk::ALIGN_LEFT);
121            legend_hbox.add(imageMissingSample);
122            legend_hbox.add(labelMissingSample);
123    
124            imageLooped.set(blackLoop);
125            imageLooped.set_alignment(Gtk::ALIGN_RIGHT);
126            labelLooped.set_alignment(Gtk::ALIGN_LEFT);
127            legend_hbox.add(imageLooped);
128            legend_hbox.add(labelLooped);
129    
130            imageSomeLoops.set(grayLoop);
131            imageSomeLoops.set_alignment(Gtk::ALIGN_RIGHT);
132            labelSomeLoops.set_alignment(Gtk::ALIGN_LEFT);
133            legend_hbox.add(imageSomeLoops);
134            legend_hbox.add(labelSomeLoops);
135    
136            legend_hbox.show_all_children();
137        }
138        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
139      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
140    
141      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 521  MainWindow::MainWindow() : Line 554  MainWindow::MainWindow() :
554      // Create the Tree model:      // Create the Tree model:
555      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
556      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
557        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
558      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
559      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
560          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
561      );      );
562    
563      // Add the TreeView's view columns:      // Add the TreeView's view columns:
564      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
565      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
566        m_TreeView.set_headers_visible(true);
567            
568      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
569      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 551  MainWindow::MainWindow() : Line 586  MainWindow::MainWindow() :
586      // create samples treeview (including its data model)      // create samples treeview (including its data model)
587      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
588      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
589        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
590      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
591      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
592      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 728  void MainWindow::region_changed() Line 764  void MainWindow::region_changed()
764  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
765  {  {
766      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
767      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
768          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
769        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
770      if (it) {      if (it) {
771          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
772          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 772  void MainWindow::update_dimregs() Line 809  void MainWindow::update_dimregs()
809              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
810          }          }
811      }      }
812    
813        m_DimRegionChooser.setModifyAllRegions(all_regions);
814        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
815        m_DimRegionChooser.setModifyBothChannels(stereo);
816  }  }
817    
818  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 789  void MainWindow::dimreg_changed() Line 830  void MainWindow::dimreg_changed()
830  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
831  {  {
832      // select item in instrument menu      // select item in instrument menu
833      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
834      if (it) {      if (!rows.empty()) {
835          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
836          int index = path[0];          if (it) {
837          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
838              instrument_menu->get_children();              int index = path[0];
839          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
840                    instrument_menu->get_children();
841                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
842            }
843      }      }
844    
845      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 820  void Loader::progress_callback(float fra Line 864  void Loader::progress_callback(float fra
864      progress_dispatcher();      progress_dispatcher();
865  }  }
866    
867    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
868    // make sure stack is 16-byte aligned for SSE instructions
869    __attribute__((force_align_arg_pointer))
870    #endif
871  void Loader::thread_function()  void Loader::thread_function()
872  {  {
873      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 899  void Saver::progress_callback(float frac Line 947  void Saver::progress_callback(float frac
947      progress_dispatcher.emit();      progress_dispatcher.emit();
948  }  }
949    
950    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
951    // make sure stack is 16-byte aligned for SSE instructions
952    __attribute__((force_align_arg_pointer))
953    #endif
954  void Saver::thread_function()  void Saver::thread_function()
955  {  {
956      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 923  void Saver::thread_function() Line 975  void Saver::thread_function()
975                  String tmpname = filename + ".TMP";                  String tmpname = filename + ".TMP";
976                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
977                  #if defined(WIN32)                  #if defined(WIN32)
978                  if (!DeleteFile(filename.c_str()) {                  if (!DeleteFile(filename.c_str())) {
979                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
980                  }                  }
981                  #else // POSIX ...                  #else // POSIX ...
# Line 1512  void MainWindow::on_action_help_about() Line 1564  void MainWindow::on_action_help_about()
1564      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1565  #endif  #endif
1566      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1567      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1568      const std::string sComment =      const std::string sComment =
1569          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1570          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1807  void MainWindow::load_gig(gig::File* gig Line 1859  void MainWindow::load_gig(gig::File* gig
1859      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1860    
1861      instrument_name_connection.block();      instrument_name_connection.block();
1862        int index = 0;
1863      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1864           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1865          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1866    
1867          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1868          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1869            row[m_Columns.m_col_nr] = index;
1870          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1871          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1872    
# Line 1885  bool MainWindow::instr_props_set_instrum Line 1939  bool MainWindow::instr_props_set_instrum
1939  {  {
1940      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
1941    
1942      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1943          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
1944            instrumentProps.hide();
1945            return false;
1946        }
1947        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1948      if (it) {      if (it) {
1949          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1950          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1939  void MainWindow::show_midi_rules() Line 1997  void MainWindow::show_midi_rules()
1997  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
1998      if (!file) return;      if (!file) return;
1999      // get selected instrument      // get selected instrument
2000      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2001      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2002        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2003      if (!it) return;      if (!it) return;
2004      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2005      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 2060  void MainWindow::select_instrument(gig:: Line 2119  void MainWindow::select_instrument(gig::
2119          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2120              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2121              show_intruments_tab();              show_intruments_tab();
2122                m_TreeView.get_selection()->unselect_all();
2123              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2124              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2125                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2126              );              if (!rows.empty())
2127              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2128              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2129          }          }
2130      }      }
# Line 2081  bool MainWindow::select_dimension_region Line 2141  bool MainWindow::select_dimension_region
2141          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2142              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2143              show_intruments_tab();              show_intruments_tab();
2144                m_TreeView.get_selection()->unselect_all();
2145              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2146              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2147                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2148              );              if (!rows.empty())
2149              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2150              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2151    
2152              // select respective region in the region selector              // select respective region in the region selector
# Line 2111  void MainWindow::select_sample(gig::Samp Line 2172  void MainWindow::select_sample(gig::Samp
2172              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2173              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2174                  show_samples_tab();                  show_samples_tab();
2175                    m_TreeViewSamples.get_selection()->unselect_all();
2176                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2177                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2178                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2179                  );                  if (rows.empty()) return;
2180                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2181                  return;                  return;
2182              }              }
2183          }          }
# Line 2124  void MainWindow::select_sample(gig::Samp Line 2186  void MainWindow::select_sample(gig::Samp
2186    
2187  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2188      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2189            // by default if Ctrl keys is pressed down, then a mouse right-click
2190            // does not select the respective row, so we must assure this
2191            // programmatically ...
2192            /*{
2193                Gtk::TreeModel::Path path;
2194                Gtk::TreeViewColumn* pColumn = NULL;
2195                int cellX, cellY;
2196                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2197                    (int)button->x, (int)button->y,
2198                    path, pColumn, cellX, cellY
2199                );
2200                if (bSuccess) {
2201                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2202                        printf("not selected !!!\n");
2203                        m_TreeViewSamples.get_selection()->select(path);
2204                    }
2205                }
2206            }*/
2207    
2208          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2209              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2210          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2211          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2212          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2213          bool group_selected  = false;          const int n = rows.size();
2214          bool sample_selected = false;          int nGroups  = 0;
2215          if (it) {          int nSamples = 0;
2216            for (int r = 0; r < n; ++r) {
2217                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2218                if (!it) continue;
2219              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2220              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2221              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2222          }          }
2223            
               
2224          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2225              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2226          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2227              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2228          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2229              set_sensitive(file);              set_sensitive(file);
2230          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2231              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2232          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2233              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2234          // show sample popup          // show sample popup
2235          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2236    
2237          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2238              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2239          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2240              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2241          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2242              set_sensitive(file);              set_sensitive(file);
2243          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2244              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2245          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2246              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2247      }      }
2248  }  }
2249    
# Line 2239  void MainWindow::add_instrument(gig::Ins Line 2322  void MainWindow::add_instrument(gig::Ins
2322      instrument_name_connection.block();      instrument_name_connection.block();
2323      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2324      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2325        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2326      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2327      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2328      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2267  void MainWindow::on_action_duplicate_ins Line 2351  void MainWindow::on_action_duplicate_ins
2351      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2352      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2353      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2354      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2355      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2356      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2357      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2358      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2359                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2360      // duplicate the orginal instrument              if (instrOrig) {
2361      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2362      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2363          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2364          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2365                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2366    
2367      add_instrument(instrNew);                  add_instrument(instrNew);
2368                }
2369            }
2370        }
2371  }  }
2372    
2373  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2296  void MainWindow::on_action_remove_instru Line 2384  void MainWindow::on_action_remove_instru
2384      }      }
2385    
2386      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2387      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2388      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2389            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2390            if (!it) continue;
2391          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2392          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2393          try {          try {
# Line 2312  void MainWindow::on_action_remove_instru Line 2402  void MainWindow::on_action_remove_instru
2402    
2403              // remove row from instruments tree view              // remove row from instruments tree view
2404              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2405                // update "Nr" column of all instrument rows
2406                {
2407                    int index = 0;
2408                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2409                         it != m_refTreeModel->children().end(); ++it, ++index)
2410                    {
2411                        Gtk::TreeModel::Row row = *it;
2412                        row[m_Columns.m_col_nr] = index;
2413                    }
2414                }
2415    
2416  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2417              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2493  void MainWindow::add_or_replace_sample(b Line 2593  void MainWindow::add_or_replace_sample(b
2593    
2594      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2595      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2596      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2597        if (rows.empty()) return;
2598        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2599      if (!it) return;      if (!it) return;
2600      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2601      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2776  void MainWindow::on_action_replace_all_s Line 2878  void MainWindow::on_action_replace_all_s
2878  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2879      if (!file) return;      if (!file) return;
2880      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2881      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2882      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2883            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2884            if (!it) continue;
2885          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2886          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2887          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2956  void MainWindow::on_instruments_treeview Line 3060  void MainWindow::on_instruments_treeview
3060      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3061      {      {
3062          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3063          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3064          if (it) {          if (!rows.empty()) {
3065              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3066              src = row[m_Columns.m_col_instr];              if (it) {
3067                    Gtk::TreeModel::Row row = *it;
3068                    src = row[m_Columns.m_col_instr];
3069                }
3070          }          }
3071      }      }
3072      if (!src) return;      if (!src) return;
# Line 3014  void MainWindow::on_sample_treeview_drag Line 3121  void MainWindow::on_sample_treeview_drag
3121      // get selected sample      // get selected sample
3122      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3123      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3124      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3125      if (it) {      if (!rows.empty()) {
3126          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3127          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3128                Gtk::TreeModel::Row row = *it;
3129                sample = row[m_SamplesModel.m_col_sample];
3130            }
3131      }      }
3132      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3133      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,      selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&sample,
# Line 3216  void MainWindow::on_action_combine_instr Line 3326  void MainWindow::on_action_combine_instr
3326    
3327  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3328      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3329      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3330        if (rows.empty()) return;
3331        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3332      if (!it) return;      if (!it) return;
3333      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3334      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];

Legend:
Removed from v.2967  
changed lines
  Added in v.3106

  ViewVC Help
Powered by ViewVC