-
Notifications
You must be signed in to change notification settings - Fork 0
/
envelopeclient.cpp
180 lines (156 loc) · 5.79 KB
/
envelopeclient.cpp
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
/*
Copyright 2011 Arne Jacobs <jarne@jarne.de>
This file is part of elektrocillin.
Elektrocillin 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 3 of the License, or
(at your option) any later version.
Elektrocillin 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 Elektrocillin. If not, see <http://www.gnu.org/licenses/>.
*/
#include "envelopeclient.h"
#include <cmath>
EnvelopeClient::EnvelopeClient(const QString &clientName, Envelope *processEnvelope_, Envelope *guiEnvelope_, size_t ringBufferSize) :
ParameterClient(clientName, processEnvelope_, processEnvelope_, processEnvelope_, processEnvelope_, guiEnvelope_, ringBufferSize),
processEnvelope(processEnvelope_),
guiEnvelope(guiEnvelope_)
{
}
EnvelopeClient::~EnvelopeClient()
{
close();
delete processEnvelope;
delete guiEnvelope;
}
void EnvelopeClient::saveState(QDataStream &stream)
{
ParameterClient::saveState(stream);
guiEnvelope->save(stream);
}
void EnvelopeClient::loadState(QDataStream &stream)
{
ParameterClient::loadState(stream);
guiEnvelope->load(stream);
*processEnvelope = *guiEnvelope;
}
QGraphicsItem * EnvelopeClient::createGraphicsItem()
{
int padding = 4;
QGraphicsRectItem *item = new QGraphicsRectItem();
ParameterGraphicsItem *parameterItem = new ParameterGraphicsItem(this);
QRectF rect = QRect(0, 0, 1200, 420);
rect = rect.translated(parameterItem->boundingRect().width() + 2 * padding, padding);
parameterItem->setPos(padding, padding);
parameterItem->setParentItem(item);
EnvelopeGraphicsItem *ourItem = new EnvelopeGraphicsItem(rect, this, item);
item->setRect((rect | parameterItem->boundingRect().translated(parameterItem->pos())).adjusted(-padding, -padding, padding, padding));
item->setPen(QPen(QBrush(Qt::black), 1));
item->setBrush(QBrush(Qt::white));
QObject::connect(this, SIGNAL(changedYSteps(int)), ourItem, SLOT(setHorizontalSlices(int)));
return item;
}
void EnvelopeClient::postChangeSustainIndex(int sustainIndex)
{
Envelope::ChangeSustainPositionEvent *event = new Envelope::ChangeSustainPositionEvent(sustainIndex);
guiEnvelope->processEvent(event, 0);
postEvent(event);
}
double EnvelopeClient::evaluate(double x, int *index)
{
return guiEnvelope->evaluate(x, index);
}
int EnvelopeClient::getNrOfControlPoints()
{
return guiEnvelope->getNrOfControlPoints();
}
QPointF EnvelopeClient::getControlPoint(int index)
{
return guiEnvelope->getControlPoint(index);
}
void EnvelopeClient::changeControlPoint(int index, double x, double y)
{
guiEnvelope->changeControlPoint(index, x, y);
// send the change to the process thread:
Interpolator::ChangeControlPointEvent *event = new Interpolator::ChangeControlPointEvent(index, x, y);
postEvent(event);
}
void EnvelopeClient::addControlPoint(double x, double y)
{
guiEnvelope->addControlPoint(x, y);
// this will have changed the bounds of the sustain index parameter:
const ParameterProcessor::Parameter ¶meter = guiEnvelope->getParameter(1);
changedParameterValue(1, parameter.value, parameter.min, parameter.max);
// send the change to the process thread:
Interpolator::AddControlPointEvent *event = new Interpolator::AddControlPointEvent(x, y);
postEvent(event);
}
void EnvelopeClient::deleteControlPoint(int index)
{
guiEnvelope->deleteControlPoint(index);
// this will have changed the bounds of the sustain index parameter:
const ParameterProcessor::Parameter ¶meter = guiEnvelope->getParameter(1);
changedParameterValue(1, parameter.value, parameter.min, parameter.max);
// send the change to the process thread:
Interpolator::DeleteControlPointEvent *event = new Interpolator::DeleteControlPointEvent(index);
postEvent(event);
}
QString EnvelopeClient::getControlPointName(int index) const
{
return guiEnvelope->getControlPointName(index);
}
void EnvelopeClient::onChangedParameterValue(int index, double value, double min, double max)
{
if (index == 2) {
// y steps:
changedYSteps(qRound(value));
}
ParameterClient::onChangedParameterValue(index, value, min, max);
}
EnvelopeGraphicsItem::EnvelopeGraphicsItem(const QRectF &rect, EnvelopeClient *client_, QGraphicsItem *parent_) :
GraphicsInterpolatorEditItem(
client_,
rect,
QRectF(0, 1, client_->getControlPoint(client_->getNrOfControlPoints() - 1).x(), -2),
parent_,
4,
8,
true
),
client(client_)
{
setVisible(GraphicsInterpolatorEditItem::FIRST, false);
QObject::connect(client, SIGNAL(changedParameterValue(int,double,double,double)), this, SLOT(onChangedParameterValue(int)));
}
void EnvelopeGraphicsItem::onChangedParameterValue(int index)
{
// update the interpolator if the slope or sustain index have been changed:
if (index <= 1) {
updateInterpolator();
}
}
class EnvelopeClientFactory : public JackClientFactory
{
public:
EnvelopeClientFactory()
{
JackClientSerializer::getInstance()->registerFactory(this);
}
QString getName()
{
return "Envelope";
}
JackClient * createClient(const QString &clientName)
{
return new EnvelopeClient(clientName, new Envelope(), new Envelope());
}
static EnvelopeClientFactory factory;
};
EnvelopeClientFactory EnvelopeClientFactory::factory;
JackClientFactory * EnvelopeClient::getFactory()
{
return &EnvelopeClientFactory::factory;
}