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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1492 - (show annotations) (download)
Mon Nov 19 21:08:18 2007 UTC (16 years, 5 months ago) by schoenebeck
File size: 6952 byte(s)
* Qt4 migration: finished MIDI instrument mapping dialogs, with this commit
  all the functionalities from the Qt3 version of qsampler are finally
  restored, only minor "cosmetical" things to fix now

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

  ViewVC Help
Powered by ViewVC