/[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 2621 by schoenebeck, Wed Jun 11 16:46:27 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 "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
51  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
52    
# Line 134  MainWindow::MainWindow() : Line 135  MainWindow::MainWindow() :
135                       sigc::mem_fun(                       sigc::mem_fun(
136                           *this, &MainWindow::show_instr_props));                           *this, &MainWindow::show_instr_props));
137      actionGroup->add(Gtk::Action::create("MidiRules",      actionGroup->add(Gtk::Action::create("MidiRules",
138                                           _("_Midi Rules")),                                           _("_Midi Rules...")),
139                       sigc::mem_fun(                       sigc::mem_fun(
140                           *this, &MainWindow::show_midi_rules));                           *this, &MainWindow::show_midi_rules));
141        actionGroup->add(Gtk::Action::create("ScriptSlots",
142                                             _("_Script Slots...")),
143                         sigc::mem_fun(
144                             *this, &MainWindow::show_script_slots));
145      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),      actionGroup->add(Gtk::Action::create("Quit", Gtk::Stock::QUIT),
146                       sigc::mem_fun(                       sigc::mem_fun(
147                           *this, &MainWindow::on_action_quit));                           *this, &MainWindow::on_action_quit));
# Line 296  MainWindow::MainWindow() : Line 301  MainWindow::MainWindow() :
301          "  <popup name='PopupMenu'>"          "  <popup name='PopupMenu'>"
302          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
303          "    <menuitem action='MidiRules'/>"          "    <menuitem action='MidiRules'/>"
304            "    <menuitem action='ScriptSlots'/>"
305          "    <menuitem action='AddInstrument'/>"          "    <menuitem action='AddInstrument'/>"
306          "    <menuitem action='DupInstrument'/>"          "    <menuitem action='DupInstrument'/>"
307          "    <separator/>"          "    <separator/>"
# Line 398  MainWindow::MainWindow() : Line 404  MainWindow::MainWindow() :
404      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
405      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."));
406      // m_TreeViewSamples.set_reorderable();      // m_TreeViewSamples.set_reorderable();
407      m_TreeViewSamples.append_column_editable("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column_editable(_("Name"), m_SamplesModel.m_col_name);
408      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.append_column(_("Referenced"), m_SamplesModel.m_col_refcount);
409        {
410            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(0);
411            Gtk::CellRendererText* cellrenderer =
412                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
413            column->add_attribute(
414                cellrenderer->property_foreground(), m_SamplesModel.m_color
415            );
416        }
417        {
418            Gtk::TreeViewColumn* column = m_TreeViewSamples.get_column(1);
419            Gtk::CellRendererText* cellrenderer =
420                dynamic_cast<Gtk::CellRendererText*>(column->get_first_cell_renderer());
421            column->add_attribute(
422                cellrenderer->property_foreground(), m_SamplesModel.m_color
423            );
424        }
425        m_TreeViewSamples.set_headers_visible(true);
426      m_TreeViewSamples.signal_button_press_event().connect_notify(      m_TreeViewSamples.signal_button_press_event().connect_notify(
427          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)          sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
428      );      );
# Line 424  MainWindow::MainWindow() : Line 447  MainWindow::MainWindow() :
447          sigc::mem_fun(*this, &MainWindow::script_name_changed)          sigc::mem_fun(*this, &MainWindow::script_name_changed)
448      );      );
449    
450        // establish drag&drop between scripts tree view and ScriptSlots window
451        std::vector<Gtk::TargetEntry> drag_target_gig_script;
452        drag_target_gig_script.push_back(Gtk::TargetEntry("gig::Script"));
453        m_TreeViewScripts.drag_source_set(drag_target_gig_script);
454        m_TreeViewScripts.signal_drag_begin().connect(
455            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_begin)
456        );
457        m_TreeViewScripts.signal_drag_data_get().connect(
458            sigc::mem_fun(*this, &MainWindow::on_scripts_treeview_drag_data_get)
459        );
460    
461      // 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
462      std::vector<Gtk::TargetEntry> drag_target_gig_sample;      std::vector<Gtk::TargetEntry> drag_target_gig_sample;
463      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 491  MainWindow::MainWindow() :
491          dimreg_changed_signal.make_slot());          dimreg_changed_signal.make_slot());
492      dimreg_edit.signal_sample_ref_changed().connect(      dimreg_edit.signal_sample_ref_changed().connect(
493          sample_ref_changed_signal.make_slot());          sample_ref_changed_signal.make_slot());
494        sample_ref_changed_signal.connect(
495            sigc::mem_fun(*this, &MainWindow::on_sample_ref_changed)
496        );
497        samples_to_be_removed_signal.connect(
498            sigc::mem_fun(*this, &MainWindow::on_samples_to_be_removed)
499        );
500    
501      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(      m_RegionChooser.signal_instrument_struct_to_be_changed().connect(
502          sigc::hide(          sigc::hide(
# Line 680  void MainWindow::__clear() { Line 720  void MainWindow::__clear() {
720      // clear the samples and instruments tree views      // clear the samples and instruments tree views
721      m_refTreeModel->clear();      m_refTreeModel->clear();
722      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
723        m_refScriptsTreeModel->clear();
724      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
725      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
726          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 694  void MainWindow::__refreshEntireGUI() { Line 735  void MainWindow::__refreshEntireGUI() {
735      // clear the samples and instruments tree views      // clear the samples and instruments tree views
736      m_refTreeModel->clear();      m_refTreeModel->clear();
737      m_refSamplesTreeModel->clear();      m_refSamplesTreeModel->clear();
738        m_refScriptsTreeModel->clear();
739      // remove all entries from "Instrument" menu      // remove all entries from "Instrument" menu
740      while (!instrument_menu->get_children().empty()) {      while (!instrument_menu->get_children().empty()) {
741          remove_instrument_from_menu(0);          remove_instrument_from_menu(0);
# Line 1341  void MainWindow::file_changed() Line 1383  void MainWindow::file_changed()
1383      }      }
1384  }  }
1385    
1386    void MainWindow::updateSampleRefCountMap(gig::File* gig) {
1387        sample_ref_count.clear();
1388        
1389        if (!gig) return;
1390    
1391        for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
1392             instrument = gig->GetNextInstrument())
1393        {
1394            for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
1395                 rgn = instrument->GetNextRegion())
1396            {
1397                for (int i = 0; i < 256; ++i) {
1398                    if (!rgn->pDimensionRegions[i]) continue;
1399                    if (rgn->pDimensionRegions[i]->pSample) {
1400                        sample_ref_count[rgn->pDimensionRegions[i]->pSample]++;
1401                    }
1402                }
1403            }
1404        }
1405    }
1406    
1407  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
1408  {  {
1409      file = 0;      file = 0;
# Line 1369  void MainWindow::load_gig(gig::File* gig Line 1432  void MainWindow::load_gig(gig::File* gig
1432      instrument_name_connection.unblock();      instrument_name_connection.unblock();
1433      uiManager->get_widget("/MenuBar/MenuInstrument")->show();      uiManager->get_widget("/MenuBar/MenuInstrument")->show();
1434    
1435        updateSampleRefCountMap(gig);
1436    
1437      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {      for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1438          if (group->Name != "") {          if (group->Name != "") {
1439              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();              Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
# Line 1385  void MainWindow::load_gig(gig::File* gig Line 1450  void MainWindow::load_gig(gig::File* gig
1450                      gig_to_utf8(sample->pInfo->Name);                      gig_to_utf8(sample->pInfo->Name);
1451                  rowSample[m_SamplesModel.m_col_sample] = sample;                  rowSample[m_SamplesModel.m_col_sample] = sample;
1452                  rowSample[m_SamplesModel.m_col_group]  = NULL;                  rowSample[m_SamplesModel.m_col_group]  = NULL;
1453                    int refcount = sample_ref_count.count(sample) ? sample_ref_count[sample] : 0;
1454                    rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
1455                    rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
1456              }              }
1457          }          }
1458      }      }
# Line 1478  void MainWindow::show_midi_rules() Line 1546  void MainWindow::show_midi_rules()
1546      }      }
1547  }  }
1548    
1549    void MainWindow::show_script_slots() {
1550        if (!file) return;
1551        // get selected instrument
1552        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeView.get_selection();
1553        Gtk::TreeModel::iterator it = sel->get_selected();
1554        if (!it) return;
1555        Gtk::TreeModel::Row row = *it;
1556        gig::Instrument* instrument = row[m_Columns.m_col_instr];
1557        if (!instrument) return;
1558    
1559        ScriptSlots* window = new ScriptSlots;
1560        window->setInstrument(instrument);
1561        //window->reparent(*this);
1562        window->show();
1563    }
1564    
1565  void MainWindow::on_action_view_status_bar() {  void MainWindow::on_action_view_status_bar() {
1566      Gtk::CheckMenuItem* item =      Gtk::CheckMenuItem* item =
1567          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));          dynamic_cast<Gtk::CheckMenuItem*>(uiManager->get_widget("/MenuBar/MenuView/Statusbar"));
# Line 2228  void MainWindow::on_action_remove_sample Line 2312  void MainWindow::on_action_remove_sample
2312      }      }
2313  }  }
2314    
2315    // see comment on on_sample_treeview_drag_begin()
2316    void MainWindow::on_scripts_treeview_drag_begin(const Glib::RefPtr<Gdk::DragContext>& context)
2317    {
2318        first_call_to_drag_data_get = true;
2319    }
2320    
2321    void MainWindow::on_scripts_treeview_drag_data_get(const Glib::RefPtr<Gdk::DragContext>&,
2322                                                       Gtk::SelectionData& selection_data, guint, guint)
2323    {
2324        if (!first_call_to_drag_data_get) return;
2325        first_call_to_drag_data_get = false;
2326    
2327        // get selected script
2328        gig::Script* script = NULL;
2329        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewScripts.get_selection();
2330        Gtk::TreeModel::iterator it = sel->get_selected();
2331        if (it) {
2332            Gtk::TreeModel::Row row = *it;
2333            script = row[m_ScriptsModel.m_col_script];
2334        }
2335        // pass the gig::Script as pointer
2336        selection_data.set(selection_data.get_target(), 0/*unused*/,
2337                           (const guchar*)&script,
2338                           sizeof(script)/*length of data in bytes*/);
2339    }
2340    
2341  // For some reason drag_data_get gets called two times for each  // For some reason drag_data_get gets called two times for each
2342  // 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
2343  // 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 2585  void MainWindow::set_file_is_shared(bool Line 2695  void MainWindow::set_file_is_shared(bool
2695      }      }
2696  }  }
2697    
2698    void MainWindow::on_sample_ref_count_incremented(gig::Sample* sample, int offset) {
2699        if (!sample) return;
2700        sample_ref_count[sample] += offset;
2701        const int refcount = sample_ref_count[sample];
2702    
2703        Glib::RefPtr<Gtk::TreeModel> model = m_TreeViewSamples.get_model();
2704        for (int g = 0; g < model->children().size(); ++g) {
2705            Gtk::TreeModel::Row rowGroup = model->children()[g];
2706            for (int s = 0; s < rowGroup.children().size(); ++s) {
2707                Gtk::TreeModel::Row rowSample = rowGroup.children()[s];
2708                if (rowSample[m_SamplesModel.m_col_sample] != sample) continue;
2709                rowSample[m_SamplesModel.m_col_refcount] = ToString(refcount) + " " + _("Refs.");
2710                rowSample[m_SamplesModel.m_color] = refcount ? "black" : "gray";
2711            }
2712        }
2713    }
2714    
2715    void MainWindow::on_sample_ref_changed(gig::Sample* oldSample, gig::Sample* newSample) {
2716        on_sample_ref_count_incremented(oldSample, -1);
2717        on_sample_ref_count_incremented(newSample, +1);
2718    }
2719    
2720    void MainWindow::on_samples_to_be_removed(std::list<gig::Sample*> samples) {
2721        // just in case a new sample is added later with exactly the same memory
2722        // address, which would lead to incorrect refcount if not deleted here
2723        for (std::list<gig::Sample*>::const_iterator it = samples.begin();
2724             it != samples.end(); it != samples.end())
2725        {
2726            sample_ref_count.erase(*it);
2727        }
2728    }
2729    
2730  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
2731      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
2732  }  }

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

  ViewVC Help
Powered by ViewVC