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);
302 mwindow->gui->update(0, 1, 0, 0, 0, 0, 0);
306 mwindow->undo->update_undo(_("expand patch"), LOAD_PATCHES);
312 char* PatchGUI::calculate_nudge_text(int *changed)
314 if(changed) *changed = 0;
315 if(track->edl->session->nudge_seconds)
317 sprintf(string_return, "%.4f", track->from_units(track->nudge));
318 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
323 sprintf(string_return, "%d", track->nudge);
324 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
327 return string_return;
331 int64_t PatchGUI::calculate_nudge(char *string)
333 if(mwindow->edl->session->nudge_seconds)
336 sscanf(string, "%f", &result);
337 return track->to_units(result, 0);
342 sscanf(string, "%lld", &temp);
358 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
361 mwindow->theme->get_image_set("playpatch_data"),
368 this->mwindow = mwindow;
370 set_tooltip(_("Play track"));
374 int PlayPatch::button_press_event()
376 if(is_event_win() && get_buttonpress() == 1)
378 set_status(BC_Toggle::TOGGLE_DOWN);
379 update(!get_value());
380 patch->toggle_behavior(Tracks::PLAY,
383 &patch->track->play);
389 int PlayPatch::button_release_event()
391 int result = BC_Toggle::button_release_event();
392 if(patch->patchbay->drag_operation != Tracks::NONE)
394 patch->patchbay->drag_operation = Tracks::NONE;
409 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
412 mwindow->theme->get_image_set("recordpatch_data"),
413 patch->track->record,
419 this->mwindow = mwindow;
421 set_tooltip(_("Arm track"));
425 int RecordPatch::button_press_event()
427 if(is_event_win() && get_buttonpress() == 1)
429 set_status(BC_Toggle::TOGGLE_DOWN);
430 update(!get_value());
431 patch->toggle_behavior(Tracks::RECORD,
434 &patch->track->record);
440 int RecordPatch::button_release_event()
442 int result = BC_Toggle::button_release_event();
443 if(patch->patchbay->drag_operation != Tracks::NONE)
445 patch->patchbay->drag_operation = Tracks::NONE;
460 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
462 mwindow->theme->get_image_set("gangpatch_data"),
469 this->mwindow = mwindow;
471 set_tooltip(_("Gang faders"));
475 int GangPatch::button_press_event()
477 if(is_event_win() && get_buttonpress() == 1)
479 set_status(BC_Toggle::TOGGLE_DOWN);
480 update(!get_value());
481 patch->toggle_behavior(Tracks::GANG,
484 &patch->track->gang);
490 int GangPatch::button_release_event()
492 int result = BC_Toggle::button_release_event();
493 if(patch->patchbay->drag_operation != Tracks::NONE)
495 patch->patchbay->drag_operation = Tracks::NONE;
510 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
512 mwindow->theme->get_image_set("drawpatch_data"),
519 this->mwindow = mwindow;
521 set_tooltip(_("Draw media"));
525 int DrawPatch::button_press_event()
527 if(is_event_win() && get_buttonpress() == 1)
529 set_status(BC_Toggle::TOGGLE_DOWN);
530 update(!get_value());
531 patch->toggle_behavior(Tracks::DRAW,
534 &patch->track->draw);
540 int DrawPatch::button_release_event()
542 int result = BC_Toggle::button_release_event();
543 if(patch->patchbay->drag_operation != Tracks::NONE)
545 patch->patchbay->drag_operation = Tracks::NONE;
559 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
561 mwindow->theme->get_image_set("mutepatch_data"),
562 get_keyframe(mwindow, patch)->value,
568 this->mwindow = mwindow;
570 set_tooltip(_("Don't send to output"));
574 int MutePatch::button_press_event()
576 if(is_event_win() && get_buttonpress() == 1)
578 set_status(BC_Toggle::TOGGLE_DOWN);
579 update(!get_value());
581 double position = mwindow->edl->local_session->get_selectionstart(1);
582 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
585 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
586 current->value = get_value();
588 patch->toggle_behavior(Tracks::MUTE,
594 mwindow->undo->update_undo(_("keyframe"), LOAD_AUTOMATION);
596 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
598 mwindow->gui->canvas->draw_overlays();
599 mwindow->gui->canvas->flash();
606 int MutePatch::button_release_event()
608 int result = BC_Toggle::button_release_event();
609 if(patch->patchbay->drag_operation != Tracks::NONE)
611 patch->patchbay->drag_operation = Tracks::NONE;
616 IntAuto* MutePatch::get_keyframe(MWindow *mwindow, PatchGUI *patch)
619 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
620 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
621 unit_position = patch->track->to_units(unit_position, 0);
622 return (IntAuto*)patch->track->automation->autos[AUTOMATION_MUTE]->get_prev_auto(
623 (int64_t)unit_position,
639 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
642 mwindow->theme->get_image_set("expandpatch_data"),
643 patch->track->expand_view,
649 this->mwindow = mwindow;
654 int ExpandPatch::button_press_event()
656 if(is_event_win() && get_buttonpress() == 1)
658 set_status(BC_Toggle::TOGGLE_DOWN);
659 update(!get_value());
660 patch->toggle_behavior(Tracks::EXPAND,
663 &patch->track->expand_view);
664 mwindow->trackmovement(mwindow->edl->local_session->track_start);
670 int ExpandPatch::button_release_event()
672 int result = BC_Toggle::button_release_event();
673 if(patch->patchbay->drag_operation != Tracks::NONE)
675 patch->patchbay->drag_operation = Tracks::NONE;
684 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
687 patch->patchbay->get_w() - 10,
691 this->mwindow = mwindow;
695 int TitlePatch::handle_event()
697 strcpy(patch->track->title, get_text());
698 mwindow->update_plugin_titles();
699 mwindow->gui->canvas->draw_overlays();
700 mwindow->gui->canvas->flash();
701 mwindow->undo->update_undo(_("track title"), LOAD_PATCHES);
713 NudgePatch::NudgePatch(MWindow *mwindow,
722 patch->calculate_nudge_text(0))
724 this->mwindow = mwindow;
726 set_tooltip(_("Nudge"));
729 int NudgePatch::handle_event()
731 set_value(patch->calculate_nudge(get_text()));
735 void NudgePatch::set_value(int64_t value)
737 patch->track->nudge = value;
739 if(patch->track->gang)
740 patch->patchbay->synchronize_nudge(patch->track->nudge, patch->track);
742 mwindow->undo->update_undo("nudge", LOAD_AUTOMATION, this);
744 mwindow->gui->unlock_window();
745 if(patch->track->data_type == TRACK_VIDEO)
746 mwindow->restart_brender();
747 mwindow->sync_parameters(CHANGE_PARAMS);
748 mwindow->gui->lock_window("NudgePatch::handle_event 2");
750 mwindow->session->changes_made = 1;
754 int NudgePatch::button_press_event()
758 if(is_event_win() && cursor_inside())
760 if(get_buttonpress() == 4)
762 int value = patch->calculate_nudge(get_text());
763 value += calculate_increment();
769 if(get_buttonpress() == 5)
771 int value = patch->calculate_nudge(get_text());
772 value -= calculate_increment();
778 if(get_buttonpress() == 3)
780 patch->patchbay->nudge_popup->activate_menu(patch);
786 return BC_TextBox::button_press_event();
791 int64_t NudgePatch::calculate_increment()
793 if(patch->track->data_type == TRACK_AUDIO)
795 return (int64_t)ceil(patch->track->edl->session->sample_rate / 10);
799 return (int64_t)ceil(1.0 / patch->track->edl->session->frame_rate);
803 void NudgePatch::update()
806 char *string = patch->calculate_nudge_text(&changed);
808 BC_TextBox::update(string);
817 // c-file-style: "linux"