Menu

[729340]: / src / qsamplerFxSendsModel.cpp  Maximize  Restore  History

Download this file

219 lines (177 with data), 5.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
// qsamplerFxSendList.cpp
//
/****************************************************************************
Copyright (C) 2010-2019, rncbc aka Rui Nuno Capela. All rights reserved.
Copyright (C) 2008, Christian Schoenebeck
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*****************************************************************************/
#include "qsamplerAbout.h"
#include "qsamplerFxSendsModel.h"
#include "qsamplerFxSend.h"
#include <QBrush>
#include <QIcon>
#include <QFont>
namespace QSampler {
FxSendsModel::FxSendsModel ( int iChannelID, QObject* pParent )
: QAbstractListModel(pParent)
{
m_iChannelID = iChannelID;
cleanRefresh();
}
int FxSendsModel::rowCount ( const QModelIndex& /*parent*/ ) const
{
return m_fxSends.size();
}
QVariant FxSendsModel::data ( const QModelIndex& index, int role ) const
{
if (!index.isValid())
return QVariant();
switch (role) {
case Qt::DisplayRole:
return m_fxSends[index.row()].name();
break;
case Qt::ToolTipRole:
if (m_fxSends[index.row()].deletion())
return QString(
"Scheduled for deletion. Click on 'Apply' to actually "
"destroy FX Send."
);
return (m_fxSends[index.row()].isNew()) ?
QString(
"New FX send. Click on 'Apply' to actually "
"perform creation."
) :
QString("FX Send ID ") +
QString::number(m_fxSends.at(index.row()).id());
break;
case Qt::ForegroundRole:
if (m_fxSends.at(index.row()).deletion())
return QBrush(Qt::red);
if (m_fxSends.at(index.row()).isNew())
return QBrush(Qt::green);
break;
case Qt::DecorationRole:
if (m_fxSends.at(index.row()).deletion())
return QIcon(":/images/formRemove.png");
if (m_fxSends.at(index.row()).isNew())
return QIcon(":/images/itemNew.png");
if (m_fxSends.at(index.row()).isModified())
return QIcon(":/images/formEdit.png");
return QIcon(":/images/itemFile.png");
case Qt::FontRole: {
if (m_fxSends.at(index.row()).isModified()) {
QFont font;
font.setBold(true);
return font;
}
break;
}
default:
return QVariant();
}
return QVariant();
}
bool FxSendsModel::setData (
const QModelIndex& index, const QVariant& value, int /*role*/ )
{
if (!index.isValid())
return false;
m_fxSends[index.row()].setName(value.toString());
emit dataChanged(index, index);
emit fxSendsDirtyChanged(true);
return true;
}
QVariant FxSendsModel::headerData (
int section, Qt::Orientation /*orientation*/, int role ) const
{
if (role == Qt::DisplayRole && section == 0)
return QString("FX Send Name");
else
return QVariant();
}
Qt::ItemFlags FxSendsModel::flags ( const QModelIndex& /*index*/) const
{
return Qt::ItemIsEditable | Qt::ItemIsEnabled;
}
FxSend *FxSendsModel::addFxSend (void)
{
#if CONFIG_FXSEND
FxSend fxSend(m_iChannelID);
fxSend.setName("New FX Send");
m_fxSends.push_back(fxSend);
createIndex(m_fxSends.size() - 1, 0);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QAbstractListModel::reset();
#else
QAbstractListModel::beginResetModel();
QAbstractListModel::endResetModel();
#endif
emit fxSendsDirtyChanged(true);
return &m_fxSends.last();
#else
return nullptr;
#endif // CONFIG_FXSEND
}
FxSend *FxSendsModel::fxSend ( const QModelIndex& index )
{
if (!index.isValid())
return nullptr;
return &m_fxSends[index.row()];
}
void FxSendsModel::removeFxSend ( const QModelIndex& index )
{
FxSend *pFxSend = fxSend(index);
if (!pFxSend) return;
pFxSend->setDeletion(true);
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QAbstractListModel::reset();
#else
QAbstractListModel::beginResetModel();
QAbstractListModel::endResetModel();
#endif
emit fxSendsDirtyChanged(true);
}
void FxSendsModel::cleanRefresh (void)
{
m_fxSends.clear();
const QList<int>& sends = FxSend::allFxSendsOfSamplerChannel(m_iChannelID);
for (int i = 0; i < sends.size(); ++i) {
const int iFxSendId = sends.at(i);
FxSend fxSend(m_iChannelID, iFxSendId);
fxSend.getFromSampler();
m_fxSends.push_back(fxSend);
}
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
QAbstractListModel::reset();
#else
QAbstractListModel::beginResetModel();
QAbstractListModel::endResetModel();
#endif
emit fxSendsDirtyChanged(false);
}
void FxSendsModel::onExternalModifiication ( const QModelIndex& index )
{
if (!index.isValid()) return;
emit dataChanged(index, index);
emit fxSendsDirtyChanged(true);
}
void FxSendsModel::applyToSampler (void)
{
for (int i = 0; i < m_fxSends.size(); ++i)
m_fxSends[i].applyToSampler();
// make a clean refresh
// (throws out all FxSend objects marked for deletion)
cleanRefresh();
}
} // namespace QSampler
// end of qsamplerFxSendList.cpp
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.