1 #include "automation.h"
6 #include "edlsession.h"
10 #include "localsession.h"
11 #include "mainsession.h"
14 #include "mwindowgui.h"
17 #include "playbackengine.h"
20 #include "trackcanvas.h"
22 #include "transportque.h"
27 PatchGUI::PatchGUI(MWindow *mwindow,
33 this->mwindow = mwindow;
34 this->patchbay = patchbay;
49 if(track) track_id = track->get_id();
54 if(title) delete title;
55 if(record) delete record;
57 // if(automate) delete automate;
61 if(expand) delete expand;
62 if(nudge) delete nudge;
65 int PatchGUI::create_objects()
70 int PatchGUI::reposition(int x, int y)
76 if(x != this->x || y != this->y)
83 TRACE("PatchGUI::reposition 1\n");
84 title->reposition_window(x1, y1 + y);
85 TRACE("PatchGUI::reposition 2\n");
87 y1 += mwindow->theme->title_h;
91 TRACE("PatchGUI::reposition 3\n");
92 play->reposition_window(x1, y1 + y);
94 TRACE("PatchGUI::reposition 4\n");
95 record->reposition_window(x1, y1 + y);
96 x1 += record->get_w();
97 TRACE("PatchGUI::reposition 5\n");
98 // automate->reposition_window(x1, y1 + y);
99 // x1 += automate->get_w();
100 gang->reposition_window(x1, y1 + y);
102 TRACE("PatchGUI::reposition 6\n");
103 draw->reposition_window(x1, y1 + y);
105 TRACE("PatchGUI::reposition 7\n");
106 mute->reposition_window(x1, y1 + y);
108 TRACE("PatchGUI::reposition 8\n");
112 TRACE("PatchGUI::reposition 9\n");
113 VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
114 expand->reposition_window(
115 patchbay->get_w() - 10 - expandpatch_data[0]->get_w(),
117 TRACE("PatchGUI::reposition 10\n");
118 x1 += expand->get_w();
119 TRACE("PatchGUI::reposition 11\n");
122 y1 += mwindow->theme->play_h;
126 y1 += mwindow->theme->title_h;
127 y1 += mwindow->theme->play_h;
133 int PatchGUI::update(int x, int y)
135 //TRACE("PatchGUI::update 1");
137 //TRACE("PatchGUI::update 10");
139 int h = track->vertical_span(mwindow->theme);
142 //printf("PatchGUI::update 10\n");
153 title->update(track->title);
159 patchbay->add_subwindow(title = new TitlePatch(mwindow, this, x1 + x, y1 + y));
161 y1 += mwindow->theme->title_h;
165 if(h - y1 < mwindow->theme->play_h)
181 play->update(track->play);
182 record->update(track->record);
183 gang->update(track->gang);
184 draw->update(track->draw);
185 mute->update(mute->get_keyframe(mwindow, this)->value);
186 expand->update(track->expand_view);
190 if(h - y1 >= mwindow->theme->play_h)
192 patchbay->add_subwindow(play = new PlayPatch(mwindow, this, x1 + x, y1 + y));
193 //printf("PatchGUI::update 1 %p %p\n", play, &play->status);
195 patchbay->add_subwindow(record = new RecordPatch(mwindow, this, x1 + x, y1 + y));
196 x1 += record->get_w();
197 patchbay->add_subwindow(gang = new GangPatch(mwindow, this, x1 + x, y1 + y));
199 patchbay->add_subwindow(draw = new DrawPatch(mwindow, this, x1 + x, y1 + y));
201 patchbay->add_subwindow(mute = new MutePatch(mwindow, this, x1 + x, y1 + y));
204 VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
205 patchbay->add_subwindow(expand = new ExpandPatch(mwindow,
207 patchbay->get_w() - 10 - expandpatch_data[0]->get_w(),
209 x1 += expand->get_w();
211 y1 += mwindow->theme->play_h;
218 void PatchGUI::toggle_behavior(int type,
223 if(toggle->shift_down())
225 int total_selected = mwindow->edl->tracks->total_of(type);
227 // nothing previously selected
228 if(total_selected == 0)
230 mwindow->edl->tracks->select_all(type,
234 if(total_selected == 1)
236 // this patch was previously the only one on
239 mwindow->edl->tracks->select_all(type,
242 // another patch was previously the only one on
245 mwindow->edl->tracks->select_all(type,
251 if(total_selected > 1)
253 mwindow->edl->tracks->select_all(type,
257 toggle->set_value(*output);
259 patchbay->drag_operation = type;
260 patchbay->new_status = 1;
261 patchbay->button_down = 1;
266 // Select + drag behavior
267 patchbay->drag_operation = type;
268 patchbay->new_status = value;
269 patchbay->button_down = 1;
275 mwindow->gui->unlock_window();
276 mwindow->restart_brender();
277 mwindow->sync_parameters(CHANGE_EDL);
278 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
279 mwindow->undo->update_undo(_("play patch"), LOAD_PATCHES);
283 mwindow->gui->unlock_window();
284 mwindow->restart_brender();
285 mwindow->sync_parameters(CHANGE_PARAMS);
286 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
287 mwindow->undo->update_undo(_("mute patch"), LOAD_PATCHES);
290 // Update affected tracks in cwindow
292 mwindow->cwindow->update(0, 1, 1);
293 mwindow->undo->update_undo(_("record patch"), LOAD_PATCHES);
297 mwindow->undo->update_undo(_("gang patch"), LOAD_PATCHES);
301 mwindow->undo->update_undo(_("draw patch"), LOAD_PATCHES);
305 mwindow->undo->update_undo(_("expand patch"), LOAD_PATCHES);
311 char* PatchGUI::calculate_nudge_text(int *changed)
313 if(changed) *changed = 0;
314 if(track->edl->session->nudge_seconds)
316 sprintf(string_return, "%.4f", track->from_units(track->nudge));
317 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
322 sprintf(string_return, "%d", track->nudge);
323 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
326 return string_return;
330 int64_t PatchGUI::calculate_nudge(char *string)
332 if(mwindow->edl->session->nudge_seconds)
335 sscanf(string, "%f", &result);
336 return track->to_units(result, 0);
341 sscanf(string, "%lld", &temp);
357 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
360 mwindow->theme->get_image_set("playpatch_data"),
367 this->mwindow = mwindow;
369 set_tooltip(_("Play track"));
373 int PlayPatch::button_press_event()
375 if(is_event_win() && get_buttonpress() == 1)
377 set_status(BC_Toggle::TOGGLE_DOWN);
378 update(!get_value());
379 patch->toggle_behavior(Tracks::PLAY,
382 &patch->track->play);
388 int PlayPatch::button_release_event()
390 int result = BC_Toggle::button_release_event();
391 if(patch->patchbay->drag_operation != Tracks::NONE)
393 patch->patchbay->drag_operation = Tracks::NONE;
408 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
411 mwindow->theme->get_image_set("recordpatch_data"),
412 patch->track->record,
418 this->mwindow = mwindow;
420 set_tooltip(_("Arm track"));
424 int RecordPatch::button_press_event()
426 if(is_event_win() && get_buttonpress() == 1)
428 set_status(BC_Toggle::TOGGLE_DOWN);
429 update(!get_value());
430 patch->toggle_behavior(Tracks::RECORD,
433 &patch->track->record);
439 int RecordPatch::button_release_event()
441 int result = BC_Toggle::button_release_event();
442 if(patch->patchbay->drag_operation != Tracks::NONE)
444 patch->patchbay->drag_operation = Tracks::NONE;
459 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
461 mwindow->theme->get_image_set("gangpatch_data"),
468 this->mwindow = mwindow;
470 set_tooltip(_("Gang faders"));
474 int GangPatch::button_press_event()
476 if(is_event_win() && get_buttonpress() == 1)
478 set_status(BC_Toggle::TOGGLE_DOWN);
479 update(!get_value());
480 patch->toggle_behavior(Tracks::GANG,
483 &patch->track->gang);
489 int GangPatch::button_release_event()
491 int result = BC_Toggle::button_release_event();
492 if(patch->patchbay->drag_operation != Tracks::NONE)
494 patch->patchbay->drag_operation = Tracks::NONE;
509 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
511 mwindow->theme->get_image_set("drawpatch_data"),
518 this->mwindow = mwindow;
520 set_tooltip(_("Draw media"));
524 int DrawPatch::button_press_event()
526 if(is_event_win() && get_buttonpress() == 1)
528 set_status(BC_Toggle::TOGGLE_DOWN);
529 update(!get_value());
530 patch->toggle_behavior(Tracks::DRAW,
533 &patch->track->draw);
539 int DrawPatch::button_release_event()
541 int result = BC_Toggle::button_release_event();
542 if(patch->patchbay->drag_operation != Tracks::NONE)
544 patch->patchbay->drag_operation = Tracks::NONE;
558 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
560 mwindow->theme->get_image_set("mutepatch_data"),
561 get_keyframe(mwindow, patch)->value,
567 this->mwindow = mwindow;
569 set_tooltip(_("Don't send to output"));
573 int MutePatch::button_press_event()
575 if(is_event_win() && get_buttonpress() == 1)
577 set_status(BC_Toggle::TOGGLE_DOWN);
578 update(!get_value());
580 double position = mwindow->edl->local_session->get_selectionstart(1);
581 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
584 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
585 current->value = get_value();
587 patch->toggle_behavior(Tracks::MUTE,
593 mwindow->undo->update_undo(_("keyframe"), LOAD_AUTOMATION);
595 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
597 mwindow->gui->canvas->draw_overlays();
598 mwindow->gui->canvas->flash();
605 int MutePatch::button_release_event()
607 int result = BC_Toggle::button_release_event();
608 if(patch->patchbay->drag_operation != Tracks::NONE)
610 patch->patchbay->drag_operation = Tracks::NONE;
615 IntAuto* MutePatch::get_keyframe(MWindow *mwindow, PatchGUI *patch)
618 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
619 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
620 unit_position = patch->track->to_units(unit_position, 0);
621 return (IntAuto*)patch->track->automation->autos[AUTOMATION_MUTE]->get_prev_auto(
622 (int64_t)unit_position,
638 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
641 mwindow->theme->get_image_set("expandpatch_data"),
642 patch->track->expand_view,
648 this->mwindow = mwindow;
653 int ExpandPatch::button_press_event()
655 if(is_event_win() && get_buttonpress() == 1)
657 set_status(BC_Toggle::TOGGLE_DOWN);
658 update(!get_value());
659 patch->toggle_behavior(Tracks::EXPAND,
662 &patch->track->expand_view);
663 mwindow->trackmovement(mwindow->edl->local_session->track_start);
669 int ExpandPatch::button_release_event()
671 int result = BC_Toggle::button_release_event();
672 if(patch->patchbay->drag_operation != Tracks::NONE)
674 patch->patchbay->drag_operation = Tracks::NONE;
683 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
686 patch->patchbay->get_w() - 10,
690 this->mwindow = mwindow;
694 int TitlePatch::handle_event()
696 strcpy(patch->track->title, get_text());
697 mwindow->update_plugin_titles();
698 mwindow->gui->canvas->draw_overlays();
699 mwindow->gui->canvas->flash();
700 mwindow->undo->update_undo(_("track title"), LOAD_PATCHES);
712 NudgePatch::NudgePatch(MWindow *mwindow,
721 patch->calculate_nudge_text(0))
723 this->mwindow = mwindow;
725 set_tooltip(_("Nudge"));
728 int NudgePatch::handle_event()
730 set_value(patch->calculate_nudge(get_text()));
734 void NudgePatch::set_value(int64_t value)
736 patch->track->nudge = value;
738 if(patch->track->gang)
739 patch->patchbay->synchronize_nudge(patch->track->nudge, patch->track);
741 mwindow->undo->update_undo("nudge", LOAD_AUTOMATION, this);
743 mwindow->gui->unlock_window();
744 if(patch->track->data_type == TRACK_VIDEO)
745 mwindow->restart_brender();
746 mwindow->sync_parameters(CHANGE_PARAMS);
747 mwindow->gui->lock_window("NudgePatch::handle_event 2");
749 mwindow->session->changes_made = 1;
753 int NudgePatch::button_press_event()
757 if(is_event_win() && cursor_inside())
759 if(get_buttonpress() == 4)
761 int value = patch->calculate_nudge(get_text());
762 value += calculate_increment();
768 if(get_buttonpress() == 5)
770 int value = patch->calculate_nudge(get_text());
771 value -= calculate_increment();
777 if(get_buttonpress() == 3)
779 patch->patchbay->nudge_popup->activate_menu(patch);
785 return BC_TextBox::button_press_event();
790 int64_t NudgePatch::calculate_increment()
792 if(patch->track->data_type == TRACK_AUDIO)
794 return (int64_t)ceil(patch->track->edl->session->sample_rate / 10);
798 return (int64_t)ceil(1.0 / patch->track->edl->session->frame_rate);
802 void NudgePatch::update()
805 char *string = patch->calculate_nudge_text(&changed);
807 BC_TextBox::update(string);