summaryrefslogtreecommitdiff
path: root/Userland/Applications/Piano/KeysWidget.h
blob: d21aba7fa0aecd1ea14a5f4c69f11729e1d486d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
 * Copyright (c) 2019-2020, William McPherson <willmcpherson2@gmail.com>
 * Copyright (c) 2022, the SerenityOS developers.
 *
 * SPDX-License-Identifier: BSD-2-Clause
 */

#pragma once

#include "Music.h"
#include <LibGUI/Frame.h>

class TrackManager;

class KeysWidget final : public GUI::Frame {
    C_OBJECT(KeysWidget)
public:
    virtual ~KeysWidget() override = default;

    int key_code_to_key(int key_code) const;
    int mouse_note() const;

    void set_key(int key, Switch);
    bool note_is_set(int note) const;

private:
    explicit KeysWidget(TrackManager&);

    virtual void paint_event(GUI::PaintEvent&) override;
    virtual void mousedown_event(GUI::MouseEvent&) override;
    virtual void mouseup_event(GUI::MouseEvent&) override;
    virtual void mousemove_event(GUI::MouseEvent&) override;

    int note_for_event_position(Gfx::IntPoint const&) const;

    TrackManager& m_track_manager;

    u8 m_key_on[note_count] { 0 };

    bool m_mouse_down { false };
    int m_mouse_note { -1 };
};