1
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
5
A MIDI and audio sequencer and musical notation editor.
7
This program is Copyright 2000-2007
8
Guillaume Laurent <glaurent@telegraph-road.org>,
9
Chris Cannam <cannam@all-day-breakfast.com>,
10
Richard Bown <richard.bown@ferventsoftware.com>
12
The moral rights of Guillaume Laurent, Chris Cannam, and Richard
13
Bown to claim authorship of this work have been asserted.
15
Other copyrights also apply to some parts of this work. Please
16
see the AUTHORS file and individual file headers for details.
18
This program is free software; you can redistribute it and/or
19
modify it under the terms of the GNU General Public License as
20
published by the Free Software Foundation; either version 2 of the
21
License, or (at your option) any later version. See the file
22
COPYING included with this distribution for more information.
26
#include "PluginControl.h"
28
#include "misc/Strings.h"
29
#include "base/AudioPluginInstance.h"
30
#include "gui/general/GUIPalette.h"
31
#include "gui/studio/AudioPluginManager.h"
32
#include "gui/widgets/Rotary.h"
45
PluginControl::PluginControl(QWidget *parent,
49
AudioPluginManager *aPM,
62
plainFont.setPointSize((plainFont.pointSize() * 9 ) / 10);
64
QLabel *controlTitle =
65
new QLabel(QString("%1 ").arg(strtoqstr(port->getName())), parent);
66
controlTitle->setFont(plainFont);
69
float lowerBound = port->getLowerBound();
70
float upperBound = port->getUpperBound();
71
// Default value was already handled when calling this constructor
73
if (lowerBound > upperBound) {
74
float swap = upperBound;
75
upperBound = lowerBound;
79
float step = (upperBound - lowerBound) / 100.0;
80
float pageStep = step * 10.f;
81
Rotary::TickMode ticks = Rotary::PageStepTicks;
82
bool snapToTicks = false;
84
if (port->getDisplayHint() & PluginPort::Integer) {
86
ticks = Rotary::StepTicks;
87
if (upperBound - lowerBound > 30.0)
91
if (port->getDisplayHint() & PluginPort::Toggled) {
96
ticks = Rotary::StepTicks;
100
float displayLower = lowerBound, displayUpper = upperBound;
102
bool logarithmic = (port->getDisplayHint() & PluginPort::Logarithmic);
105
float logthresh = -10;
106
float thresh = powf(10, logthresh);
107
if (lowerBound > thresh) lowerBound = log10f(lowerBound);
109
if (upperBound > 1) lowerBound = 0;
110
else lowerBound = logthresh;
112
if (upperBound > thresh) upperBound = log10f(upperBound);
113
else upperBound = logthresh;
115
step = (upperBound - lowerBound) / 100.0;
116
pageStep = step * 10.f;
117
initialValue = log10f(initialValue);
121
if (port->getDisplayHint() &
122
(PluginPort::Integer | PluginPort::Toggled)) {
123
low = new QLabel(QString("%1").arg(int(displayLower)), parent);
125
low = new QLabel(QString("%1").arg(displayLower), parent);
127
low->setFont(plainFont);
129
// std::cerr << "port " << port->getName() << ": lower bound "
130
// << displayLower << ", upper bound " << displayUpper
131
// << ", logarithmic " << logarithmic << ", default "
132
// << initialValue << ", actual lower " << lowerBound
133
// << ", actual upper " << upperBound << ", step "
134
// << step << std::endl;
136
m_dial = new ::Rosegarden::Rotary(parent,
140
pageStep, // page step
141
initialValue, // initial
148
m_dial->setKnobColour(GUIPalette::getColour(GUIPalette::RotaryPlugin));
150
connect(m_dial, SIGNAL(valueChanged(float)),
151
this, SLOT(slotValueChanged(float)));
154
if (port->getDisplayHint() &
155
(PluginPort::Integer | PluginPort::Toggled)) {
156
upp = new QLabel(QString("%1").arg(int(displayUpper)), parent);
158
upp = new QLabel(QString("%1").arg(displayUpper), parent);
160
upp->setFont(plainFont);
165
controlTitle->show();
166
item = new QWidgetItem(controlTitle);
167
item->setAlignment(Qt::AlignRight | Qt::AlignBottom);
168
m_layout->addItem(item);
170
controlTitle->hide();
173
if (showBounds && !hidden) {
175
item = new QWidgetItem(low);
176
item->setAlignment(Qt::AlignRight | Qt::AlignBottom);
177
m_layout->addItem(item);
184
item = new QWidgetItem(m_dial);
185
item->setAlignment(Qt::AlignCenter);
186
m_layout->addItem(item);
191
if (showBounds && !hidden) {
193
item = new QWidgetItem(upp);
194
item->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
195
m_layout->addItem(item);
203
PluginControl::setValue(float value, bool emitSignals)
206
m_dial->blockSignals(true);
207
m_dial->setPosition(value);
209
m_dial->blockSignals(false);
211
emit valueChanged(value);
215
PluginControl::getValue() const
217
return m_dial == 0 ? 0 : m_dial->getPosition();
221
PluginControl::slotValueChanged(float value)
223
emit valueChanged(value);
227
#include "PluginControl.moc"