/[svn]/gigedit/trunk/src/gigedit/ReferencesView.cpp
ViewVC logotype

Contents of /gigedit/trunk/src/gigedit/ReferencesView.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2624 - (show annotations) (download)
Wed Jun 11 20:26:26 2014 UTC (9 years, 9 months ago) by schoenebeck
File size: 4428 byte(s)
* Samples tree view: implemented sample reference browser, which shows a
  tree with all instruments and their respective regions which reference the
  selected sample once ore more.

1 /*
2 Copyright (c) 2014 Christian Schoenebeck
3
4 This file is part of "gigedit" and released under the terms of the
5 GNU General Public License version 2.
6 */
7
8 #include "ReferencesView.h"
9 #include "global.h"
10 #include "compat.h"
11
12 Glib::ustring gig_to_utf8(const gig::String& gig_string);
13 Glib::ustring note_str(int note);
14
15 ReferencesView::ReferencesView(Gtk::Window& parent) :
16 Gtk::Dialog("", parent, true), m_sample(NULL),
17 m_closeButton(Gtk::Stock::CLOSE), m_descriptionLabel()
18 {
19 set_title("Nothing selected");
20
21 m_scrolledWindow.add(m_treeView);
22 m_scrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
23
24 get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK);
25 get_vbox()->pack_start(m_scrolledWindow);
26 get_vbox()->pack_start(m_summaryLabel, Gtk::PACK_SHRINK);
27 get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK);
28
29 #if GTKMM_MAJOR_VERSION >= 3
30 m_descriptionLabel.set_line_wrap();
31 #endif
32 m_descriptionLabel.set_text(_(
33 "Selected sample is referenced by the following instruments and their "
34 "respective regions:"
35 ));
36
37 m_refTreeModel = RefsTreeStore::create(m_columns);
38 m_treeView.set_model(m_refTreeModel);
39 m_treeView.set_tooltip_text(_(
40 "Amount of times the selected sample in question is referenced."
41 ));
42 m_treeView.append_column(_("Name"), m_columns.m_col_name);
43 m_treeView.append_column(_("References"), m_columns.m_col_refcount);
44 m_treeView.set_headers_visible(true);
45 //m_treeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
46 //m_treeView.get_selection()->signal_changed().connect(
47 // sigc::mem_fun(*this, &ReferencesView::onSelectionChanged)
48 //);
49
50 m_buttonBox.set_layout(Gtk::BUTTONBOX_END);
51 m_buttonBox.set_border_width(5);
52 m_buttonBox.pack_start(m_closeButton, Gtk::PACK_SHRINK);
53
54 m_closeButton.signal_clicked().connect(
55 sigc::mem_fun(*this, &ReferencesView::hide)
56 );
57
58 show_all_children();
59 }
60
61 void ReferencesView::setSample(gig::Sample* sample) {
62 m_refTreeModel->clear();
63
64 m_sample = sample;
65 if (!sample) {
66 set_title("Nothing selected");
67 m_summaryLabel.set_text("");
68 return;
69 }
70
71 set_title(_("References of Sample \"") + sample->pInfo->Name + "\"");
72
73 int filesRefCount = 0;
74
75 gig::File* gig = (gig::File*) sample->GetParent();
76
77 for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
78 instrument = gig->GetNextInstrument())
79 {
80 Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
81 Gtk::TreeModel::Row rowInstr = *iterInstr;
82 rowInstr[m_columns.m_col_name] = gig_to_utf8(instrument->pInfo->Name);
83 rowInstr[m_columns.m_col_instr] = instrument;
84 rowInstr[m_columns.m_col_region] = NULL;
85
86 int instrumentsRefcount = 0;
87 for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
88 rgn = instrument->GetNextRegion())
89 {
90 int regionsRefCount = 0;
91
92 for (int i = 0; i < 256; ++i) {
93 if (!rgn->pDimensionRegions[i]) continue;
94 if (rgn->pDimensionRegions[i]->pSample != sample) continue;
95 regionsRefCount++;
96 }
97 if (!regionsRefCount) continue;
98
99 instrumentsRefcount += regionsRefCount;
100
101 Gtk::TreeModel::iterator iterRegion = m_refTreeModel->append(rowInstr.children());
102 Gtk::TreeModel::Row rowRegion = *iterRegion;
103 rowRegion[m_columns.m_col_name] =
104 _("Region from ") + note_str(rgn->KeyRange.low) + _(" to ") + note_str(rgn->KeyRange.high);
105 rowRegion[m_columns.m_col_instr] = NULL;
106 rowRegion[m_columns.m_col_region] = rgn;
107 rowRegion[m_columns.m_col_refcount] =
108 ToString(regionsRefCount) + " " + _("Refs.");
109 }
110
111 if (!instrumentsRefcount) {
112 m_refTreeModel->erase(iterInstr);
113 continue;
114 }
115
116 rowInstr[m_columns.m_col_refcount] =
117 ToString(instrumentsRefcount) + " " + _("Refs.");
118
119 filesRefCount += instrumentsRefcount;
120 }
121
122 if (filesRefCount)
123 m_summaryLabel.set_text(_("Total References: ") + ToString(filesRefCount));
124 else
125 m_summaryLabel.set_text(_("This sample is not referenced at all."));
126
127 // unfold all instruments by default
128 m_treeView.expand_all();
129 }

  ViewVC Help
Powered by ViewVC