/[svn]/qsampler/trunk/src/qsamplerInstrumentListForm.cpp
ViewVC logotype

Annotation of /qsampler/trunk/src/qsamplerInstrumentListForm.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2065 - (hide annotations) (download)
Sat Mar 13 12:44:15 2010 UTC (9 years, 11 months ago) by capela
File size: 8522 byte(s)
* Automatic crash-dump reports, debugger stack-traces (gdb), back-
  traces, whatever, are being introduced as a brand new configure
  option (--enable-stacktrace) and default enabled on debug build
  targets (--enable-debug).

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 capela 2065 m_pMapComboBox = new QComboBox(m_ui.instrumentToolbar);
52 capela 1509 m_pMapComboBox->setMinimumWidth(120);
53     m_pMapComboBox->setEnabled(false);
54     m_pMapComboBox->setToolTip(tr("Instrument Map"));
55 capela 2065 m_ui.instrumentToolbar->addWidget(m_pMapComboBox);
56 schoenebeck 1461
57 capela 2065 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     m_pInstrumentListView->setContextMenuPolicy(Qt::CustomContextMenu);
66     QMainWindow::setCentralWidget(m_pInstrumentListView);
67    
68 schoenebeck 1461 QObject::connect(m_pMapComboBox,
69     SIGNAL(activated(int)),
70     SLOT(activateMap(int)));
71 capela 1466 QObject::connect(
72 capela 2064 m_pInstrumentListView,
73 capela 1528 SIGNAL(customContextMenuRequested(const QPoint&)),
74     SLOT(contextMenu(const QPoint&)));
75 capela 1504 QObject::connect(
76 capela 2064 m_pInstrumentListView,
77 capela 2065 SIGNAL(activated(const QModelIndex&)),
78 capela 1528 SLOT(stabilizeForm()));
79     QObject::connect(
80 capela 2064 m_pInstrumentListView,
81 capela 2065 SIGNAL(doubleClicked(const QModelIndex&)),
82 capela 1509 SLOT(editInstrument(const QModelIndex&)));
83 capela 1504 QObject::connect(
84 capela 1509 m_ui.newInstrumentAction,
85 schoenebeck 1492 SIGNAL(triggered()),
86 capela 1509 SLOT(newInstrument()));
87 capela 1504 QObject::connect(
88 capela 1509 m_ui.deleteInstrumentAction,
89 schoenebeck 1492 SIGNAL(triggered()),
90 capela 1509 SLOT(deleteInstrument()));
91 capela 1504 QObject::connect(
92 capela 1509 m_ui.editInstrumentAction,
93 schoenebeck 1492 SIGNAL(triggered()),
94 capela 1509 SLOT(editInstrument()));
95 capela 1528 QObject::connect(
96     m_ui.refreshInstrumentsAction,
97     SIGNAL(triggered()),
98     SLOT(refreshInstruments()));
99 capela 1509
100 capela 1528 // Things must be stable from the start.
101     stabilizeForm();
102 schoenebeck 1461 }
103    
104 capela 1504
105     InstrumentListForm::~InstrumentListForm (void)
106     {
107 capela 2064 delete m_pInstrumentListView;
108 schoenebeck 1461 delete m_pMapComboBox;
109     }
110    
111    
112     // Notify our parent that we're emerging.
113     void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
114     {
115 capela 1504 MainForm* pMainForm = MainForm::getInstance();
116     if (pMainForm)
117     pMainForm->stabilizeForm();
118 schoenebeck 1461
119     QWidget::showEvent(pShowEvent);
120     }
121    
122    
123     // Notify our parent that we're closing.
124     void InstrumentListForm::hideEvent ( QHideEvent *pHideEvent )
125     {
126     QWidget::hideEvent(pHideEvent);
127    
128 capela 1504 MainForm* pMainForm = MainForm::getInstance();
129     if (pMainForm)
130     pMainForm->stabilizeForm();
131 schoenebeck 1461 }
132    
133    
134 capela 1504 // Just about to notify main-window that we're closing.
135     void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ )
136     {
137     QWidget::hide();
138    
139     MainForm *pMainForm = MainForm::getInstance();
140     if (pMainForm)
141     pMainForm->stabilizeForm();
142     }
143    
144    
145 schoenebeck 1461 // Refresh all instrument list and views.
146     void InstrumentListForm::refreshInstruments (void)
147     {
148     MainForm* pMainForm = MainForm::getInstance();
149     if (pMainForm == NULL)
150     return;
151    
152 capela 1558 Options *pOptions = pMainForm->options();
153 schoenebeck 1461 if (pOptions == NULL)
154     return;
155    
156     // Get/save current map selection...
157 capela 1499 int iMap = m_pMapComboBox->currentIndex();
158 schoenebeck 1461 if (iMap < 0 || m_pMapComboBox->count() < 2)
159     iMap = pOptions->iMidiMap + 1;
160    
161     // Populate maps list.
162     m_pMapComboBox->clear();
163 capela 1499 m_pMapComboBox->addItem(tr("(All)"));
164 capela 1558 m_pMapComboBox->insertItems(1, Instrument::getMapNames());
165 schoenebeck 1461
166     // Adjust to saved selection...
167     if (iMap < 0 || iMap >= m_pMapComboBox->count())
168     iMap = 0;
169 capela 1499 m_pMapComboBox->setCurrentIndex(iMap);
170 schoenebeck 1461 m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);
171    
172     activateMap(iMap);
173     }
174    
175    
176     // Refresh instrument maps selector.
177     void InstrumentListForm::activateMap ( int iMap )
178     {
179     MainForm* pMainForm = MainForm::getInstance();
180     if (pMainForm == NULL)
181     return;
182    
183 capela 1558 Options *pOptions = pMainForm->options();
184 schoenebeck 1461 if (pOptions == NULL)
185     return;
186    
187     int iMidiMap = iMap - 1;
188     if (iMidiMap >= 0)
189     pOptions->iMidiMap = iMidiMap;
190    
191 capela 2064 m_pInstrumentListView->setMidiMap(iMidiMap);
192     m_pInstrumentListView->refresh();
193 capela 1528
194     stabilizeForm();
195 schoenebeck 1461 }
196    
197 capela 1504
198     void InstrumentListForm::editInstrument (void)
199     {
200 capela 2064 editInstrument(m_pInstrumentListView->currentIndex());
201 schoenebeck 1492 }
202    
203 capela 1504
204     void InstrumentListForm::editInstrument ( const QModelIndex& index )
205     {
206 capela 2064 if (!index.isValid())
207 schoenebeck 1492 return;
208    
209 capela 2064 Instrument *pInstrument
210     = static_cast<Instrument *> (index.internalPointer());
211     if (pInstrument == NULL)
212     return;
213 schoenebeck 1492
214     // Save current key values...
215 capela 2065 int iMap = pInstrument->map();
216     int iBank = pInstrument->bank();
217     int iProg = pInstrument->prog();
218 capela 2064
219 capela 2065 Instrument instrument(iMap, iBank, iProg);
220    
221 schoenebeck 1492 // Do the edit dance...
222     InstrumentForm form(this);
223 capela 2065 form.setup(&instrument);
224 schoenebeck 1492 if (form.exec()) {
225     // Commit...
226 capela 2065 instrument.mapInstrument();
227 schoenebeck 1492 // Check whether we changed instrument key...
228 capela 2065 if (instrument.map() == iMap &&
229     instrument.bank() == iBank &&
230     instrument.prog() == iProg) {
231 capela 1523 // Just update tree item...
232 schoenebeck 1492 //pItem->update();
233     } else {
234     // Unmap old instance...
235 capela 2065 Instrument(iMap, iBank, iProg).unmapInstrument();
236 schoenebeck 1492 // correct the position of the instrument in the model
237 capela 2064 m_pInstrumentListView->updateInstrument(pInstrument);
238 schoenebeck 1492 }
239     }
240 capela 2065
241     stabilizeForm();
242 schoenebeck 1492 }
243    
244 capela 1504
245     void InstrumentListForm::newInstrument (void)
246     {
247 capela 1558 Instrument instrument;
248 schoenebeck 1492
249     InstrumentForm form(this);
250     form.setup(&instrument);
251 capela 1504 if (!form.exec())
252     return;
253 schoenebeck 1492
254     // Commit...
255     instrument.mapInstrument();
256 capela 2064
257 schoenebeck 1492 // add new item to the table model
258 capela 2064 m_pInstrumentListView->addInstrument(
259     instrument.map(),
260     instrument.bank(),
261     instrument.prog());
262 capela 2065
263     stabilizeForm();
264 schoenebeck 1492 }
265    
266    
267 capela 1504 void InstrumentListForm::deleteInstrument (void)
268     {
269 capela 2064 const QModelIndex& index = m_pInstrumentListView->currentIndex();
270     if (!index.isValid())
271 capela 1504 return;
272    
273 capela 2064 Instrument *pInstrument
274     = static_cast<Instrument *> (index.internalPointer());
275 capela 1504 if (pInstrument == NULL)
276     return;
277 schoenebeck 1492
278 capela 1528 MainForm *pMainForm = MainForm::getInstance();
279     if (pMainForm == NULL)
280     return;
281    
282     // Prompt user if this is for real...
283 capela 1558 Options *pOptions = pMainForm->options();
284 capela 1528 if (pOptions && pOptions->bConfirmRemove) {
285     if (QMessageBox::warning(this,
286     QSAMPLER_TITLE ": " + tr("Warning"),
287     tr("About to delete instrument map entry:\n\n"
288     "%1\n\n"
289     "Are you sure?")
290     .arg(pInstrument->name()),
291 capela 1840 QMessageBox::Ok | QMessageBox::Cancel)
292     == QMessageBox::Cancel)
293 capela 1528 return;
294     }
295    
296 schoenebeck 1492 pInstrument->unmapInstrument();
297 capela 2064
298 schoenebeck 1492 // let the instrument vanish from the table model
299 capela 2064 m_pInstrumentListView->removeInstrument(pInstrument);
300 capela 2065
301     stabilizeForm();
302 schoenebeck 1492 }
303    
304 capela 1528
305     // Update form actions enablement...
306     void InstrumentListForm::stabilizeForm (void)
307     {
308     MainForm *pMainForm = MainForm::getInstance();
309    
310     bool bEnabled = (pMainForm && pMainForm->client());
311     m_ui.newInstrumentAction->setEnabled(bEnabled);
312 capela 2064 const QModelIndex& index = m_pInstrumentListView->currentIndex();
313 capela 1528 bEnabled = (bEnabled && index.isValid());
314     m_ui.editInstrumentAction->setEnabled(bEnabled);
315     m_ui.deleteInstrumentAction->setEnabled(bEnabled);
316     }
317    
318    
319     // Handle custom context menu here...
320     void InstrumentListForm::contextMenu ( const QPoint& pos )
321     {
322     if (!m_ui.newInstrumentAction->isEnabled())
323     return;
324    
325     m_ui.contextMenu->exec(
326 capela 2064 (m_pInstrumentListView->viewport())->mapToGlobal(pos));
327 capela 1528 }
328    
329    
330 schoenebeck 1461 } // namespace QSampler
331 capela 1464
332    
333     // end of qsamplerInstrumentListForm.cpp

  ViewVC Help
Powered by ViewVC