/[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 2683 by schoenebeck, Mon Dec 29 16:30:21 2014 UTC revision 2701 by schoenebeck, Mon Jan 12 23:28:04 2015 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2014 Andreas Persson   * Copyright (C) 2006-2015 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 217  MainWindow::MainWindow() : Line 217  MainWindow::MainWindow() :
217          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)          sigc::mem_fun(*this, &MainWindow::on_action_warn_user_on_extensions)
218      );      );
219    
220        toggle_action =
221            Gtk::ToggleAction::create("SyncSamplerInstrumentSelection", _("Synchronize sampler's instrument selection"));
222        toggle_action->set_active(Settings::singleton()->syncSamplerInstrumentSelection);
223        actionGroup->add(
224            toggle_action,
225            sigc::mem_fun(*this, &MainWindow::on_action_sync_sampler_instrument_selection)
226        );
227    
228    
229      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));      actionGroup->add(Gtk::Action::create("MenuTools", _("_Tools")));
230    
# Line 336  MainWindow::MainWindow() : Line 344  MainWindow::MainWindow() :
344          "    </menu>"          "    </menu>"
345          "    <menu action='MenuSettings'>"          "    <menu action='MenuSettings'>"
346          "      <menuitem action='WarnUserOnExtensions'/>"          "      <menuitem action='WarnUserOnExtensions'/>"
347            "      <menuitem action='SyncSamplerInstrumentSelection'/>"
348          "    </menu>"          "    </menu>"
349          "    <menu action='MenuHelp'>"          "    <menu action='MenuHelp'>"
350          "      <menuitem action='About'/>"          "      <menuitem action='About'/>"
# Line 397  MainWindow::MainWindow() : Line 406  MainWindow::MainWindow() :
406      }      }
407      {      {
408          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(          Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
409                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
410            item->set_tooltip_text(_("If checked, the sampler's current instrument will automatically be switched whenever another instrument was selected in gigedit (only available in live-mode)."));
411        }
412        {
413            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
414              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));              uiManager->get_widget("/MenuBar/MenuTools/CombineInstruments"));
415          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."));
416      }      }
# Line 434  MainWindow::MainWindow() : Line 448  MainWindow::MainWindow() :
448      // Create the Tree model:      // Create the Tree model:
449      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
450      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
451      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
452      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
453          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
454      );      );
# Line 442  MainWindow::MainWindow() : Line 456  MainWindow::MainWindow() :
456      // Add the TreeView's view columns:      // Add the TreeView's view columns:
457      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);      m_TreeView.append_column_editable("Instrument", m_Columns.m_col_name);
458      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
459        
460        // establish drag&drop within the instrument tree view, allowing to reorder
461        // the sequence of instruments within the gig file
462        {
463            std::vector<Gtk::TargetEntry> drag_target_instrument;
464            drag_target_instrument.push_back(Gtk::TargetEntry("gig::Instrument"));
465            m_TreeView.drag_source_set(drag_target_instrument);
466            m_TreeView.drag_dest_set(drag_target_instrument);
467            m_TreeView.signal_drag_begin().connect(
468                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_begin)
469            );
470            m_TreeView.signal_drag_data_get().connect(
471                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drag_data_get)
472            );
473            m_TreeView.signal_drag_data_received().connect(
474                sigc::mem_fun(*this, &MainWindow::on_instruments_treeview_drop_drag_data_received)
475            );
476        }
477    
478      // create samples treeview (including its data model)      // create samples treeview (including its data model)
479      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);      m_refSamplesTreeModel = SamplesTreeStore::create(m_SamplesModel);
# Line 489  MainWindow::MainWindow() : Line 521  MainWindow::MainWindow() :
521      m_TreeViewScripts.signal_button_press_event().connect_notify(      m_TreeViewScripts.signal_button_press_event().connect_notify(
522          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release)
523      );      );
524      //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ?      //FIXME: why the heck does this double click signal_row_activated() only fire while CTRL key is pressed ?
525      m_TreeViewScripts.signal_row_activated().connect(      m_TreeViewScripts.signal_row_activated().connect(
526          sigc::mem_fun(*this, &MainWindow::script_double_clicked)          sigc::mem_fun(*this, &MainWindow::script_double_clicked)
527      );      );
# Line 548  MainWindow::MainWindow() : Line 580  MainWindow::MainWindow() :
580          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)          sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
581      );      );
582    
583        dimreg_edit.signal_select_sample().connect(
584            sigc::mem_fun(*this, &MainWindow::select_sample)
585        );
586    
587      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
588          sigc::hide(          sigc::hide(
589              sigc::bind(              sigc::bind(
# Line 688  void MainWindow::on_sel_change() Line 724  void MainWindow::on_sel_change()
724      }      }
725    
726      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
727    
728        if (Settings::singleton()->syncSamplerInstrumentSelection) {
729            switch_sampler_instrument_signal.emit(get_instrument());
730        }
731  }  }
732    
733  void loader_progress_callback(gig::progress_t* progress)  void loader_progress_callback(gig::progress_t* progress)
# Line 925  bool MainWindow::close_confirmation_dial Line 965  bool MainWindow::close_confirmation_dial
965      int response = dialog.run();      int response = dialog.run();
966      dialog.hide();      dialog.hide();
967    
968        // user decided to exit app without saving
969        if (response == Gtk::RESPONSE_NO) return true;
970    
971        // user cancelled dialog, thus don't close app
972        if (response == Gtk::RESPONSE_CANCEL) return false;
973    
974      // TODO: the following return valid is disabled and hard coded instead for      // TODO: the following return valid is disabled and hard coded instead for
975      // now, due to the fact that saving with progress bar is now implemented      // now, due to the fact that saving with progress bar is now implemented
976      // asynchronously, as a result the app does not close automatically anymore      // asynchronously, as a result the app does not close automatically anymore
# Line 1141  void MainWindow::on_saver_finished() Line 1187  void MainWindow::on_saver_finished()
1187    
1188      file_structure_changed_signal.emit(this->file);      file_structure_changed_signal.emit(this->file);
1189    
1190      load_gig(this->file, this->filename.c_str());      __refreshEntireGUI();
1191      progress_dialog->hide();      progress_dialog->hide();
1192  }  }
1193    
# Line 1339  void MainWindow::on_action_warn_user_on_ Line 1385  void MainWindow::on_action_warn_user_on_
1385          !Settings::singleton()->warnUserOnExtensions;          !Settings::singleton()->warnUserOnExtensions;
1386  }  }
1387    
1388    void MainWindow::on_action_sync_sampler_instrument_selection() {
1389        Settings::singleton()->syncSamplerInstrumentSelection =
1390            !Settings::singleton()->syncSamplerInstrumentSelection;
1391    }
1392    
1393  void MainWindow::on_action_help_about()  void MainWindow::on_action_help_about()
1394  {  {
1395      Gtk::AboutDialog dialog;      Gtk::AboutDialog dialog;
# Line 1348  void MainWindow::on_action_help_about() Line 1399  void MainWindow::on_action_help_about()
1399      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1400  #endif  #endif
1401      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1402      dialog.set_copyright("Copyright (C) 2006-2014 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2015 Andreas Persson");
1403      const std::string sComment =      const std::string sComment =
1404          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1405          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 1860  void MainWindow::on_instrument_selection Line 1911  void MainWindow::on_instrument_selection
1911      }      }
1912  }  }
1913    
1914    void MainWindow::select_instrument(gig::Instrument* instrument) {
1915        if (!instrument) return;
1916    
1917        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1918        for (int i = 0; i < model->children().size(); ++i) {
1919            Gtk::TreeModel::Row row = model->children()[i];
1920            if (row[m_Columns.m_col_instr] == instrument) {
1921                // select and show the respective instrument in the list view
1922                show_intruments_tab();
1923                m_TreeView.get_selection()->select(model->children()[i]);
1924                Gtk::TreePath path(
1925                    m_TreeView.get_selection()->get_selected()
1926                );
1927                m_TreeView.scroll_to_row(path);
1928                on_sel_change(); // the regular instrument selection change callback
1929            }
1930        }
1931    }
1932    
1933    /// Returns true if requested dimension region was successfully selected and scrolled to in the list view, false on error.
1934    bool MainWindow::select_dimension_region(gig::DimensionRegion* dimRgn) {
1935        gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
1936        gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
1937    
1938        Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
1939        for (int i = 0; i < model->children().size(); ++i) {
1940            Gtk::TreeModel::Row row = model->children()[i];
1941            if (row[m_Columns.m_col_instr] == pInstrument) {
1942                // select and show the respective instrument in the list view
1943                show_intruments_tab();
1944                m_TreeView.get_selection()->select(model->children()[i]);
1945                Gtk::TreePath path(
1946                    m_TreeView.get_selection()->get_selected()
1947                );
1948                m_TreeView.scroll_to_row(path);
1949                on_sel_change(); // the regular instrument selection change callback
1950    
1951                // select respective region in the region selector
1952                m_RegionChooser.set_region(pRegion);
1953    
1954                // select and show the respective dimension region in the editor
1955                //update_dimregs();
1956                if (!m_DimRegionChooser.select_dimregion(dimRgn)) return false;
1957                //dimreg_edit.set_dim_region(dimRgn);
1958    
1959                return true;
1960            }
1961        }
1962    
1963        return false;
1964    }
1965    
1966    void MainWindow::select_sample(gig::Sample* sample) {
1967        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
1968        for (int g = 0; g < model->children().size(); ++g) {
1969            Gtk::TreeModel::Row rowGroup = model->children()[g];
1970            for (int s = 0; s < rowGroup.children().size(); ++s) {
1971                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
1972                if (rowSample[m_SamplesModel.m_col_sample] == sample) {
1973                    show_samples_tab();
1974                    m_TreeViewSamples.get_selection()->select(rowGroup.children()[s]);
1975                    Gtk::TreePath path(
1976                        m_TreeViewSamples.get_selection()->get_selected()
1977                    );
1978                    m_TreeViewSamples.scroll_to_row(path);
1979                    return;
1980                }
1981            }
1982        }
1983    }
1984    
1985  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
1986      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {      if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1987          Gtk::Menu* sample_popup =          Gtk::Menu* sample_popup =
# Line 2591  void MainWindow::on_scripts_treeview_dra Line 2713  void MainWindow::on_scripts_treeview_dra
2713                         sizeof(script)/*length of data in bytes*/);                         sizeof(script)/*length of data in bytes*/);
2714  }  }
2715    
2716    // see comment on on_sample_treeview_drag_begin()
2717    void MainWindow::on_instruments_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2718    {
2719        first_call_to_drag_data_get = true;
2720    }
2721    
2722    void MainWindow::on_instruments_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2723                                                           Gtk::SelectionData& selection_data, guint, guint)
2724    {
2725        if (!first_call_to_drag_data_get) return;
2726        first_call_to_drag_data_get = false;
2727    
2728        // get selected source instrument
2729        gig::Instrument* src = NULL;
2730        {
2731            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
2732            Gtk::TreeModel::iterator it = sel->get_selected();
2733            if (it) {
2734                Gtk::TreeModel::Row row = *it;
2735                src = row[m_Columns.m_col_instr];
2736            }
2737        }
2738        if (!src) return;
2739    
2740        // pass the source gig::Instrument as pointer
2741        selection_data.set(selection_data.get_target(), 0/*unused*/, (const guchar*)&src,
2742                           sizeof(src)/*length of data in bytes*/);
2743    }
2744    
2745    void MainWindow::on_instruments_treeview_drop_drag_data_received(
2746        const Glib::RefPtr<Gdk::DragContext>& context, int x, int y,
2747        const Gtk::SelectionData& selection_data, guint, guint time)
2748    {
2749        gig::Instrument* src = *((gig::Instrument**) selection_data.get_data());
2750        if (!src || selection_data.get_length() != sizeof(gig::Instrument*))
2751            return;
2752    
2753        gig::Instrument* dst = NULL;
2754        {
2755            Gtk::TreeModel::Path path;
2756            const bool found = m_TreeView.get_path_at_pos(x, y, path);
2757            if (!found) return;
2758    
2759            Gtk::TreeModel::iterator iter = m_refTreeModel->get_iter(path);
2760            if (!iter) return;
2761            Gtk::TreeModel::Row row = *iter;
2762            dst = row[m_Columns.m_col_instr];
2763        }
2764        if (!dst) return;
2765    
2766        //printf("dragdrop received src=%s dst=%s\n", src->pInfo->Name.c_str(), dst->pInfo->Name.c_str());
2767        src->MoveTo(dst);
2768        __refreshEntireGUI();
2769        select_instrument(src);
2770    }
2771    
2772  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2773  // drag'n'drop (at least when target is an Entry). This work-around  // drag'n'drop (at least when target is an Entry). This work-around
2774  // makes sure the code in drag_data_get and drop_drag_data_received is  // makes sure the code in drag_data_get and drop_drag_data_received is
# Line 2813  void MainWindow::on_action_view_referenc Line 2991  void MainWindow::on_action_view_referenc
2991    
2992      ReferencesView* d = new ReferencesView(*this);      ReferencesView* d = new ReferencesView(*this);
2993      d->setSample(sample);      d->setSample(sample);
2994        d->dimension_region_selected.connect(
2995            sigc::mem_fun(*this, &MainWindow::select_dimension_region)
2996        );
2997      d->show_all();      d->show_all();
2998      d->resize(500, 400);      d->resize(500, 400);
2999      d->run();      d->run();
# Line 2996  void MainWindow::set_file_is_shared(bool Line 3177  void MainWindow::set_file_is_shared(bool
3177              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)              Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm)
3178          );          );
3179      }      }
3180    
3181        {
3182            Gtk::MenuItem* item = dynamic_cast<Gtk::MenuItem*>(
3183                uiManager->get_widget("/MenuBar/MenuSettings/SyncSamplerInstrumentSelection"));
3184            if (item) item->set_sensitive(b);
3185        }
3186  }  }
3187    
3188  void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {  void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
# Line 3097  sigc::signal<void, int/*key*/, int/*velo Line 3284  sigc::signal<void, int/*key*/, int/*velo
3284  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {  sigc::signal<void, int/*key*/, int/*velocity*/>& MainWindow::signal_keyboard_key_released() {
3285      return m_RegionChooser.signal_keyboard_key_released();      return m_RegionChooser.signal_keyboard_key_released();
3286  }  }
3287    
3288    sigc::signal<void, gig::Instrument*>& MainWindow::signal_switch_sampler_instrument() {
3289        return switch_sampler_instrument_signal;
3290    }

Legend:
Removed from v.2683  
changed lines
  Added in v.2701

  ViewVC Help
Powered by ViewVC