fix for ffmpeg seek pos 0, add pactl probe
[goodguy/history.git] / cinelerra-5.1 / cinelerra / editpanel.C
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 #include "awindow.h"
23 #include "awindowgui.h"
24 #include "bcsignals.h"
25 #include "clipedit.h"
26 #include "cplayback.h"
27 #include "cwindow.h"
28 #include "cwindowgui.h"
29 #include "editpanel.h"
30 #include "edl.h"
31 #include "edlsession.h"
32 #include "filexml.h"
33 #include "keys.h"
34 #include "language.h"
35 #include "localsession.h"
36 #include "mainclock.h"
37 #include "mainundo.h"
38 #include "mbuttons.h"
39 #include "meterpanel.h"
40 #include "mwindow.h"
41 #include "mwindowgui.h"
42 #include "playbackengine.h"
43 #include "theme.h"
44 #include "timebar.h"
45 #include "trackcanvas.h"
46 #include "transportque.h"
47 #include "zoombar.h"
48 #include "manualgoto.h"
49
50
51
52 EditPanel::EditPanel(MWindow *mwindow,
53         BC_WindowBase *subwindow,
54         int x,
55         int y,
56         int editing_mode,
57         int use_editing_mode,
58         int use_keyframe,
59         int use_splice,   // Extra buttons
60         int use_overwrite,
61         int use_lift,
62         int use_extract,
63         int use_copy,
64         int use_paste,
65         int use_undo,
66         int use_fit,
67         int use_locklabels,
68         int use_labels,
69         int use_toclip,
70         int use_meters,
71         int is_mwindow,
72         int use_cut,
73         int use_commercial)
74 {
75         this->editing_mode = editing_mode;
76         this->use_editing_mode = use_editing_mode;
77         this->use_keyframe = use_keyframe;
78         this->use_splice = use_splice;
79         this->use_overwrite = use_overwrite;
80         this->use_lift = 0;
81         this->use_extract = 0;
82         this->use_copy = use_copy;
83         this->use_paste = use_paste;
84         this->use_undo = use_undo;
85         this->mwindow = mwindow;
86         this->subwindow = subwindow;
87         this->use_fit = use_fit;
88         this->use_labels = use_labels;
89         this->use_locklabels = use_locklabels;
90         this->use_toclip = use_toclip;
91         this->use_meters = use_meters;
92         this->is_mwindow = is_mwindow;
93         this->use_cut = use_cut;
94         this->use_commercial = use_commercial;
95
96         this->x = x;
97         this->y = y;
98         this->fit = 0;
99         this->fit_autos = 0;
100         this->inpoint = 0;
101         this->outpoint = 0;
102         this->splice = 0;
103         this->overwrite = 0;
104         this->lift = 0;
105         this->extract = 0;
106         this->clip = 0;
107         this->cut = 0;
108         this->commercial = 0;
109         this->copy = 0;
110         this->paste = 0;
111         this->labelbutton = 0;
112         this->prevlabel = 0;
113         this->nextlabel = 0;
114         this->prevedit = 0;
115         this->nextedit = 0;
116         this->undo = 0;
117         this->redo = 0;
118         this->meter_panel = 0;
119         this->meters = 0;
120         this->arrow = 0;
121         this->ibeam = 0;
122         this->keyframe = 0;
123         locklabels = 0;
124 }
125
126 EditPanel::~EditPanel()
127 {
128 }
129
130 void EditPanel::set_meters(MeterPanel *meter_panel)
131 {
132         this->meter_panel = meter_panel;
133 }
134
135
136 void EditPanel::update()
137 {
138         int new_editing_mode = mwindow->edl->session->editing_mode;
139         if(arrow) arrow->update(new_editing_mode == EDITING_ARROW);
140         if(ibeam) ibeam->update(new_editing_mode == EDITING_IBEAM);
141         if(keyframe) keyframe->update(mwindow->edl->session->auto_keyframes);
142         if(locklabels) locklabels->set_value(mwindow->edl->session->labels_follow_edits);
143         if(meters)
144         {
145 //printf("EditPanel::update %d %p %p\n", __LINE__, subwindow, (BC_WindowBase*)mwindow->cwindow->gui);
146                 if(subwindow == (BC_WindowBase*)mwindow->cwindow->gui)
147                 {
148 //printf("EditPanel::update %d %d\n", __LINE__, mwindow->edl->session->cwindow_meter);
149                         meters->update(mwindow->edl->session->cwindow_meter);
150                         mwindow->cwindow->gui->update_meters();
151                 }
152                 else
153                 {
154 //printf("EditPanel::update %d %d\n", __LINE__, mwindow->edl->session->vwindow_meter);
155                         meters->update(mwindow->edl->session->vwindow_meter);
156                 }
157         }
158         subwindow->flush();
159 }
160
161 int EditPanel::calculate_w(MWindow *mwindow, int use_keyframe, int total_buttons)
162 {
163         int result = 0;
164         int button_w = mwindow->theme->get_image_set("ibeam")[0]->get_w();
165         if(use_keyframe)
166         {
167                 result += button_w + mwindow->theme->toggle_margin;
168         }
169
170         result += button_w * total_buttons;
171         return result;
172 }
173
174 int EditPanel::calculate_h(MWindow *mwindow)
175 {
176         return mwindow->theme->get_image_set("ibeam")[0]->get_h();
177 }
178
179 void EditPanel::create_buttons()
180 {
181         x1 = x, y1 = y;
182
183
184 SET_TRACE
185         if(use_editing_mode)
186         {
187                 subwindow->add_subwindow(arrow = new ArrowButton(mwindow, this, x1, y1));
188                 x1 += arrow->get_w();
189                 subwindow->add_subwindow(ibeam = new IBeamButton(mwindow, this, x1, y1));
190                 x1 += ibeam->get_w();
191                 x1 += mwindow->theme->toggle_margin;
192         }
193
194         if(use_keyframe)
195         {
196                 subwindow->add_subwindow(keyframe = new KeyFrameButton(mwindow, this, x1, y1));
197                 x1 += keyframe->get_w();
198         }
199
200         if(use_locklabels)
201         {
202                 subwindow->add_subwindow(locklabels = new LockLabelsButton(mwindow,
203                         x1,
204                         y1));
205                 x1 += locklabels->get_w();
206         }
207         if(use_keyframe || use_locklabels)
208                 x1 += mwindow->theme->toggle_margin;
209
210 // Mandatory
211         subwindow->add_subwindow(inpoint = new EditInPoint(mwindow, this, x1, y1));
212         x1 += inpoint->get_w();
213         subwindow->add_subwindow(outpoint = new EditOutPoint(mwindow, this, x1, y1));
214         x1 += outpoint->get_w();
215         if(use_splice)
216         {
217                 subwindow->add_subwindow(splice = new EditSplice(mwindow, this, x1, y1));
218                 x1 += splice->get_w();
219         }
220         if(use_overwrite)
221         {
222                 subwindow->add_subwindow(overwrite = new EditOverwrite(mwindow, this, x1, y1));
223                 x1 += overwrite->get_w();
224         }
225         if(use_lift)
226         {
227                 subwindow->add_subwindow(lift = new EditLift(mwindow, this, x1, y1));
228                 x1 += lift->get_w();
229         }
230         if(use_extract)
231         {
232                 subwindow->add_subwindow(extract = new EditExtract(mwindow, this, x1, y1));
233                 x1 += extract->get_w();
234         }
235         if(use_toclip)
236         {
237                 subwindow->add_subwindow(clip = new EditToClip(mwindow, this, x1, y1));
238                 x1 += clip->get_w();
239         }
240
241         if(use_cut)
242         {
243                 subwindow->add_subwindow(cut = new EditCut(mwindow, this, x1, y1));
244                 x1 += cut->get_w();
245         }
246         if(use_copy)
247         {
248                 subwindow->add_subwindow(copy = new EditCopy(mwindow, this, x1, y1));
249                 x1 += copy->get_w();
250         }
251         if(use_paste)
252         {
253                 subwindow->add_subwindow(paste = new EditPaste(mwindow, this, x1, y1));
254                 x1 += paste->get_w();
255         }
256
257         if(use_meters)
258         {
259                 if(!meter_panel)
260                 {
261                         printf("EditPanel::create_objects: meter_panel == 0\n");
262                 }
263                 subwindow->add_subwindow(meters = new MeterShow(mwindow, meter_panel, x1, y1));
264                 x1 += meters->get_w();
265         }
266
267         if(use_labels)
268         {
269                 subwindow->add_subwindow(labelbutton = new EditLabelbutton(mwindow,
270                         this,
271                         x1,
272                         y1));
273                 x1 += labelbutton->get_w();
274                 subwindow->add_subwindow(prevlabel = new EditPrevLabel(mwindow,
275                         this,
276                         x1,
277                         y1,
278                         is_mwindow));
279                 x1 += prevlabel->get_w();
280                 subwindow->add_subwindow(nextlabel = new EditNextLabel(mwindow,
281                         this,
282                         x1,
283                         y1,
284                         is_mwindow));
285                 x1 += nextlabel->get_w();
286         }
287
288 // all windows except VWindow since it's only implemented in MWindow.
289         if(use_cut)
290         {
291                 subwindow->add_subwindow(prevedit = new EditPrevEdit(mwindow,
292                         this,
293                         x1,
294                         y1,
295                         is_mwindow));
296                 x1 += prevedit->get_w();
297                 subwindow->add_subwindow(nextedit = new EditNextEdit(mwindow,
298                         this,
299                         x1,
300                         y1,
301                         is_mwindow));
302                 x1 += nextedit->get_w();
303         }
304
305         if(use_fit)
306         {
307                 subwindow->add_subwindow(fit = new EditFit(mwindow, this, x1, y1));
308                 x1 += fit->get_w();
309                 subwindow->add_subwindow(fit_autos = new EditFitAutos(mwindow, this, x1, y1));
310                 x1 += fit_autos->get_w();
311         }
312
313         if(use_undo)
314         {
315                 subwindow->add_subwindow(undo = new EditUndo(mwindow, this, x1, y1));
316                 x1 += undo->get_w();
317                 subwindow->add_subwindow(redo = new EditRedo(mwindow, this, x1, y1));
318                 x1 += redo->get_w();
319         }
320
321         subwindow->add_subwindow(mangoto = new EditManualGoto(mwindow, this, x1, y1));
322         x1 += mangoto->get_w();
323
324         if(use_commercial)
325         {
326                 subwindow->add_subwindow(commercial = new EditCommercial(mwindow, this, x1, y1));
327                 x1 += commercial->get_w();
328         }
329 SET_TRACE
330 }
331
332
333
334 void EditPanel::toggle_label()
335 {
336         mwindow->toggle_label(is_mwindow);
337 }
338
339 void EditPanel::prev_label()
340 {
341         int shift_down = subwindow->shift_down();
342         int have_mwindow_lock = mwindow->gui->get_window_lock();
343         int have_subwindow_lock =
344                  subwindow->get_top_level() == mwindow->gui->get_top_level() ?
345                          0 : subwindow->get_window_lock();
346         if(have_mwindow_lock)
347                 mwindow->gui->unlock_window();
348         if(have_subwindow_lock)
349                 subwindow->unlock_window();
350
351         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
352
353         if(have_subwindow_lock)
354                 subwindow->lock_window("EditPanel::prev_label 1");
355
356         mwindow->gui->lock_window("EditPanel::prev_label 2");
357
358         mwindow->prev_label(shift_down);
359
360         if(!have_mwindow_lock)
361                 mwindow->gui->unlock_window();
362 }
363
364 void EditPanel::next_label()
365 {
366         int shift_down = subwindow->shift_down();
367         int have_mwindow_lock = mwindow->gui->get_window_lock();
368         int have_subwindow_lock =
369                  subwindow->get_top_level() == mwindow->gui->get_top_level() ?
370                          0 : subwindow->get_window_lock();
371         if(have_mwindow_lock)
372                 mwindow->gui->unlock_window();
373         if(have_subwindow_lock)
374                 subwindow->unlock_window();
375
376         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
377
378         if(have_subwindow_lock)
379                 subwindow->lock_window("EditPanel::next_label 1");
380
381         mwindow->gui->lock_window("EditPanel::next_label 2");
382
383         mwindow->next_label(shift_down);
384
385         if(!have_mwindow_lock)
386                 mwindow->gui->unlock_window();
387 }
388
389
390
391 void EditPanel::prev_edit()
392 {
393         int shift_down = subwindow->shift_down();
394         int have_mwindow_lock = mwindow->gui->get_window_lock();
395         int have_subwindow_lock =
396                  subwindow->get_top_level() == mwindow->gui->get_top_level() ?
397                          0 : subwindow->get_window_lock();
398         if(have_mwindow_lock)
399                 mwindow->gui->unlock_window();
400         if(have_subwindow_lock)
401                 subwindow->unlock_window();
402
403         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
404
405         if(have_subwindow_lock)
406                 subwindow->lock_window("EditPanel::prev_edit 1");
407
408         mwindow->gui->lock_window("EditPanel::prev_edit 2");
409
410         mwindow->prev_edit_handle(shift_down);
411
412         if(!have_mwindow_lock)
413                 mwindow->gui->unlock_window();
414 }
415
416 void EditPanel::next_edit()
417 {
418         int shift_down = subwindow->shift_down();
419         int have_mwindow_lock = mwindow->gui->get_window_lock();
420         int have_subwindow_lock =
421                  subwindow->get_top_level() == mwindow->gui->get_top_level() ?
422                          0 : subwindow->get_window_lock();
423         if(have_mwindow_lock)
424                 mwindow->gui->unlock_window();
425         if(have_subwindow_lock)
426                 subwindow->unlock_window();
427
428         mwindow->gui->mbuttons->transport->handle_transport(STOP, 1, 0, 0);
429
430         if(have_subwindow_lock)
431                 subwindow->lock_window("EditPanel::next_edit 1");
432
433         mwindow->gui->lock_window("EditPanel::next_edit 2");
434
435         mwindow->next_edit_handle(shift_down);
436
437         if(!have_mwindow_lock)
438                 mwindow->gui->unlock_window();
439 }
440
441
442 double EditPanel::get_position()
443 {
444         EDL *edl = mwindow->edl;
445         return !edl ? 0 :
446                 edl->local_session->get_selectionstart(1) +
447                         edl->session->get_frame_offset() / edl->session->frame_rate;
448 }
449
450 void EditPanel::set_position(double position)
451 {
452         EDL *edl = mwindow->edl;
453         if( !edl ) return;
454         if( position != get_position() ) {
455                 position -= edl->session->get_frame_offset() / edl->session->frame_rate;
456                 if( position < 0 ) position = 0;
457                 edl->local_session->set_selectionstart(position);
458                 edl->local_session->set_selectionend(position);
459                 mwindow->gui->lock_window();
460                 mwindow->find_cursor();
461                 mwindow->gui->update(1, 1, 1, 1, 1, 1, 0);
462                 mwindow->gui->unlock_window();
463                 mwindow->cwindow->update(1, 0, 0, 0, 0);
464         }
465 }
466
467
468
469
470
471
472
473 void EditPanel::reposition_buttons(int x, int y)
474 {
475         this->x = x;
476         this->y = y;
477         x1 = x, y1 = y;
478
479         if(use_editing_mode)
480         {
481                 arrow->reposition_window(x1, y1);
482                 x1 += arrow->get_w();
483                 ibeam->reposition_window(x1, y1);
484                 x1 += ibeam->get_w();
485                 x1 += mwindow->theme->toggle_margin;
486         }
487
488         if(use_keyframe)
489         {
490                 keyframe->reposition_window(x1, y1);
491                 x1 += keyframe->get_w();
492         }
493
494         if(use_locklabels)
495         {
496                 locklabels->reposition_window(x1,y1);
497                 x1 += locklabels->get_w();
498         }
499
500         if(use_keyframe || use_locklabels)
501                 x1 += mwindow->theme->toggle_margin;
502
503         inpoint->reposition_window(x1, y1);
504         x1 += inpoint->get_w();
505         outpoint->reposition_window(x1, y1);
506         x1 += outpoint->get_w();
507         if(use_splice)
508         {
509                 splice->reposition_window(x1, y1);
510                 x1 += splice->get_w();
511         }
512         if(use_overwrite)
513         {
514                 overwrite->reposition_window(x1, y1);
515                 x1 += overwrite->get_w();
516         }
517         if(use_lift)
518         {
519                 lift->reposition_window(x1, y1);
520                 x1 += lift->get_w();
521         }
522         if(use_extract)
523         {
524                 extract->reposition_window(x1, y1);
525                 x1 += extract->get_w();
526         }
527         if(use_toclip)
528         {
529                 clip->reposition_window(x1, y1);
530                 x1 += clip->get_w();
531         }
532         if(use_cut)
533         {
534                 cut->reposition_window(x1, y1);
535                 x1 += cut->get_w();
536         }
537         if(use_copy)
538         {
539                 copy->reposition_window(x1, y1);
540                 x1 += copy->get_w();
541         }
542         if(use_paste)
543         {
544                 paste->reposition_window(x1, y1);
545                 x1 += paste->get_w();
546         }
547
548         if(use_meters)
549         {
550                 meters->reposition_window(x1, y1);
551                 x1 += meters->get_w();
552         }
553
554         if(use_labels)
555         {
556                 labelbutton->reposition_window(x1, y1);
557                 x1 += labelbutton->get_w();
558                 prevlabel->reposition_window(x1, y1);
559                 x1 += prevlabel->get_w();
560                 nextlabel->reposition_window(x1, y1);
561                 x1 += nextlabel->get_w();
562         }
563
564         if(prevedit)
565         {
566                 prevedit->reposition_window(x1, y1);
567                 x1 += prevedit->get_w();
568         }
569
570         if(nextedit)
571         {
572                 nextedit->reposition_window(x1, y1);
573                 x1 += nextedit->get_w();
574         }
575
576         if(use_fit)
577         {
578                 fit->reposition_window(x1, y1);
579                 x1 += fit->get_w();
580                 fit_autos->reposition_window(x1, y1);
581                 x1 += fit_autos->get_w();
582         }
583
584         if(use_undo)
585         {
586                 undo->reposition_window(x1, y1);
587                 x1 += undo->get_w();
588                 redo->reposition_window(x1, y1);
589                 x1 += redo->get_w();
590         }
591
592         mangoto->reposition_window(x1, y1);
593         x1 += mangoto->get_w();
594 }
595
596
597
598 void EditPanel::create_objects()
599 {
600         create_buttons();
601 }
602
603 int EditPanel::get_w()
604 {
605         return x1 - x;
606 }
607
608
609 void EditPanel::copy_selection()
610 {
611         mwindow->copy();
612 }
613
614 void EditPanel::splice_selection()
615 {
616 }
617
618 void EditPanel::overwrite_selection()
619 {
620 }
621
622 void EditPanel::set_inpoint()
623 {
624         mwindow->set_inpoint(1);
625 }
626
627 void EditPanel::set_outpoint()
628 {
629         mwindow->set_outpoint(1);
630 }
631
632 void EditPanel::clear_inpoint()
633 {
634         mwindow->delete_inpoint();
635 }
636
637 void EditPanel::clear_outpoint()
638 {
639         mwindow->delete_outpoint();
640 }
641
642 void EditPanel::to_clip()
643 {
644         subwindow->unlock_window();
645         mwindow->to_clip();
646         subwindow->lock_window("EditPanel::to_clip");
647 }
648
649
650 EditInPoint::EditInPoint(MWindow *mwindow, EditPanel *panel, int x, int y)
651  : BC_Button(x, y, mwindow->theme->get_image_set("inbutton"))
652 {
653         this->mwindow = mwindow;
654         this->panel = panel;
655         set_tooltip(_("In point ( [ )"));
656 }
657 EditInPoint::~EditInPoint()
658 {
659 }
660 int EditInPoint::handle_event()
661 {
662         panel->set_inpoint();
663         return 1;
664 }
665 int EditInPoint::keypress_event()
666 {
667         if(get_keypress() == '[')
668         {
669                 panel->set_inpoint();
670                 return 1;
671         }
672         return 0;
673 }
674
675 EditOutPoint::EditOutPoint(MWindow *mwindow, EditPanel *panel, int x, int y)
676  : BC_Button(x, y, mwindow->theme->get_image_set("outbutton"))
677 {
678         this->mwindow = mwindow;
679         this->panel = panel;
680         set_tooltip(_("Out point ( ] )"));
681 }
682 EditOutPoint::~EditOutPoint()
683 {
684 }
685 int EditOutPoint::handle_event()
686 {
687         panel->set_outpoint();
688         return 1;
689 }
690 int EditOutPoint::keypress_event()
691 {
692         if(get_keypress() == ']')
693         {
694                 panel->set_outpoint();
695                 return 1;
696         }
697         return 0;
698 }
699
700
701 EditNextLabel::EditNextLabel(MWindow *mwindow,
702         EditPanel *panel,
703         int x,
704         int y,
705         int is_mwindow)
706  : BC_Button(x, y, mwindow->theme->get_image_set("nextlabel"))
707 {
708         this->mwindow = mwindow;
709         this->panel = panel;
710         this->is_mwindow = is_mwindow;
711         set_tooltip(_("Next label ( ctrl -> )"));
712 }
713 EditNextLabel::~EditNextLabel()
714 {
715 }
716 int EditNextLabel::keypress_event()
717 {
718         if(get_keypress() == RIGHT && ctrl_down())
719                 return handle_event();
720         return 0;
721 }
722 int EditNextLabel::handle_event()
723 {
724         panel->next_label();
725         return 1;
726 }
727
728 EditPrevLabel::EditPrevLabel(MWindow *mwindow,
729         EditPanel *panel,
730         int x,
731         int y,
732         int is_mwindow)
733  : BC_Button(x, y, mwindow->theme->get_image_set("prevlabel"))
734 {
735         this->mwindow = mwindow;
736         this->panel = panel;
737         this->is_mwindow = is_mwindow;
738         set_tooltip(_("Previous label ( ctrl <- )"));
739 }
740 EditPrevLabel::~EditPrevLabel()
741 {
742 }
743 int EditPrevLabel::keypress_event()
744 {
745         if(get_keypress() == LEFT && ctrl_down())
746                 return handle_event();
747         return 0;
748 }
749 int EditPrevLabel::handle_event()
750 {
751         panel->prev_label();
752         return 1;
753 }
754
755
756
757 EditNextEdit::EditNextEdit(MWindow *mwindow,
758         EditPanel *panel,
759         int x,
760         int y,
761         int is_mwindow)
762  : BC_Button(x, y, mwindow->theme->get_image_set("nextedit"))
763 {
764         this->mwindow = mwindow;
765         this->panel = panel;
766         this->is_mwindow = is_mwindow;
767         set_tooltip(_("Next edit ( alt -> )"));
768 }
769 EditNextEdit::~EditNextEdit()
770 {
771 }
772 int EditNextEdit::keypress_event()
773 {
774         if(get_keypress() == RIGHT && alt_down())
775                 return handle_event();
776         return 0;
777 }
778 int EditNextEdit::handle_event()
779 {
780         panel->next_edit();
781         return 1;
782 }
783
784 EditPrevEdit::EditPrevEdit(MWindow *mwindow,
785         EditPanel *panel,
786         int x,
787         int y,
788         int is_mwindow)
789  : BC_Button(x, y, mwindow->theme->get_image_set("prevedit"))
790 {
791         this->mwindow = mwindow;
792         this->panel = panel;
793         this->is_mwindow = is_mwindow;
794         set_tooltip(_("Previous edit (alt <- )"));
795 }
796 EditPrevEdit::~EditPrevEdit()
797 {
798 }
799 int EditPrevEdit::keypress_event()
800 {
801         if(get_keypress() == LEFT && alt_down())
802                 return handle_event();
803         return 0;
804 }
805 int EditPrevEdit::handle_event()
806 {
807         panel->prev_edit();
808         return 1;
809 }
810
811
812
813 EditLift::EditLift(MWindow *mwindow, EditPanel *panel, int x, int y)
814  : BC_Button(x, y, mwindow->theme->lift_data)
815 {
816         this->mwindow = mwindow;
817         this->panel = panel;
818         set_tooltip(_("Lift"));
819 }
820 EditLift::~EditLift()
821 {
822 }
823 int EditLift::handle_event()
824 {
825         return 1;
826 }
827
828 EditOverwrite::EditOverwrite(MWindow *mwindow, EditPanel *panel, int x, int y)
829  : BC_Button(x, y, mwindow->theme->overwrite_data)
830 {
831         this->mwindow = mwindow;
832         this->panel = panel;
833         set_tooltip(_("Overwrite ( b )"));
834 }
835 EditOverwrite::~EditOverwrite()
836 {
837 }
838 int EditOverwrite::handle_event()
839 {
840         panel->overwrite_selection();
841         return 1;
842 }
843 int EditOverwrite::keypress_event()
844 {
845         if(get_keypress() == 'b')
846         {
847                 handle_event();
848                 return 1;
849         }
850         return 0;
851 }
852
853 EditExtract::EditExtract(MWindow *mwindow, EditPanel *panel, int x, int y)
854  : BC_Button(x, y, mwindow->theme->extract_data)
855 {
856         this->mwindow = mwindow;
857         this->panel = panel;
858         set_tooltip(_("Extract"));
859 }
860 EditExtract::~EditExtract()
861 {
862 }
863 int EditExtract::handle_event()
864 {
865 //      mwindow->extract_selection();
866         return 1;
867 }
868
869 EditToClip::EditToClip(MWindow *mwindow, EditPanel *panel, int x, int y)
870  : BC_Button(x, y, mwindow->theme->get_image_set("toclip"))
871 {
872         this->mwindow = mwindow;
873         this->panel = panel;
874         set_tooltip(_("To clip ( i )"));
875 }
876 EditToClip::~EditToClip()
877 {
878 }
879 int EditToClip::handle_event()
880 {
881         panel->to_clip();
882         return 1;
883 }
884
885 int EditToClip::keypress_event()
886 {
887         if(get_keypress() == 'i')
888         {
889                 handle_event();
890                 return 1;
891         }
892         return 0;
893 }
894
895 EditManualGoto::EditManualGoto(MWindow *mwindow, EditPanel *panel, int x, int y)
896  : BC_Button(x, y, mwindow->theme->get_image_set("goto"))
897 {
898         this->mwindow = mwindow;
899         this->panel = panel;
900         mangoto = new ManualGoto(mwindow, panel);
901         set_tooltip(_("Manual goto ( g )"));
902 }
903 EditManualGoto::~EditManualGoto()
904 {
905         delete mangoto;
906 }
907 int EditManualGoto::handle_event()
908 {
909         mangoto->start();
910         return 1;
911 }
912
913 int EditManualGoto::keypress_event()
914 {
915         if(get_keypress() == 'g')
916         {
917                 handle_event();
918                 return 1;
919         }
920         return 0;
921 }
922
923
924 EditSplice::EditSplice(MWindow *mwindow, EditPanel *panel, int x, int y)
925  : BC_Button(x, y, mwindow->theme->splice_data)
926 {
927         this->mwindow = mwindow;
928         this->panel = panel;
929         set_tooltip(_("Splice ( v )"));
930 }
931 EditSplice::~EditSplice()
932 {
933 }
934 int EditSplice::handle_event()
935 {
936         panel->splice_selection();
937         return 1;
938 }
939 int EditSplice::keypress_event()
940 {
941         if(get_keypress() == 'v')
942         {
943                 handle_event();
944                 return 1;
945         }
946         return 0;
947 }
948
949 EditCut::EditCut(MWindow *mwindow, EditPanel *panel, int x, int y)
950  : BC_Button(x, y, mwindow->theme->get_image_set("cut"))
951 {
952         this->mwindow = mwindow;
953         this->panel = panel;
954         set_tooltip(_("Cut ( x )"));
955 }
956 EditCut::~EditCut()
957 {
958 }
959 int EditCut::keypress_event()
960 {
961         if(get_keypress() == 'x')
962                 return handle_event();
963         return 0;
964 }
965
966 int EditCut::handle_event()
967 {
968         int have_mwindow_lock = mwindow->gui->get_window_lock();
969         if(!have_mwindow_lock)
970                 mwindow->gui->lock_window("EditCut::handle_event");
971
972         mwindow->cut();
973
974         if(!have_mwindow_lock)
975                 mwindow->gui->unlock_window();
976         return 1;
977 }
978
979 EditCommercial::EditCommercial(MWindow *mwindow, EditPanel *panel, int x, int y)
980  : BC_Button(x, y, mwindow->theme->get_image_set("commercial"))
981 {
982         this->mwindow = mwindow;
983         this->panel = panel;
984         set_tooltip(_("Commercial ( shift X )"));
985 }
986 EditCommercial::~EditCommercial()
987 {
988 }
989 int EditCommercial::keypress_event()
990 {
991         if(get_keypress() == 'X')
992                 return handle_event();
993         return 0;
994 }
995
996 int EditCommercial::handle_event()
997 {
998         int have_mwindow_lock = mwindow->gui->get_window_lock();
999         if(have_mwindow_lock)
1000                 mwindow->gui->unlock_window();
1001         mwindow->commit_commercial();
1002         if( !mwindow->put_commercial() ) {
1003                 mwindow->gui->lock_window("EditCommercial::handle_event 1");
1004                 mwindow->cut();
1005                 if(!have_mwindow_lock)
1006                         mwindow->gui->unlock_window();
1007                 mwindow->activate_commercial();
1008                 return 1;
1009         }
1010         mwindow->undo_commercial();
1011         if(have_mwindow_lock)
1012                 mwindow->gui->lock_window("EditCommercial::handle_event 2");
1013         return 1;
1014 }
1015
1016 EditCopy::EditCopy(MWindow *mwindow, EditPanel *panel, int x, int y)
1017  : BC_Button(x, y, mwindow->theme->get_image_set("copy"))
1018 {
1019         this->mwindow = mwindow;
1020         this->panel = panel;
1021         set_tooltip(_("Copy ( c )"));
1022 }
1023 EditCopy::~EditCopy()
1024 {
1025 }
1026
1027 int EditCopy::keypress_event()
1028 {
1029         if(get_keypress() == 'c')
1030                 return handle_event();
1031         return 0;
1032 }
1033 int EditCopy::handle_event()
1034 {
1035         panel->copy_selection();
1036         return 1;
1037 }
1038
1039 EditAppend::EditAppend(MWindow *mwindow, EditPanel *panel, int x, int y)
1040  : BC_Button(x, y, mwindow->theme->append_data)
1041 {
1042         this->mwindow = mwindow;
1043         this->panel = panel;
1044         set_tooltip(_("Append to end of track"));
1045 }
1046 EditAppend::~EditAppend()
1047 {
1048 }
1049
1050
1051 int EditAppend::handle_event()
1052 {
1053         return 1;
1054 }
1055
1056
1057 EditInsert::EditInsert(MWindow *mwindow, EditPanel *panel, int x, int y)
1058  : BC_Button(x, y, mwindow->theme->insert_data)
1059 {
1060         this->mwindow = mwindow;
1061         this->panel = panel;
1062         set_tooltip(_("Insert before beginning of track"));
1063 }
1064 EditInsert::~EditInsert()
1065 {
1066 }
1067
1068
1069 int EditInsert::handle_event()
1070 {
1071
1072         return 1;
1073 }
1074
1075
1076 EditPaste::EditPaste(MWindow *mwindow, EditPanel *panel, int x, int y)
1077  : BC_Button(x, y, mwindow->theme->get_image_set("paste"))
1078 {
1079         this->mwindow = mwindow;
1080         this->panel = panel;
1081         set_tooltip(_("Paste ( v )"));
1082 }
1083 EditPaste::~EditPaste()
1084 {
1085 }
1086
1087 int EditPaste::keypress_event()
1088 {
1089         if(get_keypress() == 'v')
1090                 return handle_event();
1091         return 0;
1092 }
1093 int EditPaste::handle_event()
1094 {
1095         int have_mwindow_lock = mwindow->gui->get_window_lock();
1096         if(!have_mwindow_lock)
1097                 mwindow->gui->lock_window("EditPaste::handle_event");
1098
1099         mwindow->paste();
1100
1101         if(!have_mwindow_lock)
1102                 mwindow->gui->unlock_window();
1103         return 1;
1104 }
1105
1106
1107
1108 EditTransition::EditTransition(MWindow *mwindow, EditPanel *panel, int x, int y)
1109  : BC_Button(x, y, mwindow->theme->transition_data)
1110 {
1111         this->mwindow = mwindow;
1112         this->panel = panel;
1113         set_tooltip(_("Set transition"));
1114 }
1115 EditTransition::~EditTransition()
1116 {
1117 }
1118 int EditTransition::handle_event()
1119 {
1120         return 1;
1121 }
1122
1123 EditPresentation::EditPresentation(MWindow *mwindow, EditPanel *panel, int x, int y)
1124  : BC_Button(x, y, mwindow->theme->presentation_data)
1125 {
1126         this->mwindow = mwindow;
1127         this->panel = panel;
1128         set_tooltip(_("Set presentation up to current position"));
1129 }
1130 EditPresentation::~EditPresentation()
1131 {
1132 }
1133 int EditPresentation::handle_event()
1134 {
1135         return 1;
1136 }
1137
1138 EditUndo::EditUndo(MWindow *mwindow, EditPanel *panel, int x, int y)
1139  : BC_Button(x, y, mwindow->theme->get_image_set("undo"))
1140 {
1141         this->mwindow = mwindow;
1142         this->panel = panel;
1143         set_tooltip(_("Undo ( z )"));
1144 }
1145 EditUndo::~EditUndo()
1146 {
1147 }
1148 int EditUndo::keypress_event()
1149 {
1150         if(get_keypress() == 'z')
1151                 return handle_event();
1152         return 0;
1153 }
1154 int EditUndo::handle_event()
1155 {
1156         mwindow->undo_entry(panel->subwindow);
1157         return 1;
1158 }
1159
1160 EditRedo::EditRedo(MWindow *mwindow, EditPanel *panel, int x, int y)
1161  : BC_Button(x, y, mwindow->theme->get_image_set("redo"))
1162 {
1163         this->mwindow = mwindow;
1164         this->panel = panel;
1165         set_tooltip(_("Redo ( shift Z )"));
1166 }
1167 EditRedo::~EditRedo()
1168 {
1169 }
1170 int EditRedo::keypress_event()
1171 {
1172         if(get_keypress() == 'Z')
1173                 return handle_event();
1174         return 0;
1175 }
1176 int EditRedo::handle_event()
1177 {
1178         mwindow->redo_entry(panel->subwindow);
1179         return 1;
1180 };
1181
1182
1183
1184
1185
1186 EditLabelbutton::EditLabelbutton(MWindow *mwindow, EditPanel *panel, int x, int y)
1187  : BC_Button(x, y, mwindow->theme->get_image_set("labelbutton"))
1188 {
1189         this->mwindow = mwindow;
1190         this->panel = panel;
1191         set_tooltip(_("Toggle label at current position ( l )"));
1192 }
1193
1194 EditLabelbutton::~EditLabelbutton()
1195 {
1196 }
1197 int EditLabelbutton::keypress_event()
1198 {
1199         if(get_keypress() == 'l')
1200                 return handle_event();
1201         return 0;
1202 }
1203 int EditLabelbutton::handle_event()
1204 {
1205         panel->toggle_label();
1206         return 1;
1207 }
1208
1209
1210
1211
1212
1213
1214
1215 EditFit::EditFit(MWindow *mwindow, EditPanel *panel, int x, int y)
1216  : BC_Button(x, y, mwindow->theme->get_image_set("fit"))
1217 {
1218         this->mwindow = mwindow;
1219         this->panel = panel;
1220         set_tooltip(_("Fit selection to display ( f )"));
1221 }
1222 EditFit::~EditFit()
1223 {
1224 }
1225 int EditFit::keypress_event()
1226 {
1227         if(!alt_down() && get_keypress() == 'f')
1228         {
1229                 handle_event();
1230                 return 1;
1231         }
1232         return 0;
1233 }
1234 int EditFit::handle_event()
1235 {
1236         mwindow->fit_selection();
1237         return 1;
1238 }
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248 EditFitAutos::EditFitAutos(MWindow *mwindow, EditPanel *panel, int x, int y)
1249  : BC_Button(x, y, mwindow->theme->get_image_set("fitautos"))
1250 {
1251         this->mwindow = mwindow;
1252         this->panel = panel;
1253         set_tooltip(_("Fit all autos to display ( Alt + f )"));
1254 }
1255 EditFitAutos::~EditFitAutos()
1256 {
1257 }
1258 int EditFitAutos::keypress_event()
1259 {
1260         if(!ctrl_down() && alt_down() && get_keypress() == 'f')
1261         {
1262                 mwindow->fit_autos(1);
1263                 return 1;
1264         }
1265         if(ctrl_down() && alt_down() && get_keypress() == 'f')
1266         {
1267                 mwindow->fit_autos(0);
1268                 return 1;
1269         }
1270         return 0;
1271 }
1272 int EditFitAutos::handle_event()
1273 {
1274         mwindow->fit_autos(1);
1275         return 1;
1276 }
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290 ArrowButton::ArrowButton(MWindow *mwindow, EditPanel *panel, int x, int y)
1291  : BC_Toggle(x,
1292         y,
1293         mwindow->theme->get_image_set("arrow"),
1294         mwindow->edl->session->editing_mode == EDITING_ARROW,
1295         "",
1296         0,
1297         0,
1298         0)
1299 {
1300         this->mwindow = mwindow;
1301         this->panel = panel;
1302         set_tooltip(_("Drag and drop editing mode"));
1303 }
1304
1305 int ArrowButton::handle_event()
1306 {
1307         update(1);
1308         panel->ibeam->update(0);
1309         mwindow->set_editing_mode(EDITING_ARROW,
1310                 !panel->is_mwindow,
1311                 panel->is_mwindow);
1312 // Nothing after this
1313         return 1;
1314 }
1315
1316
1317 IBeamButton::IBeamButton(MWindow *mwindow, EditPanel *panel, int x, int y)
1318  : BC_Toggle(x,
1319         y,
1320         mwindow->theme->get_image_set("ibeam"),
1321         mwindow->edl->session->editing_mode == EDITING_IBEAM,
1322         "",
1323         0,
1324         0,
1325         0)
1326 {
1327         this->mwindow = mwindow;
1328         this->panel = panel;
1329         set_tooltip(_("Cut and paste editing mode"));
1330 }
1331
1332 int IBeamButton::handle_event()
1333 {
1334         update(1);
1335         panel->arrow->update(0);
1336         mwindow->set_editing_mode(EDITING_IBEAM,
1337                 !panel->is_mwindow,
1338                 panel->is_mwindow);
1339 // Nothing after this
1340         return 1;
1341 }
1342
1343 KeyFrameButton::KeyFrameButton(MWindow *mwindow, EditPanel *panel, int x, int y)
1344  : BC_Toggle(x,
1345         y,
1346         mwindow->theme->get_image_set("autokeyframe"),
1347         mwindow->edl->session->auto_keyframes,
1348         "",
1349         0,
1350         0,
1351         0)
1352 {
1353         this->mwindow = mwindow;
1354         this->panel = panel;
1355         set_tooltip(_("Generate keyframes while tweeking"));
1356 }
1357
1358 int KeyFrameButton::handle_event()
1359 {
1360         mwindow->set_auto_keyframes(get_value(),
1361                 !panel->is_mwindow,
1362                 panel->is_mwindow);
1363         return 1;
1364 }
1365
1366
1367 LockLabelsButton::LockLabelsButton(MWindow *mwindow, int x, int y)
1368  : BC_Toggle(x,
1369         y,
1370         mwindow->theme->get_image_set("locklabels"),
1371         mwindow->edl->session->labels_follow_edits,
1372         "",
1373         0,
1374         0,
1375         0)
1376 {
1377         this->mwindow = mwindow;
1378         set_tooltip(_("Lock labels from moving"));
1379 }
1380
1381 int LockLabelsButton::handle_event()
1382 {
1383         mwindow->set_labels_follow_edits(get_value());
1384         return 1;
1385 }
1386