/[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 2442 by persson, Sun Apr 14 07:29:59 2013 UTC revision 2553 by schoenebeck, Wed May 14 19:57:56 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2013 Andreas Persson   * Copyright (C) 2006-2014 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# 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"
47    #include "CombineInstrumentsDialog.h"
48  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
49  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
50    
# Line 89  MainWindow::MainWindow() : Line 91  MainWindow::MainWindow() :
91      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
92      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
93    
94        dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
95        dimreg_all_regions.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to all regions of this instrument as well."));
96        dimreg_all_dimregs.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied as well to all dimension splits of the region selected below."));
97        dimreg_stereo.set_tooltip_text(_("If checked: all changes you perform above will automatically be applied to both audio channel splits (only if a \"stereo\" dimension is defined below)."));
98    
99      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
100      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
# Line 123  MainWindow::MainWindow() : Line 129  MainWindow::MainWindow() :
129                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
130                       sigc::mem_fun(                       sigc::mem_fun(
131                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
132        actionGroup->add(Gtk::Action::create("MidiRules",
133                                             _("_Midi Rules")),
134                         sigc::mem_fun(
135                             *this, &MainWindow::show_midi_rules));
136      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
137                       sigc::mem_fun(                       sigc::mem_fun(
138                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
139      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
140    
141      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
142        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
143    
144      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
145            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
146        toggle_action->set_active(true);
147        actionGroup->add(toggle_action);
148    
149        toggle_action =
150            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
151        toggle_action->set_active(true);
152        actionGroup->add(toggle_action);
153    
154        toggle_action =
155            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
156        toggle_action->set_active(true);
157        actionGroup->add(toggle_action);
158    
159    
160        actionGroup->add(Gtk::Action::create("MenuView", _("_View")));
161        toggle_action =
162          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
163      toggle_action->set_active(true);      toggle_action->set_active(true);
164      actionGroup->add(toggle_action,      actionGroup->add(toggle_action,
# Line 155  MainWindow::MainWindow() : Line 184  MainWindow::MainWindow() :
184          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
185      );      );
186    
187    
188        actionGroup->add(Gtk::Action::create("MenuSettings", _("_Settings")));
189        
190        toggle_action =
191            Gtk::ToggleAction::create("WarnUserOnExtensions", _("Show warning on format _extensions"));
192        toggle_action->set_active(Settings::singleton()->warnUserOnExtensions);
193        actionGroup->add(
194            toggle_action,
195            sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
196        );
197    
198    
199        actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
200    
201        actionGroup->add(
202            Gtk::Action::create("CombineInstruments", _("_Combine Instruments...")),
203            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
204        );
205    
206        actionGroup->add(
207            Gtk::Action::create("MergeFiles", _("_Merge Files...")),
208            sigc::mem_fun(*this, &MainWindow::on_action_merge_files)
209        );
210    
211    
212      // sample right-click popup actions      // sample right-click popup actions
213      actionGroup->add(      actionGroup->add(
214          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),          Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
# Line 196  MainWindow::MainWindow() : Line 250  MainWindow::MainWindow() :
250          "      <separator/>"          "      <separator/>"
251          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
252          "    </menu>"          "    </menu>"
253            "    <menu action='MenuEdit'>"
254            "      <menuitem action='CopySampleUnity'/>"
255            "      <menuitem action='CopySampleTune'/>"
256            "      <menuitem action='CopySampleLoop'/>"
257            "    </menu>"
258          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
259          "    </menu>"          "    </menu>"
260          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
261          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
262          "    </menu>"          "    </menu>"
263            "    <menu action='MenuTools'>"
264            "      <menuitem action='CombineInstruments'/>"
265            "      <menuitem action='MergeFiles'/>"
266            "    </menu>"
267            "    <menu action='MenuSettings'>"
268            "      <menuitem action='WarnUserOnExtensions'/>"
269            "    </menu>"
270          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
271          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
272          "    </menu>"          "    </menu>"
273          "  </menubar>"          "  </menubar>"
274          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
275          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
276            "    <menuitem action='MidiRules'/>"
277          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
278          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
279          "    <separator/>"          "    <separator/>"
# Line 224  MainWindow::MainWindow() : Line 291  MainWindow::MainWindow() :
291      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
292    
293      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
294        
295        // Set tooltips for menu items (for some reason, setting a tooltip on the
296        // respective Gtk::Action objects above will simply be ignored, no matter
297        // if using Gtk::Action::set_tooltip() or passing the tooltip string on
298        // Gtk::Action::create()).
299        {
300            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
301                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
302            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current unity note setting will be altered by this action."));
303        }
304        {
305            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
306                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
307            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current sample playback tuning will be altered by this action."));
308        }
309        {
310            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
311                uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
312            item->set_tooltip_text(_("Used when dragging a sample to a region's sample reference field. You may disable this for example if you want to replace an existing sample in a region with a new sample, but don't want that the region's current loop informations to be altered by this action."));
313        }
314        {
315            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
316                uiManager->get_widget("/MenuBar/MenuSettings/WarnUserOnExtensions"));
317            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."));
318        }
319        {
320            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
321                uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
322            item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
323        }
324        {
325            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
326                uiManager->get_widget("/MenuBar/MenuTools/MergeFiles"));
327            item->set_tooltip_text(_("Add instruments and samples of other .gig files to this .gig file."));
328        }
329    
330    
331      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
332          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
# Line 252  MainWindow::MainWindow() : Line 355  MainWindow::MainWindow() :
355      // Create the Tree model:      // Create the Tree model:
356      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
357      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
358        m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));
359      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
360          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
361      );      );
# Line 263  MainWindow::MainWindow() : Line 367  MainWindow::MainWindow() :
367      // create samples treeview (including its data model)      // create samples treeview (including its data model)
368      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
369      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
370        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."));
371      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
372      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);
373      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
# Line 297  MainWindow::MainWindow() : Line 402  MainWindow::MainWindow() :
402          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
403      propDialog.signal_changed().connect(      propDialog.signal_changed().connect(
404          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
405        midiRules.signal_changed().connect(
406            sigc::mem_fun(*this, &MainWindow::file_changed));
407    
408      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
409          dimreg_to_be_changed_signal.make_slot());          dimreg_to_be_changed_signal.make_slot());
# Line 345  MainWindow::MainWindow() : Line 452  MainWindow::MainWindow() :
452    
453      // start with a new gig file by default      // start with a new gig file by default
454      on_action_file_new();      on_action_file_new();
455    
456        // select 'Instruments' tab by default
457        // (gtk allows this only if the tab childs are visible, thats why it's here)
458        m_TreeViewNotebook.set_current_page(1);
459  }  }
460    
461  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 533  void MainWindow::__clear() { Line 644  void MainWindow::__clear() {
644      set_file_is_shared(false);      set_file_is_shared(false);
645  }  }
646    
647    void MainWindow::__refreshEntireGUI() {
648        // clear the samples and instruments tree views
649        m_refTreeModel->clear();
650        m_refSamplesTreeModel->clear();
651        // remove all entries from "Instrument" menu
652        while (!instrument_menu->get_children().empty()) {
653            remove_instrument_from_menu(0);
654        }
655    
656        if (!this->file) return;
657    
658        load_gig(
659            this->file, this->file->pInfo->Name.c_str(), this->file_is_shared
660        );
661    }
662    
663  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
664  {  {
665      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
# Line 545  void MainWindow::on_action_file_new() Line 672  void MainWindow::on_action_file_new()
672      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
673      // already add one new instrument by default      // already add one new instrument by default
674      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
675      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
676      // update GUI with that new gig::File      // update GUI with that new gig::File
677      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
678  }  }
# Line 897  void MainWindow::on_action_file_properti Line 1024  void MainWindow::on_action_file_properti
1024      propDialog.deiconify();      propDialog.deiconify();
1025  }  }
1026    
1027    void MainWindow::on_action_warn_user_on_extensions() {
1028        Settings::singleton()->warnUserOnExtensions =
1029            !Settings::singleton()->warnUserOnExtensions;
1030    }
1031    
1032  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1033  {  {
1034      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 906  void MainWindow::on_action_help_about() Line 1038  void MainWindow::on_action_help_about()
1038      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1039  #endif  #endif
1040      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1041      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
1042      dialog.set_comments(_(      const std::string sComment =
1043          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
1044          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
1045          "Please notice that this is still a very young instrument editor. "          _(
1046          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
1047          "this application.\n"              "\n"
1048          "\n"              "Please notice that this is still a very young instrument editor. "
1049          "Please report bugs to: http://bugs.linuxsampler.org")              "So better backup your Gigasampler files before editing them with "
1050      );              "this application.\n"
1051                "\n"
1052                "Please report bugs to: http://bugs.linuxsampler.org"
1053            );
1054        dialog.set_comments(sComment.c_str());
1055      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1056      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1057      dialog.run();      dialog.run();
# Line 1003  void PropDialog::set_info(DLS::Info* inf Line 1139  void PropDialog::set_info(DLS::Info* inf
1139  }  }
1140    
1141    
1142    void InstrumentProps::set_Name(const gig::String& name)
1143    {
1144        m->pInfo->Name = name;
1145    }
1146    
1147    void InstrumentProps::update_name()
1148    {
1149        update_model++;
1150        eName.set_value(m->pInfo->Name);
1151        update_model--;
1152    }
1153    
1154  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_IsDrum(bool value)
1155  {  {
1156      m->IsDrum = value;      m->IsDrum = value;
# Line 1045  InstrumentProps::InstrumentProps() : Line 1193  InstrumentProps::InstrumentProps() :
1193            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1194      );      );
1195    
1196        connect(eName, &InstrumentProps::set_Name);
1197      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1198      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1199      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1057  InstrumentProps::InstrumentProps() : Line 1206  InstrumentProps::InstrumentProps() :
1206      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1207              &gig::Instrument::DimensionKeyRange);              &gig::Instrument::DimensionKeyRange);
1208    
1209        eName.signal_value_changed().connect(sig_name_changed.make_slot());
1210    
1211      table.set_col_spacings(5);      table.set_col_spacings(5);
1212    
1213      table.add(eName);      table.add(eName);
# Line 1097  void InstrumentProps::set_instrument(gig Line 1248  void InstrumentProps::set_instrument(gig
1248      update(instrument);      update(instrument);
1249    
1250      update_model++;      update_model++;
1251        eName.set_value(instrument->pInfo->Name);
1252      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1253      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1254      eMIDIProgram.set_value(instrument->MIDIProgram);      eMIDIProgram.set_value(instrument->MIDIProgram);
# Line 1127  void MainWindow::load_gig(gig::File* gig Line 1279  void MainWindow::load_gig(gig::File* gig
1279      instrument_name_connection.block();      instrument_name_connection.block();
1280      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1281           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1282          Glib::ustring name(instrument->pInfo->Name);          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1283    
1284          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1285          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
# Line 1143  void MainWindow::load_gig(gig::File* gig Line 1295  void MainWindow::load_gig(gig::File* gig
1295          if (group->Name != "") {          if (group->Name != "") {
1296              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1297              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1298              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1299              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1300              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1301              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1151  void MainWindow::load_gig(gig::File* gig Line 1303  void MainWindow::load_gig(gig::File* gig
1303                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1304                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1305                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1306                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1307                        gig_to_utf8(sample->pInfo->Name);
1308                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1309                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1310              }              }
# Line 1163  void MainWindow::load_gig(gig::File* gig Line 1316  void MainWindow::load_gig(gig::File* gig
1316      // select the first instrument      // select the first instrument
1317      m_TreeView.get_selection()->select(Gtk::TreePath("0"));      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1318    
1319        instr_props_set_instrument();
1320      gig::Instrument* instrument = get_instrument();      gig::Instrument* instrument = get_instrument();
1321      if (instrument) {      if (instrument) {
1322            midiRules.set_instrument(instrument);
1323        }
1324    }
1325    
1326    bool MainWindow::instr_props_set_instrument()
1327    {
1328        instrumentProps.signal_name_changed().clear();
1329    
1330        Gtk::TreeModel::const_iterator it =
1331            m_TreeView.get_selection()->get_selected();
1332        if (it) {
1333            Gtk::TreeModel::Row row = *it;
1334            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1335    
1336          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1337    
1338            // make sure instrument tree is updated when user changes the
1339            // instrument name in instrument properties window
1340            instrumentProps.signal_name_changed().connect(
1341                sigc::bind(
1342                    sigc::mem_fun(*this,
1343                                  &MainWindow::instr_name_changed_by_instr_props),
1344                    it));
1345        } else {
1346            instrumentProps.hide();
1347      }      }
1348        return it;
1349  }  }
1350    
1351  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
1352  {  {
1353      gig::Instrument* instrument = get_instrument();      if (instr_props_set_instrument()) {
     if (instrument)  
     {  
         instrumentProps.set_instrument(instrument);  
1354          instrumentProps.show();          instrumentProps.show();
1355          instrumentProps.deiconify();          instrumentProps.deiconify();
1356      }      }
1357  }  }
1358    
1359    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1360    {
1361        Gtk::TreeModel::Row row = *it;
1362        Glib::ustring name = row[m_Columns.m_col_name];
1363    
1364        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1365        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1366        if (gigname != name) {
1367            row[m_Columns.m_col_name] = gigname;
1368        }
1369    }
1370    
1371    void MainWindow::show_midi_rules()
1372    {
1373        if (gig::Instrument* instrument = get_instrument())
1374        {
1375            midiRules.set_instrument(instrument);
1376            midiRules.show();
1377            midiRules.deiconify();
1378        }
1379    }
1380    
1381  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1382      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1383          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1191  void MainWindow::on_action_view_status_b Line 1389  void MainWindow::on_action_view_status_b
1389      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1390  }  }
1391    
1392    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1393        Gtk::CheckMenuItem* item =
1394            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1395        if (!item) {
1396            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1397            return true;
1398        }
1399        return item->get_active();
1400    }
1401    
1402    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1403        Gtk::CheckMenuItem* item =
1404            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1405        if (!item) {
1406            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1407            return true;
1408        }
1409        return item->get_active();
1410    }
1411    
1412    bool MainWindow::is_copy_samples_loop_enabled() const {
1413        Gtk::CheckMenuItem* item =
1414            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1415        if (!item) {
1416            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1417            return true;
1418        }
1419        return item->get_active();
1420    }
1421    
1422  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1423  {  {
1424      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1425          show_instr_props();          show_instr_props();
1426      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1427            // gig v2 files have no midi rules
1428            static_cast<Gtk::MenuItem*>(
1429                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1430                    !(file->pVersion && file->pVersion->major == 2));
1431          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1432      }      }
1433  }  }
# Line 1276  void MainWindow::remove_instrument_from_ Line 1508  void MainWindow::remove_instrument_from_
1508  }  }
1509    
1510  void MainWindow::add_instrument(gig::Instrument* instrument) {  void MainWindow::add_instrument(gig::Instrument* instrument) {
1511      const char* name = instrument->pInfo->Name.c_str();      const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1512    
1513      // update instrument tree view      // update instrument tree view
1514      instrument_name_connection.block();      instrument_name_connection.block();
# Line 1298  void MainWindow::on_action_add_instrumen Line 1530  void MainWindow::on_action_add_instrumen
1530      if (!file) return;      if (!file) return;
1531      gig::Instrument* instrument = file->AddInstrument();      gig::Instrument* instrument = file->AddInstrument();
1532      __instrument_indexer++;      __instrument_indexer++;
1533      instrument->pInfo->Name =      instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1534          _("Unnamed Instrument ") + ToString(__instrument_indexer);                                              ToString(__instrument_indexer));
1535    
1536      add_instrument(instrument);      add_instrument(instrument);
1537  }  }
# Line 1319  void MainWindow::on_action_duplicate_ins Line 1551  void MainWindow::on_action_duplicate_ins
1551      // duplicate the orginal instrument      // duplicate the orginal instrument
1552      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1553      instrNew->pInfo->Name =      instrNew->pInfo->Name =
1554          instrOrig->pInfo->Name + " (" + _("Copy") + ")";          instrOrig->pInfo->Name +
1555            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1556    
1557      add_instrument(instrNew);      add_instrument(instrNew);
1558  }  }
# Line 1366  void MainWindow::on_action_remove_instru Line 1599  void MainWindow::on_action_remove_instru
1599                      Gtk::TreePath(ToString(index)));                      Gtk::TreePath(ToString(index)));
1600              }              }
1601  #endif  #endif
1602                instr_props_set_instrument();
1603              instr = get_instrument();              instr = get_instrument();
1604              if (instr) {              if (instr) {
1605                  instrumentProps.set_instrument(instr);                  midiRules.set_instrument(instr);
1606              } else {              } else {
1607                  instrumentProps.hide();                  midiRules.hide();
1608              }              }
1609          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1610              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
# Line 1391  void MainWindow::on_action_add_group() { Line 1625  void MainWindow::on_action_add_group() {
1625      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1626      if (!file) return;      if (!file) return;
1627      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1628      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1629      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1630      __sample_indexer++;      __sample_indexer++;
1631      // update sample tree view      // update sample tree view
1632      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1633      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1634      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1635      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1636      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1637      file_changed();      file_changed();
# Line 1506  void MainWindow::on_action_add_sample() Line 1740  void MainWindow::on_action_add_sample()
1740                          break;                          break;
1741                      }                      }
1742                  }                  }
1743                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1744                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1745                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1746                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1520  void MainWindow::on_action_add_sample() Line 1754  void MainWindow::on_action_add_sample()
1754                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1755                  {                  {
1756                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1757                        sample->FineTune      = instrument.detune;
1758    
1759                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1760                          sample->Loops = 1;                          sample->Loops = 1;
# Line 1557  void MainWindow::on_action_add_sample() Line 1792  void MainWindow::on_action_add_sample()
1792                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1793                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1794                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1795                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1796                        gig_to_utf8(sample->pInfo->Name);
1797                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1798                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1799                  // close sound file                  // close sound file
# Line 1628  void MainWindow::on_action_replace_all_s Line 1864  void MainWindow::on_action_replace_all_s
1864               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1865          {          {
1866              std::string filename =              std::string filename =
1867                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1868                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1869                                             postfixEntryBox.get_text());
1870              SF_INFO info;              SF_INFO info;
1871              info.format = 0;              info.format = 0;
1872              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1663  void MainWindow::on_action_replace_all_s Line 1900  void MainWindow::on_action_replace_all_s
1900              catch (std::string what)              catch (std::string what)
1901              {              {
1902                  if (!error_files.empty()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1903                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1904                        " (" + what + ")";
1905              }              }
1906          }          }
1907          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
# Line 1688  void MainWindow::on_action_remove_sample Line 1926  void MainWindow::on_action_remove_sample
1926          try {          try {
1927              // remove group or sample from the gig file              // remove group or sample from the gig file
1928              if (group) {              if (group) {
1929                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1930                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1931                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1932                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1810  void MainWindow::on_sample_label_drop_dr Line 2048  void MainWindow::on_sample_label_drop_dr
2048          bool channels_changed = false;          bool channels_changed = false;
2049          if (sample->Channels == 1 && stereo_dimension) {          if (sample->Channels == 1 && stereo_dimension) {
2050              // remove the samplechannel dimension              // remove the samplechannel dimension
2051    /* commented out, because it makes it impossible building up an instrument from scratch using two separate L/R samples
2052              region->DeleteDimension(stereo_dimension);              region->DeleteDimension(stereo_dimension);
2053              channels_changed = true;              channels_changed = true;
2054              region_changed();              region_changed();
2055    */
2056          }          }
2057          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
2058                sample,
2059                is_copy_samples_unity_note_enabled(),
2060                is_copy_samples_fine_tune_enabled(),
2061                is_copy_samples_loop_enabled()
2062            );
2063    
2064          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
2065              // add samplechannel dimension              // add samplechannel dimension
# Line 1857  void MainWindow::sample_name_changed(con Line 2102  void MainWindow::sample_name_changed(con
2102      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2103      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2104      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2105        gig::String gigname(gig_from_utf8(name));
2106      if (group) {      if (group) {
2107          if (group->Name != name) {          if (group->Name != gigname) {
2108              group->Name = name;              group->Name = gigname;
2109              printf("group name changed\n");              printf("group name changed\n");
2110              file_changed();              file_changed();
2111          }          }
2112      } else if (sample) {      } else if (sample) {
2113          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2114              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2115              printf("sample name changed\n");              printf("sample name changed\n");
2116              file_changed();              file_changed();
2117          }          }
# Line 1893  void MainWindow::instrument_name_changed Line 2139  void MainWindow::instrument_name_changed
2139    
2140      // change name in gig      // change name in gig
2141      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2142      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2143          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2144            instrument->pInfo->Name = gigname;
2145    
2146            // change name in the instrument properties window
2147            if (instrumentProps.get_instrument() == instrument) {
2148                instrumentProps.update_name();
2149            }
2150    
2151          file_changed();          file_changed();
2152      }      }
2153  }  }
2154    
2155    void MainWindow::on_action_combine_instruments() {
2156        CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
2157        d->show_all();
2158        d->resize(500, 400);
2159        d->run();
2160        if (d->fileWasChanged()) {
2161            // update GUI with new instrument just created
2162            add_instrument(d->newCombinedInstrument());
2163        }
2164        delete d;
2165    }
2166    
2167    void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2168        struct _Source {
2169            std::vector<RIFF::File*> riffs;
2170            std::vector<gig::File*> gigs;
2171            
2172            ~_Source() {
2173                for (int k = 0; k < gigs.size(); ++k) delete gigs[k];
2174                for (int k = 0; k < riffs.size(); ++k) delete riffs[k];
2175                riffs.clear();
2176                gigs.clear();
2177            }
2178        } sources;
2179    
2180        if (filenames.empty())
2181            throw RIFF::Exception(_("No files selected, so nothing done."));
2182    
2183        // first open all input files (to avoid output file corruption)
2184        int i;
2185        try {
2186            for (i = 0; i < filenames.size(); ++i) {
2187                const std::string& filename = filenames[i];
2188                printf("opening file=%s\n", filename.c_str());
2189    
2190                RIFF::File* riff = new RIFF::File(filename);
2191                sources.riffs.push_back(riff);
2192    
2193                gig::File* gig = new gig::File(riff);
2194                sources.gigs.push_back(gig);
2195            }
2196        } catch (RIFF::Exception e) {
2197            throw RIFF::Exception(
2198                _("Error occurred while opening '") +
2199                filenames[i] +
2200                "': " +
2201                e.Message
2202            );
2203        } catch (...) {
2204            throw RIFF::Exception(
2205                _("Unknown exception occurred while opening '") +
2206                filenames[i] + "'"
2207            );
2208        }
2209    
2210        // now merge the opened .gig files to the main .gig file currently being
2211        // open in gigedit
2212        try {
2213            for (i = 0; i < filenames.size(); ++i) {
2214                const std::string& filename = filenames[i];
2215                printf("merging file=%s\n", filename.c_str());
2216                assert(i < sources.gigs.size());
2217    
2218                this->file->AddContentOf(sources.gigs[i]);
2219            }
2220        } catch (RIFF::Exception e) {
2221            throw RIFF::Exception(
2222                _("Error occurred while merging '") +
2223                filenames[i] +
2224                "': " +
2225                e.Message
2226            );
2227        } catch (...) {
2228            throw RIFF::Exception(
2229                _("Unknown exception occurred while merging '") +
2230                filenames[i] + "'"
2231            );
2232        }
2233    
2234        // Note: requires that this file already has a filename !
2235        this->file->Save();
2236    }
2237    
2238    void MainWindow::on_action_merge_files() {
2239        if (this->file->GetFileName().empty()) {
2240            Glib::ustring txt = _(
2241                "You seem to have a new .gig file open that has not been saved "
2242                "yet. You must save it somewhere before starting to merge it with "
2243                "other .gig files though, because during the merge operation the "
2244                "other files' sample data must be written on file level to the "
2245                "target .gig file."
2246            );
2247            Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
2248            msg.run();
2249            return;
2250        }
2251    
2252        Gtk::FileChooserDialog dialog(*this, _("Merge .gig files"));
2253        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
2254        dialog.add_button(_("Merge"), Gtk::RESPONSE_OK);
2255        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
2256    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
2257        Gtk::FileFilter filter;
2258        filter.add_pattern("*.gig");
2259    #else
2260        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
2261        filter->add_pattern("*.gig");
2262    #endif
2263        dialog.set_filter(filter);
2264        if (current_gig_dir != "") {
2265            dialog.set_current_folder(current_gig_dir);
2266        }
2267        dialog.set_select_multiple(true);
2268    
2269        // show warning in the file picker dialog
2270        Gtk::HBox descriptionArea;
2271        descriptionArea.set_spacing(15);
2272        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
2273        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
2274    #if GTKMM_MAJOR_VERSION < 3
2275        view::WrapLabel description;
2276    #else
2277        Gtk::Label description;
2278        description.set_line_wrap();
2279    #endif
2280        description.set_markup(_(
2281            "\nSelect at least one .gig file that shall be merged to the .gig file "
2282            "currently being open in gigedit.\n\n"
2283            "<b>Please Note:</b> Merging with other files will modify your "
2284            "currently open .gig file on file level! And be aware that the current "
2285            "merge algorithm does not detect duplicate samples yet. So if you are "
2286            "merging files which are using equivalent sample data, those "
2287            "equivalent samples will currently be treated as separate samples and "
2288            "will accordingly be stored separately in the target .gig file!"
2289        ));
2290        descriptionArea.pack_start(description);
2291        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
2292        descriptionArea.show_all();
2293    
2294        if (dialog.run() == Gtk::RESPONSE_OK) {
2295            printf("on_action_merge_files self=%x\n", Glib::Threads::Thread::self());
2296            std::vector<std::string> filenames = dialog.get_filenames();
2297    
2298            // merge the selected files to the currently open .gig file
2299            try {
2300                mergeFiles(filenames);
2301            } catch (RIFF::Exception e) {
2302                Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
2303                msg.run();
2304            }
2305    
2306            // update GUI
2307            __refreshEntireGUI();        
2308        }
2309    }
2310    
2311  void MainWindow::set_file_is_shared(bool b) {  void MainWindow::set_file_is_shared(bool b) {
2312      this->file_is_shared = b;      this->file_is_shared = b;
2313    

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

  ViewVC Help
Powered by ViewVC