1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-10-27 22:22:33 +00:00
serenity/Userland/Applications/Piano/RollWidget.h
kleines Filmröllchen c1345bda3e Userland: Piano: Optimize repaints
The Piano application used to perform very poorly due to unnecessary
draw calls. This is solved with two optimziations:

1. Don't draw the widgets as often as possible. The widgets are instead
   at least updated every 150ms, except for other events.
2. Don't re-draw the entire piano roll sheet. The piano roll background,
   excluding in-motion objects (notes, the play cursor), is only re-drawn
   when its "viewport" changes.

A minor drawback of this change is that notes will appear on top of the
pitch labels if placed at the left edge of the roll. This is IMO
acceptable or may be changed by moving the text to the "foreground".
2021-04-23 22:35:49 +02:00

51 lines
1.5 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2019-2020, William McPherson <willmcpherson2@gmail.com>
* Copyright (c) 2021, kleines Filmröllchen <malu.bertsch@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include "KeysWidget.h"
#include "Music.h"
#include <LibGUI/ScrollableWidget.h>
class TrackManager;
class RollWidget final : public GUI::ScrollableWidget {
C_OBJECT(RollWidget)
public:
virtual ~RollWidget() override;
const KeysWidget* keys_widget() const { return m_keys_widget; }
void set_keys_widget(const KeysWidget* widget) { m_keys_widget = widget; }
private:
explicit RollWidget(TrackManager&);
virtual void paint_event(GUI::PaintEvent&) override;
virtual void mousedown_event(GUI::MouseEvent& event) override;
virtual void mousemove_event(GUI::MouseEvent& event) override;
virtual void mouseup_event(GUI::MouseEvent& event) override;
virtual void mousewheel_event(GUI::MouseEvent&) override;
bool viewport_changed() const;
TrackManager& m_track_manager;
const KeysWidget* m_keys_widget;
int m_roll_width { 0 };
int m_num_notes { 0 };
double m_note_width { 0.0 };
int m_zoom_level { 1 };
Optional<Gfx::IntPoint> m_note_drag_start;
Optional<RollNote> m_note_drag_location;
int m_drag_note;
RefPtr<Gfx::Bitmap> m_background;
int m_prev_zoom_level { m_zoom_level };
int m_prev_scroll_x { horizontal_scrollbar().value() };
int m_prev_scroll_y { vertical_scrollbar().value() };
};