/[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 3814 by schoenebeck, Fri Aug 14 12:29:01 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 5056  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

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

  ViewVC Help
Powered by ViewVC