aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/facade/SoundContext.h
blob: 3bc8be504ef60b4babcc0c0062a65efb41c65524 (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
#pragma once

#include <soloud/soloud.h>

#include "../api/Config.h"

#include "Sound.h"

namespace crepe {

/**
 * \brief Sound engine facade
 *
 * This class is a wrapper around a \c SoLoud::Soloud instance, which provides the methods for
 * playing \c Sound instances. It is part of the sound facade.
 */
class SoundContext {
public:
	SoundContext();
	virtual ~SoundContext();

	SoundContext(const SoundContext &) = delete;
	SoundContext(SoundContext &&) = delete;
	SoundContext & operator=(const SoundContext &) = delete;
	SoundContext & operator=(SoundContext &&) = delete;

	/**
	 * \brief Play a sample
	 *
	 * Plays a Sound from the beginning of the sample and returns a handle to control it later.
	 *
	 * \param resource Sound instance to play
	 *
	 * \returns Handle to control this voice
	 */
	virtual Sound::Handle play(Sound & resource);
	/**
	 * \brief Stop a voice immediately if it is still playing
	 *
	 * \note This function does nothing if the handle is invalid or if the sound is already
	 * stopped / finished playing.
	 *
	 * \param handle Voice handle returned by SoundContext::play
	 */
	virtual void stop(Sound::Handle & handle);
	/**
	 * \brief Change the volume of a voice
	 *
	 * \note This function does nothing if the handle is invalid or if the sound is already
	 * stopped / finished playing.
	 *
	 * \param handle Voice handle returned by SoundContext::play
	 * \param volume New gain value (0=silent, 1=default)
	 */
	virtual void set_volume(Sound::Handle & handle, float volume);
	/**
	 * \brief Set the looping behavior of a voice
	 *
	 * \note This function does nothing if the handle is invalid or if the sound is already
	 * stopped / finished playing.
	 *
	 * \param handle Voice handle returned by SoundContext::play
	 * \param loop Looping behavior (false=oneshot, true=loop)
	 */
	virtual void set_loop(Sound::Handle & handle, bool loop);

private:
	//! Abstracted class
	SoLoud::Soloud engine;

	//! Config reference
	Config & config = Config::get_instance();
};

} // namespace crepe