/[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 2566 by schoenebeck, Tue May 20 14:35:36 2014 UTC revision 2627 by schoenebeck, Thu Jun 12 16:12:55 2014 UTC
# Line 45  Line 45 
45  #include "mainwindow.h"  #include "mainwindow.h"
46  #include "Settings.h"  #include "Settings.h"
47  #include "CombineInstrumentsDialog.h"  #include "CombineInstrumentsDialog.h"
48    #include "scripteditor.h"
49    #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 78  MainWindow::MainWindow() : Line 82  MainWindow::MainWindow() :
82      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
83      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
84    
85        m_ScrolledWindowScripts.add(m_TreeViewScripts);
86        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
87    
88    
89      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
90    
# Line 98  MainWindow::MainWindow() : Line 105  MainWindow::MainWindow() :
105    
106      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
107      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
108        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
109    
110      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
111    
# Line 130  MainWindow::MainWindow() : Line 137  MainWindow::MainWindow() :
137                       sigc::mem_fun(                       sigc::mem_fun(
138                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
139      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
140                                           _("_Midi Rules")),                                           _("_Midi Rules...")),
141                       sigc::mem_fun(                       sigc::mem_fun(
142                           *this, &MainWindow::show_midi_rules));                           *this, &MainWindow::show_midi_rules));
143        actionGroup->add(Gtk::Action::create("ScriptSlots",
144                                             _("_Script Slots...")),
145                         sigc::mem_fun(
146                             *this, &MainWindow::show_script_slots));
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 227  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)
259      );      );
260        
261        // script right-click popup actions
262        actionGroup->add(
263            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
264            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
265        );
266        actionGroup->add(
267            Gtk::Action::create("AddScript", _("Add _Script")),
268            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
269        );
270        actionGroup->add(
271            Gtk::Action::create("EditScript", _("_Edit Script...")),
272            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
273        );
274        actionGroup->add(
275            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
276            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
277        );
278    
279      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
280      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 255  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 274  MainWindow::MainWindow() : Line 344  MainWindow::MainWindow() :
344          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
345          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
346          "    <menuitem action='MidiRules'/>"          "    <menuitem action='MidiRules'/>"
347            "    <menuitem action='ScriptSlots'/>"
348          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
349          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
350          "    <separator/>"          "    <separator/>"
# Line 283  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'/>"
361          "  </popup>"          "  </popup>"
362            "  <popup name='ScriptPopupMenu'>"
363            "    <menuitem action='AddScriptGroup'/>"
364            "    <menuitem action='AddScript'/>"
365            "    <menuitem action='EditScript'/>"
366            "    <separator/>"
367            "    <menuitem action='RemoveScript'/>"
368            "  </popup>"
369          "</ui>";          "</ui>";
370      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
371    
# Line 329  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 369  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 378  MainWindow::MainWindow() : Line 474  MainWindow::MainWindow() :
474          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
475      );      );
476    
477        // create scripts treeview (including its data model)
478        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
479        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
480        m_TreeViewScripts.set_tooltip_text(_(
481            "Note: instrument scripts are a LinuxSampler extension of the gig "
482            "format. This feature will not work with the GigaStudio software!"
483        ));
484        // m_TreeViewScripts.set_reorderable();
485        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
486        m_TreeViewScripts.set_headers_visible(false);
487        m_TreeViewScripts.signal_button_press_event().connect_notify(
488            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
489        );
490        m_refScriptsTreeModel->signal_row_changed().connect(
491            sigc::mem_fun(*this, &MainWindow::script_name_changed)
492        );
493    
494        // establish drag&drop between scripts tree view and ScriptSlots window
495        std::vector<Gtk::TargetEntry> drag_target_gig_script;
496        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
497        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
498        m_TreeViewScripts.signal_drag_begin().connect(
499            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
500        );
501        m_TreeViewScripts.signal_drag_data_get().connect(
502            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
503        );
504    
505      // establish drag&drop between samples tree view and dimension region 'Sample' text entry      // establish drag&drop between samples tree view and dimension region 'Sample' text entry
506      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
507      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 411  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 536  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 634  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 648  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 1045  void MainWindow::on_action_help_about() Line 1177  void MainWindow::on_action_help_about()
1177          _(          _(
1178              "Gigedit is released under the GNU General Public License.\n"              "Gigedit is released under the GNU General Public License.\n"
1179              "\n"              "\n"
1180              "Please notice that this is still a very young instrument editor. "              "This program is distributed WITHOUT ANY WARRANTY; So better "
1181              "So better backup your Gigasampler files before editing them with "              "backup your Gigasampler/GigaStudio files before editing them with "
1182              "this application.\n"              "this application.\n"
1183              "\n"              "\n"
1184              "Please report bugs to: http://bugs.linuxsampler.org"              "Please report bugs to: http://bugs.linuxsampler.org"
# Line 1154  void PropDialog::set_file(gig::File* fil Line 1286  void PropDialog::set_file(gig::File* fil
1286      }      }
1287      std::vector<const char*> texts;      std::vector<const char*> texts;
1288      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());      for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1289      texts.push_back(NULL); values.push_back(NULL);      texts.push_back(NULL); values.push_back(0);
1290      eFileFormat.set_choices(&texts[0], &values[0]);      eFileFormat.set_choices(&texts[0], &values[0]);
1291      eFileFormat.set_value(major);      eFileFormat.set_value(major);
1292  }  }
# Line 1295  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 1321  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 1339  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      }      }
1503        
1504        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1505            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1506    
1507            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1508            Gtk::TreeModel::Row rowGroup = *iterGroup;
1509            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1510            rowGroup[m_ScriptsModel.m_col_group]  = group;
1511            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1512            for (int s = 0; group->GetScript(s); ++s) {
1513                gig::Script* script = group->GetScript(s);
1514    
1515                Gtk::TreeModel::iterator iterScript =
1516                    m_refScriptsTreeModel->append(rowGroup.children());
1517                Gtk::TreeModel::Row rowScript = *iterScript;
1518                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1519                rowScript[m_ScriptsModel.m_col_script] = script;
1520                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1521            }
1522        }
1523        // unfold all sample groups & script groups by default
1524        m_TreeViewSamples.expand_all();
1525        m_TreeViewScripts.expand_all();
1526    
1527      file = gig;      file = gig;
1528    
# Line 1410  void MainWindow::show_midi_rules() Line 1591  void MainWindow::show_midi_rules()
1591      }      }
1592  }  }
1593    
1594    void MainWindow::show_script_slots() {
1595        if (!file) return;
1596        // get selected instrument
1597        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1598        Gtk::TreeModel::iterator it = sel->get_selected();
1599        if (!it) return;
1600        Gtk::TreeModel::Row row = *it;
1601        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1602        if (!instrument) return;
1603    
1604        ScriptSlots* window = new ScriptSlots;
1605        window->setInstrument(instrument);
1606        //window->reparent(*this);
1607        window->show();
1608    }
1609    
1610  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1611      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1612          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1457  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 1493  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    
1727    void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1728        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1729            Gtk::Menu* script_popup =
1730                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1731            // update enabled/disabled state of sample popup items
1732            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1733            Gtk::TreeModel::iterator it = sel->get_selected();
1734            bool group_selected  = false;
1735            bool script_selected = false;
1736            if (it) {
1737                Gtk::TreeModel::Row row = *it;
1738                group_selected  = row[m_ScriptsModel.m_col_group];
1739                script_selected = row[m_ScriptsModel.m_col_script];
1740            }
1741            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1742                set_sensitive(group_selected || script_selected);
1743            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1744                set_sensitive(file);
1745            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1746                set_sensitive(script_selected);    
1747            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1748                set_sensitive(group_selected || script_selected);
1749            // show sample popup
1750            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    
1763  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1764      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
# Line 1653  void MainWindow::on_action_sample_proper Line 1906  void MainWindow::on_action_sample_proper
1906      msg.run();      msg.run();
1907  }  }
1908    
1909    void MainWindow::on_action_add_script_group() {
1910        static int __script_indexer = 0;
1911        if (!file) return;
1912        gig::ScriptGroup* group = file->AddScriptGroup();
1913        group->Name = gig_from_utf8(_("Unnamed Group"));
1914        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1915        __script_indexer++;
1916        // update sample tree view
1917        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1918        Gtk::TreeModel::Row rowGroup = *iterGroup;
1919        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1920        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1921        rowGroup[m_ScriptsModel.m_col_group] = group;
1922        file_changed();
1923    }
1924    
1925    void MainWindow::on_action_add_script() {
1926        if (!file) return;
1927        // get selected group
1928        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1929        Gtk::TreeModel::iterator it = sel->get_selected();
1930        if (!it) return;
1931        Gtk::TreeModel::Row row = *it;
1932        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1933        if (!group) { // not a group, but a script is selected (probably)
1934            gig::Script* script = row[m_ScriptsModel.m_col_script];
1935            if (!script) return;
1936            it = row.parent(); // resolve parent (that is the script's group)
1937            if (!it) return;
1938            row = *it;
1939            group = row[m_ScriptsModel.m_col_group];
1940            if (!group) return;
1941        }
1942    
1943        // add a new script to the .gig file
1944        gig::Script* script = group->AddScript();    
1945        Glib::ustring name = _("Unnamed Script");
1946        script->Name = gig_from_utf8(name);
1947    
1948        // add script to the tree view
1949        Gtk::TreeModel::iterator iterScript =
1950            m_refScriptsTreeModel->append(row.children());
1951        Gtk::TreeModel::Row rowScript = *iterScript;
1952        rowScript[m_ScriptsModel.m_col_name] = name;
1953        rowScript[m_ScriptsModel.m_col_script] = script;
1954        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1955    
1956        // unfold group of new script item in treeview
1957        Gtk::TreeModel::Path path(iterScript);
1958        m_TreeViewScripts.expand_to_path(path);
1959    }
1960    
1961    void MainWindow::on_action_edit_script() {
1962        if (!file) return;
1963        // get selected script
1964        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1965        Gtk::TreeModel::iterator it = sel->get_selected();
1966        if (!it) return;
1967        Gtk::TreeModel::Row row = *it;
1968        gig::Script* script = row[m_ScriptsModel.m_col_script];
1969        if (!script) return;
1970    
1971        ScriptEditor* editor = new ScriptEditor;
1972        editor->setScript(script);
1973        //editor->reparent(*this);
1974        editor->show();
1975    }
1976    
1977    void MainWindow::on_action_remove_script() {
1978        if (!file) return;
1979        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1980        Gtk::TreeModel::iterator it = sel->get_selected();
1981        if (it) {
1982            Gtk::TreeModel::Row row = *it;
1983            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1984            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1985            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1986            try {
1987                // remove script group or script from the gig file
1988                if (group) {
1989                    // notify everybody that we're going to remove these samples
1990    //TODO:         scripts_to_be_removed_signal.emit(members);
1991                    // delete the group in the .gig file including the
1992                    // samples that belong to the group
1993                    file->DeleteScriptGroup(group);
1994                    // notify that we're done with removal
1995    //TODO:         scripts_removed_signal.emit();
1996                    file_changed();
1997                } else if (script) {
1998                    // notify everybody that we're going to remove this sample
1999    //TODO:         std::list<gig::Script*> lscripts;
2000    //TODO:         lscripts.push_back(script);
2001    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2002                    // remove sample from the .gig file
2003                    script->GetGroup()->DeleteScript(script);
2004                    // notify that we're done with removal
2005    //TODO:         scripts_removed_signal.emit();
2006                    dimreg_changed();
2007                    file_changed();
2008                }
2009                // remove respective row(s) from samples tree view
2010                m_refScriptsTreeModel->erase(it);
2011            } catch (RIFF::Exception e) {
2012                // pretend we're done with removal (i.e. to avoid dead locks)
2013    //TODO:     scripts_removed_signal.emit();
2014                // show error message
2015                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2016                msg.run();
2017            }
2018        }
2019    }
2020    
2021  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2022      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2023      if (!file) return;      if (!file) return;
# Line 2022  void MainWindow::on_action_remove_sample Line 2387  void MainWindow::on_action_remove_sample
2387      }      }
2388  }  }
2389    
2390    // see comment on on_sample_treeview_drag_begin()
2391    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2392    {
2393        first_call_to_drag_data_get = true;
2394    }
2395    
2396    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2397                                                       Gtk::SelectionData& selection_data, guint, guint)
2398    {
2399        if (!first_call_to_drag_data_get) return;
2400        first_call_to_drag_data_get = false;
2401    
2402        // get selected script
2403        gig::Script* script = NULL;
2404        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2405        Gtk::TreeModel::iterator it = sel->get_selected();
2406        if (it) {
2407            Gtk::TreeModel::Row row = *it;
2408            script = row[m_ScriptsModel.m_col_script];
2409        }
2410        // pass the gig::Script as pointer
2411        selection_data.set(selection_data.get_target(), 0/*unused*/,
2412                           (const guchar*)&script,
2413                           sizeof(script)/*length of data in bytes*/);
2414    }
2415    
2416  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2417  // 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
2418  // 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 2150  void MainWindow::sample_name_changed(con Line 2541  void MainWindow::sample_name_changed(con
2541      }      }
2542  }  }
2543    
2544    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2545                                         const Gtk::TreeModel::iterator& iter) {
2546        if (!iter) return;
2547        Gtk::TreeModel::Row row = *iter;
2548        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2549        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2550        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2551        gig::String gigname(gig_from_utf8(name));
2552        if (group) {
2553            if (group->Name != gigname) {
2554                group->Name = gigname;
2555                printf("script group name changed\n");
2556                file_changed();
2557            }
2558        } else if (script) {
2559            if (script->Name != gigname) {
2560                script->Name = gigname;
2561                printf("script name changed\n");
2562                file_changed();
2563            }
2564        }
2565    }
2566    
2567  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2568                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2569      if (!iter) return;      if (!iter) return;
# Line 2196  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 2356  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.2566  
changed lines
  Added in v.2627

  ViewVC Help
Powered by ViewVC