/[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 2398 by persson, Sun Jan 13 09:14:29 2013 UTC revision 2446 by persson, Sun Apr 28 15:40:43 2013 UTC
# Line 30  Line 30 
30  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
31  #include <gtkmm/targetentry.h>  #include <gtkmm/targetentry.h>
32  #include <gtkmm/main.h>  #include <gtkmm/main.h>
 #include <gtkmm/radiomenuitem.h>  
33  #include <gtkmm/toggleaction.h>  #include <gtkmm/toggleaction.h>
34  #if GTKMM_MAJOR_VERSION < 3  #if GTKMM_MAJOR_VERSION < 3
35  #include "wrapLabel.hh"  #include "wrapLabel.hh"
# Line 47  Line 46 
46  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
47  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
48    
 template<class T> inline std::string ToString(T o) {  
     std::stringstream ss;  
     ss << o;  
     return ss.str();  
 }  
   
 Table::Table(int x, int y) : Gtk::Table(x, y), rowno(0) {  }  
   
 void Table::add(BoolEntry& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(BoolEntryPlus6& boolentry)  
 {  
     attach(boolentry.widget, 0, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
   
 void Table::add(LabelWidget& prop)  
 {  
     attach(prop.label, 1, 2, rowno, rowno + 1,  
            Gtk::FILL, Gtk::SHRINK);  
     attach(prop.widget, 2, 3, rowno, rowno + 1,  
            Gtk::EXPAND | Gtk::FILL, Gtk::SHRINK);  
     rowno++;  
 }  
49    
50  MainWindow::MainWindow() :  MainWindow::MainWindow() :
51      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
# Line 91  MainWindow::MainWindow() : Line 60  MainWindow::MainWindow() :
60      add(m_VBox);      add(m_VBox);
61    
62      // Handle selection      // Handle selection
63      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->signal_changed().connect(
     tree_sel_ref->signal_changed().connect(  
64          sigc::mem_fun(*this, &MainWindow::on_sel_change));          sigc::mem_fun(*this, &MainWindow::on_sel_change));
65    
66      // m_TreeView.set_reorderable();      // m_TreeView.set_reorderable();
# Line 248  MainWindow::MainWindow() : Line 216  MainWindow::MainWindow() :
216          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
217          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
218          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
219          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
220          "    <separator/>"          "    <separator/>"
221          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
222          "  </popup>"          "  </popup>"
# Line 257  MainWindow::MainWindow() : Line 225  MainWindow::MainWindow() :
225    
226      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));      popup_menu = dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/PopupMenu"));
227    
228        instrument_menu = static_cast<Gtk::MenuItem*>(
229            uiManager->get_widget("/MenuBar/MenuInstrument"))->get_submenu();
230    
231      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");      Gtk::Widget* menuBar = uiManager->get_widget("/MenuBar");
232      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);      m_VBox.pack_start(*menuBar, Gtk::PACK_SHRINK);
233      m_VBox.pack_start(m_HPaned);      m_VBox.pack_start(m_HPaned);
# Line 281  MainWindow::MainWindow() : Line 252  MainWindow::MainWindow() :
252      // Create the Tree model:      // Create the Tree model:
253      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
254      m_TreeView.set_model(m_refTreeModel);      m_TreeView.set_model(m_refTreeModel);
255      m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
256          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
257      );      );
258    
# Line 322  MainWindow::MainWindow() : Line 293  MainWindow::MainWindow() :
293          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
294      m_DimRegionChooser.signal_region_changed().connect(      m_DimRegionChooser.signal_region_changed().connect(
295          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
296      instrumentProps.signal_instrument_changed().connect(      instrumentProps.signal_changed().connect(
297          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
298      propDialog.signal_info_changed().connect(      propDialog.signal_changed().connect(
299          sigc::mem_fun(*this, &MainWindow::file_changed));          sigc::mem_fun(*this, &MainWindow::file_changed));
300    
301      dimreg_edit.signal_dimreg_to_be_changed().connect(      dimreg_edit.signal_dimreg_to_be_changed().connect(
# Line 399  void MainWindow::region_changed() Line 370  void MainWindow::region_changed()
370  gig::Instrument* MainWindow::get_instrument()  gig::Instrument* MainWindow::get_instrument()
371  {  {
372      gig::Instrument* instrument = 0;      gig::Instrument* instrument = 0;
373      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      Gtk::TreeModel::const_iterator it =
374            m_TreeView.get_selection()->get_selected();
     Gtk::TreeModel::iterator it = tree_sel_ref->get_selected();  
375      if (it) {      if (it) {
376          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
377          instrument = row[m_Columns.m_col_instr];          instrument = row[m_Columns.m_col_instr];
# Line 460  void MainWindow::dimreg_changed() Line 430  void MainWindow::dimreg_changed()
430    
431  void MainWindow::on_sel_change()  void MainWindow::on_sel_change()
432  {  {
433        // select item in instrument menu
434        Gtk::TreeModel::iterator it = m_TreeView.get_selection()->get_selected();
435        if (it) {
436            Gtk::TreePath path(it);
437            int index = path[0];
438            const std::vector<Gtk::Widget*> children =
439                instrument_menu->get_children();
440            static_cast<Gtk::RadioMenuItem*>(children[index])->set_active();
441        }
442    
443      m_RegionChooser.set_instrument(get_instrument());      m_RegionChooser.set_instrument(get_instrument());
444  }  }
445    
# Line 538  LoadDialog::LoadDialog(const Glib::ustri Line 518  LoadDialog::LoadDialog(const Glib::ustri
518  // Clear all GUI elements / controls. This method is typically called  // Clear all GUI elements / controls. This method is typically called
519  // before a new .gig file is to be created or to be loaded.  // before a new .gig file is to be created or to be loaded.
520  void MainWindow::__clear() {  void MainWindow::__clear() {
     // remove all entries from "Instrument" menu  
     Gtk::MenuItem* instrument_menu =  
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
     instrument_menu->hide();  
     Gtk::Menu* menu = instrument_menu->get_submenu();  
     while (menu->get_children().size()) {  
         Gtk::Widget* child = *menu->get_children().begin();  
         menu->remove(*child);  
         delete child;  
     }  
521      // forget all samples that ought to be imported      // forget all samples that ought to be imported
522      m_SampleImportQueue.clear();      m_SampleImportQueue.clear();
523      // clear the samples and instruments tree views      // clear the samples and instruments tree views
524      m_refTreeModel->clear();      m_refTreeModel->clear();
525      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
526        // remove all entries from "Instrument" menu
527        while (!instrument_menu->get_children().empty()) {
528            remove_instrument_from_menu(0);
529        }
530      // free libgig's gig::File instance      // free libgig's gig::File instance
531      if (file && !file_is_shared) delete file;      if (file && !file_is_shared) delete file;
532      file = NULL;      file = NULL;
# Line 571  void MainWindow::on_action_file_new() Line 545  void MainWindow::on_action_file_new()
545      gig::File* pFile = new gig::File;      gig::File* pFile = new gig::File;
546      // already add one new instrument by default      // already add one new instrument by default
547      gig::Instrument* pInstrument = pFile->AddInstrument();      gig::Instrument* pInstrument = pFile->AddInstrument();
548      pInstrument->pInfo->Name = _("Unnamed Instrument");      pInstrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument"));
549      // update GUI with that new gig::File      // update GUI with that new gig::File
550      load_gig(pFile, 0 /*no file name yet*/);      load_gig(pFile, 0 /*no file name yet*/);
551  }  }
# Line 904  void MainWindow::__import_queued_samples Line 878  void MainWindow::__import_queued_samples
878              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
879          } catch (std::string what) {          } catch (std::string what) {
880              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
881              if (error_files.size()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
882              error_files += (*iter).sample_path += " (" + what + ")";              error_files += (*iter).sample_path += " (" + what + ")";
883              ++iter;              ++iter;
884          }          }
885      }      }
886      // show error message box when some sample(s) could not be imported      // show error message box when some sample(s) could not be imported
887      if (error_files.size()) {      if (!error_files.empty()) {
888          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;          Glib::ustring txt = _("Could not import the following sample(s):\n") + error_files;
889          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
890          msg.run();          msg.run();
# Line 965  PropDialog::PropDialog() Line 939  PropDialog::PropDialog()
939        eCommissioned(_("Commissioned")),        eCommissioned(_("Commissioned")),
940        eSubject(_("Subject")),        eSubject(_("Subject")),
941        quitButton(Gtk::Stock::CLOSE),        quitButton(Gtk::Stock::CLOSE),
942        table(2, 1),        table(2, 1)
       update_model(0)  
943  {  {
944      set_title(_("File Properties"));      set_title(_("File Properties"));
945      eName.set_width_chars(50);      eName.set_width_chars(50);
# Line 1026  PropDialog::PropDialog() Line 999  PropDialog::PropDialog()
999    
1000  void PropDialog::set_info(DLS::Info* info)  void PropDialog::set_info(DLS::Info* info)
1001  {  {
1002      this->info = info;      update(info);
     update_model++;  
     eName.set_value(info->Name);  
     eCreationDate.set_value(info->CreationDate);  
     eComments.set_value(info->Comments);  
     eProduct.set_value(info->Product);  
     eCopyright.set_value(info->Copyright);  
     eArtists.set_value(info->Artists);  
     eGenre.set_value(info->Genre);  
     eKeywords.set_value(info->Keywords);  
     eEngineer.set_value(info->Engineer);  
     eTechnician.set_value(info->Technician);  
     eSoftware.set_value(info->Software);  
     eMedium.set_value(info->Medium);  
     eSource.set_value(info->Source);  
     eSourceForm.set_value(info->SourceForm);  
     eCommissioned.set_value(info->Commissioned);  
     eSubject.set_value(info->Subject);  
     update_model--;  
1003  }  }
1004    
 sigc::signal<void>& PropDialog::signal_info_changed()  
 {  
     return info_changed;  
 }  
1005    
1006  void InstrumentProps::set_IsDrum(bool value)  void InstrumentProps::set_Name(const gig::String& name)
1007  {  {
1008      instrument->IsDrum = value;      m->pInfo->Name = name;
1009  }  }
1010    
1011  void InstrumentProps::set_MIDIBank(uint16_t value)  void InstrumentProps::update_name()
1012  {  {
1013      instrument->MIDIBank = value;      update_model++;
1014        eName.set_value(m->pInfo->Name);
1015        update_model--;
1016  }  }
1017    
1018  void InstrumentProps::set_MIDIProgram(uint32_t value)  void InstrumentProps::set_IsDrum(bool value)
1019  {  {
1020      instrument->MIDIProgram = value;      m->IsDrum = value;
1021  }  }
1022    
1023  void InstrumentProps::set_DimensionKeyRange_low(uint8_t value)  void InstrumentProps::set_MIDIBank(uint16_t value)
1024  {  {
1025      instrument->DimensionKeyRange.low = value;      m->MIDIBank = value;
     if (value > instrument->DimensionKeyRange.high) {  
         eDimensionKeyRangeHigh.set_value(value);  
     }  
1026  }  }
1027    
1028  void InstrumentProps::set_DimensionKeyRange_high(uint8_t value)  void InstrumentProps::set_MIDIProgram(uint32_t value)
1029  {  {
1030      instrument->DimensionKeyRange.high = value;      m->MIDIProgram = value;
     if (value < instrument->DimensionKeyRange.low) {  
         eDimensionKeyRangeLow.set_value(value);  
     }  
1031  }  }
1032    
1033  InstrumentProps::InstrumentProps()  InstrumentProps::InstrumentProps() :
1034      : update_model(0),      quitButton(Gtk::Stock::CLOSE),
1035        quitButton(Gtk::Stock::CLOSE),      table(2,1),
1036        table(2,1),      eName(_("Name")),
1037        eName(_("Name")),      eIsDrum(_("Is drum")),
1038        eIsDrum(_("Is drum")),      eMIDIBank(_("MIDI bank"), 0, 16383),
1039        eMIDIBank(_("MIDI bank"), 0, 16383),      eMIDIProgram(_("MIDI program")),
1040        eMIDIProgram(_("MIDI program")),      eAttenuation(_("Attenuation"), 0, 96, 0, 1),
1041        eAttenuation(_("Attenuation"), 0, 96, 0, 1),      eGainPlus6(_("Gain +6dB"), eAttenuation, -6),
1042        eGainPlus6(_("Gain +6dB"), eAttenuation, -6),      eEffectSend(_("Effect send"), 0, 65535),
1043        eEffectSend(_("Effect send"), 0, 65535),      eFineTune(_("Fine tune"), -8400, 8400),
1044        eFineTune(_("Fine tune"), -8400, 8400),      ePitchbendRange(_("Pitchbend range"), 0, 12),
1045        ePitchbendRange(_("Pitchbend range"), 0, 12),      ePianoReleaseMode(_("Piano release mode")),
1046        ePianoReleaseMode(_("Piano release mode")),      eDimensionKeyRangeLow(_("Keyswitching range low")),
1047        eDimensionKeyRangeLow(_("Keyswitching range low")),      eDimensionKeyRangeHigh(_("Keyswitching range high"))
       eDimensionKeyRangeHigh(_("Keyswitching range high"))  
1048  {  {
1049      set_title(_("Instrument Properties"));      set_title(_("Instrument Properties"));
1050    
# Line 1111  InstrumentProps::InstrumentProps() Line 1057  InstrumentProps::InstrumentProps()
1057            "\"keyswitching\" dimension")            "\"keyswitching\" dimension")
1058      );      );
1059    
1060        connect(eName, &InstrumentProps::set_Name);
1061      connect(eIsDrum, &InstrumentProps::set_IsDrum);      connect(eIsDrum, &InstrumentProps::set_IsDrum);
1062      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);      connect(eMIDIBank, &InstrumentProps::set_MIDIBank);
1063      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);      connect(eMIDIProgram, &InstrumentProps::set_MIDIProgram);
# Line 1120  InstrumentProps::InstrumentProps() Line 1067  InstrumentProps::InstrumentProps()
1067      connect(eFineTune, &gig::Instrument::FineTune);      connect(eFineTune, &gig::Instrument::FineTune);
1068      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);      connect(ePitchbendRange, &gig::Instrument::PitchbendRange);
1069      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);      connect(ePianoReleaseMode, &gig::Instrument::PianoReleaseMode);
1070      connect(eDimensionKeyRangeLow,      connect(eDimensionKeyRangeLow, eDimensionKeyRangeHigh,
1071              &InstrumentProps::set_DimensionKeyRange_low);              &gig::Instrument::DimensionKeyRange);
1072      connect(eDimensionKeyRangeHigh,  
1073              &InstrumentProps::set_DimensionKeyRange_high);      eName.signal_value_changed().connect(sig_name_changed.make_slot());
1074    
1075      table.set_col_spacings(5);      table.set_col_spacings(5);
1076    
# Line 1162  InstrumentProps::InstrumentProps() Line 1109  InstrumentProps::InstrumentProps()
1109    
1110  void InstrumentProps::set_instrument(gig::Instrument* instrument)  void InstrumentProps::set_instrument(gig::Instrument* instrument)
1111  {  {
1112      this->instrument = instrument;      update(instrument);
1113    
1114      update_model++;      update_model++;
1115      eName.set_value(instrument->pInfo->Name);      eName.set_value(instrument->pInfo->Name);
1116      eIsDrum.set_value(instrument->IsDrum);      eIsDrum.set_value(instrument->IsDrum);
1117      eMIDIBank.set_value(instrument->MIDIBank);      eMIDIBank.set_value(instrument->MIDIBank);
1118      eMIDIProgram.set_value(instrument->MIDIProgram);      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);  
1119      update_model--;      update_model--;
1120  }  }
1121    
 sigc::signal<void>& InstrumentProps::signal_instrument_changed()  
 {  
     return instrument_changed;  
 }  
1122    
1123  void MainWindow::file_changed()  void MainWindow::file_changed()
1124  {  {
# Line 1205  void MainWindow::load_gig(gig::File* gig Line 1140  void MainWindow::load_gig(gig::File* gig
1140    
1141      propDialog.set_info(gig->pInfo);      propDialog.set_info(gig->pInfo);
1142    
1143      Gtk::MenuItem* instrument_menu =      instrument_name_connection.block();
         dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/MenuBar/MenuInstrument"));  
   
     int instrument_index = 0;  
     Gtk::RadioMenuItem::Group instrument_group;  
1144      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;      for (gig::Instrument* instrument = gig->GetFirstInstrument() ; instrument ;
1145           instrument = gig->GetNextInstrument()) {           instrument = gig->GetNextInstrument()) {
1146            Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1147    
1148          Gtk::TreeModel::iterator iter = m_refTreeModel->append();          Gtk::TreeModel::iterator iter = m_refTreeModel->append();
1149          Gtk::TreeModel::Row row = *iter;          Gtk::TreeModel::Row row = *iter;
1150          row[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();          row[m_Columns.m_col_name] = name;
1151          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
1152          // create a menu item for this instrument  
1153          Gtk::RadioMenuItem* item =          add_instrument_to_menu(name);
             new Gtk::RadioMenuItem(instrument_group, instrument->pInfo->Name.c_str());  
         instrument_menu->get_submenu()->append(*item);  
         item->signal_activate().connect(  
             sigc::bind(  
                 sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),  
                 instrument_index  
             )  
         );  
         instrument_index++;  
1154      }      }
1155      instrument_menu->show();      instrument_name_connection.unblock();
1156      instrument_menu->get_submenu()->show_all_children();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1157    
1158      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1159          if (group->Name != "") {          if (group->Name != "") {
1160              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1161              Gtk::TreeModel::Row rowGroup = *iterGroup;              Gtk::TreeModel::Row rowGroup = *iterGroup;
1162              rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();              rowGroup[m_SamplesModel.m_col_name]   = gig_to_utf8(group->Name);
1163              rowGroup[m_SamplesModel.m_col_group]  = group;              rowGroup[m_SamplesModel.m_col_group]  = group;
1164              rowGroup[m_SamplesModel.m_col_sample] = NULL;              rowGroup[m_SamplesModel.m_col_sample] = NULL;
1165              for (gig::Sample* sample = group->GetFirstSample();              for (gig::Sample* sample = group->GetFirstSample();
# Line 1243  void MainWindow::load_gig(gig::File* gig Line 1167  void MainWindow::load_gig(gig::File* gig
1167                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1168                      m_refSamplesTreeModel->append(rowGroup.children());                      m_refSamplesTreeModel->append(rowGroup.children());
1169                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1170                  rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();                  rowSample[m_SamplesModel.m_col_name] =
1171                        gig_to_utf8(sample->pInfo->Name);
1172                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1173                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1174              }              }
# Line 1253  void MainWindow::load_gig(gig::File* gig Line 1178  void MainWindow::load_gig(gig::File* gig
1178      file = gig;      file = gig;
1179    
1180      // select the first instrument      // select the first instrument
1181      Glib::RefPtr<Gtk::TreeSelection> tree_sel_ref = m_TreeView.get_selection();      m_TreeView.get_selection()->select(Gtk::TreePath("0"));
1182      tree_sel_ref->select(Gtk::TreePath("0"));  
1183        instr_props_set_instrument();
1184  }  }
1185    
1186  void MainWindow::show_instr_props()  bool MainWindow::instr_props_set_instrument()
1187  {  {
1188      gig::Instrument* instrument = get_instrument();      instrumentProps.signal_name_changed().clear();
1189      if (instrument)  
1190      {      Gtk::TreeModel::const_iterator it =
1191            m_TreeView.get_selection()->get_selected();
1192        if (it) {
1193            Gtk::TreeModel::Row row = *it;
1194            gig::Instrument* instrument = row[m_Columns.m_col_instr];
1195    
1196          instrumentProps.set_instrument(instrument);          instrumentProps.set_instrument(instrument);
1197    
1198            // make sure instrument tree is updated when user changes the
1199            // instrument name in instrument properties window
1200            instrumentProps.signal_name_changed().connect(
1201                sigc::bind(
1202                    sigc::mem_fun(*this,
1203                                  &MainWindow::instr_name_changed_by_instr_props),
1204                    it));
1205        } else {
1206            instrumentProps.hide();
1207        }
1208        return it;
1209    }
1210    
1211    void MainWindow::show_instr_props()
1212    {
1213        if (instr_props_set_instrument()) {
1214          instrumentProps.show();          instrumentProps.show();
1215          instrumentProps.deiconify();          instrumentProps.deiconify();
1216      }      }
1217  }  }
1218    
1219    void MainWindow::instr_name_changed_by_instr_props(Gtk::TreeModel::iterator& it)
1220    {
1221        Gtk::TreeModel::Row row = *it;
1222        Glib::ustring name = row[m_Columns.m_col_name];
1223    
1224        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1225        Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
1226        if (gigname != name) {
1227            row[m_Columns.m_col_name] = gigname;
1228        }
1229    }
1230    
1231  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1232      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1233          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1288  void MainWindow::on_button_release(GdkEv Line 1248  void MainWindow::on_button_release(GdkEv
1248      }      }
1249  }  }
1250    
1251  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(Gtk::RadioMenuItem* item) {
1252      m_RegionChooser.set_instrument(file->GetInstrument(index));      if (item->get_active()) {
1253            const std::vector<Gtk::Widget*> children =
1254                instrument_menu->get_children();
1255            std::vector<Gtk::Widget*>::const_iterator it =
1256                find(children.begin(), children.end(), item);
1257            if (it != children.end()) {
1258                int index = it - children.begin();
1259                m_TreeView.get_selection()->select(Gtk::TreePath(ToString(index)));
1260    
1261                m_RegionChooser.set_instrument(file->GetInstrument(index));
1262            }
1263        }
1264  }  }
1265    
1266  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {  void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
# Line 1319  void MainWindow::on_sample_treeview_butt Line 1290  void MainWindow::on_sample_treeview_butt
1290      }      }
1291  }  }
1292    
1293  void MainWindow::on_action_add_instrument() {  
1294      static int __instrument_indexer = 0;  Gtk::RadioMenuItem* MainWindow::add_instrument_to_menu(
1295      if (!file) return;      const Glib::ustring& name, int position) {
1296      gig::Instrument* instrument = file->AddInstrument();  
1297      __instrument_indexer++;      Gtk::RadioMenuItem::Group instrument_group;
1298      instrument->pInfo->Name =      const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1299          _("Unnamed Instrument ") + ToString(__instrument_indexer);      if (!children.empty()) {
1300            instrument_group =
1301                static_cast<Gtk::RadioMenuItem*>(children[0])->get_group();
1302        }
1303        Gtk::RadioMenuItem* item =
1304            new Gtk::RadioMenuItem(instrument_group, name);
1305        if (position < 0) {
1306            instrument_menu->append(*item);
1307        } else {
1308            instrument_menu->insert(*item, position);
1309        }
1310        item->show();
1311        item->signal_activate().connect(
1312            sigc::bind(
1313                sigc::mem_fun(*this, &MainWindow::on_instrument_selection_change),
1314                item));
1315        return item;
1316    }
1317    
1318    void MainWindow::remove_instrument_from_menu(int index) {
1319        const std::vector<Gtk::Widget*> children =
1320            instrument_menu->get_children();
1321        Gtk::Widget* child = children[index];
1322        instrument_menu->remove(*child);
1323        delete child;
1324    }
1325    
1326    void MainWindow::add_instrument(gig::Instrument* instrument) {
1327        const Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
1328    
1329      // update instrument tree view      // update instrument tree view
1330        instrument_name_connection.block();
1331      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
1332      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
1333      rowInstr[m_Columns.m_col_name] = instrument->pInfo->Name.c_str();      rowInstr[m_Columns.m_col_name] = name;
1334      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
1335        instrument_name_connection.unblock();
1336    
1337        add_instrument_to_menu(name);
1338    
1339        m_TreeView.get_selection()->select(iterInstr);
1340    
1341      file_changed();      file_changed();
1342  }  }
1343    
1344    void MainWindow::on_action_add_instrument() {
1345        static int __instrument_indexer = 0;
1346        if (!file) return;
1347        gig::Instrument* instrument = file->AddInstrument();
1348        __instrument_indexer++;
1349        instrument->pInfo->Name = gig_from_utf8(_("Unnamed Instrument ") +
1350                                                ToString(__instrument_indexer));
1351    
1352        add_instrument(instrument);
1353    }
1354    
1355  void MainWindow::on_action_duplicate_instrument() {  void MainWindow::on_action_duplicate_instrument() {
1356      if (!file) return;      if (!file) return;
1357        
1358      // retrieve the currently selected instrument      // retrieve the currently selected instrument
1359      // (being the original instrument to be duplicated)      // (being the original instrument to be duplicated)
1360      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();      Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
# Line 1345  void MainWindow::on_action_duplicate_ins Line 1363  void MainWindow::on_action_duplicate_ins
1363      Gtk::TreeModel::Row row = *itSelection;      Gtk::TreeModel::Row row = *itSelection;
1364      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];      gig::Instrument* instrOrig = row[m_Columns.m_col_instr];
1365      if (!instrOrig) return;      if (!instrOrig) return;
1366        
1367      // duplicate the orginal instrument      // duplicate the orginal instrument
1368      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);      gig::Instrument* instrNew = file->AddDuplicateInstrument(instrOrig);
1369      instrNew->pInfo->Name =      instrNew->pInfo->Name =
1370          instrOrig->pInfo->Name + " (" + _("Copy") + ")";          instrOrig->pInfo->Name +
1371                    gig_from_utf8(Glib::ustring(" (") + _("Copy") + ")");
1372      // update instrument tree view  
1373      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      add_instrument(instrNew);
     Gtk::TreeModel::Row rowInstr = *iterInstr;  
     rowInstr[m_Columns.m_col_name] = instrNew->pInfo->Name.c_str();  
     rowInstr[m_Columns.m_col_instr] = instrNew;  
     file_changed();  
