MCPcopy Create free account
hub / github.com/SFML/SFML / onLoop

Method onLoop

src/SFML/Audio/Music.cpp:289–312  ·  view source on GitHub ↗

///////////////////////////////////////////////////////

Source from the content-addressed store, hash-verified

287
288////////////////////////////////////////////////////////////
289std::optional<std::uint64_t> Music::onLoop()
290{
291 // Called by underlying SoundStream so we can determine where to loop.
292 const std::lock_guard lock(m_impl->mutex);
293 const std::uint64_t currentOffset = m_impl->file.getSampleOffset();
294
295 if (isLooping() && (m_impl->loopSpan.length != 0) &&
296 (currentOffset == m_impl->loopSpan.offset + m_impl->loopSpan.length))
297 {
298 // Looping is enabled, and either we're at the loop end, or we're at the EOF
299 // when it's equivalent to the loop end (loop end takes priority). Send us to loop begin
300 m_impl->file.seek(m_impl->loopSpan.offset);
301 return m_impl->file.getSampleOffset();
302 }
303
304 if (isLooping() && (currentOffset >= m_impl->file.getSampleCount()))
305 {
306 // If we're at the EOF, reset to 0
307 m_impl->file.seek(0);
308 return 0;
309 }
310
311 return std::nullopt;
312}
313
314
315////////////////////////////////////////////////////////////

Callers

nothing calls this directly

Calls 3

getSampleOffsetMethod · 0.80
seekMethod · 0.45
getSampleCountMethod · 0.45

Tested by

no test coverage detected