/[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 3162 by schoenebeck, Tue May 9 14:35:23 2017 UTC revision 3340 by schoenebeck, Mon Jul 31 11:20:18 2017 UTC
# Line 32  Line 32 
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
34  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
35    #include <glibmm/regex.h>
36  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
37  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
38  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
# Line 62  Line 63 
63  #include "gfx/builtinpix.h"  #include "gfx/builtinpix.h"
64  #include "MacroEditor.h"  #include "MacroEditor.h"
65  #include "MacrosSetup.h"  #include "MacrosSetup.h"
66    #if defined(__APPLE__)
67    # include "MacHelper.h"
68    #endif
69    
70    static const Gdk::ModifierType primaryModifierKey =
71        #if defined(__APPLE__)
72        Gdk::META_MASK; // Cmd key on Mac
73        #else
74        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
75        #endif
76    
77  MainWindow::MainWindow() :  MainWindow::MainWindow() :
78      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
# Line 77  MainWindow::MainWindow() : Line 88  MainWindow::MainWindow() :
88  {  {
89      loadBuiltInPix();      loadBuiltInPix();
90    
91        this->file = NULL;
92    
93  //    set_border_width(5);  //    set_border_width(5);
94  //    set_default_size(400, 200);  
95        if (!Settings::singleton()->autoRestoreWindowDimension) {
96            set_default_size(800, 600);
97            set_position(Gtk::WIN_POS_CENTER);
98        }
99    
100      add(m_VBox);      add(m_VBox);
101    
# Line 105  MainWindow::MainWindow() : Line 122  MainWindow::MainWindow() :
122    
123      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
124    
125      m_HPaned.add1(m_TreeViewNotebook);      m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
126        m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
127        m_searchField.pack_start(m_searchText);
128        m_searchField.set_spacing(5);
129    
130        m_left_vbox.pack_start(m_TreeViewNotebook);
131        m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
132    
133        m_HPaned.add1(m_left_vbox);
134    
135      dimreg_hbox.add(dimreg_label);      dimreg_hbox.add(dimreg_label);
136      dimreg_hbox.add(dimreg_all_regions);      dimreg_hbox.add(dimreg_all_regions);
137      dimreg_hbox.add(dimreg_all_dimregs);      dimreg_hbox.add(dimreg_all_dimregs);
# Line 207  MainWindow::MainWindow() : Line 233  MainWindow::MainWindow() :
233          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
234      );      );
235      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
236        actionGroup->add(Gtk::Action::create("AssignScripts", _("Assign Script")));
237    
238      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
239    
# Line 232  MainWindow::MainWindow() : Line 259  MainWindow::MainWindow() :
259                       Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),                       Gtk::AccelKey(GDK_KEY_x, Gdk::MOD1_MASK),
260                       sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));                       sigc::mem_fun(*this, &MainWindow::adjust_clipboard_content));
261    
262        actionGroup->add(Gtk::Action::create("SelectPrevInstr",
263                                             _("Select Previous Instrument")),
264                         Gtk::AccelKey(GDK_KEY_Up, primaryModifierKey),
265                         sigc::mem_fun(*this, &MainWindow::select_prev_instrument));
266    
267        actionGroup->add(Gtk::Action::create("SelectNextInstr",
268                                             _("Select Next Instrument")),
269                         Gtk::AccelKey(GDK_KEY_Down, primaryModifierKey),
270                         sigc::mem_fun(*this, &MainWindow::select_next_instrument));
271    
272      actionGroup->add(Gtk::Action::create("SelectPrevRegion",      actionGroup->add(Gtk::Action::create("SelectPrevRegion",
273                                           _("Select Previous Region")),                                           _("Select Previous Region")),
274                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
# Line 333  MainWindow::MainWindow() : Line 370  MainWindow::MainWindow() :
370          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
371      );      );
372      actionGroup->add(      actionGroup->add(
373            Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
374            Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
375            sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
376        );
377        actionGroup->add(
378          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),          Gtk::Action::create("RemoveInstrument", Gtk::Stock::REMOVE),
379          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_remove_instrument)
380      );      );
# Line 455  MainWindow::MainWindow() : Line 497  MainWindow::MainWindow() :
497          "      <menuitem action='AdjustClipboard'/>"          "      <menuitem action='AdjustClipboard'/>"
498          "      <menuitem action='PasteDimRgn'/>"          "      <menuitem action='PasteDimRgn'/>"
499          "      <separator/>"          "      <separator/>"
500            "      <menuitem action='SelectPrevInstr'/>"
501            "      <menuitem action='SelectNextInstr'/>"
502            "      <separator/>"
503          "      <menuitem action='SelectPrevRegion'/>"          "      <menuitem action='SelectPrevRegion'/>"
504          "      <menuitem action='SelectNextRegion'/>"          "      <menuitem action='SelectNextRegion'/>"
505          "      <separator/>"          "      <separator/>"
# Line 489  MainWindow::MainWindow() : Line 534  MainWindow::MainWindow() :
534          "      <menuitem action='InstrProperties'/>"          "      <menuitem action='InstrProperties'/>"
535          "      <menuitem action='MidiRules'/>"          "      <menuitem action='MidiRules'/>"
536          "      <menuitem action='ScriptSlots'/>"          "      <menuitem action='ScriptSlots'/>"
537            "      <menu action='AssignScripts'/>"
538          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
539          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
540            "      <menuitem action='CombInstruments'/>"
541          "      <separator/>"          "      <separator/>"
542          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
543          "    </menu>"          "    </menu>"
# Line 527  MainWindow::MainWindow() : Line 574  MainWindow::MainWindow() :
574          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
575          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
576          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
577            "    <menuitem action='CombInstruments'/>"
578          "    <separator/>"          "    <separator/>"
579          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
580          "  </popup>"          "  </popup>"
# Line 621  MainWindow::MainWindow() : Line 669  MainWindow::MainWindow() :
669      instrument_menu = static_cast<Gtk::MenuItem*>(      instrument_menu = static_cast<Gtk::MenuItem*>(
670          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();          uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu();
671    
672        assign_scripts_menu = static_cast<Gtk::MenuItem*>(
673            uiManager->get_widget("/MenuBar/MenuInstrument/AssignScripts"))->get_submenu();
674    
675      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
676      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
677      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
# Line 644  MainWindow::MainWindow() : Line 695  MainWindow::MainWindow() :
695    
696      // Create the Tree model:      // Create the Tree model:
697      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
698      m_TreeView.set_model(m_refTreeModel);      m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
699        m_refTreeModelFilter->set_visible_func(
700            sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
701        );
702        m_TreeView.set_model(m_refTreeModelFilter);
703    
704      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
705      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
706      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
# Line 654  MainWindow::MainWindow() : Line 710  MainWindow::MainWindow() :
710      // Add the TreeView's view columns:      // Add the TreeView's view columns:
711      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);      m_TreeView.append_column(_("Nr"), m_Columns.m_col_nr);
712      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);      m_TreeView.append_column_editable(_("Instrument"), m_Columns.m_col_name);
713        m_TreeView.append_column(_("Scripts"), m_Columns.m_col_scripts);
714      m_TreeView.set_headers_visible(true);      m_TreeView.set_headers_visible(true);
715            
716      // establish drag&drop within the instrument tree view, allowing to reorder      // establish drag&drop within the instrument tree view, allowing to reorder
# Line 819  MainWindow::MainWindow() : Line 876  MainWindow::MainWindow() :
876      dimreg_stereo.signal_toggled().connect(      dimreg_stereo.signal_toggled().connect(
877          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
878    
879        m_searchText.signal_changed().connect(
880            sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
881        );
882    
883      file = 0;      file = 0;
884      file_is_changed = false;      file_is_changed = false;
885    
# Line 827  MainWindow::MainWindow() : Line 888  MainWindow::MainWindow() :
888      // start with a new gig file by default      // start with a new gig file by default
889      on_action_file_new();      on_action_file_new();
890    
891        m_TreeViewNotebook.signal_switch_page().connect(
892            sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
893        );
894    
895      // select 'Instruments' tab by default      // select 'Instruments' tab by default
896      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
897      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
# Line 843  MainWindow::MainWindow() : Line 908  MainWindow::MainWindow() :
908              uiManager->get_widget("/MenuBar/MenuMacro")              uiManager->get_widget("/MenuBar/MenuMacro")
909          )->get_submenu();          )->get_submenu();
910    
         const Gdk::ModifierType primaryModifierKey =  
 #if defined(__APPLE__)  
             Gdk::META_MASK; // Cmd key on Mac  
 #else  
             Gdk::CONTROL_MASK; // Ctrl key on all other OSs  
 #endif  
   
