/[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 2169 by persson, Sun Mar 6 07:51:04 2011 UTC revision 2398 by persson, Sun Jan 13 09:14:29 2013 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2011 Andreas Persson   * Copyright (C) 2006-2013 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 20  Line 20 
20  #include <iostream>  #include <iostream>
21  #include <cstring>  #include <cstring>
22    
23    #include <glibmm/convert.h>
24    #include <glibmm/dispatcher.h>
25    #include <glibmm/miscutils.h>
26    #include <glibmm/stringutils.h>
27  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
28  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
29  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
# Line 28  Line 32 
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
33  #include <gtkmm/radiomenuitem.h>  #include <gtkmm/radiomenuitem.h>
34  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
35    #if GTKMM_MAJOR_VERSION < 3
36  #include "wrapLabel.hh"  #include "wrapLabel.hh"
37    #endif
38    
39  #include "global.h"  #include "global.h"
40  #include "compat.h"  #include "compat.h"
# Line 173  MainWindow::MainWindow() : Line 179  MainWindow::MainWindow() :
179          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
180      );      );
181      actionGroup->add(      actionGroup->add(
182            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
183            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
184        );
185        actionGroup->add(
186          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
187          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
188      );      );
# Line 230  MainWindow::MainWindow() : Line 240  MainWindow::MainWindow() :
240          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
241          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
242          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
243            "    <menuitem action='DupInstrument'/>"
244          "    <separator/>"          "    <separator/>"
245          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
246          "  </popup>"          "  </popup>"
# Line 254  MainWindow::MainWindow() : Line 265  MainWindow::MainWindow() :
265      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
266      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
267    
268        set_file_is_shared(false);
269    
270      // Status Bar:      // Status Bar:
271      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
272      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 356  MainWindow::MainWindow() : Line 369  MainWindow::MainWindow() :
369    
370      file = 0;      file = 0;
371      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
372    
373      show_all_children();      show_all_children();
374    
# Line 460  void loader_progress_callback(gig::progr Line 472  void loader_progress_callback(gig::progr
472  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
473  {  {
474      {      {
475          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
476          progress = fraction;          progress = fraction;
477      }      }
478      progress_dispatcher();      progress_dispatcher();
# Line 468  void Loader::progress_callback(float fra Line 480  void Loader::progress_callback(float fra
480    
481  void Loader::thread_function()  void Loader::thread_function()
482  {  {
483      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
484      printf("Start %s\n", filename);      printf("Start %s\n", filename);
485      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
486      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 488  Loader::Loader(const char* filename) Line 500  Loader::Loader(const char* filename)
500    
501  void Loader::launch()  void Loader::launch()
502  {  {
503    #ifdef OLD_THREADS
504      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
505    #else
506        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
507    #endif
508      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
509  }  }
510    
# Line 496  float Loader::get_progress() Line 512  float Loader::get_progress()
512  {  {
513      float res;      float res;
514      {      {
515          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
516          res = progress;          res = progress;
517      }      }
518      return res;      return res;
# Line 616  void MainWindow::on_action_file_open() Line 632  void MainWindow::on_action_file_open()
632      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
633          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
634          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
635          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
636          load_file(filename.c_str());          load_file(filename.c_str());
637          current_gig_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
638      }      }
# Line 658  void MainWindow::on_loader_progress() Line 674  void MainWindow::on_loader_progress()
674  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
675  {  {
676      printf("Loader finished!\n");      printf("Loader finished!\n");
677      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
678      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
679      load_dialog->hide();      load_dialog->hide();
680  }  }
# Line 761  bool MainWindow::file_save_as() Line 777  bool MainWindow::file_save_as()
777      descriptionArea.set_spacing(15);      descriptionArea.set_spacing(15);
778      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));      Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
779      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);      descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
780    #if GTKMM_MAJOR_VERSION < 3
781      view::WrapLabel description;      view::WrapLabel description;
782    #else
783        Gtk::Label description;
784        description.set_line_wrap();
785    #endif
786      description.set_markup(      description.set_markup(
787          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "          _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
788            "<span style=\"italic\">\"Save\"</span> dialog instead of "            "<span style=\"italic\">\"Save\"</span> dialog instead of "
# Line 813  void MainWindow::__import_queued_samples Line 834  void MainWindow::__import_queued_samples
834          SF_INFO info;          SF_INFO info;
835          info.format = 0;          info.format = 0;
836          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
837            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
838          try {          try {
839              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
840              // determine sample's bit depth              // determine sample's bit depth
# Line 910  void MainWindow::on_action_help_about() Line 932  void MainWindow::on_action_help_about()
932      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
933  #endif  #endif
934      dialog.set_version(VERSION);      dialog.set_version(VERSION);
935      dialog.set_copyright("Copyright (C) 2006-2011 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2013 Andreas Persson");
936      dialog.set_comments(_(      dialog.set_comments(_(
937          "Released under the GNU General Public License.\n"          "Released under the GNU General Public License.\n"
938          "\n"          "\n"
# Line 1312  void MainWindow::on_action_add_instrumen Line 1334  void MainWindow::on_action_add_instrumen
1334      file_changed();      file_changed();
1335  }  }
1336    
1337    void MainWindow::on_action_duplicate_instrument() {
1338        if (!file) return;
1339        
1340        // retrieve the currently selected instrument
1341        // (being the original instrument to be duplicated)
1342        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1343        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1344        if (!itSelection) return;
1345        Gtk::TreeModel::Row row = *itSelection;
1346        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1347        if (!instrOrig) return;
1348        
1349        // duplicate the orginal instrument
1350        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1351        instrNew->pInfo->Name =
1352            instrOrig->pInfo->Name + " (" + _("Copy") + ")";
1353            
1354        // update instrument tree view
1355        Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1356        Gtk::TreeModel::Row rowInstr = *iterInstr;
1357        rowInstr[m_Columns.m_col_name] = instrNew->pInfo->Name.c_str();
1358        rowInstr[m_Columns.m_col_instr] = instrNew;
1359        file_changed();
1360    }
1361    
1362  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1363      if (!file) return;      if (!file) return;
1364      if (file_is_shared) {      if (file_is_shared) {
# Line 1485  void MainWindow::on_action_add_sample() Line 1532  void MainWindow::on_action_add_sample()
1532                  {                  {
1533                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1534    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1535                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1536                          sample->Loops = 1;                          sample->Loops = 1;
1537    
# Line 1505  void MainWindow::on_action_add_sample() Line 1551  void MainWindow::on_action_add_sample()
1551                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1552                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1553                      }                      }
 #endif  
1554                  }                  }
1555    
1556                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1548  void MainWindow::on_action_replace_all_s Line 1593  void MainWindow::on_action_replace_all_s
1593      if (!file) return;      if (!file) return;
1594      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1595                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1596      view::WrapLabel description(      const char* str =
1597          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1598            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
1599            "directory.\n\n"            "directory.\n\n"
# Line 1562  void MainWindow::on_action_replace_all_s Line 1607  void MainWindow::on_action_replace_all_s
1607            "the sample in the gig file accordingly. If you don't need an "            "the sample in the gig file accordingly. If you don't need an "
1608            "extension, blank the field below. Any gig sample where no "            "extension, blank the field below. Any gig sample where no "
1609            "appropriate sample file could be found will be reported and left "            "appropriate sample file could be found will be reported and left "
1610            "untouched.\n")            "untouched.\n");
1611      );  #if GTKMM_MAJOR_VERSION < 3
1612        view::WrapLabel description(str);
1613    #else
1614        Gtk::Label description(str);
1615        description.set_line_wrap();
1616    #endif
1617      Gtk::HBox entryArea;      Gtk::HBox entryArea;
1618      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);      Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1619      Gtk::Entry postfixEntryBox;      Gtk::Entry postfixEntryBox;

Legend:
Removed from v.2169  
changed lines
  Added in v.2398

  ViewVC Help
Powered by ViewVC