File: mixers.cc

package info (click to toggle)
mp3blaster 2-0b16-1.1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 1,012 kB
  • ctags: 1,241
  • sloc: cpp: 12,228; ansic: 1,557; sh: 362; makefile: 107
file content (67 lines) | stat: -rw-r--r-- 1,408 bytes parent folder | download
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
/*\
|*|  Base class for handling different mixer types
\*/
#include <nmixer.h>

#define MIXER_ID_SHIFT 12
#define MIXER_ID_MASK (~((1 << MIXER_ID_SHIFT) - 1))

baseMixer::baseMixer(baseMixer *next)
{
	this->next = next;
	mixerID = 0;
	if (next) {
		devs = next->GetDevices(&num_devs);
		if (num_devs) {
			mixerID = (devs[num_devs - 1] & MIXER_ID_MASK) +
					(1 << MIXER_ID_SHIFT);
		}
	} else {
		devs = NULL;
		num_devs = 0;
	}
}
 
baseMixer::~baseMixer()
{
	if (devs) free(devs);
}

int *baseMixer::GetDevices(int *num)
{
	int *ret = new int[num_devs];
	*num = num_devs;
	memcpy(ret, devs, sizeof(int) * num_devs);
	return ret;
}

void baseMixer::AddDevice(int device)
{
	++num_devs;
	devs = (int *)realloc(devs, sizeof(int) * num_devs);
	devs[num_devs - 1] = device | mixerID;
}

bool baseMixer::SetMixer(int device, struct volume *vol)
{
	if ((device & MIXER_ID_MASK) == mixerID)
		return Set((device & ~MIXER_ID_MASK), vol);
	if (next) return next->SetMixer(device, vol);
	return false;
}

bool baseMixer::GetMixer(int device, struct volume *vol)
{
	if ((device & MIXER_ID_MASK) == mixerID)
		return Get(device & ~MIXER_ID_MASK, vol);
	if (next) return next->GetMixer(device, vol);
	return false;
}

const char *baseMixer::GetMixerLabel(int device)
{
	if ((device & MIXER_ID_MASK) == mixerID)
		return Label(device & ~MIXER_ID_MASK);
	if (next) return next->GetMixerLabel(device);
	return "<none>";
}