1+ // //////////////////////////////////////////////////////////
2+ //
3+ // SFML - Simple and Fast Multimedia Library
4+ // Copyright (C) 2007-2024 Laurent Gomila ([email protected] )5+ //
6+ // This software is provided 'as-is', without any express or implied warranty.
7+ // In no event will the authors be held liable for any damages 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 freely,
11+ // subject to the following restrictions:
12+ //
13+ // 1. The origin of this software must not be misrepresented;
14+ // you must not claim that you wrote the original software.
15+ // If you use this software in a product, an acknowledgment
16+ // in the product documentation would be appreciated but is not required.
17+ //
18+ // 2. Altered source versions must be plainly marked as such,
19+ // and must not be misrepresented as being the original software.
20+ //
21+ // 3. This notice may not be removed or altered from any source distribution.
22+ //
23+ // //////////////////////////////////////////////////////////
24+
25+ // //////////////////////////////////////////////////////////
26+ // Headers
27+ // //////////////////////////////////////////////////////////
28+ #include < CSFML/Audio/MusicStruct.hpp>
29+
30+
31+ // //////////////////////////////////////////////////////////
32+ bool sfMusic::onGetDataOriginal (sfMusic* music, sfSoundStreamChunk* data)
33+ {
34+ sf::SoundStream::Chunk cppData;
35+
36+ cppData.samples = data->samples ;
37+ cppData.sampleCount = data->sampleCount ;
38+
39+ bool result = music->sf ::Music::onGetData (cppData);
40+
41+ data->samples = cppData.samples ;
42+ data->sampleCount = cppData.sampleCount ;
43+
44+ return result;
45+ }
46+
47+
48+ // //////////////////////////////////////////////////////////
49+ bool sfMusic::onGetData (sf::SoundStream::Chunk& data)
50+ {
51+ if (!OnGetDataMixin)
52+ return sf::Music::onGetData (data);
53+
54+ sfSoundStreamChunk cData;
55+
56+ cData.samples = data.samples ;
57+ cData.sampleCount = data.sampleCount ;
58+
59+ bool result = OnGetDataMixin (onGetDataOriginal, this , &cData);
60+
61+ data.samples = cData.samples ;
62+ data.sampleCount = cData.sampleCount ;
63+
64+ return result;
65+ }
66+
67+
68+ // //////////////////////////////////////////////////////////
69+ void sfMusic::onSeekOriginal (sfMusic* music, sfTime timeOffset)
70+ {
71+ return music->sf ::Music::onSeek (sf::microseconds (timeOffset.microseconds ));
72+ }
73+
74+
75+ // //////////////////////////////////////////////////////////
76+ void sfMusic::onSeek (sf::Time timeOffset)
77+ {
78+ if (!OnSeekMixin)
79+ return sf::Music::onSeek (timeOffset);
80+
81+ return OnSeekMixin (onSeekOriginal, this , {timeOffset.asMicroseconds ()});
82+ }
83+
84+
85+ // //////////////////////////////////////////////////////////
86+ bool sfMusic::onLoopOriginal (sfMusic* music, uint64_t * position)
87+ {
88+ auto result = music->sf ::Music::onLoop ();
89+
90+ if (!result)
91+ {
92+ return false ;
93+ }
94+
95+ *position = *result;
96+ return true ;
97+ }
98+
99+
100+ // //////////////////////////////////////////////////////////
101+ std::optional<std::uint64_t > sfMusic::onLoop ()
102+ {
103+ if (!OnLoopMixin)
104+ return sf::Music::onLoop ();
105+
106+ std::uint64_t data = 0 ;
107+
108+ bool noLoop = OnLoopMixin (onLoopOriginal, this , &data);
109+
110+ return noLoop ? std::nullopt : std::optional (data);
111+ }
0 commit comments