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