/
AIVocalSetChooserDialog.cpp
221 lines (170 loc) · 5.06 KB
/
AIVocalSetChooserDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#include "AIVocalSetChooserDialog.h"
#include "i18n.h"
#include "imainframe.h"
#include "iuimanager.h"
#include "ieclass.h"
#include "isound.h"
#include "eclass.h"
#include <wx/stattext.h>
#include <wx/sizer.h>
namespace ui
{
namespace
{
const char* const WINDOW_TITLE = N_("Choose AI Vocal Set");
}
AIVocalSetChooserDialog::AIVocalSetChooserDialog() :
DialogBase(_(WINDOW_TITLE)),
_setStore(new wxutil::TreeModel(_columns, true)),
_preview(NULL)
{
SetSizer(new wxBoxSizer(wxVERTICAL));
if (module::GlobalModuleRegistry().moduleExists(MODULE_SOUNDMANAGER))
{
_preview = new AIVocalSetPreview(this);
}
_setView = wxutil::TreeView::CreateWithModel(this, _setStore.get(), wxDV_NO_HEADER);
_setView->Connect(wxEVT_DATAVIEW_SELECTION_CHANGED,
wxDataViewEventHandler(AIVocalSetChooserDialog::onSetSelectionChanged), NULL, this);
// Head Name column
_setView->AppendTextColumn("", _columns.name.getColumnIndex(),
wxDATAVIEW_CELL_INERT, wxCOL_WIDTH_AUTOSIZE, wxALIGN_NOT, wxDATAVIEW_COL_SORTABLE);
// Allow searching for the name
_setView->AddSearchColumn(_columns.name);
wxBoxSizer* vbox1 = new wxBoxSizer(wxVERTICAL);
wxStaticText* label1 = new wxStaticText(this, wxID_ANY, _("Available Sets"));
label1->SetFont(label1->GetFont().Bold());
vbox1->Add(label1, 0, wxBOTTOM, 6);
vbox1->Add(_setView, 1, wxEXPAND);
// Right: the description
wxBoxSizer* vbox2 = new wxBoxSizer(wxVERTICAL);
wxStaticText* label2 = new wxStaticText(this, wxID_ANY, _("Description"));
label2->SetFont(label2->GetFont().Bold());
_description = new wxTextCtrl(this, wxID_ANY, "",
wxDefaultPosition, wxDefaultSize, wxTE_LEFT | wxTE_MULTILINE | wxTE_READONLY | wxTE_WORDWRAP);
_description->SetMinClientSize(wxSize(-1, 60));
vbox2->Add(label2, 0, wxBOTTOM, 6);
vbox2->Add(_description, 1, wxEXPAND | wxBOTTOM, 6);
// Right: the preview control panel
if (_preview != NULL)
{
vbox2->Add(_preview, 0, wxEXPAND);
}
// dialog hbox, left is the treeview, right is the preview panel
wxBoxSizer* hbox = new wxBoxSizer(wxHORIZONTAL);
hbox->Add(vbox1, 3, wxEXPAND | wxRIGHT, 6);
hbox->Add(vbox2, 1, wxEXPAND | wxRIGHT, 6);
GetSizer()->Add(hbox, 1, wxEXPAND | wxALL, 12);
GetSizer()->Add(CreateStdDialogButtonSizer(wxOK | wxCANCEL), 0, wxALIGN_RIGHT | wxBOTTOM | wxRIGHT, 12);
FitToScreen(0.7f, 0.6f);
// Check if the liststore is populated
findAvailableSets();
// Load the found sets into the GtkListStore
populateSetStore();
}
void AIVocalSetChooserDialog::setSelectedVocalSet(const std::string& setName)
{
_selectedSet = setName;
if (_selectedSet.empty())
{
_setView->UnselectAll();
return;
}
wxDataViewItem found = _setStore->FindString(setName, _columns.name);
// Lookup the model path in the treemodel
if (found.IsOk())
{
_setView->Select(found);
_setView->EnsureVisible(found);
handleSetSelectionChanged();
}
}
std::string AIVocalSetChooserDialog::getSelectedVocalSet()
{
return _selectedSet;
}
void AIVocalSetChooserDialog::handleSetSelectionChanged()
{
// Prepare to check for a selection
wxDataViewItem item = _setView->GetSelection();
// Add button is enabled if there is a selection
if (item.IsOk())
{
// Make the OK button active
FindWindowById(wxID_OK, this)->Enable(true);
_description->Enable(true);
// Set the panel text with the usage information
wxutil::TreeModel::Row row(item, *_setStore);
_selectedSet = row[_columns.name];
// Lookup the IEntityClass instance
IEntityClassPtr ecls = GlobalEntityClassManager().findClass(_selectedSet);
if (ecls)
{
// Update the preview pane
if (_preview != NULL)
{
_preview->setVocalSetEclass(ecls);
}
// Update the usage panel
_description->SetValue(eclass::getUsage(*ecls));
}
}
else
{
_selectedSet = "";
if (_preview != NULL)
{
_preview->setVocalSetEclass(IEntityClassPtr());
}
FindWindowById(wxID_OK, this)->Enable(false);
_description->Enable(false);
}
}
void AIVocalSetChooserDialog::onSetSelectionChanged(wxDataViewEvent& ev)
{
handleSetSelectionChanged();
}
void AIVocalSetChooserDialog::populateSetStore()
{
// Clear the head list to be safe
_setStore->Clear();
for (SetList::const_iterator i = _availableSets.begin(); i != _availableSets.end(); ++i)
{
// Add the entity to the list
wxutil::TreeModel::Row row = _setStore->AddItem();
row[_columns.name] = *i;
row.SendItemAdded();
}
}
namespace
{
class VocalSetEClassFinder :
public EntityClassVisitor
{
AIVocalSetChooserDialog::SetList& _list;
public:
VocalSetEClassFinder(AIVocalSetChooserDialog::SetList& list) :
_list(list)
{}
void visit(const IEntityClassPtr& eclass)
{
if (eclass->getAttribute("editor_vocal_set").getValue() == "1")
{
_list.insert(eclass->getName());
}
}
};
} // namespace
void AIVocalSetChooserDialog::findAvailableSets()
{
if (!_availableSets.empty())
{
return;
}
// Instantiate a finder class and traverse all eclasses
VocalSetEClassFinder visitor(_availableSets);
GlobalEntityClassManager().forEachEntityClass(visitor);
}
// Init static class member
AIVocalSetChooserDialog::SetList AIVocalSetChooserDialog::_availableSets;
} // namespace ui