1374  }  }
1375    
1376  void MainWindow::on_action_remove_instrument() {  void MainWindow::on_action_remove_instrument() {
# Line 1378  void MainWindow::on_action_remove_instru Line 1392  void MainWindow::on_action_remove_instru
1392          Gtk::TreeModel::Row row = *it;          Gtk::TreeModel::Row row = *it;
1393          gig::Instrument* instr = row[m_Columns.m_col_instr];          gig::Instrument* instr = row[m_Columns.m_col_instr];
1394          try {          try {
1395                Gtk::TreePath path(it);
1396                int index = path[0];
1397    
1398              // remove instrument from the gig file              // remove instrument from the gig file
1399              if (instr) file->DeleteInstrument(instr);              if (instr) file->DeleteInstrument(instr);
             // remove respective row from instruments tree view  
             m_refTreeModel->erase(it);  
1400              file_changed();              file_changed();
1401    
1402                remove_instrument_from_menu(index);
1403    
1404                // remove row from instruments tree view
1405                m_refTreeModel->erase(it);
1406    
1407    #if GTKMM_MAJOR_VERSION < 3
1408                // select another instrument (in gtk3 this is done
1409                // automatically)
1410                if (!m_refTreeModel->children().empty()) {
1411                    if (index == m_refTreeModel->children().size()) {
1412                        index--;
1413                    }
1414                    m_TreeView.get_selection()->select(
1415                        Gtk::TreePath(ToString(index)));
1416                }
1417    #endif
1418                instr_props_set_instrument();
1419          } catch (RIFF::Exception e) {          } catch (RIFF::Exception e) {
1420              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1421              msg.run();              msg.run();
# Line 1402  void MainWindow::on_action_add_group() { Line 1435  void MainWindow::on_action_add_group() {
1435      static int __sample_indexer = 0;      static int __sample_indexer = 0;
1436      if (!file) return;      if (!file) return;
1437      gig::Group* group = file->AddGroup();      gig::Group* group = file->AddGroup();
1438      group->Name = _("Unnamed Group");      group->Name = gig_from_utf8(_("Unnamed Group"));
1439      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);      if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1440      __sample_indexer++;      __sample_indexer++;
1441      // update sample tree view      // update sample tree view
1442      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();      Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1443      Gtk::TreeModel::Row rowGroup = *iterGroup;      Gtk::TreeModel::Row rowGroup = *iterGroup;
1444      rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();      rowGroup[m_SamplesModel.m_col_name] = gig_to_utf8(group->Name);
1445      rowGroup[m_SamplesModel.m_col_sample] = NULL;      rowGroup[m_SamplesModel.m_col_sample] = NULL;
1446      rowGroup[m_SamplesModel.m_col_group] = group;      rowGroup[m_SamplesModel.m_col_group] = group;
1447      file_changed();      file_changed();
# Line 1517  void MainWindow::on_action_add_sample() Line 1550  void MainWindow::on_action_add_sample()
1550                          break;                          break;
1551                      }                      }
1552                  }                  }
1553                  sample->pInfo->Name = filename;                  sample->pInfo->Name = gig_from_utf8(filename);
1554                  sample->Channels = info.channels;                  sample->Channels = info.channels;
1555                  sample->BitDepth = bitdepth;                  sample->BitDepth = bitdepth;
1556                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;                  sample->FrameSize = bitdepth / 8/*1 byte are 8 bits*/ * info.channels;
# Line 1568  void MainWindow::on_action_add_sample() Line 1601  void MainWindow::on_action_add_sample()
1601                  Gtk::TreeModel::iterator iterSample =                  Gtk::TreeModel::iterator iterSample =
1602                      m_refSamplesTreeModel->append(row.children());                      m_refSamplesTreeModel->append(row.children());
1603                  Gtk::TreeModel::Row rowSample = *iterSample;                  Gtk::TreeModel::Row rowSample = *iterSample;
1604                  rowSample[m_SamplesModel.m_col_name]   = filename;                  rowSample[m_SamplesModel.m_col_name] =
1605                        gig_to_utf8(sample->pInfo->Name);
1606                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1607                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1608                  // close sound file                  // close sound file
1609                  sf_close(hFile);                  sf_close(hFile);
1610                  file_changed();                  file_changed();
1611              } catch (std::string what) { // remember the files that made trouble (and their cause)              } catch (std::string what) { // remember the files that made trouble (and their cause)
1612                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1613                  error_files += *iter += " (" + what + ")";                  error_files += *iter += " (" + what + ")";
1614              }              }
1615          }          }
1616          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
1617          if (error_files.size()) {          if (!error_files.empty()) {
1618              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;              Glib::ustring txt = _("Could not add the following sample(s):\n") + error_files;
1619              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
1620              msg.run();              msg.run();
# Line 1593  void MainWindow::on_action_replace_all_s Line 1627  void MainWindow::on_action_replace_all_s
1627      if (!file) return;      if (!file) return;
1628      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),      Gtk::FileChooserDialog dialog(*this, _("Select Folder"),
1629                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);                                    Gtk::FILE_CHOOSER_ACTION_SELECT_FOLDER);
1630      const char* str =      const char* str =
1631          _("This is a very specific function. It tries to replace all samples "          _("This is a very specific function. It tries to replace all samples "
1632            "in the current gig file by samples located in the chosen "            "in the current gig file by samples located in the chosen "
1633            "directory.\n\n"            "directory.\n\n"
# Line 1639  void MainWindow::on_action_replace_all_s Line 1673  void MainWindow::on_action_replace_all_s
1673               sample; sample = file->GetNextSample())               sample; sample = file->GetNextSample())
1674          {          {
1675              std::string filename =              std::string filename =
1676                  folder + G_DIR_SEPARATOR_S + sample->pInfo->Name +                  folder + G_DIR_SEPARATOR_S +
1677                  postfixEntryBox.get_text().raw();                  Glib::filename_from_utf8(gig_to_utf8(sample->pInfo->Name) +
1678                                             postfixEntryBox.get_text());
1679              SF_INFO info;              SF_INFO info;
1680              info.format = 0;              info.format = 0;
1681              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);              SNDFILE* hFile = sf_open(filename.c_str(), SFM_READ, &info);
# Line 1673  void MainWindow::on_action_replace_all_s Line 1708  void MainWindow::on_action_replace_all_s
1708              }              }
1709              catch (std::string what)              catch (std::string what)
1710              {              {
1711                  if (error_files.size()) error_files += "\n";                  if (!error_files.empty()) error_files += "\n";
1712                      error_files += filename += " (" + what + ")";                  error_files += Glib::filename_to_utf8(filename) +
1713                        " (" + what + ")";
1714              }              }
1715          }          }
1716          // show error message box when some file(s) could not be opened / added          // show error message box when some file(s) could not be opened / added
1717          if (error_files.size()) {          if (!error_files.empty()) {
1718              Glib::ustring txt =              Glib::ustring txt =
1719                  _("Could not replace the following sample(s):\n") + error_files;                  _("Could not replace the following sample(s):\n") + error_files;
1720              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);              Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
# Line 1699  void MainWindow::on_action_remove_sample Line 1735  void MainWindow::on_action_remove_sample
1735          try {          try {
1736              // remove group or sample from the gig file              // remove group or sample from the gig file
1737              if (group) {              if (group) {
1738                  // temporarily remember the samples that bolong to                  // temporarily remember the samples that belong to
1739                  // that group (we need that to clean the queue)                  // that group (we need that to clean the queue)
1740                  std::list<gig::Sample*> members;                  std::list<gig::Sample*> members;
1741                  for (gig::Sample* pSample = group->GetFirstSample();                  for (gig::Sample* pSample = group->GetFirstSample();
# Line 1868  void MainWindow::sample_name_changed(con Line 1904  void MainWindow::sample_name_changed(con
1904      Glib::ustring name  = row[m_SamplesModel.m_col_name];      Glib::ustring name  = row[m_SamplesModel.m_col_name];
1905      gig::Group* group   = row[m_SamplesModel.m_col_group];      gig::Group* group   = row[m_SamplesModel.m_col_group];
1906      gig::Sample* sample = row[m_SamplesModel.m_col_sample];      gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1907        gig::String gigname(gig_from_utf8(name));
1908      if (group) {      if (group) {
1909          if (group->Name != name) {          if (group->Name != gigname) {
1910              group->Name = name;              group->Name = gigname;
1911              printf("group name changed\n");              printf("group name changed\n");
1912              file_changed();              file_changed();
1913          }          }
1914      } else if (sample) {      } else if (sample) {
1915          if (sample->pInfo->Name != name.raw()) {          if (sample->pInfo->Name != gigname) {
1916              sample->pInfo->Name = name.raw();              sample->pInfo->Name = gigname;
1917              printf("sample name changed\n");              printf("sample name changed\n");
1918              file_changed();              file_changed();
1919          }          }
# Line 1888  void MainWindow::instrument_name_changed Line 1925  void MainWindow::instrument_name_changed
1925      if (!iter) return;      if (!iter) return;
1926      Gtk::TreeModel::Row row = *iter;      Gtk::TreeModel::Row row = *iter;
1927      Glib::ustring name = row[m_Columns.m_col_name];      Glib::ustring name = row[m_Columns.m_col_name];
1928    
1929        // change name in instrument menu
1930        int index = path[0];
1931        const std::vector<Gtk::Widget*> children = instrument_menu->get_children();
1932        if (index < children.size()) {
1933    #if (GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 16) || GTKMM_MAJOR_VERSION > 2
1934            static_cast<Gtk::RadioMenuItem*>(children[index])->set_label(name);
1935    #else
1936            remove_instrument_from_menu(index);
1937            Gtk::RadioMenuItem* item = add_instrument_to_menu(name, index);
1938            item->set_active();
1939    #endif
1940        }
1941    
1942        // change name in gig
1943      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
1944      if (instrument && instrument->pInfo->Name != name.raw()) {      gig::String gigname(gig_from_utf8(name));
1945          instrument->pInfo->Name = name.raw();      if (instrument && instrument->pInfo->Name != gigname) {
1946            instrument->pInfo->Name = gigname;
1947    
1948            // change name in the instrument properties window
1949            if (instrumentProps.get_instrument() == instrument) {
1950                instrumentProps.update_name();
1951            }
1952    
1953          file_changed();          file_changed();
1954      }      }
1955  }  }

Legend:
Removed from v.2398  
changed lines
  Added in v.2446

  ViewVC Help
Powered by ViewVC