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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2074 - (show annotations) (download)
Mon Mar 29 17:00:30 2010 UTC (9 years, 7 months ago) by capela
File size: 4908 byte(s)
* General source tree layout and build configuration change.

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

  ViewVC Help
Powered by ViewVC