~ubuntu-branches/ubuntu/saucy/goldencheetah/saucy

« back to all changes in this revision

Viewing changes to qwt/examples/radio/ampfrm.cpp

  • Committer: Package Import Robot
  • Author(s): KURASHIKI Satoru
  • Date: 2013-08-18 07:02:45 UTC
  • mfrom: (4.1.8 sid)
  • Revision ID: package-import@ubuntu.com-20130818070245-zgdvb47e1k3mtgil
Tags: 3.0-3
debian/control: remove needless dependency. (Closes: #719571)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "ampfrm.h"
2
2
#include <qwt_knob.h>
 
3
#include <qwt_thermo.h>
 
4
#include <qwt_round_scale_draw.h>
 
5
#include <qwt_math.h>
3
6
#include <qlayout.h>
4
7
#include <qlabel.h>
5
8
#include <qfont.h>
6
9
#include <qpen.h>
7
10
#include <qevent.h>
8
 
#include <qwt_thermo.h>
9
 
#include <qwt_round_scale_draw.h>
10
 
#include <qwt_math.h>
 
11
 
 
12
#if QT_VERSION < 0x040600
 
13
#define qFastSin(x) ::sin(x)
 
14
#define qFastCos(x) ::cos(x)
 
15
#endif
11
16
 
12
17
class Knob: public QWidget
13
18
{
19
24
        d_knob->setRange(min, max, 0,1);
20
25
        d_knob->setScaleMaxMajor(10);
21
26
 
 
27
        d_knob->setKnobStyle(QwtKnob::Raised);
22
28
        d_knob->setKnobWidth(50);
 
29
        d_knob->setBorderWidth(2);
 
30
        d_knob->setMarkerStyle(QwtKnob::Notch);
 
31
        d_knob->setMarkerSize( 8 );
 
32
 
 
33
        d_knob->scaleDraw()->setTickLength( QwtScaleDiv::MinorTick, 4 );
 
34
        d_knob->scaleDraw()->setTickLength( QwtScaleDiv::MediumTick, 4 );
 
35
        d_knob->scaleDraw()->setTickLength( QwtScaleDiv::MajorTick, 6 );
23
36
 
24
37
        d_label = new QLabel(title, this);
25
38
        d_label->setAlignment(Qt::AlignTop | Qt::AlignHCenter);
26
39
 
27
 
        setSizePolicy(QSizePolicy::MinimumExpanding, 
 
40
        setSizePolicy(QSizePolicy::MinimumExpanding,
28
41
            QSizePolicy::MinimumExpanding);
29
42
    }
30
43
 
33
46
        QSize sz1 = d_knob->sizeHint();
34
47
        QSize sz2 = d_label->sizeHint();
35
48
 
36
 
        const int w = qwtMax(sz1.width(), sz2.width());
 
49
        const int w = qMax(sz1.width(), sz2.width());
37
50
        const int h = sz1.height() + sz2.height();
38
 
            
39
 
        int off = d_knob->scaleDraw()->extent(QPen(), d_knob->font());
 
51
 
 
52
        int off = d_knob->scaleDraw()->extent(d_knob->font());
40
53
        off -= 10; // spacing
41
54
 
42
55
        return QSize(w, h - off);
43
56
    }
44
57
 
 
58
    void setValue( double value )
 
59
    {
 
60
        d_knob->setValue( value );
 
61
    }
 
62
 
45
63
    double value() const
46
64
    {
47
65
        return d_knob->value();
48
66
    }
49
 
    
 
67
 
50
68
protected:
51
69
    virtual void resizeEvent(QResizeEvent *e)
52
70
    {
58
76
            sz.width(), h);
59
77
 
60
78
        h = d_knob->sizeHint().height();
61
 
        int off = d_knob->scaleDraw()->extent(QPen(), d_knob->font());
 
79
        int off = d_knob->scaleDraw()->extent(d_knob->font());
62
80
        off -= 10; // spacing
63
81
 
64
82
        d_knob->setGeometry(0, d_label->pos().y() - h + off,
76
94
    Thermo(const QString &title, QWidget *parent):
77
95
        QWidget(parent)
78
96
    {
79
 
        d_thermo = new QwtThermo(this);
80
 
        d_thermo->setPipeWidth(6);
81
 
        d_thermo->setRange(-40,10);
82
 
        d_thermo->setFillColor(Qt::green);
83
 
        d_thermo->setAlarmColor(Qt::red);
84
 
        d_thermo->setAlarmLevel(0.0);
85
 
        d_thermo->setAlarmEnabled(true);
 
97
        d_thermo = new QwtThermo( this );
 
98
        d_thermo->setPipeWidth( 6 );
 
99
        d_thermo->setRange( -40, 10 );
 
100
        d_thermo->setFillBrush( Qt::green );
 
101
        d_thermo->setAlarmBrush( Qt::red );
 
102
        d_thermo->setAlarmLevel( 0.0 );
 
103
        d_thermo->setAlarmEnabled( true );
86
104
 
87
105
        QLabel *label = new QLabel(title, this);
88
106
        label->setAlignment(Qt::AlignTop | Qt::AlignLeft);
103
121
    QwtThermo *d_thermo;
104
122
};
105
123
 
106
 
AmpFrame::AmpFrame(QWidget *p): 
 
124
AmpFrame::AmpFrame(QWidget *p):
107
125
    QFrame(p)
108
126
{
109
127
    d_knbVolume = new Knob("Volume", 0.0, 10.0, this);
127
145
    layout->addSpacing(10);
128
146
    layout->addWidget(d_thmRight);
129
147
 
130
 
    (void)startTimer(50);    
 
148
    d_knbVolume->setValue( 7.0 );
 
149
    (void)startTimer(50);
131
150
}
132
151
 
133
152
void AmpFrame::timerEvent(QTimerEvent *)
134
153
{
135
154
    static double phs = 0;
136
 
    
 
155
 
137
156
    //
138
157
    //  This amplifier generates its own input signal...
139
158
    //
140
159
 
141
 
    const double sig_bass = (1.0 + 0.1 * d_knbBass->value()) 
142
 
        * sin(13.0 * phs);
143
 
    const double sig_mid_l = sin(17.0 * phs);
144
 
    const double sig_mid_r = cos(17.5 * phs);
145
 
    const double sig_trbl_l = 0.5 * (1.0 + 0.1 * d_knbTreble->value()) 
146
 
        * sin(35.0 * phs);
147
 
    const double sig_trbl_r = 0.5 * (1.0 + 0.1 * d_knbTreble->value()) 
148
 
        * sin(34.0 * phs);
 
160
    const double sig_bass = (1.0 + 0.1 * d_knbBass->value())
 
161
        * qFastSin(13.0 * phs);
 
162
    const double sig_mid_l = qFastSin(17.0 * phs);
 
163
    const double sig_mid_r = qFastCos(17.5 * phs);
 
164
    const double sig_trbl_l = 0.5 * (1.0 + 0.1 * d_knbTreble->value())
 
165
        * qFastSin(35.0 * phs);
 
166
    const double sig_trbl_r = 0.5 * (1.0 + 0.1 * d_knbTreble->value())
 
167
        * qFastSin(34.0 * phs);
149
168
 
150
 
    double sig_l = 0.05 * d_master * d_knbVolume->value() 
 
169
    double sig_l = 0.05 * d_master * d_knbVolume->value()
151
170
        * qwtSqr(sig_bass + sig_mid_l + sig_trbl_l);
152
 
    double sig_r = 0.05 * d_master * d_knbVolume->value()   
 
171
    double sig_r = 0.05 * d_master * d_knbVolume->value()
153
172
        * qwtSqr(sig_bass + sig_mid_r + sig_trbl_r);
154
 
    
155
 
    double balance = 0.1 * d_knbBalance->value(); 
156
 
    if (balance > 0) 
 
173
 
 
174
    double balance = 0.1 * d_knbBalance->value();
 
175
    if (balance > 0)
157
176
       sig_l *= (1.0 - balance);
158
177
    else
159
178
       sig_r *= (1.0 + balance);
166
185
    if (sig_r > 0.01)
167
186
       sig_r = 20.0 * log10(sig_r);
168
187
    else
169
 
       sig_r = - 40.0; 
 
188
       sig_r = - 40.0;
170
189
 
171
190
    d_thmLeft->setValue(sig_l);
172
191
    d_thmRight->setValue(sig_r);
173
192
 
174
193
    phs += M_PI / 100;
175
 
    if (phs > M_PI) 
 
194
    if (phs > M_PI)
176
195
        phs = 0;
177
196
}
178
197