911          const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;          const Gdk::ModifierType noModifier = (Gdk::ModifierType)0;
912          Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);          Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier);
913          Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);          Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier);
# Line 870  MainWindow::MainWindow() : Line 928  MainWindow::MainWindow() :
928    
929          updateMacroMenu();          updateMacroMenu();
930      }      }
931    
932        // setup "Assign Scripts" keyboard accelerators
933        {
934            Gtk::AccelMap::add_entry("<Scripts>/script_0", GDK_KEY_F1, Gdk::SHIFT_MASK);
935            Gtk::AccelMap::add_entry("<Scripts>/script_1", GDK_KEY_F2, Gdk::SHIFT_MASK);
936            Gtk::AccelMap::add_entry("<Scripts>/script_2", GDK_KEY_F3, Gdk::SHIFT_MASK);
937            Gtk::AccelMap::add_entry("<Scripts>/script_3", GDK_KEY_F4, Gdk::SHIFT_MASK);
938            Gtk::AccelMap::add_entry("<Scripts>/script_4", GDK_KEY_F5, Gdk::SHIFT_MASK);
939            Gtk::AccelMap::add_entry("<Scripts>/script_5", GDK_KEY_F6, Gdk::SHIFT_MASK);
940            Gtk::AccelMap::add_entry("<Scripts>/script_6", GDK_KEY_F7, Gdk::SHIFT_MASK);
941            Gtk::AccelMap::add_entry("<Scripts>/script_7", GDK_KEY_F8, Gdk::SHIFT_MASK);
942            Gtk::AccelMap::add_entry("<Scripts>/script_8", GDK_KEY_F9, Gdk::SHIFT_MASK);
943            Gtk::AccelMap::add_entry("<Scripts>/script_9", GDK_KEY_F10, Gdk::SHIFT_MASK);
944            Gtk::AccelMap::add_entry("<Scripts>/script_10", GDK_KEY_F11, Gdk::SHIFT_MASK);
945            Gtk::AccelMap::add_entry("<Scripts>/script_11", GDK_KEY_F12, Gdk::SHIFT_MASK);
946    
947            Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
948            assign_scripts_menu->set_accel_group(accelGroup);
949        }
950    
951        Glib::signal_idle().connect_once(
952            sigc::mem_fun(*this, &MainWindow::bringToFront),
953            200
954        );
955  }  }
956    
957  MainWindow::~MainWindow()  MainWindow::~MainWindow()
958  {  {
959  }  }
960    
961    void MainWindow::bringToFront() {
962        #if defined(__APPLE__)
963        macRaiseAppWindow();
964        #endif
965        raise();
966        present();
967    }
968    
969  void MainWindow::updateMacroMenu() {  void MainWindow::updateMacroMenu() {
970      Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(      Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>(
971          uiManager->get_widget("/MenuBar/MenuMacro")          uiManager->get_widget("/MenuBar/MenuMacro")
# Line 914  void MainWindow::updateMacroMenu() { Line 1004  void MainWindow::updateMacroMenu() {
1004          );          );
1005          menuMacro->append(*item);          menuMacro->append(*item);
1006          item->set_accel_path("<Macros>/macro_" + ToString(iMacro));          item->set_accel_path("<Macros>/macro_" + ToString(iMacro));
1007            Glib::ustring comment = macro.comment();
1008            if (!comment.empty())
1009                item->set_tooltip_text(comment);
1010      }      }
1011      // if there are no macros configured at all, then show a dummy entry instead      // if there are no macros configured at all, then show a dummy entry instead
1012      if (m_macros.empty()) {      if (m_macros.empty()) {
# Line 971  void MainWindow::onMacrosSetupChanged(co Line 1064  void MainWindow::onMacrosSetupChanged(co
1064      updateMacroMenu();      updateMacroMenu();
1065  }  }
1066    
1067    void MainWindow::on_notebook_tab_switched(GtkNotebookPage* page, guint page_num) {
1068        bool isInstrumentsPage = (page_num == 1);
1069        // so far we only support filtering for the instruments list, so hide the
1070        // filter text entry field if another tab is selected
1071        m_searchField.set_visible(isInstrumentsPage);
1072    }
1073    
1074  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1075  {  {
1076      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 1071  void MainWindow::on_sel_change() Line 1171  void MainWindow::on_sel_change()
1171          }          }
1172      }      }
1173    
1174        updateScriptListOfMenu();
1175    
1176      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
1177    
1178      if (Settings::singleton()->syncSamplerInstrumentSelection) {      if (Settings::singleton()->syncSamplerInstrumentSelection) {
# Line 1201  void Saver::thread_function() Line 1303  void Saver::thread_function()
1303                  // save the file as separate temporary file first,                  // save the file as separate temporary file first,
1304                  // then move the saved file over the old file                  // then move the saved file over the old file
1305                  // (may result in performance speedup during save)                  // (may result in performance speedup during save)
1306                  String tmpname = filename + ".TMP";                  gig::String tmpname = filename + ".TMP";
1307                  gig->Save(tmpname, &progress);                  gig->Save(tmpname, &progress);
1308                  #if defined(WIN32)                  #if defined(WIN32)
1309                  if (!DeleteFile(filename.c_str())) {                  if (!DeleteFile(filename.c_str())) {
# Line 1209  void Saver::thread_function() Line 1311  void Saver::thread_function()
1311                  }                  }
1312                  #else // POSIX ...                  #else // POSIX ...
1313                  if (unlink(filename.c_str())) {                  if (unlink(filename.c_str())) {
1314                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + String(strerror(errno)));                      throw RIFF::Exception("Could not replace original file with temporary file (unable to remove original file): " + gig::String(strerror(errno)));
1315                  }                  }
1316                  #endif                  #endif
1317                  if (rename(tmpname.c_str(), filename.c_str())) {                  if (rename(tmpname.c_str(), filename.c_str())) {
1318                      #if defined(WIN32)                      #if defined(WIN32)
1319                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file).");
1320                      #else                      #else
1321                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + String(strerror(errno)));                      throw RIFF::Exception("Could not replace original file with temporary file (unable to rename temp file): " + gig::String(strerror(errno)));
1322                      #endif                      #endif
1323                  }                  }
1324              }              }
# Line 1812  void MainWindow::on_action_help_about() Line 1914  void MainWindow::on_action_help_about()
1914      dialog.set_comments(sComment.c_str());      dialog.set_comments(sComment.c_str());
1915      dialog.set_website("http://www.linuxsampler.org");      dialog.set_website("http://www.linuxsampler.org");
1916      dialog.set_website_label("http://www.linuxsampler.org");      dialog.set_website_label("http://www.linuxsampler.org");
1917        dialog.set_position(Gtk::WIN_POS_CENTER);
1918      dialog.run();      dialog.run();
1919  }  }
1920    
# Line 1837  PropDialog::PropDialog() Line 1940  PropDialog::PropDialog()
1940        table(2, 1),        table(2, 1),
1941        m_file(NULL)        m_file(NULL)
1942  {  {
1943        if (!Settings::singleton()->autoRestoreWindowDimension) {
1944            set_default_size(470, 390);
1945            set_position(Gtk::WIN_POS_MOUSE);
1946        }
1947    
1948      set_title(_("File Properties"));      set_title(_("File Properties"));
1949      eName.set_width_chars(50);      eName.set_width_chars(50);
1950    
# Line 1971  InstrumentProps::InstrumentProps() : Line 2079  InstrumentProps::InstrumentProps() :
2079      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2080      eDimensionKeyRangeHigh(_("Keyswitching range high"))      eDimensionKeyRangeHigh(_("Keyswitching range high"))
2081  {  {
2082        if (!Settings::singleton()->autoRestoreWindowDimension) {
2083            //set_default_size(470, 390);
2084            set_position(Gtk::WIN_POS_MOUSE);
2085        }
2086    
2087      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
2088    
2089      eDimensionKeyRangeLow.set_tip(      eDimensionKeyRangeLow.set_tip(
# Line 2095  void MainWindow::load_gig(gig::File* gig Line 2208  void MainWindow::load_gig(gig::File* gig
2208      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
2209           instrument = gig->GetNextInstrument(), ++index) {           instrument = gig->GetNextInstrument(), ++index) {
2210          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));          Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
2211            const int iScriptSlots = instrument->ScriptSlotCount();
2212    
2213          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
2214          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
2215          row[m_Columns.m_col_nr] = index;          row[m_Columns.m_col_nr] = index;
2216          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
2217          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
2218            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2219    
2220          add_instrument_to_menu(name);          add_instrument_to_menu(name);
2221      }      }
# Line 2239  void MainWindow::show_script_slots() { Line 2354  void MainWindow::show_script_slots() {
2354    
2355      ScriptSlots* window = new ScriptSlots;      ScriptSlots* window = new ScriptSlots;
2356      window->setInstrument(instrument);      window->setInstrument(instrument);
2357        window->signal_script_slots_changed().connect(
2358            sigc::mem_fun(*this, &MainWindow::onScriptSlotsModified)
2359        );
2360      //window->reparent(*this);      //window->reparent(*this);
2361      window->show();      window->show();
2362  }  }
2363    
2364    void MainWindow::onScriptSlotsModified(gig::Instrument* pInstrument) {
2365        if (!pInstrument) return;
2366        const int iScriptSlots = pInstrument->ScriptSlotCount();
2367    
2368        //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!
2369        //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2370        Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2371    
2372        for (int i = 0; i < model->children().size(); ++i) {
2373            Gtk::TreeModel::Row row = model->children()[i];
2374            if (row[m_Columns.m_col_instr] != pInstrument) continue;
2375            row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
2376            break;
2377        }
2378    
2379        // causes the sampler to reload the instrument with the new script
2380        on_sel_change();
2381    }
2382    
2383    void MainWindow::assignScript(gig::Script* pScript) {
2384        if (!pScript) {
2385            printf("assignScript() : !script\n");
2386            return;
2387        }
2388        printf("assignScript('%s')\n", pScript->Name.c_str());
2389    
2390        gig::Instrument* pInstrument = get_instrument();
2391        if (!pInstrument) {
2392            printf("!instrument\n");
2393            return;
2394        }
2395    
2396        pInstrument->AddScriptSlot(pScript);
2397    
2398        onScriptSlotsModified(pInstrument);
2399    }
2400    
2401  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
2402      __refreshEntireGUI();      __refreshEntireGUI();
2403  }  }
# Line 2345  void MainWindow::on_instrument_selection Line 2500  void MainWindow::on_instrument_selection
2500  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
2501      if (!instrument) return;      if (!instrument) return;
2502    
2503        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2504      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2505        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2506    
2507      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2508          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2509          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
# Line 2367  bool MainWindow::select_dimension_region Line 2525  bool MainWindow::select_dimension_region
2525      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2526      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2527    
2528        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2529      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2530        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2531    
2532      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2533          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2534          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
# Line 2515  void MainWindow::on_script_treeview_butt Line 2676  void MainWindow::on_script_treeview_butt
2676      }      }
2677  }  }
2678    
2679    void MainWindow::updateScriptListOfMenu() {
2680        // remove all entries from "Assign Script" menu
2681        {
2682            const std::vector<Gtk::Widget*> children = assign_scripts_menu->get_children();
2683            for (int i = 0; i < children.size(); ++i) {
2684                Gtk::Widget* child = children[i];
2685                assign_scripts_menu->remove(*child);
2686                delete child;
2687            }
2688        }
2689    
2690        int iTotalScripts = 0;
2691    
2692        if (!file) goto noScripts;
2693    
2694        // add all configured macros as menu items to the "Macro" menu
2695        for (int iGroup = 0; file->GetScriptGroup(iGroup); ++iGroup) {
2696            gig::ScriptGroup* pGroup = file->GetScriptGroup(iGroup);
2697            for (int iScript = 0; pGroup->GetScript(iScript); ++iScript, ++iTotalScripts) {
2698                gig::Script* pScript = pGroup->GetScript(iScript);
2699                std::string name = pScript->Name;
2700    
2701                Gtk::MenuItem* item = new Gtk::MenuItem(name);
2702                item->signal_activate().connect(
2703                    sigc::bind(
2704                        sigc::mem_fun(*this, &MainWindow::assignScript), pScript
2705                    )
2706                );
2707                assign_scripts_menu->append(*item);
2708                item->set_accel_path("<Scripts>/script_" + ToString(iTotalScripts));
2709                //item->set_tooltip_text(comment);
2710            }
2711        }
2712    
2713        noScripts:
2714    
2715        // if there are no macros configured at all, then show a dummy entry instead
2716        if (!iTotalScripts) {
2717            Gtk::MenuItem* item = new Gtk::MenuItem(_("No Scripts"));
2718            item->set_sensitive(false);
2719            assign_scripts_menu->append(*item);
2720        }
2721    
2722        assign_scripts_menu->show_all_children();
2723    }
2724    
2725  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
2726      const Glib::ustring& name, int position) {      const Glib::ustring& name, int position) {
2727    
# Line 2557  void MainWindow::add_instrument(gig::Ins Line 2764  void MainWindow::add_instrument(gig::Ins
2764      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;
2765      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
2766      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
2767        rowInstr[m_Columns.m_col_scripts] = "";
2768      instrument_name_connection.unblock();      instrument_name_connection.unblock();
2769    
2770      add_instrument_to_menu(name);      add_instrument_to_menu(name);
2771        select_instrument(instrument);
     m_TreeView.get_selection()->select(iterInstr);  
   
2772      file_changed();      file_changed();
2773  }  }
2774    
# Line 3532  void MainWindow::instrument_name_changed Line 3738  void MainWindow::instrument_name_changed
3738      }      }
3739  }  }
3740    
3741    bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
3742        if (!iter)
3743            return true;
3744    
3745        Glib::ustring pattern = m_searchText.get_text().lowercase();
3746        trim(pattern);
3747        if (pattern.empty()) return true;
3748    
3749        Gtk::TreeModel::Row row = *iter;
3750        Glib::ustring name = row[m_Columns.m_col_name];
3751        name = name.lowercase();
3752    
3753        std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
3754        for (int t = 0; t < tokens.size(); ++t)
3755            if (name.find(tokens[t]) == Glib::ustring::npos)
3756                return false;
3757    
3758        return true;
3759    }
3760    
3761  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3762      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3763    
3764        // take over selection from instruments list view for the combine dialog's
3765        // list view as pre-selection
3766        std::set<int> indeces;
3767        {
3768            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
3769            std::vector<Gtk::TreeModel::Path> rows = sel->get_selected_rows();
3770            for (int r = 0; r < rows.size(); ++r) {
3771                Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(rows[r]);
3772                if (it) {
3773                    Gtk::TreeModel::Row row = *it;
3774                    int index = row[m_Columns.m_col_nr];
3775                    indeces.insert(index);
3776                }
3777            }
3778        }
3779        d->setSelectedInstruments(indeces);
3780    
3781      d->show_all();      d->show_all();
     d->resize(500, 400);  
