MixerInternal.hxx 2.18 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2017 The Music Player Daemon Project
3 4 5 6 7 8 9 10 11 12 13
 * http://www.musicpd.org
 *
 * 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.
 *
 * This program 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.
14 15 16 17
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
 */
19

20 21
#ifndef MPD_MIXER_INTERNAL_HXX
#define MPD_MIXER_INTERNAL_HXX
22

23 24
#include "MixerPlugin.hxx"
#include "MixerList.hxx"
25
#include "thread/Mutex.hxx"
26
#include "Compiler.h"
27

28 29
class MixerListener;

30 31
class Mixer {
public:
32
	const MixerPlugin &plugin;
33

34 35
	MixerListener &listener;

36 37 38 39
	/**
	 * This mutex protects all of the mixer struct, including its
	 * implementation, so plugins don't have to deal with that.
	 */
40
	Mutex mutex;
41 42 43 44 45

	/**
	 * Is the mixer device currently open?
	 */
	bool open;
46 47 48 49 50 51

	/**
	 * Has this mixer failed, and should not be reopened
	 * automatically?
	 */
	bool failed;
Viliam Mateicka's avatar
Viliam Mateicka committed
52

53
public:
54 55
	explicit Mixer(const MixerPlugin &_plugin, MixerListener &_listener)
		:plugin(_plugin), listener(_listener),
56 57 58
		 open(false),
		 failed(false) {}

59 60
	Mixer(const Mixer &) = delete;

61 62
	virtual ~Mixer() {}

63
	bool IsPlugin(const MixerPlugin &other) const {
64
		return &plugin == &other;
65
	}
66 67 68 69

	/**
	 * Open mixer device
	 *
70
	 * Throws std::runtime_error on error.
71
	 */
72
	virtual void Open() = 0;
73 74 75 76 77 78 79 80 81

	/**
	 * Close mixer device
	 */
	virtual void Close() = 0;

	/**
	 * Reads the current volume.
	 *
82 83
	 * Throws std::runtime_error on error.
	 *
84
	 * @return the current volume (0..100 including) or -1 if
85
	 * unavailable
86 87
	 */
	gcc_pure
88
	virtual int GetVolume() = 0;
89 90 91 92

	/**
	 * Sets the volume.
	 *
93 94 95
	 * Throws std::runtime_error on error.
	 *
	 * @param volume the new volume (0..100 including)
96
	 */
97
	virtual void SetVolume(unsigned volume) = 0;
98
};
99

100
#endif