/[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 2610 by schoenebeck, Sun Jun 8 19:09:26 2014 UTC revision 2626 by schoenebeck, Thu Jun 12 15:12:00 2014 UTC
# Line 47  Line 47 
47  #include "CombineInstrumentsDialog.h"  #include "CombineInstrumentsDialog.h"
48  #include "scripteditor.h"  #include "scripteditor.h"
49  #include "scriptslots.h"  #include "scriptslots.h"
50    #include "ReferencesView.h"
51  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
52  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
53    
54    
55  MainWindow::MainWindow() :  MainWindow::MainWindow() :
56        m_DimRegionChooser(*this),
57      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
58      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
59      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
# Line 145  MainWindow::MainWindow() : Line 147  MainWindow::MainWindow() :
147      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
148                       sigc::mem_fun(                       sigc::mem_fun(
149                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
150      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(
151            Gtk::Action::create("MenuSample", _("_Sample")),
152            sigc::mem_fun(*this, &MainWindow::show_samples_tab)
153        );
154        actionGroup->add(
155            Gtk::Action::create("MenuInstrument", _("_Instrument")),
156            sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
157        );
158        actionGroup->add(
159            Gtk::Action::create("MenuScript", _("S_cript")),
160            sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
161        );
162        actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
163    
164      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
165    
# Line 236  MainWindow::MainWindow() : Line 249  MainWindow::MainWindow() :
249          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
250      );      );
251      actionGroup->add(      actionGroup->add(
252            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
253            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
254        );
255        actionGroup->add(
256          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
257                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
258          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 282  MainWindow::MainWindow() : Line 299  MainWindow::MainWindow() :
299          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
300          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
301          "    </menu>"          "    </menu>"
302            "    <menu action='MenuSample'>"
303            "      <menuitem action='SampleProperties'/>"
304            "      <menuitem action='AddGroup'/>"
305            "      <menuitem action='AddSample'/>"
306            "      <menuitem action='ShowSampleRefs'/>"
307            "      <menuitem action='ReplaceAllSamplesInAllGroups' />"
308            "      <separator/>"
309            "      <menuitem action='RemoveSample'/>"
310            "    </menu>"
311          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
312            "      <menu action='AllInstruments'>"
313            "      </menu>"
314            "      <separator/>"
315            "      <menuitem action='InstrProperties'/>"
316            "      <menuitem action='MidiRules'/>"
317            "      <menuitem action='ScriptSlots'/>"
318            "      <menuitem action='AddInstrument'/>"
319            "      <menuitem action='DupInstrument'/>"
320            "      <separator/>"
321            "      <menuitem action='RemoveInstrument'/>"
322            "    </menu>"
323            "    <menu action='MenuScript'>"
324            "      <menuitem action='AddScriptGroup'/>"
325            "      <menuitem action='AddScript'/>"
326            "      <menuitem action='EditScript'/>"
327            "      <separator/>"
328            "      <menuitem action='RemoveScript'/>"
329          "    </menu>"          "    </menu>"
330          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
331          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
# Line 311  MainWindow::MainWindow() : Line 354  MainWindow::MainWindow() :
354          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
355          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
356          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
357            "    <menuitem action='ShowSampleRefs'/>"
358          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
359          "    <separator/>"          "    <separator/>"
360          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
# Line 364  MainWindow::MainWindow() : Line 408  MainWindow::MainWindow() :
408    
409    
410      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
411          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
412    
413      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
414      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
# Line 404  MainWindow::MainWindow() : Line 448  MainWindow::MainWindow() :
448      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
449      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."));
450      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
451      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
452      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
453        {
454            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
455            Gtk::CellRendererText* cellrenderer =
456                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
457            column->add_attribute(
458                cellrenderer->property_foreground(), m_SamplesModel.m_color
459            );
460        }
461        {
462            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
463            Gtk::CellRendererText* cellrenderer =
464                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
465            column->add_attribute(
466                cellrenderer->property_foreground(), m_SamplesModel.m_color
467            );
468        }
469        m_TreeViewSamples.set_headers_visible(true);
470      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
471          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
472      );      );
# Line 474  MainWindow::MainWindow() : Line 535  MainWindow::MainWindow() :
535          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
536      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
537          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
538        sample_ref_changed_signal.connect(
539            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
540        );
541        samples_to_be_removed_signal.connect(
542            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
543        );
544    
545      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
546          sigc::hide(          sigc::hide(
# Line 599  void MainWindow::dimreg_all_dimregs_togg Line 666  void MainWindow::dimreg_all_dimregs_togg
666  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
667  {  {
668      update_dimregs();      update_dimregs();
669      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
670  }  }
671    
672  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
# Line 697  void MainWindow::__clear() { Line 764  void MainWindow::__clear() {
764      // clear the samples and instruments tree views      // clear the samples and instruments tree views
765      m_refTreeModel->clear();      m_refTreeModel->clear();
766      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
767        m_refScriptsTreeModel->clear();
768      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
769      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
770          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 711  void MainWindow::__refreshEntireGUI() { Line 779  void MainWindow::__refreshEntireGUI() {
779      // clear the samples and instruments tree views      // clear the samples and instruments tree views
780      m_refTreeModel->clear();      m_refTreeModel->clear();
781      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
782        m_refScriptsTreeModel->clear();
783      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
784      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
785          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 1358  void MainWindow::file_changed() Line 1427  void MainWindow::file_changed()
1427      }      }
1428  }  }
1429    
1430    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1431        sample_ref_count.clear();
1432        
1433        if (!gig) return;
1434    
1435        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1436             instrument = gig->GetNextInstrument())
1437        {
1438            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1439                 rgn = instrument->GetNextRegion())
1440            {
1441                for (int i = 0; i < 256; ++i) {
1442                    if (!rgn->pDimensionRegions[i]) continue;
1443                    if (rgn->pDimensionRegions[i]->pSample) {
1444                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1445                    }
1446                }
1447            }
1448        }
1449    }
1450    
1451  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1452  {  {
1453      file = 0;      file = 0;
# Line 1384  void MainWindow::load_gig(gig::File* gig Line 1474  void MainWindow::load_gig(gig::File* gig
1474          add_instrument_to_menu(name);          add_instrument_to_menu(name);
1475      }      }
1476      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1477      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1478    
1479        updateSampleRefCountMap(gig);
1480    
1481      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1482          if (group->Name != "") {          if (group->Name != "") {
# Line 1402  void MainWindow::load_gig(gig::File* gig Line 1494  void MainWindow::load_gig(gig::File* gig
1494                      gig_to_utf8(sample->pInfo->Name);                      gig_to_utf8(sample->pInfo->Name);
1495                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1496                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1497                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1498                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1499                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1500              }              }
1501          }          }
1502      }      }
# Line 1425  void MainWindow::load_gig(gig::File* gig Line 1520  void MainWindow::load_gig(gig::File* gig
1520              rowScript[m_ScriptsModel.m_col_group]  = NULL;              rowScript[m_ScriptsModel.m_col_group]  = NULL;
1521          }          }
1522      }      }
1523      // unfold all script groups by default      // unfold all sample groups & script groups by default
1524        m_TreeViewSamples.expand_all();
1525      m_TreeViewScripts.expand_all();      m_TreeViewScripts.expand_all();
1526    
1527      file = gig;      file = gig;
# Line 1558  void MainWindow::on_button_release(GdkEv Line 1654  void MainWindow::on_button_release(GdkEv
1654          show_instr_props();          show_instr_props();
1655      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1656          // gig v2 files have no midi rules          // gig v2 files have no midi rules
1657            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1658            static_cast<Gtk::MenuItem*>(
1659                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1660                    bEnabled
1661                );
1662          static_cast<Gtk::MenuItem*>(          static_cast<Gtk::MenuItem*>(
1663              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1664                  !(file->pVersion && file->pVersion->major == 2));                  bEnabled
1665                );
1666          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1667      }      }
1668  }  }
# Line 1594  void MainWindow::on_sample_treeview_butt Line 1696  void MainWindow::on_sample_treeview_butt
1696              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
1697              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
1698          }          }
1699            
1700                
1701          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
1702              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1703          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
1704              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1705          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1706              set_sensitive(file);              set_sensitive(file);
1707            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
1708                set_sensitive(sample_selected);
1709          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1710              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1711          // show sample popup          // show sample popup
1712          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
1713    
1714            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
1715                set_sensitive(group_selected || sample_selected);
1716            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
1717                set_sensitive(group_selected || sample_selected);
1718            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
1719                set_sensitive(file);
1720            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
1721                set_sensitive(sample_selected);
1722            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
1723                set_sensitive(group_selected || sample_selected);
1724      }      }
1725  }  }
1726    
# Line 1631  void MainWindow::on_script_treeview_butt Line 1748  void MainWindow::on_script_treeview_butt
1748              set_sensitive(group_selected || script_selected);              set_sensitive(group_selected || script_selected);
1749          // show sample popup          // show sample popup
1750          script_popup->popup(button->button, button->time);          script_popup->popup(button->button, button->time);
1751    
1752            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
1753                set_sensitive(group_selected || script_selected);
1754            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
1755                set_sensitive(file);
1756            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
1757                set_sensitive(script_selected);    
1758            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
1759                set_sensitive(group_selected || script_selected);
1760      }      }
1761  }  }
1762    
# Line 2484  void MainWindow::on_action_combine_instr Line 2610  void MainWindow::on_action_combine_instr
2610      delete d;      delete d;
2611  }  }
2612    
2613    void MainWindow::on_action_view_references() {
2614        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2615        Gtk::TreeModel::iterator it = sel->get_selected();
2616        if (!it) return;
2617        Gtk::TreeModel::Row row = *it;
2618        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2619        if (!sample) return;
2620    
2621        ReferencesView* d = new ReferencesView(*this);
2622        d->setSample(sample);
2623        d->show_all();
2624        d->resize(500, 400);
2625        d->run();
2626        delete d;
2627    }
2628    
2629  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2630      struct _Source {      struct _Source {
2631          std::vector<RIFF::File*> riffs;          std::vector<RIFF::File*> riffs;
# Line 2644  void MainWindow::set_file_is_shared(bool Line 2786  void MainWindow::set_file_is_shared(bool
2786      }      }
2787  }  }
2788    
2789    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2790        if (!sample) return;
2791        sample_ref_count[sample] += offset;
2792        const int refcount = sample_ref_count[sample];
2793    
2794        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2795        for (int g = 0; g < model->children().size(); ++g) {
2796            Gtk::TreeModel::Row rowGroup = model->children()[g];
2797            for (int s = 0; s < rowGroup.children().size(); ++s) {
2798                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2799                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2800                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2801                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
2802            }
2803        }
2804    }
2805    
2806    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2807        on_sample_ref_count_incremented(oldSample, -1);
2808        on_sample_ref_count_incremented(newSample, +1);
2809    }
2810    
2811    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2812        // just in case a new sample is added later with exactly the same memory
2813        // address, which would lead to incorrect refcount if not deleted here
2814        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2815             it != samples.end(); it != samples.end())
2816        {
2817            sample_ref_count.erase(*it);
2818        }
2819    }
2820    
2821    void MainWindow::show_samples_tab() {
2822        m_TreeViewNotebook.set_current_page(0);
2823    }
2824    
2825    void MainWindow::show_intruments_tab() {
2826        m_TreeViewNotebook.set_current_page(1);
2827    }
2828    
2829    void MainWindow::show_scripts_tab() {
2830        m_TreeViewNotebook.set_current_page(2);
2831    }
2832    
2833  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2834      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2835  }  }

Legend:
Removed from v.2610  
changed lines
  Added in v.2626

  ViewVC Help
Powered by ViewVC