/* * Copyright (c) 2018-2020, Andreas Kling * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include class PlaybackManager final { public: PlaybackManager(NonnullRefPtr); ~PlaybackManager(); void play(); void stop(); void pause(); void seek(const int position); void loop(bool); bool toggle_pause(); void set_loader(NonnullRefPtr&&); size_t device_sample_rate() const { return m_device_sample_rate; } int last_seek() const { return m_last_seek; } bool is_paused() const { return m_paused; } float total_length() const { return m_total_length; } RefPtr current_buffer() const { return m_current_buffer; } NonnullRefPtr connection() const { return m_connection; } Function on_update; Function on_load_sample_buffer; Function on_finished_playing; private: void next_buffer(); void set_paused(bool); bool m_paused { true }; bool m_loop = { false }; size_t m_last_seek { 0 }; float m_total_length { 0 }; // FIXME: Get this from the audio server size_t m_device_sample_rate { 44100 }; size_t m_device_samples_per_buffer { 0 }; size_t m_source_buffer_size_bytes { 0 }; RefPtr m_loader { nullptr }; NonnullRefPtr m_connection; RefPtr m_current_buffer; RefPtr m_timer; // Controls the GUI update rate. A smaller value makes the visualizations nicer. static constexpr u32 update_rate_ms = 50; // Number of milliseconds of audio data contained in each audio buffer static constexpr u32 buffer_size_ms = 100; };