summaryrefslogtreecommitdiffstats
path: root/kradio3/src/frequencyseekhelper.cpp
blob: 84a2bc93b1763046c89a59f16157446989256ed8 (plain)
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
/***************************************************************************
                          frequencyseekhelper.cpp  -  description
                             -------------------
    begin                : Fre Mai 9 2003
    copyright            : (C) 2003 by Martin Witte
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program 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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "include/frequencyseekhelper.h"
#include <tqtimer.h>

FrequencySeekHelper::FrequencySeekHelper(ISeekRadio &tqparent)
  : SeekHelper(tqparent)
{
    m_timer = new TQTimer(this);
    TQObject::connect (m_timer, TQT_SIGNAL(timeout()), this, TQT_SLOT(step()));
}


FrequencySeekHelper::~FrequencySeekHelper()
{
    delete m_timer;
}


bool FrequencySeekHelper::connectI   (Interface *i)
{
    bool a = SeekHelper::connectI(i);
    bool b = IFrequencyRadioClient::connectI(i);
    return a || b;
}


bool FrequencySeekHelper::disconnectI(Interface *i)
{
    bool a = SeekHelper::disconnectI(i);
    bool b = IFrequencyRadioClient::disconnectI(i);
    return a || b;
}


void FrequencySeekHelper::start(const SoundStreamID &id, direction_t dir)
{
    SeekHelper::start(id, dir);
    m_bestFrequency = 0;
}


void FrequencySeekHelper::abort()
{
    m_timer->stop();
    m_bestFrequency = 0;
}


bool FrequencySeekHelper::nextSeekStep()
{
    float f = queryFrequency();
    f += (m_direction == up ? 1 : -1) * queryScanStep();

    bool bounds = false;
    if (f > queryMaxFrequency()) {
        f = queryMaxFrequency();
        bounds = true;
    }
    if (f < queryMinFrequency()) {
        f = queryMinFrequency();
        bounds = true;
    }

    if (sendFrequency(f) > 0) {
        if (!bounds) {
            m_timer->start (50, true);
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}


bool FrequencySeekHelper::bestFound() const
{
    return m_bestFrequency > 0;
}


void FrequencySeekHelper::rememberBest()
{
    m_bestFrequency = m_currentFrequency;
}


void FrequencySeekHelper::getData()
{
    m_oldSignal        = m_currentSignal;
    m_oldFrequency     = m_currentFrequency;

    querySignalQuality(m_SoundStreamID, m_currentSignal);
    queryHasGoodQuality(m_SoundStreamID, m_goodSignal);
    m_currentFrequency = queryFrequency();
}


bool FrequencySeekHelper::isBetter() const
{
    return m_currentSignal > m_oldSignal;
}


bool FrequencySeekHelper::isWorse() const
{
    return m_currentSignal < m_oldSignal;
}


bool FrequencySeekHelper::isGood() const
{
    return m_goodSignal;
}


void FrequencySeekHelper::applyBest()
{
    sendFrequency( (m_bestFrequency + m_currentFrequency) / 2);
}




#include "frequencyseekhelper.moc"