Serenity Operating System
at hosted 92 lines 3.3 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, this 9 * list of conditions and the following disclaimer. 10 * 11 * 2. Redistributions in binary form must reproduce the above copyright notice, 12 * this list of conditions and the following disclaimer in the documentation 13 * and/or other materials provided with the distribution. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 */ 26 27#pragma once 28 29#include "PlaybackManager.h" 30#include "SampleWidget.h" 31#include <LibGUI/Button.h> 32#include <LibGUI/Label.h> 33#include <LibGUI/Slider.h> 34#include <LibGUI/Widget.h> 35#include <LibGUI/Window.h> 36 37class SoundPlayerWidget final : public GUI::Widget { 38 C_OBJECT(SoundPlayerWidget) 39public: 40 virtual ~SoundPlayerWidget() override; 41 void open_file(String path); 42 void hide_scope(bool); 43 PlaybackManager& manager() { return m_manager; } 44 45private: 46 explicit SoundPlayerWidget(GUI::Window&, NonnullRefPtr<Audio::ClientConnection>); 47 48 void update_position(const int position); 49 void update_ui(); 50 int normalize_rate(int) const; 51 int denormalize_rate(int) const; 52 53 class Slider final : public GUI::Slider { 54 C_OBJECT(Slider) 55 public: 56 virtual ~Slider() override; 57 Function<void(int)> on_knob_released; 58 void set_value(int value) 59 { 60 if (!knob_dragging()) 61 GUI::Slider::set_value(value); 62 } 63 64 protected: 65 Slider(Orientation orientation) 66 : GUI::Slider(orientation) 67 { 68 } 69 70 virtual void mouseup_event(GUI::MouseEvent& event) override 71 { 72 if (on_knob_released && is_enabled()) 73 on_knob_released(value()); 74 75 GUI::Slider::mouseup_event(event); 76 } 77 }; 78 79 GUI::Window& m_window; 80 NonnullRefPtr<Audio::ClientConnection> m_connection; 81 PlaybackManager m_manager; 82 float m_sample_ratio; 83 RefPtr<GUI::Label> m_status; 84 RefPtr<GUI::Label> m_elapsed; 85 RefPtr<GUI::Label> m_remaining; 86 RefPtr<Slider> m_slider; 87 RefPtr<SampleWidget> m_sample_widget; 88 RefPtr<Gfx::Bitmap> m_play_icon { Gfx::Bitmap::load_from_file("/res/icons/16x16/play.png") }; 89 RefPtr<Gfx::Bitmap> m_pause_icon { Gfx::Bitmap::load_from_file("/res/icons/16x16/pause.png") }; 90 RefPtr<GUI::Button> m_play; 91 RefPtr<GUI::Button> m_stop; 92};