Serenity Operating System
1/*
2 * Copyright (c) 2021, Cesar Torres <shortanemoia@protonmail.com>
3 * Copyright (c) 2021, the SerenityOS developers.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause
6 */
7
8#pragma once
9
10#include "PlaybackManager.h"
11#include "Player.h"
12#include "VisualizationWidget.h"
13#include <AK/FixedArray.h>
14#include <AK/NonnullRefPtr.h>
15#include <LibAudio/ConnectionToServer.h>
16#include <LibGUI/Slider.h>
17#include <LibGUI/Splitter.h>
18#include <LibGUI/Widget.h>
19
20class SoundPlayerWidgetAdvancedView final : public GUI::Widget
21 , public Player {
22 C_OBJECT(SoundPlayerWidgetAdvancedView)
23
24public:
25 void set_nonlinear_volume_slider(bool nonlinear);
26 void set_playlist_visible(bool visible);
27
28 template<typename T, typename... Args>
29 void set_visualization(Args... args)
30 {
31 m_visualization->remove_from_parent();
32 update();
33 auto new_visualization = T::construct(move(args)...);
34 m_player_view->insert_child_before(new_visualization, *static_cast<Core::Object*>(m_playback_progress_slider.ptr()));
35 m_visualization = new_visualization;
36 if (!loaded_filename().is_empty())
37 m_visualization->start_new_file(loaded_filename());
38 }
39
40 virtual void play_state_changed(PlayState) override;
41 virtual void loop_mode_changed(LoopMode) override;
42 virtual void shuffle_mode_changed(ShuffleMode) override;
43 virtual void time_elapsed(int) override;
44 virtual void file_name_changed(StringView) override;
45 virtual void playlist_loaded(StringView, bool) override;
46 virtual void audio_load_error(StringView path, StringView error_reason) override;
47 virtual void volume_changed(double) override;
48 virtual void mute_changed(bool) override;
49 virtual void total_samples_changed(int) override;
50 virtual void sound_buffer_played(FixedArray<Audio::Sample> const&, int sample_rate, int samples_played) override;
51
52protected:
53 void keydown_event(GUI::KeyEvent&) override;
54
55private:
56 SoundPlayerWidgetAdvancedView(GUI::Window&, Audio::ConnectionToServer&);
57
58 void sync_previous_next_actions();
59
60 void drag_enter_event(GUI::DragEvent& event) override;
61 void drop_event(GUI::DropEvent& event) override;
62 GUI::Window& m_window;
63
64 RefPtr<GUI::HorizontalSplitter> m_splitter;
65 RefPtr<GUI::Widget> m_player_view;
66 RefPtr<PlaylistWidget> m_playlist_widget;
67 RefPtr<VisualizationWidget> m_visualization;
68
69 RefPtr<Gfx::Bitmap> m_play_icon;
70 RefPtr<Gfx::Bitmap> m_pause_icon;
71 RefPtr<Gfx::Bitmap> m_stop_icon;
72 RefPtr<Gfx::Bitmap> m_back_icon;
73 RefPtr<Gfx::Bitmap> m_next_icon;
74 RefPtr<Gfx::Bitmap> m_volume_icon;
75 RefPtr<Gfx::Bitmap> m_muted_icon;
76
77 RefPtr<GUI::Action> m_play_action;
78 RefPtr<GUI::Action> m_stop_action;
79 RefPtr<GUI::Action> m_back_action;
80 RefPtr<GUI::Action> m_next_action;
81 RefPtr<GUI::Action> m_mute_action;
82
83 RefPtr<GUI::HorizontalSlider> m_playback_progress_slider;
84 RefPtr<GUI::Label> m_volume_label;
85 RefPtr<GUI::HorizontalSlider> m_volume_slider;
86 RefPtr<GUI::Label> m_timestamp_label;
87
88 bool m_nonlinear_volume_slider;
89};