/[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 3810 by schoenebeck, Fri Aug 14 11:45:08 2020 UTC revision 3918 by schoenebeck, Thu Jun 10 13:28:17 2021 UTC
# Line 1734  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 2086  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 2199  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 3516  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 3976  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_TreeViewInstruments.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 4419  void MainWindow::on_action_duplicate_ins Line 4467  void MainWindow::on_action_duplicate_ins
4467      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.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_refInstrumentsTreeModel->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_InstrumentsModel.m_col_instr];              gig::Instrument* instrOrig = row[m_InstrumentsModel.m_col_instr];
# Line 4450  void MainWindow::on_action_remove_instru Line 4500  void MainWindow::on_action_remove_instru
4500      }      }
4501    
4502      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.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_refInstrumentsTreeModel->get_iter(rows[r]);          Gtk::TreeModel::iterator it = m_refInstrumentsTreeModel->get_iter(rows[r]);
4515          if (!it) continue;          if (!it) continue;
# Line 5045  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 5145  void MainWindow::on_instruments_treeview Line 5183  void MainWindow::on_instruments_treeview
5183          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.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_refInstrumentsTreeModel->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_InstrumentsModel.m_col_instr];                  src = row[m_InstrumentsModel.m_col_instr];
# Line 5173  void MainWindow::on_instruments_treeview Line 5213  void MainWindow::on_instruments_treeview
5213          const bool found = m_TreeViewInstruments.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            // 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);          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;
# Line 5425  void MainWindow::on_action_combine_instr Line 5469  void MainWindow::on_action_combine_instr
5469          Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewInstruments.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_refInstrumentsTreeModel->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_InstrumentsModel.m_col_nr];                  int index = row[m_InstrumentsModel.m_col_nr];

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

  ViewVC Help
Powered by ViewVC