/[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 3637 by schoenebeck, Thu Oct 24 13:12:52 2019 UTC revision 3749 by schoenebeck, Sun Feb 16 18:39:53 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 2851  InstrumentProps::InstrumentProps() : Line 2924  InstrumentProps::InstrumentProps() :
2924      eIsDrum(_("Is drum")),      eIsDrum(_("Is drum")),
2925      eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIBank(_("MIDI bank"), 0, 16383),
2926      eMIDIProgram(_("MIDI program")),      eMIDIProgram(_("MIDI program")),
2927      eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eAttenuation(_("Attenuation (dB)"), -96, +96, 0, 1),
     eGainPlus6(_("Gain +6dB"), eAttenuation, -6),  
2928      eEffectSend(_("Effect send"), 0, 65535),      eEffectSend(_("Effect send"), 0, 65535),
2929      eFineTune(_("Fine tune"), -8400, 8400),      eFineTune(_("Fine tune"), -8400, 8400),
2930      ePitchbendRange(_("Pitchbend range"), 0, 48),      ePitchbendRange(_("Pitchbend range (halftones)"), 0, 48),
2931      ePianoReleaseMode(_("Piano release mode")),      ePianoReleaseMode(_("Piano release mode")),
2932      eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
2933      eDimensionKeyRangeHigh(_("Keyswitching range high")),      eDimensionKeyRangeHigh(_("Keyswitching range high")),
# Line 2901  InstrumentProps::InstrumentProps() : Line 2973  InstrumentProps::InstrumentProps() :
2973      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
2974      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
2975      connect(eAttenuation, &gig::Instrument::Attenuation);      connect(eAttenuation, &gig::Instrument::Attenuation);
     connect(eGainPlus6, &gig::Instrument::Attenuation);  
2976      connect(eEffectSend, &gig::Instrument::EffectSend);      connect(eEffectSend, &gig::Instrument::EffectSend);
2977      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
2978      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
# Line 2969  InstrumentProps::InstrumentProps() : Line 3040  InstrumentProps::InstrumentProps() :
3040      table.add(eMIDIBank);      table.add(eMIDIBank);
3041      table.add(eMIDIProgram);      table.add(eMIDIProgram);
3042      table.add(eAttenuation);      table.add(eAttenuation);
     table.add(eGainPlus6);  
3043      table.add(eEffectSend);      table.add(eEffectSend);
3044      table.add(eFineTune);      table.add(eFineTune);
3045      table.add(ePitchbendRange);      table.add(ePitchbendRange);
# Line 3767  void MainWindow::on_auto_restore_win_dim Line 3837  void MainWindow::on_auto_restore_win_dim
3837  #endif  #endif
3838  }  }
3839    
3840    void MainWindow::on_instr_double_click_opens_props() {
3841    #if USE_GLIB_ACTION
3842        bool active = false;
3843        m_actionInstrDoubleClickOpensProps->get_state(active);
3844        // for some reason toggle state does not change automatically
3845        active = !active;
3846        m_actionInstrDoubleClickOpensProps->change_state(active);
3847        Settings::singleton()->instrumentDoubleClickOpensProps = active;
3848    #else
3849        Gtk::CheckMenuItem* item =
3850            dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/OpenInstrPropsByDoubleClick"));
3851        if (!item) {
3852            std::cerr << "/MenuBar/MenuView/OpenInstrPropsByDoubleClick == NULL\n";
3853            return;
3854        }
3855        Settings::singleton()->instrumentDoubleClickOpensProps = item->get_active();
3856    #endif
3857    }
3858    
3859  void MainWindow::on_save_with_temporary_file() {  void MainWindow::on_save_with_temporary_file() {
3860  #if USE_GLIB_ACTION  #if USE_GLIB_ACTION
3861      bool active = false;      bool active = false;
# Line 3841  bool MainWindow::on_button_release(Gdk:: Line 3930  bool MainWindow::on_button_release(Gdk::
3930  void MainWindow::on_button_release(GdkEventButton* button) {  void MainWindow::on_button_release(GdkEventButton* button) {
3931  #endif  #endif
3932      if (button->type == GDK_2BUTTON_PRESS) {      if (button->type == GDK_2BUTTON_PRESS) {
3933          show_instr_props();          if (Settings::singleton()->instrumentDoubleClickOpensProps)
3934                show_instr_props();
3935      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
3936          // gig v2 files have no midi rules          // gig v2 files have no midi rules
3937          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);          const bool bEnabled = !(file->pVersion && file->pVersion->major == 2);
# Line 3881  void MainWindow::on_instrument_selection Line 3971  void MainWindow::on_instrument_selection
3971  }  }
3972  #endif  #endif
3973    
3974    void MainWindow::on_action_move_instr() {
3975        gig::Instrument* instr = get_instrument();
3976        if (!instr) return;
3977    
3978        int currentIndex = getIndexOf(instr);
3979    
3980        Gtk::Dialog dialog(_("Move Instrument"), true /*modal*/);
3981    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION < 90) || GTKMM_MAJOR_VERSION < 2
3982        Gtk::Adjustment adjustment(
3983            currentIndex,
3984            0 /*min*/, file->CountInstruments() - 1 /*max*/
3985        );
3986        Gtk::SpinButton spinBox(adjustment);
3987    #else
3988        Gtk::SpinButton spinBox(
3989            Gtk::Adjustment::create(
3990                currentIndex,
3991                0 /*min*/, file->CountInstruments() - 1 /*max*/
3992            )
3993        );
3994    #endif
3995    #if USE_GTKMM_BOX
3996        dialog.get_content_area()->pack_start(spinBox);
3997    #else
3998        dialog.get_vbox()->pack_start(spinBox);
3999    #endif
4000    #if HAS_GTKMM_STOCK
4001        Gtk::Button* okButton = dialog.add_button(Gtk::Stock::OK, 0);
4002        dialog.add_button(Gtk::Stock::CANCEL, 1);
4003    #else
4004        Gtk::Button* okButton = dialog.add_button(_("_OK"), 0);
4005        dialog.add_button(_("_Cancel"), 1);
4006    #endif
4007        okButton->set_sensitive(false);
4008        // show the dialog at a reasonable screen position
4009        dialog.set_position(Gtk::WIN_POS_MOUSE);
4010        // only enable the 'OK' button if entered new index is not instrument's
4011        // current index already
4012        spinBox.signal_value_changed().connect([&]{
4013            okButton->set_sensitive( spinBox.get_value_as_int() != currentIndex );
4014        });
4015        // usability acceleration: if user hits enter key on the text entry field
4016        // then auto trigger the 'OK' button
4017        spinBox.signal_activate().connect([&]{
4018            if (okButton->get_sensitive())
4019                okButton->clicked();
4020        });
4021    #if HAS_GTKMM_SHOW_ALL_CHILDREN
4022        dialog.show_all_children();
4023    #endif
4024        if (!dialog.run()) { // 'OK' selected ...
4025            int newIndex = spinBox.get_value_as_int();
4026            printf("MOVE TO %d\n", newIndex);
4027            gig::Instrument* dst = file->GetInstrument(newIndex);
4028            instr->MoveTo(dst);
4029            __refreshEntireGUI();
4030            select_instrument(instr);
4031        }
4032    }
4033    
4034  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
4035      if (!instrument) return;      if (!instrument) return;
4036    
# Line 4408  void MainWindow::on_action_edit_script() Line 4558  void MainWindow::on_action_edit_script()
4558      if (!it) return;      if (!it) return;
4559      Gtk::TreeModel::Row row = *it;      Gtk::TreeModel::Row row = *it;
4560      gig::Script* script = row[m_ScriptsModel.m_col_script];      gig::Script* script = row[m_ScriptsModel.m_col_script];
4561      if (!script) return;      editScript(script);
4562    }
4563    
4564    void MainWindow::editScript(gig::Script* script) {
4565        if (!script) return;
4566      ScriptEditor* editor = new ScriptEditor;      ScriptEditor* editor = new ScriptEditor;
4567      editor->signal_script_to_be_changed.connect(      editor->signal_script_to_be_changed.connect(
4568          signal_script_to_be_changed.make_slot()          signal_script_to_be_changed.make_slot()

Legend:
Removed from v.3637  
changed lines
  Added in v.3749

  ViewVC Help
Powered by ViewVC