audio wave icons, viewer wave image, 7 lib updates, tweak file size
[goodguy/history.git] / cinelerra-5.1 / cinelerra / vwindowgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 1997-2011 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 #include "arender.h"
23 #include "asset.h"
24 #include "assets.h"
25 #include "awindowgui.h"
26 #include "awindow.h"
27 #include "cache.h"
28 #include "canvas.h"
29 #include "clip.h"
30 #include "clipedit.h"
31 #include "edl.h"
32 #include "edlsession.h"
33 #include "filesystem.h"
34 #include "filexml.h"
35 #include "fonts.h"
36 #include "keys.h"
37 #include "labels.h"
38 #include "language.h"
39 #include "localsession.h"
40 #include "mainclock.h"
41 #include "mainmenu.h"
42 #include "mainsession.h"
43 #include "mainundo.h"
44 #include "meterpanel.h"
45 #include "mwindowgui.h"
46 #include "mwindow.h"
47 #include "playtransport.h"
48 #include "preferences.h"
49 #include "renderengine.h"
50 #include "samples.h"
51 #include "theme.h"
52 #include "timebar.h"
53 #include "tracks.h"
54 #include "transportque.h"
55 #include "vframe.h"
56 #include "vplayback.h"
57 #include "vtimebar.h"
58 #include "vwindowgui.h"
59 #include "vwindow.h"
60
61
62
63
64 VWindowGUI::VWindowGUI(MWindow *mwindow, VWindow *vwindow)
65  : BC_Window(_(PROGRAM_NAME ": Viewer"),
66         mwindow->session->vwindow_x,
67         mwindow->session->vwindow_y,
68         mwindow->session->vwindow_w,
69         mwindow->session->vwindow_h,
70         100,
71         100,
72         1,
73         1,
74         0) // Hide it
75 {
76         this->mwindow = mwindow;
77         this->vwindow = vwindow;
78         canvas = 0;
79         transport = 0;
80         edit_panel = 0;
81         meters = 0;
82 //      source = 0;
83         strcpy(loaded_title, "");
84         highlighted = 0;
85 }
86
87 VWindowGUI::~VWindowGUI()
88 {
89         vwindow->playback_engine->interrupt_playback(1);
90         sources.remove_all_objects();
91         labels.remove_all_objects();
92         delete canvas;
93         delete transport;
94         delete edit_panel;
95         delete meters;
96 //      delete source;
97 }
98
99 void VWindowGUI::draw_wave()
100 {
101         TransportCommand command;
102         command.command = NORMAL_FWD;
103         command.get_edl()->copy_all(vwindow->get_edl());
104         command.change_type = CHANGE_ALL;
105         command.realtime = 0;
106         RenderEngine *render_engine = new RenderEngine(0, mwindow->preferences, 0, 0);
107         CICache *cache = new CICache(mwindow->preferences);
108         render_engine->set_acache(cache);
109         render_engine->arm_command(&command);
110
111         double duration = 1.;
112         int w = mwindow->edl->session->output_w;
113         int h = mwindow->edl->session->output_h;
114         VFrame *vframe = new VFrame(w, h, BC_RGB888);
115         int sample_rate = mwindow->edl->get_sample_rate();
116         int channels = mwindow->edl->session->audio_channels;
117         if( channels > 2 ) channels = 2;
118         int64_t bfrsz = sample_rate * duration;
119         Samples *samples[MAXCHANNELS];
120         int ch = 0;
121         while( ch < channels ) samples[ch++] = new Samples(bfrsz);
122         while( ch < MAXCHANNELS ) samples[ch++] = 0;
123         render_engine->arender->process_buffer(samples, bfrsz, 0);
124
125         static int line_colors[2] = { GREEN, YELLOW };
126         static int base_colors[2] = { RED, PINK };
127         for( int i=channels; --i>=0; ) {
128                 AssetPicon::draw_wave(vframe, samples[i]->get_data(), bfrsz,
129                         base_colors[i], line_colors[i]);
130         }
131
132         for( int i=channels; --i>=0; ) delete samples[i];
133         delete render_engine;
134         delete cache;
135         delete canvas->refresh_frame;
136         canvas->refresh_frame = vframe;
137         canvas->draw_refresh(1);
138 }
139
140 void VWindowGUI::change_source(EDL *edl, const char *title)
141 {
142 //printf("VWindowGUI::change_source %d\n", __LINE__);
143
144         update_sources(title);
145         strcpy(loaded_title, title);
146         char string[BCTEXTLEN];
147         if(title[0])
148                 sprintf(string, _(PROGRAM_NAME ": %s"), title);
149         else
150                 sprintf(string, _(PROGRAM_NAME ": Viewer"));
151
152         lock_window("VWindowGUI::change_source");
153         canvas->clear();
154         if( edl &&
155             !edl->tracks->playable_video_tracks() &&
156             edl->tracks->playable_audio_tracks() )
157                 draw_wave();
158         timebar->update(0);
159         set_title(string);
160         unlock_window();
161 }
162
163
164 // Get source list from master EDL
165 void VWindowGUI::update_sources(const char *title)
166 {
167         lock_window("VWindowGUI::update_sources");
168
169 //printf("VWindowGUI::update_sources 1\n");
170         sources.remove_all_objects();
171 //printf("VWindowGUI::update_sources 2\n");
172
173
174
175         for(int i = 0;
176                 i < mwindow->edl->clips.total;
177                 i++)
178         {
179                 char *clip_title = mwindow->edl->clips.values[i]->local_session->clip_title;
180                 int exists = 0;
181
182                 for(int j = 0; j < sources.total; j++)
183                 {
184                         if(!strcasecmp(sources.values[j]->get_text(), clip_title))
185                         {
186                                 exists = 1;
187                         }
188                 }
189
190                 if(!exists)
191                 {
192                         sources.append(new BC_ListBoxItem(clip_title));
193                 }
194         }
195 //printf("VWindowGUI::update_sources 3\n");
196
197         FileSystem fs;
198         for(Asset *current = mwindow->edl->assets->first;
199                 current;
200                 current = NEXT)
201         {
202                 char clip_title[BCTEXTLEN];
203                 fs.extract_name(clip_title, current->path);
204                 int exists = 0;
205
206                 for(int j = 0; j < sources.total; j++)
207                 {
208                         if(!strcasecmp(sources.values[j]->get_text(), clip_title))
209                         {
210                                 exists = 1;
211                         }
212                 }
213
214                 if(!exists)
215                 {
216                         sources.append(new BC_ListBoxItem(clip_title));
217                 }
218         }
219
220 //printf("VWindowGUI::update_sources 4\n");
221
222 //      source->update_list(&sources);
223 //      source->update(title);
224         unlock_window();
225 }
226
227 void VWindowGUI::create_objects()
228 {
229         in_point = 0;
230         out_point = 0;
231         lock_window("VWindowGUI::create_objects");
232         set_icon(mwindow->theme->get_image("vwindow_icon"));
233
234 //printf("VWindowGUI::create_objects 1\n");
235         mwindow->theme->get_vwindow_sizes(this);
236         mwindow->theme->draw_vwindow_bg(this);
237         flash(0);
238
239         meters = new VWindowMeters(mwindow,
240                 this,
241                 mwindow->theme->vmeter_x,
242                 mwindow->theme->vmeter_y,
243                 mwindow->theme->vmeter_h);
244         meters->create_objects();
245
246 //printf("VWindowGUI::create_objects 1\n");
247 // Requires meters to build
248         edit_panel = new VWindowEditing(mwindow, vwindow);
249         edit_panel->set_meters(meters);
250         edit_panel->create_objects();
251
252 //printf("VWindowGUI::create_objects 1\n");
253         transport = new VWindowTransport(mwindow,
254                 this,
255                 mwindow->theme->vtransport_x,
256                 mwindow->theme->vtransport_y);
257         transport->create_objects();
258
259 //printf("VWindowGUI::create_objects 1\n");
260 //      add_subwindow(fps_title = new BC_Title(mwindow->theme->vedit_x, y, ""));
261     add_subwindow(clock = new MainClock(mwindow,
262                 mwindow->theme->vtime_x,
263                 mwindow->theme->vtime_y,
264                 mwindow->theme->vtime_w));
265
266         canvas = new VWindowCanvas(mwindow, this);
267         canvas->create_objects(mwindow->edl);
268         canvas->use_vwindow();
269
270
271 //printf("VWindowGUI::create_objects 1\n");
272         add_subwindow(timebar = new VTimeBar(mwindow,
273                 this,
274                 mwindow->theme->vtimebar_x,
275                 mwindow->theme->vtimebar_y,
276                 mwindow->theme->vtimebar_w,
277                 mwindow->theme->vtimebar_h));
278         timebar->create_objects();
279 //printf("VWindowGUI::create_objects 2\n");
280
281
282 //printf("VWindowGUI::create_objects 1\n");
283 //      source = new VWindowSource(mwindow,
284 //              this,
285 //              mwindow->theme->vsource_x,
286 //              mwindow->theme->vsource_y);
287 //      source->create_objects();
288         update_sources(_("None"));
289
290 //printf("VWindowGUI::create_objects 2\n");
291         deactivate();
292
293         show_window();
294         unlock_window();
295 }
296
297 int VWindowGUI::resize_event(int w, int h)
298 {
299         mwindow->session->vwindow_x = get_x();
300         mwindow->session->vwindow_y = get_y();
301         mwindow->session->vwindow_w = w;
302         mwindow->session->vwindow_h = h;
303
304         mwindow->theme->get_vwindow_sizes(this);
305         mwindow->theme->draw_vwindow_bg(this);
306         flash(0);
307
308 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vedit_y);
309         edit_panel->reposition_buttons(mwindow->theme->vedit_x,
310                 mwindow->theme->vedit_y);
311
312         timebar->resize_event();
313         transport->reposition_buttons(mwindow->theme->vtransport_x,
314                 mwindow->theme->vtransport_y);
315         clock->reposition_window(mwindow->theme->vtime_x,
316                 mwindow->theme->vtime_y,
317                 mwindow->theme->vtime_w,
318                 clock->get_h());
319         canvas->reposition_window(0,
320                 mwindow->theme->vcanvas_x,
321                 mwindow->theme->vcanvas_y,
322                 mwindow->theme->vcanvas_w,
323                 mwindow->theme->vcanvas_h);
324 //printf("VWindowGUI::resize_event %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
325 //      source->reposition_window(mwindow->theme->vsource_x,
326 //              mwindow->theme->vsource_y);
327         meters->reposition_window(mwindow->theme->vmeter_x,
328                 mwindow->theme->vmeter_y,
329                 -1,
330                 mwindow->theme->vmeter_h);
331
332         BC_WindowBase::resize_event(w, h);
333         return 1;
334 }
335
336
337
338
339
340 int VWindowGUI::translation_event()
341 {
342         mwindow->session->vwindow_x = get_x();
343         mwindow->session->vwindow_y = get_y();
344         return 0;
345 }
346
347 int VWindowGUI::close_event()
348 {
349         hide_window();
350         int i = mwindow->vwindows.size();
351         while( --i >= 0 && mwindow->vwindows.get(i)->gui != this );
352         if( i > 0 ) {
353                 set_done(0);
354                 return 1;
355         }
356
357         mwindow->session->show_vwindow = 0;
358         unlock_window();
359
360         mwindow->gui->lock_window("VWindowGUI::close_event");
361         mwindow->gui->mainmenu->show_vwindow->set_checked(0);
362         mwindow->gui->unlock_window();
363
364         lock_window("VWindowGUI::close_event");
365         mwindow->save_defaults();
366         return 1;
367 }
368
369 int VWindowGUI::keypress_event()
370 {
371         int result = 0;
372         switch(get_keypress())
373         {
374                 case 'w':
375                 case 'W':
376                         close_event();
377                         result = 1;
378                         break;
379                 case 'z':
380                         mwindow->undo_entry(this);
381                         break;
382                 case 'Z':
383                         mwindow->redo_entry(this);
384                         break;
385                 case 'f':
386                         unlock_window();
387                         if(mwindow->session->vwindow_fullscreen)
388                                 canvas->stop_fullscreen();
389                         else
390                                 canvas->start_fullscreen();
391                         lock_window("VWindowGUI::keypress_event 1");
392                         break;
393                 case ESC:
394                         unlock_window();
395                         if(mwindow->session->vwindow_fullscreen)
396                                 canvas->stop_fullscreen();
397                         lock_window("VWindowGUI::keypress_event 2");
398                         break;
399         }
400         if(!result) result = transport->keypress_event();
401         return result;
402 }
403
404 void VWindowGUI::stop_transport(const char *lock_msg)
405 {
406         if( !transport->is_stopped() ) {
407                 if( lock_msg ) unlock_window();
408                 transport->handle_transport(STOP, 1, 0, 0);
409                 if( lock_msg ) lock_window(lock_msg);
410         }
411 }
412
413 int VWindowGUI::button_press_event()
414 {
415         if( vwindow->get_edl() != 0 && canvas->get_canvas() &&
416             canvas->get_canvas()->get_cursor_over_window() ) {
417                 switch( get_buttonpress() ) {
418                 case LEFT_BUTTON:
419                         if( !vwindow->playback_engine->is_playing_back ) {
420                                 double length = vwindow->get_edl()->tracks->total_playable_length();
421                                 double position = vwindow->playback_engine->get_tracking_position();
422                                 if( position >= length ) transport->goto_start();
423                         }
424                         return transport->forward_play->handle_event();
425                 case MIDDLE_BUTTON:
426                         if( !vwindow->playback_engine->is_playing_back ) {
427                                 double position = vwindow->playback_engine->get_tracking_position();
428                                 if( position <= 0 ) transport->goto_end();
429                         }
430                         return transport->reverse_play->handle_event();
431                 case RIGHT_BUTTON:  // activates popup
432                         break;
433                 case WHEEL_UP:
434                         return transport->frame_forward_play->handle_event();
435                 case WHEEL_DOWN:
436                         return transport->frame_reverse_play->handle_event();
437                 }
438         }
439         if(canvas->get_canvas())
440                 return canvas->button_press_event_base(canvas->get_canvas());
441         return 0;
442 }
443
444 int VWindowGUI::cursor_leave_event()
445 {
446         if(canvas->get_canvas())
447                 return canvas->cursor_leave_event_base(canvas->get_canvas());
448         return 0;
449 }
450
451 int VWindowGUI::cursor_enter_event()
452 {
453         if(canvas->get_canvas())
454                 return canvas->cursor_enter_event_base(canvas->get_canvas());
455         return 0;
456 }
457
458 int VWindowGUI::button_release_event()
459 {
460         if(canvas->get_canvas())
461                 return canvas->button_release_event();
462         return 0;
463 }
464
465 int VWindowGUI::cursor_motion_event()
466 {
467         if(canvas->get_canvas())
468         {
469                 canvas->get_canvas()->unhide_cursor();
470                 return canvas->cursor_motion_event();
471         }
472         return 0;
473 }
474
475
476 void VWindowGUI::drag_motion()
477 {
478 // Window hidden
479         if(get_hidden()) return;
480         if(mwindow->session->current_operation != DRAG_ASSET) return;
481         int need_highlight = cursor_above() && get_cursor_over_window() ? 1 : 0;
482         if( highlighted == need_highlight ) return;
483         highlighted = need_highlight;
484         canvas->draw_refresh();
485 }
486
487 int VWindowGUI::drag_stop()
488 {
489         if(get_hidden()) return 0;
490
491         if(highlighted &&
492                 mwindow->session->current_operation == DRAG_ASSET)
493         {
494                 highlighted = 0;
495                 canvas->draw_refresh();
496                 unlock_window();
497
498                 Indexable *indexable = mwindow->session->drag_assets->size() ?
499                         mwindow->session->drag_assets->get(0) :
500                         0;
501                 EDL *edl = mwindow->session->drag_clips->size() ?
502                         mwindow->session->drag_clips->get(0) :
503                         0;
504                 if(indexable)
505                         vwindow->change_source(indexable);
506                 else
507                 if(edl)
508                         vwindow->change_source(edl);
509                 lock_window("VWindowGUI::drag_stop");
510                 return 1;
511         }
512
513         return 0;
514 }
515
516
517 void VWindowGUI::update_meters()
518 {
519         if(mwindow->edl->session->vwindow_meter != meters->visible)
520         {
521                 meters->set_meters(meters->meter_count,
522                         mwindow->edl->session->vwindow_meter);
523                 mwindow->theme->get_vwindow_sizes(this);
524                 resize_event(get_w(), get_h());
525         }
526 }
527
528
529
530 VWindowMeters::VWindowMeters(MWindow *mwindow,
531         VWindowGUI *gui,
532         int x,
533         int y,
534         int h)
535  : MeterPanel(mwindow,
536                 gui,
537                 x,
538                 y,
539                 -1,
540                 h,
541                 mwindow->edl->session->audio_channels,
542                 mwindow->edl->session->vwindow_meter,
543                 0,
544                 0)
545 {
546         this->mwindow = mwindow;
547         this->gui = gui;
548 }
549
550 VWindowMeters::~VWindowMeters()
551 {
552 }
553
554 int VWindowMeters::change_status_event(int new_status)
555 {
556         mwindow->edl->session->vwindow_meter = new_status;
557         gui->update_meters();
558         return 1;
559 }
560
561
562
563
564
565
566
567 VWindowEditing::VWindowEditing(MWindow *mwindow, VWindow *vwindow)
568  : EditPanel(mwindow,
569                 vwindow->gui,
570                 mwindow->theme->vedit_x,
571                 mwindow->theme->vedit_y,
572                 EDITING_ARROW,
573                 0,
574                 0,
575                 1,
576                 1,
577                 0,
578                 0,
579                 1,
580                 0,
581                 0,
582                 0,
583                 0, // locklabels
584                 1,
585                 1,
586                 1,
587                 0,
588                 0,
589                 0)
590 {
591         this->mwindow = mwindow;
592         this->vwindow = vwindow;
593 }
594
595 VWindowEditing::~VWindowEditing()
596 {
597 }
598
599 void VWindowEditing::copy_selection()
600 {
601         vwindow->copy();
602 }
603
604 void VWindowEditing::splice_selection()
605 {
606         if(vwindow->get_edl())
607         {
608                 mwindow->gui->lock_window("VWindowEditing::splice_selection");
609                 mwindow->splice(vwindow->get_edl());
610                 mwindow->gui->unlock_window();
611         }
612 }
613
614 void VWindowEditing::overwrite_selection()
615 {
616         if(vwindow->get_edl())
617         {
618                 mwindow->gui->lock_window("VWindowEditing::overwrite_selection");
619                 mwindow->overwrite(vwindow->get_edl());
620                 mwindow->gui->unlock_window();
621         }
622 }
623
624 void VWindowEditing::toggle_label()
625 {
626         if(vwindow->get_edl())
627         {
628                 EDL *edl = vwindow->get_edl();
629                 edl->labels->toggle_label(edl->local_session->get_selectionstart(1),
630                         edl->local_session->get_selectionend(1));
631                 vwindow->gui->timebar->update(1);
632         }
633 }
634
635 void VWindowEditing::prev_label()
636 {
637         if(vwindow->get_edl())
638         {
639                 EDL *edl = vwindow->get_edl();
640                 vwindow->gui->unlock_window();
641                 vwindow->playback_engine->interrupt_playback(1);
642                 vwindow->gui->lock_window("VWindowEditing::prev_label");
643
644                 Label *current = edl->labels->prev_label(
645                         edl->local_session->get_selectionstart(1));
646
647
648                 if(!current)
649                 {
650                         edl->local_session->set_selectionstart(0);
651                         edl->local_session->set_selectionend(0);
652                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
653                         vwindow->gui->timebar->update(1);
654                 }
655                 else
656                 {
657                         edl->local_session->set_selectionstart(current->position);
658                         edl->local_session->set_selectionend(current->position);
659                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
660                         vwindow->gui->timebar->update(1);
661                 }
662         }
663 }
664
665 void VWindowEditing::next_label()
666 {
667         if(vwindow->get_edl())
668         {
669                 EDL *edl = vwindow->get_edl();
670                 Label *current = edl->labels->next_label(
671                         edl->local_session->get_selectionstart(1));
672                 if(!current)
673                 {
674                         vwindow->gui->unlock_window();
675                         vwindow->playback_engine->interrupt_playback(1);
676                         vwindow->gui->lock_window("VWindowEditing::next_label 1");
677
678                         double position = edl->tracks->total_length();
679                         edl->local_session->set_selectionstart(position);
680                         edl->local_session->set_selectionend(position);
681                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
682                         vwindow->gui->timebar->update(1);
683                 }
684                 else
685                 {
686                         vwindow->gui->unlock_window();
687                         vwindow->playback_engine->interrupt_playback(1);
688                         vwindow->gui->lock_window("VWindowEditing::next_label 2");
689
690                         edl->local_session->set_selectionstart(current->position);
691                         edl->local_session->set_selectionend(current->position);
692                         vwindow->update_position(CHANGE_NONE, 0, 1, 0);
693                         vwindow->gui->timebar->update(1);
694                 }
695         }
696 }
697
698 double VWindowEditing::get_position()
699 {
700         EDL *edl = vwindow->get_edl();
701         double position = !edl ? 0 : edl->local_session->get_selectionstart(1);
702         return position;
703 }
704
705 void VWindowEditing::set_position(double position)
706 {
707         EDL *edl = vwindow->get_edl();
708         if( !edl ) return;
709         if( get_position() != position ) {
710                 if( position < 0 ) position = 0;
711                 edl->local_session->set_selectionstart(position);
712                 edl->local_session->set_selectionend(position);
713                 vwindow->update_position(CHANGE_NONE, 0, 1);
714         }
715 }
716
717 void VWindowEditing::set_inpoint()
718 {
719         vwindow->set_inpoint();
720 }
721
722 void VWindowEditing::set_outpoint()
723 {
724         vwindow->set_outpoint();
725 }
726
727 void VWindowEditing::unset_inoutpoint()
728 {
729         vwindow->unset_inoutpoint();
730 }
731
732
733 void VWindowEditing::to_clip()
734 {
735         EDL *edl = vwindow->get_edl();
736         if( !edl ) return;
737         mwindow->to_clip(edl, _("viewer window: "));
738 }
739
740 VWindowSource::VWindowSource(MWindow *mwindow, VWindowGUI *vwindow, int x, int y)
741  : BC_PopupTextBox(vwindow,
742         &vwindow->sources,
743         "",
744         x,
745         y,
746         200,
747         200)
748 {
749         this->mwindow = mwindow;
750         this->vwindow = vwindow;
751 }
752
753 VWindowSource::~VWindowSource()
754 {
755 }
756
757 int VWindowSource::handle_event()
758 {
759         return 1;
760 }
761
762
763 VWindowTransport::VWindowTransport(MWindow *mwindow,
764         VWindowGUI *gui,
765         int x,
766         int y)
767  : PlayTransport(mwindow,
768         gui,
769         x,
770         y)
771 {
772         this->gui = gui;
773 }
774
775 EDL* VWindowTransport::get_edl()
776 {
777         return gui->vwindow->get_edl();
778 }
779
780
781 void VWindowTransport::goto_start()
782 {
783         gui->unlock_window();
784         handle_transport(REWIND, 1);
785         gui->lock_window("VWindowTransport::goto_start");
786         gui->vwindow->goto_start();
787 }
788
789 void VWindowTransport::goto_end()
790 {
791         gui->unlock_window();
792         handle_transport(GOTO_END, 1);
793         gui->lock_window("VWindowTransport::goto_end");
794         gui->vwindow->goto_end();
795 }
796
797
798
799
800 VWindowCanvas::VWindowCanvas(MWindow *mwindow, VWindowGUI *gui)
801  : Canvas(mwindow,
802         gui,
803         mwindow->theme->vcanvas_x,
804         mwindow->theme->vcanvas_y,
805         mwindow->theme->vcanvas_w,
806         mwindow->theme->vcanvas_h,
807         0, 0, 0)
808 {
809 //printf("VWindowCanvas::VWindowCanvas %d %d\n", __LINE__, mwindow->theme->vcanvas_x);
810         this->mwindow = mwindow;
811         this->gui = gui;
812 }
813
814 void VWindowCanvas::zoom_resize_window(float percentage)
815 {
816         EDL *edl = gui->vwindow->get_edl();
817         if(!edl) edl = mwindow->edl;
818
819         int canvas_w, canvas_h;
820         int new_w, new_h;
821
822 // Get required canvas size
823         calculate_sizes(edl->get_aspect_ratio(),
824                 edl->session->output_w,
825                 edl->session->output_h,
826                 percentage,
827                 canvas_w,
828                 canvas_h);
829
830 // Estimate window size from current borders
831         new_w = canvas_w + (gui->get_w() - mwindow->theme->vcanvas_w);
832         new_h = canvas_h + (gui->get_h() - mwindow->theme->vcanvas_h);
833
834         mwindow->session->vwindow_w = new_w;
835         mwindow->session->vwindow_h = new_h;
836
837         mwindow->theme->get_vwindow_sizes(gui);
838
839 // Estimate again from new borders
840         new_w = canvas_w + (mwindow->session->vwindow_w - mwindow->theme->vcanvas_w);
841         new_h = canvas_h + (mwindow->session->vwindow_h - mwindow->theme->vcanvas_h);
842
843
844         gui->resize_window(new_w, new_h);
845         gui->resize_event(new_w, new_h);
846 }
847
848 void VWindowCanvas::close_source()
849 {
850         gui->unlock_window();
851         gui->vwindow->playback_engine->interrupt_playback(1);
852         gui->lock_window("VWindowCanvas::close_source");
853         gui->vwindow->delete_source(1, 1);
854 }
855
856
857 void VWindowCanvas::draw_refresh(int flush)
858 {
859         EDL *edl = gui->vwindow->get_edl();
860
861         if(!get_canvas()->get_video_on()) get_canvas()->clear_box(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
862         if(!get_canvas()->get_video_on() && refresh_frame && edl)
863         {
864                 float in_x1, in_y1, in_x2, in_y2;
865                 float out_x1, out_y1, out_x2, out_y2;
866                 get_transfers(edl,
867                         in_x1,
868                         in_y1,
869                         in_x2,
870                         in_y2,
871                         out_x1,
872                         out_y1,
873                         out_x2,
874                         out_y2);
875                 get_canvas()->draw_vframe(refresh_frame,
876                                 (int)out_x1,
877                                 (int)out_y1,
878                                 (int)(out_x2 - out_x1),
879                                 (int)(out_y2 - out_y1),
880                                 (int)in_x1,
881                                 (int)in_y1,
882                                 (int)(in_x2 - in_x1),
883                                 (int)(in_y2 - in_y1),
884                                 0);
885         }
886
887         if(!get_canvas()->get_video_on())
888         {
889                 draw_overlays();
890                 get_canvas()->flash(flush);
891         }
892 }
893
894 void VWindowCanvas::draw_overlays()
895 {
896         if( gui->highlighted )
897         {
898                 get_canvas()->set_color(WHITE);
899                 get_canvas()->set_inverse();
900                 get_canvas()->draw_rectangle(0, 0, get_canvas()->get_w(), get_canvas()->get_h());
901                 get_canvas()->draw_rectangle(1, 1, get_canvas()->get_w() - 2, get_canvas()->get_h() - 2);
902                 get_canvas()->set_opaque();
903         }
904 }
905
906 int VWindowCanvas::get_fullscreen()
907 {
908         return mwindow->session->vwindow_fullscreen;
909 }
910
911 void VWindowCanvas::set_fullscreen(int value)
912 {
913         mwindow->session->vwindow_fullscreen = value;
914 }
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952 #if 0
953 void VWindowGUI::update_points()
954 {
955         EDL *edl = vwindow->get_edl();
956
957 //printf("VWindowGUI::update_points 1\n");
958         if(!edl) return;
959
960 //printf("VWindowGUI::update_points 2\n");
961         long pixel = (long)((double)edl->local_session->in_point /
962                 edl->tracks->total_length() *
963                 (mwindow->theme->vtimebar_w -
964                         2 *
965                         mwindow->theme->in_point[0]->get_w())) +
966                 mwindow->theme->in_point[0]->get_w();
967
968 //printf("VWindowGUI::update_points 3 %d\n", edl->local_session->in_point);
969         if(in_point)
970         {
971 //printf("VWindowGUI::update_points 3.1\n");
972                 if(edl->local_session->in_point >= 0)
973                 {
974 //printf("VWindowGUI::update_points 4\n");
975                         if(edl->local_session->in_point != in_point->position ||
976                                 in_point->pixel != pixel)
977                         {
978                                 in_point->pixel = pixel;
979                                 in_point->reposition();
980                         }
981
982 //printf("VWindowGUI::update_points 5\n");
983                         in_point->position = edl->local_session->in_point;
984
985 //printf("VWindowGUI::update_points 6\n");
986                         if(edl->equivalent(in_point->position, edl->local_session->get_selectionstart(1)) ||
987                                 edl->equivalent(in_point->position, edl->local_session->get_selectionend(1)))
988                                 in_point->update(1);
989                         else
990                                 in_point->update(0);
991 //printf("VWindowGUI::update_points 7\n");
992                 }
993                 else
994                 {
995                         delete in_point;
996                         in_point = 0;
997                 }
998         }
999         else
1000         if(edl->local_session->in_point >= 0)
1001         {
1002 //printf("VWindowGUI::update_points 8 %p\n", mwindow->theme->in_point);
1003                 add_subwindow(in_point =
1004                         new VWindowInPoint(mwindow,
1005                                 0,
1006                                 this,
1007                                 pixel,
1008                                 edl->local_session->in_point));
1009 //printf("VWindowGUI::update_points 9\n");
1010         }
1011 //printf("VWindowGUI::update_points 10\n");
1012
1013         pixel = (long)((double)edl->local_session->out_point /
1014                 (edl->tracks->total_length() + 0.5) *
1015                 (mwindow->theme->vtimebar_w -
1016                         2 *
1017                         mwindow->theme->in_point[0]->get_w())) +
1018                 mwindow->theme->in_point[0]->get_w() *
1019                 2;
1020
1021         if(out_point)
1022         {
1023                 if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
1024                 {
1025                         if(edl->local_session->out_point != out_point->position ||
1026                                 out_point->pixel != pixel)
1027                         {
1028                                 out_point->pixel = pixel;
1029                                 out_point->reposition();
1030                         }
1031                         out_point->position = edl->local_session->out_point;
1032
1033                         if(edl->equivalent(out_point->position, edl->local_session->get_selectionstart(1)) ||
1034                                 edl->equivalent(out_point->position, edl->local_session->get_selectionend(1)))
1035                                 out_point->update(1);
1036                         else
1037                                 out_point->update(0);
1038                 }
1039                 else
1040                 {
1041                         delete out_point;
1042                         out_point = 0;
1043                 }
1044         }
1045         else
1046         if(edl->local_session->out_point >= 0 && pixel >= 0 && pixel <= mwindow->theme->vtimebar_w)
1047         {
1048                 add_subwindow(out_point =
1049                         new VWindowOutPoint(mwindow,
1050                                 0,
1051                                 this,
1052                                 pixel,
1053                                 edl->local_session->out_point));
1054         }
1055 }
1056
1057
1058 void VWindowGUI::update_labels()
1059 {
1060         EDL *edl = vwindow->get_edl();
1061         int output = 0;
1062
1063         for(Label *current = edl->labels->first;
1064                 current;
1065                 current = NEXT)
1066         {
1067                 long pixel = (long)((current->position - edl->local_session->view_start) / edl->local_session->zoom_sample);
1068
1069                 if(pixel >= 0 && pixel < mwindow->theme->vtimebar_w)
1070                 {
1071 // Create new label
1072                         if(output >= labels.total)
1073                         {
1074                                 LabelGUI *new_label;
1075                                 add_subwindow(new_label = new LabelGUI(mwindow, this, pixel, 0, current->position));
1076                                 labels.append(new_label);
1077                         }
1078                         else
1079 // Reposition old label
1080                         if(labels.values[output]->pixel != pixel)
1081                         {
1082                                 labels.values[output]->pixel = pixel;
1083                                 labels.values[output]->position = current->position;
1084                                 labels.values[output]->reposition();
1085                         }
1086
1087                         if(mwindow->edl->local_session->get_selectionstart(1) <= current->position &&
1088                                 mwindow->edl->local_session->get_selectionend(1) >= current->position)
1089                                 labels.values[output]->update(1);
1090                         else
1091                         if(labels.values[output]->get_value())
1092                                 labels.values[output]->update(0);
1093                         output++;
1094                 }
1095         }
1096
1097 // Delete excess labels
1098         while(labels.total > output)
1099         {
1100                 labels.remove_object();
1101         }
1102 }
1103
1104
1105
1106 VWindowInPoint::VWindowInPoint(MWindow *mwindow,
1107                 TimeBar *timebar,
1108                 VWindowGUI *gui,
1109                 long pixel,
1110                 double position)
1111  : InPointGUI(mwindow,
1112                 timebar,
1113                 pixel,
1114                 position)
1115 {
1116         this->gui = gui;
1117 }
1118
1119 int VWindowInPoint::handle_event()
1120 {
1121         EDL *edl = gui->vwindow->get_edl();
1122
1123         if(edl)
1124         {
1125                 double position = edl->align_to_frame(this->position, 0);
1126
1127                 edl->local_session->set_selectionstart(position);
1128                 edl->local_session->set_selectionend(position);
1129                 gui->timebar->update(1);
1130
1131 // Que the VWindow
1132                 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);
1133         }
1134         return 1;
1135 }
1136
1137
1138
1139 VWindowOutPoint::VWindowOutPoint(MWindow *mwindow,
1140                 TimeBar *timebar,
1141                 VWindowGUI *gui,
1142                 long pixel,
1143                 double position)
1144  : OutPointGUI(mwindow,
1145                 timebar,
1146                 pixel,
1147                 position)
1148 {
1149         this->gui = gui;
1150 }
1151
1152 int VWindowOutPoint::handle_event()
1153 {
1154         EDL *edl = gui->vwindow->get_edl();
1155
1156         if(edl)
1157         {
1158                 double position = edl->align_to_frame(this->position, 0);
1159
1160                 edl->local_session->set_selectionstart(position);
1161                 edl->local_session->set_selectionend(position);
1162                 gui->timebar->update(1);
1163
1164 // Que the VWindow
1165                 mwindow->vwindow->update_position(CHANGE_NONE, 0, 1, 0);
1166         }
1167
1168         return 1;
1169 }
1170
1171
1172
1173 #endif
1174