/[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 2664 by schoenebeck, Sat Jul 5 19:43:14 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());
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());
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            "Use CTRL + double click for editing a script."
482            "\n\n"
483            "Note: instrument scripts are a LinuxSampler extension of the gig "
484            "format. This feature will not work with the GigaStudio software!"
485        ));
486        // m_TreeViewScripts.set_reorderable();
487        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
488        m_TreeViewScripts.set_headers_visible(false);
489        m_TreeViewScripts.signal_button_press_event().connect_notify(
490            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
491        );
492        //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?
493        m_TreeViewScripts.signal_row_activated().connect(
494            sigc::mem_fun(*this, &MainWindow::script_double_clicked)
495        );
496        m_refScriptsTreeModel->signal_row_changed().connect(
497            sigc::mem_fun(*this, &MainWindow::script_name_changed)
498        );
499    
500        // establish drag&drop between scripts tree view and ScriptSlots window
501        std::vector<Gtk::TargetEntry> drag_target_gig_script;
502        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
503        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
504        m_TreeViewScripts.signal_drag_begin().connect(
505            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
506        );
507        m_TreeViewScripts.signal_drag_data_get().connect(
508            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
509        );
510    
511      // 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
512      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
513      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 541  MainWindow::MainWindow() :
541          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
542      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
543          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
544        sample_ref_changed_signal.connect(
545            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
546        );
547        samples_to_be_removed_signal.connect(
548            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
549        );
550    
551      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
552          sigc::hide(          sigc::hide(
# Line 536  void MainWindow::dimreg_all_dimregs_togg Line 672  void MainWindow::dimreg_all_dimregs_togg
672  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
673  {  {
674      update_dimregs();      update_dimregs();
675      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion());
676  }  }
677    
678  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
# Line 634  void MainWindow::__clear() { Line 770  void MainWindow::__clear() {
770      // clear the samples and instruments tree views      // clear the samples and instruments tree views
771      m_refTreeModel->clear();      m_refTreeModel->clear();
772      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
773        m_refScriptsTreeModel->clear();
774      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
775      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
776          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 648  void MainWindow::__refreshEntireGUI() { Line 785  void MainWindow::__refreshEntireGUI() {
785      // clear the samples and instruments tree views      // clear the samples and instruments tree views
786      m_refTreeModel->clear();      m_refTreeModel->clear();
787      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
788        m_refScriptsTreeModel->clear();
789      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
790      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
791          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 764  void MainWindow::load_instrument(gig::In Line 902  void MainWindow::load_instrument(gig::In
902      // load the instrument      // load the instrument
903      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
904      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
905      //TODO: automatically select the given instrument      // automatically select the given instrument
906        int i = 0;
907        for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument;
908             instrument = pFile->GetNextInstrument(), ++i)
909        {
910            if (instrument == instr) {
911                // select item in "instruments" tree view
912                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i)));
913                // make sure the selected item in the "instruments" tree view is
914                // visible (scroll to it)
915                m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i)));
916                // select item in instrument menu
917                {
918                    const std::vector<Gtk::Widget*> children =
919                        instrument_menu->get_children();
920                    static_cast<Gtk::RadioMenuItem*>(children[i])->set_active();
921                }
922                // update region chooser and dimension region chooser
923                m_RegionChooser.set_instrument(instr);
924                break;
925            }
926        }
927  }  }
928    
929  void MainWindow::on_loader_progress()  void MainWindow::on_loader_progress()
# Line 1045  void MainWindow::on_action_help_about() Line 1204  void MainWindow::on_action_help_about()
1204          _(          _(
1205              "Gigedit is released under the GNU General Public License.\n"              "Gigedit is released under the GNU General Public License.\n"
1206              "\n"              "\n"
1207              "Please notice that this is still a very young instrument editor. "              "This program is distributed WITHOUT ANY WARRANTY; So better "
1208              "So better backup your Gigasampler files before editing them with "              "backup your Gigasampler/GigaStudio files before editing them with "
1209              "this application.\n"              "this application.\n"
1210              "\n"              "\n"
1211              "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 1313  void PropDialog::set_file(gig::File* fil
1313      }      }
1314      std::vector<const char*> texts;      std::vector<const char*> texts;
1315      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());
1316      texts.push_back(NULL); values.push_back(NULL);      texts.push_back(NULL); values.push_back(0);
1317      eFileFormat.set_choices(&texts[0], &values[0]);      eFileFormat.set_choices(&texts[0], &values[0]);
1318      eFileFormat.set_value(major);      eFileFormat.set_value(major);
1319  }  }
# Line 1295  void MainWindow::file_changed() Line 1454  void MainWindow::file_changed()
1454      }      }
1455  }  }
1456    
1457    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1458        sample_ref_count.clear();
1459        
1460        if (!gig) return;
1461    
1462        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1463             instrument = gig->GetNextInstrument())
1464        {
1465            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1466                 rgn = instrument->GetNextRegion())
1467            {
1468                for (int i = 0; i < 256; ++i) {
1469                    if (!rgn->pDimensionRegions[i]) continue;
1470                    if (rgn->pDimensionRegions[i]->pSample) {
1471                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1472                    }
1473                }
1474            }
1475        }
1476    }
1477    
1478  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1479  {  {
1480      file = 0;      file = 0;
# Line 1321  void MainWindow::load_gig(gig::File* gig Line 1501  void MainWindow::load_gig(gig::File* gig
1501          add_instrument_to_menu(name);          add_instrument_to_menu(name);
1502      }      }
1503      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1504      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show();
1505    
1506        updateSampleRefCountMap(gig);
1507    
1508      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1509          if (group->Name != "") {          if (group->Name != "") {
# Line 1339  void MainWindow::load_gig(gig::File* gig Line 1521  void MainWindow::load_gig(gig::File* gig
1521                      gig_to_utf8(sample->pInfo->Name);                      gig_to_utf8(sample->pInfo->Name);
1522                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1523                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1524                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1525                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1526                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
1527              }              }
1528          }          }
1529      }      }
1530        
1531        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1532            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1533    
1534            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1535            Gtk::TreeModel::Row rowGroup = *iterGroup;
1536            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1537            rowGroup[m_ScriptsModel.m_col_group]  = group;
1538            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1539            for (int s = 0; group->GetScript(s); ++s) {
1540                gig::Script* script = group->GetScript(s);
1541    
1542                Gtk::TreeModel::iterator iterScript =
1543                    m_refScriptsTreeModel->append(rowGroup.children());
1544                Gtk::TreeModel::Row rowScript = *iterScript;
1545                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1546                rowScript[m_ScriptsModel.m_col_script] = script;
1547                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1548            }
1549        }
1550        // unfold all sample groups & script groups by default
1551        m_TreeViewSamples.expand_all();
1552        m_TreeViewScripts.expand_all();
1553    
1554      file = gig;      file = gig;
1555    
# Line 1410  void MainWindow::show_midi_rules() Line 1618  void MainWindow::show_midi_rules()
1618      }      }
1619  }  }
1620    
1621    void MainWindow::show_script_slots() {
1622        if (!file) return;
1623        // get selected instrument
1624        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1625        Gtk::TreeModel::iterator it = sel->get_selected();
1626        if (!it) return;
1627        Gtk::TreeModel::Row row = *it;
1628        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1629        if (!instrument) return;
1630    
1631        ScriptSlots* window = new ScriptSlots;
1632        window->setInstrument(instrument);
1633        //window->reparent(*this);
1634        window->show();
1635    }
1636    
1637  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1638      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1639          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 1681  void MainWindow::on_button_release(GdkEv
1681          show_instr_props();          show_instr_props();
1682      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1683          // gig v2 files have no midi rules          // gig v2 files have no midi rules
1684            const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
1685            static_cast<Gtk::MenuItem*>(
1686                uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive(
1687                    bEnabled
1688                );
1689          static_cast<Gtk::MenuItem*>(          static_cast<Gtk::MenuItem*>(
1690              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(              uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1691                  !(file->pVersion && file->pVersion->major == 2));                  bEnabled
1692                );
1693          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1694      }      }
1695  }  }
# Line 1493  void MainWindow::on_sample_treeview_butt Line 1723  void MainWindow::on_sample_treeview_butt
1723              group_selected  = row[m_SamplesModel.m_col_group];              group_selected  = row[m_SamplesModel.m_col_group];
1724              sample_selected = row[m_SamplesModel.m_col_sample];              sample_selected = row[m_SamplesModel.m_col_sample];
1725          }          }
1726            
1727                
1728          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->
1729              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1730          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->
1731              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1732          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1733              set_sensitive(file);              set_sensitive(file);
1734            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
1735                set_sensitive(sample_selected);
1736          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1737              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1738          // show sample popup          // show sample popup
1739          sample_popup->popup(button->button, button->time);          sample_popup->popup(button->button, button->time);
1740    
1741            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))->
1742                set_sensitive(group_selected || sample_selected);
1743            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))->
1744                set_sensitive(group_selected || sample_selected);
1745            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))->
1746                set_sensitive(file);
1747            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))->
1748                set_sensitive(sample_selected);
1749            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))->
1750                set_sensitive(group_selected || sample_selected);
1751      }      }
1752  }  }
1753    
1754    void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1755        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1756            Gtk::Menu* script_popup =
1757                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1758            // update enabled/disabled state of sample popup items
1759            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1760            Gtk::TreeModel::iterator it = sel->get_selected();
1761            bool group_selected  = false;
1762            bool script_selected = false;
1763            if (it) {
1764                Gtk::TreeModel::Row row = *it;
1765                group_selected  = row[m_ScriptsModel.m_col_group];
1766                script_selected = row[m_ScriptsModel.m_col_script];
1767            }
1768            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1769                set_sensitive(group_selected || script_selected);
1770            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1771                set_sensitive(file);
1772            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1773                set_sensitive(script_selected);    
1774            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1775                set_sensitive(group_selected || script_selected);
1776            // show sample popup
1777            script_popup->popup(button->button, button->time);
1778    
1779            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))->
1780                set_sensitive(group_selected || script_selected);
1781            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))->
1782                set_sensitive(file);
1783            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))->
1784                set_sensitive(script_selected);    
1785            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))->
1786                set_sensitive(group_selected || script_selected);
1787        }
1788    }
1789    
1790  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1791      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
# Line 1653  void MainWindow::on_action_sample_proper Line 1933  void MainWindow::on_action_sample_proper
1933      msg.run();      msg.run();
1934  }  }
1935    
1936    void MainWindow::on_action_add_script_group() {
1937        static int __script_indexer = 0;
1938        if (!file) return;
1939        gig::ScriptGroup* group = file->AddScriptGroup();
1940        group->Name = gig_from_utf8(_("Unnamed Group"));
1941        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1942        __script_indexer++;
1943        // update sample tree view
1944        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1945        Gtk::TreeModel::Row rowGroup = *iterGroup;
1946        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1947        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1948        rowGroup[m_ScriptsModel.m_col_group] = group;
1949        file_changed();
1950    }
1951    
1952    void MainWindow::on_action_add_script() {
1953        if (!file) return;
1954        // get selected group
1955        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1956        Gtk::TreeModel::iterator it = sel->get_selected();
1957        if (!it) return;
1958        Gtk::TreeModel::Row row = *it;
1959        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1960        if (!group) { // not a group, but a script is selected (probably)
1961            gig::Script* script = row[m_ScriptsModel.m_col_script];
1962            if (!script) return;
1963            it = row.parent(); // resolve parent (that is the script's group)
1964            if (!it) return;
1965            row = *it;
1966            group = row[m_ScriptsModel.m_col_group];
1967            if (!group) return;
1968        }
1969    
1970        // add a new script to the .gig file
1971        gig::Script* script = group->AddScript();    
1972        Glib::ustring name = _("Unnamed Script");
1973        script->Name = gig_from_utf8(name);
1974    
1975        // add script to the tree view
1976        Gtk::TreeModel::iterator iterScript =
1977            m_refScriptsTreeModel->append(row.children());
1978        Gtk::TreeModel::Row rowScript = *iterScript;
1979        rowScript[m_ScriptsModel.m_col_name] = name;
1980        rowScript[m_ScriptsModel.m_col_script] = script;
1981        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1982    
1983        // unfold group of new script item in treeview
1984        Gtk::TreeModel::Path path(iterScript);
1985        m_TreeViewScripts.expand_to_path(path);
1986    }
1987    
1988    void MainWindow::on_action_edit_script() {
1989        if (!file) return;
1990        // get selected script
1991        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1992        Gtk::TreeModel::iterator it = sel->get_selected();
1993        if (!it) return;
1994        Gtk::TreeModel::Row row = *it;
1995        gig::Script* script = row[m_ScriptsModel.m_col_script];
1996        if (!script) return;
1997    
1998        ScriptEditor* editor = new ScriptEditor;
1999        editor->setScript(script);
2000        //editor->reparent(*this);
2001        editor->show();
2002    }
2003    
2004    void MainWindow::on_action_remove_script() {
2005        if (!file) return;
2006        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2007        Gtk::TreeModel::iterator it = sel->get_selected();
2008        if (it) {
2009            Gtk::TreeModel::Row row = *it;
2010            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2011            gig::Script* script     = row[m_ScriptsModel.m_col_script];
2012            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2013            try {
2014                // remove script group or script from the gig file
2015                if (group) {
2016                    // notify everybody that we're going to remove these samples
2017    //TODO:         scripts_to_be_removed_signal.emit(members);
2018                    // delete the group in the .gig file including the
2019                    // samples that belong to the group
2020                    file->DeleteScriptGroup(group);
2021                    // notify that we're done with removal
2022    //TODO:         scripts_removed_signal.emit();
2023                    file_changed();
2024                } else if (script) {
2025                    // notify everybody that we're going to remove this sample
2026    //TODO:         std::list<gig::Script*> lscripts;
2027    //TODO:         lscripts.push_back(script);
2028    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
2029                    // remove sample from the .gig file
2030                    script->GetGroup()->DeleteScript(script);
2031                    // notify that we're done with removal
2032    //TODO:         scripts_removed_signal.emit();
2033                    dimreg_changed();
2034                    file_changed();
2035                }
2036                // remove respective row(s) from samples tree view
2037                m_refScriptsTreeModel->erase(it);
2038            } catch (RIFF::Exception e) {
2039                // pretend we're done with removal (i.e. to avoid dead locks)
2040    //TODO:     scripts_removed_signal.emit();
2041                // show error message
2042                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
2043                msg.run();
2044            }
2045        }
2046    }
2047    
2048  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
2049      static int __sample_indexer = 0;      static int __sample_indexer = 0;
2050      if (!file) return;      if (!file) return;
# Line 2022  void MainWindow::on_action_remove_sample Line 2414  void MainWindow::on_action_remove_sample
2414      }      }
2415  }  }
2416    
2417    // see comment on on_sample_treeview_drag_begin()
2418    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2419    {
2420        first_call_to_drag_data_get = true;
2421    }
2422    
2423    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2424                                                       Gtk::SelectionData& selection_data, guint, guint)
2425    {
2426        if (!first_call_to_drag_data_get) return;
2427        first_call_to_drag_data_get = false;
2428    
2429        // get selected script
2430        gig::Script* script = NULL;
2431        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2432        Gtk::TreeModel::iterator it = sel->get_selected();
2433        if (it) {
2434            Gtk::TreeModel::Row row = *it;
2435            script = row[m_ScriptsModel.m_col_script];
2436        }
2437        // pass the gig::Script as pointer
2438        selection_data.set(selection_data.get_target(), 0/*unused*/,
2439                           (const guchar*)&script,
2440                           sizeof(script)/*length of data in bytes*/);
2441    }
2442    
2443  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2444  // 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
2445  // 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 2568  void MainWindow::sample_name_changed(con
2568      }      }
2569  }  }
2570    
2571    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2572                                         const Gtk::TreeModel::iterator& iter) {
2573        if (!iter) return;
2574        Gtk::TreeModel::Row row = *iter;
2575        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2576        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2577        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2578        gig::String gigname(gig_from_utf8(name));
2579        if (group) {
2580            if (group->Name != gigname) {
2581                group->Name = gigname;
2582                printf("script group name changed\n");
2583                file_changed();
2584            }
2585        } else if (script) {
2586            if (script->Name != gigname) {
2587                script->Name = gigname;
2588                printf("script name changed\n");
2589                file_changed();
2590            }
2591        }
2592    }
2593    
2594    void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path,
2595                                           Gtk::TreeViewColumn* column)
2596    {
2597        Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path);
2598        if (!iter) return;
2599        Gtk::TreeModel::Row row = *iter;
2600        gig::Script* script = row[m_ScriptsModel.m_col_script];
2601        if (!script) return;
2602    
2603        ScriptEditor* editor = new ScriptEditor;
2604        editor->setScript(script);
2605        //editor->reparent(*this);
2606        editor->show();
2607    }
2608    
2609  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2610                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2611      if (!iter) return;      if (!iter) return;
# Line 2196  void MainWindow::on_action_combine_instr Line 2652  void MainWindow::on_action_combine_instr
2652      delete d;      delete d;
2653  }  }
2654    
2655    void MainWindow::on_action_view_references() {
2656        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2657        Gtk::TreeModel::iterator it = sel->get_selected();
2658        if (!it) return;
2659        Gtk::TreeModel::Row row = *it;
2660        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2661        if (!sample) return;
2662    
2663        ReferencesView* d = new ReferencesView(*this);
2664        d->setSample(sample);
2665        d->show_all();
2666        d->resize(500, 400);
2667        d->run();
2668        delete d;
2669    }
2670    
2671  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2672      struct _Source {      struct _Source {
2673          std::vector<RIFF::File*> riffs;          std::vector<RIFF::File*> riffs;
# Line 2356  void MainWindow::set_file_is_shared(bool Line 2828  void MainWindow::set_file_is_shared(bool
2828      }      }
2829  }  }
2830    
2831    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2832        if (!sample) return;
2833        sample_ref_count[sample] += offset;
2834        const int refcount = sample_ref_count[sample];
2835    
2836        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2837        for (int g = 0; g < model->children().size(); ++g) {
2838            Gtk::TreeModel::Row rowGroup = model->children()[g];
2839            for (int s = 0; s < rowGroup.children().size(); ++s) {
2840                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2841                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2842                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2843                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red";
2844            }
2845        }
2846    }
2847    
2848    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2849        on_sample_ref_count_incremented(oldSample, -1);
2850        on_sample_ref_count_incremented(newSample, +1);
2851    }
2852    
2853    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2854        // just in case a new sample is added later with exactly the same memory
2855        // address, which would lead to incorrect refcount if not deleted here
2856        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2857             it != samples.end(); it != samples.end())
2858        {
2859            sample_ref_count.erase(*it);
2860        }
2861    }
2862    
2863    void MainWindow::show_samples_tab() {
2864        m_TreeViewNotebook.set_current_page(0);
2865    }
2866    
2867    void MainWindow::show_intruments_tab() {
2868        m_TreeViewNotebook.set_current_page(1);
2869    }
2870    
2871    void MainWindow::show_scripts_tab() {
2872        m_TreeViewNotebook.set_current_page(2);
2873    }
2874    
2875  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2876      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2877  }  }

Legend:
Removed from v.2566  
changed lines
  Added in v.2664

  ViewVC Help
Powered by ViewVC