Skip to content

Commit c989584

Browse files
committed
Merge branch 'piano_keys' into devel
* Implemented new tk::PianoKeys widget.
2 parents 5a0bbfb + 97c9bce commit c989584

File tree

14 files changed

+2423
-8
lines changed

14 files changed

+2423
-8
lines changed

CHANGELOG

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
=== 1.0.30 ===
66
* Implemented new tk::RangeSlider widget.
7+
* Implemented new tk::PianoKeys widget.
78
* Fixed use after free for several scenarios when destroying the display.
89

910
=== 1.0.29 ===

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ The full list of provided widgets:
8989
* Fraction - music fraction with numerator and denominator.
9090
* LedMeter - led level/peak meter with multiple channels.
9191
* LedMeterChannel - single-channel level/peak meter.
92+
* PianoKeys - a piano key layout with ability to press keys and select key range.
9293

9394
## Styling system
9495

include/lsp-plug.in/tk/prop/multi/SizeConstraints.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,11 @@ namespace lsp
144144
static void scale(ws::size_limit_t *dst, float scale);
145145

146146
static bool match(const ws::rectangle_t *r, const ws::size_limit_t *sr);
147+
148+
static void transpose(ws::size_limit_t *r);
149+
static void transpose(ws::size_limit_t *dst, const ws::size_limit_t *src);
150+
static void transpose(ws::rectangle_t *r);
151+
static void transpose(ws::rectangle_t *dst, const ws::rectangle_t *src);
147152
};
148153

149154
namespace prop
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*
2+
* Copyright (C) 2025 Linux Studio Plugins Project <https://lsp-plug.in/>
3+
* (C) 2025 Vladimir Sadovnikov <[email protected]>
4+
*
5+
* This file is part of lsp-tk-lib
6+
* Created on: 27 сент. 2025 г.
7+
*
8+
* lsp-tk-lib is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Lesser General Public License as published by
10+
* the Free Software Foundation, either version 3 of the License, or
11+
* any later version.
12+
*
13+
* lsp-tk-lib is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Lesser General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Lesser General Public License
19+
* along with lsp-tk-lib. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
#ifndef LSP_PLUG_IN_TK_PROP_SPECIFIC_NOTESTATE_H_
23+
#define LSP_PLUG_IN_TK_PROP_SPECIFIC_NOTESTATE_H_
24+
25+
#ifndef LSP_PLUG_IN_TK_IMPL
26+
#error "use <lsp-plug.in/tk/tk.h>"
27+
#endif
28+
29+
namespace lsp
30+
{
31+
namespace tk
32+
{
33+
class NoteState: public SimpleProperty
34+
{
35+
protected:
36+
static constexpr size_t NOTES_TOTAL = 128;
37+
static constexpr size_t NUM_BINS = NOTES_TOTAL / sizeof(umword_t);
38+
static constexpr size_t NUM_CHARS = NOTES_TOTAL / 4; // 4 bits per character
39+
static constexpr size_t NUM_BIN_CHARS = NUM_CHARS / NUM_BINS;
40+
static constexpr size_t BITS_PER_BIN = sizeof(umword_t) * 8;
41+
42+
static constexpr umword_t ALL_ZERO = umword_t(0);
43+
static constexpr umword_t ALL_ONES = ~umword_t(0);
44+
static constexpr umword_t ONE = umword_t(1);
45+
46+
protected:
47+
umword_t nState[NUM_BINS]; // State of all possible MIDI notes
48+
49+
protected:
50+
virtual void commit(atom_t property) override;
51+
virtual void push() override;
52+
53+
protected:
54+
static void deserialize(umword_t *dst, const char *src);
55+
static void deserialize(umword_t *dst, const lsp_wchar_t *src, size_t count);
56+
static void serialize(char *dst, const umword_t *src);
57+
58+
public:
59+
explicit NoteState(prop::Listener *listener);
60+
NoteState(const NoteState &) = delete;
61+
NoteState(NoteState &&) = delete;
62+
virtual ~NoteState() override;
63+
64+
NoteState & operator = (const NoteState &) = delete;
65+
NoteState & operator = (NoteState &&) = delete;
66+
67+
public:
68+
bool clear(size_t index);
69+
void clear_range(size_t first, size_t last);
70+
void clear_count(size_t first, size_t last);
71+
void clear_all();
72+
bool reset(size_t index);
73+
74+
bool set(size_t index);
75+
bool set(size_t index, bool on);
76+
void set_range(size_t first, size_t last);
77+
void set_count(size_t first, size_t last);
78+
void set_all();
79+
80+
bool toggle(size_t index);
81+
void toggle_range(size_t first, size_t last);
82+
void toggle_count(size_t first, size_t last);
83+
void toggle_all();
84+
85+
void set_state(const char *state);
86+
void set_state(const LSPString *state);
87+
bool get(size_t index) const;
88+
89+
bool all_set() const;
90+
bool all_unset() const;
91+
92+
void swap(NoteState *dst);
93+
void swap(NoteState &dst);
94+
};
95+
96+
namespace prop
97+
{
98+
class NoteState: public tk::NoteState
99+
{
100+
public:
101+
explicit inline NoteState(prop::Listener *listener = NULL): tk::NoteState(listener) {}
102+
NoteState(const NoteState &) = delete;
103+
NoteState(NoteState &&) = delete;
104+
105+
NoteState & operator = (const NoteState &) = delete;
106+
NoteState & operator = (NoteState &&) = delete;
107+
108+
public:
109+
inline status_t bind(atom_t property, Style *style) { return SimpleProperty::bind(property, style, PT_STRING, &sListener); }
110+
inline status_t bind(const char *property, Style *style) { return SimpleProperty::bind(property, style, PT_STRING, &sListener); }
111+
inline status_t bind(const LSPString *property, Style *style) { return SimpleProperty::bind(property, style, PT_STRING, &sListener); }
112+
113+
};
114+
115+
} /* namespace prop */
116+
} /* namespace tk */
117+
} /* namespace lsp */
118+
119+
120+
121+
122+
#endif /* LSP_PLUG_IN_TK_PROP_SPECIFIC_NOTESTATE_H_ */

include/lsp-plug.in/tk/tk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@
118118
// Specific properties
119119
#include <lsp-plug.in/tk/prop/specific/GraphMeshData.h>
120120
#include <lsp-plug.in/tk/prop/specific/GraphFrameData.h>
121+
#include <lsp-plug.in/tk/prop/specific/NoteState.h>
121122

122123
// Styles and schemas
123124
#include <lsp-plug.in/tk/style/StyleSheet.h>
@@ -197,6 +198,7 @@
197198
#include <lsp-plug.in/tk/widgets/specific/Fraction.h>
198199
#include <lsp-plug.in/tk/widgets/specific/LedMeter.h>
199200
#include <lsp-plug.in/tk/widgets/specific/LedMeterChannel.h>
201+
#include <lsp-plug.in/tk/widgets/specific/PianoKeys.h>
200202

201203
// 3D rendering
202204
#include <lsp-plug.in/tk/widgets/3d/Area3D.h>

0 commit comments

Comments
 (0)