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

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

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

revision 2978 by capela, Sat Dec 29 00:21:11 2012 UTC revision 2979 by capela, Tue Aug 16 15:34:45 2016 UTC
# Line 1  Line 1 
1  // qsamplerFxSendList.cpp  // qsamplerFxSendList.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2010-2012, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2010-2016, 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 30  Line 30 
30    
31  namespace QSampler {  namespace QSampler {
32    
33  FxSendsModel::FxSendsModel(int SamplerChannelID, QObject* pParent) : QAbstractListModel(pParent) {  
34          m_SamplerChannelID = SamplerChannelID;  FxSendsModel::FxSendsModel ( int iChannelID, QObject* pParent )
35            : QAbstractListModel(pParent)
36    {
37            m_iChannelID = iChannelID;
38          cleanRefresh();          cleanRefresh();
39  }  }
40    
41  int FxSendsModel::rowCount(const QModelIndex& /*parent*/) const {  
42          return m_FxSends.size();  int FxSendsModel::rowCount ( const QModelIndex& /*parent*/ ) const
43    {
44            return m_fxSends.size();
45  }  }
46    
47  QVariant FxSendsModel::data(const QModelIndex& index, int role) const {  
48    QVariant FxSendsModel::data ( const QModelIndex& index, int role ) const
49    {
50          if (!index.isValid())          if (!index.isValid())
51                  return QVariant();                  return QVariant();
52    
53          switch (role) {          switch (role) {
54                  case Qt::DisplayRole:                  case Qt::DisplayRole:
55                          return m_FxSends[index.row()].name();                          return m_fxSends[index.row()].name();
56                          break;                          break;
57                  case Qt::ToolTipRole:                  case Qt::ToolTipRole:
58                          if (m_FxSends[index.row()].deletion())                          if (m_fxSends[index.row()].deletion())
59                                  return QString(                                  return QString(
60                                          "Scheduled for deletion. Click on 'Apply' to actually "                                          "Scheduled for deletion. Click on 'Apply' to actually "
61                                          "destroy FX Send."                                          "destroy FX Send."
62                                  );                                  );
63                          return (m_FxSends[index.row()].isNew()) ?                          return (m_fxSends[index.row()].isNew()) ?
64                                                  QString(                                                  QString(
65                                                          "New FX send. Click on 'Apply' to actually "                                                          "New FX send. Click on 'Apply' to actually "
66                                                          "perform creation."                                                          "perform creation."
67                                                  ) :                                                  ) :
68                                                  QString("FX Send ID ") +                                                  QString("FX Send ID ") +
69                                                  QString::number(m_FxSends[index.row()].id());                                                  QString::number(m_fxSends.at(index.row()).id());
70                          break;                          break;
71                  case Qt::ForegroundRole:                  case Qt::ForegroundRole:
72                          if (m_FxSends[index.row()].deletion())                          if (m_fxSends.at(index.row()).deletion())
73                                  return QBrush(Qt::red);                                  return QBrush(Qt::red);
74                          if (m_FxSends[index.row()].isNew())                          if (m_fxSends.at(index.row()).isNew())
75                                  return QBrush(Qt::green);                                  return QBrush(Qt::green);
76                          break;                          break;
77                  case Qt::DecorationRole:                  case Qt::DecorationRole:
78                          if (m_FxSends[index.row()].deletion())                          if (m_fxSends.at(index.row()).deletion())
79                                  return QIcon(":/images/formRemove.png");                                  return QIcon(":/images/formRemove.png");
80                          if (m_FxSends[index.row()].isNew())                          if (m_fxSends.at(index.row()).isNew())
81                                  return QIcon(":/images/itemNew.png");                                  return QIcon(":/images/itemNew.png");
82                          if (m_FxSends[index.row()].isModified())                          if (m_fxSends.at(index.row()).isModified())
83                                  return QIcon(":/images/formEdit.png");                                  return QIcon(":/images/formEdit.png");
84                          return QIcon(":/images/itemFile.png");                          return QIcon(":/images/itemFile.png");
85                  case Qt::FontRole: {                  case Qt::FontRole: {
86                          if (m_FxSends[index.row()].isModified()) {                          if (m_fxSends.at(index.row()).isModified()) {
87                                  QFont font;                                  QFont font;
88                                  font.setBold(true);                                  font.setBold(true);
89                                  return font;                                  return font;
# Line 86  QVariant FxSendsModel::data(const QModel Line 93  QVariant FxSendsModel::data(const QModel
93                  default:                  default:
94                          return QVariant();                          return QVariant();
95          }          }
96    
97          return QVariant();          return QVariant();
98  }  }
99    
100  bool FxSendsModel::setData(  
101          const QModelIndex& index, const QVariant& value, int /*role*/)  bool FxSendsModel::setData (
102            const QModelIndex& index, const QVariant& value, int /*role*/ )
103  {  {
104          if (!index.isValid())          if (!index.isValid())
105                  return false;                  return false;
106    
107          m_FxSends[index.row()].setName(value.toString());          m_fxSends[index.row()].setName(value.toString());
108          emit dataChanged(index, index);          emit dataChanged(index, index);
109          emit fxSendsDirtyChanged(true);          emit fxSendsDirtyChanged(true);
110    
111          return true;          return true;
112  }  }
113    
114  QVariant FxSendsModel::headerData(int section, Qt::Orientation /*orientation*/,  
115          int role) const  QVariant FxSendsModel::headerData (
116            int section, Qt::Orientation /*orientation*/, int role ) const
117  {  {
118          if (role == Qt::DisplayRole && section == 0)          if (role == Qt::DisplayRole && section == 0)
119                  return QString("FX Send Name");                  return QString("FX Send Name");
# Line 111  QVariant FxSendsModel::headerData(int se Line 121  QVariant FxSendsModel::headerData(int se
121                  return QVariant();                  return QVariant();
122  }  }
123    
124  Qt::ItemFlags FxSendsModel::flags(const QModelIndex& /*index*/) const {  
125    Qt::ItemFlags FxSendsModel::flags ( const QModelIndex& /*index*/) const
126    {
127          return Qt::ItemIsEditable | Qt::ItemIsEnabled;          return Qt::ItemIsEditable | Qt::ItemIsEnabled;
128  }  }
129    
130  FxSend* FxSendsModel::addFxSend() {  
131    FxSend *FxSendsModel::addFxSend (void)
132    {
133  #if CONFIG_FXSEND  #if CONFIG_FXSEND
134          FxSend fxSend(m_SamplerChannelID);          FxSend fxSend(m_iChannelID);
135          fxSend.setName("New FX Send");          fxSend.setName("New FX Send");
136          m_FxSends.push_back(fxSend);          m_fxSends.push_back(fxSend);
137          QModelIndex index = createIndex(m_FxSends.size() - 1, 0);          createIndex(m_fxSends.size() - 1, 0);
138  #if QT_VERSION < 0x050000  #if QT_VERSION < 0x050000
139          QAbstractListModel::reset();          QAbstractListModel::reset();
140  #else  #else
# Line 128  FxSend* FxSendsModel::addFxSend() { Line 142  FxSend* FxSendsModel::addFxSend() {
142          QAbstractListModel::endResetModel();          QAbstractListModel::endResetModel();
143  #endif  #endif
144          emit fxSendsDirtyChanged(true);          emit fxSendsDirtyChanged(true);
145          return &m_FxSends.last();          return &m_fxSends.last();
146  #else // CONFIG_FXSEND  #else
147          return NULL;          return NULL;
148  #endif // CONFIG_FXSEND  #endif // CONFIG_FXSEND
149  }  }
150    
151  FxSend* FxSendsModel::fxSend(const QModelIndex& index) {  
152    FxSend *FxSendsModel::fxSend ( const QModelIndex& index )
153    {
154          if (!index.isValid())          if (!index.isValid())
155                  return NULL;                  return NULL;
156    
157          return &m_FxSends[index.row()];          return &m_fxSends[index.row()];
158  }  }
159    
160  void FxSendsModel::removeFxSend(const QModelIndex& index) {  
161          FxSend* pFxSend = fxSend(index);  void FxSendsModel::removeFxSend ( const QModelIndex& index )
162    {
163            FxSend *pFxSend = fxSend(index);
164          if (!pFxSend) return;          if (!pFxSend) return;
165          pFxSend->setDeletion(true);          pFxSend->setDeletion(true);
166  #if QT_VERSION < 0x050000  #if QT_VERSION < 0x050000
# Line 154  void FxSendsModel::removeFxSend(const QM Line 172  void FxSendsModel::removeFxSend(const QM
172          emit fxSendsDirtyChanged(true);          emit fxSendsDirtyChanged(true);
173  }  }
174    
175  void FxSendsModel::cleanRefresh() {  
176          m_FxSends.clear();  void FxSendsModel::cleanRefresh (void)
177          QList<int> sends = FxSend::allFxSendsOfSamplerChannel(m_SamplerChannelID);  {
178            m_fxSends.clear();
179            const QList<int>& sends = FxSend::allFxSendsOfSamplerChannel(m_iChannelID);
180          for (int i = 0; i < sends.size(); ++i) {          for (int i = 0; i < sends.size(); ++i) {
181                  const int iFxSendId = sends[i];                  const int iFxSendId = sends.at(i);
182                  FxSend fxSend(m_SamplerChannelID, iFxSendId);                  FxSend fxSend(m_iChannelID, iFxSendId);
183                  fxSend.getFromSampler();                  fxSend.getFromSampler();
184                  m_FxSends.push_back(fxSend);                  m_fxSends.push_back(fxSend);
185          }          }
186  #if QT_VERSION < 0x050000  #if QT_VERSION < 0x050000
187          QAbstractListModel::reset();          QAbstractListModel::reset();
# Line 172  void FxSendsModel::cleanRefresh() { Line 192  void FxSendsModel::cleanRefresh() {
192          emit fxSendsDirtyChanged(false);          emit fxSendsDirtyChanged(false);
193  }  }
194    
195  void FxSendsModel::onExternalModifiication(const QModelIndex& index) {  
196    void FxSendsModel::onExternalModifiication ( const QModelIndex& index )
197    {
198          if (!index.isValid()) return;          if (!index.isValid()) return;
199          emit dataChanged(index, index);          emit dataChanged(index, index);
200          emit fxSendsDirtyChanged(true);          emit fxSendsDirtyChanged(true);
201  }  }
202    
203  void FxSendsModel::applyToSampler() {  
204          for (int i = 0; i < m_FxSends.size(); ++i)  void FxSendsModel::applyToSampler (void)
205                  m_FxSends[i].applyToSampler();  {
206            for (int i = 0; i < m_fxSends.size(); ++i)
207                    m_fxSends[i].applyToSampler();
208    
209          // make a clean refresh          // make a clean refresh
210          // (throws out all FxSend objects marked for deletion)          // (throws out all FxSend objects marked for deletion)
211          cleanRefresh();          cleanRefresh();
212  }  }
213    
214    
215  } // namespace QSampler  } // namespace QSampler
216    
217    
218  // end of qsamplerFxSendList.cpp  // end of qsamplerFxSendList.cpp

Legend:
Removed from v.2978  
changed lines
  Added in v.2979

  ViewVC Help
Powered by ViewVC