~ubuntu-branches/ubuntu/karmic/rosegarden/karmic

« back to all changes in this revision

Viewing changes to src/gui/widgets/PluginControl.cpp.~1~

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2008-05-02 00:33:44 UTC
  • mfrom: (1.1.7 upstream) (6.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080502003344-67vbfhgqx2yl0ksi
Tags: 1:1.7.0-1ubuntu1
* Merge from Debian unstable. (LP: #225849) Remaining Ubuntu changes:
  - Add usr/share/doc/kde/HTML to rosegarden-data, to provide online
    help documentation.
  - Change fftw3-dev to libfftw3-dev.
  - Update maintainer field as per spec.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
 
 
3
 
/*
4
 
    Rosegarden
5
 
    A MIDI and audio sequencer and musical notation editor.
6
 
 
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>
11
 
 
12
 
    The moral rights of Guillaume Laurent, Chris Cannam, and Richard
13
 
    Bown to claim authorship of this work have been asserted.
14
 
 
15
 
    Other copyrights also apply to some parts of this work.  Please
16
 
    see the AUTHORS file and individual file headers for details.
17
 
 
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.
23
 
*/
24
 
 
25
 
 
26
 
#include "PluginControl.h"
27
 
#include "Rotary.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"
33
 
#include <qfont.h>
34
 
#include <qhbox.h>
35
 
#include <qlabel.h>
36
 
#include <qlayout.h>
37
 
#include <qobject.h>
38
 
#include <qstring.h>
39
 
#include <qwidget.h>
40
 
 
41
 
 
42
 
namespace Rosegarden
43
 
{
44
 
 
45
 
PluginControl::PluginControl(QWidget *parent,
46
 
                             QGridLayout *layout,
47
 
                             ControlType type,
48
 
                             PluginPort *port,
49
 
                             AudioPluginManager *aPM,
50
 
                             int index,
51
 
                             float initialValue,
52
 
                             bool showBounds,
53
 
                             bool hidden):
54
 
        QObject(parent),
55
 
        m_layout(layout),
56
 
        m_type(type),
57
 
        m_port(port),
58
 
        m_pluginManager(aPM),
59
 
        m_index(index)
60
 
{
61
 
    QFont plainFont;
62
 
    plainFont.setPointSize((plainFont.pointSize() * 9 ) / 10);
63
 
 
64
 
    QLabel *controlTitle =
65
 
        new QLabel(QString("%1    ").arg(strtoqstr(port->getName())), parent);
66
 
    controlTitle->setFont(plainFont);
67
 
 
68
 
    if (type == Rotary) {
69
 
        float lowerBound = port->getLowerBound();
70
 
        float upperBound = port->getUpperBound();
71
 
        // Default value was already handled when calling this constructor
72
 
 
73
 
        if (lowerBound > upperBound) {
74
 
            float swap = upperBound;
75
 
            upperBound = lowerBound;
76
 
            lowerBound = swap;
77
 
        }
78
 
 
79
 
        float step = (upperBound - lowerBound) / 100.0;
80
 
        float pageStep = step * 10.f;
81
 
        Rotary::TickMode ticks = Rotary::PageStepTicks;
82
 
        bool snapToTicks = false;
83
 
 
84
 
        if (port->getDisplayHint() & PluginPort::Integer) {
85
 
            step = 1.0;
86
 
            ticks = Rotary::StepTicks;
87
 
            if (upperBound - lowerBound > 30.0)
88
 
                pageStep = 10.0;
89
 
            snapToTicks = true;
90
 
        }
91
 
        if (port->getDisplayHint() & PluginPort::Toggled) {
92
 
            lowerBound = -0.0001;
93
 
            upperBound = 1.0001;
94
 
            step = 1.0;
95
 
            pageStep = 1.0;
96
 
            ticks = Rotary::StepTicks;
97
 
            snapToTicks = true;
98
 
        }
99
 
 
100
 
        float displayLower = lowerBound, displayUpper = upperBound;
101
 
 
102
 
        bool logarithmic = (port->getDisplayHint() & PluginPort::Logarithmic);
103
 
 
104
 
        if (logarithmic) {
105
 
            float logthresh = -10;
106
 
            float thresh = powf(10, logthresh);
107
 
            if (lowerBound > thresh) lowerBound = log10f(lowerBound);
108
 
            else {
109
 
                if (upperBound > 1) lowerBound = 0;
110
 
                else lowerBound = logthresh;
111
 
            }
112
 
            if (upperBound > thresh) upperBound = log10f(upperBound);
113
 
            else upperBound = logthresh;
114
 
 
115
 
            step = (upperBound - lowerBound) / 100.0;
116
 
            pageStep = step * 10.f;
117
 
            initialValue = log10f(initialValue);
118
 
        }
119
 
 
120
 
        QLabel *low;
121
 
        if (port->getDisplayHint() &
122
 
            (PluginPort::Integer | PluginPort::Toggled)) {
123
 
            low = new QLabel(QString("%1").arg(int(displayLower)), parent);
124
 
        } else {
125
 
            low = new QLabel(QString("%1").arg(displayLower), parent);
126
 
        }
127
 
        low->setFont(plainFont);
128
 
 
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;
135
 
 
136
 
        m_dial = new ::Rosegarden::Rotary(parent,
137
 
                                          lowerBound,    // min
138
 
                                          upperBound,    // max
139
 
                                          step,          // step
140
 
                                          pageStep,      // page step
141
 
                                          initialValue,  // initial
142
 
                                          30,            // size
143
 
                                          ticks,
144
 
                                          snapToTicks,
145
 
                                          false,         // centred
146
 
                                          logarithmic);
147
 
 
148
 
        m_dial->setKnobColour(GUIPalette::getColour(GUIPalette::RotaryPlugin));
149
 
 
150
 
        connect(m_dial, SIGNAL(valueChanged(float)),
151
 
                this, SLOT(slotValueChanged(float)));
152
 
 
153
 
        QLabel *upp;
154
 
        if (port->getDisplayHint() &
155
 
            (PluginPort::Integer | PluginPort::Toggled)) {
156
 
            upp = new QLabel(QString("%1").arg(int(displayUpper)), parent);
157
 
        } else {
158
 
            upp = new QLabel(QString("%1").arg(displayUpper), parent);
159
 
        }
160
 
        upp->setFont(plainFont);
161
 
 
162
 
        QWidgetItem *item;
163
 
 
164
 
        if (!hidden) {
165
 
            controlTitle->show();
166
 
            item = new QWidgetItem(controlTitle);
167
 
            item->setAlignment(Qt::AlignRight | Qt::AlignBottom);
168
 
            m_layout->addItem(item);
169
 
        } else {
170
 
            controlTitle->hide();
171
 
        }
172
 
 
173
 
        if (showBounds && !hidden) {
174
 
            low->show();
175
 
            item = new QWidgetItem(low);
176
 
            item->setAlignment(Qt::AlignRight | Qt::AlignBottom);
177
 
            m_layout->addItem(item);
178
 
        } else {
179
 
            low->hide();
180
 
        }
181
 
 
182
 
        if (!hidden) {
183
 
            m_dial->show();
184
 
            item = new QWidgetItem(m_dial);
185
 
            item->setAlignment(Qt::AlignCenter);
186
 
            m_layout->addItem(item);
187
 
        } else {
188
 
            m_dial->hide();
189
 
        }
190
 
 
191
 
        if (showBounds && !hidden) {
192
 
            upp->show();
193
 
            item = new QWidgetItem(upp);
194
 
            item->setAlignment(Qt::AlignLeft | Qt::AlignBottom);
195
 
            m_layout->addItem(item);
196
 
        } else {
197
 
            upp->hide();
198
 
        }
199
 
    }
200
 
}
201
 
 
202
 
void
203
 
PluginControl::setValue(float value, bool emitSignals)
204
 
{
205
 
    if (!emitSignals)
206
 
        m_dial->blockSignals(true);
207
 
    m_dial->setPosition(value);
208
 
    if (!emitSignals)
209
 
        m_dial->blockSignals(false);
210
 
    else
211
 
        emit valueChanged(value);
212
 
}
213
 
 
214
 
float
215
 
PluginControl::getValue() const
216
 
{
217
 
    return m_dial == 0 ? 0 : m_dial->getPosition();
218
 
}
219
 
 
220
 
void
221
 
PluginControl::slotValueChanged(float value)
222
 
{
223
 
    emit valueChanged(value);
224
 
}
225
 
 
226
 
}
227
 
#include "PluginControl.moc"