/[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 1519 by capela, Sat Nov 24 13:06:19 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            m_ui.InstrumentTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
60    
61            m_ui.InstrumentTable->setModel(&m_model);
62            m_ui.InstrumentTable->setItemDelegate(&m_delegate);
63            m_ui.InstrumentTable->verticalHeader()->hide();
64    
65          QObject::connect(m_pMapComboBox,          QObject::connect(m_pMapComboBox,
66                  SIGNAL(activated(int)),                  SIGNAL(activated(int)),
67                  SLOT(activateMap(int)));                  SLOT(activateMap(int)));
68            QObject::connect(
69      connect(                  m_ui.refreshInstrumentsAction,
70          ui.refreshInstrumentsAction,                  SIGNAL(triggered()),
71          SIGNAL(triggered()), SLOT(refreshInstruments(void))                  SLOT(refreshInstruments(void)));
72      );          QObject::connect(
73                    m_ui.InstrumentTable,
74                    SIGNAL(activated(const QModelIndex&)),
75                    SLOT(editInstrument(const QModelIndex&)));
76            QObject::connect(
77                    m_ui.newInstrumentAction,
78                    SIGNAL(triggered()),
79                    SLOT(newInstrument()));
80            QObject::connect(
81                    m_ui.deleteInstrumentAction,
82                    SIGNAL(triggered()),
83                    SLOT(deleteInstrument()));
84            QObject::connect(
85                    m_ui.editInstrumentAction,
86                    SIGNAL(triggered()),
87                    SLOT(editInstrument()));
88    
89            MainForm *pMainForm = MainForm::getInstance();
90            if (pMainForm) {
91                    QObject::connect(&m_model,
92                            SIGNAL(instrumentsChanged()),
93                            pMainForm, SLOT(sessionDirty()));
94            }
95  }  }
96    
97  InstrumentListForm::~InstrumentListForm() {  
98    InstrumentListForm::~InstrumentListForm (void)
99    {
100          delete m_pMapComboBox;          delete m_pMapComboBox;
101  }  }
102    
# Line 77  InstrumentListForm::~InstrumentListForm( Line 104  InstrumentListForm::~InstrumentListForm(
104  // Notify our parent that we're emerging.  // Notify our parent that we're emerging.
105  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )  void InstrumentListForm::showEvent ( QShowEvent *pShowEvent )
106  {  {
107          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
108          //if (pMainForm)          if (pMainForm)
109          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
110    
111          QWidget::showEvent(pShowEvent);          QWidget::showEvent(pShowEvent);
112  }  }
# Line 90  void InstrumentListForm::hideEvent ( QHi Line 117  void InstrumentListForm::hideEvent ( QHi
117  {  {
118          QWidget::hideEvent(pHideEvent);          QWidget::hideEvent(pHideEvent);
119    
120          //MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
121          //if (pMainForm)          if (pMainForm)
122          //      pMainForm->stabilizeForm();                  pMainForm->stabilizeForm();
123    }
124    
125    
126    // Just about to notify main-window that we're closing.
127    void InstrumentListForm::closeEvent ( QCloseEvent * /*pCloseEvent*/ )
128    {
129            QWidget::hide();
130    
131            MainForm *pMainForm = MainForm::getInstance();
132            if (pMainForm)
133                    pMainForm->stabilizeForm();
134  }  }
135    
136    
# Line 108  void InstrumentListForm::refreshInstrume Line 146  void InstrumentListForm::refreshInstrume
146                  return;                  return;
147    
148          // Get/save current map selection...          // Get/save current map selection...
149          int iMap = m_pMapComboBox->currentItem();          int iMap = m_pMapComboBox->currentIndex();
150          if (iMap < 0 || m_pMapComboBox->count() < 2)          if (iMap < 0 || m_pMapComboBox->count() < 2)
151                  iMap = pOptions->iMidiMap + 1;                  iMap = pOptions->iMidiMap + 1;
152    
153          // Populate maps list.          // Populate maps list.
154          m_pMapComboBox->clear();          m_pMapComboBox->clear();
155          m_pMapComboBox->insertItem(tr("(All)"));          m_pMapComboBox->addItem(tr("(All)"));
156          m_pMapComboBox->insertStringList(qsamplerInstrument::getMapNames());          m_pMapComboBox->insertItems(1, qsamplerInstrument::getMapNames());
157    
158          // Adjust to saved selection...          // Adjust to saved selection...
159          if (iMap < 0 || iMap >= m_pMapComboBox->count())          if (iMap < 0 || iMap >= m_pMapComboBox->count())
160                  iMap = 0;                  iMap = 0;
161          m_pMapComboBox->setCurrentItem(iMap);          m_pMapComboBox->setCurrentIndex(iMap);
162          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);          m_pMapComboBox->setEnabled(m_pMapComboBox->count() > 1);
163    
164          activateMap(iMap);          activateMap(iMap);
# Line 142  void InstrumentListForm::activateMap ( i Line 180  void InstrumentListForm::activateMap ( i
180          if (iMidiMap >= 0)          if (iMidiMap >= 0)
181                  pOptions->iMidiMap = iMidiMap;                  pOptions->iMidiMap = iMidiMap;
182    
183          model.setMidiMap(iMidiMap);          m_model.setMidiMap(iMidiMap);
184          model.refresh();          m_model.refresh();
185    }
186    
187    
188    void InstrumentListForm::editInstrument (void)
189    {
190            editInstrument(m_ui.InstrumentTable->currentIndex());
191    }
192    
193    
194    void InstrumentListForm::editInstrument ( const QModelIndex& index )
195    {
196            if (!index.isValid() || !index.data(Qt::UserRole).isValid())
197                    return;
198    
199            qsamplerInstrument* pInstrument
200                    = static_cast<qsamplerInstrument *> (
201                            index.data(Qt::UserRole).value<void *> ());
202    
203            if (pInstrument == NULL)
204                    return;
205    
206            // Save current key values...
207            qsamplerInstrument oldInstrument(*pInstrument);
208            // Do the edit dance...
209            InstrumentForm form(this);
210            form.setup(pInstrument);
211            if (form.exec()) {
212                    // Commit...
213                    pInstrument->mapInstrument();
214                    // Check whether we changed instrument key...
215                    if (oldInstrument.map()  == pInstrument->map()  &&
216                            oldInstrument.bank() == pInstrument->bank() &&
217                            oldInstrument.prog() == pInstrument->prog()) {
218                            // just update tree item...
219                            //pItem->update();
220                    } else {
221                            // Unmap old instance...
222                            oldInstrument.unmapInstrument();
223                            // correct the position of the instrument in the model
224                            m_model.resort(*pInstrument);
225                    }
226                    // Notify we've changes...
227                    emit m_model.reset();
228            }
229    }
230    
231    
232    void InstrumentListForm::newInstrument (void)
233    {
234            qsamplerInstrument instrument;
235    
236            InstrumentForm form(this);
237            form.setup(&instrument);
238            if (!form.exec())
239                    return;
240    
241            // Commit...
242            instrument.mapInstrument();
243            // add new item to the table model
244            m_model.resort(instrument);
245            // Notify we've changes...
246            //emit model.reset();
247            //FIXME: call above didnt really refresh, so we use this for now ...
248            refreshInstruments();
249    }
250    
251    
252    void InstrumentListForm::deleteInstrument (void)
253    {
254            const QModelIndex& index = m_ui.InstrumentTable->currentIndex();
255            if (!index.isValid() || !index.data(Qt::UserRole).isValid())
256                    return;
257    
258            qsamplerInstrument* pInstrument =
259                    static_cast<qsamplerInstrument*> (
260                            index.data(Qt::UserRole).value<void *> ());
261    
262            if (pInstrument == NULL)
263                    return;
264    
265            pInstrument->unmapInstrument();
266            // let the instrument vanish from the table model
267            m_model.removeInstrument(*pInstrument);
268            // Notify we've changes...
269            emit m_model.reset();
270  }  }
271    
272  } // namespace QSampler  } // namespace QSampler

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

  ViewVC Help
Powered by ViewVC