anonymous contribution for much improved ChromakeyHSV plugin menu with boxes to set...
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / dbwindow.h
1 /*
2  * CINELERRA
3  * Copyright (C) 2016-2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21 #if defined(__i386__) || defined(__x86_64__)
22 #if defined (__linux__)
23 #ifndef _DBWINDOW_H_
24 #define _DBWINDOW_H_
25
26 #include "canvas.h"
27 #include "condition.h"
28 #include "garbage.h"
29 #include "linklist.h"
30 #include "mutex.h"
31 #include "commercials.inc"
32 #include "dbwindow.inc"
33 #include "guicast.h"
34 #include "mediadb.h"
35 #include "mwindow.inc"
36 #include "vicon.h"
37
38 enum {
39         col_vicon, col_id, col_length, col_source,
40         col_title, col_start_time, col_access_time,
41         col_access_count, sizeof_col
42 };
43
44 class DbSearchItem : public BC_ListBoxItem {
45 public:
46         DbWindowVIcon *vicon;
47
48         DbSearchItem(const char *text, int color=-1);
49         ~DbSearchItem();
50 };
51
52 class DbWindow : public Thread
53 {
54 public:
55         MWindow *mwindow;
56         DbWindowGUI *gui;
57         Mutex *window_lock;
58         Mutex *db_lock;
59         class MDb : public Garbage, public MediaDb {
60                 DbWindow *dwin;
61         public:
62                 int attach_rd() { dwin->db_lock->lock();  attachDb(0);  return 0; }
63                 int attach_wr() { dwin->db_lock->lock();  attachDb(1);  return 0; }
64                 int detach() {  dwin->db_lock->unlock();  detachDb();   return 0; }
65
66                 MDb(DbWindow *d);
67                 ~MDb();
68         } *mdb;
69
70         void start();
71         void stop();
72         void run();
73
74         DbWindow(MWindow *mwindow);
75         ~DbWindow();
76 };
77
78 class DbWindowGUI : public BC_Window
79 {
80 public:
81         DbWindow *dwindow;
82
83         DbWindowText *search_text;
84         DbWindowTitleText *title_text;
85         DbWindowInfoText *info_text;
86         DbWindowMatchCase *match_case;
87         DbWindowStart *search_start;
88         DbWindowDeleteItems *del_items;
89         DbWindowCancel *cancel;
90         DbWindowList *search_list;
91         DbWindowCanvas *canvas;
92         DbWindowVIconThread *vicon_thread;
93
94         int title_text_enable;
95         int info_text_enable;
96         int match_case_enable;
97
98         int search_x, search_y, text_x, text_y;
99         int del_items_x, del_items_y;
100         int cancel_x, cancel_y, cancel_w, cancel_h;
101         int canvas_x, canvas_y, canvas_w, canvas_h;
102         int list_x, list_y, list_w, list_h;
103         int sort_column, sort_order;
104
105         const char *search_column_titles[sizeof_col];
106         int search_column_widths[sizeof_col];
107         int search_columns[sizeof_col];
108         ArrayList<DbSearchItem*> search_items[sizeof_col];
109         ArrayList<DbWindowItem*> search_results;
110
111         void create_objects();
112         void search(int n, const char *text);
113         void delete_items();
114         int close_event();
115         int resize_event(int x, int y);
116         int stop_drawing();
117         int start_drawing(int update=1);
118         void update();
119         static int cmpr_id_dn(const void *a, const void *b);
120         static int cmpr_id_up(const void *a, const void *b);
121         static int cmpr_length_dn(const void *a, const void *b);
122         static int cmpr_length_up(const void *a, const void *b);
123         static int cmpr_source_dn(const void *a, const void *b);
124         static int cmpr_source_up(const void *a, const void *b);
125         static int cmpr_Source_dn(const void *a, const void *b);
126         static int cmpr_Source_up(const void *a, const void *b);
127         static int cmpr_Title_dn(const void *a, const void *b);
128         static int cmpr_Title_up(const void *a, const void *b);
129         static int cmpr_title_dn(const void *a, const void *b);
130         static int cmpr_title_up(const void *a, const void *b);
131         static int cmpr_start_time_dn(const void *a, const void *b);
132         static int cmpr_start_time_up(const void *a, const void *b);
133         static int cmpr_access_time_dn(const void *a, const void *b);
134         static int cmpr_access_time_up(const void *a, const void *b);
135         static int cmpr_access_count_dn(const void *a, const void *b);
136         static int cmpr_access_count_up(const void *a, const void *b);
137         void sort_events(int column, int order);
138         void move_column(int src, int dst);
139
140         DbWindowGUI(DbWindow *dwindow);
141         ~DbWindowGUI();
142 private:
143         int search_string(const char *text, const char *sp);
144         void search_clips(MediaDb *mdb, int n, const char *text);
145         int delete_selection(MediaDb *mdb);
146 };
147
148 class DbWindowInfoText : public BC_CheckBox
149 {
150 public:
151         DbWindowGUI *gui;
152
153         int handle_event();
154         void update(int v) { set_value(gui->info_text_enable = v); }
155
156         DbWindowInfoText(DbWindowGUI *gui, int x, int y);
157         ~DbWindowInfoText();
158 };
159
160 class DbWindowTitleText : public BC_CheckBox
161 {
162 public:
163         DbWindowGUI *gui;
164
165         int handle_event();
166         void update(int v) { set_value(gui->title_text_enable = v); }
167
168         DbWindowTitleText(DbWindowGUI *gui, int x, int y);
169         ~DbWindowTitleText();
170 };
171
172 class DbWindowMatchCase : public BC_CheckBox
173 {
174 public:
175         DbWindowGUI *gui;
176
177         int handle_event();
178
179         DbWindowMatchCase(DbWindowGUI *gui, int x, int y);
180         ~DbWindowMatchCase();
181 };
182
183 class DbWindowText : public BC_TextBox
184 {
185 public:
186         DbWindowGUI *gui;
187
188         int handle_event();
189         int keypress_event();
190
191         DbWindowText(DbWindowGUI *gui, int x, int y, int w);
192         ~DbWindowText();
193 };
194
195 class DbWindowStart : public BC_GenericButton
196 {
197 public:
198         DbWindowGUI *gui;
199
200         int handle_event();
201
202         DbWindowStart(DbWindowGUI *gui, int x, int y);
203         ~DbWindowStart();
204 };
205
206 class DbWindowCancel : public BC_CancelButton
207 {
208 public:
209         DbWindowGUI *gui;
210
211         int handle_event();
212
213         DbWindowCancel(DbWindowGUI *gui, int x, int y);
214         ~DbWindowCancel();
215 };
216
217 class DbWindowDeleteItems : public BC_GenericButton
218 {
219 public:
220         DbWindowGUI *gui;
221
222         int handle_event();
223
224         DbWindowDeleteItems(DbWindowGUI *gui, int x, int y);
225         ~DbWindowDeleteItems();
226 };
227
228 class DbWindowList : public BC_ListBox
229 {
230 public:
231         DbWindowGUI *gui;
232
233         int handle_event();
234         int sort_order_event();
235         int keypress_event();
236         int move_column_event();
237         int selection_changed();
238         void set_view_popup(DbWindowVIcon *vicon);
239
240         int update_images();
241         int update();
242
243         DbWindowList(DbWindowGUI *gui, int x, int y, int w, int h);
244         ~DbWindowList();
245 };
246
247 class DbWindowCanvas : public Canvas
248 {
249 public:
250         DbWindowGUI *gui;
251
252         DbWindowCanvas(DbWindowGUI *gui, int x, int y, int w, int h);
253         ~DbWindowCanvas();
254         void flash_canvas();
255         void draw_frame(VFrame *frame, int x, int y, int w, int h);
256         int button_press_event() { return 0; }
257         int keypress_event() { return 0; }
258 };
259
260 class DbWindowVIcon : public VIcon
261 {
262 public:
263         DbWindowList *lbox;
264         DbSearchItem *item;
265
266         int clip_id, clip_size;
267         int frame_id, frames;
268         int prefix_size, suffix_offset;
269
270         VFrame *frame();
271         int64_t set_seq_no(int64_t no);
272         void load_frames(DbWindow::MDb *mdb);
273         void read_frames(DbWindow::MDb *mdb);
274
275         int get_vx();
276         int get_vy();
277
278         void update_image(DbWindowGUI *gui, int clip_id);
279         DbWindowVIcon();
280         ~DbWindowVIcon();
281 };
282
283 class DbWindowVIconThread : public VIconThread {
284 public:
285         DbWindowGUI *gui;
286         int list_update;
287
288         ArrayList <DbWindowVIcon *> vicons;
289         DbWindowVIcon *get_vicon(int i, DbSearchItem *item);
290         void drawing_started();
291
292         DbWindowVIconThread(DbWindowGUI *gui);
293         ~DbWindowVIconThread();
294 };
295
296 class DbWindowItem
297 {
298 public:
299         int no, id, access_count;
300         char *source, *title;
301         double length, start_time, access_time;
302
303         DbWindowItem(int id, const char *source, const char *title,
304                 double length, double start_time, double access_time,
305                 int access_count);
306         ~DbWindowItem();
307 };
308
309 class DbWindowScan : public BC_MenuItem
310 {
311 public:
312         MWindow *mwindow;
313         int handle_event();
314
315         DbWindowScan(MWindow *mwindow);
316         ~DbWindowScan();
317 };
318
319
320 #endif
321 #endif // linux
322 #endif /* x86 */