1 |
capela |
1464 |
// qsamplerInstrumentListForm.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
capela |
2064 |
Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
capela |
1464 |
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
|
7 |
|
|
This program is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU General Public License |
9 |
|
|
as published by the Free Software Foundation; either version 2 |
10 |
|
|
of the License, or (at your option) any later version. |
11 |
|
|
|
12 |
|
|
This program is distributed in the hope that it will be useful, |
13 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 |
|
|
GNU General Public License for more details. |
16 |
|
|
|
17 |
|
|
You should have received a copy of the GNU General Public License |
18 |
|
|
along with this program; if not, write to the Free Software |
19 |
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
20 |
|
|
|
21 |
|
|
*****************************************************************************/ |
22 |
|
|
|
23 |
capela |
1513 |
#include "qsamplerAbout.h" |
24 |
schoenebeck |
1461 |
#include "qsamplerInstrumentListForm.h" |
25 |
|
|
|
26 |
capela |
2064 |
#include "qsamplerInstrumentList.h" |
27 |
|
|
|
28 |
schoenebeck |
1492 |
#include "qsamplerInstrumentForm.h" |
29 |
capela |
1513 |
|
30 |
schoenebeck |
1461 |
#include "qsamplerOptions.h" |
31 |
|
|
#include "qsamplerInstrument.h" |
32 |
capela |
1513 |
#include "qsamplerMainForm.h" |
33 |
schoenebeck |
1461 |
|
34 |
capela |
1519 |
#include <QHeaderView> |
35 |
capela |
1528 |
#include <QMessageBox> |
36 |
schoenebeck |
1461 |
|
37 |
capela |
1519 |
|
38 |
schoenebeck |
1461 |
namespace QSampler { |
39 |
|
|
|
40 |
capela |
1558 |
//------------------------------------------------------------------------- |
41 |
|
|
// QSampler::InstrumentListForm -- Instrument map list form implementation. |
42 |
|
|
// |
43 |
|
|
|
44 |
capela |
1504 |
InstrumentListForm::InstrumentListForm ( |
45 |
|
|
QWidget* pParent, Qt::WindowFlags wflags ) |
46 |
|
|
: QMainWindow(pParent, wflags) |
47 |
capela |
1473 |
{ |
48 |
capela |
1509 |
m_ui.setupUi(this); |
49 |
schoenebeck |
1461 |
|
50 |
capela |
1509 |
// Setup toolbar widgets. |
51 |
|
|
m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar); |
52 |
|
|
m_pMapComboBox->setMinimumWidth(120); |
53 |
|
|
m_pMapComboBox->setEnabled(false); |
54 |
|
|
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
55 |
|
|
m_ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
56 |
schoenebeck |
1461 |
|
57 |
capela |
1509 |
m_ui.InstrumentToolbar->addSeparator(); |
58 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction); |
59 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction); |
60 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
61 |
|
|
m_ui.InstrumentToolbar->addSeparator(); |
62 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
63 |
schoenebeck |
1461 |
|
64 |
capela |
2064 |
m_pInstrumentListView = new InstrumentListView(this); |
65 |
capela |
1519 |
|
66 |
capela |
2064 |
QHeaderView *pHeader = m_pInstrumentListView->header(); |
67 |
capela |
1526 |
pHeader->setDefaultAlignment(Qt::AlignLeft); |
68 |
|
|
pHeader->setMovable(false); |
69 |
|
|
pHeader->setStretchLastSection(true); |
70 |
|
|
pHeader->resizeSection(0, 120); // Name |
71 |
capela |
2064 |
m_pInstrumentListView->resizeColumnToContents(1); // Map |
72 |
|
|
m_pInstrumentListView->resizeColumnToContents(2); // Bank |
73 |
|
|
m_pInstrumentListView->resizeColumnToContents(3); // Prog |
74 |
|
|
m_pInstrumentListView->resizeColumnToContents(4); // Engine |
75 |
capela |
1526 |
pHeader->resizeSection(5, 240); // File |
76 |
capela |
2064 |
m_pInstrumentListView->resizeColumnToContents(6); // Nr |
77 |
capela |
1528 |
pHeader->resizeSection(7, 60); // Vol |
78 |
capela |
1526 |
|
79 |
capela |
1528 |
// Enable custom context menu... |
80 |
capela |
2064 |
m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu); |
81 |
capela |
1528 |
|
82 |
capela |
2064 |
QMainWindow::setCentralWidget(m_pInstrumentListView); |
83 |
|
|
|
84 |
schoenebeck |
1461 |
QObject::connect(m_pMapComboBox, |
85 |
|
|
SIGNAL(activated(int)), |
86 |
|
|
SLOT(activateMap(int))); |
87 |
capela |
1466 |
QObject::connect( |
88 |
capela |
2064 |
m_pInstrumentListView, |
89 |
capela |
1528 |
SIGNAL(customContextMenuRequested(const QPoint&)), |
90 |
|
|
SLOT(contextMenu(const QPoint&))); |
91 |
capela |
1504 |
QObject::connect( |
92 |
capela |
2064 |
m_pInstrumentListView, |
93 |
capela |
1528 |
SIGNAL(pressed(const QModelIndex&)), |
94 |
|
|
SLOT(stabilizeForm())); |
95 |
|
|
QObject::connect( |
96 |
capela |
2064 |
m_pInstrumentListView, |
97 |
schoenebeck |
1492 |
SIGNAL(activated(const QModelIndex&)), |
98 |
capela |
1509 |
SLOT(editInstrument(const QModelIndex&))); |
99 |
capela |
1504 |
QObject::connect( |
100 |
capela |
1509 |
m_ui.newInstrumentAction, |
101 |
schoenebeck |
1492 |
SIGNAL(triggered()), |
102 |
capela |
1509 |
SLOT(newInstrument())); |
103 |
capela |
1504 |
QObject::connect( |
104 |
capela |
1509 |
m_ui.deleteInstrumentAction, |
105 |
schoenebeck |
1492 |
SIGNAL(triggered()), |
106 |
capela |
1509 |
SLOT(deleteInstrument())); |
107 |
capela |
1504 |
QObject::connect( |
108 |
capela |
1509 |
m_ui.editInstrumentAction, |
109 |
schoenebeck |
1492 |
SIGNAL(triggered()), |
110 |
capela |
1509 |
SLOT(editInstrument())); |
111 |
capela |
1528 |
QObject::connect( |
112 |
|
|
m_ui.refreshInstrumentsAction, |
113 |
|
|
SIGNAL(triggered()), |
114 |
|
|
SLOT(refreshInstruments())); |
115 |
capela |
1509 |
|
116 |
capela |
1528 |
// Things must be stable from the start. |
117 |
|
|
stabilizeForm(); |
118 |
schoenebeck |
1461 |
} |
119 |
|
|
|
120 |
capela |
1504 |
|
121 |
|
|
InstrumentListForm::~InstrumentListForm (void) |
122 |
|
|
{ |
123 |
capela |
2064 |
delete m_pInstrumentListView; |
124 |
schoenebeck |
1461 |
delete m_pMapComboBox; |
125 |
|
|
} |
126 |
|
|
|
127 |
|
|
|
128 |
|
|
// Notify our parent that we're emerging. |
129 |
|
|
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
130 |
|
|
{ |
131 |
capela |
1504 |
MainForm* pMainForm = MainForm::getInstance(); |
132 |
|
|
if (pMainForm) |
133 |
|
|
pMainForm->stabilizeForm(); |
134 |
schoenebeck |
1461 |
|
135 |
|
|
QWidget::showEvent(pShowEvent); |
136 |
|
|
} |
137 |
|
|
|
138 |
|
|
|
139 |
|
|
// Notify our parent that we're closing. |
140 |
|
|
void InstrumentListForm::hideEvent ( QHideEvent *pHideEvent ) |
141 |
|
|
{ |
142 |
|
|
QWidget::hideEvent(pHideEvent); |
143 |
|
|
|
144 |
capela |
1504 |
MainForm* pMainForm = MainForm::getInstance(); |
145 |
|
|
if (pMainForm) |
146 |
|
|
pMainForm->stabilizeForm(); |
147 |
schoenebeck |
1461 |
} |
148 |
|
|
|
149 |
|
|
|
150 |
capela |
1504 |
// Just about to notify main-window that we're closing. |
151 |
|
|
void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ ) |
152 |
|
|
{ |
153 |
|
|
QWidget::hide(); |
154 |
|
|
|
155 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
156 |
|
|
if (pMainForm) |
157 |
|
|
pMainForm->stabilizeForm(); |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
|
161 |
schoenebeck |
1461 |
// Refresh all instrument list and views. |
162 |
|
|
void InstrumentListForm::refreshInstruments (void) |
163 |
|
|
{ |
164 |
|
|
MainForm* pMainForm = MainForm::getInstance(); |
165 |
|
|
if (pMainForm == NULL) |
166 |
|
|
return; |
167 |
|
|
|
168 |
capela |
1558 |
Options *pOptions = pMainForm->options(); |
169 |
schoenebeck |
1461 |
if (pOptions == NULL) |
170 |
|
|
return; |
171 |
|
|
|
172 |
|
|
// Get/save current map selection... |
173 |
capela |
1499 |
int iMap = m_pMapComboBox->currentIndex(); |
174 |
schoenebeck |
1461 |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
175 |
|
|
iMap = pOptions->iMidiMap + 1; |
176 |
|
|
|
177 |
|
|
// Populate maps list. |
178 |
|
|
m_pMapComboBox->clear(); |
179 |
capela |
1499 |
m_pMapComboBox->addItem(tr("(All)")); |
180 |
capela |
1558 |
m_pMapComboBox->insertItems(1, Instrument::getMapNames()); |
181 |
schoenebeck |
1461 |
|
182 |
|
|
// Adjust to saved selection... |
183 |
|
|
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
184 |
|
|
iMap = 0; |
185 |
capela |
1499 |
m_pMapComboBox->setCurrentIndex(iMap); |
186 |
schoenebeck |
1461 |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
187 |
|
|
|
188 |
|
|
activateMap(iMap); |
189 |
|
|
} |
190 |
|
|
|
191 |
|
|
|
192 |
|
|
// Refresh instrument maps selector. |
193 |
|
|
void InstrumentListForm::activateMap ( int iMap ) |
194 |
|
|
{ |
195 |
|
|
MainForm* pMainForm = MainForm::getInstance(); |
196 |
|
|
if (pMainForm == NULL) |
197 |
|
|
return; |
198 |
|
|
|
199 |
capela |
1558 |
Options *pOptions = pMainForm->options(); |
200 |
schoenebeck |
1461 |
if (pOptions == NULL) |
201 |
|
|
return; |
202 |
|
|
|
203 |
|
|
int iMidiMap = iMap - 1; |
204 |
|
|
if (iMidiMap >= 0) |
205 |
|
|
pOptions->iMidiMap = iMidiMap; |
206 |
|
|
|
207 |
capela |
2064 |
m_pInstrumentListView->setMidiMap(iMidiMap); |
208 |
|
|
m_pInstrumentListView->refresh(); |
209 |
capela |
1528 |
|
210 |
|
|
stabilizeForm(); |
211 |
schoenebeck |
1461 |
} |
212 |
|
|
|
213 |
capela |
1504 |
|
214 |
|
|
void InstrumentListForm::editInstrument (void) |
215 |
|
|
{ |
216 |
capela |
2064 |
editInstrument(m_pInstrumentListView->currentIndex()); |
217 |
schoenebeck |
1492 |
} |
218 |
|
|
|
219 |
capela |
1504 |
|
220 |
|
|
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
221 |
|
|
{ |
222 |
capela |
2064 |
if (!index.isValid()) |
223 |
schoenebeck |
1492 |
return; |
224 |
|
|
|
225 |
capela |
2064 |
Instrument *pInstrument |
226 |
|
|
= static_cast<Instrument *> (index.internalPointer()); |
227 |
|
|
if (pInstrument == NULL) |
228 |
|
|
return; |
229 |
schoenebeck |
1492 |
|
230 |
capela |
1504 |
if (pInstrument == NULL) |
231 |
|
|
return; |
232 |
schoenebeck |
1492 |
|
233 |
|
|
// Save current key values... |
234 |
capela |
2064 |
Instrument oldInstrument( |
235 |
|
|
pInstrument->map(), |
236 |
|
|
pInstrument->bank(), |
237 |
|
|
pInstrument->prog()); |
238 |
|
|
|
239 |
schoenebeck |
1492 |
// Do the edit dance... |
240 |
|
|
InstrumentForm form(this); |
241 |
|
|
form.setup(pInstrument); |
242 |
|
|
if (form.exec()) { |
243 |
|
|
// Commit... |
244 |
|
|
pInstrument->mapInstrument(); |
245 |
|
|
// Check whether we changed instrument key... |
246 |
|
|
if (oldInstrument.map() == pInstrument->map() && |
247 |
|
|
oldInstrument.bank() == pInstrument->bank() && |
248 |
|
|
oldInstrument.prog() == pInstrument->prog()) { |
249 |
capela |
1523 |
// Just update tree item... |
250 |
schoenebeck |
1492 |
//pItem->update(); |
251 |
|
|
} else { |
252 |
|
|
// Unmap old instance... |
253 |
|
|
oldInstrument.unmapInstrument(); |
254 |
|
|
// correct the position of the instrument in the model |
255 |
capela |
2064 |
m_pInstrumentListView->updateInstrument(pInstrument); |
256 |
schoenebeck |
1492 |
} |
257 |
|
|
} |
258 |
|
|
} |
259 |
|
|
|
260 |
capela |
1504 |
|
261 |
|
|
void InstrumentListForm::newInstrument (void) |
262 |
|
|
{ |
263 |
capela |
1558 |
Instrument instrument; |
264 |
schoenebeck |
1492 |
|
265 |
|
|
InstrumentForm form(this); |
266 |
|
|
form.setup(&instrument); |
267 |
capela |
1504 |
if (!form.exec()) |
268 |
|
|
return; |
269 |
schoenebeck |
1492 |
|
270 |
|
|
// Commit... |
271 |
|
|
instrument.mapInstrument(); |
272 |
capela |
2064 |
|
273 |
schoenebeck |
1492 |
// add new item to the table model |
274 |
capela |
2064 |
m_pInstrumentListView->addInstrument( |
275 |
|
|
instrument.map(), |
276 |
|
|
instrument.bank(), |
277 |
|
|
instrument.prog()); |
278 |
schoenebeck |
1492 |
} |
279 |
|
|
|
280 |
|
|
|
281 |
capela |
1504 |
void InstrumentListForm::deleteInstrument (void) |
282 |
|
|
{ |
283 |
capela |
2064 |
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
284 |
|
|
if (!index.isValid()) |
285 |
capela |
1504 |
return; |
286 |
|
|
|
287 |
capela |
2064 |
Instrument *pInstrument |
288 |
|
|
= static_cast<Instrument *> (index.internalPointer()); |
289 |
capela |
1504 |
if (pInstrument == NULL) |
290 |
|
|
return; |
291 |
schoenebeck |
1492 |
|
292 |
capela |
1528 |
MainForm *pMainForm = MainForm::getInstance(); |
293 |
|
|
if (pMainForm == NULL) |
294 |
|
|
return; |
295 |
|
|
|
296 |
|
|
// Prompt user if this is for real... |
297 |
capela |
1558 |
Options *pOptions = pMainForm->options(); |
298 |
capela |
1528 |
if (pOptions && pOptions->bConfirmRemove) { |
299 |
|
|
if (QMessageBox::warning(this, |
300 |
|
|
QSAMPLER_TITLE ": " + tr("Warning"), |
301 |
|
|
tr("About to delete instrument map entry:\n\n" |
302 |
|
|
"%1\n\n" |
303 |
|
|
"Are you sure?") |
304 |
|
|
.arg(pInstrument->name()), |
305 |
capela |
1840 |
QMessageBox::Ok | QMessageBox::Cancel) |
306 |
|
|
== QMessageBox::Cancel) |
307 |
capela |
1528 |
return; |
308 |
|
|
} |
309 |
|
|
|
310 |
schoenebeck |
1492 |
pInstrument->unmapInstrument(); |
311 |
capela |
2064 |
|
312 |
schoenebeck |
1492 |
// let the instrument vanish from the table model |
313 |
capela |
2064 |
m_pInstrumentListView->removeInstrument(pInstrument); |
314 |
schoenebeck |
1492 |
} |
315 |
|
|
|
316 |
capela |
1528 |
|
317 |
|
|
// Update form actions enablement... |
318 |
|
|
void InstrumentListForm::stabilizeForm (void) |
319 |
|
|
{ |
320 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
321 |
|
|
|
322 |
|
|
bool bEnabled = (pMainForm && pMainForm->client()); |
323 |
|
|
m_ui.newInstrumentAction->setEnabled(bEnabled); |
324 |
capela |
2064 |
const QModelIndex& index = m_pInstrumentListView->currentIndex(); |
325 |
capela |
1528 |
bEnabled = (bEnabled && index.isValid()); |
326 |
|
|
m_ui.editInstrumentAction->setEnabled(bEnabled); |
327 |
|
|
m_ui.deleteInstrumentAction->setEnabled(bEnabled); |
328 |
|
|
} |
329 |
|
|
|
330 |
|
|
|
331 |
|
|
// Handle custom context menu here... |
332 |
|
|
void InstrumentListForm::contextMenu ( const QPoint& pos ) |
333 |
|
|
{ |
334 |
|
|
if (!m_ui.newInstrumentAction->isEnabled()) |
335 |
|
|
return; |
336 |
|
|
|
337 |
|
|
m_ui.contextMenu->exec( |
338 |
capela |
2064 |
(m_pInstrumentListView->viewport())->mapToGlobal(pos)); |
339 |
capela |
1528 |
} |
340 |
|
|
|
341 |
|
|
|
342 |
schoenebeck |
1461 |
} // namespace QSampler |
343 |
capela |
1464 |
|
344 |
|
|
|
345 |
|
|
// end of qsamplerInstrumentListForm.cpp |