File: agc_options.cpp

package info (click to toggle)
gqrx-sdr 2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,700 kB
  • ctags: 2,724
  • sloc: cpp: 22,413; ansic: 564; xml: 25; makefile: 4
file content (234 lines) | stat: -rw-r--r-- 5,974 bytes parent folder | download | duplicates (4)
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/* -*- c++ -*- */
/*
 * Gqrx SDR: Software defined radio receiver powered by GNU Radio and Qt
 *           http://gqrx.dk/
 *
 * Copyright 2012-2013 Alexandru Csete OZ9AEC.
 *
 * Gqrx 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, or (at your option)
 * any later version.
 *
 * Gqrx 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 Gqrx; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */
#include <QDebug>
#include <QString>
#include "agc_options.h"
#include "ui_agc_options.h"

CAgcOptions::CAgcOptions(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::CAgcOptions)
{
    ui->setupUi(this);
}

CAgcOptions::~CAgcOptions()
{
    delete ui;
}

/*! \brief Catch window close events.
 *
 * This method is called when the user closes the dialog window using the
 * window close icon. We catch the event and hide the dialog but keep it
 * around for later use.
 */
void CAgcOptions::closeEvent(QCloseEvent *event)
{
    hide();
    event->ignore();
}

/*! \brief Get current gain slider value. */
int CAgcOptions::gain()
{
    return ui->gainSlider->value();
}

/*! \brief Set AGC preset. */
void CAgcOptions::setPreset(agc_preset_e preset)
{
    switch (preset)
    {
    case AGC_FAST:
        setDecay(100);
        enableDecay(false);
        setSlope(0);
        enableSlope(false);
        enableGain(false);
        break;

    case AGC_MEDIUM:
        setDecay(500);
        enableDecay(false);
        setSlope(0);
        enableSlope(false);
        enableGain(false);
        break;

    case AGC_SLOW:
        setDecay(2000);
        enableDecay(false);
        setSlope(0);
        enableSlope(false);
        enableGain(false);
        break;

    case AGC_USER:
        enableDecay(true);
        enableSlope(true);
        enableGain(false);
        break;

    case AGC_OFF:
        enableGain(true);
        break;

    default:
        qDebug() << __func__ << "Invalid AGC preset" << preset;
        break;

    }
}

/*! \brief Set new gain slider value. */
void CAgcOptions::setGain(int value)
{
    ui->gainSlider->setValue(value);
    ui->gainLabel->setText(QString("%1 dB").arg(ui->gainSlider->value()));
}

/*! \brief Enable or disable gain slider.
 *  \param enabled Whether the slider should be enabled or not.
 *
 * The gain slider is enabled when AGC is OFF to provide manual gain
 * control. It is disabled when AGC is ON.
 */
void CAgcOptions::enableGain(bool enabled)
{
    ui->gainLabel->setEnabled(enabled);
    ui->gainSlider->setEnabled(enabled);
    ui->label1->setEnabled(enabled);
}

/*! \brief Get current AGC threshold. */
int CAgcOptions::threshold()
{
    return ui->thresholdSlider->value();
}

/*! \brief Set new AGC threshold. */
void CAgcOptions::setThreshold(int value)
{
    ui->thresholdSlider->setValue(value);
    ui->thresholdLabel->setText(QString("%1 dB").arg(ui->thresholdSlider->value()));
}

/*! \brief Get current AGC slope. */
int CAgcOptions::slope()
{
    return ui->slopeSlider->value();
}

/*! \brief Set new AGC slope. */
void CAgcOptions::setSlope(int value)
{
    ui->slopeSlider->setValue(value);
    ui->slopeLabel->setText(QString("%1 dB").arg(ui->slopeSlider->value()));
}

/*! \brief Enable or disable AGC slope slider.
 *  \param enabled Whether the slider should be enabled or not.
 *
 * The slope slider is enabled when AGC is in user mode.
 */
void CAgcOptions::enableSlope(bool enabled)
{
    ui->slopeSlider->setEnabled(enabled);
    ui->slopeLabel->setEnabled(enabled);
    ui->label3->setEnabled(enabled);
}

/*! \brief Get current decay value. */
int CAgcOptions::decay()
{
    return ui->decaySlider->value();
}

/*! \brief Set new decay value. */
void CAgcOptions::setDecay(int value)
{
    ui->decaySlider->setValue(value);
    ui->decayLabel->setText(QString("%1 ms").arg(ui->decaySlider->value()));
}

/*! \brief Enable or disable AGC decay slider.
 *  \param enabled Whether the slider should be enabled or not.
 *
 * The decay slider is enabled when AGC is in user mode.
 */
void CAgcOptions::enableDecay(bool enabled)
{
    ui->decaySlider->setEnabled(enabled);
    ui->decayLabel->setEnabled(enabled);
    ui->label4->setEnabled(enabled);
}

/*! \brief Get current state of AGC hang button. */
bool CAgcOptions::hang()
{
    return ui->hangButton->isChecked();
}

/*! \brief Set state og AGC hang button. */
void CAgcOptions::setHang(bool checked)
{
    ui->hangButton->setChecked(checked);
}



/*! \brief AGC gain slider value has changed. */
void CAgcOptions::on_gainSlider_valueChanged(int gain)
{
    ui->gainLabel->setText(QString("%1 dB").arg(ui->gainSlider->value()));
    emit gainChanged(gain);
}

/*! \brief AGC threshold slider value has changed. */
void CAgcOptions::on_thresholdSlider_valueChanged(int threshold)
{
    ui->thresholdLabel->setText(QString("%1 dB").arg(ui->thresholdSlider->value()));
    emit thresholdChanged(threshold);
}

/*! \brief AGC slope slider value has changed. */
void CAgcOptions::on_slopeSlider_valueChanged(int slope)
{
    ui->slopeLabel->setText(QString("%1 dB").arg(ui->slopeSlider->value()));
    emit slopeChanged(slope);
}

/*! \brief AGC decay slider value has changed. */
void CAgcOptions::on_decaySlider_valueChanged(int decay)
{
    ui->decayLabel->setText(QString("%1 ms").arg(ui->decaySlider->value()));
    emit decayChanged(decay);
}

/*! \brief AGC hang button has been toggled. */
void CAgcOptions::on_hangButton_toggled(bool checked)
{
    ui->hangButton->setText(checked ? tr("Enabled") : tr("Disabled"));
    emit hangChanged(checked);
}