summaryrefslogtreecommitdiff
path: root/include/SSVOpenHexagon/Global/Audio.hpp
blob: a88d89988a26274223b4b880f46d3803f0d7628f (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
// Copyright (c) 2013-2020 Vittorio Romeo
// License: Academic Free License ("AFL") v. 3.0
// AFL License page: https://opensource.org/licenses/AFL-3.0

#pragma once

#include <string>
#include <memory>
#include <functional>

namespace sf {
class SoundBuffer;
}

namespace hg {

class Audio
{
public:
    using SoundBufferGetter =
        std::function<sf::SoundBuffer*(const std::string&)>;

    using MusicPathGetter =
        std::function<const std::string*(const std::string&)>;

private:
    class AudioImpl;

    std::unique_ptr<AudioImpl> _impl;

    [[nodiscard]] const AudioImpl& impl() const noexcept;
    [[nodiscard]] AudioImpl& impl() noexcept;

public:
    explicit Audio(const SoundBufferGetter& soundBufferGetter,
        const MusicPathGetter& musicPathGetter);

    ~Audio();

    void setSoundVolume(const float volume);
    void setMusicVolume(const float volume);

    void resumeMusic();
    void pauseMusic();
    void stopMusic();

    void stopSounds();

    void playSoundOverride(const std::string& id);
    void playPackSoundOverride(
        const std::string& packId, const std::string& id);

    void playSoundAbort(const std::string& id);
    void playPackSoundAbort(const std::string& packId, const std::string& id);

    [[nodiscard]] bool loadAndPlayMusic(const std::string& packId,
        const std::string& id, const float playingOffsetSeconds);

    void setCurrentMusicPitch(const float pitch);
};

} // namespace hg