/[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 1436 by schoenebeck, Mon Oct 15 15:29:58 2007 UTC revision 2507 by persson, Sun Jan 12 19:37:55 2014 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006, 2007 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 18  Line 18 
18   */   */
19    
20  #include <iostream>  #include <iostream>
21    #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>
28  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
29  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34    #if GTKMM_MAJOR_VERSION < 3
35  #include "global.h"  #include "wrapLabel.hh"
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
 #define ABOUT_DIALOG  
 #include <gtkmm/aboutdialog.h>  
36  #endif  #endif
37    
38  #if (GLIBMM_MAJOR_VERSION == 2 && GLIBMM_MINOR_VERSION < 6) || GLIBMM_MAJOR_VERSION < 2  #include "global.h"
39  namespace Glib {  #include "compat.h"
 Glib::ustring filename_display_basename(const std::string& filename)  
 {  
     gchar* gstr = g_path_get_basename(filename.c_str());  
     Glib::ustring str(gstr);  
     g_free(gstr);  
     return Glib::filename_to_utf8(str);  
 }  
 }  
 #endif  
40    
41  #include <stdio.h>  #include <stdio.h>
42  #include <sndfile.h>  #include <sndfile.h>
# Line 53  Glib::ustring filename_display_basename( Line 46  Glib::ustring filename_display_basename(
46  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
47  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
48    
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
49    
50  MainWindow::MainWindow()  MainWindow::MainWindow() :
51        dimreg_label(_("Changes apply to:")),
52        dimreg_all_regions(_("all regions")),
53        dimreg_all_dimregs(_("all dimension splits")),
54        dimreg_stereo(_("both channels"))
55  {  {
56  //    set_border_width(5);  //    set_border_width(5);
57  //    set_default_size(400, 200);  //    set_default_size(400, 200);
# Line 68  MainWindow::MainWindow() Line 60  MainWindow::MainWindow()
60      add(m_VBox);      add(m_VBox);
61    
62      // Handle selection      // Handle selection
63      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
64          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
65    
66      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 89  MainWindow::MainWindow() Line 80  MainWindow::MainWindow()
80      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
81    
82      m_HPaned.add1(m_TreeViewNotebook);      m_HPaned.add1(m_TreeViewNotebook);
83      m_HPaned.add2(dimreg_edit);      dimreg_hbox.add(dimreg_label);
84        dimreg_hbox.add(dimreg_all_regions);
85        dimreg_hbox.add(dimreg_all_dimregs);
86        dimreg_stereo.set_active();
87        dimreg_hbox.add(dimreg_stereo);
88        dimreg_vbox.add(dimreg_edit);
89        dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
90        m_HPaned.add2(dimreg_vbox);
91    
92    
93      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples");      m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, _("Samples"));
94      m_TreeViewNotebook.append_page(m_ScrolledWindow, "Instruments");      m_TreeViewNotebook.append_page(m_ScrolledWindow, _("Instruments"));
95    
96    
97      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
# Line 125  MainWindow::MainWindow() Line 123  MainWindow::MainWindow()
123                                           Gtk::Stock::PROPERTIES),                                           Gtk::Stock::PROPERTIES),
124                       sigc::mem_fun(                       sigc::mem_fun(
125                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
126        actionGroup->add(Gtk::Action::create("MidiRules",
127                                             _("_Midi Rules")),
128                         sigc::mem_fun(
129                             *this, &MainWindow::show_midi_rules));
130      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
131                       sigc::mem_fun(                       sigc::mem_fun(
132                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
133      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));      actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument")));
134    
135      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));  
136        actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
137    
138      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
139            Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"), "ffaga");
140        toggle_action->set_active(true);
141        //FIXME: doesn't work, why?
142        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
143        actionGroup->add(toggle_action);
144    
145        toggle_action =
146            Gtk::ToggleAction::create("CopySampleTune", _("Copy Sample's _Fine Tune"));
147        toggle_action->set_active(true);
148        //FIXME: doesn't work, why?
149        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
150        actionGroup->add(toggle_action);
151    
152        toggle_action =
153            Gtk::ToggleAction::create("CopySampleLoop", _("Copy Sample's _Loop Points"));
154        toggle_action->set_active(true);
155        //FIXME: doesn't work, why?
156        toggle_action->set_tooltip(_("Used when dragging a sample to a region's sample reference field."));
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 141  MainWindow::MainWindow() Line 168  MainWindow::MainWindow()
168      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);      action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP);
169      actionGroup->add(Gtk::Action::create("MenuHelp",      actionGroup->add(Gtk::Action::create("MenuHelp",
170                                           action->property_label()));                                           action->property_label()));
 #ifdef ABOUT_DIALOG  
171      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),      actionGroup->add(Gtk::Action::create("About", Gtk::Stock::ABOUT),
172                       sigc::mem_fun(                       sigc::mem_fun(
173                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
 #endif  
174      actionGroup->add(      actionGroup->add(
175          Gtk::Action::create("AddInstrument", _("Add _Instrument")),          Gtk::Action::create("AddInstrument", _("Add _Instrument")),
176          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_add_instrument)
177      );      );
178      actionGroup->add(      actionGroup->add(
179            Gtk::Action::create("DupInstrument", _("_Duplicate Instrument")),
180            sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
181        );
182        actionGroup->add(
183          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
184          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
185      );      );
# Line 165  MainWindow::MainWindow() Line 194  MainWindow::MainWindow()
194          sigc::mem_fun(*this, &MainWindow::on_action_add_group)          sigc::mem_fun(*this, &MainWindow::on_action_add_group)
195      );      );
196      actionGroup->add(      actionGroup->add(
197          Gtk::Action::create("AddSample", _("Add _Sample(s)")),          Gtk::Action::create("AddSample", _("Add _Sample(s)...")),
198          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)          sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
199      );      );
200      actionGroup->add(      actionGroup->add(
201          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
202          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
203      );      );
204        actionGroup->add(
205            Gtk::Action::create("ReplaceAllSamplesInAllGroups",
206                                _("Replace All Samples in All Groups...")),
207            sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
208        );
209    
210      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
211      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
# Line 191  MainWindow::MainWindow() Line 225  MainWindow::MainWindow()
225          "      <separator/>"          "      <separator/>"
226          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
227          "    </menu>"          "    </menu>"
228            "    <menu action='MenuEdit'>"
229            "      <menuitem action='CopySampleUnity'/>"
230            "      <menuitem action='CopySampleTune'/>"
231            "      <menuitem action='CopySampleLoop'/>"
232            "    </menu>"
233          "    <menu action='MenuInstrument'>"          "    <menu action='MenuInstrument'>"
234          "    </menu>"          "    </menu>"
235          "    <menu action='MenuView'>"          "    <menu action='MenuView'>"
236          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
237          "    </menu>"          "    </menu>"
 #ifdef ABOUT_DIALOG  
238          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
239          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
240          "    </menu>"          "    </menu>"
 #endif  
