|
| 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_ */ |
0 commit comments