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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1464 by capela, Thu Nov 1 17:14:21 2007 UTC revision 1526 by capela, Mon Nov 26 10:58:23 2007 UTC
# Line 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24  #include "qsamplerInstrumentListForm.h"  #include "qsamplerInstrumentListForm.h"
25    
26  #include "qsamplerMainForm.h"  #include "qsamplerInstrumentForm.h"
27    
28  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
29  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
30    #include "qsamplerMainForm.h"
31    
32  #include <QToolTip>  #include <QHeaderView>
33    
 namespace QSampler {  
34    
35  InstrumentListForm::InstrumentListForm(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) {  namespace QSampler {
     ui.setupUi(this);  
36    
37      ui.newInstrumentAction->setText(tr("New &Instrument..."));  InstrumentListForm::InstrumentListForm (
38      ui.newInstrumentAction->setShortcut(Qt::Key_Insert);          QWidget* pParent, Qt::WindowFlags wflags )
39      ui.editInstrumentAction->setText(tr("&Edit..."));          : QMainWindow(pParent, wflags)
40      ui.editInstrumentAction->setShortcut(Qt::Key_Enter);  {
41      ui.deleteInstrumentAction->setText(tr("&Delete"));          m_ui.setupUi(this);
     ui.deleteInstrumentAction->setShortcut(Qt::Key_Delete);  
     ui.refreshInstrumentsAction->setText(tr("&Refresh"));  
     ui.refreshInstrumentsAction->setShortcut(Qt::Key_F5);  
   
     // Setup toolbar widgets.  
     InstrumentToolbar = addToolBar(tr("MIDI Instruments"));  
     m_pMapComboBox = new QComboBox(InstrumentToolbar);  
     m_pMapComboBox->setMinimumWidth(120);  
     m_pMapComboBox->setEnabled(false);  
     QToolTip::add(m_pMapComboBox, tr("Instrument Map"));  
   
     InstrumentToolbar->addSeparator();  
     ui.newInstrumentAction->addTo(InstrumentToolbar);  
     ui.editInstrumentAction->addTo(InstrumentToolbar);  
     ui.deleteInstrumentAction->addTo(InstrumentToolbar);  
     InstrumentToolbar->addSeparator();  
     ui.refreshInstrumentsAction->addTo(InstrumentToolbar);  
42    
43      ui.InstrumentTable->setModel(&model);          // Setup toolbar widgets.
44      //ui.InstrumentTable->setDelegate(delegate);          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    
50            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    
57            int iRowHeight = m_ui.InstrumentTable->fontMetrics().height() + 4;
58            m_ui.InstrumentTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
59    
60            m_ui.InstrumentTable->setModel(&m_model);
61            m_ui.InstrumentTable->setItemDelegate(&m_delegate);
62            m_ui.InstrumentTable->verticalHeader()->hide();
63    
64            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          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
78                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
79                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
80            QObject::connect(
81      connect(                  m_ui.refreshInstrumentsAction,
82          ui.refreshInstrumentsAction,                  SIGNAL(triggered()),
83          SIGNAL(triggered()), SLOT(refreshInstruments(void))                  SLOT(refreshInstruments(void)));
84      );          QObject::connect(
85                    m_ui.InstrumentTable,
86                    SIGNAL(activated(const QModelIndex&)),
87                    SLOT(editInstrument(const QModelIndex&)));
88            QObject::connect(
89                    m_ui.newInstrumentAction,
90                    SIGNAL(triggered()),
91                    SLOT(newInstrument()));
92            QObject::connect(
93                    m_ui.deleteInstrumentAction,
94                    SIGNAL(triggered()),
95                    SLOT(deleteInstrument()));
96            QObject::connect(
97                    m_ui.editInstrumentAction,
98                    SIGNAL(triggered()),
99                    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  }  }
108    
109  InstrumentListForm::~InstrumentListForm() {  
110    InstrumentListForm::~InstrumentListForm (void)
111    {
112          delete m_pMapComboBox;          delete m_pMapComboBox;
113  }  }
114    
# Line 77  InstrumentListForm::~InstrumentListForm( Line 116  InstrumentListForm::~InstrumentListForm(
116  // Notify our parent that we're emerging.  // Notify our parent that we're emerging.
117  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
118  {  {
119          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
120          //if (pMainForm)          if (pMainForm)
121          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
122    
123          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
124  }  }
# Line 90  void InstrumentListForm::hideEvent ( QHi Line 129  void InstrumentListForm::hideEvent ( QHi
129  {  {
130          QWidget::hideEvent(pHideEvent);          QWidget::hideEvent(pHideEvent);
131    
132          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
133          //if (pMainForm)          if (pMainForm)
134          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
135    }
136    
137    
138    // 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    
# Line 108  void InstrumentListForm::refreshInstrume Line 158  void InstrumentListForm::refreshInstrume
158                  return;                  return;
159    
160          // Get/save current map selection...          // Get/save current map selection...
161          int iMap = m_pMapComboBox->currentItem();          int iMap = m_pMapComboBox->currentIndex();
162          if (iMap < 0 || m_pMapComboBox->count() < 2)          if (iMap < 0 || m_pMapComboBox->count() < 2)
163                  iMap = pOptions->iMidiMap + 1;                  iMap = pOptions->iMidiMap + 1;
164    
165          // Populate maps list.          // Populate maps list.
166          m_pMapComboBox->clear();          m_pMapComboBox->clear();
167          m_pMapComboBox->insertItem(tr("(All)"));          m_pMapComboBox->addItem(tr("(All)"));
168          m_pMapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames());
169    
170          // Adjust to saved selection...          // Adjust to saved selection...
171          if (iMap < 0 || iMap >= m_pMapComboBox->count())          if (iMap < 0 || iMap >= m_pMapComboBox->count())
172                  iMap = 0;                  iMap = 0;
173          m_pMapComboBox->setCurrentItem(iMap);          m_pMapComboBox->setCurrentIndex(iMap);
174          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);
175    
176          activateMap(iMap);          activateMap(iMap);
# Line 142  void InstrumentListForm::activateMap ( i Line 192  void InstrumentListForm::activateMap ( i
192          if (iMidiMap >= 0)          if (iMidiMap >= 0)
193                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
194    
195          model.setMidiMap(iMidiMap);          m_model.setMidiMap(iMidiMap);
196          model.refresh();          m_model.refresh();
197    }
198    
199    
200    void InstrumentListForm::editInstrument (void)
201    {
202            editInstrument(m_ui.InstrumentTable->currentIndex());
203    }
204    
205    
206    void InstrumentListForm::editInstrument ( const QModelIndex& index )
207    {
208            if (!index.isValid() || !index.data(Qt::UserRole).isValid())
209                    return;
210    
211            qsamplerInstrument* pInstrument
212                    = static_cast<qsamplerInstrument *> (
213                            index.data(Qt::UserRole).value<void *> ());
214    
215            if (pInstrument == NULL)
216                    return;
217    
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                            // Just update tree item...
231                            //pItem->update();
232                    } else {
233                            // Unmap old instance...
234                            oldInstrument.unmapInstrument();
235                            // correct the position of the instrument in the model
236                            m_model.resort(*pInstrument);
237                    }
238                    // Notify we've changes...
239                    emit m_model.reset();
240            }
241    }
242    
243    
244    void InstrumentListForm::newInstrument (void)
245    {
246            qsamplerInstrument instrument;
247    
248            InstrumentForm form(this);
249            form.setup(&instrument);
250            if (!form.exec())
251                    return;
252    
253            // Commit...
254            instrument.mapInstrument();
255            // add new item to the table model
256            m_model.resort(instrument);
257            // 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    void InstrumentListForm::deleteInstrument (void)
265    {
266            const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
267            if (!index.isValid() || !index.data(Qt::UserRole).isValid())
268                    return;
269    
270            qsamplerInstrument* pInstrument =
271                    static_cast<qsamplerInstrument*> (
272                            index.data(Qt::UserRole).value<void *> ());
273    
274            if (pInstrument == NULL)
275                    return;
276    
277            pInstrument->unmapInstrument();
278            // let the instrument vanish from the table model
279            m_model.removeInstrument(*pInstrument);
280            // Notify we've changes...
281            emit m_model.reset();
282  }  }
283    
284  } // namespace QSampler  } // namespace QSampler

Legend:
Removed from v.1464  
changed lines
  Added in v.1526

  ViewVC Help
Powered by ViewVC