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