Skip to content

Protected SFML Methods cannot be consumed by CSFML consumers #394

Open
@ShadowMarker789

Description

@ShadowMarker789

Consider sf::Audio

////////////////////////////////////////////////////////////
bool Music::onGetData(SoundStream::Chunk& data)
{
    const std::lock_guard lock(m_impl->mutex);

    std::size_t         toFill        = m_impl->samples.size();
    std::uint64_t       currentOffset = m_impl->file.getSampleOffset();
    const std::uint64_t loopEnd       = m_impl->loopSpan.offset + m_impl->loopSpan.length;

    // If the loop end is enabled and imminent, request less data.
    // This will trip an "onLoop()" call from the underlying SoundStream,
    // and we can then take action.
    if (isLooping() && (m_impl->loopSpan.length != 0) && (currentOffset <= loopEnd) && (currentOffset + toFill > loopEnd))
        toFill = static_cast<std::size_t>(loopEnd - currentOffset);

    // Fill the chunk parameters
    data.samples     = m_impl->samples.data();
    data.sampleCount = static_cast<std::size_t>(m_impl->file.read(m_impl->samples.data(), toFill));
    currentOffset += data.sampleCount;

    // Check if we have stopped obtaining samples or reached either the EOF or the loop end point
    return (data.sampleCount != 0) && (currentOffset < m_impl->file.getSampleCount()) &&
           (currentOffset != loopEnd || m_impl->loopSpan.length == 0);
}

This is a protected method, intended to be overriden by user classes for custom behaviour when required.

Consider the usecase of wanting to present and draw the waveform of Audio streamed from disk with sf::Audio

This is impossible with consumers of CSFML or those downstream (e.g.: SFML.Net C# Consumers)

I do not know how it ought to be done, but consumers of CSFML should have a way to consume and override or obtain information from these protected methods.

As of right now, if one wants said waveform in C# they would need to fork SFML, create a new class that overrides onGetData, fork CSFML to bind that functionality, and then bind that into C# via SFML.Net. That's a bit much, ain't it?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions