libSDL2pp
C++ bindings/wrapper for SDL2
Loading...
Searching...
No Matches
Mixer.hh
1/*
2 libSDL2pp - C++ bindings/wrapper for SDL2
3 Copyright (C) 2015-2016 Dmitry Marakasov <amdmi3@amdmi3.ru>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22#ifndef SDL2PP_MIXER_HH
23#define SDL2PP_MIXER_HH
24
25#include <functional>
26#include <memory>
27
28#include <SDL_stdinc.h>
29#include <SDL_mixer.h>
30
31#include <SDL2pp/Export.hh>
32
33namespace SDL2pp {
34
35class Chunk;
36class Music;
37
50class SDL2PP_EXPORT Mixer {
51public:
52 typedef void (*ChannelFinishedHandler)(int);
53 typedef void (*MusicFinishedHandler)();
54
55 typedef std::function<void(Uint8 *stream, int len)> MusicHook;
56
57private:
58 bool open_;
59 std::unique_ptr<MusicHook> current_music_hook_;
60
61public:
62
65
84 Mixer(int frequency, Uint16 format, int channels, int chunksize);
85
92 ~Mixer();
93
95
98
105 Mixer(Mixer&& other) noexcept;
106
115 Mixer& operator=(Mixer&& other) noexcept;
116
123 Mixer(const Mixer& other) = delete;
124
131 Mixer& operator=(const Mixer& other) = delete;
132
134
137
148 int AllocateChannels(int numchans);
149
158 int GetNumChannels() const;
159
174 int SetVolume(int channel, int volume);
175
188 int GetVolume(int channel) const;
189
191
194
211 int PlayChannel(int channel, const Chunk& chunk, int loops = 0);
212
233 int PlayChannel(int channel, const Chunk& chunk, int loops, int ticks);
234
253 int FadeInChannel(int channel, const Chunk& chunk, int loops, int ms);
254
277 int FadeInChannel(int channel, const Chunk& chunk, int loops, int ms, int ticks);
278
280
283
292 void PauseChannel(int channel = -1);
293
302 void ResumeChannel(int channel = -1);
303
305
308
317 void HaltChannel(int channel = -1);
318
330 int ExpireChannel(int channel, int ticks);
331
344 int FadeOutChannel(int channel, int ms);
345
359 void SetChannelFinishedHandler(ChannelFinishedHandler channel_finished);
360
367 void RemoveChannelFinishedHandler();
368
370
373
388 int IsChannelPlaying(int channel) const;
389
404 int IsChannelPaused(int channel) const;
405
416 Mix_Fading GetChannelFading(int which) const;
417
419
422
437 int ReserveChannels(int num);
438
452 void GroupChannel(int which, int tag);
453
468 void GroupChannels(int from, int to, int tag);
469
471
474
485 int GetGroupNumChannels(int tag) const;
486
498 int GetGroupAvailableChannel(int tag) const;
499
511 int GetGroupOldestChannel(int tag) const;
512
524 int GetGroupNewestChannel(int tag) const;
525
527
530
543 int FadeOutGroup(int tag, int ms);
544
553 void HaltGroup(int tag);
554
556
559
571 void PlayMusic(const Music& music, int loops = -1);
572
585 void FadeInMusic(const Music& music, int loops = -1, int ms = 0);
586
595 void SetMusicHook(MusicHook&& hook);
596
598
601
612 int SetMusicVolume(int volume);
613
622 int GetMusicVolume() const;
623
630 void PauseMusic();
631
638 void ResumeMusic();
639
646 void RewindMusic();
647
656 void SetMusicPosition(double position);
657
659
662
669 void HaltMusic();
670
682 bool FadeOutMusic(int ms);
683
696 void SetMusicFinishedHandler(MusicFinishedHandler music_finished);
697
704 void RemoveMusicFinishedHandler();
705
707
710
719 bool IsMusicPlaying() const;
720
729 bool IsMusicPaused() const;
730
739 Mix_Fading GetMusicFading() const;
740
742
745
746 // TODO: custom effects
747
763 void SetPanning(int channel, Uint8 left, Uint8 right);
764
776 void UnsetPanning(int channel);
777
791 void SetDistance(int channel, Uint8 distance);
792
804 void UnsetDistance(int channel);
805
823 void SetPosition(int channel, Sint16 angle, Uint8 distance);
824
836 void UnsetPosition(int channel);
837
849 void SetReverseStereo(int channel);
850
862 void UnsetReverseStereo(int channel);
863
865};
866
867}
868
869#endif
Fragment of audio data.
Definition: Chunk.hh:43
Audio mixer.
Definition: Mixer.hh:50
Mixer(const Mixer &other)=delete
Deleted copy constructor.
Mixer & operator=(const Mixer &other)=delete
Deleted assignment operator.
std::function< void(Uint8 *stream, int len)> MusicHook
Custom music hook.
Definition: Mixer.hh:55
Music data
Definition: Music.hh:43