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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
|
/*
* Copyright (C) 2024 Linux Studio Plugins Project <https://lsp-plug.in/>
* (C) 2024 Vladimir Sadovnikov <sadko4u@gmail.com>
*
* This file is part of lsp-tk-lib
* Created on: 28 сент. 2020 г.
*
* lsp-tk-lib is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* lsp-tk-lib is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with lsp-tk-lib. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef LSP_PLUG_IN_TK_WIDGETS_SPECIFIC_AUDIOSAMPLE_H_
#define LSP_PLUG_IN_TK_WIDGETS_SPECIFIC_AUDIOSAMPLE_H_
#ifndef LSP_PLUG_IN_TK_IMPL
#error "use <lsp-plug.in/tk/tk.h>"
#endif
namespace lsp
{
namespace tk
{
// Style definition
namespace style
{
LSP_TK_STYLE_DEF_BEGIN(AudioSample, WidgetContainer)
static const size_t LABELS = 5;
prop::Integer sWaveBorder; // Wave border
prop::Integer sFadeInBorder; // Fade in border
prop::Integer sFadeOutBorder; // Fade out border
prop::Integer sStretchBorder; // Stretch border
prop::Integer sLoopBorder; // Loop border
prop::Integer sPlayBorder; // Play position border
prop::Integer sLineWidth; // Line width
prop::Float sMaxAmplitude; // Maximum amplitude
prop::Color sLineColor; // Line color
prop::SizeConstraints sConstraints; // Size constraints
prop::Boolean sActive; // Active, allow button press
prop::Boolean sSGroups; // Stereo groups enable
prop::String sMainText; // Main text
prop::TextLayout sMainTextLayout; // Layout of main text
prop::Font sMainFont; // Main font
prop::Color sMainColor; // Main font color
prop::Boolean sMainVisibility; // Show main text
prop::String sLabel[LABELS]; // Label
prop::Color sLabelColor[LABELS]; // Label text color
prop::Layout sLabelLayout[LABELS]; // Layout of each label
prop::TextLayout sLabelTextLayout[LABELS]; // Text layout of each label
prop::Font sLabelFont; // Font of label
prop::Color sLabelBgColor; // Background color of label
prop::Integer sLabelRadius; // Label radius
prop::Boolean sLabelVisibility[LABELS]; // Visibility of label
prop::Integer sBorder; // Border size
prop::Integer sBorderRadius; // Border radius
prop::Boolean sBorderFlat; // Border is flat
prop::Boolean sGlass; // Draw glass
prop::Color sColor; // Graph color
prop::Color sBorderColor; // Color of the border
prop::Color sGlassColor; // Color of the glass
prop::Color sStretchColor; // Stretch fill color
prop::Color sLoopColor; // Loop fill color
prop::Color sPlayColor; // Play marker color
prop::Color sStretchBorderColor; // Stretch border color
prop::Color sLoopBorderColor; // Loop border color
prop::Padding sIPadding; // Internal padding
LSP_TK_STYLE_DEF_END
}
class AudioSample: public WidgetContainer
{
public:
static const w_class_t metadata;
static const size_t LABELS = 5;
protected:
enum flags_t
{
XF_LBUTTON = 1 << 0,
XF_RBUTTON = 1 << 1,
XF_DOWN = 1 << 2
};
typedef struct range_t
{
prop::Integer *begin;
prop::Integer *end;
prop::Integer *border;
prop::Color *color;
prop::Color *border_color;
} range_t;
protected:
prop::WidgetList<AudioChannel> vChannels; // List of audio channels
lltl::parray<AudioChannel> vVisible; // List of visible audio channels
prop::CollectionListener sIListener; // Listener to trigger vItems content change
prop::Integer sWaveBorder; // Wave border
prop::Integer sFadeInBorder; // Fade in border
prop::Integer sFadeOutBorder; // Fade out border
prop::Integer sStretchBorder; // Stretch border
prop::Integer sLoopBorder; // Loop border
prop::Integer sPlayBorder; // Play position border
prop::Integer sLineWidth; // Line width
prop::Float sMaxAmplitude; // Maximum amplitude
prop::Color sLineColor; // Line color
prop::SizeConstraints sConstraints; // Size constraints
prop::Boolean sActive; // Active, allow button press
prop::Boolean sSGroups; // Stereo groups enable
prop::String sMainText; // Main text
prop::TextLayout sMainTextLayout; // Layout of main text
prop::Font sMainFont; // Main font
prop::Color sMainColor; // Main font color
prop::Boolean sMainVisibility; // Show main text
prop::String sLabel[LABELS]; // Label
prop::Color sLabelColor[LABELS]; // Label text color
prop::Layout sLabelLayout[LABELS]; // Layout of each label
prop::TextLayout sLabelTextLayout[LABELS]; // Text layout of each label
prop::Font sLabelFont; // Font of label
prop::Color sLabelBgColor; // Background color of label
prop::Integer sLabelRadius; // Label radius
prop::Boolean sLabelVisibility[LABELS]; // Visibility of label
prop::Integer sBorder; // Border size
prop::Integer sBorderRadius; // Border radius
prop::Boolean sBorderFlat; // Border is flat
prop::Boolean sGlass; // Draw glass
prop::Color sColor; // Graph color
prop::Color sBorderColor; // Color of the border
prop::Color sGlassColor; // Color of the glass
prop::Color sStretchColor; // Stretch fill color
prop::Color sLoopColor; // Loop fill color
prop::Color sPlayColor; // Playback position color
prop::Color sStretchBorderColor; // Stretch border color
prop::Color sLoopBorderColor; // Loop border color
prop::Padding sIPadding; // Internal padding
prop::WidgetPtr<Menu> sPopup; // Popup Menu
size_t nBMask; // Mouse button state
size_t nXFlags; // Button flags
ws::rectangle_t sGraph; // Area for sample rendering
ws::ISurface *pGlass; // Surface to draw glass
protected:
static status_t slot_on_before_popup(Widget *sender, void *ptr, void *data);
static status_t slot_on_popup(Widget *sender, void *ptr, void *data);
static status_t slot_on_submit(Widget *sender, void *ptr, void *data);
public:
virtual void size_request(ws::size_limit_t *r) override;
virtual void realize(const ws::rectangle_t *r) override;
virtual void property_changed(Property *prop) override;
virtual void hide_widget() override;
void draw_range(const ws::rectangle_t *r, ws::ISurface *s, AudioChannel *c, range_t *range, size_t samples);
void draw_channel1(const ws::rectangle_t *r, ws::ISurface *s, AudioChannel *c, size_t samples, float max_amplitude);
void draw_fades1(const ws::rectangle_t *r, ws::ISurface *s, AudioChannel *c, size_t samples);
void draw_channel2(const ws::rectangle_t *r, ws::ISurface *s, AudioChannel *c, size_t samples, bool down, float max_amplitude);
void draw_fades2(const ws::rectangle_t *r, ws::ISurface *s, AudioChannel *c1, size_t samples, bool down);
void draw_play_position(const ws::rectangle_t *r, ws::ISurface *s, AudioChannel *c, size_t samples);
void draw_main_text(ws::ISurface *s);
void draw_label(ws::ISurface *s, size_t idx);
static void on_add_item(void *obj, Property *prop, void *w);
static void on_remove_item(void *obj, Property *prop, void *w);
void do_destroy();
void get_visible_items(lltl::parray<AudioChannel> *dst);
status_t handle_mouse_move(const ws::event_t *ev);
void drop_glass();
public:
explicit AudioSample(Display *dpy);
AudioSample(const AudioSample &) = delete;
AudioSample(AudioSample &&) = delete;
virtual ~AudioSample() override;
AudioSample & operator = (const AudioSample &) = delete;
AudioSample & operator = (AudioSample &&) = delete;
virtual status_t init() override;
virtual void destroy() override;
public:
LSP_TK_PROPERTY(WidgetList<AudioChannel>, channels, &vChannels)
LSP_TK_PROPERTY(Integer, wave_border, &sWaveBorder)
LSP_TK_PROPERTY(Integer, fade_in_border, &sFadeInBorder)
LSP_TK_PROPERTY(Integer, fade_out_border, &sFadeOutBorder)
LSP_TK_PROPERTY(Integer, stretch_border, &sStretchBorder)
LSP_TK_PROPERTY(Integer, loop_border, &sLoopBorder)
LSP_TK_PROPERTY(Integer, play_border, &sPlayBorder)
LSP_TK_PROPERTY(Integer, line_width, &sLineWidth)
LSP_TK_PROPERTY(Float, max_amplitude, &sMaxAmplitude)
LSP_TK_PROPERTY(Color, line_color, &sLineColor)
LSP_TK_PROPERTY(SizeConstraints, constraints, &sConstraints)
LSP_TK_PROPERTY(Boolean, active, &sActive)
LSP_TK_PROPERTY(Boolean, stereo_groups, &sSGroups)
LSP_TK_PROPERTY(String, main_text, &sMainText)
LSP_TK_PROPERTY(TextLayout, main_text_layout, &sMainTextLayout)
LSP_TK_PROPERTY(Font, main_font, &sMainFont)
LSP_TK_PROPERTY(Color, main_color, &sMainColor)
LSP_TK_PROPERTY(Boolean, main_visibility, &sMainVisibility)
LSP_TK_IPROPERTY(String, label, &sLabel[index], LABELS)
LSP_TK_IPROPERTY(Color, label_color, &sLabelColor[index], LABELS)
LSP_TK_IPROPERTY(Layout, label_layout, &sLabelLayout[index], LABELS)
LSP_TK_IPROPERTY(TextLayout, label_text_layout, &sLabelTextLayout[index], LABELS)
LSP_TK_PROPERTY(Font, label_font, &sLabelFont)
LSP_TK_PROPERTY(Color, label_bg_color, &sLabelBgColor)
LSP_TK_PROPERTY(Integer, label_radius, &sLabelRadius)
LSP_TK_IPROPERTY(Boolean, label_visibility, &sLabelVisibility[index], LABELS)
LSP_TK_PROPERTY(Integer, border_size, &sBorder);
LSP_TK_PROPERTY(Integer, border_radius, &sBorderRadius);
LSP_TK_PROPERTY(Boolean, border_flat, &sBorderFlat);
LSP_TK_PROPERTY(Boolean, glass, &sGlass);
LSP_TK_PROPERTY(Color, color, &sColor)
LSP_TK_PROPERTY(Color, border_color, &sBorderColor);
LSP_TK_PROPERTY(Color, glass_color, &sGlassColor);
LSP_TK_PROPERTY(Color, stretch_color, &sStretchColor)
LSP_TK_PROPERTY(Color, loop_color, &sLoopColor)
LSP_TK_PROPERTY(Color, play_color, &sPlayColor)
LSP_TK_PROPERTY(Color, stretch_border_color, &sStretchBorderColor);
LSP_TK_PROPERTY(Color, loop_border_color, &sLoopBorderColor);
LSP_TK_PROPERTY(Padding, ipadding, &sIPadding);
LSP_TK_PROPERTY(WidgetPtr<Menu>, popup, &sPopup);
public:
virtual void query_draw(size_t flags = REDRAW_SURFACE) override;
virtual void draw(ws::ISurface *s) override;
virtual void render(ws::ISurface *s, const ws::rectangle_t *area, bool force) override;
virtual status_t add(Widget *widget) override;
virtual status_t remove(Widget *child) override;
virtual status_t remove_all() override;
public:
virtual status_t on_mouse_down(const ws::event_t *e) override;
virtual status_t on_mouse_up(const ws::event_t *e) override;
virtual status_t on_mouse_move(const ws::event_t *e) override;
virtual status_t on_before_popup(Menu *menu);
virtual status_t on_popup(Menu *menu);
virtual status_t on_submit();
};
} /* namespace tk */
} /* namespace lsp */
#endif /* LSP_PLUG_IN_TK_WIDGETS_SPECIFIC_AUDIOSAMPLE_H_ */
|