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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1499 - (show annotations) (download)
Tue Nov 20 16:48:04 2007 UTC (16 years, 5 months ago) by capela
File size: 6942 byte(s)
* Qt4 migration: one first step forward to kiss Qt3Support goodbye.

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

  ViewVC Help
Powered by ViewVC