--- gigedit/trunk/src/gigedit/mainwindow.cpp 2007/10/10 15:48:54 1396 +++ gigedit/trunk/src/gigedit/mainwindow.cpp 2007/12/01 10:21:07 1533 @@ -24,6 +24,7 @@ #include #include #include +#include #include "global.h" @@ -49,13 +50,20 @@ #include "mainwindow.h" +#include "../../gfx/status_attached.xpm" +#include "../../gfx/status_detached.xpm" + template inline std::string ToString(T o) { std::stringstream ss; ss << o; return ss.str(); } -MainWindow::MainWindow() +MainWindow::MainWindow() : + dimreg_label(_("Changes apply to:")), + dimreg_all_regions(_("all regions")), + dimreg_all_dimregs(_("all dimension splits")), + dimreg_stereo(_("both channels")) { // set_border_width(5); // set_default_size(400, 200); @@ -85,7 +93,14 @@ m_TreeViewNotebook.set_size_request(300); m_HPaned.add1(m_TreeViewNotebook); - m_HPaned.add2(dimreg_edit); + dimreg_hbox.add(dimreg_label); + dimreg_hbox.add(dimreg_all_regions); + dimreg_hbox.add(dimreg_all_dimregs); + dimreg_stereo.set_active(); + dimreg_hbox.add(dimreg_stereo); + dimreg_vbox.add(dimreg_edit); + dimreg_vbox.add(dimreg_hbox); + m_HPaned.add2(dimreg_vbox); m_TreeViewNotebook.append_page(m_ScrolledWindowSamples, "Samples"); @@ -126,6 +141,14 @@ *this, &MainWindow::on_action_quit)); actionGroup->add(Gtk::Action::create("MenuInstrument", _("_Instrument"))); + actionGroup->add(Gtk::Action::create("MenuView", _("_View"))); + Glib::RefPtr toggle_action = + Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); + toggle_action->set_active(true); + actionGroup->add(toggle_action, + sigc::mem_fun( + *this, &MainWindow::on_action_view_status_bar)); + action = Gtk::Action::create("MenuHelp", Gtk::Stock::HELP); actionGroup->add(Gtk::Action::create("MenuHelp", action->property_label())); @@ -181,6 +204,9 @@ " " " " " " + " " + " " + " " #ifdef ABOUT_DIALOG " " " " @@ -210,6 +236,12 @@ m_VBox.pack_start(m_HPaned); m_VBox.pack_start(m_RegionChooser, Gtk::PACK_SHRINK); m_VBox.pack_start(m_DimRegionChooser, Gtk::PACK_SHRINK); + m_VBox.pack_start(m_StatusBar, Gtk::PACK_SHRINK); + + // Status Bar: + m_StatusBar.pack_start(m_AttachedStateLabel, Gtk::PACK_SHRINK); + m_StatusBar.pack_start(m_AttachedStateImage, Gtk::PACK_SHRINK); + m_StatusBar.show(); m_RegionChooser.signal_region_selected().connect( sigc::mem_fun(*this, &MainWindow::region_changed) ); @@ -292,9 +324,16 @@ m_RegionChooser.signal_region_changed_signal().connect( region_changed_signal.make_slot()); + dimreg_all_regions.signal_toggled().connect( + sigc::mem_fun(*this, &MainWindow::update_dimregs)); + dimreg_all_dimregs.signal_toggled().connect( + sigc::mem_fun(*this, &MainWindow::dimreg_all_dimregs_toggled)); + dimreg_stereo.signal_toggled().connect( + sigc::mem_fun(*this, &MainWindow::update_dimregs)); + file = 0; file_is_changed = false; - file_is_shared = false; + set_file_is_shared(false); show_all_children(); @@ -322,26 +361,73 @@ m_DimRegionChooser.set_region(m_RegionChooser.get_region()); } -void MainWindow::dimreg_changed() -{ - dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); -} - -void MainWindow::on_sel_change() +gig::Instrument* MainWindow::get_instrument() { + gig::Instrument* instrument = 0; Glib::RefPtr tree_sel_ref = m_TreeView.get_selection(); Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); if (it) { Gtk::TreeModel::Row row = *it; - std::cout << row[m_Columns.m_col_name] << std::endl; + instrument = row[m_Columns.m_col_instr]; + } + return instrument; +} - m_RegionChooser.set_instrument(row[m_Columns.m_col_instr]); +void MainWindow::add_region_to_dimregs(gig::Region* region, bool stereo, bool all_dimregs) +{ + if (all_dimregs) { + for (int i = 0 ; i < region->DimensionRegions ; i++) { + if (region->pDimensionRegions[i]) { + dimreg_edit.dimregs.insert(region->pDimensionRegions[i]); + } + } } else { - m_RegionChooser.set_instrument(0); + m_DimRegionChooser.get_dimregions(region, stereo, dimreg_edit.dimregs); } } +void MainWindow::update_dimregs() +{ + dimreg_edit.dimregs.clear(); + bool all_regions = dimreg_all_regions.get_active(); + bool stereo = dimreg_stereo.get_active(); + bool all_dimregs = dimreg_all_dimregs.get_active(); + + if (all_regions) { + gig::Instrument* instrument = get_instrument(); + if (instrument) { + for (gig::Region* region = instrument->GetFirstRegion() ; + region ; + region = instrument->GetNextRegion()) { + add_region_to_dimregs(region, stereo, all_dimregs); + } + } + } else { + gig::Region* region = m_RegionChooser.get_region(); + if (region) { + add_region_to_dimregs(region, stereo, all_dimregs); + } + } +} + +void MainWindow::dimreg_all_dimregs_toggled() +{ + dimreg_stereo.set_sensitive(!dimreg_all_dimregs.get_active()); + update_dimregs(); +} + +void MainWindow::dimreg_changed() +{ + update_dimregs(); + dimreg_edit.set_dim_region(m_DimRegionChooser.get_dimregion()); +} + +void MainWindow::on_sel_change() +{ + m_RegionChooser.set_instrument(get_instrument()); +} + void loader_progress_callback(gig::progress_t* progress) { Loader* loader = static_cast(progress->custom); @@ -429,7 +515,7 @@ // free libgig's gig::File instance if (file && !file_is_shared) delete file; file = NULL; - file_is_shared = false; + set_file_is_shared(false); } void MainWindow::on_action_file_new() @@ -765,6 +851,18 @@ #ifdef ABOUT_DIALOG Gtk::AboutDialog dialog; dialog.set_version(VERSION); + dialog.set_copyright("Copyright (C) 2006,2007 Andreas Persson"); + dialog.set_comments( + "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 application.\n" + "\n" + "Please report bugs to: http://bugs.linuxsampler.org" + ); + dialog.set_website("http://www.linuxsampler.org"); + dialog.set_website_label("http://www.linuxsampler.org"); dialog.run(); #endif } @@ -825,12 +923,42 @@ entry[15].set_text(info->Subject); } +void InstrumentProps::set_IsDrum(bool value) +{ + instrument->IsDrum = value; +} + +void InstrumentProps::set_MIDIBank(uint16_t value) +{ + instrument->MIDIBank = value; +} + +void InstrumentProps::set_MIDIProgram(uint32_t value) +{ + instrument->MIDIProgram = value; +} + +void InstrumentProps::set_DimensionKeyRange_low(uint8_t value) +{ + instrument->DimensionKeyRange.low = value; + if (value > instrument->DimensionKeyRange.high) { + eDimensionKeyRangeHigh.set_value(value); + } +} + +void InstrumentProps::set_DimensionKeyRange_high(uint8_t value) +{ + instrument->DimensionKeyRange.high = value; + if (value < instrument->DimensionKeyRange.low) { + eDimensionKeyRangeLow.set_value(value); + } +} + void InstrumentProps::add_prop(BoolEntry& boolentry) { table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, Gtk::FILL, Gtk::SHRINK); rowno++; - boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); } void InstrumentProps::add_prop(BoolEntryPlus6& boolentry) @@ -838,7 +966,6 @@ table.attach(boolentry.widget, 0, 2, rowno, rowno + 1, Gtk::FILL, Gtk::SHRINK); rowno++; - boolentry.signal_changed_by_user().connect(instrument_changed.make_slot()); } void InstrumentProps::add_prop(LabelWidget& prop) @@ -848,7 +975,6 @@ table.attach(prop.widget, 1, 2, rowno, rowno + 1, Gtk::FILL | Gtk::EXPAND, Gtk::SHRINK); rowno++; - prop.signal_changed_by_user().connect(instrument_changed.make_slot()); } InstrumentProps::InstrumentProps() @@ -865,10 +991,25 @@ ePitchbendRange("Pitchbend range", 0, 12), ePianoReleaseMode("Piano release mode"), eDimensionKeyRangeLow("Dimension key range low"), - eDimensionKeyRangeHigh("Dimension key range high") + eDimensionKeyRangeHigh("Dimension key range high"), + update_model(0) { set_title("Instrument properties"); + connect(eIsDrum, &InstrumentProps::set_IsDrum); + connect(eMIDIBank, &InstrumentProps::set_MIDIBank); + connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram); + connect(eAttenuation, &gig::Instrument::Attenuation); + connect(eGainPlus6, &gig::Instrument::Attenuation); + connect(eEffectSend, &gig::Instrument::EffectSend); + connect(eFineTune, &gig::Instrument::FineTune); + connect(ePitchbendRange, &gig::Instrument::PitchbendRange); + connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode); + connect(eDimensionKeyRangeLow, + &InstrumentProps::set_DimensionKeyRange_low); + connect(eDimensionKeyRangeHigh, + &InstrumentProps::set_DimensionKeyRange_high); + rowno = 0; table.set_col_spacings(5); @@ -885,11 +1026,6 @@ add_prop(eDimensionKeyRangeLow); add_prop(eDimensionKeyRangeHigh); - eDimensionKeyRangeLow.signal_changed_by_user().connect( - sigc::mem_fun(*this, &InstrumentProps::key_range_low_changed)); - eDimensionKeyRangeHigh.signal_changed_by_user().connect( - sigc::mem_fun(*this, &InstrumentProps::key_range_high_changed)); - add(vbox); table.set_border_width(5); vbox.pack_start(table); @@ -912,34 +1048,22 @@ void InstrumentProps::set_instrument(gig::Instrument* instrument) { + this->instrument = instrument; + + update_model++; eName.set_ptr(&instrument->pInfo->Name); - eIsDrum.set_ptr(&instrument->IsDrum); - eMIDIBank.set_ptr(&instrument->MIDIBank); - eMIDIProgram.set_ptr(&instrument->MIDIProgram); - eAttenuation.set_ptr(&instrument->Attenuation); - eGainPlus6.set_ptr(&instrument->Attenuation); - eEffectSend.set_ptr(&instrument->EffectSend); - eFineTune.set_ptr(&instrument->FineTune); - ePitchbendRange.set_ptr(&instrument->PitchbendRange); - ePianoReleaseMode.set_ptr(&instrument->PianoReleaseMode); - eDimensionKeyRangeLow.set_ptr(0); - eDimensionKeyRangeHigh.set_ptr(0); - eDimensionKeyRangeLow.set_ptr(&instrument->DimensionKeyRange.low); - eDimensionKeyRangeHigh.set_ptr(&instrument->DimensionKeyRange.high); -} - -void InstrumentProps::key_range_low_changed() -{ - double l = eDimensionKeyRangeLow.get_value(); - double h = eDimensionKeyRangeHigh.get_value(); - if (h < l) eDimensionKeyRangeHigh.set_value(l); -} - -void InstrumentProps::key_range_high_changed() -{ - double l = eDimensionKeyRangeLow.get_value(); - double h = eDimensionKeyRangeHigh.get_value(); - if (h < l) eDimensionKeyRangeLow.set_value(h); + eIsDrum.set_value(instrument->IsDrum); + eMIDIBank.set_value(instrument->MIDIBank); + eMIDIProgram.set_value(instrument->MIDIProgram); + eAttenuation.set_value(instrument->Attenuation); + eGainPlus6.set_value(instrument->Attenuation); + eEffectSend.set_value(instrument->EffectSend); + eFineTune.set_value(instrument->FineTune); + ePitchbendRange.set_value(instrument->PitchbendRange); + ePianoReleaseMode.set_value(instrument->PianoReleaseMode); + eDimensionKeyRangeLow.set_value(instrument->DimensionKeyRange.low); + eDimensionKeyRangeHigh.set_value(instrument->DimensionKeyRange.high); + update_model--; } sigc::signal& InstrumentProps::signal_instrument_changed() @@ -958,7 +1082,7 @@ void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument) { file = 0; - file_is_shared = isSharedInstrument; + set_file_is_shared(isSharedInstrument); this->filename = filename ? filename : _("Unsaved Gig File"); set_title(Glib::filename_display_basename(this->filename)); @@ -1021,20 +1145,26 @@ void MainWindow::show_instr_props() { - Glib::RefPtr tree_sel_ref = m_TreeView.get_selection(); - Gtk::TreeModel::iterator it = tree_sel_ref->get_selected(); - if (it) + gig::Instrument* instrument = get_instrument(); + if (instrument) { - Gtk::TreeModel::Row row = *it; - if (row[m_Columns.m_col_instr]) - { - instrumentProps.set_instrument(row[m_Columns.m_col_instr]); - instrumentProps.show(); - instrumentProps.deiconify(); - } + instrumentProps.set_instrument(instrument); + instrumentProps.show(); + instrumentProps.deiconify(); } } +void MainWindow::on_action_view_status_bar() { + Gtk::CheckMenuItem* item = + dynamic_cast(uiManager->get_widget("/MenuBar/MenuView/Statusbar")); + if (!item) { + std::cerr << "/MenuBar/MenuView/Statusbar == NULL\n"; + return; + } + if (item->get_active()) m_StatusBar.show(); + else m_StatusBar.hide(); +} + void MainWindow::on_button_release(GdkEventButton* button) { if (button->type == GDK_2BUTTON_PRESS) { @@ -1462,6 +1592,8 @@ // notify we're done with altering region_changed_signal.emit(region); + file_changed(); + return; } // drop failed @@ -1502,6 +1634,22 @@ } } +void MainWindow::set_file_is_shared(bool b) { + this->file_is_shared = b; + + if (file_is_shared) { + m_AttachedStateLabel.set_label(_("live-mode")); + m_AttachedStateImage.set( + Gdk::Pixbuf::create_from_xpm_data(status_attached_xpm) + ); + } else { + m_AttachedStateLabel.set_label(_("stand-alone")); + m_AttachedStateImage.set( + Gdk::Pixbuf::create_from_xpm_data(status_detached_xpm) + ); + } +} + sigc::signal& MainWindow::signal_file_structure_to_be_changed() { return file_structure_to_be_changed_signal; }