/[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 1492 by schoenebeck, Mon Nov 19 21:08:18 2007 UTC
# Line 22  Line 22 
22    
23  #include "qsamplerInstrumentListForm.h"  #include "qsamplerInstrumentListForm.h"
24    
25    #include "qsamplerInstrumentForm.h"
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27  #include "qsamplerOptions.h"  #include "qsamplerOptions.h"
28  #include "qsamplerInstrument.h"  #include "qsamplerInstrument.h"
# Line 30  Line 31 
31    
32  namespace QSampler {  namespace QSampler {
33    
34  InstrumentListForm::InstrumentListForm(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags) {  InstrumentListForm::InstrumentListForm ( QWidget* parent, Qt::WindowFlags flags )
35            : QMainWindow(parent, flags)
36    {
37      ui.setupUi(this);      ui.setupUi(this);
38    
39      ui.newInstrumentAction->setText(tr("New &Instrument..."));      ui.newInstrumentAction->setText(tr("New &Instrument..."));
# Line 43  InstrumentListForm::InstrumentListForm(Q Line 46  InstrumentListForm::InstrumentListForm(Q
46      ui.refreshInstrumentsAction->setShortcut(Qt::Key_F5);      ui.refreshInstrumentsAction->setShortcut(Qt::Key_F5);
47    
48      // Setup toolbar widgets.      // Setup toolbar widgets.
49      InstrumentToolbar = addToolBar(tr("MIDI Instruments"));      m_pMapComboBox = new QComboBox(ui.InstrumentToolbar);
     m_pMapComboBox = new QComboBox(InstrumentToolbar);  
50      m_pMapComboBox->setMinimumWidth(120);      m_pMapComboBox->setMinimumWidth(120);
51      m_pMapComboBox->setEnabled(false);      m_pMapComboBox->setEnabled(false);
52      QToolTip::add(m_pMapComboBox, tr("Instrument Map"));      QToolTip::add(m_pMapComboBox, tr("Instrument Map"));
53        ui.InstrumentToolbar->addWidget(m_pMapComboBox);
54    
55      InstrumentToolbar->addSeparator();      ui.InstrumentToolbar->addSeparator();
56      ui.newInstrumentAction->addTo(InstrumentToolbar);      ui.newInstrumentAction->addTo(ui.InstrumentToolbar);
57      ui.editInstrumentAction->addTo(InstrumentToolbar);      ui.editInstrumentAction->addTo(ui.InstrumentToolbar);
58      ui.deleteInstrumentAction->addTo(InstrumentToolbar);      ui.deleteInstrumentAction->addTo(ui.InstrumentToolbar);
59      InstrumentToolbar->addSeparator();      ui.InstrumentToolbar->addSeparator();
60      ui.refreshInstrumentsAction->addTo(InstrumentToolbar);      ui.refreshInstrumentsAction->addTo(ui.InstrumentToolbar);
61    
62      ui.InstrumentTable->setModel(&model);      ui.InstrumentTable->setModel(&model);
63      //ui.InstrumentTable->setDelegate(delegate);      ui.InstrumentTable->setItemDelegate(&delegate);
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    
69      connect(          QObject::connect(
70          ui.refreshInstrumentsAction,                  ui.refreshInstrumentsAction,
71          SIGNAL(triggered()), SLOT(refreshInstruments(void))                  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() {  InstrumentListForm::~InstrumentListForm() {
# Line 146  void InstrumentListForm::activateMap ( i Line 171  void InstrumentListForm::activateMap ( i
171          model.refresh();          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  } // namespace QSampler
247    
248    

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

  ViewVC Help
Powered by ViewVC