b936647fd7b572ee874c9ac32ad4688eec53cf33
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / awindowgui.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef AWINDOWGUI_H
23 #define AWINDOWGUI_H
24
25 #include "arraylist.h"
26 #include "bcdialog.h"
27 #include "binfolder.inc"
28 #include "assetpopup.inc"
29 #include "asset.inc"
30 #include "assets.inc"
31 #include "audiodevice.inc"
32 #include "awindow.inc"
33 #include "awindowgui.inc"
34 #include "clippopup.inc"
35 #include "edl.inc"
36 #include "effectlist.inc"
37 #include "folderlistmenu.inc"
38 #include "garbage.h"
39 #include "guicast.h"
40 #include "labeledit.inc"
41 #include "labelpopup.inc"
42 #include "labels.h"
43 #include "indexable.inc"
44 #include "mwindow.inc"
45 #include "mutex.inc"
46 #include "pluginserver.inc"
47 #include "proxypopup.inc"
48 #include "renderengine.inc"
49 #include "samples.inc"
50 #include "vicon.h"
51
52 #define SELECT_ALL 0
53 #define SELECT_USED 1
54 #define SELECT_UNUSED 2
55 #define SELECT_NONE 3
56 #define VIEW_POPUP_BAR_H 15
57
58 class AWindowFolderItem : public BC_ListBoxItem
59 {
60 public:
61         AWindowFolderItem();
62         AWindowFolderItem(const char *text, int color = -1);
63         AWindowFolderItem(const char *text, BC_Pixmap *icon, int color = -1);
64
65         AssetPicon *get_picon();
66         int matches(const char *text);
67
68         AWindowFolderItem *parent;
69 };
70
71 class AssetPicon : public AWindowFolderItem
72 {
73 public:
74         AssetPicon(MWindow *mwindow, AWindowGUI *gui, Indexable *indexable);
75         AssetPicon(MWindow *mwindow, AWindowGUI *gui, EDL *edl);
76         AssetPicon(MWindow *mwindow, AWindowGUI *gui, PluginServer *plugin);
77         AssetPicon(MWindow *mwindow, AWindowGUI *gui, Label *plugin);
78         AssetPicon(MWindow *mwindow, AWindowGUI *gui, int folder, int persist);
79         AssetPicon(MWindow *mwindow, AWindowGUI *gui, int folder, const char *title);
80         virtual ~AssetPicon();
81
82         void create_objects();
83         void reset();
84         static void draw_hue_bar(VFrame *frame, double t);
85         static void draw_wave(VFrame *frame, double *dp, int len,
86                 int base_color, int line_color, int x, int y, int w, int h);
87         static void draw_wave(VFrame *frame, double *dp, int len,
88                 int base_color, int line_color, int x=0, int y=0) {
89           draw_wave(frame, dp, len, base_color, line_color,
90                 x,y,frame->get_w(),frame->get_h());
91         }
92         void open_render_engine(EDL *edl, int is_audio);
93         void close_render_engine();
94         void render_video(int64_t pos, VFrame *vfrm);
95         void render_audio(int64_t pos, Samples **samples, int len);
96         VFrame *get_vicon_frame();
97
98         MWindow *mwindow;
99         AWindowGUI *gui;
100         BC_Pixmap *icon;
101         VFrame *icon_vframe;
102         VFrame *vicon_frame;
103         int foldernum;
104 // sublist items if set
105         AWindowFolderSubItems *sub_items;
106
107 // ID of thing pointed to
108         int id;
109
110 // Check ID first.  Update these next before dereferencing
111 // Asset if asset
112         Indexable *indexable;
113 // EDL if clip
114         EDL *edl;
115
116         int in_use;
117         int persistent;
118         time_t comments_time;
119         double sort_key;
120         PluginServer *plugin;
121         Label *label;
122         AssetVIcon *vicon;
123         RenderEngine *render_engine;
124 };
125
126 typedef int16_t vicon_audio_t;
127
128 class AssetVIconAudio : public Thread
129 {
130 public:
131         AssetVIconAudio(AWindowGUI *gui);
132         ~AssetVIconAudio();
133
134         void run();
135         void start(AssetVIcon *vicon);
136         void stop(int wait);
137
138         AWindowGUI *gui;
139         AudioDevice *audio;
140         AssetVIcon *vicon;
141         int interrupted;
142         int audio_pos;
143 };
144
145 class AssetVIcon : public VIcon, public Garbage {
146 public:
147         AssetPicon *picon;
148         VFrame *temp;
149         int64_t length;
150
151         VFrame *frame();
152         int64_t set_seq_no(int64_t no);
153         int get_vx();
154         int get_vy();
155         void load_audio();
156         void start_audio();
157         void stop_audio();
158         int popup_button_press(int x, int y);
159         int popup_cursor_motion(int x, int y);
160
161         AssetVIcon(AssetPicon *picon, int w, int h, double framerate, int64_t length);
162         ~AssetVIcon();
163 };
164
165 class AWindowRemovePlugin;
166
167 class AWindowRemovePluginGUI : public BC_Window {
168 public:
169         AWindow *awindow;
170         AWindowRemovePlugin *thread;
171         PluginServer *plugin;
172         ArrayList<BC_ListBoxItem*> plugin_list;
173         BC_Pixmap *icon;
174         VFrame *icon_vframe;
175         BC_ListBox *list;
176
177         void create_objects();
178
179         AWindowRemovePluginGUI(AWindow *awindow, AWindowRemovePlugin *thread,
180                  int x, int y, PluginServer *plugin);
181         ~AWindowRemovePluginGUI();
182 };
183
184 class AWindowRemovePlugin : public BC_DialogThread {
185 public:
186         AWindow *awindow;
187         PluginServer *plugin;
188         BC_Window* new_gui();
189         void handle_close_event(int result);
190         int remove_plugin(PluginServer *plugin, ArrayList<BC_ListBoxItem*> &folder);
191
192         AWindowRemovePlugin(AWindow *awindow, PluginServer *plugin);
193         ~AWindowRemovePlugin();
194 };
195
196 class AWindowGUI : public BC_Window
197 {
198 public:
199         AWindowGUI(MWindow *mwindow, AWindow *awindow);
200         ~AWindowGUI();
201
202         void create_objects();
203         int resize_event(int w, int h);
204         int translation_event();
205         int close_event();
206         int keypress_event();
207         void async_update_assets();     // Sends update asset event
208         void update_effects();
209         void sort_assets();
210         void sort_folders();
211         void reposition_objects();
212 // Call back for MWindow entry point
213         int drag_motion();
214         int drag_stop();
215 // Collect items into the drag vectors of MainSession
216         void collect_assets(int proxy=0);
217         EDL *collect_proxy(Indexable *indexable);
218         void create_persistent_folder(ArrayList<BC_ListBoxItem*> *output,
219                 int do_audio,
220                 int do_video,
221                 int is_realtime,
222                 int is_transition);
223         void create_label_folder();
224         void copy_picons(AssetPicon *picon, ArrayList<BC_ListBoxItem*> *src);
225         void sort_picons(ArrayList<BC_ListBoxItem*> *src);
226 // Return the selected asset in asset_list
227         Indexable* selected_asset();
228         PluginServer* selected_plugin();
229         AssetPicon* selected_folder();
230         bool protected_pixmap(BC_Pixmap *pixmap);
231         int save_defaults(BC_Hash *defaults);
232         int load_defaults(BC_Hash *defaults);
233         void start_vicon_drawing();
234         void stop_vicon_drawing();
235         void update_picon(Indexable *indexable);
236         int cycle_assetlist_format();
237
238         VFrame *get_picon(const char *name, const char *plugin_icons);
239         VFrame *get_picon(const char *name);
240         void resource_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, int idx);
241         void theme_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn);
242         void plugin_icon(VFrame *&vfrm, BC_Pixmap *&icon, const char *fn, unsigned char *png);
243
244         MWindow *mwindow;
245         AWindow *awindow;
246
247         AWindowAssets *asset_list;
248         AWindowFolders *folder_list;
249         AWindowDivider *divider;
250         AWindowSearchText *search_text;
251         Mutex *folder_lock;
252
253 // Store data to speed up responses
254 // Persistant data for listboxes
255 // All assets in current EDL
256         ArrayList<BC_ListBoxItem*> assets;
257         ArrayList<BC_ListBoxItem*> folders;
258         ArrayList<BC_ListBoxItem*> aeffects;
259         ArrayList<BC_ListBoxItem*> veffects;
260         ArrayList<BC_ListBoxItem*> atransitions;
261         ArrayList<BC_ListBoxItem*> vtransitions;
262         ArrayList<BC_ListBoxItem*> labellist;
263
264 // Currently displayed data for listboxes
265 // Currently displayed assets + comments
266         ArrayList<BC_ListBoxItem*> displayed_assets[2];
267         const char *asset_titles[ASSET_COLUMNS];
268         int displayed_folder;
269
270         BC_Hash *defaults;
271 // Persistent icons
272         BC_Pixmap *aeffect_folder_icon;      VFrame *aeffect_folder_vframe;
273         BC_Pixmap *atransition_folder_icon;  VFrame *atransition_folder_vframe;
274         BC_Pixmap *clip_folder_icon;         VFrame *clip_folder_vframe;
275         BC_Pixmap *label_folder_icon;        VFrame *label_folder_vframe;
276         BC_Pixmap *media_folder_icon;        VFrame *media_folder_vframe;
277         BC_Pixmap *proxy_folder_icon;        VFrame *proxy_folder_vframe;
278         BC_Pixmap *veffect_folder_icon;      VFrame *veffect_folder_vframe;
279         BC_Pixmap *vtransition_folder_icon;  VFrame *vtransition_folder_vframe;
280         BC_Pixmap *folder_icons[AWINDOW_FOLDERS];
281
282         BC_Pixmap *folder_icon;       VFrame *folder_vframe;
283         BC_Pixmap *file_icon;         VFrame *file_vframe;
284         BC_Pixmap *audio_icon;        VFrame *audio_vframe;
285         BC_Pixmap *video_icon;        VFrame *video_vframe;
286         BC_Pixmap *label_icon;        VFrame *label_vframe;
287         BC_Pixmap *clip_icon;         VFrame *clip_vframe;
288         BC_Pixmap *atransition_icon;  VFrame *atransition_vframe;
289         BC_Pixmap *vtransition_icon;  VFrame *vtransition_vframe;
290         BC_Pixmap *aeffect_icon;      VFrame *aeffect_vframe;
291         BC_Pixmap *veffect_icon;      VFrame *veffect_vframe;
292         BC_Pixmap *ladspa_icon;       VFrame *ladspa_vframe;
293         BC_Pixmap *ff_aud_icon;       VFrame *ff_aud_vframe;
294         BC_Pixmap *ff_vid_icon;       VFrame *ff_vid_vframe;
295
296 // Popup menus
297         AssetPopup *asset_menu;
298         ClipPopup *clip_menu;
299         LabelPopup *label_menu;
300         ProxyPopup *proxy_menu;
301         EffectListMenu *effectlist_menu;
302         AssetListMenu *assetlist_menu;
303         ClipListMenu *cliplist_menu;
304         LabelListMenu *labellist_menu;
305         ProxyListMenu *proxylist_menu;
306         FolderListMenu *folderlist_menu;
307         AddTools *add_tools;
308 // Temporary for reading picons from files
309         VFrame *temp_picon;
310         VIconThread *vicon_thread;
311         AssetVIconAudio *vicon_audio;
312
313         int64_t plugin_visibility;
314         AWindowRemovePlugin *remove_plugin;
315
316         AVIconDrawing *avicon_drawing;
317         int avicon_w, avicon_h, vicon_drawing;
318         int allow_iconlisting;
319
320 // Create custom atoms to be used for async messages between windows
321         int create_custom_xatoms();
322 // Function to overload to receive customly defined atoms
323         virtual int receive_custom_xatoms(xatom_event *event);
324         static const char *folder_names[];
325         NewFolderThread *new_folder_thread;
326         ModifyFolderThread *modify_folder_thread;
327
328 private:
329         void update_folder_list();
330         void update_asset_list();
331         void filter_displayed_assets();
332         Atom UpdateAssetsXAtom;
333         void update_assets();
334
335 };
336
337 class AWindowAssets : public BC_ListBox
338 {
339 public:
340         AWindowAssets(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h);
341         ~AWindowAssets();
342
343         int handle_event();
344         int selection_changed();
345         void draw_background();
346         int drag_start_event();
347         int drag_motion_event();
348         int drag_stop_event();
349         int button_press_event();
350         int column_resize_event();
351         int focus_in_event();
352         int focus_out_event();
353         int cursor_enter_event();
354         int cursor_leave_event();
355         void update_vicon_area();
356         int mouse_over_event(int no);
357         static VIconDrawVFrame draw_vframe;
358         VIconDrawVFrame *draw_func;
359
360         MWindow *mwindow;
361         AWindowGUI *gui;
362 };
363
364 class AWindowDivider : public BC_SubWindow
365 {
366 public:
367         AWindowDivider(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h);
368         ~AWindowDivider();
369
370         int button_press_event();
371         int cursor_motion_event();
372         int button_release_event();
373
374         MWindow *mwindow;
375         AWindowGUI *gui;
376 };
377
378 class AWindowSubFolderNames : public ArrayList<const char *>
379 {
380 public:
381         AWindowSubFolderNames() { set_array_delete(); }
382         ~AWindowSubFolderNames() { remove_all_objects(); }
383 };
384
385 class AWindowFolderSubItems : public AWindowFolderItem
386 {
387 public:
388         AWindowFolderSubItems(AWindowFolderItem *parent, const char *text);
389         int matches(const char *text);
390
391         AWindowSubFolderNames names;
392 };
393
394 class AWindowFolders : public BC_ListBox
395 {
396 public:
397         AWindowFolders(MWindow *mwindow, AWindowGUI *gui, int x, int y, int w, int h);
398         ~AWindowFolders();
399
400         int selection_changed();
401         int button_press_event();
402         int drag_stop();
403         int load_expanders();
404
405         MWindow *mwindow;
406         AWindowGUI *gui;
407 // last selection
408         AWindowFolderItem *last_item0, *last_item1;
409 };
410
411 class AWindowSearchTextBox : public BC_TextBox
412 {
413 public:
414         AWindowSearchTextBox(AWindowSearchText *search_text, int x, int y, int w);
415         int handle_event();
416
417         AWindowSearchText *search_text;
418 };
419
420 class AWindowSearchText
421 {
422 public:
423         AWindowSearchText(MWindow *mwindow, AWindowGUI *gui, int x, int y);
424
425         int handle_event();
426         void create_objects();
427         int get_w();
428         int get_h();
429         void reposition_window(int x, int y, int w);
430         const char *get_text();
431         void clear();
432
433         MWindow *mwindow;
434         AWindowGUI *gui;
435         int x, y;
436         BC_Title *text_title;
437         BC_TextBox *text_box;
438 };
439
440 class AWindowDeleteDisk : public BC_Button
441 {
442 public:
443         AWindowDeleteDisk(MWindow *mwindow, AWindowGUI *gui, int x, int y);
444         int handle_event();
445         MWindow *mwindow;
446         AWindowGUI *gui;
447         int x, y;
448 };
449
450 class AWindowDeleteProject : public BC_Button
451 {
452 public:
453         AWindowDeleteProject(MWindow *mwindow, AWindowGUI *gui, int x, int y);
454         int handle_event();
455         MWindow *mwindow;
456         AWindowGUI *gui;
457         int x, y;
458 };
459
460 class AWindowInfo : public BC_Button
461 {
462 public:
463         AWindowInfo(MWindow *mwindow, AWindowGUI *gui, int x, int y);
464         int handle_event();
465         MWindow *mwindow;
466         AWindowGUI *gui;
467         int x, y;
468 };
469
470 class AWindowRedrawIndex : public BC_Button
471 {
472 public:
473         AWindowRedrawIndex(MWindow *mwindow, AWindowGUI *gui, int x, int y);
474         int handle_event();
475         MWindow *mwindow;
476         AWindowGUI *gui;
477         int x, y;
478 };
479
480 class AWindowPaste : public BC_Button
481 {
482 public:
483         AWindowPaste(MWindow *mwindow, AWindowGUI *gui, int x, int y);
484         int handle_event();
485         MWindow *mwindow;
486         AWindowGUI *gui;
487         int x, y;
488 };
489
490 class AWindowAppend : public BC_Button
491 {
492 public:
493         AWindowAppend(MWindow *mwindow, AWindowGUI *gui, int x, int y);
494         int handle_event();
495         MWindow *mwindow;
496         AWindowGUI *gui;
497         int x, y;
498 };
499
500 class AWindowView : public BC_Button
501 {
502 public:
503         AWindowView(MWindow *mwindow, AWindowGUI *gui, int x, int y);
504         int handle_event();
505         MWindow *mwindow;
506         AWindowGUI *gui;
507         int x, y;
508 };
509
510 class AddTools : public BC_PopupMenu
511 {
512 public:
513         AddTools(MWindow *mwindow, AWindowGUI *gui, int x, int y, const char *title);
514         void create_objects();
515
516         MWindow *mwindow;
517         AWindowGUI *gui;
518 };
519
520 class AddPluginItem : public BC_MenuItem
521 {
522 public:
523         AddPluginItem(AddTools *menu, const char *text, int idx);
524         int handle_event();
525
526         AddTools *menu;
527         int idx;
528 };
529
530 class AVIconDrawing : public BC_Toggle
531 {
532 public:
533         AWindowGUI *agui;
534
535         int handle_event();
536         static void calculate_geometry(AWindowGUI *agui, VFrame **images, int *ww, int *hh);
537
538         AVIconDrawing(AWindowGUI *agui, int x, int y, VFrame **images);
539         ~AVIconDrawing();
540 };
541
542
543 class AWindowListFormat : public BC_MenuItem
544 {
545 public:
546         AWindowListFormat(MWindow *mwindow, AWindowGUI *gui);
547
548         void update();
549         int handle_event();
550         MWindow *mwindow;
551         AWindowGUI *gui;
552 };
553
554
555 class AWindowListSort : public BC_MenuItem
556 {
557 public:
558         AWindowListSort(MWindow *mwindow, AWindowGUI *gui);
559
560         void update();
561         int handle_event();
562         MWindow *mwindow;
563         AWindowGUI *gui;
564 };
565
566 class AssetSelectUsedItem : public BC_MenuItem
567 {
568 public:
569         AssetSelectUsedItem(AssetSelectUsed *select_used, const char *text, int action);
570         int handle_event();
571
572         int action;
573         AssetSelectUsed *select_used;
574 };
575
576 class AssetSelectUsed : public BC_MenuItem
577 {
578 public:
579         AssetSelectUsed(MWindow *mwindow, AWindowGUI *gui);
580
581         MWindow *mwindow;
582         AWindowGUI *gui;
583 };
584
585 #endif