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