/[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 2918 by schoenebeck, Wed May 18 10:10:25 2016 UTC revision 3109 by schoenebeck, Sun Feb 12 16:35:03 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        labelLegend(_("Legend:")),
69        labelNoSample(_(" No Sample")),
70        labelMissingSample(_(" Missing some Sample(s)")),
71        labelLooped(_(" Looped")),
72        labelSomeLoops(_(" Some Loop(s)"))
73  {  {
74        loadBuiltInPix();
75    
76  //    set_border_width(5);  //    set_border_width(5);
77  //    set_default_size(400, 200);  //    set_default_size(400, 200);
78    
   
79      add(m_VBox);      add(m_VBox);
80    
81      // Handle selection      // Handle selection
# Line 103  MainWindow::MainWindow() : Line 109  MainWindow::MainWindow() :
109      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
110      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
111      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
112        {
113            legend_hbox.add(labelLegend);
114    
115            imageNoSample.set(redDot);
116            imageNoSample.set_alignment(Gtk::ALIGN_END);
117            labelNoSample.set_alignment(Gtk::ALIGN_START);
118            legend_hbox.add(imageNoSample);
119            legend_hbox.add(labelNoSample);
120    
121            imageMissingSample.set(yellowDot);
122            imageMissingSample.set_alignment(Gtk::ALIGN_END);
123            labelMissingSample.set_alignment(Gtk::ALIGN_START);
124            legend_hbox.add(imageMissingSample);
125            legend_hbox.add(labelMissingSample);
126    
127            imageLooped.set(blackLoop);
128            imageLooped.set_alignment(Gtk::ALIGN_END);
129            labelLooped.set_alignment(Gtk::ALIGN_START);
130            legend_hbox.add(imageLooped);
131            legend_hbox.add(labelLooped);
132    
133            imageSomeLoops.set(grayLoop);
134            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
135            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
136            legend_hbox.add(imageSomeLoops);
137            legend_hbox.add(labelSomeLoops);
138    
139            legend_hbox.show_all_children();
140        }
141        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
142      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
143    
144      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 200  MainWindow::MainWindow() : Line 236  MainWindow::MainWindow() :
236                       sigc::mem_fun(                       sigc::mem_fun(
237                           *this, &MainWindow::on_auto_restore_win_dim));                           *this, &MainWindow::on_auto_restore_win_dim));
238    
239        toggle_action =
240            Gtk::ToggleAction::create("SaveWithTemporaryFile", _("Save with _temporary file"));
241        toggle_action->set_active(Settings::singleton()->saveWithTemporaryFile);
242        actionGroup->add(toggle_action,
243                         sigc::mem_fun(
244                             *this, &MainWindow::on_save_with_temporary_file));
245    
246      actionGroup->add(      actionGroup->add(
247          Gtk::Action::create("RefreshAll", _("_Refresh All")),          Gtk::Action::create("RefreshAll", _("_Refresh All")),
248          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)          sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
# Line 384  MainWindow::MainWindow() : Line 427  MainWindow::MainWindow() :
427          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
428          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
429          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"          "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
430            "      <menuitem action='SaveWithTemporaryFile'/>"
431          "    </menu>"          "    </menu>"
432          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
433          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 513  MainWindow::MainWindow() : Line 557  MainWindow::MainWindow() :
557      // Create the Tree model:      // Create the Tree model:
558      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
559      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
560        m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
561      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."));
562      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
563          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
564      );      );
565    
566      // Add the TreeView's view columns:      // Add the TreeView's view columns:
567      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
568      m_TreeView.set_headers_visible(false);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
569        m_TreeView.set_headers_visible(true);
570            
571      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
572      // the sequence of instruments within the gig file      // the sequence of instruments within the gig file
# Line 543  MainWindow::MainWindow() : Line 589  MainWindow::MainWindow() :
589      // create samples treeview (including its data model)      // create samples treeview (including its data model)
590      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
591      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
592        m_TreeViewSamples.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
593      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."));
594      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
595      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
# Line 720  void MainWindow::region_changed() Line 767  void MainWindow::region_changed()
767  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
768  {  {
769      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
770      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
771          m_TreeView.get_selection()->get_selected();      if (rows.empty()) return NULL;
772        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
773      if (it) {      if (it) {
774          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
775          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 764  void MainWindow::update_dimregs() Line 812  void MainWindow::update_dimregs()
812              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
813          }          }
814      }      }
815    
816        m_DimRegionChooser.setModifyAllRegions(all_regions);
817        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
818        m_DimRegionChooser.setModifyBothChannels(stereo);
819  }  }
820    
821  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 781  void MainWindow::dimreg_changed() Line 833  void MainWindow::dimreg_changed()
833  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
834  {  {
835      // select item in instrument menu      // select item in instrument menu
836      Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
837      if (it) {      if (!rows.empty()) {
838          Gtk::TreePath path(it);          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
839          int index = path[0];          if (it) {
840          const std::vector<Gtk::Widget*> children =              Gtk::TreePath path(it);
841              instrument_menu->get_children();              int index = path[0];
842          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();              const std::vector<Gtk::Widget*> children =
843                    instrument_menu->get_children();
844                static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
845            }
846      }      }
847    
848      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
# Line 812  void Loader::progress_callback(float fra Line 867  void Loader::progress_callback(float fra
867      progress_dispatcher();      progress_dispatcher();
868  }  }
869    
870    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
871    // make sure stack is 16-byte aligned for SSE instructions
872    __attribute__((force_align_arg_pointer))
873    #endif
874  void Loader::thread_function()  void Loader::thread_function()
875  {  {
876      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 891  void Saver::progress_callback(float frac Line 950  void Saver::progress_callback(float frac
950      progress_dispatcher.emit();      progress_dispatcher.emit();
951  }  }
952    
953    #if defined(WIN32) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2))
954    // make sure stack is 16-byte aligned for SSE instructions
955    __attribute__((force_align_arg_pointer))
956    #endif
957  void Saver::thread_function()  void Saver::thread_function()
958  {  {
959      printf("thread_function self=%p\n",      printf("thread_function self=%p\n",
# Line 903  void Saver::thread_function() Line 966  void Saver::thread_function()
966    
967          // if no filename was provided, that means "save", if filename was provided means "save as"          // if no filename was provided, that means "save", if filename was provided means "save as"
968          if (filename.empty()) {          if (filename.empty()) {
969              gig->Save(&progress);              if (!Settings::singleton()->saveWithTemporaryFile) {
970                    // save directly over the existing .gig file
971                    // (requires less disk space than solution below
972                    // but may be slower)
973                    gig->Save(&progress);
974                } else {
975                    // save the file as separate temporary file first,
976                    // then move the saved file over the old file
977                    // (may result in performance speedup during save)
978                    String tmpname = filename + ".TMP";
979                    gig->Save(tmpname, &progress);
980                    #if defined(WIN32)
981                    if (!DeleteFile(filename.c_str())) {
982                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file).");
983                    }
984                    #else // POSIX ...
985                    if (unlink(filename.c_str())) {
986                        throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));
987                    }
988                    #endif
989                    if (rename(tmpname.c_str(), filename.c_str())) {
990                        #if defined(WIN32)
991                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
992                        #else
993                        throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));
994                        #endif
995                    }
996                }
997          } else {          } else {
998              gig->Save(filename, &progress);              gig->Save(filename, &progress);
999          }          }
# Line 1477  void MainWindow::on_action_help_about() Line 1567  void MainWindow::on_action_help_about()
1567      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1568  #endif  #endif
1569      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1570      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1571      const std::string sComment =      const std::string sComment =
1572          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1573          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1772  void MainWindow::load_gig(gig::File* gig Line 1862  void MainWindow::load_gig(gig::File* gig
1862      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1863    
1864      instrument_name_connection.block();      instrument_name_connection.block();
1865        int index = 0;
1866      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1867           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument(), ++index) {
1868          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1869    
1870          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1871          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1872            row[m_Columns.m_col_nr] = index;
1873          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
1874          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1875    
# Line 1850  bool MainWindow::instr_props_set_instrum Line 1942  bool MainWindow::instr_props_set_instrum
1942  {  {
1943      instrumentProps.signal_name_changed().clear();      instrumentProps.signal_name_changed().clear();
1944    
1945      Gtk::TreeModel::const_iterator it =      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
1946          m_TreeView.get_selection()->get_selected();      if (rows.empty()) {
1947            instrumentProps.hide();
1948            return false;
1949        }
1950        Gtk::TreeModel::const_iterator it = m_refTreeModel->get_iter(rows[0]);
1951      if (it) {      if (it) {
1952          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1953          gig::Instrument* instrument = row[m_Columns.m_col_instr];          gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1904  void MainWindow::show_midi_rules() Line 2000  void MainWindow::show_midi_rules()
2000  void MainWindow::show_script_slots() {  void MainWindow::show_script_slots() {
2001      if (!file) return;      if (!file) return;
2002      // get selected instrument      // get selected instrument
2003      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      std::vector<Gtk::TreeModel::Path> rows = m_TreeView.get_selection()->get_selected_rows();
2004      Gtk::TreeModel::iterator it = sel->get_selected();      if (rows.empty()) return;
2005        Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
2006      if (!it) return;      if (!it) return;
2007      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2008      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
# Line 1942  void MainWindow::on_auto_restore_win_dim Line 2039  void MainWindow::on_auto_restore_win_dim
2039      Settings::singleton()->autoRestoreWindowDimension = item->get_active();      Settings::singleton()->autoRestoreWindowDimension = item->get_active();
2040  }  }
2041    
2042    void MainWindow::on_save_with_temporary_file() {
2043        Gtk::CheckMenuItem* item =
2044            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuSettings/SaveWithTemporaryFile"));
2045        if (!item) {
2046            std::cerr << "/MenuBar/MenuSettings/SaveWithTemporaryFile == NULL\n";
2047            return;
2048        }
2049        Settings::singleton()->saveWithTemporaryFile = item->get_active();
2050    }
2051    
2052  bool MainWindow::is_copy_samples_unity_note_enabled() const {  bool MainWindow::is_copy_samples_unity_note_enabled() const {
2053      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
2054          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
# Line 2015  void MainWindow::select_instrument(gig:: Line 2122  void MainWindow::select_instrument(gig::
2122          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
2123              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2124              show_intruments_tab();              show_intruments_tab();
2125                m_TreeView.get_selection()->unselect_all();
2126              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2127              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2128                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2129              );              if (!rows.empty())
2130              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2131              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2132          }          }
2133      }      }
# Line 2036  bool MainWindow::select_dimension_region Line 2144  bool MainWindow::select_dimension_region
2144          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
2145              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
2146              show_intruments_tab();              show_intruments_tab();
2147                m_TreeView.get_selection()->unselect_all();
2148              m_TreeView.get_selection()->select(model->children()[i]);              m_TreeView.get_selection()->select(model->children()[i]);
2149              Gtk::TreePath path(              std::vector<Gtk::TreeModel::Path> rows =
2150                  m_TreeView.get_selection()->get_selected()                  m_TreeView.get_selection()->get_selected_rows();
2151              );              if (!rows.empty())
2152              m_TreeView.scroll_to_row(path);                  m_TreeView.scroll_to_row(rows[0]);
2153              on_sel_change(); // the regular instrument selection change callback              on_sel_change(); // the regular instrument selection change callback
2154    
2155              // select respective region in the region selector              // select respective region in the region selector
# Line 2066  void MainWindow::select_sample(gig::Samp Line 2175  void MainWindow::select_sample(gig::Samp
2175              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];              Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2176              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2177                  show_samples_tab();                  show_samples_tab();
2178                    m_TreeViewSamples.get_selection()->unselect_all();
2179                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);                  m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2180                  Gtk::TreePath path(                  std::vector<Gtk::TreeModel::Path> rows =
2181                      m_TreeViewSamples.get_selection()->get_selected()                      m_TreeViewSamples.get_selection()->get_selected_rows();
2182                  );                  if (rows.empty()) return;
2183                  m_TreeViewSamples.scroll_to_row(path);                  m_TreeViewSamples.scroll_to_row(rows[0]);
2184                  return;                  return;
2185              }              }
2186          }          }
# Line 2079  void MainWindow::select_sample(gig::Samp Line 2189  void MainWindow::select_sample(gig::Samp
2189    
2190  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2191      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2192            // by default if Ctrl keys is pressed down, then a mouse right-click
2193            // does not select the respective row, so we must assure this
2194            // programmatically ...
2195            /*{
2196                Gtk::TreeModel::Path path;
2197                Gtk::TreeViewColumn* pColumn = NULL;
2198                int cellX, cellY;
2199                bool bSuccess = m_TreeViewSamples.get_path_at_pos(
2200                    (int)button->x, (int)button->y,
2201                    path, pColumn, cellX, cellY
2202                );
2203                if (bSuccess) {
2204                    if (m_TreeViewSamples.get_selection()->count_selected_rows() <= 0) {
2205                        printf("not selected !!!\n");
2206                        m_TreeViewSamples.get_selection()->select(path);
2207                    }
2208                }
2209            }*/
2210    
2211          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
2212              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));              dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
2213          // update enabled/disabled state of sample popup items          // update enabled/disabled state of sample popup items
2214          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2215          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2216          bool group_selected  = false;          const int n = rows.size();
2217          bool sample_selected = false;          int nGroups  = 0;
2218          if (it) {          int nSamples = 0;
2219            for (int r = 0; r < n; ++r) {
2220                Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2221                if (!it) continue;
2222              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::Row row = *it;
2223              group_selected  = row[m_SamplesModel.m_col_group];              if (row[m_SamplesModel.m_col_group]) nGroups++;
2224              sample_selected = row[m_SamplesModel.m_col_sample];              if (row[m_SamplesModel.m_col_sample]) nSamples++;
2225          }          }
2226            
               