241          "  </menubar>"          "  </menubar>"
242          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
243          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
244            "    <menuitem action='MidiRules'/>"
245          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
246            "    <menuitem action='DupInstrument'/>"
247          "    <separator/>"          "    <separator/>"
248          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
249          "  </popup>"          "  </popup>"
# Line 212  MainWindow::MainWindow() Line 251  MainWindow::MainWindow()
251          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
252          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
253          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
254            "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
255          "    <separator/>"          "    <separator/>"
256          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
257          "  </popup>"          "  </popup>"
# Line 220  MainWindow::MainWindow() Line 260  MainWindow::MainWindow()
260    
261      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
262    
263        instrument_menu = static_cast<Gtk::MenuItem*>(
264            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
265    
266      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
267      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
268      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
269      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK);
270        m_VBox.pack_start(m_RegionChooser.m_VirtKeybPropsBox, Gtk::PACK_SHRINK);
271      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK);
272      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK);
273    
274        set_file_is_shared(false);
275    
276      // Status Bar:      // Status Bar:
277      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK);
278      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);      m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK);
# Line 241  MainWindow::MainWindow() Line 287  MainWindow::MainWindow()
287      // Create the Tree model:      // Create the Tree model:
288      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
289      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
290      m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
291          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
292      );      );
293    
# Line 263  MainWindow::MainWindow() Line 309  MainWindow::MainWindow()
309      );      );
310    
311      // 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
312      std::list<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
313      drag_target_gig_sample.push_back( Gtk::TargetEntry("gig::Sample") );      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
314      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);      m_TreeViewSamples.drag_source_set(drag_target_gig_sample);
315      m_TreeViewSamples.signal_drag_begin().connect(      m_TreeViewSamples.signal_drag_begin().connect(
316          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_drag_begin)
# Line 282  MainWindow::MainWindow() Line 328  MainWindow::MainWindow()
328          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
329      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
330          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
331      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
332            sigc::mem_fun(*this, &MainWindow::file_changed));
333        propDialog.signal_changed().connect(
334            sigc::mem_fun(*this, &MainWindow::file_changed));
335        midiRules.signal_changed().connect(
336          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
337    
338      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 313  MainWindow::MainWindow() Line 363  MainWindow::MainWindow()
363      m_RegionChooser.signal_region_changed_signal().connect(      m_RegionChooser.signal_region_changed_signal().connect(
364          region_changed_signal.make_slot());          region_changed_signal.make_slot());
365    
366        note_on_signal.connect(
367            sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_on_event));
368        note_off_signal.connect(
369            sigc::mem_fun(m_RegionChooser, &RegionChooser::on_note_off_event));
370    
371        dimreg_all_regions.signal_toggled().connect(
372            sigc::mem_fun(*this, &MainWindow::update_dimregs));
373        dimreg_all_dimregs.signal_toggled().connect(
374            sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled));
375        dimreg_stereo.signal_toggled().connect(
376            sigc::mem_fun(*this, &MainWindow::update_dimregs));
377    
378      file = 0;      file = 0;
379      file_is_changed = false;      file_is_changed = false;
     set_file_is_shared(false);  
380    
381      show_all_children();      show_all_children();
382    
# Line 343  void MainWindow::region_changed() Line 404  void MainWindow::region_changed()
404      m_DimRegionChooser.set_region(m_RegionChooser.get_region());      m_DimRegionChooser.set_region(m_RegionChooser.get_region());
405  }  }
406    
407    gig::Instrument* MainWindow::get_instrument()
408    {
409        gig::Instrument* instrument = 0;
410        Gtk::TreeModel::const_iterator it =
411            m_TreeView.get_selection()->get_selected();
412        if (it) {
413            Gtk::TreeModel::Row row = *it;
414            instrument = row[m_Columns.m_col_instr];
415        }
416        return instrument;
417    }
418    
419    void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs)
420    {
421        if (all_dimregs) {
422            for (int i = 0 ; i < region->DimensionRegions ; i++) {
423                if (region->pDimensionRegions[i]) {
424                    dimreg_edit.dimregs.insert(region->pDimensionRegions[i]);
425                }
426            }
427        } else {
428            m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs);
429        }
430    }
431    
432    void MainWindow::update_dimregs()
433    {
434        dimreg_edit.dimregs.clear();
435        bool all_regions = dimreg_all_regions.get_active();
436        bool stereo = dimreg_stereo.get_active();
437        bool all_dimregs = dimreg_all_dimregs.get_active();
438    
439        if (all_regions) {
440            gig::Instrument* instrument = get_instrument();
441            if (instrument) {
442                for (gig::Region* region = instrument->GetFirstRegion() ;
443                     region ;
444                     region = instrument->GetNextRegion()) {
445                    add_region_to_dimregs(region, stereo, all_dimregs);
446                }
447            }
448        } else {
449            gig::Region* region = m_RegionChooser.get_region();
450            if (region) {
451                add_region_to_dimregs(region, stereo, all_dimregs);
452            }
453        }
454    }
455    
456    void MainWindow::dimreg_all_dimregs_toggled()
457    {
458        dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active());
459        update_dimregs();
460    }
461    
462  void MainWindow::dimreg_changed()  void MainWindow::dimreg_changed()
463  {  {
464        update_dimregs();
465      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());      dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion());
466  }  }
467    
468  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
469  {  {
470      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      // select item in instrument menu
471        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
472      if (it) {      if (it) {
473          Gtk::TreeModel::Row row = *it;          Gtk::TreePath path(it);
474          std::cout << row[m_Columns.m_col_name] << std::endl;          int index = path[0];
475            const std::vector<Gtk::Widget*> children =
476          m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]);              instrument_menu->get_children();
477      } else {          static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
         m_RegionChooser.set_instrument(0);  
478      }      }
479    
480        m_RegionChooser.set_instrument(get_instrument());
481  }  }
482    
483  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 372  void loader_progress_callback(gig::progr Line 489  void loader_progress_callback(gig::progr
489  void Loader::progress_callback(float fraction)  void Loader::progress_callback(float fraction)
490  {  {
491      {      {
492          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
493          progress = fraction;          progress = fraction;
494      }      }
495      progress_dispatcher();      progress_dispatcher();
# Line 380  void Loader::progress_callback(float fra Line 497  void Loader::progress_callback(float fra
497    
498  void Loader::thread_function()  void Loader::thread_function()
499  {  {
500      printf("thread_function self=%x\n", Glib::Thread::self());      printf("thread_function self=%x\n", Glib::Threads::Thread::self());
501      printf("Start %s\n", filename);      printf("Start %s\n", filename);
502      RIFF::File* riff = new RIFF::File(filename);      RIFF::File* riff = new RIFF::File(filename);
503      gig = new gig::File(riff);      gig = new gig::File(riff);
# Line 394  void Loader::thread_function() Line 511  void Loader::thread_function()
511  }  }
512    
513  Loader::Loader(const char* filename)  Loader::Loader(const char* filename)
514      : thread(0), filename(filename)      : filename(filename), thread(0)
515  {  {
516  }  }
517    
518  void Loader::launch()  void Loader::launch()
519  {  {
520    #ifdef OLD_THREADS
521      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);      thread = Glib::Thread::create(sigc::mem_fun(*this, &Loader::thread_function), true);
522    #else
523        thread = Glib::Threads::Thread::create(sigc::mem_fun(*this, &Loader::thread_function));
524    #endif
525      printf("launch thread=%x\n", thread);      printf("launch thread=%x\n", thread);
526  }  }
527    
# Line 408  float Loader::get_progress() Line 529  float Loader::get_progress()
529  {  {
530      float res;      float res;
531      {      {
532          Glib::Mutex::Lock lock(progressMutex);          Glib::Threads::Mutex::Lock lock(progressMutex);
533          res = progress;          res = progress;
534      }      }
535      return res;      return res;
# Line 434  LoadDialog::LoadDialog(const Glib::ustri Line 555  LoadDialog::LoadDialog(const Glib::ustri
555  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
556  // before a new .gig file is to be created or to be loaded.  // before a new .gig file is to be created or to be loaded.
557  void MainWindow::__clear() {  void MainWindow::__clear() {
     // remove all entries from "Instrument" menu  
     Gtk::MenuItem* instrument_menu =  
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
     instrument_menu->hide();  
     for (int i = 0; i < instrument_menu->get_submenu()->items().size(); i++) {  
         delete &instrument_menu->get_submenu()->items()[i];  
     }  
     instrument_menu->get_submenu()->items().clear();  
558      // forget all samples that ought to be imported      // forget all samples that ought to be imported
559      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
560      // clear the samples and instruments tree views      // clear the samples and instruments tree views
561      m_refTreeModel->clear();      m_refTreeModel->clear();
562      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
563        // remove all entries from "Instrument" menu
564        while (!instrument_menu->get_children().empty()) {
565            remove_instrument_from_menu(0);
566        }
567      // free libgig's gig::File instance      // free libgig's gig::File instance
568      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
569      file = NULL;      file = NULL;
# Line 465  void MainWindow::on_action_file_new() Line 582  void MainWindow::on_action_file_new()
582      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
583      // already add one new instrument by default      // already add one new instrument by default
584      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
585      pInstrument->pInfo->Name = "Unnamed Instrument";      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
586      // update GUI with that new gig::File      // update GUI with that new gig::File
587      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
588  }  }
# Line 476  bool MainWindow::close_confirmation_dial Line 593  bool MainWindow::close_confirmation_dial
593                                   Glib::filename_display_basename(filename).c_str());                                   Glib::filename_display_basename(filename).c_str());
594      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
595      g_free(msg);      g_free(msg);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
596      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));      dialog.set_secondary_text(_("If you close without saving, your changes will be lost."));
 #endif  
597      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);      dialog.add_button(_("Close _Without Saving"), Gtk::RESPONSE_NO);
598      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
599      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);      dialog.add_button(file_has_name ? Gtk::Stock::SAVE : Gtk::Stock::SAVE_AS, Gtk::RESPONSE_YES);
# Line 492  bool MainWindow::close_confirmation_dial Line 607  bool MainWindow::close_confirmation_dial
607  bool MainWindow::leaving_shared_mode_dialog() {  bool MainWindow::leaving_shared_mode_dialog() {
608      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");      Glib::ustring msg = _("Detach from sampler and proceed working stand-alone?");
609      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);      Gtk::MessageDialog dialog(*this, msg, false, Gtk::MESSAGE_WARNING, Gtk::BUTTONS_NONE);
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6) || GTKMM_MAJOR_VERSION > 2  
610      dialog.set_secondary_text(      dialog.set_secondary_text(
611          _("If you proceed to work on another instrument file, it won't be "          _("If you proceed to work on another instrument file, it won't be "
612            "used by the sampler until you tell the sampler explicitly to "            "used by the sampler until you tell the sampler explicitly to "
613            "load it.")            "load it."));
    );  
 #endif  
