/[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 1303 by persson, Sun Aug 26 09:29:52 2007 UTC revision 1411 by schoenebeck, Fri Oct 12 17:46:29 2007 UTC
# Line 17  Line 17 
17   * 02110-1301 USA.   * 02110-1301 USA.
18   */   */
19    
 #include <libintl.h>  
20  #include <iostream>  #include <iostream>
21    
22  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
# Line 26  Line 25 
25  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
26  #include <gtkmm/main.h>  #include <gtkmm/main.h>
27    
28    #include "global.h"
29    
30  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2
31  #define ABOUT_DIALOG  #define ABOUT_DIALOG
32  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
# Line 48  Glib::ustring filename_display_basename( Line 49  Glib::ustring filename_display_basename(
49    
50  #include "mainwindow.h"  #include "mainwindow.h"
51    
52  #define _(String) gettext(String)  #include "../../gfx/status_attached.xpm"
53    #include "../../gfx/status_detached.xpm"
54    
55  template<class T> inline std::string ToString(T o) {  template<class T> inline std::string ToString(T o) {
56      std::stringstream ss;      std::stringstream ss;
# Line 211  MainWindow::MainWindow() Line 213  MainWindow::MainWindow()
213      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
214      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
215      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
216        m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
217    
218        // Status Bar:
219        m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
220        m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
221        m_StatusBar.show();
222    
223      m_RegionChooser.signal_region_selected().connect(      m_RegionChooser.signal_region_selected().connect(
224          sigc::mem_fun(*this, &MainWindow::region_changed) );          sigc::mem_fun(*this, &MainWindow::region_changed) );
# Line 257  MainWindow::MainWindow() Line 265  MainWindow::MainWindow()
265          sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)          sigc::mem_fun(*this, &MainWindow::on_sample_label_drop_drag_data_received)
266      );      );
267      dimreg_edit.signal_dimreg_changed().connect(      dimreg_edit.signal_dimreg_changed().connect(
268          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::hide(sigc::mem_fun(*this, &MainWindow::file_changed)));
269      m_RegionChooser.signal_instrument_changed().connect(      m_RegionChooser.signal_instrument_changed().connect(
270          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
271      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
272          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
273      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_instrument_changed().connect(
274          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
275    
276        dimreg_edit.signal_dimreg_to_be_changed().connect(
277            dimreg_to_be_changed_signal.make_slot());
278        dimreg_edit.signal_dimreg_changed().connect(
279            dimreg_changed_signal.make_slot());
280        dimreg_edit.signal_sample_ref_changed().connect(
281            sample_ref_changed_signal.make_slot());
282    
283        m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
284            sigc::hide(
285                sigc::bind(
286                    file_structure_to_be_changed_signal.make_slot(),
287                    sigc::ref(this->file)
288                )
289            )
290        );
291        m_RegionChooser.signal_instrument_struct_changed().connect(
292            sigc::hide(
293                sigc::bind(
294                    file_structure_changed_signal.make_slot(),
295                    sigc::ref(this->file)
296                )
297            )
298        );
299        m_RegionChooser.signal_region_to_be_changed().connect(
300            region_to_be_changed_signal.make_slot());
301        m_RegionChooser.signal_region_changed_signal().connect(
302            region_changed_signal.make_slot());
303    
304      file = 0;      file = 0;
305      file_is_changed = false;      file_is_changed = false;
306        set_file_is_shared(false);
307    
308      show_all_children();      show_all_children();
309    
# Line 279  MainWindow::~MainWindow() Line 317  MainWindow::~MainWindow()
317    
318  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
319  {  {
320      return file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
321  }  }
322    
323  void MainWindow::on_action_quit()  void MainWindow::on_action_quit()
324  {  {
325      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
326      hide();      hide();
327  }  }
328    
# Line 398  void MainWindow::__clear() { Line 436  void MainWindow::__clear() {
436      m_refTreeModel->clear();      m_refTreeModel->clear();
437      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
438      // free libgig's gig::File instance      // free libgig's gig::File instance
439      if (file) {      if (file && !file_is_shared) delete file;
440          delete file;      file = NULL;
441          file = NULL;      set_file_is_shared(false);
     }  
442  }  }
443    
444  void MainWindow::on_action_file_new()  void MainWindow::on_action_file_new()
445  {  {
446      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
447    
448        if (file_is_shared && !leaving_shared_mode_dialog()) return;
449    
450      // clear all GUI elements      // clear all GUI elements
451      __clear();      __clear();
# Line 438  bool MainWindow::close_confirmation_dial Line 477  bool MainWindow::close_confirmation_dial
477      return response != Gtk::RESPONSE_CANCEL;      return response != Gtk::RESPONSE_CANCEL;
478  }  }
479    
480    bool MainWindow::leaving_shared_mode_dialog() {
481        Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
482        Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
483    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2
484        dialog.set_secondary_text(
485            _("If you proceed to work on another instrument file, it won't be "
486              "used by the sampler until you tell the sampler explicitly to "
487              "load it.")
488       );
489    #endif
490        dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
491        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
492        dialog.set_default_response(Gtk::RESPONSE_CANCEL);
493        int response = dialog.run();
494        dialog.hide();
495        return response == Gtk::RESPONSE_YES;
496    }
497    
498  void MainWindow::on_action_file_open()  void MainWindow::on_action_file_open()
499  {  {
500      if (file_is_changed && !close_confirmation_dialog()) return;      if (!file_is_shared && file_is_changed && !close_confirmation_dialog()) return;
501    
502        if (file_is_shared && !leaving_shared_mode_dialog()) return;
503    
504      Gtk::FileChooserDialog dialog(*this, _("Open file"));      Gtk::FileChooserDialog dialog(*this, _("Open file"));
505      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
# Line 481  void MainWindow::load_instrument(gig::In Line 540  void MainWindow::load_instrument(gig::In
540          msg.run();          msg.run();
541          Gtk::Main::quit();          Gtk::Main::quit();
542      }      }
543        // clear all GUI elements
544        __clear();
545        // load the instrument
546      gig::File* pFile = (gig::File*) instr->GetParent();      gig::File* pFile = (gig::File*) instr->GetParent();
547      load_gig(pFile, 0 /*file name*/);      load_gig(pFile, 0 /*file name*/, true /*shared instrument*/);
548      //TODO: automatically select the given instrument      //TODO: automatically select the given instrument
549  }  }
550    
# Line 531  bool MainWindow::check_if_savable() Line 593  bool MainWindow::check_if_savable()
593  bool MainWindow::file_save()  bool MainWindow::file_save()
594  {  {
595      if (!check_if_savable()) return false;      if (!check_if_savable()) return false;
596      if (!file_has_name) return file_save_as();      if (!file_is_shared && !file_has_name) return file_save_as();
597    
598      std::cout << "Saving file\n" << std::flush;      std::cout << "Saving file\n" << std::flush;
599        file_structure_to_be_changed_signal.emit(this->file);
600      try {      try {
601          file->Save();          file->Save();
602          if (file_is_changed) {          if (file_is_changed) {
# Line 541  bool MainWindow::file_save() Line 604  bool MainWindow::file_save()
604              file_is_changed = false;              file_is_changed = false;
605          }          }
606      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
607          Glib::ustring txt = "Could not save file: " + e.Message;          file_structure_changed_signal.emit(this->file);
608            Glib::ustring txt = _("Could not save file: ") + e.Message;
609          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
610          msg.run();          msg.run();
611          return false;          return false;
612      }      }
613      std::cout << "Saving file done\n" << std::flush;      std::cout << "Saving file done\n" << std::flush;
614      __import_queued_samples();      __import_queued_samples();
615        file_structure_changed_signal.emit(this->file);
616      return true;      return true;
617  }  }
618    
# Line 580  bool MainWindow::file_save_as() Line 645  bool MainWindow::file_save_as()
645      dialog.set_current_name(Glib::filename_display_basename(filename));      dialog.set_current_name(Glib::filename_display_basename(filename));
646    
647      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
648            file_structure_to_be_changed_signal.emit(this->file);
649          try {          try {
650              std::string filename = dialog.get_filename();              std::string filename = dialog.get_filename();
651              if (!Glib::str_has_suffix(filename, ".gig")) {              if (!Glib::str_has_suffix(filename, ".gig")) {
# Line 593  bool MainWindow::file_save_as() Line 659  bool MainWindow::file_save_as()
659              file_has_name = true;              file_has_name = true;
660              file_is_changed = false;              file_is_changed = false;
661          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
662              Glib::ustring txt = "Could not save file: " + e.Message;              file_structure_changed_signal.emit(this->file);
663                Glib::ustring txt = _("Could not save file: ") + e.Message;
664              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
665              msg.run();              msg.run();
666              return false;              return false;
667          }          }
668          __import_queued_samples();          __import_queued_samples();
669            file_structure_changed_signal.emit(this->file);
670          return true;          return true;
671      }      }
672      return false;      return false;
# Line 689  void MainWindow::__import_queued_samples Line 757  void MainWindow::__import_queued_samples
757      }      }
758      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
759      if (error_files.size()) {      if (error_files.size()) {
760          Glib::ustring txt = "Could not import the following sample(s):\n" + error_files;          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
761          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
762          msg.run();          msg.run();
763      }      }
# Line 883  void InstrumentProps::key_range_high_cha Line 951  void InstrumentProps::key_range_high_cha
951      if (h < l) eDimensionKeyRangeLow.set_value(h);      if (h < l) eDimensionKeyRangeLow.set_value(h);
952  }  }
953    
954  sigc::signal<void> InstrumentProps::signal_instrument_changed()  sigc::signal<void>& InstrumentProps::signal_instrument_changed()
955  {  {
956      return instrument_changed;      return instrument_changed;
957  }  }
# Line 896  void MainWindow::file_changed() Line 964  void MainWindow::file_changed()
964      }      }
965  }  }
966    
967  void MainWindow::load_gig(gig::File* gig, const char* filename)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
968  {  {
969      file = 0;      file = 0;
970        set_file_is_shared(isSharedInstrument);
971    
972      this->filename = filename ? filename : _("Unsaved Gig File");      this->filename = filename ? filename : _("Unsaved Gig File");
973      set_title(Glib::filename_display_basename(this->filename));      set_title(Glib::filename_display_basename(this->filename));
# Line 1032  void MainWindow::on_action_add_instrumen Line 1101  void MainWindow::on_action_add_instrumen
1101    
1102  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1103      if (!file) return;      if (!file) return;
1104        if (file_is_shared) {
1105            Gtk::MessageDialog msg(
1106                *this,
1107                 _("You cannot delete an instrument from this file, since it's "
1108                   "currently used by the sampler."),
1109                 false, Gtk::MESSAGE_INFO
1110            );
1111            msg.run();
1112            return;
1113        }
1114    
1115      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1116      Gtk::TreeModel::iterator it = sel->get_selected();      Gtk::TreeModel::iterator it = sel->get_selected();
1117      if (it) {      if (it) {
# Line 1218  void MainWindow::on_action_add_sample() Line 1298  void MainWindow::on_action_add_sample()
1298          }          }
1299          // 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
1300          if (error_files.size()) {          if (error_files.size()) {
1301              Glib::ustring txt = "Could not add the following sample(s):\n" + error_files;              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;
1302              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1303              msg.run();              msg.run();
1304          }          }
# Line 1244  void MainWindow::on_action_remove_sample Line 1324  void MainWindow::on_action_remove_sample
1324                       pSample; pSample = group->GetNextSample()) {                       pSample; pSample = group->GetNextSample()) {
1325                      members.push_back(pSample);                      members.push_back(pSample);
1326                  }                  }
1327                    // notify everybody that we're going to remove these samples
1328                    samples_to_be_removed_signal.emit(members);
1329                  // delete the group in the .gig file including the                  // delete the group in the .gig file including the
1330                  // samples that belong to the group                  // samples that belong to the group
1331                  file->DeleteGroup(group);                  file->DeleteGroup(group);
1332                    // notify that we're done with removal
1333                    samples_removed_signal.emit();
1334                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
1335                  // them from the import queue                  // them from the import queue
1336                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
# Line 1263  void MainWindow::on_action_remove_sample Line 1347  void MainWindow::on_action_remove_sample
1347                  }                  }
1348                  file_changed();                  file_changed();
1349              } else if (sample) {              } else if (sample) {
1350                    // notify everybody that we're going to remove this sample
1351                    std::list<gig::Sample*> lsamples;
1352                    lsamples.push_back(sample);
1353                    samples_to_be_removed_signal.emit(lsamples);
1354                  // remove sample from the .gig file                  // remove sample from the .gig file
1355                  file->DeleteSample(sample);                  file->DeleteSample(sample);
1356                    // notify that we're done with removal
1357                    samples_removed_signal.emit();
1358                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
1359                  // the import queue                  // the import queue
1360                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
# Line 1282  void MainWindow::on_action_remove_sample Line 1372  void MainWindow::on_action_remove_sample
1372              // remove respective row(s) from samples tree view              // remove respective row(s) from samples tree view
1373              m_refSamplesTreeModel->erase(it);              m_refSamplesTreeModel->erase(it);
1374          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1375                // pretend we're done with removal (i.e. to avoid dead locks)
1376                samples_removed_signal.emit();
1377                // show error message
1378              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1379              msg.run();              msg.run();
1380          }          }
# Line 1328  void MainWindow::on_sample_label_drop_dr Line 1421  void MainWindow::on_sample_label_drop_dr
1421          // drop success          // drop success
1422          context->drop_reply(true, time);          context->drop_reply(true, time);
1423    
1424          // find the samplechannel dimension          //TODO: we should better move most of the following code to DimRegionEdit::set_sample()
1425    
1426            // notify everybody that we're going to alter the region
1427          gig::Region* region = m_RegionChooser.get_region();          gig::Region* region = m_RegionChooser.get_region();
1428            region_to_be_changed_signal.emit(region);
1429    
1430            // find the samplechannel dimension
1431          gig::dimension_def_t* stereo_dimension = 0;          gig::dimension_def_t* stereo_dimension = 0;
1432          for (int i = 0 ; i < region->Dimensions ; i++) {          for (int i = 0 ; i < region->Dimensions ; i++) {
1433              if (region->pDimensionDefinitions[i].dimension ==              if (region->pDimensionDefinitions[i].dimension ==
# Line 1363  void MainWindow::on_sample_label_drop_dr Line 1461  void MainWindow::on_sample_label_drop_dr
1461              for (int i = 0 ; i < region->DimensionRegions ; i++) {              for (int i = 0 ; i < region->DimensionRegions ; i++) {
1462                  gig::DimensionRegion* d = region->pDimensionRegions[i];                  gig::DimensionRegion* d = region->pDimensionRegions[i];
1463                  if (d->pSample && d->pSample->Channels != sample->Channels) {                  if (d->pSample && d->pSample->Channels != sample->Channels) {
1464                      d->pSample = 0;                      gig::Sample* oldref = d->pSample;
1465                        d->pSample = NULL;
1466                        sample_ref_changed_signal.emit(oldref, NULL);
1467                  }                  }
1468              }              }
1469          }          }
1470    
1471            // notify we're done with altering
1472            region_changed_signal.emit(region);
1473    
1474          return;          return;
1475      }      }
1476      // drop failed      // drop failed
# Line 1407  void MainWindow::instrument_name_changed Line 1510  void MainWindow::instrument_name_changed
1510          file_changed();          file_changed();
1511      }      }
1512  }  }
1513    
1514    void MainWindow::set_file_is_shared(bool b) {
1515        this->file_is_shared = b;
1516    
1517        if (file_is_shared) {
1518            m_AttachedStateLabel.set_label(_("live-mode"));
1519            m_AttachedStateImage.set(
1520                Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm)
1521            );
1522        } else {
1523            m_AttachedStateLabel.set_label(_("stand-alone"));
1524            m_AttachedStateImage.set(
1525                Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
1526            );
1527        }
1528    }
1529    
1530    sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
1531        return file_structure_to_be_changed_signal;
1532    }
1533    
1534    sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_changed() {
1535        return file_structure_changed_signal;
1536    }
1537    
1538    sigc::signal<void, std::list<gig::Sample*> >& MainWindow::signal_samples_to_be_removed() {
1539        return samples_to_be_removed_signal;
1540    }
1541    
1542    sigc::signal<void>& MainWindow::signal_samples_removed() {
1543        return samples_removed_signal;
1544    }
1545    
1546    sigc::signal<void, gig::Region*>& MainWindow::signal_region_to_be_changed() {
1547        return region_to_be_changed_signal;
1548    }
1549    
1550    sigc::signal<void, gig::Region*>& MainWindow::signal_region_changed() {
1551        return region_changed_signal;
1552    }
1553    
1554    sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
1555        return sample_ref_changed_signal;
1556    }
1557    
1558    sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_to_be_changed() {
1559        return dimreg_to_be_changed_signal;
1560    }
1561    
1562    sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
1563        return dimreg_changed_signal;
1564    }

Legend:
Removed from v.1303  
changed lines
  Added in v.1411

  ViewVC Help
Powered by ViewVC