3782      d->run();      d->run();
3783      if (d->fileWasChanged()) {      if (d->fileWasChanged()) {
3784          // update GUI with new instrument just created          // update GUI with new instrument just created
# Line 3797  void MainWindow::show_scripts_tab() { Line 4040  void MainWindow::show_scripts_tab() {
4040      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
4041  }  }
4042    
4043    void MainWindow::select_instrument_by_dir(int dir) {
4044        if (!file) return;
4045        gig::Instrument* pInstrument = get_instrument();
4046        if (!pInstrument) {
4047            select_instrument( file->GetInstrument(0) );
4048            return;
4049        }
4050        for (int i = 0; file->GetInstrument(i); ++i) {
4051            if (file->GetInstrument(i) == pInstrument) {
4052                select_instrument( file->GetInstrument(i + dir) );
4053                return;
4054            }
4055        }
4056    }
4057    
4058    void MainWindow::select_prev_instrument() {
4059        select_instrument_by_dir(-1);
4060    }
4061    
4062    void MainWindow::select_next_instrument() {
4063        select_instrument_by_dir(1);
4064    }
4065    
4066  void MainWindow::select_prev_region() {  void MainWindow::select_prev_region() {
4067      m_RegionChooser.select_prev_region();      m_RegionChooser.select_prev_region();
4068  }  }
# Line 3920  void MainWindow::applyMacro(Serializatio Line 4186  void MainWindow::applyMacro(Serializatio
4186           itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)           itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
4187      {      {
4188          gig::DimensionRegion* pDimRgn = *itDimReg;          gig::DimensionRegion* pDimRgn = *itDimReg;
4189          dimreg_to_be_changed_signal.emit(pDimRgn);          DimRegionChangeGuard(this, pDimRgn);
4190          macro.deserialize(pDimRgn);          macro.deserialize(pDimRgn);
         dimreg_changed_signal.emit(pDimRgn);  
4191      }      }
4192      //region_changed()      //region_changed()
4193      file_changed();      file_changed();

Legend:
Removed from v.3162  
changed lines
  Added in v.3340

  ViewVC Help
Powered by ViewVC