--- gigedit/trunk/src/gigedit/mainwindow.cpp 2014/06/11 16:46:27 2621 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2014/07/05 19:43:14 2664 @@ -47,11 +47,13 @@ #include "CombineInstrumentsDialog.h" #include "scripteditor.h" #include "scriptslots.h" +#include "ReferencesView.h" #include "../../gfx/status_attached.xpm" #include "../../gfx/status_detached.xpm" MainWindow::MainWindow() : + m_DimRegionChooser(*this), dimreg_label(_("Changes apply to:")), dimreg_all_regions(_("all regions")), dimreg_all_dimregs(_("all dimension splits")), @@ -145,8 +147,19 @@ actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT), sigc::mem_fun( *this, &MainWindow::on_action_quit)); - actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); - + actionGroup->add( + Gtk::Action::create("MenuSample", _("_Sample")), + sigc::mem_fun(*this, &MainWindow::show_samples_tab) + ); + actionGroup->add( + Gtk::Action::create("MenuInstrument", _("_Instrument")), + sigc::mem_fun(*this, &MainWindow::show_intruments_tab) + ); + actionGroup->add( + Gtk::Action::create("MenuScript", _("S_cript")), + sigc::mem_fun(*this, &MainWindow::show_scripts_tab) + ); + actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select"))); actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit"))); @@ -236,6 +249,10 @@ sigc::mem_fun(*this, &MainWindow::on_action_remove_sample) ); actionGroup->add( + Gtk::Action::create("ShowSampleRefs", _("Show References...")), + sigc::mem_fun(*this, &MainWindow::on_action_view_references) + ); + actionGroup->add( Gtk::Action::create("ReplaceAllSamplesInAllGroups", _("Replace All Samples in All Groups...")), sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups) @@ -282,7 +299,33 @@ " " " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " + " " " " " " " " @@ -311,6 +354,7 @@ " " " " " " + " " " " " " " " @@ -364,7 +408,7 @@ instrument_menu = static_cast( - uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu(); + uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments"))->get_submenu(); Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar"); m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK); @@ -409,7 +453,7 @@ { Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0); Gtk::CellRendererText* cellrenderer = - dynamic_cast(column->get_first_cell_renderer()); + dynamic_cast(column->get_first_cell()); column->add_attribute( cellrenderer->property_foreground(), m_SamplesModel.m_color ); @@ -417,7 +461,7 @@ { Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1); Gtk::CellRendererText* cellrenderer = - dynamic_cast(column->get_first_cell_renderer()); + dynamic_cast(column->get_first_cell()); column->add_attribute( cellrenderer->property_foreground(), m_SamplesModel.m_color ); @@ -434,6 +478,8 @@ m_refScriptsTreeModel = ScriptsTreeStore::create(m_ScriptsModel); m_TreeViewScripts.set_model(m_refScriptsTreeModel); m_TreeViewScripts.set_tooltip_text(_( + "Use CTRL + double click for editing a script." + "\n\n" "Note: instrument scripts are a LinuxSampler extension of the gig " "format. This feature will not work with the GigaStudio software!" )); @@ -443,6 +489,10 @@ m_TreeViewScripts.signal_button_press_event().connect_notify( sigc::mem_fun(*this, &MainWindow::on_script_treeview_button_release) ); + //FIXME: why the heck does this double click signal_row_activated() only fired while CTRL key is pressed ? + m_TreeViewScripts.signal_row_activated().connect( + sigc::mem_fun(*this, &MainWindow::script_double_clicked) + ); m_refScriptsTreeModel->signal_row_changed().connect( sigc::mem_fun(*this, &MainWindow::script_name_changed) ); @@ -622,7 +672,7 @@ void MainWindow::dimreg_changed() { update_dimregs(); - dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); + dimreg_edit.set_dim_region(m_DimRegionChooser.get_main_dimregion()); } void MainWindow::on_sel_change() @@ -852,7 +902,28 @@ // load the instrument gig::File* pFile = (gig::File*) instr->GetParent(); load_gig(pFile, 0 /*file name*/, true /*shared instrument*/); - //TODO: automatically select the given instrument + // automatically select the given instrument + int i = 0; + for (gig::Instrument* instrument = pFile->GetFirstInstrument(); instrument; + instrument = pFile->GetNextInstrument(), ++i) + { + if (instrument == instr) { + // select item in "instruments" tree view + m_TreeView.get_selection()->select(Gtk::TreePath(ToString(i))); + // make sure the selected item in the "instruments" tree view is + // visible (scroll to it) + m_TreeView.scroll_to_row(Gtk::TreePath(ToString(i))); + // select item in instrument menu + { + const std::vector children = + instrument_menu->get_children(); + static_cast(children[i])->set_active(); + } + // update region chooser and dimension region chooser + m_RegionChooser.set_instrument(instr); + break; + } + } } void MainWindow::on_loader_progress() @@ -1133,8 +1204,8 @@ _( "Gigedit is released under the GNU General Public License.\n" "\n" - "Please notice that this is still a very young instrument editor. " - "So better backup your Gigasampler files before editing them with " + "This program is distributed WITHOUT ANY WARRANTY; So better " + "backup your Gigasampler/GigaStudio files before editing them with " "this application.\n" "\n" "Please report bugs to: http://bugs.linuxsampler.org" @@ -1430,7 +1501,7 @@ add_instrument_to_menu(name); } instrument_name_connection.unblock(); - uiManager->get_widget("/MenuBar/MenuInstrument")->show(); + uiManager->get_widget("/MenuBar/MenuInstrument/AllInstruments")->show(); updateSampleRefCountMap(gig); @@ -1452,7 +1523,7 @@ rowSample[m_SamplesModel.m_col_group] = NULL; int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0; rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); - rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; + rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; } } } @@ -1476,7 +1547,8 @@ rowScript[m_ScriptsModel.m_col_group] = NULL; } } - // unfold all script groups by default + // unfold all sample groups & script groups by default + m_TreeViewSamples.expand_all(); m_TreeViewScripts.expand_all(); file = gig; @@ -1609,9 +1681,15 @@ show_instr_props(); } else if (button->type == GDK_BUTTON_PRESS && button->button == 3) { // gig v2 files have no midi rules + const bool bEnabled = !(file->pVersion && file->pVersion->major == 2); + static_cast( + uiManager->get_widget("/MenuBar/MenuInstrument/MidiRules"))->set_sensitive( + bEnabled + ); static_cast( uiManager->get_widget("/PopupMenu/MidiRules"))->set_sensitive( - !(file->pVersion && file->pVersion->major == 2)); + bEnabled + ); popup_menu->popup(button->button, button->time); } } @@ -1645,16 +1723,31 @@ group_selected = row[m_SamplesModel.m_col_group]; sample_selected = row[m_SamplesModel.m_col_sample]; } + + dynamic_cast(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))-> set_sensitive(group_selected || sample_selected); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddSample"))-> set_sensitive(group_selected || sample_selected); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/AddGroup"))-> set_sensitive(file); + dynamic_cast(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))-> + set_sensitive(sample_selected); dynamic_cast(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))-> set_sensitive(group_selected || sample_selected); // show sample popup sample_popup->popup(button->button, button->time); + + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/SampleProperties"))-> + set_sensitive(group_selected || sample_selected); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddSample"))-> + set_sensitive(group_selected || sample_selected); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/AddGroup"))-> + set_sensitive(file); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/ShowSampleRefs"))-> + set_sensitive(sample_selected); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuSample/RemoveSample"))-> + set_sensitive(group_selected || sample_selected); } } @@ -1682,6 +1775,15 @@ set_sensitive(group_selected || script_selected); // show sample popup script_popup->popup(button->button, button->time); + + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScript"))-> + set_sensitive(group_selected || script_selected); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/AddScriptGroup"))-> + set_sensitive(file); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/EditScript"))-> + set_sensitive(script_selected); + dynamic_cast(uiManager->get_widget("/MenuBar/MenuScript/RemoveScript"))-> + set_sensitive(group_selected || script_selected); } } @@ -2489,6 +2591,21 @@ } } +void MainWindow::script_double_clicked(const Gtk::TreeModel::Path& path, + Gtk::TreeViewColumn* column) +{ + Gtk::TreeModel::iterator iter = m_refScriptsTreeModel->get_iter(path); + if (!iter) return; + Gtk::TreeModel::Row row = *iter; + gig::Script* script = row[m_ScriptsModel.m_col_script]; + if (!script) return; + + ScriptEditor* editor = new ScriptEditor; + editor->setScript(script); + //editor->reparent(*this); + editor->show(); +} + void MainWindow::instrument_name_changed(const Gtk::TreeModel::Path& path, const Gtk::TreeModel::iterator& iter) { if (!iter) return; @@ -2535,6 +2652,22 @@ delete d; } +void MainWindow::on_action_view_references() { + Glib::RefPtr sel = m_TreeViewSamples.get_selection(); + Gtk::TreeModel::iterator it = sel->get_selected(); + if (!it) return; + Gtk::TreeModel::Row row = *it; + gig::Sample* sample = row[m_SamplesModel.m_col_sample]; + if (!sample) return; + + ReferencesView* d = new ReferencesView(*this); + d->setSample(sample); + d->show_all(); + d->resize(500, 400); + d->run(); + delete d; +} + void MainWindow::mergeFiles(const std::vector& filenames) { struct _Source { std::vector riffs; @@ -2707,7 +2840,7 @@ Gtk::TreeModel::Row rowSample = rowGroup.children()[s]; if (rowSample[m_SamplesModel.m_col_sample] != sample) continue; rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs."); - rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray"; + rowSample[m_SamplesModel.m_color] = refcount ? "black" : "red"; } } } @@ -2727,6 +2860,18 @@ } } +void MainWindow::show_samples_tab() { + m_TreeViewNotebook.set_current_page(0); +} + +void MainWindow::show_intruments_tab() { + m_TreeViewNotebook.set_current_page(1); +} + +void MainWindow::show_scripts_tab() { + m_TreeViewNotebook.set_current_page(2); +} + sigc::signal& MainWindow::signal_file_structure_to_be_changed() { return file_structure_to_be_changed_signal; }