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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3340 - (hide annotations) (download)
Mon Jul 31 11:20:18 2017 UTC (6 years, 8 months ago) by schoenebeck
File size: 6110 byte(s)
* Added search filter field which allows to quickly filter the instrument
  list by case insensitive search tokens.
* Fix: navigating between dimension zones by keyboard did sometimes not
  work after switching from an instrument with different dimension types.
* Fix: Sample references view dialog had some odd behaviors, like it did not
  respond to mouse scroll events for instance.
* Bumped version (1.0.0.svn62).

1 schoenebeck 2624 /*
2 schoenebeck 2695 Copyright (c) 2014,2015 Christian Schoenebeck
3 schoenebeck 2624
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 schoenebeck 2894 ManagedDialog("", parent, true), m_sample(NULL),
17 schoenebeck 3158 m_closeButton(Gtk::Stock::CLOSE), m_descriptionLabel()
18 schoenebeck 2624 {
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 schoenebeck 2695 "respective regions. Click on a reference below to jump directly to "
35     "its specific dimension region."
36 schoenebeck 2624 ));
37    
38     m_refTreeModel = RefsTreeStore::create(m_columns);
39     m_treeView.set_model(m_refTreeModel);
40     m_treeView.set_tooltip_text(_(
41 schoenebeck 2695 "Amount of times the selected sample in question is referenced. Click "
42     "to jump to the specific reference."
43 schoenebeck 2624 ));
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 schoenebeck 2695 m_treeView.get_selection()->set_mode(Gtk::SELECTION_SINGLE);
48 schoenebeck 3340 m_treeView.signal_row_activated().connect(
49 schoenebeck 2695 sigc::mem_fun(*this, &ReferencesView::onSelectionChanged)
50     );
51 schoenebeck 2624
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 schoenebeck 2695
133 schoenebeck 3340 void ReferencesView::onSelectionChanged(const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn* column) {
134 schoenebeck 2695 if (!m_sample) return;
135    
136 schoenebeck 3340 Gtk::TreeModel::iterator it = m_refTreeModel->get_iter(path);
137     if (!it) return;
138    
139 schoenebeck 2695 Gtk::TreeModel::Row row = *it;
140 schoenebeck 3340
141 schoenebeck 2695 gig::Instrument* pInstrument = row[m_columns.m_col_instr];
142     gig::Region* pRegion = row[m_columns.m_col_region];
143     gig::DimensionRegion* pDimRgn = NULL;
144     if (pRegion) {
145     // pick the 1st dimension region of that region referencing the sample
146     for (int dr = 0; dr < pRegion->DimensionRegions && pRegion->pDimensionRegions[dr]; ++dr) {
147     if (pRegion->pDimensionRegions[dr]->pSample == m_sample) {
148     pDimRgn = pRegion->pDimensionRegions[dr];
149     break;
150     }
151     }
152     } else if (pInstrument) {
153     // pick the 1st region and its 1st dimension region referencing the sample
154     for (pRegion = pInstrument->GetFirstRegion(); pRegion; pRegion = pInstrument->GetNextRegion()) {
155     for (int dr = 0; dr < pRegion->DimensionRegions && pRegion->pDimensionRegions[dr]; ++dr) {
156     if (pRegion->pDimensionRegions[dr]->pSample == m_sample) {
157     pDimRgn = pRegion->pDimensionRegions[dr];
158     break;
159     }
160     }
161     }
162     } else {
163     return; // no dimension region resolved to be selected, so do nothing
164     }
165    
166     if (pDimRgn) {
167     bool selectionSuccess = dimension_region_selected.emit(pDimRgn);
168     if (selectionSuccess) hide();
169     }
170     }

  ViewVC Help
Powered by ViewVC