/[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 2553 by schoenebeck, Wed May 14 19:57:56 2014 UTC revision 2621 by schoenebeck, Wed Jun 11 16:46:27 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 "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
51  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
52    
# Line 78  MainWindow::MainWindow() : Line 80  MainWindow::MainWindow() :
80      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
81      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
82    
83        m_ScrolledWindowScripts.add(m_TreeViewScripts);
84        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
85    
86    
87      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
88    
# Line 98  MainWindow::MainWindow() : Line 103  MainWindow::MainWindow() :
103    
104      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
105      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
106        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
107    
108      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
109    
# Line 130  MainWindow::MainWindow() : Line 135  MainWindow::MainWindow() :
135                       sigc::mem_fun(                       sigc::mem_fun(
136                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
137      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
138                                           _("_Midi Rules")),                                           _("_Midi Rules...")),
139                       sigc::mem_fun(                       sigc::mem_fun(
140                           *this, &MainWindow::show_midi_rules));                           *this, &MainWindow::show_midi_rules));
141        actionGroup->add(Gtk::Action::create("ScriptSlots",
142                                             _("_Script Slots...")),
143                         sigc::mem_fun(
144                             *this, &MainWindow::show_script_slots));
145      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
146                       sigc::mem_fun(                       sigc::mem_fun(
147                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
# Line 231  MainWindow::MainWindow() : Line 240  MainWindow::MainWindow() :
240                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
241          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)
242      );      );
243        
244        // script right-click popup actions
245        actionGroup->add(
246            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
247            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
248        );
249        actionGroup->add(
250            Gtk::Action::create("AddScript", _("Add _Script")),
251            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
252        );
253        actionGroup->add(
254            Gtk::Action::create("EditScript", _("_Edit Script...")),
255            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
256        );
257        actionGroup->add(
258            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
259            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
260        );
261    
262      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
263      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 274  MainWindow::MainWindow() : Line 301  MainWindow::MainWindow() :
301          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
302          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
303          "    <menuitem action='MidiRules'/>"          "    <menuitem action='MidiRules'/>"
304            "    <menuitem action='ScriptSlots'/>"
305          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
306          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
307          "    <separator/>"          "    <separator/>"
# Line 287  MainWindow::MainWindow() : Line 315  MainWindow::MainWindow() :
315          "    <separator/>"          "    <separator/>"
316          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
317          "  </popup>"          "  </popup>"
318            "  <popup name='ScriptPopupMenu'>"
319            "    <menuitem action='AddScriptGroup'/>"
320            "    <menuitem action='AddScript'/>"
321            "    <menuitem action='EditScript'/>"
322            "    <separator/>"
323            "    <menuitem action='RemoveScript'/>"
324            "  </popup>"
325          "</ui>";          "</ui>";
326      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
327    
# Line 369  MainWindow::MainWindow() : Line 404  MainWindow::MainWindow() :
404      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
405      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."));
406      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
407      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
408      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
409        {
410            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
411            Gtk::CellRendererText* cellrenderer =
412                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
413            column->add_attribute(
414                cellrenderer->property_foreground(), m_SamplesModel.m_color
415            );
416        }
417        {
418            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
419            Gtk::CellRendererText* cellrenderer =
420                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
421            column->add_attribute(
422                cellrenderer->property_foreground(), m_SamplesModel.m_color
423            );
424        }
425        m_TreeViewSamples.set_headers_visible(true);
426      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
427          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
428      );      );
# Line 378  MainWindow::MainWindow() : Line 430  MainWindow::MainWindow() :
430          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
431      );      );
432    
433        // create scripts treeview (including its data model)
434        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
435        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
436        m_TreeViewScripts.set_tooltip_text(_(
437            "Note: instrument scripts are a LinuxSampler extension of the gig "
438            "format. This feature will not work with the GigaStudio software!"
439        ));
440        // m_TreeViewScripts.set_reorderable();
441        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
442        m_TreeViewScripts.set_headers_visible(false);
443        m_TreeViewScripts.signal_button_press_event().connect_notify(
444            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
445        );
446        m_refScriptsTreeModel->signal_row_changed().connect(
447            sigc::mem_fun(*this, &MainWindow::script_name_changed)
448        );
449    
450        // establish drag&drop between scripts tree view and ScriptSlots window
451        std::vector<Gtk::TargetEntry> drag_target_gig_script;
452        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
453        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
454        m_TreeViewScripts.signal_drag_begin().connect(
455            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
456        );
457        m_TreeViewScripts.signal_drag_data_get().connect(
458            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
459        );
460    
461      // 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
462      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
463      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 491  MainWindow::MainWindow() :
491          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
492      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
493          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
494        sample_ref_changed_signal.connect(
495            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
496        );
497        samples_to_be_removed_signal.connect(
498            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
499        );
500    
501      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
502          sigc::hide(          sigc::hide(
# Line 634  void MainWindow::__clear() { Line 720  void MainWindow::__clear() {
720      // clear the samples and instruments tree views      // clear the samples and instruments tree views
721      m_refTreeModel->clear();      m_refTreeModel->clear();
722      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
723        m_refScriptsTreeModel->clear();
724      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
725      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
726          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 648  void MainWindow::__refreshEntireGUI() { Line 735  void MainWindow::__refreshEntireGUI() {
735      // clear the samples and instruments tree views      // clear the samples and instruments tree views
736      m_refTreeModel->clear();      m_refTreeModel->clear();
737      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
738        m_refScriptsTreeModel->clear();
739      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
740      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
741          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 1058  void MainWindow::on_action_help_about() Line 1146  void MainWindow::on_action_help_about()
1146  }  }
1147    
1148  PropDialog::PropDialog()  PropDialog::PropDialog()
1149      : eName(_("Name")),      : eFileFormat(_("File Format")),
1150          eName(_("Name")),
1151        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1152        eComments(_("Comments")),        eComments(_("Comments")),
1153        eProduct(_("Product")),        eProduct(_("Product")),
# Line 1075  PropDialog::PropDialog() Line 1164  PropDialog::PropDialog()
1164        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1165        eSubject(_("Subject")),        eSubject(_("Subject")),
1166        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1167        table(2, 1)        table(2, 1),
1168          m_file(NULL)
1169  {  {
1170      set_title(_("File Properties"));      set_title(_("File Properties"));
1171      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1097  PropDialog::PropDialog() Line 1187  PropDialog::PropDialog()
1187      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1188      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1189    
1190        table.add(eFileFormat);
1191      table.add(eName);      table.add(eName);
1192      table.add(eCreationDate);      table.add(eCreationDate);
1193      table.add(eComments);      table.add(eComments);
# Line 1127  PropDialog::PropDialog() Line 1218  PropDialog::PropDialog()
1218      quitButton.grab_focus();      quitButton.grab_focus();
1219      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1220          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1221        eFileFormat.signal_value_changed().connect(
1222            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1223    
1224      quitButton.show();      quitButton.show();
1225      vbox.show();      vbox.show();
1226      show_all_children();      show_all_children();
1227  }  }
1228    
1229    void PropDialog::set_file(gig::File* file)
1230    {
1231        m_file = file;
1232    
1233        // update file format version combo box
1234        const std::string sGiga = "Gigasampler/GigaStudio v";
1235        const int major = file->pVersion->major;
1236        std::vector<std::string> txts;
1237        std::vector<int> values;
1238        txts.push_back(sGiga + "2"); values.push_back(2);
1239        txts.push_back(sGiga + "3/v4"); values.push_back(3);
1240        if (major != 2 && major != 3) {
1241            txts.push_back(sGiga + ToString(major)); values.push_back(major);
1242        }
1243        std::vector<const char*> texts;
1244        for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1245        texts.push_back(NULL); values.push_back(0);
1246        eFileFormat.set_choices(&texts[0], &values[0]);
1247        eFileFormat.set_value(major);
1248    }
1249    
1250    void PropDialog::onFileFormatChanged() {
1251        const int major = eFileFormat.get_value();
1252        if (m_file) m_file->pVersion->major = major;
1253    }
1254    
1255  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1256  {  {
1257      update(info);      update(info);
# Line 1264  void MainWindow::file_changed() Line 1383  void MainWindow::file_changed()
1383      }      }
1384  }  }
1385    
1386    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1387        sample_ref_count.clear();
1388        
1389        if (!gig) return;
1390    
1391        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1392             instrument = gig->GetNextInstrument())
1393        {
1394            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1395                 rgn = instrument->GetNextRegion())
1396            {
1397                for (int i = 0; i < 256; ++i) {
1398                    if (!rgn->pDimensionRegions[i]) continue;
1399                    if (rgn->pDimensionRegions[i]->pSample) {
1400                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1401                    }
1402                }
1403            }
1404        }
1405    }
1406    
1407  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1408  {  {
1409      file = 0;      file = 0;
# Line 1274  void MainWindow::load_gig(gig::File* gig Line 1414  void MainWindow::load_gig(gig::File* gig
1414      file_has_name = filename;      file_has_name = filename;
1415      file_is_changed = false;      file_is_changed = false;
1416    
1417        propDialog.set_file(gig);
1418      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1419    
1420      instrument_name_connection.block();      instrument_name_connection.block();
# Line 1291  void MainWindow::load_gig(gig::File* gig Line 1432  void MainWindow::load_gig(gig::File* gig
1432      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1433      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1434    
1435        updateSampleRefCountMap(gig);
1436    
1437      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1438          if (group->Name != "") {          if (group->Name != "") {
1439              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
# Line 1307  void MainWindow::load_gig(gig::File* gig Line 1450  void MainWindow::load_gig(gig::File* gig
1450                      gig_to_utf8(sample->pInfo->Name);                      gig_to_utf8(sample->pInfo->Name);
1451                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1452                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1453                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1454                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1455                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
1456              }              }
1457          }          }
1458      }      }
1459        
1460        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1461            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1462    
1463            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1464            Gtk::TreeModel::Row rowGroup = *iterGroup;
1465            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1466            rowGroup[m_ScriptsModel.m_col_group]  = group;
1467            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1468            for (int s = 0; group->GetScript(s); ++s) {
1469                gig::Script* script = group->GetScript(s);
1470    
1471                Gtk::TreeModel::iterator iterScript =
1472                    m_refScriptsTreeModel->append(rowGroup.children());
1473                Gtk::TreeModel::Row rowScript = *iterScript;
1474                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1475                rowScript[m_ScriptsModel.m_col_script] = script;
1476                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1477            }
1478        }
1479        // unfold all script groups by default
1480        m_TreeViewScripts.expand_all();
1481    
1482      file = gig;      file = gig;
1483    
# Line 1378  void MainWindow::show_midi_rules() Line 1546  void MainWindow::show_midi_rules()
1546      }      }
1547  }  }
1548    
1549    void MainWindow::show_script_slots() {
1550        if (!file) return;
1551        // get selected instrument
1552        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1553        Gtk::TreeModel::iterator it = sel->get_selected();
1554        if (!it) return;
1555        Gtk::TreeModel::Row row = *it;
1556        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1557        if (!instrument) return;
1558    
1559        ScriptSlots* window = new ScriptSlots;
1560        window->setInstrument(instrument);
1561        //window->reparent(*this);
1562        window->show();
1563    }
1564    
1565  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1566      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1567          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1474  void MainWindow::on_sample_treeview_butt Line 1658  void MainWindow::on_sample_treeview_butt
1658      }      }
1659  }  }
1660    
1661    void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1662        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1663            Gtk::Menu* script_popup =
1664                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1665            // update enabled/disabled state of sample popup items
1666            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1667            Gtk::TreeModel::iterator it = sel->get_selected();
1668            bool group_selected  = false;
1669            bool script_selected = false;
1670            if (it) {
1671                Gtk::TreeModel::Row row = *it;
1672                group_selected  = row[m_ScriptsModel.m_col_group];
1673                script_selected = row[m_ScriptsModel.m_col_script];
1674            }
1675            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1676                set_sensitive(group_selected || script_selected);
1677            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1678                set_sensitive(file);
1679            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1680                set_sensitive(script_selected);    
1681            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1682                set_sensitive(group_selected || script_selected);
1683            // show sample popup
1684            script_popup->popup(button->button, button->time);
1685        }
1686    }
1687    
1688  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1689      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
# Line 1621  void MainWindow::on_action_sample_proper Line 1831  void MainWindow::on_action_sample_proper
1831      msg.run();      msg.run();
1832  }  }
1833    
1834    void MainWindow::on_action_add_script_group() {
1835        static int __script_indexer = 0;
1836        if (!file) return;
1837        gig::ScriptGroup* group = file->AddScriptGroup();
1838        group->Name = gig_from_utf8(_("Unnamed Group"));
1839        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1840        __script_indexer++;
1841        // update sample tree view
1842        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1843        Gtk::TreeModel::Row rowGroup = *iterGroup;
1844        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1845        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1846        rowGroup[m_ScriptsModel.m_col_group] = group;
1847        file_changed();
1848    }
1849    
1850    void MainWindow::on_action_add_script() {
1851        if (!file) return;
1852        // get selected group
1853        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1854        Gtk::TreeModel::iterator it = sel->get_selected();
1855        if (!it) return;
1856        Gtk::TreeModel::Row row = *it;
1857        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1858        if (!group) { // not a group, but a script is selected (probably)
1859            gig::Script* script = row[m_ScriptsModel.m_col_script];
1860            if (!script) return;
1861            it = row.parent(); // resolve parent (that is the script's group)
1862            if (!it) return;
1863            row = *it;
1864            group = row[m_ScriptsModel.m_col_group];
1865            if (!group) return;
1866        }
1867    
1868        // add a new script to the .gig file
1869        gig::Script* script = group->AddScript();    
1870        Glib::ustring name = _("Unnamed Script");
1871        script->Name = gig_from_utf8(name);
1872    
1873        // add script to the tree view
1874        Gtk::TreeModel::iterator iterScript =
1875            m_refScriptsTreeModel->append(row.children());
1876        Gtk::TreeModel::Row rowScript = *iterScript;
1877        rowScript[m_ScriptsModel.m_col_name] = name;
1878        rowScript[m_ScriptsModel.m_col_script] = script;
1879        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1880    
1881        // unfold group of new script item in treeview
1882        Gtk::TreeModel::Path path(iterScript);
1883        m_TreeViewScripts.expand_to_path(path);
1884    }
1885    
1886    void MainWindow::on_action_edit_script() {
1887        if (!file) return;
1888        // get selected script
1889        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1890        Gtk::TreeModel::iterator it = sel->get_selected();
1891        if (!it) return;
1892        Gtk::TreeModel::Row row = *it;
1893        gig::Script* script = row[m_ScriptsModel.m_col_script];
1894        if (!script) return;
1895    
1896        ScriptEditor* editor = new ScriptEditor;
1897        editor->setScript(script);
1898        //editor->reparent(*this);
1899        editor->show();
1900    }
1901    
1902    void MainWindow::on_action_remove_script() {
1903        if (!file) return;
1904        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1905        Gtk::TreeModel::iterator it = sel->get_selected();
1906        if (it) {
1907            Gtk::TreeModel::Row row = *it;
1908            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1909            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1910            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1911            try {
1912                // remove script group or script from the gig file
1913                if (group) {
1914                    // notify everybody that we're going to remove these samples
1915    //TODO:         scripts_to_be_removed_signal.emit(members);
1916                    // delete the group in the .gig file including the
1917                    // samples that belong to the group
1918                    file->DeleteScriptGroup(group);
1919                    // notify that we're done with removal
1920    //TODO:         scripts_removed_signal.emit();
1921                    file_changed();
1922                } else if (script) {
1923                    // notify everybody that we're going to remove this sample
1924    //TODO:         std::list<gig::Script*> lscripts;
1925    //TODO:         lscripts.push_back(script);
1926    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
1927                    // remove sample from the .gig file
1928                    script->GetGroup()->DeleteScript(script);
1929                    // notify that we're done with removal
1930    //TODO:         scripts_removed_signal.emit();
1931                    dimreg_changed();
1932                    file_changed();
1933                }
1934                // remove respective row(s) from samples tree view
1935                m_refScriptsTreeModel->erase(it);
1936            } catch (RIFF::Exception e) {
1937                // pretend we're done with removal (i.e. to avoid dead locks)
1938    //TODO:     scripts_removed_signal.emit();
1939                // show error message
1940                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1941                msg.run();
1942            }
1943        }
1944    }
1945    
1946  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
1947      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1948      if (!file) return;      if (!file) return;
# Line 1990  void MainWindow::on_action_remove_sample Line 2312  void MainWindow::on_action_remove_sample
2312      }      }
2313  }  }
2314    
2315    // see comment on on_sample_treeview_drag_begin()
2316    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2317    {
2318        first_call_to_drag_data_get = true;
2319    }
2320    
2321    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2322                                                       Gtk::SelectionData& selection_data, guint, guint)
2323    {
2324        if (!first_call_to_drag_data_get) return;
2325        first_call_to_drag_data_get = false;
2326    
2327        // get selected script
2328        gig::Script* script = NULL;
2329        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2330        Gtk::TreeModel::iterator it = sel->get_selected();
2331        if (it) {
2332            Gtk::TreeModel::Row row = *it;
2333            script = row[m_ScriptsModel.m_col_script];
2334        }
2335        // pass the gig::Script as pointer
2336        selection_data.set(selection_data.get_target(), 0/*unused*/,
2337                           (const guchar*)&script,
2338                           sizeof(script)/*length of data in bytes*/);
2339    }
2340    
2341  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2342  // 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
2343  // 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 2118  void MainWindow::sample_name_changed(con Line 2466  void MainWindow::sample_name_changed(con
2466      }      }
2467  }  }
2468    
2469    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2470                                         const Gtk::TreeModel::iterator& iter) {
2471        if (!iter) return;
2472        Gtk::TreeModel::Row row = *iter;
2473        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2474        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2475        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2476        gig::String gigname(gig_from_utf8(name));
2477        if (group) {
2478            if (group->Name != gigname) {
2479                group->Name = gigname;
2480                printf("script group name changed\n");
2481                file_changed();
2482            }
2483        } else if (script) {
2484            if (script->Name != gigname) {
2485                script->Name = gigname;
2486                printf("script name changed\n");
2487                file_changed();
2488            }
2489        }
2490    }
2491    
2492  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2493                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2494      if (!iter) return;      if (!iter) return;
# Line 2324  void MainWindow::set_file_is_shared(bool Line 2695  void MainWindow::set_file_is_shared(bool
2695      }      }
2696  }  }
2697    
2698    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2699        if (!sample) return;
2700        sample_ref_count[sample] += offset;
2701        const int refcount = sample_ref_count[sample];
2702    
2703        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2704        for (int g = 0; g < model->children().size(); ++g) {
2705            Gtk::TreeModel::Row rowGroup = model->children()[g];
2706            for (int s = 0; s < rowGroup.children().size(); ++s) {
2707                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2708                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2709                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2710                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
2711            }
2712        }
2713    }
2714    
2715    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2716        on_sample_ref_count_incremented(oldSample, -1);
2717        on_sample_ref_count_incremented(newSample, +1);
2718    }
2719    
2720    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2721        // just in case a new sample is added later with exactly the same memory
2722        // address, which would lead to incorrect refcount if not deleted here
2723        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2724             it != samples.end(); it != samples.end())
2725        {
2726            sample_ref_count.erase(*it);
2727        }
2728    }
2729    
2730  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2731      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2732  }  }

Legend:
Removed from v.2553  
changed lines
  Added in v.2621

  ViewVC Help
Powered by ViewVC