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