614      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);      dialog.add_button(_("_Yes, Detach"), Gtk::RESPONSE_YES);
615      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
616      dialog.set_default_response(Gtk::RESPONSE_CANCEL);      dialog.set_default_response(Gtk::RESPONSE_CANCEL);
# Line 517  void MainWindow::on_action_file_open() Line 629  void MainWindow::on_action_file_open()
629      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
630      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
631      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
632    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
633      Gtk::FileFilter filter;      Gtk::FileFilter filter;
634      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
635    #else
636        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
637        filter->add_pattern("*.gig");
638    #endif
639      dialog.set_filter(filter);      dialog.set_filter(filter);
640      if (current_dir != "") {      if (current_gig_dir != "") {
641          dialog.set_current_folder(current_dir);          dialog.set_current_folder(current_gig_dir);
642      }      }
643      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
644          std::string filename = dialog.get_filename();          std::string filename = dialog.get_filename();
645          printf("filename=%s\n", filename.c_str());          printf("filename=%s\n", filename.c_str());
646          printf("on_action_file_open self=%x\n", Glib::Thread::self());          printf("on_action_file_open self=%x\n", Glib::Threads::Thread::self());
647          load_file(filename.c_str());          load_file(filename.c_str());
648          current_dir = Glib::path_get_dirname(filename);          current_gig_dir = Glib::path_get_dirname(filename);
649      }      }
650  }  }
651    
652  void MainWindow::load_file(const char* name)  void MainWindow::load_file(const char* name)
653  {  {
654      __clear();      __clear();
655      load_dialog = new LoadDialog("Loading...", *this);      load_dialog = new LoadDialog(_("Loading..."), *this);
656      load_dialog->show_all();      load_dialog->show_all();
657      loader = new Loader(strdup(name));      loader = new Loader(strdup(name));
658      loader->signal_progress().connect(      loader->signal_progress().connect(
# Line 568  void MainWindow::on_loader_progress() Line 685  void MainWindow::on_loader_progress()
685  void MainWindow::on_loader_finished()  void MainWindow::on_loader_finished()
686  {  {
687      printf("Loader finished!\n");      printf("Loader finished!\n");
688      printf("on_loader_finished self=%x\n", Glib::Thread::self());      printf("on_loader_finished self=%x\n", Glib::Threads::Thread::self());
689      load_gig(loader->gig, loader->filename);      load_gig(loader->gig, loader->filename);
690      load_dialog->hide();      load_dialog->hide();
691  }  }
# Line 640  bool MainWindow::file_save_as() Line 757  bool MainWindow::file_save_as()
757      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
758      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::SAVE, Gtk::RESPONSE_OK);
759      dialog.set_default_response(Gtk::RESPONSE_OK);      dialog.set_default_response(Gtk::RESPONSE_OK);
   
 #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 8) || GTKMM_MAJOR_VERSION > 2  
760      dialog.set_do_overwrite_confirmation();      dialog.set_do_overwrite_confirmation();
761      // TODO: an overwrite dialog for gtkmm < 2.8  
762  #endif  #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
763      Gtk::FileFilter filter;      Gtk::FileFilter filter;
764      filter.add_pattern("*.gig");      filter.add_pattern("*.gig");
765    #else
766        Glib::RefPtr<Gtk::FileFilter> filter = Gtk::FileFilter::create();
767        filter->add_pattern("*.gig");
768    #endif
769      dialog.set_filter(filter);      dialog.set_filter(filter);
770    
771      if (Glib::path_is_absolute(filename)) {      // set initial dir and filename of the Save As dialog
772          dialog.set_filename(filename);      // and prepare that initial filename as a copy of the gig
773      } else if (current_dir != "") {      {
774          dialog.set_current_folder(current_dir);          std::string basename = Glib::path_get_basename(filename);
775            std::string dir = Glib::path_get_dirname(filename);
776            basename = std::string(_("copy_of_")) + basename;
777            Glib::ustring copyFileName = Glib::build_filename(dir, basename);
778            if (Glib::path_is_absolute(filename)) {
779                dialog.set_filename(copyFileName);
780            } else {
781                if (current_gig_dir != "") dialog.set_current_folder(current_gig_dir);
782            }
783            dialog.set_current_name(Glib::filename_display_basename(copyFileName));
784      }      }
785      dialog.set_current_name(Glib::filename_display_basename(filename));  
786        // show warning in the dialog
787        Gtk::HBox descriptionArea;
788        descriptionArea.set_spacing(15);
789        Gtk::Image warningIcon(Gtk::Stock::DIALOG_WARNING, Gtk::IconSize(Gtk::ICON_SIZE_DIALOG));
790        descriptionArea.pack_start(warningIcon, Gtk::PACK_SHRINK);
791    #if GTKMM_MAJOR_VERSION < 3
792        view::WrapLabel description;
793    #else
794        Gtk::Label description;
795        description.set_line_wrap();
796    #endif
797        description.set_markup(
798            _("\n<b>CAUTION:</b> You <b>MUST</b> use the "
799              "<span style=\"italic\">\"Save\"</span> dialog instead of "
800              "<span style=\"italic\">\"Save As...\"</span> if you want to save "
801              "to the same .gig file. Using "
802              "<span style=\"italic\">\"Save As...\"</span> for writing to the "
803              "same .gig file will end up in corrupted sample wave data!\n")
804        );
805        descriptionArea.pack_start(description);
806        dialog.get_vbox()->pack_start(descriptionArea, Gtk::PACK_SHRINK);
807        descriptionArea.show_all();
808    
809      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
810          file_structure_to_be_changed_signal.emit(this->file);          file_structure_to_be_changed_signal.emit(this->file);
# Line 666  bool MainWindow::file_save_as() Line 816  bool MainWindow::file_save_as()
816              printf("filename=%s\n", filename.c_str());              printf("filename=%s\n", filename.c_str());
817              file->Save(filename);              file->Save(filename);
818              this->filename = filename;              this->filename = filename;
819              current_dir = Glib::path_get_dirname(filename);              current_gig_dir = Glib::path_get_dirname(filename);
820              set_title(Glib::filename_display_basename(filename));              set_title(Glib::filename_display_basename(filename));
821              file_has_name = true;              file_has_name = true;
822              file_is_changed = false;              file_is_changed = false;
# Line 695  void MainWindow::__import_queued_samples Line 845  void MainWindow::__import_queued_samples
845          SF_INFO info;          SF_INFO info;
846          info.format = 0;          info.format = 0;
847          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);
848            sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
849          try {          try {
850              if (!hFile) throw std::string("could not open file");              if (!hFile) throw std::string(_("could not open file"));
851              // determine sample's bit depth              // determine sample's bit depth
852              int bitdepth;              int bitdepth;
853              switch (info.format & 0xff) {              switch (info.format & 0xff) {
# Line 713  void MainWindow::__import_queued_samples Line 864  void MainWindow::__import_queued_samples
864                      break;                      break;
865                  default:                  default:
866                      sf_close(hFile); // close sound file                      sf_close(hFile); // close sound file
867                      throw std::string("format not supported"); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
868              }              }
869    
870              const int bufsize = 10000;              const int bufsize = 10000;
# Line 755  void MainWindow::__import_queued_samples Line 906  void MainWindow::__import_queued_samples
906              }              }
907              // cleanup              // cleanup
908              sf_close(hFile);              sf_close(hFile);
909                // let the sampler re-cache the sample if needed
910                sample_changed_signal.emit(iter->gig_sample);
911              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
912              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
913              std::list<SampleImportItem>::iterator cur = iter;              std::list<SampleImportItem>::iterator cur = iter;
# Line 762  void MainWindow::__import_queued_samples Line 915  void MainWindow::__import_queued_samples
915              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
916          } catch (std::string what) {          } catch (std::string what) {
917              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
918              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
919              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
920              ++iter;              ++iter;
921          }          }
922      }      }
923      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
924      if (error_files.size()) {      if (!error_files.empty()) {
925          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;
926          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
927          msg.run();          msg.run();
# Line 783  void MainWindow::on_action_file_properti Line 936  void MainWindow::on_action_file_properti
936    
937  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
938  {  {
 #ifdef ABOUT_DIALOG  
939      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
940    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 12) || GTKMM_MAJOR_VERSION > 2
941        dialog.set_program_name("Gigedit");
942    #else
943        dialog.set_name("Gigedit");
944    #endif
945      dialog.set_version(VERSION);      dialog.set_version(VERSION);
946      dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");
947      dialog.set_comments(      const std::string sComment =
948          "Released under the GNU General Public License.\n"          _("Built " __DATE__ "\nUsing ") +
949          "\n"          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
950          "Please notice that this is still a very young instrument editor. "          _(
951          "So better backup your Gigasampler files before editing them with "              "Gigedit is released under the GNU General Public License.\n"
952          "this application.\n"              "\n"
953          "\n"              "Please notice that this is still a very young instrument editor. "
954          "Please report bugs to: http://bugs.linuxsampler.org"              "So better backup your Gigasampler files before editing them with "
955      );              "this application.\n"
956                "\n"
957                "Please report bugs to: http://bugs.linuxsampler.org"
958            );
959        dialog.set_comments(sComment.c_str());
960      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
961      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
962      dialog.run();      dialog.run();
 #endif  
963  }  }
964    
965  PropDialog::PropDialog()  PropDialog::PropDialog()
966      : table(2,1)      : eName(_("Name")),
967          eCreationDate(_("Creation date")),
968          eComments(_("Comments")),
969          eProduct(_("Product")),
970          eCopyright(_("Copyright")),
971          eArtists(_("Artists")),
972          eGenre(_("Genre")),
973          eKeywords(_("Keywords")),
974          eEngineer(_("Engineer")),
975          eTechnician(_("Technician")),
976          eSoftware(_("Software")),
977          eMedium(_("Medium")),
978          eSource(_("Source")),
979          eSourceForm(_("Source form")),
980          eCommissioned(_("Commissioned")),
981          eSubject(_("Subject")),
982          quitButton(Gtk::Stock::CLOSE),
983          table(2, 1)
984  {  {
985        set_title(_("File Properties"));
986        eName.set_width_chars(50);
987    
988        connect(eName, &DLS::Info::Name);
989        connect(eCreationDate, &DLS::Info::CreationDate);
990        connect(eComments, &DLS::Info::Comments);
991        connect(eProduct, &DLS::Info::Product);
992        connect(eCopyright, &DLS::Info::Copyright);
993        connect(eArtists, &DLS::Info::Artists);
994        connect(eGenre, &DLS::Info::Genre);
995        connect(eKeywords, &DLS::Info::Keywords);
996        connect(eEngineer, &DLS::Info::Engineer);
997        connect(eTechnician, &DLS::Info::Technician);
998        connect(eSoftware, &DLS::Info::Software);
999        connect(eMedium, &DLS::Info::Medium);
1000        connect(eSource, &DLS::Info::Source);
1001        connect(eSourceForm, &DLS::Info::SourceForm);
1002        connect(eCommissioned, &DLS::Info::Commissioned);
1003        connect(eSubject, &DLS::Info::Subject);
1004    
1005        table.add(eName);
1006        table.add(eCreationDate);
1007        table.add(eComments);
1008        table.add(eProduct);
1009        table.add(eCopyright);
1010        table.add(eArtists);
1011        table.add(eGenre);
1012        table.add(eKeywords);
1013        table.add(eEngineer);
1014        table.add(eTechnician);
1015        table.add(eSoftware);
1016        table.add(eMedium);
1017        table.add(eSource);
1018        table.add(eSourceForm);
1019        table.add(eCommissioned);
1020        table.add(eSubject);
1021    
1022      table.set_col_spacings(5);      table.set_col_spacings(5);
1023      const char* propLabels[] = {      add(vbox);
1024          "Name:",      table.set_border_width(5);
1025          "CreationDate:",      vbox.add(table);
1026          "Comments:", // TODO: multiline      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
1027          "Product:",      buttonBox.set_layout(Gtk::BUTTONBOX_END);
1028          "Copyright:",      buttonBox.set_border_width(5);
1029          "Artists:",      buttonBox.show();
1030          "Genre:",      buttonBox.pack_start(quitButton);
1031          "Keywords:",      quitButton.set_can_default();
1032          "Engineer:",      quitButton.grab_focus();
1033          "Technician:",      quitButton.signal_clicked().connect(
1034          "Software:", // TODO: readonly          sigc::mem_fun(*this, &PropDialog::hide));
         "Medium:",  
         "Source:",  
         "SourceForm:",  
         "Commissioned:",  
         "Subject:"  
     };  
     for (int i = 0 ; i < sizeof(propLabels) / sizeof(char*) ; i++) {  
         label[i].set_text(propLabels[i]);  
         label[i].set_alignment(Gtk::ALIGN_LEFT);  
         table.attach(label[i], 0, 1, i, i + 1, Gtk::FILL, Gtk::SHRINK);  
         table.attach(entry[i], 1, 2, i, i + 1, Gtk::FILL | Gtk::EXPAND,  
                      Gtk::SHRINK);  
     }  
1035    
1036      add(table);      quitButton.show();
1037      // add_button(Gtk::Stock::CANCEL, 0);      vbox.show();
     // add_button(Gtk::Stock::OK, 1);  
1038      show_all_children();      show_all_children();
1039  }  }
1040    
1041  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1042  {  {
1043      entry[0].set_text(info->Name);      update(info);
     entry[1].set_text(info->CreationDate);  
     entry[2].set_text(Glib::convert(info->Comments, "UTF-8", "ISO-8859-1"));  
     entry[3].set_text(info->Product);  
     entry[4].set_text(info->Copyright);  
     entry[5].set_text(info->Artists);  
     entry[6].set_text(info->Genre);  
     entry[7].set_text(info->Keywords);  
     entry[8].set_text(info->Engineer);  
     entry[9].set_text(info->Technician);  
     entry[10].set_text(info->Software);  
     entry[11].set_text(info->Medium);  
     entry[12].set_text(info->Source);  
     entry[13].set_text(info->SourceForm);  
     entry[14].set_text(info->Commissioned);  
     entry[15].set_text(info->Subject);  
 }  
   
 void InstrumentProps::add_prop(BoolEntry& boolentry)  
 {  
     table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
                  Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
     boolentry.signal_changed_by_user().connect(instrument_changed.make_slot());  
 }  
   
 void InstrumentProps::add_prop(BoolEntryPlus6& boolentry)  
 {  
     table.attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
                  Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
     boolentry.signal_changed_by_user().connect(instrument_changed.make_slot());  
 }  
   
 void InstrumentProps::add_prop(LabelWidget& prop)  
 {  
     table.attach(prop.label, 0, 1, rowno, rowno + 1,  
                  Gtk::FILL, Gtk::SHRINK);  
     table.attach(prop.widget, 1, 2, rowno, rowno + 1,  
                  Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK);  
     rowno++;  
     prop.signal_changed_by_user().connect(instrument_changed.make_slot());  
1044  }  }
1045    
1046  InstrumentProps::InstrumentProps()  
1047      : table(2,1),  void InstrumentProps::set_Name(const gig::String& name)
1048        quitButton(Gtk::Stock::CLOSE),  {
1049        eName("Name"),      m->pInfo->Name = name;
1050        eIsDrum("Is drum"),  }
1051        eMIDIBank("MIDI bank", 0, 16383),  
1052        eMIDIProgram("MIDI program"),  void InstrumentProps::update_name()
1053        eAttenuation("Attenuation", 0, 96, 0, 1),  {
1054        eGainPlus6("Gain +6dB", eAttenuation, -6),      update_model++;
1055        eEffectSend("Effect send", 0, 65535),      eName.set_value(m->pInfo->Name);
1056        eFineTune("Fine tune", -8400, 8400),      update_model--;
1057        ePitchbendRange("Pitchbend range", 0, 12),  }
1058        ePianoReleaseMode("Piano release mode"),  
1059        eDimensionKeyRangeLow("Dimension key range low"),  void InstrumentProps::set_IsDrum(bool value)
1060        eDimensionKeyRangeHigh("Dimension key range high")  {
1061        m->IsDrum = value;
1062    }
1063    
1064    void InstrumentProps::set_MIDIBank(uint16_t value)
1065    {
1066        m->MIDIBank = value;
1067    }
1068    
1069    void InstrumentProps::set_MIDIProgram(uint32_t value)
1070    {
1071        m->MIDIProgram = value;
1072    }
1073    
1074    InstrumentProps::InstrumentProps() :
1075        quitButton(Gtk::Stock::CLOSE),
1076        table(2,1),
1077        eName(_("Name")),
1078        eIsDrum(_("Is drum")),
1079        eMIDIBank(_("MIDI bank"), 0, 16383),
1080        eMIDIProgram(_("MIDI program")),
1081        eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1082        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1083        eEffectSend(_("Effect send"), 0, 65535),
1084        eFineTune(_("Fine tune"), -8400, 8400),
1085        ePitchbendRange(_("Pitchbend range"), 0, 12),
1086        ePianoReleaseMode(_("Piano release mode")),
1087        eDimensionKeyRangeLow(_("Keyswitching range low")),
1088        eDimensionKeyRangeHigh(_("Keyswitching range high"))
1089  {  {
1090      set_title("Instrument properties");      set_title(_("Instrument Properties"));
1091    
1092        eDimensionKeyRangeLow.set_tip(
1093            _("start of the keyboard area which should switch the "
1094              "\"keyswitching\" dimension")
1095        );
1096        eDimensionKeyRangeHigh.set_tip(
1097            _("end of the keyboard area which should switch the "
1098              "\"keyswitching\" dimension")
1099        );
1100    
1101        connect(eName, &InstrumentProps::set_Name);
1102        connect(eIsDrum, &InstrumentProps::set_IsDrum);
1103        connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1104        connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
1105        connect(eAttenuation, &gig::Instrument::Attenuation);
1106        connect(eGainPlus6, &gig::Instrument::Attenuation);
1107        connect(eEffectSend, &gig::Instrument::EffectSend);
1108        connect(eFineTune, &gig::Instrument::FineTune);
1109        connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1110        connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1111        connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1112                &gig::Instrument::DimensionKeyRange);
1113    
1114        eName.signal_value_changed().connect(sig_name_changed.make_slot());
1115    
     rowno = 0;  
1116      table.set_col_spacings(5);      table.set_col_spacings(5);
1117    
1118      add_prop(eName);      table.add(eName);
1119      add_prop(eIsDrum);      table.add(eIsDrum);
1120      add_prop(eMIDIBank);      table.add(eMIDIBank);
1121      add_prop(eMIDIProgram);      table.add(eMIDIProgram);
1122      add_prop(eAttenuation);      table.add(eAttenuation);
1123      add_prop(eGainPlus6);      table.add(eGainPlus6);
1124      add_prop(eEffectSend);      table.add(eEffectSend);
1125      add_prop(eFineTune);      table.add(eFineTune);
1126      add_prop(ePitchbendRange);      table.add(ePitchbendRange);
1127      add_prop(ePianoReleaseMode);      table.add(ePianoReleaseMode);
1128      add_prop(eDimensionKeyRangeLow);      table.add(eDimensionKeyRangeLow);
1129      add_prop(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
   
     eDimensionKeyRangeLow.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed));  
     eDimensionKeyRangeHigh.signal_changed_by_user().connect(  
         sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed));  
1130    
1131      add(vbox);      add(vbox);
1132      table.set_border_width(5);      table.set_border_width(5);
# Line 932  InstrumentProps::InstrumentProps() Line 1137  InstrumentProps::InstrumentProps()
1137      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
1138      buttonBox.show();      buttonBox.show();
1139      buttonBox.pack_start(quitButton);      buttonBox.pack_start(quitButton);
1140      quitButton.set_flags(Gtk::CAN_DEFAULT);      quitButton.set_can_default();
1141      quitButton.grab_focus();      quitButton.grab_focus();
1142    
1143      quitButton.signal_clicked().connect(      quitButton.signal_clicked().connect(
# Line 945  InstrumentProps::InstrumentProps() Line 1150  InstrumentProps::InstrumentProps()
1150    
1151  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1152  {  {
1153      eName.set_ptr(&instrument->pInfo->Name);      update(instrument);
     eIsDrum.set_ptr(&instrument->IsDrum);  
     eMIDIBank.set_ptr(&instrument->MIDIBank);  
     eMIDIProgram.set_ptr(&instrument->MIDIProgram);  
     eAttenuation.set_ptr(&instrument->Attenuation);  
     eGainPlus6.set_ptr(&instrument->Attenuation);  
     eEffectSend.set_ptr(&instrument->EffectSend);  
     eFineTune.set_ptr(&instrument->FineTune);  
     ePitchbendRange.set_ptr(&instrument->PitchbendRange);  
     ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode);  
     eDimensionKeyRangeLow.set_ptr(0);  
     eDimensionKeyRangeHigh.set_ptr(0);  
     eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low);  
     eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high);  
 }  
1154    
1155  void InstrumentProps::key_range_low_changed()      update_model++;
1156  {      eName.set_value(instrument->pInfo->Name);
1157      double l = eDimensionKeyRangeLow.get_value();      eIsDrum.set_value(instrument->IsDrum);
1158      double h = eDimensionKeyRangeHigh.get_value();      eMIDIBank.set_value(instrument->MIDIBank);
1159      if (h < l) eDimensionKeyRangeHigh.set_value(l);      eMIDIProgram.set_value(instrument->MIDIProgram);
1160        update_model--;
1161  }  }
1162    
 void InstrumentProps::key_range_high_changed()  
 {  
     double l = eDimensionKeyRangeLow.get_value();  
     double h = eDimensionKeyRangeHigh.get_value();  
     if (h < l) eDimensionKeyRangeLow.set_value(h);  
 }  
   
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1163    
1164  void MainWindow::file_changed()  void MainWindow::file_changed()
1165  {  {
# Line 1000  void MainWindow::load_gig(gig::File* gig Line 1181  void MainWindow::load_gig(gig::File* gig
1181    
1182      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1183    
1184      Gtk::MenuItem* instrument_menu =      instrument_name_connection.block();
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
   
     int instrument_index = 0;  
     Gtk::RadioMenuItem::Group instrument_group;  
1185      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1186           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1187            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1188    
1189          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1190          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1191          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1192          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1193          // create a menu item for this instrument  
1194          Gtk::RadioMenuItem* item =          add_instrument_to_menu(name);
             new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str());  
         instrument_menu->get_submenu()->append(*item);  
         item->signal_activate().connect(  
             sigc::bind(  
                 sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),  
                 instrument_index  
             )  
         );  
         instrument_index++;  
