4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
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.
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.
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
22 #include "automation.h"
23 #include "bcsignals.h"
24 #include "cplayback.h"
27 #include "edlsession.h"
32 #include "localsession.h"
33 #include "mainsession.h"
36 #include "mwindowgui.h"
39 #include "playbackengine.h"
42 #include "trackcanvas.h"
44 #include "transportque.h"
49 PatchGUI::PatchGUI(MWindow *mwindow,
55 this->mwindow = mwindow;
56 this->patchbay = patchbay;
71 if(track) track_id = track->get_id();
76 if(title) delete title;
77 if(record) delete record;
79 // if(automate) delete automate;
83 if(expand) delete expand;
84 if(nudge) delete nudge;
87 void PatchGUI::create_objects()
92 int PatchGUI::reposition(int x, int y)
98 if(x != this->x || y != this->y)
105 TRACE("PatchGUI::reposition 1\n");
106 title->reposition_window(title->get_x(), y1 + y, 0);
107 TRACE("PatchGUI::reposition 2\n");
109 y1 += mwindow->theme->title_h;
113 TRACE("PatchGUI::reposition 3\n");
114 play->reposition_window(play->get_x(), y1 + y);
116 TRACE("PatchGUI::reposition 4\n");
117 record->reposition_window(record->get_x(), y1 + y);
118 x1 += record->get_w();
119 TRACE("PatchGUI::reposition 5\n");
120 // automate->reposition_window(x1, y1 + y);
121 // x1 += automate->get_w();
122 gang->reposition_window(gang->get_x(), y1 + y);
124 TRACE("PatchGUI::reposition 6\n");
125 draw->reposition_window(draw->get_x(), y1 + y);
127 TRACE("PatchGUI::reposition 7\n");
128 mute->reposition_window(mute->get_x(), y1 + y);
130 TRACE("PatchGUI::reposition 8\n");
134 TRACE("PatchGUI::reposition 9\n");
135 // VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
136 // int x = patchbay->get_w() - 10 - expandpatch_data[0]->get_w();
137 expand->reposition_window(
140 TRACE("PatchGUI::reposition 10\n");
141 x1 += expand->get_w();
142 TRACE("PatchGUI::reposition 11\n");
145 y1 += mwindow->theme->play_h;
149 y1 += mwindow->theme->title_h;
150 y1 += mwindow->theme->play_h;
156 int PatchGUI::update(int x, int y)
158 //TRACE("PatchGUI::update 1");
160 //TRACE("PatchGUI::update 10");
162 int h = track->vertical_span(mwindow->theme);
165 //printf("PatchGUI::update 10\n");
176 title->update(track->title);
182 patchbay->add_subwindow(title = new TitlePatch(mwindow, this, x1 + x, y1 + y));
184 y1 += mwindow->theme->title_h;
188 if(h - y1 < mwindow->theme->play_h)
190 delete play; play = 0;
191 delete record; record = 0;
192 delete gang; gang = 0;
193 delete draw; draw = 0;
194 delete mute; mute = 0;
195 delete expand; expand = 0;
199 play->update(track->play);
200 record->update(track->record);
201 gang->update(track->gang);
202 draw->update(track->draw);
203 mute->update(mute->get_keyframe(mwindow, this)->value);
204 expand->update(track->expand_view);
208 if(h - y1 >= mwindow->theme->play_h)
210 patchbay->add_subwindow(play = new PlayPatch(mwindow, this, x1 + x, y1 + y));
211 //printf("PatchGUI::update %d %d\n", __LINE__, play->get_h());
213 patchbay->add_subwindow(record = new RecordPatch(mwindow, this, x1 + x, y1 + y));
214 x1 += record->get_w();
215 patchbay->add_subwindow(gang = new GangPatch(mwindow, this, x1 + x, y1 + y));
217 patchbay->add_subwindow(draw = new DrawPatch(mwindow, this, x1 + x, y1 + y));
219 patchbay->add_subwindow(mute = new MutePatch(mwindow, this, x1 + x, y1 + y));
222 VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
223 patchbay->add_subwindow(expand = new ExpandPatch(mwindow,
225 patchbay->get_w() - 10 - expandpatch_data[0]->get_w(),
227 x1 += expand->get_w();
229 y1 += mwindow->theme->play_h;
236 void PatchGUI::toggle_behavior(int type,
241 if(toggle->shift_down())
243 int total_selected = mwindow->edl->tracks->total_of(type);
245 // nothing previously selected
246 if(total_selected == 0)
248 mwindow->edl->tracks->select_all(type,
252 if(total_selected == 1)
254 // this patch was previously the only one on
257 mwindow->edl->tracks->select_all(type,
260 // another patch was previously the only one on
263 mwindow->edl->tracks->select_all(type,
269 if(total_selected > 1)
271 mwindow->edl->tracks->select_all(type,
275 toggle->set_value(*output);
277 patchbay->drag_operation = type;
278 patchbay->new_status = 1;
283 // Select + drag behavior
284 patchbay->drag_operation = type;
285 patchbay->new_status = value;
291 mwindow->gui->unlock_window();
292 mwindow->restart_brender();
293 mwindow->sync_parameters(CHANGE_EDL);
294 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
298 mwindow->gui->unlock_window();
299 mwindow->restart_brender();
300 mwindow->sync_parameters(CHANGE_PARAMS);
301 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
304 // Update affected tracks in cwindow
306 mwindow->cwindow->update(0, 1, 1);
313 mwindow->gui->update(0, 1, 0, 0, 0, 0, 0);
321 mwindow->gui->update_patchbay();
325 char* PatchGUI::calculate_nudge_text(int *changed)
327 if(changed) *changed = 0;
328 if(track->edl->session->nudge_seconds)
330 sprintf(string_return, "%.4f", track->from_units(track->nudge));
331 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
336 sprintf(string_return, "" _LD "", track->nudge);
337 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
340 return string_return;
344 int64_t PatchGUI::calculate_nudge(const char *string)
346 if(mwindow->edl->session->nudge_seconds)
349 sscanf(string, "%f", &result);
350 return track->to_units(result, 0);
355 sscanf(string, "" _LD "", &temp);
371 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
374 mwindow->theme->get_image_set("playpatch_data"),
381 this->mwindow = mwindow;
383 set_tooltip(_("Play track"));
387 int PlayPatch::button_press_event()
389 if(is_event_win() && get_buttonpress() == 1)
391 mwindow->undo->update_undo_before();
392 set_status(BC_Toggle::TOGGLE_DOWN);
393 update(!get_value());
394 patch->toggle_behavior(Tracks::PLAY,
397 &patch->track->play);
403 int PlayPatch::button_release_event()
405 int result = BC_Toggle::button_release_event();
406 if(patch->patchbay->drag_operation == Tracks::PLAY)
408 mwindow->undo->update_undo_after(_("play patch"), LOAD_PATCHES);
409 patch->patchbay->drag_operation = Tracks::NONE;
424 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
427 mwindow->theme->get_image_set("recordpatch_data"),
428 patch->track->record,
434 this->mwindow = mwindow;
436 set_tooltip(_("Arm track"));
440 int RecordPatch::button_press_event()
442 if(is_event_win() && get_buttonpress() == 1)
444 mwindow->undo->update_undo_before();
445 set_status(BC_Toggle::TOGGLE_DOWN);
446 update(!get_value());
447 patch->toggle_behavior(Tracks::RECORD,
450 &patch->track->record);
456 int RecordPatch::button_release_event()
458 int result = BC_Toggle::button_release_event();
459 if(patch->patchbay->drag_operation == Tracks::RECORD)
461 mwindow->undo->update_undo_after(_("record patch"), LOAD_PATCHES);
462 patch->patchbay->drag_operation = Tracks::NONE;
477 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
479 mwindow->theme->get_image_set("gangpatch_data"),
486 this->mwindow = mwindow;
488 set_tooltip(_("Gang faders"));
492 int GangPatch::button_press_event()
494 if(is_event_win() && get_buttonpress() == 1)
496 mwindow->undo->update_undo_before();
497 set_status(BC_Toggle::TOGGLE_DOWN);
498 update(!get_value());
499 patch->toggle_behavior(Tracks::GANG,
502 &patch->track->gang);
508 int GangPatch::button_release_event()
510 int result = BC_Toggle::button_release_event();
511 if(patch->patchbay->drag_operation == Tracks::GANG)
513 mwindow->undo->update_undo_after(_("gang patch"), LOAD_PATCHES);
514 patch->patchbay->drag_operation = Tracks::NONE;
529 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
531 mwindow->theme->get_image_set("drawpatch_data"),
538 this->mwindow = mwindow;
540 set_tooltip(_("Draw media"));
544 int DrawPatch::button_press_event()
546 if(is_event_win() && get_buttonpress() == 1)
548 mwindow->undo->update_undo_before();
549 set_status(BC_Toggle::TOGGLE_DOWN);
550 update(!get_value());
551 patch->toggle_behavior(Tracks::DRAW,
554 &patch->track->draw);
560 int DrawPatch::button_release_event()
562 int result = BC_Toggle::button_release_event();
563 if(patch->patchbay->drag_operation == Tracks::DRAW)
565 mwindow->undo->update_undo_after(_("draw patch"), LOAD_PATCHES);
566 patch->patchbay->drag_operation = Tracks::NONE;
580 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
582 mwindow->theme->get_image_set("mutepatch_data"),
583 get_keyframe(mwindow, patch)->value,
589 this->mwindow = mwindow;
591 set_tooltip(_("Don't send to output"));
595 int MutePatch::button_press_event()
597 if(is_event_win() && get_buttonpress() == 1)
599 mwindow->undo->update_undo_before();
600 set_status(BC_Toggle::TOGGLE_DOWN);
601 update(!get_value());
603 double position = mwindow->edl->local_session->get_selectionstart(1);
604 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
607 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
608 current->value = get_value();
610 patch->toggle_behavior(Tracks::MUTE,
617 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
619 mwindow->gui->draw_overlays(1);
626 int MutePatch::button_release_event()
628 int result = BC_Toggle::button_release_event();
629 if(patch->patchbay->drag_operation == Tracks::MUTE)
631 mwindow->undo->update_undo_after(_("mute patch"), LOAD_PATCHES);
632 patch->patchbay->drag_operation = Tracks::NONE;
637 IntAuto* MutePatch::get_keyframe(MWindow *mwindow, PatchGUI *patch)
640 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
641 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
642 unit_position = patch->track->to_units(unit_position, 0);
643 return (IntAuto*)patch->track->automation->autos[AUTOMATION_MUTE]->get_prev_auto(
644 (int64_t)unit_position,
660 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
663 mwindow->theme->get_image_set("expandpatch_data"),
664 patch->track->expand_view,
670 this->mwindow = mwindow;
675 int ExpandPatch::button_press_event()
677 if(is_event_win() && get_buttonpress() == 1)
679 mwindow->undo->update_undo_before();
680 set_status(BC_Toggle::TOGGLE_DOWN);
681 update(!get_value());
682 patch->toggle_behavior(Tracks::EXPAND,
685 &patch->track->expand_view);
686 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
687 mwindow->gui->draw_trackmovement();
693 int ExpandPatch::button_release_event()
695 int result = BC_Toggle::button_release_event();
696 if(patch->patchbay->drag_operation == Tracks::EXPAND)
698 mwindow->undo->update_undo_after(_("expand patch"), LOAD_PATCHES);
699 patch->patchbay->drag_operation = Tracks::NONE;
708 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
711 patch->patchbay->get_w() - 10,
715 this->mwindow = mwindow;
719 int TitlePatch::handle_event()
721 mwindow->undo->update_undo_before(_("track title"), this);
722 strcpy(patch->track->title, get_text());
723 mwindow->update_plugin_titles();
724 mwindow->gui->draw_overlays(1);
725 mwindow->undo->update_undo_after(_("track title"), LOAD_PATCHES);
737 NudgePatch::NudgePatch(MWindow *mwindow,
746 patch->calculate_nudge_text(0))
748 this->mwindow = mwindow;
750 set_tooltip(_("Nudge"));
753 int NudgePatch::handle_event()
755 set_value(patch->calculate_nudge(get_text()));
759 void NudgePatch::set_value(int64_t value)
761 mwindow->undo->update_undo_before(_("nudge"), this);
762 patch->track->nudge = value;
764 if(patch->track->gang && patch->track->record)
765 patch->patchbay->synchronize_nudge(patch->track->nudge, patch->track);
767 mwindow->undo->update_undo_after(_("nudge"), LOAD_PATCHES);
769 mwindow->gui->unlock_window();
770 if(patch->track->data_type == TRACK_VIDEO)
771 mwindow->restart_brender();
772 mwindow->sync_parameters(CHANGE_PARAMS);
773 mwindow->gui->lock_window("NudgePatch::handle_event 2");
775 mwindow->session->changes_made = 1;
779 int NudgePatch::button_press_event()
783 if(is_event_win() && cursor_inside())
785 if(get_buttonpress() == 4)
787 int value = patch->calculate_nudge(get_text());
788 value += calculate_increment();
794 if(get_buttonpress() == 5)
796 int value = patch->calculate_nudge(get_text());
797 value -= calculate_increment();
803 if(get_buttonpress() == 3)
805 patch->patchbay->nudge_popup->activate_menu(patch);
811 return BC_TextBox::button_press_event();
816 int64_t NudgePatch::calculate_increment()
818 if(patch->track->data_type == TRACK_AUDIO)
820 return (int64_t)ceil(patch->track->edl->session->sample_rate / 10);
824 return (int64_t)ceil(1.0 / patch->track->edl->session->frame_rate);
828 void NudgePatch::update()
831 char *string = patch->calculate_nudge_text(&changed);
833 BC_TextBox::update(string);