2227          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
2228              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2229          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
2230              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2231          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
2232              set_sensitive(file);              set_sensitive(file);
2233          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
2234              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2235          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
2236              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2237          // show sample popup          // show sample popup
2238          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
2239    
2240          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
2241              set_sensitive(group_selected || sample_selected);              set_sensitive(n == 1);
2242          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
2243              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2244          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
2245              set_sensitive(file);              set_sensitive(file);
2246          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
2247              set_sensitive(sample_selected);              set_sensitive(nSamples == 1);
2248          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
2249              set_sensitive(group_selected || sample_selected);              set_sensitive(n);
2250      }      }
2251  }  }
2252    
# Line 2194  void MainWindow::add_instrument(gig::Ins Line 2325  void MainWindow::add_instrument(gig::Ins
2325      instrument_name_connection.block();      instrument_name_connection.block();
2326      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
2327      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
2328        rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2329      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2330      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2331      instrument_name_connection.unblock();      instrument_name_connection.unblock();
# Line 2222  void MainWindow::on_action_duplicate_ins Line 2354  void MainWindow::on_action_duplicate_ins
2354      // retrieve the currently selected instrument      // retrieve the currently selected instrument
2355      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
2356      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2357      Gtk::TreeModel::iterator itSelection = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2358      if (!itSelection) return;      for (int r = 0; r < rows.size(); ++r) {
2359      Gtk::TreeModel::Row row = *itSelection;          Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2360      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];          if (it) {
2361      if (!instrOrig) return;              Gtk::TreeModel::Row row = *it;
2362                gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
2363      // duplicate the orginal instrument              if (instrOrig) {
2364      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);                  // duplicate the orginal instrument
2365      instrNew->pInfo->Name =                  gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
2366          instrOrig->pInfo->Name +                  instrNew->pInfo->Name =
2367          gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");                      instrOrig->pInfo->Name +
2368                        gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
2369    
2370      add_instrument(instrNew);                  add_instrument(instrNew);
2371                }
2372            }
2373        }
2374  }  }
2375    
2376  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 2251  void MainWindow::on_action_remove_instru Line 2387  void MainWindow::on_action_remove_instru
2387      }      }
2388    
2389      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2390      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2391      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2392            Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
2393            if (!it) continue;
2394          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2395          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
2396          try {          try {
# Line 2267  void MainWindow::on_action_remove_instru Line 2405  void MainWindow::on_action_remove_instru
2405    
2406              // remove row from instruments tree view              // remove row from instruments tree view
2407              m_refTreeModel->erase(it);              m_refTreeModel->erase(it);
2408                // update "Nr" column of all instrument rows
2409                {
2410                    int index = 0;
2411                    for (Gtk::TreeModel::iterator it = m_refTreeModel->children().begin();
2412                         it != m_refTreeModel->children().end(); ++it, ++index)
2413                    {
2414                        Gtk::TreeModel::Row row = *it;
2415                        row[m_Columns.m_col_nr] = index;
2416                    }
2417                }
2418    
2419  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
2420              // select another instrument (in gtk3 this is done              // select another instrument (in gtk3 this is done
# Line 2448  void MainWindow::add_or_replace_sample(b Line 2596  void MainWindow::add_or_replace_sample(b
2596    
2597      // get selected group (and probably selected sample)      // get selected group (and probably selected sample)
2598      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2599      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2600        if (rows.empty()) return;
2601        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
2602      if (!it) return;      if (!it) return;
2603      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2604      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
# Line 2731  void MainWindow::on_action_replace_all_s Line 2881  void MainWindow::on_action_replace_all_s
2881  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
2882      if (!file) return;      if (!file) return;
2883      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2884      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
2885      if (it) {      for (int r = rows.size() - 1; r >= 0; --r) {
2886            Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[r]);
2887            if (!it) continue;
2888          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
2889          gig::Group* group   = row[m_SamplesModel.m_col_group];          gig::Group* group   = row[m_SamplesModel.m_col_group];
2890          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          gig::Sample* sample = row[m_SamplesModel.m_col_sample];
# Line 2911  void MainWindow::on_instruments_treeview Line 3063  void MainWindow::on_instruments_treeview
3063      gig::Instrument* src = NULL;      gig::Instrument* src = NULL;
3064      {      {
3065          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3066          Gtk::TreeModel::iterator it = sel->get_selected();          std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3067          if (it) {          if (!rows.empty()) {
3068              Gtk::TreeModel::Row row = *it;              Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[0]);
3069              src = row[m_Columns.m_col_instr];              if (it) {
3070                    Gtk::TreeModel::Row row = *it;
3071                    src = row[m_Columns.m_col_instr];
3072                }
3073          }          }
3074      }      }
3075      if (!src) return;      if (!src) return;
# Line 2969  void MainWindow::on_sample_treeview_drag Line 3124  void MainWindow::on_sample_treeview_drag
3124      // get selected sample      // get selected sample
3125      gig::Sample* sample = NULL;      gig::Sample* sample = NULL;
3126      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3127      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3128      if (it) {      if (!rows.empty()) {
3129          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3130          sample = row[m_SamplesModel.m_col_sample];          if (it) {
3131                Gtk::TreeModel::Row row = *it;
3132                sample = row[m_SamplesModel.m_col_sample];
3133            }
3134      }      }
3135      // pass the gig::Sample as pointer      // pass the gig::Sample as pointer
3136      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 3171  void MainWindow::on_action_combine_instr Line 3329  void MainWindow::on_action_combine_instr
3329    
3330  void MainWindow::on_action_view_references() {  void MainWindow::on_action_view_references() {
3331      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
3332      Gtk::TreeModel::iterator it = sel->get_selected();      std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3333        if (rows.empty()) return;
3334        Gtk::TreeModel::iterator it = m_refSamplesTreeModel->get_iter(rows[0]);
3335      if (!it) return;      if (!it) return;
3336      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
3337      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];

Legend:
Removed from v.2918  
changed lines
  Added in v.3109

  ViewVC Help
Powered by ViewVC