summaryrefslogtreecommitdiffstats
path: root/kradio3/plugins/v4lradio/v4lcfg_interfaces.h
blob: f2e103296d28d38a12383bc291bcee4460eb9477 (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
143
144
145
146
147
148
149
150
151
/***************************************************************************
                          v4lradio_interfaces.h  -  description
                             -------------------
    begin                : Sam Jun 21 2003
    copyright            : (C) 2003 by Martin Witte
    email                : witte@kawo1.rwth-aachen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   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.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef KRADIO_V4LCFG_INTERFACES_H
#define KRADIO_V4LCFG_INTERFACES_H

#include "../../src/include/interfaces.h"
#include "math.h"

struct V4LCaps
{
    int     version;
    QString description;

    bool    hasMute;

    bool    hasVolume;
    int     minVolume,  maxVolume;
    bool    hasTreble;
    int     minTreble,  maxTreble;
    bool    hasBass;
    int     minBass,    maxBass;
    bool    hasBalance;
    int     minBalance, maxBalance;

    V4LCaps();
    V4LCaps(const V4LCaps &);

    float  volumeStep()  const { return 1.0 / (float)(maxVolume  - minVolume); }
    float  trebleStep()  const { return 1.0 / (float)(maxTreble  - minTreble); }
    float  bassStep()    const { return 1.0 / (float)(maxBass    - minBass); }
    float  balanceStep() const { return 1.0 / (float)(maxBalance - minBalance); }

    void   setVolume (int min, int max) { hasVolume  = true; minVolume  = min; maxVolume  = max; }
    void   setTreble (int min, int max) { hasTreble  = true; minTreble  = min; maxTreble  = max; }
    void   setBass   (int min, int max) { hasBass    = true; minBass    = min; maxBass    = max; }
    void   setBalance(int min, int max) { hasBalance = true; minBalance = min; maxBalance = max; }

    void   unsetVolume () { hasVolume  = false; minVolume  = 0; maxVolume  = 65535; }
    void   unsetTreble () { hasTreble  = false; minTreble  = 0; maxTreble  = 65535; }
    void   unsetBass   () { hasBass    = false; minBass    = 0; maxBass    = 65535; }
    void   unsetBalance() { hasBalance = false; minBalance = 0; maxBalance = 65535; }

    int    intGetVolume (float f) const { return (int)rint(minVolume  + (maxVolume  - minVolume ) * f); }
    int    intGetTreble (float f) const { return (int)rint(minTreble  + (maxTreble  - minTreble ) * f); }
    int    intGetBass   (float f) const { return (int)rint(minBass    + (maxBass    - minBass   ) * f); }
    int    intGetBalance(float f) const { return (int)rint(minBalance + (maxBalance - minBalance) / 2.0 * (1.0 + f)); }

    float  floatGetVolume (int i) const { return (float)(i - minVolume)  * volumeStep(); }
    float  floatGetTreble (int i) const { return (float)(i - minTreble)  * trebleStep(); }
    float  floatGetBass   (int i) const { return (float)(i - minBass  )  * bassStep(); }
    float  floatGetBalance(int i) const { return (float)(i - minBalance) * balanceStep() * 2.0 - 1.0; }
};



INTERFACE(IV4LCfg, IV4LCfgClient)
{
public:
    IF_CON_DESTRUCTOR(IV4LCfg, -1)

RECEIVERS:
    IF_RECEIVER(   setRadioDevice  (const QString &s)                            )
    IF_RECEIVER(   setPlaybackMixer(const QString &soundStreamClientID, const QString &ch)  )
    IF_RECEIVER(   setCaptureMixer (const QString &soundStreamClientID, const QString &ch)  )
    IF_RECEIVER(   setDeviceVolume(float v)                                      )
    IF_RECEIVER(   setActivePlayback(bool a)                                     )
    IF_RECEIVER(   setMuteOnPowerOff(bool m)                                     )
    IF_RECEIVER(   setVolumeZeroOnPowerOff(bool m)                               )

SENDERS:
    IF_SENDER  (   notifyRadioDeviceChanged  (const QString &s)                   )
    IF_SENDER  (   notifyPlaybackMixerChanged(const QString &soundStreamClientID, const QString &Channel)      )
    IF_SENDER  (   notifyCaptureMixerChanged (const QString &soundStreamClientID, const QString &Channel)      )
    IF_SENDER  (   notifyDeviceVolumeChanged (float v)                           )
    IF_SENDER  (   notifyCapabilitiesChanged (const V4LCaps &)                   )
    IF_SENDER  (   notifyActivePlaybackChanged (bool a)                          )
    IF_SENDER  (   notifyMuteOnPowerOffChanged (bool a)                          )
    IF_SENDER  (   notifyVolumeZeroOnPowerOffChanged (bool a)                    )

ANSWERS:
    IF_ANSWER  (   const QString &getRadioDevice () const                       )
    IF_ANSWER  (   const QString &getPlaybackMixerID () const                   )
    IF_ANSWER  (   const QString &getCaptureMixerID () const                    )
    IF_ANSWER  (   const QString &getPlaybackMixerChannel() const               )
    IF_ANSWER  (   const QString &getCaptureMixerChannel() const                )
    IF_ANSWER  (   float          getDeviceVolume() const                       )
    IF_ANSWER  (   V4LCaps        getCapabilities(QString dev = QString::null) const )
    IF_ANSWER  (   bool           getActivePlayback() const                     )
    IF_ANSWER  (   bool           getMuteOnPowerOff() const                     )
    IF_ANSWER  (   bool           getVolumeZeroOnPowerOff() const               )
};



INTERFACE(IV4LCfgClient, IV4LCfg)
{
public:
    IF_CON_DESTRUCTOR(IV4LCfgClient, 1)

SENDERS:
    IF_SENDER  (   sendRadioDevice (const QString &s)                            )
    IF_SENDER  (   sendPlaybackMixer(const QString &soundStreamClientID, const QString &ch) )
    IF_SENDER  (   sendCaptureMixer (const QString &soundStreamClientID, const QString &ch) )
    IF_SENDER  (   sendDeviceVolume(float v)                                     )
    IF_SENDER  (   sendActivePlayback(bool a)                                    )
    IF_SENDER  (   sendMuteOnPowerOff(bool a)                                    )
    IF_SENDER  (   sendVolumeZeroOnPowerOff(bool a)                              )

RECEIVERS:
    IF_RECEIVER(   noticeRadioDeviceChanged(const QString &s)                    )
    IF_RECEIVER(   noticePlaybackMixerChanged(const QString &soundStreamClientID, const QString &Channel)       )
    IF_RECEIVER(   noticeCaptureMixerChanged (const QString &soundStreamClientID, const QString &Channel)       )
    IF_RECEIVER(   noticeDeviceVolumeChanged(float v)                            )
    IF_RECEIVER(   noticeCapabilitiesChanged(const V4LCaps &)                    )
    IF_RECEIVER(   noticeActivePlaybackChanged(bool a)                           )
    IF_RECEIVER(   noticeMuteOnPowerOffChanged(bool a)                           )
    IF_RECEIVER(   noticeVolumeZeroOnPowerOffChanged(bool a)                     )

QUERIES:
    IF_QUERY   (   const QString &queryRadioDevice ()                            )
    IF_QUERY   (   const QString &queryPlaybackMixerID ()                        )
    IF_QUERY   (   const QString &queryCaptureMixerID ()                         )
    IF_QUERY   (   const QString &queryPlaybackMixerChannel()                    )
    IF_QUERY   (   const QString &queryCaptureMixerChannel()                     )
    IF_QUERY   (   float          queryDeviceVolume()                            )
    IF_QUERY   (   V4LCaps        queryCapabilities(QString dev = QString::null) )
    IF_QUERY   (   bool           queryActivePlayback()                          )
    IF_QUERY   (   bool           queryMuteOnPowerOff()                          )
    IF_QUERY   (   bool           queryVolumeZeroOnPowerOff()                    )

RECEIVERS:
    virtual void noticeConnectedI    (cmplInterface *, bool /*pointer_valid*/);
    virtual void noticeDisconnectedI (cmplInterface *, bool /*pointer_valid*/);
};

#endif