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

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

  ViewVC Help
Powered by ViewVC