/[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 2894 - (show annotations) (download)
Sat Apr 30 14:42:14 2016 UTC (3 years, 6 months ago) by schoenebeck
File size: 6118 byte(s)
* Enabled auto save & restore of window size & position of all
  remaining windows.
* Bumped version (1.0.0.svn7).

1 /*
2 Copyright (c) 2014,2015 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 ManagedDialog("", parent, true), m_sample(NULL),
17 m_closeButton(_("_Close"), true), 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. Click on a reference below to jump directly to "
35 "its specific dimension region."
36 ));
37
38 m_refTreeModel = RefsTreeStore::create(m_columns);
39 m_treeView.set_model(m_refTreeModel);
40 m_treeView.set_tooltip_text(_(
41 "Amount of times the selected sample in question is referenced. Click "
42 "to jump to the specific reference."
43 ));
44 m_treeView.append_column(_("Name"), m_columns.m_col_name);
45 m_treeView.append_column(_("References"), m_columns.m_col_refcount);
46 m_treeView.set_headers_visible(true);
47 m_treeView.get_selection()->set_mode(Gtk::SELECTION_SINGLE);
48 m_treeView.get_selection()->signal_changed().connect(
49 sigc::mem_fun(*this, &ReferencesView::onSelectionChanged)
50 );
51
52 m_buttonBox.set_layout(Gtk::BUTTONBOX_END);
53 m_buttonBox.set_border_width(5);
54 m_buttonBox.pack_start(m_closeButton, Gtk::PACK_SHRINK);
55
56 m_closeButton.signal_clicked().connect(
57 sigc::mem_fun(*this, &ReferencesView::hide)
58 );
59
60 show_all_children();
61 }
62
63 void ReferencesView::setSample(gig::Sample* sample) {
64 m_refTreeModel->clear();
65
66 m_sample = sample;
67 if (!sample) {
68 set_title("Nothing selected");
69 m_summaryLabel.set_text("");
70 return;
71 }
72
73 set_title(_("References of Sample \"") + sample->pInfo->Name + "\"");
74
75 int filesRefCount = 0;
76
77 gig::File* gig = (gig::File*) sample->GetParent();
78
79 for (gig::Instrument* instrument = gig->GetFirstInstrument(); instrument;
80 instrument = gig->GetNextInstrument())
81 {
82 Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
83 Gtk::TreeModel::Row rowInstr = *iterInstr;
84 rowInstr[m_columns.m_col_name] = gig_to_utf8(instrument->pInfo->Name);
85 rowInstr[m_columns.m_col_instr] = instrument;
86 rowInstr[m_columns.m_col_region] = NULL;
87
88 int instrumentsRefcount = 0;
89 for (gig::Region* rgn = instrument->GetFirstRegion(); rgn;
90 rgn = instrument->GetNextRegion())
91 {
92 int regionsRefCount = 0;
93
94 for (int i = 0; i < 256; ++i) {
95 if (!rgn->pDimensionRegions[i]) continue;
96 if (rgn->pDimensionRegions[i]->pSample != sample) continue;
97 regionsRefCount++;
98 }
99 if (!regionsRefCount) continue;
100
101 instrumentsRefcount += regionsRefCount;
102
103 Gtk::TreeModel::iterator iterRegion = m_refTreeModel->append(rowInstr.children());
104 Gtk::TreeModel::Row rowRegion = *iterRegion;
105 rowRegion[m_columns.m_col_name] =
106 _("Region from ") + note_str(rgn->KeyRange.low) + _(" to ") + note_str(rgn->KeyRange.high);
107 rowRegion[m_columns.m_col_instr] = NULL;
108 rowRegion[m_columns.m_col_region] = rgn;
109 rowRegion[m_columns.m_col_refcount] =
110 ToString(regionsRefCount) + " " + _("Refs.");
111 }
112
113 if (!instrumentsRefcount) {
114 m_refTreeModel->erase(iterInstr);
115 continue;
116 }
117
118 rowInstr[m_columns.m_col_refcount] =
119 ToString(instrumentsRefcount) + " " + _("Refs.");
120
121 filesRefCount += instrumentsRefcount;
122 }
123
124 if (filesRefCount)
125 m_summaryLabel.set_text(_("Total References: ") + ToString(filesRefCount));
126 else
127 m_summaryLabel.set_text(_("This sample is not referenced at all."));
128
129 // unfold all instruments by default
130 m_treeView.expand_all();
131 }
132
133 void ReferencesView::onSelectionChanged() {
134 if (!m_sample) return;
135
136 Glib::RefPtr<Gtk::TreeSelection> sel = m_treeView.get_selection();
137 Gtk::TreeModel::iterator it = sel->get_selected();
138 Gtk::TreeModel::Row row = *it;
139 if (!it) return;
140 gig::Instrument* pInstrument = row[m_columns.m_col_instr];
141 gig::Region* pRegion = row[m_columns.m_col_region];
142 gig::DimensionRegion* pDimRgn = NULL;
143 if (pRegion) {
144 // pick the 1st dimension region of that region referencing the sample
145 for (int dr = 0; dr < pRegion->DimensionRegions && pRegion->pDimensionRegions[dr]; ++dr) {
146 if (pRegion->pDimensionRegions[dr]->pSample == m_sample) {
147 pDimRgn = pRegion->pDimensionRegions[dr];
148 break;
149 }
150 }
151 } else if (pInstrument) {
152 // pick the 1st region and its 1st dimension region referencing the sample
153 for (pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion()) {
154 for (int dr = 0; dr < pRegion->DimensionRegions && pRegion->pDimensionRegions[dr]; ++dr) {
155 if (pRegion->pDimensionRegions[dr]->pSample == m_sample) {
156 pDimRgn = pRegion->pDimensionRegions[dr];
157 break;
158 }
159 }
160 }
161 } else {
162 return; // no dimension region resolved to be selected, so do nothing
163 }
164
165 if (pDimRgn) {
166 bool selectionSuccess = dimension_region_selected.emit(pDimRgn);
167 if (selectionSuccess) hide();
168 }
169 }

  ViewVC Help
Powered by ViewVC