summaryrefslogtreecommitdiff
path: root/src/model/alsadevice.h
blob: cc26801f9cbc1dddaa6abd7bce9e5568f4bbedc1 (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
#pragma once

#include <tqobject.h>
#include <tqstring.h>
#include <tqstringlist.h>
#include <alsa/asoundlib.h>

class AlsaDevice : public TQObject
{
    TQ_OBJECT
public:
    enum Category { Output, Input, Neutral };
    enum Type     { Slider, Switch, Enum };

    AlsaDevice( Category cat, int cardIndex, snd_mixer_elem_t *elem,
                const TQString &cardName, TQObject *parent = 0 );

    TQString  name()       const { return m_name; }
    TQString  cardName()   const { return m_cardName; }
    int      cardIndex()  const { return m_cardIndex; }
    Category category()   const { return m_category; }
    Type     type()       const { return m_type; }

    // Slider
    int      volume()  const { return m_volume; }
    bool     muted()   const { return m_muted; }
    int      pan()     const { return m_pan; }
    bool     stereo()  const { return m_stereo; }
    bool     hasMute() const { return m_hasMute; }
    void setVolume( int v );
    void setMuted( bool m );
    void setPan( int p );

    // Enum
    TQStringList enumValues() const { return m_enumValues; }
    int         enumId()     const { return m_enumId; }
    void setEnumId( int id );

    void syncFromAlsa();
    static int elemCallback( snd_mixer_elem_t *elem, unsigned int mask );

signals:
    void volumeChanged( int v );
    void muteChanged( bool m );
    void panChanged( int p );
    void enumChanged( int id );

private:
    long toAlsaVol( int pct ) const;
    void pushVolume();

    Category          m_category;
    Type              m_type;
    int               m_cardIndex;
    snd_mixer_elem_t *m_elem;
    TQString           m_name;
    TQString           m_cardName;
    bool              m_stereo;
    bool              m_hasMute;
    long              m_volMin;
    long              m_volMax;
    int               m_volume;
    bool              m_muted;
    int               m_pan;
    TQStringList       m_enumValues;
    int               m_enumId;
};