/[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 2689 by schoenebeck, Sun Jan 4 17:19:19 2015 UTC revision 2773 by schoenebeck, Fri Jun 12 17:57:52 2015 UTC
# Line 186  MainWindow::MainWindow() : Line 186  MainWindow::MainWindow() :
186      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
187                       sigc::mem_fun(                       sigc::mem_fun(
188                           *this, &MainWindow::on_action_view_status_bar));                           *this, &MainWindow::on_action_view_status_bar));
189        actionGroup->add(
190            Gtk::Action::create("RefreshAll", _("_Refresh All")),
191            sigc::mem_fun(*this, &MainWindow::on_action_refresh_all)
192        );                
193    
194      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
195      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
# Line 225  MainWindow::MainWindow() : Line 229  MainWindow::MainWindow() :
229          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)          sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
230      );      );
231    
232        toggle_action =
233            Gtk::ToggleAction::create("MoveRootNoteWithRegionMoved", _("Move root note with region moved"));
234        toggle_action->set_active(Settings::singleton()->moveRootNoteWithRegionMoved);
235        actionGroup->add(
236            toggle_action,
237            sigc::mem_fun(*this, &MainWindow::on_action_move_root_note_with_region_moved)
238        );
239    
240    
241      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
242    
# Line 257  MainWindow::MainWindow() : Line 269  MainWindow::MainWindow() :
269          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
270      );      );
271      actionGroup->add(      actionGroup->add(
272            Gtk::Action::create("RemoveUnusedSamples", _("Remove _Unused Samples")),
273            sigc::mem_fun(*this, &MainWindow::on_action_remove_unused_samples)
274        );
275        actionGroup->add(
276          Gtk::Action::create("ShowSampleRefs", _("Show References...")),          Gtk::Action::create("ShowSampleRefs", _("Show References...")),
277          sigc::mem_fun(*this, &MainWindow::on_action_view_references)          sigc::mem_fun(*this, &MainWindow::on_action_view_references)
278      );      );
279      actionGroup->add(      actionGroup->add(
280            Gtk::Action::create("ReplaceSample",
281                                _("Replace Sample...")),
282            sigc::mem_fun(*this, &MainWindow::on_action_replace_sample)
283        );
284        actionGroup->add(
285          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
286                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
287          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
# Line 312  MainWindow::MainWindow() : Line 333  MainWindow::MainWindow() :
333          "      <menuitem action='AddGroup'/>"          "      <menuitem action='AddGroup'/>"
334          "      <menuitem action='AddSample'/>"          "      <menuitem action='AddSample'/>"
335          "      <menuitem action='ShowSampleRefs'/>"          "      <menuitem action='ShowSampleRefs'/>"
336            "      <menuitem action='ReplaceSample' />"
337          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"          "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
338          "      <separator/>"          "      <separator/>"
339          "      <menuitem action='RemoveSample'/>"          "      <menuitem action='RemoveSample'/>"
340            "      <menuitem action='RemoveUnusedSamples'/>"
341          "    </menu>"          "    </menu>"
342          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
343          "      <menu action='AllInstruments'>"          "      <menu action='AllInstruments'>"
# Line 337  MainWindow::MainWindow() : Line 360  MainWindow::MainWindow() :
360          "    </menu>"          "    </menu>"
361          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
362          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
363            "      <separator/>"
364            "      <menuitem action='RefreshAll'/>"
365          "    </menu>"          "    </menu>"
366          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
367          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
# Line 345  MainWindow::MainWindow() : Line 370  MainWindow::MainWindow() :
370          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
371          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
372          "      <menuitem action='SyncSamplerInstrumentSelection'/>"          "      <menuitem action='SyncSamplerInstrumentSelection'/>"
373            "      <menuitem action='MoveRootNoteWithRegionMoved'/>"
374          "    </menu>"          "    </menu>"
375          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
376          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 364  MainWindow::MainWindow() : Line 390  MainWindow::MainWindow() :
390          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
391          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
392          "    <menuitem action='ShowSampleRefs'/>"          "    <menuitem action='ShowSampleRefs'/>"
393            "    <menuitem action='ReplaceSample' />"
394          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
395          "    <separator/>"          "    <separator/>"
396          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
397            "    <menuitem action='RemoveUnusedSamples'/>"
398          "  </popup>"          "  </popup>"
399          "  <popup name='ScriptPopupMenu'>"          "  <popup name='ScriptPopupMenu'>"
400          "    <menuitem action='AddScriptGroup'/>"          "    <menuitem action='AddScriptGroup'/>"
# Line 411  MainWindow::MainWindow() : Line 439  MainWindow::MainWindow() :
439      }      }
440      {      {
441          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
442                uiManager->get_widget("/MenuBar/MenuSettings/MoveRootNoteWithRegionMoved"));
443            item->set_tooltip_text(_("If checked, and when a region is moved by dragging it around on the virtual keyboard, the keybord position dependent pitch will move exactly with the amount of semi tones the region was moved around."));
444        }
445        {
446            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
447                uiManager->get_widget("/MenuBar/MenuSample/RemoveUnusedSamples"));
448            item->set_tooltip_text(_("Removes all samples that are not referenced by any instrument (i.e. red ones)."));
449            // copy tooltip to popup menu
450            Gtk::MenuItem* item2 = dynamic_cast<Gtk::MenuItem*>(
451                uiManager->get_widget("/SamplePopupMenu/RemoveUnusedSamples"));
452            item2->set_tooltip_text(item->get_tooltip_text());
453        }
454        {
455            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
456                uiManager->get_widget("/MenuBar/MenuView/RefreshAll"));
457            item->set_tooltip_text(_("Reloads the currently open gig file and updates the entire graphical user interface."));
458        }
459        {
460            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
461              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
462          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
463      }      }
# Line 448  MainWindow::MainWindow() : Line 495  MainWindow::MainWindow() :
495      // Create the Tree model:      // Create the Tree model:
496      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
497      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
498      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
499      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
500          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
501      );      );
# Line 456  MainWindow::MainWindow() : Line 503  MainWindow::MainWindow() :
503      // Add the TreeView's view columns:      // Add the TreeView's view columns:
504      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);
505      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
506        
507        // establish drag&drop within the instrument tree view, allowing to reorder
508        // the sequence of instruments within the gig file
509        {
510            std::vector<Gtk::TargetEntry> drag_target_instrument;
511            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
512            m_TreeView.drag_source_set(drag_target_instrument);
513            m_TreeView.drag_dest_set(drag_target_instrument);
514            m_TreeView.signal_drag_begin().connect(
515                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
516            );
517            m_TreeView.signal_drag_data_get().connect(
518                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
519            );
520            m_TreeView.signal_drag_data_received().connect(
521                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
522            );
523        }
524    
525      // create samples treeview (including its data model)      // create samples treeview (including its data model)
526      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
# Line 503  MainWindow::MainWindow() : Line 568  MainWindow::MainWindow() :
568      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
569          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
570      );      );
571      //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?      //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
572      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
573          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
574      );      );
# Line 540  MainWindow::MainWindow() : Line 605  MainWindow::MainWindow() :
605          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
606      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
607          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
608        m_RegionChooser.signal_instrument_changed().connect(
609            sigc::mem_fun(*this, &MainWindow::region_changed));
610      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
611          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
612      instrumentProps.signal_changed().connect(      instrumentProps.signal_changed().connect(
# Line 562  MainWindow::MainWindow() : Line 629  MainWindow::MainWindow() :
629          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
630      );      );
631    
632        dimreg_edit.signal_select_sample().connect(
633            sigc::mem_fun(*this, &MainWindow::select_sample)
634        );
635    
636      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
637          sigc::hide(          sigc::hide(
638              sigc::bind(              sigc::bind(
# Line 943  bool MainWindow::close_confirmation_dial Line 1014  bool MainWindow::close_confirmation_dial
1014      int response = dialog.run();      int response = dialog.run();
1015      dialog.hide();      dialog.hide();
1016    
1017        // user decided to exit app without saving
1018        if (response == Gtk::RESPONSE_NO) return true;
1019    
1020        // user cancelled dialog, thus don't close app
1021        if (response == Gtk::RESPONSE_CANCEL) return false;
1022    
1023      // TODO: the following return valid is disabled and hard coded instead for      // TODO: the following return valid is disabled and hard coded instead for
1024      // now, due to the fact that saving with progress bar is now implemented      // now, due to the fact that saving with progress bar is now implemented
1025      // asynchronously, as a result the app does not close automatically anymore      // asynchronously, as a result the app does not close automatically anymore
# Line 1159  void MainWindow::on_saver_finished() Line 1236  void MainWindow::on_saver_finished()
1236    
1237      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1238    
1239      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1240      progress_dialog->hide();      progress_dialog->hide();
1241  }  }
1242    
# Line 1362  void MainWindow::on_action_sync_sampler_ Line 1439  void MainWindow::on_action_sync_sampler_
1439          !Settings::singleton()->syncSamplerInstrumentSelection;          !Settings::singleton()->syncSamplerInstrumentSelection;
1440  }  }
1441    
1442    void MainWindow::on_action_move_root_note_with_region_moved() {
1443        Settings::singleton()->moveRootNoteWithRegionMoved =
1444            !Settings::singleton()->moveRootNoteWithRegionMoved;
1445    }
1446    
1447  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1448  {  {
1449      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1654  void MainWindow::load_gig(gig::File* gig Line 1736  void MainWindow::load_gig(gig::File* gig
1736      file = 0;      file = 0;
1737      set_file_is_shared(isSharedInstrument);      set_file_is_shared(isSharedInstrument);
1738    
1739      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename =
1740            (filename && strlen(filename) > 0) ?
1741                filename : (!gig->GetFileName().empty()) ?
1742                    gig->GetFileName() : _("Unsaved Gig File");
1743      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
1744      file_has_name = filename;      file_has_name = filename;
1745      file_is_changed = false;      file_is_changed = false;
# Line 1808  void MainWindow::show_script_slots() { Line 1893  void MainWindow::show_script_slots() {
1893      window->show();      window->show();
1894  }  }
1895    
1896    void MainWindow::on_action_refresh_all() {
1897        __refreshEntireGUI();
1898    }
1899    
1900  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1901      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1902          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1883  void MainWindow::on_instrument_selection Line 1972  void MainWindow::on_instrument_selection
1972      }      }
1973  }  }
1974    
1975    void MainWindow::select_instrument(gig::Instrument* instrument) {
1976        if (!instrument) return;
1977    
1978        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1979        for (int i = 0; i < model->children().size(); ++i) {
1980            Gtk::TreeModel::Row row = model->children()[i];
1981            if (row[m_Columns.m_col_instr] == instrument) {
1982                // select and show the respective instrument in the list view
1983                show_intruments_tab();
1984                m_TreeView.get_selection()->select(model->children()[i]);
1985                Gtk::TreePath path(
1986                    m_TreeView.get_selection()->get_selected()
1987                );
1988                m_TreeView.scroll_to_row(path);
1989                on_sel_change(); // the regular instrument selection change callback
1990            }
1991        }
1992    }
1993    
1994    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
1995    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
1996        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
1997        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
1998    
1999        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2000        for (int i = 0; i < model->children().size(); ++i) {
2001            Gtk::TreeModel::Row row = model->children()[i];
2002            if (row[m_Columns.m_col_instr] == pInstrument) {
2003                // select and show the respective instrument in the list view
2004                show_intruments_tab();
2005                m_TreeView.get_selection()->select(model->children()[i]);
2006                Gtk::TreePath path(
2007                    m_TreeView.get_selection()->get_selected()
2008                );
2009                m_TreeView.scroll_to_row(path);
2010                on_sel_change(); // the regular instrument selection change callback
2011    
2012                // select respective region in the region selector
2013                m_RegionChooser.set_region(pRegion);
2014    
2015                // select and show the respective dimension region in the editor
2016                //update_dimregs();
2017                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
2018                //dimreg_edit.set_dim_region(dimRgn);
2019    
2020                return true;
2021            }
2022        }
2023    
2024        return false;
2025    }
2026    
2027    void MainWindow::select_sample(gig::Sample* sample) {
2028        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2029        for (int g = 0; g < model->children().size(); ++g) {
2030            Gtk::TreeModel::Row rowGroup = model->children()[g];
2031            for (int s = 0; s < rowGroup.children().size(); ++s) {
2032                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2033                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
2034                    show_samples_tab();
2035                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
2036                    Gtk::TreePath path(
2037                        m_TreeViewSamples.get_selection()->get_selected()
2038                    );
2039                    m_TreeViewSamples.scroll_to_row(path);
2040                    return;
2041                }
2042            }
2043        }
2044    }
2045    
2046  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
2047      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
2048          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
# Line 2235  void MainWindow::on_action_add_group() { Line 2395  void MainWindow::on_action_add_group() {
2395      file_changed();      file_changed();
2396  }  }
2397    
2398    void MainWindow::on_action_replace_sample() {
2399        add_or_replace_sample(true);
2400    }
2401    
2402  void MainWindow::on_action_add_sample() {  void MainWindow::on_action_add_sample() {
2403        add_or_replace_sample(false);
2404    }
2405    
2406    void MainWindow::add_or_replace_sample(bool replace) {
2407      if (!file) return;      if (!file) return;
2408      // get selected group  
2409        // get selected group (and probably selected sample)
2410      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2411      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
2412      if (!it) return;      if (!it) return;
2413      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
2414        gig::Sample* sample = NULL;
2415      gig::Group* group = row[m_SamplesModel.m_col_group];      gig::Group* group = row[m_SamplesModel.m_col_group];
2416      if (!group) { // not a group, but a sample is selected (probably)      if (!group) { // not a group, but a sample is selected (probably)
2417          gig::Sample* sample = row[m_SamplesModel.m_col_sample];          if (replace) sample = row[m_SamplesModel.m_col_sample];
2418          if (!sample) return;          if (!row[m_SamplesModel.m_col_sample]) return;
2419          it = row.parent(); // resolve parent (that is the sample's group)          it = row.parent(); // resolve parent (that is the sample's group)
2420          if (!it) return;          if (!it) return;
2421          row = *it;          if (!replace) row = *it;
2422          group = row[m_SamplesModel.m_col_group];          group = (*it)[m_SamplesModel.m_col_group];
2423          if (!group) return;          if (!group) return;
2424      }      }
2425        if (replace && !sample) return;
2426    
2427      // show 'browse for file' dialog      // show 'browse for file' dialog
2428      Gtk::FileChooserDialog dialog(*this, _("Add Sample(s)"));      Gtk::FileChooserDialog dialog(*this, replace ? _("Replace Sample with") : _("Add Sample(s)"));
2429      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2430      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
2431      dialog.set_select_multiple(true);      dialog.set_select_multiple(!replace); // allow multi audio file selection only when adding new samples, does not make sense when replacing a specific sample
2432    
2433      // matches all file types supported by libsndfile      // matches all file types supported by libsndfile
2434  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
# Line 2327  void MainWindow::on_action_add_sample() Line 2499  void MainWindow::on_action_add_sample()
2499                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
2500                          throw std::string(_("format not supported")); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
2501                  }                  }
2502                  // add a new sample to the .gig file                  // add a new sample to the .gig file (if adding is requested actually)
2503                  gig::Sample* sample = file->AddSample();                  if (!replace) sample = file->AddSample();
2504                  // file name without path                  // file name without path
2505                  Glib::ustring filename = Glib::filename_display_basename(*iter);                  Glib::ustring filename = Glib::filename_display_basename(*iter);
2506                  // remove file extension if there is one                  // remove file extension if there is one
# Line 2379  void MainWindow::on_action_add_sample() Line 2551  void MainWindow::on_action_add_sample()
2551                  // physically when File::Save() is called)                  // physically when File::Save() is called)
2552                  sample->Resize(info.frames);                  sample->Resize(info.frames);
2553                  // make sure sample is part of the selected group                  // make sure sample is part of the selected group
2554                  group->AddSample(sample);                  if (!replace) group->AddSample(sample);
2555                  // schedule that physical resize and sample import                  // schedule that physical resize and sample import
2556                  // (data copying), performed when "Save" is requested                  // (data copying), performed when "Save" is requested
2557                  SampleImportItem sched_item;                  SampleImportItem sched_item;
# Line 2387  void MainWindow::on_action_add_sample() Line 2559  void MainWindow::on_action_add_sample()
2559                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2560                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue.push_back(sched_item);
2561                  // add sample to the tree view                  // add sample to the tree view
2562                  Gtk::TreeModel::iterator iterSample =                  if (replace) {
2563                      m_refSamplesTreeModel->append(row.children());                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
2564                  Gtk::TreeModel::Row rowSample = *iterSample;                  } else {
2565                  rowSample[m_SamplesModel.m_col_name] =                      Gtk::TreeModel::iterator iterSample =
2566                      gig_to_utf8(sample->pInfo->Name);                          m_refSamplesTreeModel->append(row.children());
2567                  rowSample[m_SamplesModel.m_col_sample] = sample;                      Gtk::TreeModel::Row rowSample = *iterSample;
2568                  rowSample[m_SamplesModel.m_col_group]  = NULL;                      rowSample[m_SamplesModel.m_col_name] =
2569                            gig_to_utf8(sample->pInfo->Name);
2570                        rowSample[m_SamplesModel.m_col_sample] = sample;
2571                        rowSample[m_SamplesModel.m_col_group]  = NULL;
2572                    }
2573                  // close sound file                  // close sound file
2574                  sf_close(hFile);                  sf_close(hFile);
2575                  file_changed();                  file_changed();
# Line 2404  void MainWindow::on_action_add_sample() Line 2580  void MainWindow::on_action_add_sample()
2580          }          }
2581          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
2582          if (!error_files.empty()) {          if (!error_files.empty()) {
2583              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt =
2584                    (replace
2585                        ? _("Failed to replace sample with:\n")
2586                        : _("Could not add the following sample(s):\n"))
2587                    + error_files;
2588              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2589              msg.run();              msg.run();
2590          }          }
# Line 2588  void MainWindow::on_action_remove_sample Line 2768  void MainWindow::on_action_remove_sample
2768      }      }
2769  }  }
2770    
2771    void MainWindow::on_action_remove_unused_samples() {
2772        if (!file) return;
2773    
2774        // collect all samples that are not referenced by any instrument
2775        std::list<gig::Sample*> lsamples;
2776        for (int iSample = 0; file->GetSample(iSample); ++iSample) {
2777            gig::Sample* sample = file->GetSample(iSample);
2778            bool isUsed = false;
2779            for (gig::Instrument* instrument = file->GetFirstInstrument(); instrument;
2780                                  instrument = file->GetNextInstrument())
2781            {
2782                for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
2783                                  rgn = instrument->GetNextRegion())
2784                {
2785                    for (int i = 0; i < 256; ++i) {
2786                        if (!rgn->pDimensionRegions[i]) continue;
2787                        if (rgn->pDimensionRegions[i]->pSample != sample) continue;
2788                        isUsed = true;
2789                        goto endOfRefSearch;
2790                    }
2791                }
2792            }
2793            endOfRefSearch:
2794            if (!isUsed) lsamples.push_back(sample);
2795        }
2796    
2797        if (lsamples.empty()) return;
2798    
2799        // notify everybody that we're going to remove these samples
2800        samples_to_be_removed_signal.emit(lsamples);
2801    
2802        // remove collected samples
2803        try {
2804            for (std::list<gig::Sample*>::iterator itSample = lsamples.begin();
2805                 itSample != lsamples.end(); ++itSample)
2806            {
2807                gig::Sample* sample = *itSample;
2808                // remove sample from the .gig file
2809                file->DeleteSample(sample);
2810                // if sample was just previously added, remove it fro the import queue
2811                for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
2812                     iter != m_SampleImportQueue.end(); ++iter)
2813                {
2814                    if ((*iter).gig_sample == sample) {
2815                        printf("Removing previously added sample '%s'\n",
2816                               (*iter).sample_path.c_str());
2817                        m_SampleImportQueue.erase(iter);
2818                        break;
2819                    }
2820                }
2821            }
2822        } catch (RIFF::Exception e) {
2823            // show error message
2824            Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2825            msg.run();
2826        }
2827    
2828        // notify everybody that we're done with removal
2829        samples_removed_signal.emit();
2830    
2831        dimreg_changed();
2832        file_changed();
2833        __refreshEntireGUI();
2834    }
2835    
2836  // see comment on on_sample_treeview_drag_begin()  // see comment on on_sample_treeview_drag_begin()
2837  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)  void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2838  {  {
# Line 2614  void MainWindow::on_scripts_treeview_dra Line 2859  void MainWindow::on_scripts_treeview_dra
2859                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
2860  }  }
2861    
2862    // see comment on on_sample_treeview_drag_begin()
2863    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2864    {
2865        first_call_to_drag_data_get = true;
2866    }
2867    
2868    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2869                                                           Gtk::SelectionData& selection_data, guint, guint)
2870    {
2871        if (!first_call_to_drag_data_get) return;
2872        first_call_to_drag_data_get = false;
2873    
2874        // get selected source instrument
2875        gig::Instrument* src = NULL;
2876        {
2877            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2878            Gtk::TreeModel::iterator it = sel->get_selected();
2879            if (it) {
2880                Gtk::TreeModel::Row row = *it;
2881                src = row[m_Columns.m_col_instr];
2882            }
2883        }
2884        if (!src) return;
2885    
2886        // pass the source gig::Instrument as pointer
2887        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
2888                           sizeof(src)/*length of data in bytes*/);
2889    }
2890    
2891    void MainWindow::on_instruments_treeview_drop_drag_data_received(
2892        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
2893        const Gtk::SelectionData& selection_data, guint, guint time)
2894    {
2895        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
2896        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
2897            return;
2898    
2899        gig::Instrument* dst = NULL;
2900        {
2901            Gtk::TreeModel::Path path;
2902            const bool found = m_TreeView.get_path_at_pos(x, y, path);
2903            if (!found) return;
2904    
2905            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
2906            if (!iter) return;
2907            Gtk::TreeModel::Row row = *iter;
2908            dst = row[m_Columns.m_col_instr];
2909        }
2910        if (!dst) return;
2911    
2912        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
2913        src->MoveTo(dst);
2914        __refreshEntireGUI();
2915        select_instrument(src);
2916    }
2917    
2918  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2919  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
2920  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 2836  void MainWindow::on_action_view_referenc Line 3137  void MainWindow::on_action_view_referenc
3137    
3138      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
3139      d->setSample(sample);      d->setSample(sample);
3140        d->dimension_region_selected.connect(
3141            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
3142        );
3143      d->show_all();      d->show_all();
3144      d->resize(500, 400);      d->resize(500, 400);
3145      d->run();      d->run();
# Line 3001  void MainWindow::on_action_merge_files() Line 3305  void MainWindow::on_action_merge_files()
3305          }          }
3306    
3307          // update GUI          // update GUI
3308          __refreshEntireGUI();                  __refreshEntireGUI();
3309      }      }
3310  }  }
3311    

Legend:
Removed from v.2689  
changed lines
  Added in v.2773

  ViewVC Help
Powered by ViewVC