/[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 2604 by schoenebeck, Sat Jun 7 22:34:31 2014 UTC revision 2624 by schoenebeck, Wed Jun 11 20:26:26 2014 UTC
# Line 46  Line 46 
46  #include "Settings.h"  #include "Settings.h"
47  #include "CombineInstrumentsDialog.h"  #include "CombineInstrumentsDialog.h"
48  #include "scripteditor.h"  #include "scripteditor.h"
49    #include "scriptslots.h"
50    #include "ReferencesView.h"
51  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
52  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
53    
# Line 134  MainWindow::MainWindow() : Line 136  MainWindow::MainWindow() :
136                       sigc::mem_fun(                       sigc::mem_fun(
137                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
138      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
139                                           _("_Midi Rules")),                                           _("_Midi Rules...")),
140                       sigc::mem_fun(                       sigc::mem_fun(
141                           *this, &MainWindow::show_midi_rules));                           *this, &MainWindow::show_midi_rules));
142        actionGroup->add(Gtk::Action::create("ScriptSlots",
143                                             _("_Script Slots...")),
144                         sigc::mem_fun(
145                             *this, &MainWindow::show_script_slots));
146      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
147                       sigc::mem_fun(                       sigc::mem_fun(
148                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
# Line 231  MainWindow::MainWindow() : Line 237  MainWindow::MainWindow() :
237          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)          sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
238      );      );
239      actionGroup->add(      actionGroup->add(
240            Gtk::Action::create("ShowSampleRefs", _("Show References...")),
241            sigc::mem_fun(*this, &MainWindow::on_action_view_references)
242        );
243        actionGroup->add(
244          Gtk::Action::create("ReplaceAllSamplesInAllGroups",          Gtk::Action::create("ReplaceAllSamplesInAllGroups",
245                              _("Replace All Samples in All Groups...")),                              _("Replace All Samples in All Groups...")),
246          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)          sigc::mem_fun(*this, &MainWindow::on_action_replace_all_samples_in_all_groups)
# Line 296  MainWindow::MainWindow() : Line 306  MainWindow::MainWindow() :
306          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
307          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
308          "    <menuitem action='MidiRules'/>"          "    <menuitem action='MidiRules'/>"
309            "    <menuitem action='ScriptSlots'/>"
310          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
311          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
312          "    <separator/>"          "    <separator/>"
# Line 305  MainWindow::MainWindow() : Line 316  MainWindow::MainWindow() :
316          "    <menuitem action='SampleProperties'/>"          "    <menuitem action='SampleProperties'/>"
317          "    <menuitem action='AddGroup'/>"          "    <menuitem action='AddGroup'/>"
318          "    <menuitem action='AddSample'/>"          "    <menuitem action='AddSample'/>"
319            "    <menuitem action='ShowSampleRefs'/>"
320          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"          "    <menuitem action='ReplaceAllSamplesInAllGroups' />"
321          "    <separator/>"          "    <separator/>"
322          "    <menuitem action='RemoveSample'/>"          "    <menuitem action='RemoveSample'/>"
# Line 398  MainWindow::MainWindow() : Line 410  MainWindow::MainWindow() :
410      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
411      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));      m_TreeViewSamples.set_tooltip_text(_("To actually use a sample, drag it from this list view to \"Sample\" -> \"Sample:\" on the region's settings pane on the right.\n\nRight click here for more actions on samples."));
412      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
413      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
414      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
415        {
416            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
417            Gtk::CellRendererText* cellrenderer =
418                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
419            column->add_attribute(
420                cellrenderer->property_foreground(), m_SamplesModel.m_color
421            );
422        }
423        {
424            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
425            Gtk::CellRendererText* cellrenderer =
426                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
427            column->add_attribute(
428                cellrenderer->property_foreground(), m_SamplesModel.m_color
429            );
430        }
431        m_TreeViewSamples.set_headers_visible(true);
432      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
433          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
434      );      );
# Line 424  MainWindow::MainWindow() : Line 453  MainWindow::MainWindow() :
453          sigc::mem_fun(*this, &MainWindow::script_name_changed)          sigc::mem_fun(*this, &MainWindow::script_name_changed)
454      );      );
455    
456        // establish drag&drop between scripts tree view and ScriptSlots window
457        std::vector<Gtk::TargetEntry> drag_target_gig_script;
458        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
459        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
460        m_TreeViewScripts.signal_drag_begin().connect(
461            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
462        );
463        m_TreeViewScripts.signal_drag_data_get().connect(
464            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
465        );
466    
467      // establish drag&drop between samples tree view and dimension region 'Sample' text entry      // establish drag&drop between samples tree view and dimension region 'Sample' text entry
468      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
469      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));      drag_target_gig_sample.push_back(Gtk::TargetEntry("gig::Sample"));
# Line 457  MainWindow::MainWindow() : Line 497  MainWindow::MainWindow() :
497          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
498      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
499          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
500        sample_ref_changed_signal.connect(
501            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
502        );
503        samples_to_be_removed_signal.connect(
504            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
505        );
506    
507      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
508          sigc::hide(          sigc::hide(
# Line 680  void MainWindow::__clear() { Line 726  void MainWindow::__clear() {
726      // clear the samples and instruments tree views      // clear the samples and instruments tree views
727      m_refTreeModel->clear();      m_refTreeModel->clear();
728      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
729        m_refScriptsTreeModel->clear();
730      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
731      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
732          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 694  void MainWindow::__refreshEntireGUI() { Line 741  void MainWindow::__refreshEntireGUI() {
741      // clear the samples and instruments tree views      // clear the samples and instruments tree views
742      m_refTreeModel->clear();      m_refTreeModel->clear();
743      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
744        m_refScriptsTreeModel->clear();
745      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
746      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
747          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 1341  void MainWindow::file_changed() Line 1389  void MainWindow::file_changed()
1389      }      }
1390  }  }
1391    
1392    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1393        sample_ref_count.clear();
1394        
1395        if (!gig) return;
1396    
1397        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1398             instrument = gig->GetNextInstrument())
1399        {
1400            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1401                 rgn = instrument->GetNextRegion())
1402            {
1403                for (int i = 0; i < 256; ++i) {
1404                    if (!rgn->pDimensionRegions[i]) continue;
1405                    if (rgn->pDimensionRegions[i]->pSample) {
1406                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1407                    }
1408                }
1409            }
1410        }
1411    }
1412    
1413  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1414  {  {
1415      file = 0;      file = 0;
# Line 1369  void MainWindow::load_gig(gig::File* gig Line 1438  void MainWindow::load_gig(gig::File* gig
1438      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1439      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1440    
1441        updateSampleRefCountMap(gig);
1442    
1443      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1444          if (group->Name != "") {          if (group->Name != "") {
1445              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
# Line 1385  void MainWindow::load_gig(gig::File* gig Line 1456  void MainWindow::load_gig(gig::File* gig
1456                      gig_to_utf8(sample->pInfo->Name);                      gig_to_utf8(sample->pInfo->Name);
1457                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1458                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1459                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1460                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1461                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
1462              }              }
1463          }          }
1464      }      }
# Line 1408  void MainWindow::load_gig(gig::File* gig Line 1482  void MainWindow::load_gig(gig::File* gig
1482              rowScript[m_ScriptsModel.m_col_group]  = NULL;              rowScript[m_ScriptsModel.m_col_group]  = NULL;
1483          }          }
1484      }      }
1485      // unfold all script groups by default      // unfold all sample groups & script groups by default
1486        m_TreeViewSamples.expand_all();
1487      m_TreeViewScripts.expand_all();      m_TreeViewScripts.expand_all();
1488    
1489      file = gig;      file = gig;
# Line 1478  void MainWindow::show_midi_rules() Line 1553  void MainWindow::show_midi_rules()
1553      }      }
1554  }  }
1555    
1556    void MainWindow::show_script_slots() {
1557        if (!file) return;
1558        // get selected instrument
1559        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1560        Gtk::TreeModel::iterator it = sel->get_selected();
1561        if (!it) return;
1562        Gtk::TreeModel::Row row = *it;
1563        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1564        if (!instrument) return;
1565    
1566        ScriptSlots* window = new ScriptSlots;
1567        window->setInstrument(instrument);
1568        //window->reparent(*this);
1569        window->show();
1570    }
1571    
1572  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1573      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1574          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 1567  void MainWindow::on_sample_treeview_butt Line 1658  void MainWindow::on_sample_treeview_butt
1658              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1659          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->
1660              set_sensitive(file);              set_sensitive(file);
1661            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/ShowSampleRefs"))->
1662                set_sensitive(sample_selected);
1663          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->          dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->
1664              set_sensitive(group_selected || sample_selected);              set_sensitive(group_selected || sample_selected);
1665          // show sample popup          // show sample popup
# Line 2228  void MainWindow::on_action_remove_sample Line 2321  void MainWindow::on_action_remove_sample
2321      }      }
2322  }  }
2323    
2324    // see comment on on_sample_treeview_drag_begin()
2325    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2326    {
2327        first_call_to_drag_data_get = true;
2328    }
2329    
2330    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2331                                                       Gtk::SelectionData& selection_data, guint, guint)
2332    {
2333        if (!first_call_to_drag_data_get) return;
2334        first_call_to_drag_data_get = false;
2335    
2336        // get selected script
2337        gig::Script* script = NULL;
2338        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2339        Gtk::TreeModel::iterator it = sel->get_selected();
2340        if (it) {
2341            Gtk::TreeModel::Row row = *it;
2342            script = row[m_ScriptsModel.m_col_script];
2343        }
2344        // pass the gig::Script as pointer
2345        selection_data.set(selection_data.get_target(), 0/*unused*/,
2346                           (const guchar*)&script,
2347                           sizeof(script)/*length of data in bytes*/);
2348    }
2349    
2350  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2351  // 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
2352  // 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 2425  void MainWindow::on_action_combine_instr Line 2544  void MainWindow::on_action_combine_instr
2544      delete d;      delete d;
2545  }  }
2546    
2547    void MainWindow::on_action_view_references() {
2548        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
2549        Gtk::TreeModel::iterator it = sel->get_selected();
2550        if (!it) return;
2551        Gtk::TreeModel::Row row = *it;
2552        gig::Sample* sample = row[m_SamplesModel.m_col_sample];
2553        if (!sample) return;
2554    
2555        ReferencesView* d = new ReferencesView(*this);
2556        d->setSample(sample);
2557        d->show_all();
2558        d->resize(500, 400);
2559        d->run();
2560        delete d;
2561    }
2562    
2563  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {  void MainWindow::mergeFiles(const std::vector<std::string>& filenames) {
2564      struct _Source {      struct _Source {
2565          std::vector<RIFF::File*> riffs;          std::vector<RIFF::File*> riffs;
# Line 2585  void MainWindow::set_file_is_shared(bool Line 2720  void MainWindow::set_file_is_shared(bool
2720      }      }
2721  }  }
2722    
2723    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2724        if (!sample) return;
2725        sample_ref_count[sample] += offset;
2726        const int refcount = sample_ref_count[sample];
2727    
2728        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2729        for (int g = 0; g < model->children().size(); ++g) {
2730            Gtk::TreeModel::Row rowGroup = model->children()[g];
2731            for (int s = 0; s < rowGroup.children().size(); ++s) {
2732                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2733                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2734                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2735                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
2736            }
2737        }
2738    }
2739    
2740    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2741        on_sample_ref_count_incremented(oldSample, -1);
2742        on_sample_ref_count_incremented(newSample, +1);
2743    }
2744    
2745    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2746        // just in case a new sample is added later with exactly the same memory
2747        // address, which would lead to incorrect refcount if not deleted here
2748        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2749             it != samples.end(); it != samples.end())
2750        {
2751            sample_ref_count.erase(*it);
2752        }
2753    }
2754    
2755  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2756      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2757  }  }

Legend:
Removed from v.2604  
changed lines
  Added in v.2624

  ViewVC Help
Powered by ViewVC