MixerInternal.hxx 2.19 KB
Newer Older
1
/*
Max Kellermann's avatar
Max Kellermann committed
2
 * Copyright 2003-2021 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 "util/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

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

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

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

58 59
	Mixer(const Mixer &) = delete;

60 61
	virtual ~Mixer() {}

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

	/**
	 * Open mixer device
	 *
69
	 * Throws std::runtime_error on error.
70
	 */
71
	virtual void Open() = 0;
72 73 74 75

	/**
	 * Close mixer device
	 */
76
	virtual void Close() noexcept = 0;
77 78 79 80

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

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

98
#endif