/[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 3643 by schoenebeck, Sat Dec 7 15:04:51 2019 UTC revision 3800 by schoenebeck, Sun Jul 26 13:27:16 2020 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2019 Andreas Persson   * Copyright (C) 2006-2020 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 96  MainWindow::MainWindow() : Line 96  MainWindow::MainWindow() :
96    
97      if (!Settings::singleton()->autoRestoreWindowDimension) {      if (!Settings::singleton()->autoRestoreWindowDimension) {
98  #if GTKMM_MAJOR_VERSION >= 3  #if GTKMM_MAJOR_VERSION >= 3
99          set_default_size(960, 600);          set_default_size(1010, -1);
100  #else  #else
101          set_default_size(865, 600);          set_default_size(915, -1);
102  #endif  #endif
103          set_position(Gtk::WIN_POS_CENTER);          set_position(Gtk::WIN_POS_CENTER);
104      }      }
# Line 451  MainWindow::MainWindow() : Line 451  MainWindow::MainWindow() :
451          m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);          m_actionGroup->add_action_bool("Statusbar", sigc::mem_fun(*this, &MainWindow::on_action_view_status_bar), true);
452      m_actionToggleRestoreWinDim =      m_actionToggleRestoreWinDim =
453          m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);          m_actionGroup->add_action_bool("AutoRestoreWinDim", sigc::mem_fun(*this, &MainWindow::on_auto_restore_win_dim), Settings::singleton()->autoRestoreWindowDimension);
454        m_actionInstrDoubleClickOpensProps =
455            m_actionGroup->add_action_bool(
456                "OpenInstrPropsByDoubleClick",
457                sigc::mem_fun(*this, &MainWindow::on_instr_double_click_opens_props),
458                Settings::singleton()->instrumentDoubleClickOpensProps
459            );
460      m_actionToggleShowTooltips = m_actionGroup->add_action_bool(      m_actionToggleShowTooltips = m_actionGroup->add_action_bool(
461          "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),          "ShowTooltips", sigc::mem_fun(*this, &MainWindow::on_action_show_tooltips),
462          Settings::singleton()->showTooltips          Settings::singleton()->showTooltips
# Line 478  MainWindow::MainWindow() : Line 484  MainWindow::MainWindow() :
484                           *this, &MainWindow::on_auto_restore_win_dim));                           *this, &MainWindow::on_auto_restore_win_dim));
485    
486      toggle_action =      toggle_action =
487            Gtk::ToggleAction::create("OpenInstrPropsByDoubleClick", _("Instrument Properties by Double Click"));
488        toggle_action->set_active(Settings::singleton()->instrumentDoubleClickOpensProps);
489        actionGroup->add(toggle_action,
490                         sigc::mem_fun(
491                             *this, &MainWindow::on_instr_double_click_opens_props));
492    
493        toggle_action =
494          Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));          Gtk::ToggleAction::create("ShowTooltips", _("Tooltips for Beginners"));
495      toggle_action->set_active(Settings::singleton()->showTooltips);      toggle_action->set_active(Settings::singleton()->showTooltips);
496      actionGroup->add(      actionGroup->add(
# Line 509  MainWindow::MainWindow() : Line 522  MainWindow::MainWindow() :
522          "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          "DupInstrument", sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
523      );      );
524      m_actionGroup->add_action(      m_actionGroup->add_action(
525            "MoveInstrument", sigc::mem_fun(*this, &MainWindow::on_action_move_instr)
526        );
527        m_actionGroup->add_action(
528          "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)          "CombInstruments", sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
529      );      );
530      m_actionGroup->add_action(      m_actionGroup->add_action(
# Line 530  MainWindow::MainWindow() : Line 546  MainWindow::MainWindow() :
546          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)          sigc::mem_fun(*this, &MainWindow::on_action_duplicate_instrument)
547      );      );
548      actionGroup->add(      actionGroup->add(
549            Gtk::Action::create("MoveInstrument", _("Move _Instrument To ...")),
550            Gtk::AccelKey(GDK_KEY_i, primaryModifierKey),
551            sigc::mem_fun(*this, &MainWindow::on_action_move_instr)
552        );
553        actionGroup->add(
554          Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),          Gtk::Action::create("CombInstruments", _("_Combine Instruments ...")),
555          Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),          Gtk::AccelKey(GDK_KEY_j, primaryModifierKey),
556          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)          sigc::mem_fun(*this, &MainWindow::on_action_combine_instruments)
# Line 885  MainWindow::MainWindow() : Line 906  MainWindow::MainWindow() :
906          "          <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"          "          <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
907          "          <attribute name='action'>AppMenu.DupInstrument</attribute>"          "          <attribute name='action'>AppMenu.DupInstrument</attribute>"
908          "        </item>"          "        </item>"
909            "        <item id='MoveInstrument'>"
910            "          <attribute name='label' translatable='yes'>Move Instrument To ...</attribute>"
911            "          <attribute name='action'>AppMenu.MoveInstrument</attribute>"
912            "        </item>"
913          "        <item id='CombInstruments'>"          "        <item id='CombInstruments'>"
914          "          <attribute name='label' translatable='yes'>Combine Instrument</attribute>"          "          <attribute name='label' translatable='yes'>Combine Instrument</attribute>"
915          "          <attribute name='action'>AppMenu.CombInstruments</attribute>"          "          <attribute name='action'>AppMenu.CombInstruments</attribute>"
# Line 935  MainWindow::MainWindow() : Line 960  MainWindow::MainWindow() :
960          "          <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"          "          <attribute name='label' translatable='yes'>Auto restore Window Dimensions</attribute>"
961          "          <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"          "          <attribute name='action'>AppMenu.AutoRestoreWinDim</attribute>"
962          "        </item>"          "        </item>"
963            "        <item id='OpenInstrPropsByDoubleClick'>"
964            "          <attribute name='label' translatable='yes'>Instrument Properties by Double Click</attribute>"
965            "          <attribute name='action'>AppMenu.OpenInstrPropsByDoubleClick</attribute>"
966            "        </item>"
967          "      </section>"          "      </section>"
968          "      <section>"          "      <section>"
969          "        <item id='RefreshAll'>"          "        <item id='RefreshAll'>"
# Line 1010  MainWindow::MainWindow() : Line 1039  MainWindow::MainWindow() :
1039          "        <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"          "        <attribute name='label' translatable='yes'>Duplicate Instrument</attribute>"
1040          "        <attribute name='action'>AppMenu.DupInstrument</attribute>"          "        <attribute name='action'>AppMenu.DupInstrument</attribute>"
1041          "      </item>"          "      </item>"
1042            "      <item id='MoveInstrument'>"
1043            "        <attribute name='label' translatable='yes'>Move Instrument To ...</attribute>"
1044            "        <attribute name='action'>AppMenu.MoveInstrument</attribute>"
1045            "      </item>"
1046          "      <item id='CombInstruments'>"          "      <item id='CombInstruments'>"
1047          "        <attribute name='label' translatable='yes'>Combine Instruments</attribute>"          "        <attribute name='label' translatable='yes'>Combine Instruments</attribute>"
1048          "        <attribute name='action'>AppMenu.CombInstruments</attribute>"          "        <attribute name='action'>AppMenu.CombInstruments</attribute>"
# Line 1148  MainWindow::MainWindow() : Line 1181  MainWindow::MainWindow() :
1181          "      <menu action='AssignScripts'/>"          "      <menu action='AssignScripts'/>"
1182          "      <menuitem action='AddInstrument'/>"          "      <menuitem action='AddInstrument'/>"
1183          "      <menuitem action='DupInstrument'/>"          "      <menuitem action='DupInstrument'/>"
1184            "      <menuitem action='MoveInstrument'/>"
1185          "      <menuitem action='CombInstruments'/>"          "      <menuitem action='CombInstruments'/>"
1186          "      <separator/>"          "      <separator/>"
1187          "      <menuitem action='RemoveInstrument'/>"          "      <menuitem action='RemoveInstrument'/>"
# Line 1163  MainWindow::MainWindow() : Line 1197  MainWindow::MainWindow() :
1197          "      <menuitem action='Statusbar'/>"          "      <menuitem action='Statusbar'/>"
1198          "      <menuitem action='ShowTooltips'/>"          "      <menuitem action='ShowTooltips'/>"
1199          "      <menuitem action='AutoRestoreWinDim'/>"          "      <menuitem action='AutoRestoreWinDim'/>"
1200            "      <menuitem action='OpenInstrPropsByDoubleClick'/>"
1201          "      <separator/>"          "      <separator/>"
1202          "      <menuitem action='RefreshAll'/>"          "      <menuitem action='RefreshAll'/>"
1203          "    </menu>"          "    </menu>"
# Line 1186  MainWindow::MainWindow() : Line 1221  MainWindow::MainWindow() :
1221          "    <menuitem action='ScriptSlots'/>"          "    <menuitem action='ScriptSlots'/>"
1222          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
1223          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
1224            "    <menuitem action='MoveInstrument'/>"
1225          "    <menuitem action='CombInstruments'/>"          "    <menuitem action='CombInstruments'/>"
1226          "    <separator/>"          "    <separator/>"
1227          "    <menuitem action='RemoveInstrument'/>"          "    <menuitem action='RemoveInstrument'/>"
# Line 1286  MainWindow::MainWindow() : Line 1322  MainWindow::MainWindow() :
1322      }      }
1323      {      {
1324          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1325                uiManager->get_widget("/MenuBar/MenuView/OpenInstrPropsByDoubleClick"));
1326            item->set_tooltip_text(_("If checked, double clicking an instrument opens its properties dialog."));
1327        }
1328        {
1329            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
1330              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
1331          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));          item->set_tooltip_text(_("Create combi sounds out of individual sounds of this .gig file."));
1332      }      }
# Line 1508  MainWindow::MainWindow() : Line 1549  MainWindow::MainWindow() :
1549          sigc::mem_fun(*this, &MainWindow::select_sample)          sigc::mem_fun(*this, &MainWindow::select_sample)
1550      );      );
1551    
1552        dimreg_edit.editScriptSlotsButton.signal_clicked().connect(
1553            sigc::mem_fun(*this, &MainWindow::show_script_slots)
1554        );
1555        // simply sending the same signal (pair) to the sampler on 'patch' variable
1556        // changes as the already existing signal (pair) when the user edits the
1557        // script's source code, because the sampler would reload the source code
1558        // and the 'patch' variables from the instrument on this signal anyway
1559        dimreg_edit.scriptVars.signal_vars_to_be_changed.connect(
1560            [this](gig::Instrument* instr) {
1561                for (int i = 0; i < instr->ScriptSlotCount(); ++i) {
1562                    gig::Script* script = instr->GetScriptOfSlot(i);
1563                    signal_script_to_be_changed.emit(script);
1564                }
1565            }
1566        );
1567        dimreg_edit.scriptVars.signal_vars_changed.connect(
1568            [this](gig::Instrument* instr) {
1569                for (int i = 0; i < instr->ScriptSlotCount(); ++i) {
1570                    gig::Script* script = instr->GetScriptOfSlot(i);
1571                    signal_script_changed.emit(script);
1572                }
1573            }
1574        );
1575        dimreg_edit.scriptVars.signal_edit_script.connect(
1576            [this](gig::Script* script) {
1577                editScript(script);
1578            }
1579        );
1580    
1581      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
1582          sigc::hide(          sigc::hide(
1583              sigc::bind(              sigc::bind(
# Line 1881  void MainWindow::on_sel_change() Line 1951  void MainWindow::on_sel_change()
1951    
1952      updateScriptListOfMenu();      updateScriptListOfMenu();
1953    
1954      m_RegionChooser.set_instrument(get_instrument());      gig::Instrument* instr = get_instrument();
1955    
1956        m_RegionChooser.set_instrument(instr);
1957        dimreg_edit.scriptVars.setInstrument(instr, true/*force update*/);
1958    
1959      if (Settings::singleton()->syncSamplerInstrumentSelection) {      if (Settings::singleton()->syncSamplerInstrumentSelection) {
1960          switch_sampler_instrument_signal.emit(get_instrument());          switch_sampler_instrument_signal.emit(get_instrument());
# Line 3684  void MainWindow::onScriptSlotsModified(g Line 3757  void MainWindow::onScriptSlotsModified(g
3757    
3758      // causes the sampler to reload the instrument with the new script      // causes the sampler to reload the instrument with the new script
3759      on_sel_change();      on_sel_change();
3760    
3761        // force script 'patch' variables editor ("Script" tab) to be refreshed
3762        dimreg_edit.scriptVars.setInstrument(pInstrument, true/*force update*/);
3763  }  }
3764    
3765  void MainWindow::assignScript(gig::Script* pScript) {  void MainWindow::assignScript(gig::Script* pScript) {
# Line 3764  void MainWindow::on_auto_restore_win_dim Line 3840  void MainWindow::on_auto_restore_win_dim
3840  #endif  #endif
3841  }  }
3842    
3843    void MainWindow::on_instr_double_click_opens_props() {
3844    #if USE_GLIB_ACTION
3845        bool active = false;
3846        m_actionInstrDoubleClickOpensProps->get_state(active);
3847        // for some reason toggle state does not change automatically
3848        active = !active;
3849        m_actionInstrDoubleClickOpensProps->change_state(active);
3850        Settings::singleton()->instrumentDoubleClickOpensProps = active;
3851    #else
3852        Gtk::CheckMenuItem* item =
3853            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/OpenInstrPropsByDoubleClick"));
3854        if (!item) {
3855            std::cerr << "/MenuBar/MenuView/OpenInstrPropsByDoubleClick == NULL\n";
3856            return;
3857        }
3858        Settings::singleton()->instrumentDoubleClickOpensProps = item->get_active();
3859    #endif
3860    }
3861    
3862  void MainWindow::on_save_with_temporary_file() {  void MainWindow::on_save_with_temporary_file() {
3863  #if USE_GLIB_ACTION  #if USE_GLIB_ACTION
3864      bool active = false;      bool active = false;
# Line 3838  bool MainWindow::on_button_release(Gdk:: Line 3933  bool MainWindow::on_button_release(Gdk::
3933  void MainWindow::on_button_release(GdkEventButton* button) {  void MainWindow::on_button_release(GdkEventButton* button) {
3934  #endif  #endif
3935      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
3936          show_instr_props();          if (Settings::singleton()->instrumentDoubleClickOpensProps)
3937                show_instr_props();
3938      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3939          // gig v2 files have no midi rules          // gig v2 files have no midi rules
3940          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
# Line 3878  void MainWindow::on_instrument_selection Line 3974  void MainWindow::on_instrument_selection
3974  }  }
3975  #endif  #endif
3976    
3977    void MainWindow::on_action_move_instr() {
3978        gig::Instrument* instr = get_instrument();
3979        if (!instr) return;
3980    
3981        int currentIndex = getIndexOf(instr);
3982    
3983        Gtk::Dialog dialog(_("Move Instrument"), true /*modal*/);
3984    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
3985        Gtk::Adjustment adjustment(
3986            currentIndex,
3987            0 /*min*/, file->CountInstruments() - 1 /*max*/
3988        );
3989        Gtk::SpinButton spinBox(adjustment);
3990    #else
3991        Gtk::SpinButton spinBox(
3992            Gtk::Adjustment::create(
3993                currentIndex,
3994                0 /*min*/, file->CountInstruments() - 1 /*max*/
3995            )
3996        );
3997    #endif
3998    #if USE_GTKMM_BOX
3999        dialog.get_content_area()->pack_start(spinBox);
4000    #else
4001        dialog.get_vbox()->pack_start(spinBox);
4002    #endif
4003    #if HAS_GTKMM_STOCK
4004        Gtk::Button* okButton = dialog.add_button(Gtk::Stock::OK, 0);
4005        dialog.add_button(Gtk::Stock::CANCEL, 1);
4006    #else
4007        Gtk::Button* okButton = dialog.add_button(_("_OK"), 0);
4008        dialog.add_button(_("_Cancel"), 1);
4009    #endif
4010        okButton->set_sensitive(false);
4011        // show the dialog at a reasonable screen position
4012        dialog.set_position(Gtk::WIN_POS_MOUSE);
4013        // only enable the 'OK' button if entered new index is not instrument's
4014        // current index already
4015        spinBox.signal_value_changed().connect([&]{
4016            okButton->set_sensitive( spinBox.get_value_as_int() != currentIndex );
4017        });
4018        // usability acceleration: if user hits enter key on the text entry field
4019        // then auto trigger the 'OK' button
4020        spinBox.signal_activate().connect([&]{
4021            if (okButton->get_sensitive())
4022                okButton->clicked();
4023        });
4024    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4025        dialog.show_all_children();
4026    #endif
4027        if (!dialog.run()) { // 'OK' selected ...
4028            int newIndex = spinBox.get_value_as_int();
4029            printf("MOVE TO %d\n", newIndex);
4030            gig::Instrument* dst = file->GetInstrument(newIndex);
4031            instr->MoveTo(dst);
4032            __refreshEntireGUI();
4033            select_instrument(instr);
4034        }
4035    }
4036    
4037  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
4038      if (!instrument) return;      if (!instrument) return;
4039    
# Line 4219  void MainWindow::add_instrument(gig::Ins Line 4375  void MainWindow::add_instrument(gig::Ins
4375      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
4376      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
4377      const int index = m_refTreeModel->children().size() - 1;      const int index = m_refTreeModel->children().size() - 1;
4378        const int iScriptSlots = instrument->ScriptSlotCount();
4379      rowInstr[m_Columns.m_col_nr] = index;      rowInstr[m_Columns.m_col_nr] = index;
4380      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
4381      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
4382      rowInstr[m_Columns.m_col_scripts] = "";      rowInstr[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
4383      rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);      rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
4384      instrument_name_connection.unblock();      instrument_name_connection.unblock();
4385    
# Line 4405  void MainWindow::on_action_edit_script() Line 4562  void MainWindow::on_action_edit_script()
4562      if (!it) return;      if (!it) return;
4563      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
4564      gig::Script* script = row[m_ScriptsModel.m_col_script];      gig::Script* script = row[m_ScriptsModel.m_col_script];
4565      if (!script) return;      editScript(script);
4566    }
4567    
4568    void MainWindow::editScript(gig::Script* script) {
4569        if (!script) return;
4570      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
4571      editor->signal_script_to_be_changed.connect(      editor->signal_script_to_be_changed.connect(
4572          signal_script_to_be_changed.make_slot()          signal_script_to_be_changed.make_slot()
4573      );      );
4574      editor->signal_script_changed.connect(      editor->signal_script_changed.connect([this](gig::Script* script) {
4575          signal_script_changed.make_slot()          // signal to sampler (which will reload the script due to this)
4576      );          signal_script_changed.emit(script);
4577            // force script 'patch' variables editor ("Script" tab) to be refreshed
4578            gig::Instrument* instr = get_instrument();
4579            dimreg_edit.scriptVars.setInstrument(instr, true/*force update*/);
4580        });
4581      editor->setScript(script);      editor->setScript(script);
4582      //editor->reparent(*this);      //editor->reparent(*this);
4583      editor->show();      editor->show();
# Line 5177  void MainWindow::script_double_clicked(c Line 5341  void MainWindow::script_double_clicked(c
5341      if (!iter) return;      if (!iter) return;
5342      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
5343      gig::Script* script = row[m_ScriptsModel.m_col_script];      gig::Script* script = row[m_ScriptsModel.m_col_script];
5344      if (!script) return;      editScript(script);
   
     ScriptEditor* editor = new ScriptEditor;  
     editor->signal_script_to_be_changed.connect(  
         signal_script_to_be_changed.make_slot()  
     );  
     editor->signal_script_changed.connect(  
         signal_script_changed.make_slot()  
     );  
     editor->setScript(script);  
     //editor->reparent(*this);  
     editor->show();  
5345  }  }
5346    
5347  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,  void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path,

Legend:
Removed from v.3643  
changed lines
  Added in v.3800

  ViewVC Help
Powered by ViewVC