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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1526 - (hide annotations) (download)
Mon Nov 26 10:58:23 2007 UTC (16 years, 4 months ago) by capela
File size: 7832 byte(s)
* Fixed crash on (All) instrument map list; instrument program number
  list display fix (off by one); header section
  widths are now arranged as in the Qt3 version.

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

  ViewVC Help
Powered by ViewVC