1 |
capela |
1464 |
// qsamplerInstrumentListForm.cpp |
2 |
|
|
// |
3 |
|
|
/**************************************************************************** |
4 |
|
|
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
|
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 |
schoenebeck |
1492 |
#include "qsamplerInstrumentForm.h" |
27 |
capela |
1513 |
|
28 |
schoenebeck |
1461 |
#include "qsamplerOptions.h" |
29 |
|
|
#include "qsamplerInstrument.h" |
30 |
capela |
1513 |
#include "qsamplerMainForm.h" |
31 |
schoenebeck |
1461 |
|
32 |
|
|
|
33 |
|
|
namespace QSampler { |
34 |
|
|
|
35 |
capela |
1504 |
InstrumentListForm::InstrumentListForm ( |
36 |
|
|
QWidget* pParent, Qt::WindowFlags wflags ) |
37 |
|
|
: QMainWindow(pParent, wflags) |
38 |
capela |
1473 |
{ |
39 |
capela |
1509 |
m_ui.setupUi(this); |
40 |
schoenebeck |
1461 |
|
41 |
capela |
1509 |
// Setup toolbar widgets. |
42 |
|
|
m_pMapComboBox = new QComboBox(m_ui.InstrumentToolbar); |
43 |
|
|
m_pMapComboBox->setMinimumWidth(120); |
44 |
|
|
m_pMapComboBox->setEnabled(false); |
45 |
|
|
m_pMapComboBox->setToolTip(tr("Instrument Map")); |
46 |
|
|
m_ui.InstrumentToolbar->addWidget(m_pMapComboBox); |
47 |
schoenebeck |
1461 |
|
48 |
capela |
1509 |
m_ui.InstrumentToolbar->addSeparator(); |
49 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.newInstrumentAction); |
50 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.editInstrumentAction); |
51 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.deleteInstrumentAction); |
52 |
|
|
m_ui.InstrumentToolbar->addSeparator(); |
53 |
|
|
m_ui.InstrumentToolbar->addAction(m_ui.refreshInstrumentsAction); |
54 |
schoenebeck |
1461 |
|
55 |
capela |
1509 |
m_ui.InstrumentTable->setModel(&m_model); |
56 |
|
|
m_ui.InstrumentTable->setItemDelegate(&m_delegate); |
57 |
schoenebeck |
1461 |
|
58 |
|
|
QObject::connect(m_pMapComboBox, |
59 |
|
|
SIGNAL(activated(int)), |
60 |
|
|
SLOT(activateMap(int))); |
61 |
capela |
1466 |
QObject::connect( |
62 |
capela |
1509 |
m_ui.refreshInstrumentsAction, |
63 |
capela |
1466 |
SIGNAL(triggered()), |
64 |
capela |
1509 |
SLOT(refreshInstruments(void))); |
65 |
capela |
1504 |
QObject::connect( |
66 |
capela |
1509 |
m_ui.InstrumentTable, |
67 |
schoenebeck |
1492 |
SIGNAL(activated(const QModelIndex&)), |
68 |
capela |
1509 |
SLOT(editInstrument(const QModelIndex&))); |
69 |
capela |
1504 |
QObject::connect( |
70 |
capela |
1509 |
m_ui.newInstrumentAction, |
71 |
schoenebeck |
1492 |
SIGNAL(triggered()), |
72 |
capela |
1509 |
SLOT(newInstrument())); |
73 |
capela |
1504 |
QObject::connect( |
74 |
capela |
1509 |
m_ui.deleteInstrumentAction, |
75 |
schoenebeck |
1492 |
SIGNAL(triggered()), |
76 |
capela |
1509 |
SLOT(deleteInstrument())); |
77 |
capela |
1504 |
QObject::connect( |
78 |
capela |
1509 |
m_ui.editInstrumentAction, |
79 |
schoenebeck |
1492 |
SIGNAL(triggered()), |
80 |
capela |
1509 |
SLOT(editInstrument())); |
81 |
|
|
|
82 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
83 |
|
|
if (pMainForm) { |
84 |
|
|
QObject::connect(&m_model, |
85 |
|
|
SIGNAL(instrumentsChanged()), |
86 |
|
|
pMainForm, SLOT(sessionDirty())); |
87 |
|
|
} |
88 |
schoenebeck |
1461 |
} |
89 |
|
|
|
90 |
capela |
1504 |
|
91 |
|
|
InstrumentListForm::~InstrumentListForm (void) |
92 |
|
|
{ |
93 |
schoenebeck |
1461 |
delete m_pMapComboBox; |
94 |
|
|
} |
95 |
|
|
|
96 |
|
|
|
97 |
|
|
// Notify our parent that we're emerging. |
98 |
|
|
void InstrumentListForm::showEvent ( QShowEvent *pShowEvent ) |
99 |
|
|
{ |
100 |
capela |
1504 |
MainForm* pMainForm = MainForm::getInstance(); |
101 |
|
|
if (pMainForm) |
102 |
|
|
pMainForm->stabilizeForm(); |
103 |
schoenebeck |
1461 |
|
104 |
|
|
QWidget::showEvent(pShowEvent); |
105 |
|
|
} |
106 |
|
|
|
107 |
|
|
|
108 |
|
|
// Notify our parent that we're closing. |
109 |
|
|
void InstrumentListForm::hideEvent ( QHideEvent *pHideEvent ) |
110 |
|
|
{ |
111 |
|
|
QWidget::hideEvent(pHideEvent); |
112 |
|
|
|
113 |
capela |
1504 |
MainForm* pMainForm = MainForm::getInstance(); |
114 |
|
|
if (pMainForm) |
115 |
|
|
pMainForm->stabilizeForm(); |
116 |
schoenebeck |
1461 |
} |
117 |
|
|
|
118 |
|
|
|
119 |
capela |
1504 |
// Just about to notify main-window that we're closing. |
120 |
|
|
void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ ) |
121 |
|
|
{ |
122 |
|
|
QWidget::hide(); |
123 |
|
|
|
124 |
|
|
MainForm *pMainForm = MainForm::getInstance(); |
125 |
|
|
if (pMainForm) |
126 |
|
|
pMainForm->stabilizeForm(); |
127 |
|
|
} |
128 |
|
|
|
129 |
|
|
|
130 |
schoenebeck |
1461 |
// Refresh all instrument list and views. |
131 |
|
|
void InstrumentListForm::refreshInstruments (void) |
132 |
|
|
{ |
133 |
|
|
MainForm* pMainForm = MainForm::getInstance(); |
134 |
|
|
if (pMainForm == NULL) |
135 |
|
|
return; |
136 |
|
|
|
137 |
|
|
qsamplerOptions *pOptions = pMainForm->options(); |
138 |
|
|
if (pOptions == NULL) |
139 |
|
|
return; |
140 |
|
|
|
141 |
|
|
// Get/save current map selection... |
142 |
capela |
1499 |
int iMap = m_pMapComboBox->currentIndex(); |
143 |
schoenebeck |
1461 |
if (iMap < 0 || m_pMapComboBox->count() < 2) |
144 |
|
|
iMap = pOptions->iMidiMap + 1; |
145 |
|
|
|
146 |
|
|
// Populate maps list. |
147 |
|
|
m_pMapComboBox->clear(); |
148 |
capela |
1499 |
m_pMapComboBox->addItem(tr("(All)")); |
149 |
|
|
m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames()); |
150 |
schoenebeck |
1461 |
|
151 |
|
|
// Adjust to saved selection... |
152 |
|
|
if (iMap < 0 || iMap >= m_pMapComboBox->count()) |
153 |
|
|
iMap = 0; |
154 |
capela |
1499 |
m_pMapComboBox->setCurrentIndex(iMap); |
155 |
schoenebeck |
1461 |
m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1); |
156 |
|
|
|
157 |
|
|
activateMap(iMap); |
158 |
|
|
} |
159 |
|
|
|
160 |
|
|
|
161 |
|
|
// Refresh instrument maps selector. |
162 |
|
|
void InstrumentListForm::activateMap ( int iMap ) |
163 |
|
|
{ |
164 |
|
|
MainForm* pMainForm = MainForm::getInstance(); |
165 |
|
|
if (pMainForm == NULL) |
166 |
|
|
return; |
167 |
|
|
|
168 |
|
|
qsamplerOptions *pOptions = pMainForm->options(); |
169 |
|
|
if (pOptions == NULL) |
170 |
|
|
return; |
171 |
|
|
|
172 |
|
|
int iMidiMap = iMap - 1; |
173 |
|
|
if (iMidiMap >= 0) |
174 |
|
|
pOptions->iMidiMap = iMidiMap; |
175 |
|
|
|
176 |
capela |
1509 |
m_model.setMidiMap(iMidiMap); |
177 |
|
|
m_model.refresh(); |
178 |
schoenebeck |
1461 |
} |
179 |
|
|
|
180 |
capela |
1504 |
|
181 |
|
|
void InstrumentListForm::editInstrument (void) |
182 |
|
|
{ |
183 |
capela |
1509 |
editInstrument(m_ui.InstrumentTable->currentIndex()); |
184 |
schoenebeck |
1492 |
} |
185 |
|
|
|
186 |
capela |
1504 |
|
187 |
|
|
void InstrumentListForm::editInstrument ( const QModelIndex& index ) |
188 |
|
|
{ |
189 |
schoenebeck |
1492 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
190 |
|
|
return; |
191 |
|
|
|
192 |
capela |
1504 |
qsamplerInstrument* pInstrument |
193 |
|
|
= static_cast<qsamplerInstrument *> ( |
194 |
|
|
index.data(Qt::UserRole).value<void *> ()); |
195 |
schoenebeck |
1492 |
|
196 |
capela |
1504 |
if (pInstrument == NULL) |
197 |
|
|
return; |
198 |
schoenebeck |
1492 |
|
199 |
|
|
// Save current key values... |
200 |
|
|
qsamplerInstrument oldInstrument(*pInstrument); |
201 |
|
|
// Do the edit dance... |
202 |
|
|
InstrumentForm form(this); |
203 |
|
|
form.setup(pInstrument); |
204 |
|
|
if (form.exec()) { |
205 |
|
|
// Commit... |
206 |
|
|
pInstrument->mapInstrument(); |
207 |
|
|
// Check whether we changed instrument key... |
208 |
|
|
if (oldInstrument.map() == pInstrument->map() && |
209 |
|
|
oldInstrument.bank() == pInstrument->bank() && |
210 |
|
|
oldInstrument.prog() == pInstrument->prog()) { |
211 |
|
|
// just update tree item... |
212 |
|
|
//pItem->update(); |
213 |
|
|
} else { |
214 |
|
|
// Unmap old instance... |
215 |
|
|
oldInstrument.unmapInstrument(); |
216 |
|
|
// correct the position of the instrument in the model |
217 |
capela |
1509 |
m_model.resort(*pInstrument); |
218 |
schoenebeck |
1492 |
} |
219 |
|
|
// Notify we've changes... |
220 |
capela |
1509 |
emit m_model.reset(); |
221 |
schoenebeck |
1492 |
} |
222 |
|
|
} |
223 |
|
|
|
224 |
capela |
1504 |
|
225 |
|
|
void InstrumentListForm::newInstrument (void) |
226 |
|
|
{ |
227 |
schoenebeck |
1492 |
qsamplerInstrument instrument; |
228 |
|
|
|
229 |
|
|
InstrumentForm form(this); |
230 |
|
|
form.setup(&instrument); |
231 |
capela |
1504 |
if (!form.exec()) |
232 |
|
|
return; |
233 |
schoenebeck |
1492 |
|
234 |
|
|
// Commit... |
235 |
|
|
instrument.mapInstrument(); |
236 |
|
|
// add new item to the table model |
237 |
capela |
1509 |
m_model.resort(instrument); |
238 |
schoenebeck |
1492 |
// Notify we've changes... |
239 |
|
|
//emit model.reset(); |
240 |
|
|
//FIXME: call above didnt really refresh, so we use this for now ... |
241 |
|
|
refreshInstruments(); |
242 |
|
|
} |
243 |
|
|
|
244 |
|
|
|
245 |
capela |
1504 |
void InstrumentListForm::deleteInstrument (void) |
246 |
|
|
{ |
247 |
capela |
1509 |
const QModelIndex& index = m_ui.InstrumentTable->currentIndex(); |
248 |
capela |
1504 |
if (!index.isValid() || !index.data(Qt::UserRole).isValid()) |
249 |
|
|
return; |
250 |
|
|
|
251 |
schoenebeck |
1492 |
qsamplerInstrument* pInstrument = |
252 |
capela |
1504 |
static_cast<qsamplerInstrument*> ( |
253 |
|
|
index.data(Qt::UserRole).value<void *> ()); |
254 |
schoenebeck |
1492 |
|
255 |
capela |
1504 |
if (pInstrument == NULL) |
256 |
|
|
return; |
257 |
schoenebeck |
1492 |
|
258 |
|
|
pInstrument->unmapInstrument(); |
259 |
|
|
// let the instrument vanish from the table model |
260 |
capela |
1509 |
m_model.removeInstrument(*pInstrument); |
261 |
schoenebeck |
1492 |
// Notify we've changes... |
262 |
capela |
1509 |
emit m_model.reset(); |
263 |
schoenebeck |
1492 |
} |
264 |
|
|
|
265 |
schoenebeck |
1461 |
} // namespace QSampler |
266 |
capela |
1464 |
|
267 |
|
|
|
268 |
|
|
// end of qsamplerInstrumentListForm.cpp |