1195      }      }
1196      instrument_menu->show();      instrument_name_connection.unblock();
1197      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1198    
1199      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1200          if (group->Name != "") {          if (group->Name != "") {
1201              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1202              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1203              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1204              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1205              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1206              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1038  void MainWindow::load_gig(gig::File* gig Line 1208  void MainWindow::load_gig(gig::File* gig
1208                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1209                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1210                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1211                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1212                        gig_to_utf8(sample->pInfo->Name);
1213                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1214                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1215              }              }
# Line 1048  void MainWindow::load_gig(gig::File* gig Line 1219  void MainWindow::load_gig(gig::File* gig
1219      file = gig;      file = gig;
1220    
1221      // select the first instrument      // select the first instrument
1222      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1223      tree_sel_ref->select(Gtk::TreePath("0"));  
1224        instr_props_set_instrument();
1225        gig::Instrument* instrument = get_instrument();
1226        if (instrument) {
1227            midiRules.set_instrument(instrument);
1228        }
1229    }
1230    
1231    bool MainWindow::instr_props_set_instrument()
1232    {
1233        instrumentProps.signal_name_changed().clear();
1234    
1235        Gtk::TreeModel::const_iterator it =
1236            m_TreeView.get_selection()->get_selected();
1237        if (it) {
1238            Gtk::TreeModel::Row row = *it;
1239            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1240    
1241            instrumentProps.set_instrument(instrument);
1242    
1243            // make sure instrument tree is updated when user changes the
1244            // instrument name in instrument properties window
1245            instrumentProps.signal_name_changed().connect(
1246                sigc::bind(
1247                    sigc::mem_fun(*this,
1248                                  &MainWindow::instr_name_changed_by_instr_props),
1249                    it));
1250        } else {
1251            instrumentProps.hide();
1252        }
1253        return it;
1254  }  }
1255    
1256  void MainWindow::show_instr_props()  void MainWindow::show_instr_props()
1257  {  {
1258      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      if (instr_props_set_instrument()) {
1259      Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();          instrumentProps.show();
1260      if (it)          instrumentProps.deiconify();
1261        }
1262    }
1263    
1264    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1265    {
1266        Gtk::TreeModel::Row row = *it;
1267        Glib::ustring name = row[m_Columns.m_col_name];
1268    
1269        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1270        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1271        if (gigname != name) {
1272            row[m_Columns.m_col_name] = gigname;
1273        }
1274    }
1275    
1276    void MainWindow::show_midi_rules()
1277    {
1278        if (gig::Instrument* instrument = get_instrument())
1279      {      {
1280          Gtk::TreeModel::Row row = *it;          midiRules.set_instrument(instrument);
1281          if (row[m_Columns.m_col_instr])          midiRules.show();
1282          {          midiRules.deiconify();
             instrumentProps.set_instrument(row[m_Columns.m_col_instr]);  
             instrumentProps.show();  
             instrumentProps.deiconify();  
         }  
1283      }      }
1284  }  }
1285    
# Line 1079  void MainWindow::on_action_view_status_b Line 1294  void MainWindow::on_action_view_status_b
1294      else                    m_StatusBar.hide();      else                    m_StatusBar.hide();
1295  }  }
1296    
1297    bool MainWindow::is_copy_samples_unity_note_enabled() const {
1298        Gtk::CheckMenuItem* item =
1299            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleUnity"));
1300        if (!item) {
1301            std::cerr << "/MenuBar/MenuEdit/CopySampleUnity == NULL\n";
1302            return true;
1303        }
1304        return item->get_active();
1305    }
1306    
1307    bool MainWindow::is_copy_samples_fine_tune_enabled() const {
1308        Gtk::CheckMenuItem* item =
1309            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleTune"));
1310        if (!item) {
1311            std::cerr << "/MenuBar/MenuEdit/CopySampleTune == NULL\n";
1312            return true;
1313        }
1314        return item->get_active();
1315    }
1316    
1317    bool MainWindow::is_copy_samples_loop_enabled() const {
1318        Gtk::CheckMenuItem* item =
1319            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuEdit/CopySampleLoop"));
1320        if (!item) {
1321            std::cerr << "/MenuBar/MenuEdit/CopySampleLoop == NULL\n";
1322            return true;
1323        }
1324        return item->get_active();
1325    }
1326    
1327  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
1328  {  {
1329      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
1330          show_instr_props();          show_instr_props();
1331      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1332            // gig v2 files have no midi rules
1333            static_cast<Gtk::MenuItem*>(
1334                uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive(
1335                    !(file->pVersion && file->pVersion->major == 2));
1336          popup_menu->popup(button->button, button->time);          popup_menu->popup(button->button, button->time);
1337      }      }
1338  }  }
1339    
1340  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1341      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1342            const std::vector<Gtk::Widget*> children =
1343                instrument_menu->get_children();
1344            std::vector<Gtk::Widget*>::const_iterator it =
1345                find(children.begin(), children.end(), item);
1346            if (it != children.end()) {
1347                int index = it - children.begin();
1348                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1349    
1350                m_RegionChooser.set_instrument(file->GetInstrument(index));
1351            }
1352        }
1353  }  }
1354    
1355  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1119  void MainWindow::on_sample_treeview_butt Line 1379  void MainWindow::on_sample_treeview_butt
1379      }      }
1380  }  }
1381    
1382  void MainWindow::on_action_add_instrument() {  
1383      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1384      if (!file) return;      const Glib::ustring& name, int position) {
1385      gig::Instrument* instrument = file->AddInstrument();  
1386      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1387      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1388          "Unnamed Instrument " + ToString(__instrument_indexer);      if (!children.empty()) {
1389            instrument_group =
1390                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1391        }
1392        Gtk::RadioMenuItem* item =
1393            new Gtk::RadioMenuItem(instrument_group, name);
1394        if (position < 0) {
1395            instrument_menu->append(*item);
1396        } else {
1397            instrument_menu->insert(*item, position);
1398        }
1399        item->show();
1400        item->signal_activate().connect(
1401            sigc::bind(
1402                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1403                item));
1404        return item;
1405    }
1406    
1407    void MainWindow::remove_instrument_from_menu(int index) {
1408        const std::vector<Gtk::Widget*> children =
1409            instrument_menu->get_children();
1410        Gtk::Widget* child = children[index];
1411        instrument_menu->remove(*child);
1412        delete child;
1413    }
1414    
1415    void MainWindow::add_instrument(gig::Instrument* instrument) {
1416        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1417    
1418      // update instrument tree view      // update instrument tree view
1419        instrument_name_connection.block();
1420      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1421      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1422      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1423      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1424        instrument_name_connection.unblock();
1425    
1426        add_instrument_to_menu(name);
1427    
1428        m_TreeView.get_selection()->select(iterInstr);
1429    
1430      file_changed();      file_changed();
1431  }  }
1432    
1433    void MainWindow::on_action_add_instrument() {
1434        static int __instrument_indexer = 0;
1435        if (!file) return;
1436        gig::Instrument* instrument = file->AddInstrument();
1437        __instrument_indexer++;
1438        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1439                                                ToString(__instrument_indexer));
1440    
1441        add_instrument(instrument);
1442    }
1443    
1444    void MainWindow::on_action_duplicate_instrument() {
1445        if (!file) return;
1446    
1447        // retrieve the currently selected instrument
1448        // (being the original instrument to be duplicated)
1449        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1450        Gtk::TreeModel::iterator itSelection = sel->get_selected();
1451        if (!itSelection) return;
1452        Gtk::TreeModel::Row row = *itSelection;
1453        gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1454        if (!instrOrig) return;
1455    
1456        // duplicate the orginal instrument
1457        gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1458        instrNew->pInfo->Name =
1459            instrOrig->pInfo->Name +
1460            gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1461    
1462        add_instrument(instrNew);
1463    }
1464    
1465  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
1466      if (!file) return;      if (!file) return;
1467      if (file_is_shared) {      if (file_is_shared) {
# Line 1153  void MainWindow::on_action_remove_instru Line 1481  void MainWindow::on_action_remove_instru
1481          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1482          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1483          try {          try {
1484                Gtk::TreePath path(it);
1485                int index = path[0];
1486    
1487              // remove instrument from the gig file              // remove instrument from the gig file
1488              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1489              file_changed();              file_changed();
1490    
1491                remove_instrument_from_menu(index);
1492    
1493                // remove row from instruments tree view
1494                m_refTreeModel->erase(it);
1495    
1496    #if GTKMM_MAJOR_VERSION < 3
1497                // select another instrument (in gtk3 this is done
1498                // automatically)
1499                if (!m_refTreeModel->children().empty()) {
1500                    if (index == m_refTreeModel->children().size()) {
1501                        index--;
1502                    }
1503                    m_TreeView.get_selection()->select(
1504                        Gtk::TreePath(ToString(index)));
1505                }
1506    #endif
1507                instr_props_set_instrument();
1508                instr = get_instrument();
1509                if (instr) {
1510                    midiRules.set_instrument(instr);
1511                } else {
1512                    midiRules.hide();
1513                }
1514          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1515              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1516              msg.run();              msg.run();
# Line 1168  void MainWindow::on_action_remove_instru Line 1521  void MainWindow::on_action_remove_instru
1521  void MainWindow::on_action_sample_properties() {  void MainWindow::on_action_sample_properties() {
1522      //TODO: show a dialog where the selected sample's properties can be edited      //TODO: show a dialog where the selected sample's properties can be edited
1523      Gtk::MessageDialog msg(      Gtk::MessageDialog msg(
1524          *this, "Sorry, yet to be implemented!", false, Gtk::MESSAGE_INFO          *this, _("Sorry, yet to be implemented!"), false, Gtk::MESSAGE_INFO
1525      );      );
1526      msg.run();      msg.run();
1527  }  }
# Line 1177  void MainWindow::on_action_add_group() { Line 1530  void MainWindow::on_action_add_group() {
1530      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1531      if (!file) return;      if (!file) return;
1532      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1533      group->Name = "Unnamed Group";      group->Name = gig_from_utf8(_("Unnamed Group"));
1534      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1535      __sample_indexer++;      __sample_indexer++;
1536      // update sample tree view      // update sample tree view
1537      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1538      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1539      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1540      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1541      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1542      file_changed();      file_changed();
# Line 1211  void MainWindow::on_action_add_sample() Line 1564  void MainWindow::on_action_add_sample()
1564      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);      dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1565      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);      dialog.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
1566      dialog.set_select_multiple(true);      dialog.set_select_multiple(true);
1567      Gtk::FileFilter soundfilter; // matches all file types supported by libsndfile  
1568        // matches all file types supported by libsndfile
1569    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1570        Gtk::FileFilter soundfilter;
1571    #else
1572        Glib::RefPtr<Gtk::FileFilter> soundfilter = Gtk::FileFilter::create();
1573    #endif
1574      const char* const supportedFileTypes[] = {      const char* const supportedFileTypes[] = {
1575          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",          "*.wav", "*.WAV", "*.aiff", "*.AIFF", "*.aifc", "*.AIFC", "*.snd",
1576          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",          "*.SND", "*.au", "*.AU", "*.paf", "*.PAF", "*.iff", "*.IFF",
# Line 1219  void MainWindow::on_action_add_sample() Line 1578  void MainWindow::on_action_add_sample()
1578          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",          "*.W64", "*.pvf", "*.PVF", "*.xi", "*.XI", "*.htk", "*.HTK",
1579          "*.caf", "*.CAF", NULL          "*.caf", "*.CAF", NULL
1580      };      };
1581        const char* soundfiles = _("Sound Files");
1582        const char* allfiles = _("All Files");
1583    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
1584      for (int i = 0; supportedFileTypes[i]; i++)      for (int i = 0; supportedFileTypes[i]; i++)
1585          soundfilter.add_pattern(supportedFileTypes[i]);          soundfilter.add_pattern(supportedFileTypes[i]);
1586      soundfilter.set_name("Sound Files");      soundfilter.set_name(soundfiles);
1587      Gtk::FileFilter allpassfilter; // matches every file  
1588        // matches every file
1589        Gtk::FileFilter allpassfilter;
1590      allpassfilter.add_pattern("*.*");      allpassfilter.add_pattern("*.*");
1591      allpassfilter.set_name("All Files");      allpassfilter.set_name(allfiles);
1592    #else
1593        for (int i = 0; supportedFileTypes[i]; i++)
1594            soundfilter->add_pattern(supportedFileTypes[i]);
1595        soundfilter->set_name(soundfiles);
1596    
1597        // matches every file
1598        Glib::RefPtr<Gtk::FileFilter> allpassfilter = Gtk::FileFilter::create();
1599        allpassfilter->add_pattern("*.*");
1600        allpassfilter->set_name(allfiles);
1601    #endif
1602      dialog.add_filter(soundfilter);      dialog.add_filter(soundfilter);
1603      dialog.add_filter(allpassfilter);      dialog.add_filter(allpassfilter);
1604        if (current_sample_dir != "") {
1605            dialog.set_current_folder(current_sample_dir);
1606        }
1607      if (dialog.run() == Gtk::RESPONSE_OK) {      if (dialog.run() == Gtk::RESPONSE_OK) {
1608            current_sample_dir = dialog.get_current_folder();
1609          Glib::ustring error_files;          Glib::ustring error_files;
1610          Glib::SListHandle<Glib::ustring> filenames = dialog.get_filenames();          std::vector<std::string> filenames = dialog.get_filenames();
1611          for (Glib::SListHandle<Glib::ustring>::iterator iter = filenames.begin();          for (std::vector<std::string>::iterator iter = filenames.begin();
1612               iter != filenames.end(); ++iter) {               iter != filenames.end(); ++iter) {
1613              printf("Adding sample %s\n",(*iter).c_str());              printf("Adding sample %s\n",(*iter).c_str());
1614              // use libsndfile to retrieve file informations              // use libsndfile to retrieve file informations
# Line 1238  void MainWindow::on_action_add_sample() Line 1616  void MainWindow::on_action_add_sample()
1616              info.format = 0;              info.format = 0;
1617              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open((*iter).c_str(), SFM_READ, &info);
1618              try {              try {
1619                  if (!hFile) throw std::string("could not open file");                  if (!hFile) throw std::string(_("could not open file"));
1620                  int bitdepth;                  int bitdepth;
1621                  switch (info.format & 0xff) {                  switch (info.format & 0xff) {
1622                      case SF_FORMAT_PCM_S8:                      case SF_FORMAT_PCM_S8:
# Line 1254  void MainWindow::on_action_add_sample() Line 1632  void MainWindow::on_action_add_sample()
1632                          break;                          break;
1633                      default:                      default:
1634                          sf_close(hFile); // close sound file                          sf_close(hFile); // close sound file
1635                          throw std::string("format not supported"); // unsupported subformat (yet?)                          throw std::string(_("format not supported")); // unsupported subformat (yet?)
1636                  }                  }
1637                  // add a new sample to the .gig file                  // add a new sample to the .gig file
1638                  gig::Sample* sample = file->AddSample();                  gig::Sample* sample = file->AddSample();
# Line 1267  void MainWindow::on_action_add_sample() Line 1645  void MainWindow::on_action_add_sample()
1645                          break;                          break;
1646                      }                      }
1647                  }                  }
1648                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1649                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1650                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1651                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1281  void MainWindow::on_action_add_sample() Line 1659  void MainWindow::on_action_add_sample()
1659                                 &instrument, sizeof(instrument)) != SF_FALSE)                                 &instrument, sizeof(instrument)) != SF_FALSE)
1660                  {                  {
1661                      sample->MIDIUnityNote = instrument.basenote;                      sample->MIDIUnityNote = instrument.basenote;
1662                        sample->FineTune      = instrument.detune;
1663    
 #if HAVE_SF_INSTRUMENT_LOOPS  
1664                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {                      if (instrument.loop_count && instrument.loops[0].mode != SF_LOOP_NONE) {
1665                          sample->Loops = 1;                          sample->Loops = 1;
1666    
# Line 1302  void MainWindow::on_action_add_sample() Line 1680  void MainWindow::on_action_add_sample()
1680                          sample->LoopPlayCount = instrument.loops[0].count;                          sample->LoopPlayCount = instrument.loops[0].count;
1681                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;                          sample->LoopSize = sample->LoopEnd - sample->LoopStart + 1;
1682                      }                      }
 #endif  
1683                  }                  }
1684    
1685                  // schedule resizing the sample (which will be done                  // schedule resizing the sample (which will be done
# Line 1320  void MainWindow::on_action_add_sample() Line 1697  void MainWindow::on_action_add_sample()
1697                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1698                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1699                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1700                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1701                        gig_to_utf8(sample->pInfo->Name);
1702                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1703                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1704                  // close sound file                  // close sound file
1705                  sf_close(hFile);                  sf_close(hFile);
1706                  file_changed();                  file_changed();
1707              } catch (std::string what) { // remember the files that made trouble (and their cause)              } catch (std::string what) { // remember the files that made trouble (and their cause)
1708                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1709                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1710              }              }
1711          }          }
1712          // 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
1713          if (error_files.size()) {          if (!error_files.empty()) {
1714              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;
1715              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1716              msg.run();              msg.run();
# Line 1340  void MainWindow::on_action_add_sample() Line 1718  void MainWindow::on_action_add_sample()
1718      }      }
1719  }  }
1720    
1721    void MainWindow::on_action_replace_all_samples_in_all_groups()
1722    {
1723        if (!file) return;
1724        Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1725                                      Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1726        const char* str =
1727            _("This is a very specific function. It tries to replace all samples "
1728              "in the current gig file by samples located in the chosen "
1729              "directory.\n\n"
1730              "It works like this: For each sample in the gig file, it tries to "
1731              "find a sample file in the selected directory with the same name as "
1732              "the sample in the gig file. Optionally, you can add a filename "
1733              "extension below, which will be added to the filename expected to be "
1734              "found. That is, assume you have a gig file with a sample called "
1735              "'Snare', if you enter '.wav' below (like it's done by default), it "
1736              "expects to find a sample file called 'Snare.wav' and will replace "
1737              "the sample in the gig file accordingly. If you don't need an "
1738              "extension, blank the field below. Any gig sample where no "
1739              "appropriate sample file could be found will be reported and left "
1740              "untouched.\n");
1741    #if GTKMM_MAJOR_VERSION < 3
1742        view::WrapLabel description(str);
1743    #else
1744        Gtk::Label description(str);
1745        description.set_line_wrap();
1746    #endif
1747        Gtk::HBox entryArea;
1748        Gtk::Label entryLabel( _("Add filename extension: "), Gtk::ALIGN_START);
1749        Gtk::Entry postfixEntryBox;
1750        postfixEntryBox.set_text(".wav");
1751        entryArea.pack_start(entryLabel);
1752        entryArea.pack_start(postfixEntryBox);
1753        dialog.get_vbox()->pack_start(description, Gtk::PACK_SHRINK);
1754        dialog.get_vbox()->pack_start(entryArea, Gtk::PACK_SHRINK);
1755        description.show();
1756        entryArea.show_all();
1757        dialog.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
1758        dialog.add_button(_("Select"), Gtk::RESPONSE_OK);
1759        dialog.set_select_multiple(false);
1760        if (current_sample_dir != "") {
1761            dialog.set_current_folder(current_sample_dir);
1762        }
1763        if (dialog.run() == Gtk::RESPONSE_OK)
1764        {
1765            current_sample_dir = dialog.get_current_folder();
1766            Glib::ustring error_files;
1767            std::string folder = dialog.get_filename();
1768            for (gig::Sample* sample = file->GetFirstSample();
1769                 sample; sample = file->GetNextSample())
1770            {
1771                std::string filename =
1772                    folder + G_DIR_SEPARATOR_S +
1773                    Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1774                                             postfixEntryBox.get_text());
1775                SF_INFO info;
1776                info.format = 0;
1777                SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
1778                try
1779                {
1780                    if (!hFile) throw std::string(_("could not open file"));
1781                    int bitdepth;
1782                    switch (info.format & 0xff) {
1783                        case SF_FORMAT_PCM_S8:
1784                        case SF_FORMAT_PCM_16:
1785                        case SF_FORMAT_PCM_U8:
1786                            bitdepth = 16;
1787                            break;
1788                        case SF_FORMAT_PCM_24:
1789                        case SF_FORMAT_PCM_32:
1790                        case SF_FORMAT_FLOAT:
1791                        case SF_FORMAT_DOUBLE:
1792                            bitdepth = 24;
1793                            break;
1794                        default:
1795                            sf_close(hFile);
1796                            throw std::string(_("format not supported"));
1797                    }
1798                    SampleImportItem sched_item;
1799                    sched_item.gig_sample  = sample;
1800                    sched_item.sample_path = filename;
1801                    m_SampleImportQueue.push_back(sched_item);
1802                    sf_close(hFile);
1803                    file_changed();
1804                }
1805                catch (std::string what)
1806                {
1807                    if (!error_files.empty()) error_files += "\n";
1808                    error_files += Glib::filename_to_utf8(filename) +
1809                        " (" + what + ")";
1810                }
1811            }
1812            // show error message box when some file(s) could not be opened / added
1813            if (!error_files.empty()) {
1814                Glib::ustring txt =
1815                    _("Could not replace the following sample(s):\n") + error_files;
1816                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1817                msg.run();
1818            }
1819        }
1820    }
1821    
1822  void MainWindow::on_action_remove_sample() {  void MainWindow::on_action_remove_sample() {
1823      if (!file) return;      if (!file) return;
1824      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
# Line 1352  void MainWindow::on_action_remove_sample Line 1831  void MainWindow::on_action_remove_sample
1831          try {          try {
1832              // remove group or sample from the gig file              // remove group or sample from the gig file
1833              if (group) {              if (group) {
1834                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1835                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1836                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1837                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1478  void MainWindow::on_sample_label_drop_dr Line 1957  void MainWindow::on_sample_label_drop_dr
1957              channels_changed = true;              channels_changed = true;
1958              region_changed();              region_changed();
1959          }          }
1960          dimreg_edit.set_sample(sample);          dimreg_edit.set_sample(
1961                sample,
1962                is_copy_samples_unity_note_enabled(),
1963                is_copy_samples_fine_tune_enabled(),
1964                is_copy_samples_loop_enabled()
1965            );
1966    
1967          if (sample->Channels == 2 && !stereo_dimension) {          if (sample->Channels == 2 && !stereo_dimension) {
1968              // add samplechannel dimension              // add samplechannel dimension
# Line 1506  void MainWindow::on_sample_label_drop_dr Line 1990  void MainWindow::on_sample_label_drop_dr
1990          // notify we're done with altering          // notify we're done with altering
1991          region_changed_signal.emit(region);          region_changed_signal.emit(region);
1992    
1993            file_changed();
1994    
1995          return;          return;
1996      }      }
1997      // drop failed      // drop failed
# Line 1519  void MainWindow::sample_name_changed(con Line 2005  void MainWindow::sample_name_changed(con
2005      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
2006      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
2007      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2008        gig::String gigname(gig_from_utf8(name));
2009      if (group) {      if (group) {
2010          if (group->Name != name) {          if (group->Name != gigname) {
2011              group->Name = name;              group->Name = gigname;
2012              printf("group name changed\n");              printf("group name changed\n");
2013              file_changed();              file_changed();
2014          }          }
2015      } else if (sample) {      } else if (sample) {
2016          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
2017              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
2018              printf("sample name changed\n");              printf("sample name changed\n");
2019              file_changed();              file_changed();
2020          }          }
# Line 1539  void MainWindow::instrument_name_changed Line 2026  void MainWindow::instrument_name_changed
2026      if (!iter) return;      if (!iter) return;
2027      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
2028      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
2029    
2030        // change name in instrument menu
2031        int index = path[0];
2032        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
2033        if (index < children.size()) {
2034    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
2035            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
2036    #else
2037            remove_instrument_from_menu(index);
2038            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
2039            item->set_active();
2040    #endif
2041        }
2042    
2043        // change name in gig
2044      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
2045      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
2046          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
2047            instrument->pInfo->Name = gigname;
2048    
2049            // change name in the instrument properties window
2050            if (instrumentProps.get_instrument() == instrument) {
2051                instrumentProps.update_name();
2052            }
2053    
2054          file_changed();          file_changed();
2055      }      }
2056  }  }
# Line 1586  sigc::signal<void, gig::Region*>& MainWi Line 2095  sigc::signal<void, gig::Region*>& MainWi
2095      return region_changed_signal;      return region_changed_signal;
2096  }  }
2097    
2098    sigc::signal<void, gig::Sample*>& MainWindow::signal_sample_changed() {
2099        return sample_changed_signal;
2100    }
2101    
2102  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {  sigc::signal<void, gig::Sample*/*old*/, gig::Sample*/*new*/>& MainWindow::signal_sample_ref_changed() {
2103      return sample_ref_changed_signal;      return sample_ref_changed_signal;
2104  }  }
# Line 1597  sigc::signal<void, gig::DimensionRegion* Line 2110  sigc::signal<void, gig::DimensionRegion*
2110  sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {  sigc::signal<void, gig::DimensionRegion*>& MainWindow::signal_dimreg_changed() {
2111      return dimreg_changed_signal;      return dimreg_changed_signal;
2112  }  }
2113    
2114    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_on() {
2115        return note_on_signal;
2116    }
2117    
2118    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_note_off() {
2119        return note_off_signal;
2120    }
2121    
2122    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_hit() {
2123        return m_RegionChooser.signal_keyboard_key_hit();
2124    }
2125    
2126    sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
2127        return m_RegionChooser.signal_keyboard_key_released();
2128    }

Legend:
Removed from v.1436  
changed lines
  Added in v.2507

  ViewVC Help
Powered by ViewVC