/[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 2548 by schoenebeck, Tue May 13 12:17:43 2014 UTC revision 2604 by schoenebeck, Sat Jun 7 22:34:31 2014 UTC
# Line 40  Line 40 
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
43    #include <assert.h>
44    
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 "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
50  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
51    
# Line 77  MainWindow::MainWindow() : Line 79  MainWindow::MainWindow() :
79      m_ScrolledWindowSamples.add(m_TreeViewSamples);      m_ScrolledWindowSamples.add(m_TreeViewSamples);
80      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindowSamples.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
81    
82        m_ScrolledWindowScripts.add(m_TreeViewScripts);
83        m_ScrolledWindowScripts.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
84    
85    
86      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
87    
# Line 97  MainWindow::MainWindow() : Line 102  MainWindow::MainWindow() :
102    
103      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
104      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
105        m_TreeViewNotebook.append_page(m_ScrolledWindowScripts, _("Scripts"));
106    
107      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
108    
# Line 202  MainWindow::MainWindow() : Line 207  MainWindow::MainWindow() :
207          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
208      );      );
209    
210        actionGroup->add(
211            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
212            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
213        );
214    
215    
216      // sample right-click popup actions      // sample right-click popup actions
217      actionGroup->add(      actionGroup->add(
# Line 225  MainWindow::MainWindow() : Line 235  MainWindow::MainWindow() :
235                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
236          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)
237      );      );
238        
239        // script right-click popup actions
240        actionGroup->add(
241            Gtk::Action::create("AddScriptGroup", _("Add _Group")),
242            sigc::mem_fun(*this, &MainWindow::on_action_add_script_group)
243        );
244        actionGroup->add(
245            Gtk::Action::create("AddScript", _("Add _Script")),
246            sigc::mem_fun(*this, &MainWindow::on_action_add_script)
247        );
248        actionGroup->add(
249            Gtk::Action::create("EditScript", _("_Edit Script...")),
250            sigc::mem_fun(*this, &MainWindow::on_action_edit_script)
251        );
252        actionGroup->add(
253            Gtk::Action::create("RemoveScript", Gtk::Stock::REMOVE),
254            sigc::mem_fun(*this, &MainWindow::on_action_remove_script)
255        );
256    
257      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
258      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 256  MainWindow::MainWindow() : Line 284  MainWindow::MainWindow() :
284          "    </menu>"          "    </menu>"
285          "    <menu action='MenuTools'>"          "    <menu action='MenuTools'>"
286          "      <menuitem action='CombineInstruments'/>"          "      <menuitem action='CombineInstruments'/>"
287            "      <menuitem action='MergeFiles'/>"
288          "    </menu>"          "    </menu>"
289          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
290          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
# Line 280  MainWindow::MainWindow() : Line 309  MainWindow::MainWindow() :
309          "    <separator/>"          "    <separator/>"
310          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
311          "  </popup>"          "  </popup>"
312            "  <popup name='ScriptPopupMenu'>"
313            "    <menuitem action='AddScriptGroup'/>"
314            "    <menuitem action='AddScript'/>"
315            "    <menuitem action='EditScript'/>"
316            "    <separator/>"
317            "    <menuitem action='RemoveScript'/>"
318            "  </popup>"
319          "</ui>";          "</ui>";
320      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
321    
# Line 309  MainWindow::MainWindow() : Line 345  MainWindow::MainWindow() :
345              uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));              uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
346          item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));          item->set_tooltip_text(_("If checked, a warning will be shown whenever you try to use a feature which is based on a LinuxSampler extension ontop of the original gig format, which would not work with the Gigasampler/GigaStudio application."));
347      }      }
348        {
349            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
350                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
351            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
352        }
353        {
354            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
355                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
356            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
357        }
358    
359    
360      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
361          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
# Line 360  MainWindow::MainWindow() : Line 407  MainWindow::MainWindow() :
407          sigc::mem_fun(*this, &MainWindow::sample_name_changed)          sigc::mem_fun(*this, &MainWindow::sample_name_changed)
408      );      );
409    
410        // create scripts treeview (including its data model)
411        m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel);
412        m_TreeViewScripts.set_model(m_refScriptsTreeModel);
413        m_TreeViewScripts.set_tooltip_text(_(
414            "Note: instrument scripts are a LinuxSampler extension of the gig "
415            "format. This feature will not work with the GigaStudio software!"
416        ));
417        // m_TreeViewScripts.set_reorderable();
418        m_TreeViewScripts.append_column_editable("Samples", m_ScriptsModel.m_col_name);
419        m_TreeViewScripts.set_headers_visible(false);
420        m_TreeViewScripts.signal_button_press_event().connect_notify(
421            sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
422        );
423        m_refScriptsTreeModel->signal_row_changed().connect(
424            sigc::mem_fun(*this, &MainWindow::script_name_changed)
425        );
426    
427      // 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
428      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
429      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 434  MainWindow::MainWindow() : Line 498  MainWindow::MainWindow() :
498    
499      // start with a new gig file by default      // start with a new gig file by default
500      on_action_file_new();      on_action_file_new();
501    
502        // select 'Instruments' tab by default
503        // (gtk allows this only if the tab childs are visible, thats why it's here)
504        m_TreeViewNotebook.set_current_page(1);
505  }  }
506    
507  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 622  void MainWindow::__clear() { Line 690  void MainWindow::__clear() {
690      set_file_is_shared(false);      set_file_is_shared(false);
691  }  }
692    
693    void MainWindow::__refreshEntireGUI() {
694        // clear the samples and instruments tree views
695        m_refTreeModel->clear();
696        m_refSamplesTreeModel->clear();
697        // remove all entries from "Instrument" menu
698        while (!instrument_menu->get_children().empty()) {
699            remove_instrument_from_menu(0);
700        }
701    
702        if (!this->file) return;
703    
704        load_gig(
705            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
706        );
707    }
708    
709  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
710  {  {
711      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 1020  void MainWindow::on_action_help_about() Line 1104  void MainWindow::on_action_help_about()
1104  }  }
1105    
1106  PropDialog::PropDialog()  PropDialog::PropDialog()
1107      : eName(_("Name")),      : eFileFormat(_("File Format")),
1108          eName(_("Name")),
1109        eCreationDate(_("Creation date")),        eCreationDate(_("Creation date")),
1110        eComments(_("Comments")),        eComments(_("Comments")),
1111        eProduct(_("Product")),        eProduct(_("Product")),
# Line 1037  PropDialog::PropDialog() Line 1122  PropDialog::PropDialog()
1122        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
1123        eSubject(_("Subject")),        eSubject(_("Subject")),
1124        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
1125        table(2, 1)        table(2, 1),
1126          m_file(NULL)
1127  {  {
1128      set_title(_("File Properties"));      set_title(_("File Properties"));
1129      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1059  PropDialog::PropDialog() Line 1145  PropDialog::PropDialog()
1145      connect(eCommissioned, &DLS::Info::Commissioned);      connect(eCommissioned, &DLS::Info::Commissioned);
1146      connect(eSubject, &DLS::Info::Subject);      connect(eSubject, &DLS::Info::Subject);
1147    
1148        table.add(eFileFormat);
1149      table.add(eName);      table.add(eName);
1150      table.add(eCreationDate);      table.add(eCreationDate);
1151      table.add(eComments);      table.add(eComments);
# Line 1089  PropDialog::PropDialog() Line 1176  PropDialog::PropDialog()
1176      quitButton.grab_focus();      quitButton.grab_focus();
1177      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
1178          sigc::mem_fun(*this, &PropDialog::hide));          sigc::mem_fun(*this, &PropDialog::hide));
1179        eFileFormat.signal_value_changed().connect(
1180            sigc::mem_fun(*this, &PropDialog::onFileFormatChanged));
1181    
1182      quitButton.show();      quitButton.show();
1183      vbox.show();      vbox.show();
1184      show_all_children();      show_all_children();
1185  }  }
1186    
1187    void PropDialog::set_file(gig::File* file)
1188    {
1189        m_file = file;
1190    
1191        // update file format version combo box
1192        const std::string sGiga = "Gigasampler/GigaStudio v";
1193        const int major = file->pVersion->major;
1194        std::vector<std::string> txts;
1195        std::vector<int> values;
1196        txts.push_back(sGiga + "2"); values.push_back(2);
1197        txts.push_back(sGiga + "3/v4"); values.push_back(3);
1198        if (major != 2 && major != 3) {
1199            txts.push_back(sGiga + ToString(major)); values.push_back(major);
1200        }
1201        std::vector<const char*> texts;
1202        for (int i = 0; i < txts.size(); ++i) texts.push_back(txts[i].c_str());
1203        texts.push_back(NULL); values.push_back(0);
1204        eFileFormat.set_choices(&texts[0], &values[0]);
1205        eFileFormat.set_value(major);
1206    }
1207    
1208    void PropDialog::onFileFormatChanged() {
1209        const int major = eFileFormat.get_value();
1210        if (m_file) m_file->pVersion->major = major;
1211    }
1212    
1213  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1214  {  {
1215      update(info);      update(info);
# Line 1236  void MainWindow::load_gig(gig::File* gig Line 1351  void MainWindow::load_gig(gig::File* gig
1351      file_has_name = filename;      file_has_name = filename;
1352      file_is_changed = false;      file_is_changed = false;
1353    
1354        propDialog.set_file(gig);
1355      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1356    
1357      instrument_name_connection.block();      instrument_name_connection.block();
# Line 1272  void MainWindow::load_gig(gig::File* gig Line 1388  void MainWindow::load_gig(gig::File* gig
1388              }              }
1389          }          }
1390      }      }
1391        
1392        for (int i = 0; gig->GetScriptGroup(i); ++i) {
1393            gig::ScriptGroup* group = gig->GetScriptGroup(i);
1394    
1395            Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1396            Gtk::TreeModel::Row rowGroup = *iterGroup;
1397            rowGroup[m_ScriptsModel.m_col_name]   = gig_to_utf8(group->Name);
1398            rowGroup[m_ScriptsModel.m_col_group]  = group;
1399            rowGroup[m_ScriptsModel.m_col_script] = NULL;
1400            for (int s = 0; group->GetScript(s); ++s) {
1401                gig::Script* script = group->GetScript(s);
1402    
1403                Gtk::TreeModel::iterator iterScript =
1404                    m_refScriptsTreeModel->append(rowGroup.children());
1405                Gtk::TreeModel::Row rowScript = *iterScript;
1406                rowScript[m_ScriptsModel.m_col_name] = gig_to_utf8(script->Name);
1407                rowScript[m_ScriptsModel.m_col_script] = script;
1408                rowScript[m_ScriptsModel.m_col_group]  = NULL;
1409            }
1410        }
1411        // unfold all script groups by default
1412        m_TreeViewScripts.expand_all();
1413    
1414      file = gig;      file = gig;
1415    
# Line 1436  void MainWindow::on_sample_treeview_butt Line 1574  void MainWindow::on_sample_treeview_butt
1574      }      }
1575  }  }
1576    
1577    void MainWindow::on_script_treeview_button_release(GdkEventButton* button) {
1578        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1579            Gtk::Menu* script_popup =
1580                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/ScriptPopupMenu"));
1581            // update enabled/disabled state of sample popup items
1582            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1583            Gtk::TreeModel::iterator it = sel->get_selected();
1584            bool group_selected  = false;
1585            bool script_selected = false;
1586            if (it) {
1587                Gtk::TreeModel::Row row = *it;
1588                group_selected  = row[m_ScriptsModel.m_col_group];
1589                script_selected = row[m_ScriptsModel.m_col_script];
1590            }
1591            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScript"))->
1592                set_sensitive(group_selected || script_selected);
1593            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/AddScriptGroup"))->
1594                set_sensitive(file);
1595            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/EditScript"))->
1596                set_sensitive(script_selected);    
1597            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/ScriptPopupMenu/RemoveScript"))->
1598                set_sensitive(group_selected || script_selected);
1599            // show sample popup
1600            script_popup->popup(button->button, button->time);
1601        }
1602    }
1603    
1604  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1605      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
# Line 1583  void MainWindow::on_action_sample_proper Line 1747  void MainWindow::on_action_sample_proper
1747      msg.run();      msg.run();
1748  }  }
1749    
1750    void MainWindow::on_action_add_script_group() {
1751        static int __script_indexer = 0;
1752        if (!file) return;
1753        gig::ScriptGroup* group = file->AddScriptGroup();
1754        group->Name = gig_from_utf8(_("Unnamed Group"));
1755        if (__script_indexer) group->Name += " " + ToString(__script_indexer);
1756        __script_indexer++;
1757        // update sample tree view
1758        Gtk::TreeModel::iterator iterGroup = m_refScriptsTreeModel->append();
1759        Gtk::TreeModel::Row rowGroup = *iterGroup;
1760        rowGroup[m_ScriptsModel.m_col_name] = gig_to_utf8(group->Name);
1761        rowGroup[m_ScriptsModel.m_col_script] = NULL;
1762        rowGroup[m_ScriptsModel.m_col_group] = group;
1763        file_changed();
1764    }
1765    
1766    void MainWindow::on_action_add_script() {
1767        if (!file) return;
1768        // get selected group
1769        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1770        Gtk::TreeModel::iterator it = sel->get_selected();
1771        if (!it) return;
1772        Gtk::TreeModel::Row row = *it;
1773        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1774        if (!group) { // not a group, but a script is selected (probably)
1775            gig::Script* script = row[m_ScriptsModel.m_col_script];
1776            if (!script) return;
1777            it = row.parent(); // resolve parent (that is the script's group)
1778            if (!it) return;
1779            row = *it;
1780            group = row[m_ScriptsModel.m_col_group];
1781            if (!group) return;
1782        }
1783    
1784        // add a new script to the .gig file
1785        gig::Script* script = group->AddScript();    
1786        Glib::ustring name = _("Unnamed Script");
1787        script->Name = gig_from_utf8(name);
1788    
1789        // add script to the tree view
1790        Gtk::TreeModel::iterator iterScript =
1791            m_refScriptsTreeModel->append(row.children());
1792        Gtk::TreeModel::Row rowScript = *iterScript;
1793        rowScript[m_ScriptsModel.m_col_name] = name;
1794        rowScript[m_ScriptsModel.m_col_script] = script;
1795        rowScript[m_ScriptsModel.m_col_group]  = NULL;
1796    
1797        // unfold group of new script item in treeview
1798        Gtk::TreeModel::Path path(iterScript);
1799        m_TreeViewScripts.expand_to_path(path);
1800    }
1801    
1802    void MainWindow::on_action_edit_script() {
1803        if (!file) return;
1804        // get selected script
1805        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1806        Gtk::TreeModel::iterator it = sel->get_selected();
1807        if (!it) return;
1808        Gtk::TreeModel::Row row = *it;
1809        gig::Script* script = row[m_ScriptsModel.m_col_script];
1810        if (!script) return;
1811    
1812        ScriptEditor* editor = new ScriptEditor;
1813        editor->setScript(script);
1814        //editor->reparent(*this);
1815        editor->show();
1816    }
1817    
1818    void MainWindow::on_action_remove_script() {
1819        if (!file) return;
1820        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
1821        Gtk::TreeModel::iterator it = sel->get_selected();
1822        if (it) {
1823            Gtk::TreeModel::Row row = *it;
1824            gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
1825            gig::Script* script     = row[m_ScriptsModel.m_col_script];
1826            Glib::ustring name      = row[m_ScriptsModel.m_col_name];
1827            try {
1828                // remove script group or script from the gig file
1829                if (group) {
1830                    // notify everybody that we're going to remove these samples
1831    //TODO:         scripts_to_be_removed_signal.emit(members);
1832                    // delete the group in the .gig file including the
1833                    // samples that belong to the group
1834                    file->DeleteScriptGroup(group);
1835                    // notify that we're done with removal
1836    //TODO:         scripts_removed_signal.emit();
1837                    file_changed();
1838                } else if (script) {
1839                    // notify everybody that we're going to remove this sample
1840    //TODO:         std::list<gig::Script*> lscripts;
1841    //TODO:         lscripts.push_back(script);
1842    //TODO:         scripts_to_be_removed_signal.emit(lscripts);
1843                    // remove sample from the .gig file
1844                    script->GetGroup()->DeleteScript(script);
1845                    // notify that we're done with removal
1846    //TODO:         scripts_removed_signal.emit();
1847                    dimreg_changed();
1848                    file_changed();
1849                }
1850                // remove respective row(s) from samples tree view
1851                m_refScriptsTreeModel->erase(it);
1852            } catch (RIFF::Exception e) {
1853                // pretend we're done with removal (i.e. to avoid dead locks)
1854    //TODO:     scripts_removed_signal.emit();
1855                // show error message
1856                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1857                msg.run();
1858            }
1859        }
1860    }
1861    
1862  void MainWindow::on_action_add_group() {  void MainWindow::on_action_add_group() {
1863      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1864      if (!file) return;      if (!file) return;
# Line 2010  void MainWindow::on_sample_label_drop_dr Line 2286  void MainWindow::on_sample_label_drop_dr
2286          bool channels_changed = false;          bool channels_changed = false;
2287          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2288              // remove the samplechannel dimension              // remove the samplechannel dimension
2289    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2290              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2291              channels_changed = true;              channels_changed = true;
2292              region_changed();              region_changed();
2293    */
2294          }          }
2295          dimreg_edit.set_sample(          dimreg_edit.set_sample(
2296              sample,              sample,
# Line 2078  void MainWindow::sample_name_changed(con Line 2356  void MainWindow::sample_name_changed(con
2356      }      }
2357  }  }
2358    
2359    void MainWindow::script_name_changed(const Gtk::TreeModel::Path& path,
2360                                         const Gtk::TreeModel::iterator& iter) {
2361        if (!iter) return;
2362        Gtk::TreeModel::Row row = *iter;
2363        Glib::ustring name      = row[m_ScriptsModel.m_col_name];
2364        gig::ScriptGroup* group = row[m_ScriptsModel.m_col_group];
2365        gig::Script* script     = row[m_ScriptsModel.m_col_script];
2366        gig::String gigname(gig_from_utf8(name));
2367        if (group) {
2368            if (group->Name != gigname) {
2369                group->Name = gigname;
2370                printf("script group name changed\n");
2371                file_changed();
2372            }
2373        } else if (script) {
2374            if (script->Name != gigname) {
2375                script->Name = gigname;
2376                printf("script name changed\n");
2377                file_changed();
2378            }
2379        }
2380    }
2381    
2382  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,
2383                                           const Gtk::TreeModel::iterator& iter) {                                           const Gtk::TreeModel::iterator& iter) {
2384      if (!iter) return;      if (!iter) return;
# Line 2124  void MainWindow::on_action_combine_instr Line 2425  void MainWindow::on_action_combine_instr
2425      delete d;      delete d;
2426  }  }
2427    
2428    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2429        struct _Source {
2430            std::vector<RIFF::File*> riffs;
2431            std::vector<gig::File*> gigs;
2432            
2433            ~_Source() {
2434                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2435                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2436                riffs.clear();
2437                gigs.clear();
2438            }
2439        } sources;
2440    
2441        if (filenames.empty())
2442            throw RIFF::Exception(_("No files selected, so nothing done."));
2443    
2444        // first open all input files (to avoid output file corruption)
2445        int i;
2446        try {
2447            for (i = 0; i < filenames.size(); ++i) {
2448                const std::string& filename = filenames[i];
2449                printf("opening file=%s\n", filename.c_str());
2450    
2451                RIFF::File* riff = new RIFF::File(filename);
2452                sources.riffs.push_back(riff);
2453    
2454                gig::File* gig = new gig::File(riff);
2455                sources.gigs.push_back(gig);
2456            }
2457        } catch (RIFF::Exception e) {
2458            throw RIFF::Exception(
2459                _("Error occurred while opening '") +
2460                filenames[i] +
2461                "': " +
2462                e.Message
2463            );
2464        } catch (...) {
2465            throw RIFF::Exception(
2466                _("Unknown exception occurred while opening '") +
2467                filenames[i] + "'"
2468            );
2469        }
2470    
2471        // now merge the opened .gig files to the main .gig file currently being
2472        // open in gigedit
2473        try {
2474            for (i = 0; i < filenames.size(); ++i) {
2475                const std::string& filename = filenames[i];
2476                printf("merging file=%s\n", filename.c_str());
2477                assert(i < sources.gigs.size());
2478    
2479                this->file->AddContentOf(sources.gigs[i]);
2480            }
2481        } catch (RIFF::Exception e) {
2482            throw RIFF::Exception(
2483                _("Error occurred while merging '") +
2484                filenames[i] +
2485                "': " +
2486                e.Message
2487            );
2488        } catch (...) {
2489            throw RIFF::Exception(
2490                _("Unknown exception occurred while merging '") +
2491                filenames[i] + "'"
2492            );
2493        }
2494    
2495        // Note: requires that this file already has a filename !
2496        this->file->Save();
2497    }
2498    
2499    void MainWindow::on_action_merge_files() {
2500        if (this->file->GetFileName().empty()) {
2501            Glib::ustring txt = _(
2502                "You seem to have a new .gig file open that has not been saved "
2503                "yet. You must save it somewhere before starting to merge it with "
2504                "other .gig files though, because during the merge operation the "
2505                "other files' sample data must be written on file level to the "
2506                "target .gig file."
2507            );
2508            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2509            msg.run();
2510            return;
2511        }
2512    
2513        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2514        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2515        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2516        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2517    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2518        Gtk::FileFilter filter;
2519        filter.add_pattern("*.gig");
2520    #else
2521        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2522        filter->add_pattern("*.gig");
2523    #endif
2524        dialog.set_filter(filter);
2525        if (current_gig_dir != "") {
2526            dialog.set_current_folder(current_gig_dir);
2527        }
2528        dialog.set_select_multiple(true);
2529    
2530        // show warning in the file picker dialog
2531        Gtk::HBox descriptionArea;
2532        descriptionArea.set_spacing(15);
2533        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2534        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2535    #if GTKMM_MAJOR_VERSION < 3
2536        view::WrapLabel description;
2537    #else
2538        Gtk::Label description;
2539        description.set_line_wrap();
2540    #endif
2541        description.set_markup(_(
2542            "\nSelect at least one .gig file that shall be merged to the .gig file "
2543            "currently being open in gigedit.\n\n"
2544            "<b>Please Note:</b> Merging with other files will modify your "
2545            "currently open .gig file on file level! And be aware that the current "
2546            "merge algorithm does not detect duplicate samples yet. So if you are "
2547            "merging files which are using equivalent sample data, those "
2548            "equivalent samples will currently be treated as separate samples and "
2549            "will accordingly be stored separately in the target .gig file!"
2550        ));
2551        descriptionArea.pack_start(description);
2552        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2553        descriptionArea.show_all();
2554    
2555        if (dialog.run() == Gtk::RESPONSE_OK) {
2556            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2557            std::vector<std::string> filenames = dialog.get_filenames();
2558    
2559            // merge the selected files to the currently open .gig file
2560            try {
2561                mergeFiles(filenames);
2562            } catch (RIFF::Exception e) {
2563                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2564                msg.run();
2565            }
2566    
2567            // update GUI
2568            __refreshEntireGUI();        
2569        }
2570    }
2571    
2572  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2573      this->file_is_shared = b;      this->file_is_shared = b;
2574    

Legend:
Removed from v.2548  
changed lines
  Added in v.2604

  ViewVC Help
Powered by ViewVC