1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 28 окт. 2017 г.
7  *
8  * lsp-plugins 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-plugins 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-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef UI_CTL_CTLAUDIOFILE_H_
23 #define UI_CTL_CTLAUDIOFILE_H_
24 
25 #include <core/io/IInStream.h>
26 #include <ui/ctl/CtlPortHandler.h>
27 
28 namespace lsp
29 {
30     namespace ctl
31     {
32         class CtlAudioFile: public CtlWidget
33         {
34             public:
35                 static const ctl_class_t metadata;
36 
37             protected:
38                 enum const_t
39                 {
40                     N_MENU_ITEMS = 4
41                 };
42 
43             protected:
44                 class DataSink: public LSPTextDataSink
45                 {
46                     private:
47                         CtlAudioFile *pFile;
48 
49                     public:
50                         explicit DataSink(CtlAudioFile *file);
51                         virtual ~DataSink();
52 
53                     public:
54                         virtual status_t    on_complete(status_t code, const LSPString *data);
55 
56                         void unbind();
57                 };
58 
59             protected:
60                 CtlColor        sColor;
61                 CtlPadding      sPadding;
62                 CtlExpression   sFormat;
63                 LSPMenu         sMenu;
64                 LSPMenuItem    *vMenuItems[N_MENU_ITEMS];
65                 char           *pPathID;
66                 LSPString       sBind;
67 
68                 CtlPort        *pFile;
69                 CtlPort        *pMesh;
70                 CtlPort        *pStatus;
71                 CtlPort        *pLength;
72                 CtlPort        *pHeadCut;
73                 CtlPort        *pTailCut;
74                 CtlPort        *pFadeIn;
75                 CtlPort        *pFadeOut;
76                 CtlPort        *pPath;
77                 DataSink       *pDataSink;
78 
79             protected:
80                 void            sync_status();
81                 void            sync_file();
82                 void            sync_mesh();
83                 void            sync_fades();
84 
85                 void            commit_file();
86                 void            update_path();
87                 status_t        bind_ports(CtlPortHandler *h);
88 
89                 static status_t     slot_on_activate(LSPWidget *sender, void *ptr, void *data);
90                 static status_t     slot_on_submit(LSPWidget *sender, void *ptr, void *data);
91                 static status_t     slot_on_close(LSPWidget *sender, void *ptr, void *data);
92 
93                 static status_t     slot_popup_cut_action(LSPWidget *sender, void *ptr, void *data);
94                 static status_t     slot_popup_copy_action(LSPWidget *sender, void *ptr, void *data);
95                 static status_t     slot_popup_paste_action(LSPWidget *sender, void *ptr, void *data);
96                 static status_t     slot_popup_clear_action(LSPWidget *sender, void *ptr, void *data);
97 
98                 static status_t     clipboard_handler(void *arg, status_t s, io::IInStream *is);
99 
100             public:
101                 explicit CtlAudioFile(CtlRegistry *src, LSPAudioFile *af);
102                 virtual ~CtlAudioFile();
103 
104             public:
105                 virtual void init();
106 
107                 virtual void set(widget_attribute_t att, const char *value);
108 
109                 virtual void end();
110 
111                 virtual void notify(CtlPort *port);
112 
113         };
114 
115     } /* namespace ctl */
116 } /* namespace lsp */
117 
118 #endif /* UI_CTL_CTLAUDIOFILE_H_ */
119