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

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

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

revision 1667 by schoenebeck, Mon Feb 4 23:24:19 2008 UTC revision 2459 by capela, Mon Jul 8 10:06:57 2013 UTC
# Line 1  Line 1 
1  // qsamplerChannelFxForm.cpp  // qsamplerChannelFxForm.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4       Copyright (C) 2010-2013, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2008, Christian Schoenebeck     Copyright (C) 2008, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 13  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
# Line 23  Line 24 
24  #include "qsamplerChannelFxForm.h"  #include "qsamplerChannelFxForm.h"
25  #include "qsamplerFxSendsModel.h"  #include "qsamplerFxSendsModel.h"
26    
27    // let's not reinvent the wheel for audio routing
28    #include "qsamplerChannel.h"
29    
30    #include <math.h>
31    
32  #include <QAbstractButton>  #include <QAbstractButton>
33    #include <QLineEdit>
34    #include <QHeaderView>
35    #include <QMap>
36    
37    namespace { // private namespace
38    
39    static const char* _midiControllerName(int iMidiCtrl) {
40            switch (iMidiCtrl) {
41                    case 0:   return "Bank select MSB";
42                    case 1:   return "Modulation MSB";
43                    case 2:   return "Breath Controller";
44                    case 4:   return "Foot Controller MSB";
45                    case 5:   return "Portamento Time MSB";
46                    case 6:   return "(N)RPN Data Byte";
47                    case 7:   return "Main Volume";
48                    case 8:   return "Balance";
49                    case 10:  return "Panorama";
50                    case 11:  return "Expression";
51                    case 12:  return "Effect Control 1";
52                    case 13:  return "Effect Control 2";
53                    case 16:  return "General Purpose Controller 1";
54                    case 17:  return "General Purpose Controller 2";
55                    case 18:  return "General Purpose Controller 3";
56                    case 19:  return "General Purpose Controller 4";
57                    case 32:  return "Bank select LSB";
58                    case 63:  return "LSB for Controllers 0?31";
59                    case 64:  return "Hold 1";
60                    case 65:  return "Portamento";
61                    case 66:  return "Sostenuto";
62                    case 67:  return "Soft Pedal";
63                    case 68:  return "Legato Footswitch";
64                    case 69:  return "Hold 2";
65                    case 70:  return "Sound Controller 1 (Sound Variation)";
66                    case 71:  return "Sound Controller 2 (Harmonic Content)";
67                    case 72:  return "Sound Controller 3 (Release Time)";
68                    case 73:  return "Sound Controller 4 (Attack Time)";
69                    case 74:  return "Sound Controller 5 (Brightness)";
70                    case 75:  return "Sound Controller 6";
71                    case 76:  return "Sound Controller 7";
72                    case 77:  return "Sound Controller 8";
73                    case 78:  return "Sound Controller 9";
74                    case 79:  return "Sound Controller 10";
75                    case 80:  return "General Purpose 5";
76                    case 81:  return "General Purpose 6";
77                    case 82:  return "General Purpose 7";
78                    case 83:  return "General Purpose 8";
79                    case 84:  return "Portamento Control";
80                    case 91:  return "Effects 1 Depth";
81                    case 92:  return "Effects 2 Depth";
82                    case 93:  return "Effects 3 Depth";
83                    case 94:  return "Effects 4 Depth";
84                    case 95:  return "Effects 5 Depth";
85                    case 96:  return "Data Increment (N)RPN";
86                    case 97:  return "Data Decrement (N)RPN";
87                    case 98:  return "NRPN LSB";
88                    case 99:  return "NRPN MSB";
89                    case 100: return "RPN LSB";
90                    case 101: return "RPN MSB";
91                    case 120: return "All Sounds Off";
92                    case 121: return "Controller Reset";
93                    case 122: return "Local Control on/off";
94                    case 123: return "All Notes Off";
95                    case 124: return "Omni Off";
96                    case 125: return "Omni On";
97                    case 126: return "Mono On / Poly Off";
98                    case 127: return "Poly On / Mono Off";
99                    default: return "";
100            }
101    }
102    
103    } // private namespace
104    
105    
106  namespace QSampler {  namespace QSampler {
107    
108  ChannelFxForm::ChannelFxForm (  ChannelFxForm::ChannelFxForm (
109          int SamplerChannelID, QWidget* pParent, Qt::WindowFlags wflags )          Channel* pSamplerChannel, QWidget* pParent, Qt::WindowFlags wflags )
110          : QDialog(pParent, wflags)          : QDialog(pParent, wflags)
111  {  {
112          m_ui.setupUi(this);          m_ui.setupUi(this);
113    
114          m_SamplerChannelID = SamplerChannelID;          m_pSamplerChannel = pSamplerChannel;
115    
116            m_pAudioDevice = NULL;
117    
118          FxSendsModel* pModel =          FxSendsModel* pModel =
119                  new FxSendsModel(SamplerChannelID, m_ui.SendsListView);                  new FxSendsModel(m_pSamplerChannel->channelID(), m_ui.SendsListView);
120          m_ui.SendsListView->setModel(pModel);          m_ui.SendsListView->setModel(pModel);
121            m_ui.SendsListView->setSelectionRectVisible(true);
122    
123            const int iRowHeight = m_ui.audioRoutingTable->fontMetrics().height() + 4;
124            m_ui.audioRoutingTable->verticalHeader()->setDefaultSectionSize(iRowHeight);
125            m_ui.audioRoutingTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft);
126            ChannelRoutingModel* pRoutingModel =
127                    new ChannelRoutingModel(m_ui.audioRoutingTable);
128            m_ui.audioRoutingTable->setModel(pRoutingModel);
129            ChannelRoutingDelegate* pRoutingDelegate =
130                    new ChannelRoutingDelegate(m_ui.audioRoutingTable);
131            m_ui.audioRoutingTable->setItemDelegate(pRoutingDelegate);
132    #if QT_VERSION >= 0x050000
133            m_ui.audioRoutingTable->horizontalHeader()->setSectionResizeMode(0, QHeaderView::Stretch);
134    #else
135            m_ui.audioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch);
136    #endif
137    //      m_ui.audioRoutingTable->verticalHeader()->hide();
138    
139          QAbstractButton* pApplyButton =          QAbstractButton* pApplyButton =
140                  m_ui.buttonBox->button(QDialogButtonBox::Apply);                  m_ui.buttonBox->button(QDialogButtonBox::Apply);
141          pApplyButton->setEnabled(false);          pApplyButton->setEnabled(false);
142          pApplyButton->setIcon(QIcon(":/icons/formEdit.png"));          pApplyButton->setIcon(QIcon(":/images/formEdit.png"));
143    
144          QAbstractButton* pCancelButton =          QAbstractButton* pCancelButton =
145                  m_ui.buttonBox->button(QDialogButtonBox::Cancel);                  m_ui.buttonBox->button(QDialogButtonBox::Cancel);
146          pCancelButton->setIcon(QIcon(":/icons/formRemove.png"));          pCancelButton->setIcon(QIcon(":/images/formRemove.png"));
147    
148          QAbstractButton* pOkButton =          QAbstractButton* pOkButton =
149                  m_ui.buttonBox->button(QDialogButtonBox::Ok);                  m_ui.buttonBox->button(QDialogButtonBox::Ok);
150          pOkButton->setIcon(QIcon(":/icons/formAccept.png"));          pOkButton->setIcon(QIcon(":/images/formAccept.png"));
151    
152          QAbstractButton* pResetButton =          QAbstractButton* pResetButton =
153                  m_ui.buttonBox->button(QDialogButtonBox::Reset);                  m_ui.buttonBox->button(QDialogButtonBox::Reset);
154          pResetButton->setEnabled(false);          pResetButton->setEnabled(false);
155            pResetButton->setToolTip("Revert all changes.");
156    
157          m_ui.destroyPushButton->setEnabled(false);          m_ui.destroyPushButton->setEnabled(false);
158    
159            m_ui.mainParametersGroupBox->setEnabled(false);
160            m_ui.audioRoutingGroupBox->setEnabled(false);
161    
162            for (int i = 0; i < 128; ++i) {
163                    m_ui.depthCtrlComboBox->addItem(
164                            QString("[") + QString::number(i) + "] " + _midiControllerName(i)
165                    );
166            }
167    
168          connect(          connect(
169                  m_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)),                  m_ui.buttonBox, SIGNAL(clicked(QAbstractButton*)),
170                  this, SLOT(onButtonClicked(QAbstractButton*))                  this, SLOT(onButtonClicked(QAbstractButton*))
# Line 82  ChannelFxForm::ChannelFxForm ( Line 189  ChannelFxForm::ChannelFxForm (
189                  m_ui.SendsListView, SIGNAL(clicked(const QModelIndex&)),                  m_ui.SendsListView, SIGNAL(clicked(const QModelIndex&)),
190                  this, SLOT(onFxSendSelection(const QModelIndex&))                  this, SLOT(onFxSendSelection(const QModelIndex&))
191          );          );
192            connect(
193                    m_ui.depthCtrlComboBox, SIGNAL(activated(int)),
194                    this, SLOT(onDepthCtrlChanged(int))
195            );
196            connect(
197                    m_ui.depthSpinBox, SIGNAL(valueChanged(int)),
198                    this, SLOT(onCurrentSendDepthChanged(int))
199            );
200            connect(
201                    pRoutingModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
202                    this, SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&))
203            );
204            connect(
205                    pRoutingModel, SIGNAL(modelReset()),
206                    this, SLOT(updateTableCellRenderers())
207            );
208            connect(
209                    pRoutingModel, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)),
210                    this, SLOT(onRoutingTableChanged())
211            );
212  }  }
213    
214  ChannelFxForm::~ChannelFxForm() {  ChannelFxForm::~ChannelFxForm() {
215            if (m_pAudioDevice) delete m_pAudioDevice;
216  }  }
217    
218  void ChannelFxForm::onButtonClicked(QAbstractButton* button) {  void ChannelFxForm::onButtonClicked(QAbstractButton* button) {
# Line 93  void ChannelFxForm::onButtonClicked(QAbs Line 221  void ChannelFxForm::onButtonClicked(QAbs
221                  case QDialogButtonBox::AcceptRole:                  case QDialogButtonBox::AcceptRole:
222                  case QDialogButtonBox::ApplyRole:                  case QDialogButtonBox::ApplyRole:
223                          pModel->applyToSampler();                          pModel->applyToSampler();
224                            // force a refresh of the parameter control elements
225                            onFxSendSelection(m_ui.SendsListView->currentIndex());
226                          break;                          break;
227                  case QDialogButtonBox::ResetRole:                  case QDialogButtonBox::ResetRole:
228                          pModel->cleanRefresh();                          pModel->cleanRefresh();
229                            // force a refresh of the parameter control elements
230                            onFxSendSelection(m_ui.SendsListView->currentIndex());
231                          break;                          break;
232                  default: // to avoid gcc warnings                  default: // to avoid gcc warnings
233                          break;                          break;
# Line 103  void ChannelFxForm::onButtonClicked(QAbs Line 235  void ChannelFxForm::onButtonClicked(QAbs
235  }  }
236    
237  void ChannelFxForm::onFxSendSelection(const QModelIndex& index) {  void ChannelFxForm::onFxSendSelection(const QModelIndex& index) {
238          m_ui.destroyPushButton->setEnabled(index.isValid());          const bool bValid = index.isValid();
239            m_ui.destroyPushButton->setEnabled(bValid);
240            m_ui.mainParametersGroupBox->setEnabled(bValid);
241            m_ui.audioRoutingGroupBox->setEnabled(bValid);
242    
243            FxSendsModel* pModel = (FxSendsModel*) m_ui.SendsListView->model();
244            FxSend* pFxSend = pModel->fxSend(index);
245    
246            // clear routing model
247            ChannelRoutingModel* pRoutingModel =
248                    (ChannelRoutingModel*) m_ui.audioRoutingTable->model();
249            pRoutingModel->refresh(NULL, ChannelRoutingMap());
250            pRoutingModel->routingMap().clear(); // Reset routing change map.
251            if (m_pAudioDevice) {
252                    delete m_pAudioDevice;
253                    m_pAudioDevice = NULL;
254            }
255    
256            if (!pFxSend) return;
257    
258            // update routing model
259            if (m_pSamplerChannel->audioDevice() >= 0) {
260                    m_pAudioDevice =
261                            new Device(Device::Audio, m_pSamplerChannel->audioDevice());
262                    pRoutingModel->refresh(m_pAudioDevice, pFxSend->audioRouting());
263            }
264    
265            m_ui.depthCtrlComboBox->setCurrentIndex(pFxSend->sendDepthMidiCtrl());
266            m_ui.depthSpinBox->setValue(
267                    int(::round(pFxSend->currentDepth() * 100.0))
268            );
269  }  }
270    
271  void ChannelFxForm::onCreateFxSend() {  void ChannelFxForm::onCreateFxSend() {
# Line 116  void ChannelFxForm::onDestroyFxSend() { Line 278  void ChannelFxForm::onDestroyFxSend() {
278          pModel->removeFxSend(m_ui.SendsListView->currentIndex());          pModel->removeFxSend(m_ui.SendsListView->currentIndex());
279  }  }
280    
281    void ChannelFxForm::onDepthCtrlChanged(int iMidiCtrl) {
282            FxSendsModel* pModel = (FxSendsModel*) m_ui.SendsListView->model();
283            const QModelIndex index = m_ui.SendsListView->currentIndex();
284            FxSend* pFxSend = pModel->fxSend(index);
285            if (!pFxSend) return;
286    
287            pFxSend->setSendDepthMidiCtrl(iMidiCtrl);
288            pModel->onExternalModifiication(index);
289    }
290    
291    void ChannelFxForm::onCurrentSendDepthChanged(int depthPercent) {
292            FxSendsModel* pModel = (FxSendsModel*) m_ui.SendsListView->model();
293            const QModelIndex index = m_ui.SendsListView->currentIndex();
294            FxSend* pFxSend = pModel->fxSend(index);
295            if (!pFxSend) return;
296    
297            if (depthPercent == int( ::round(pFxSend->currentDepth() * 100.0) ))
298                    return; // nothing changed actually
299    
300            pFxSend->setCurrentDepth(double(depthPercent) / 100.0);
301            pModel->onExternalModifiication(index);
302    }
303    
304    void ChannelFxForm::onRoutingTableChanged() {
305            ChannelRoutingModel* pRoutingModel =
306                    (ChannelRoutingModel*) m_ui.audioRoutingTable->model();
307            if (pRoutingModel->routingMap().size() <= 0)
308                    return; // no changes
309    
310            FxSendsModel* pModel = (FxSendsModel*) m_ui.SendsListView->model();
311            const QModelIndex index = m_ui.SendsListView->currentIndex();
312            FxSend* pFxSend = pModel->fxSend(index);
313            if (!pFxSend) {
314                    pRoutingModel->routingMap().clear(); // reset routing change map
315                    return;
316            }
317    
318            ChannelRoutingMap routingMap = pRoutingModel->routingMap();
319            for (
320                    ChannelRoutingMap::iterator iter = routingMap.begin();
321                    iter != routingMap.end(); ++iter
322            ) pFxSend->setAudioChannel(iter.key(), iter.value());
323    
324            pRoutingModel->routingMap().clear(); // reset routing change map
325    
326            pModel->onExternalModifiication(index);
327    }
328    
329    void ChannelFxForm::updateTableCellRenderers() {
330            ChannelRoutingModel* pRoutingModel =
331                    (ChannelRoutingModel*) m_ui.audioRoutingTable->model();
332            const int rows = pRoutingModel->rowCount();
333            const int cols = pRoutingModel->columnCount();
334            updateTableCellRenderers(
335                    pRoutingModel->index(0, 0),
336                    pRoutingModel->index(rows - 1, cols - 1)
337            );
338    }
339    
340    void ChannelFxForm::updateTableCellRenderers (
341            const QModelIndex& topLeft, const QModelIndex& bottomRight )
342    {
343            ChannelRoutingModel* pRoutingModel =
344                    (ChannelRoutingModel*) m_ui.audioRoutingTable->model();
345            for (int r = topLeft.row(); r <= bottomRight.row(); r++) {
346                    for (int c = topLeft.column(); c <= bottomRight.column(); c++) {
347                            const QModelIndex index = pRoutingModel->index(r, c);
348                            m_ui.audioRoutingTable->openPersistentEditor(index);
349                    }
350            }
351    }
352    
353  } // namespace QSampler  } // namespace QSampler
354    
355  // end of qsamplerChannelFxForm.cpp  // end of qsamplerChannelFxForm.cpp

Legend:
Removed from v.1667  
changed lines
  Added in v.2459

  ViewVC Help
Powered by ViewVC