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 expand->reposition_window(
114 patchbay->get_w() - 10 - mwindow->theme->expandpatch_data[0]->get_w(),
116 TRACE("PatchGUI::reposition 10\n");
117 x1 += expand->get_w();
118 TRACE("PatchGUI::reposition 11\n");
121 y1 += mwindow->theme->play_h;
125 y1 += mwindow->theme->title_h;
126 y1 += mwindow->theme->play_h;
132 int PatchGUI::update(int x, int y)
134 //TRACE("PatchGUI::update 1");
136 //TRACE("PatchGUI::update 10");
138 int h = track->vertical_span(mwindow->theme);
141 //printf("PatchGUI::update 10\n");
152 title->update(track->title);
158 patchbay->add_subwindow(title = new TitlePatch(mwindow, this, x1 + x, y1 + y));
160 y1 += mwindow->theme->title_h;
164 if(h - y1 < mwindow->theme->play_h)
180 play->update(track->play);
181 record->update(track->record);
182 gang->update(track->gang);
183 draw->update(track->draw);
184 mute->update(mute->get_keyframe(mwindow, this)->value);
185 expand->update(track->expand_view);
189 if(h - y1 >= mwindow->theme->play_h)
191 patchbay->add_subwindow(play = new PlayPatch(mwindow, this, x1 + x, y1 + y));
192 //printf("PatchGUI::update 1 %p %p\n", play, &play->status);
194 patchbay->add_subwindow(record = new RecordPatch(mwindow, this, x1 + x, y1 + y));
195 x1 += record->get_w();
196 patchbay->add_subwindow(gang = new GangPatch(mwindow, this, x1 + x, y1 + y));
198 patchbay->add_subwindow(draw = new DrawPatch(mwindow, this, x1 + x, y1 + y));
200 patchbay->add_subwindow(mute = new MutePatch(mwindow, this, x1 + x, y1 + y));
204 patchbay->add_subwindow(expand = new ExpandPatch(mwindow,
206 patchbay->get_w() - 10 - mwindow->theme->expandpatch_data[0]->get_w(),
208 x1 += expand->get_w();
210 y1 += mwindow->theme->play_h;
217 void PatchGUI::toggle_behavior(int type,
222 if(toggle->shift_down())
224 int total_selected = mwindow->edl->tracks->total_of(type);
226 // nothing previously selected
227 if(total_selected == 0)
229 mwindow->edl->tracks->select_all(type,
233 if(total_selected == 1)
235 // this patch was previously the only one on
238 mwindow->edl->tracks->select_all(type,
241 // another patch was previously the only one on
244 mwindow->edl->tracks->select_all(type,
250 if(total_selected > 1)
252 mwindow->edl->tracks->select_all(type,
256 toggle->set_value(*output);
258 patchbay->drag_operation = type;
259 patchbay->new_status = 1;
260 patchbay->button_down = 1;
265 // Select + drag behavior
266 patchbay->drag_operation = type;
267 patchbay->new_status = value;
268 patchbay->button_down = 1;
271 if(type == Tracks::PLAY)
273 mwindow->gui->unlock_window();
274 mwindow->restart_brender();
275 mwindow->sync_parameters(CHANGE_EDL);
276 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
279 if(type == Tracks::MUTE)
281 mwindow->gui->unlock_window();
282 mwindow->restart_brender();
283 mwindow->sync_parameters(CHANGE_PARAMS);
284 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
287 // Update affected tracks in cwindow
288 if(type == Tracks::RECORD)
289 mwindow->cwindow->update(0, 1, 1);
293 char* PatchGUI::calculate_nudge_text(int *changed)
295 if(changed) *changed = 0;
296 if(track->edl->session->nudge_seconds)
298 sprintf(string_return, "%.4f", track->from_units(track->nudge));
299 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
304 sprintf(string_return, "%d", track->nudge);
305 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
308 return string_return;
311 void PatchGUI::set_nudge_value(char *string)
313 if(track->edl->session->nudge_seconds)
316 sscanf(string, "%f", &result);
317 track->nudge = track->to_units(result, 0);
318 //printf("PatchGUI::set_nudge_value 1 %d %f %s\n", track->nudge, result, string);
323 sscanf(string, "%lld", &temp);
325 //printf("PatchGUI::set_nudge_value 10 %d\n", track->nudge);
327 //printf("PatchGUI::set_nudge_value %d\n", track->nudge);
341 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
344 mwindow->theme->playpatch_data,
351 this->mwindow = mwindow;
353 set_tooltip(_("Play track"));
357 int PlayPatch::button_press_event()
359 if(is_event_win() && get_buttonpress() == 1)
361 set_status(BC_Toggle::TOGGLE_DOWN);
362 update(!get_value());
363 patch->toggle_behavior(Tracks::PLAY,
366 &patch->track->play);
372 int PlayPatch::button_release_event()
374 int result = BC_Toggle::button_release_event();
375 if(patch->patchbay->drag_operation != Tracks::NONE)
377 patch->patchbay->drag_operation = Tracks::NONE;
392 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
395 mwindow->theme->recordpatch_data,
396 patch->track->record,
402 this->mwindow = mwindow;
404 set_tooltip(_("Arm track"));
408 int RecordPatch::button_press_event()
410 if(is_event_win() && get_buttonpress() == 1)
412 set_status(BC_Toggle::TOGGLE_DOWN);
413 update(!get_value());
414 patch->toggle_behavior(Tracks::RECORD,
417 &patch->track->record);
423 int RecordPatch::button_release_event()
425 int result = BC_Toggle::button_release_event();
426 if(patch->patchbay->drag_operation != Tracks::NONE)
428 patch->patchbay->drag_operation = Tracks::NONE;
443 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
445 mwindow->theme->gangpatch_data,
452 this->mwindow = mwindow;
454 set_tooltip(_("Gang faders"));
458 int GangPatch::button_press_event()
460 if(is_event_win() && get_buttonpress() == 1)
462 set_status(BC_Toggle::TOGGLE_DOWN);
463 update(!get_value());
464 patch->toggle_behavior(Tracks::GANG,
467 &patch->track->gang);
473 int GangPatch::button_release_event()
475 int result = BC_Toggle::button_release_event();
476 if(patch->patchbay->drag_operation != Tracks::NONE)
478 patch->patchbay->drag_operation = Tracks::NONE;
493 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
495 mwindow->theme->drawpatch_data,
502 this->mwindow = mwindow;
504 set_tooltip(_("Draw media"));
508 int DrawPatch::button_press_event()
510 if(is_event_win() && get_buttonpress() == 1)
512 set_status(BC_Toggle::TOGGLE_DOWN);
513 update(!get_value());
514 patch->toggle_behavior(Tracks::DRAW,
517 &patch->track->draw);
523 int DrawPatch::button_release_event()
525 int result = BC_Toggle::button_release_event();
526 if(patch->patchbay->drag_operation != Tracks::NONE)
528 patch->patchbay->drag_operation = Tracks::NONE;
542 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
544 mwindow->theme->mutepatch_data,
545 get_keyframe(mwindow, patch)->value,
551 this->mwindow = mwindow;
553 set_tooltip(_("Don't send to output"));
557 int MutePatch::button_press_event()
559 if(is_event_win() && get_buttonpress() == 1)
561 set_status(BC_Toggle::TOGGLE_DOWN);
562 update(!get_value());
564 double position = mwindow->edl->local_session->selectionstart;
565 Autos *mute_autos = patch->track->automation->mute_autos;
567 mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
569 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
570 current->value = get_value();
572 patch->toggle_behavior(Tracks::MUTE,
578 mwindow->undo->update_undo_after();
580 if(mwindow->edl->session->auto_conf->mute)
582 mwindow->gui->canvas->draw_overlays();
583 mwindow->gui->canvas->flash();
590 int MutePatch::button_release_event()
592 int result = BC_Toggle::button_release_event();
593 if(patch->patchbay->drag_operation != Tracks::NONE)
595 patch->patchbay->drag_operation = Tracks::NONE;
600 IntAuto* MutePatch::get_keyframe(MWindow *mwindow, PatchGUI *patch)
603 double unit_position = mwindow->edl->local_session->selectionstart;
604 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
605 unit_position = patch->track->to_units(unit_position, 0);
606 return (IntAuto*)patch->track->automation->mute_autos->get_prev_auto(
623 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
626 mwindow->theme->expandpatch_data,
627 patch->track->expand_view,
633 this->mwindow = mwindow;
638 int ExpandPatch::button_press_event()
640 if(is_event_win() && get_buttonpress() == 1)
642 set_status(BC_Toggle::TOGGLE_DOWN);
643 update(!get_value());
644 patch->toggle_behavior(Tracks::EXPAND,
647 &patch->track->expand_view);
648 mwindow->trackmovement(mwindow->edl->local_session->track_start);
654 int ExpandPatch::button_release_event()
656 int result = BC_Toggle::button_release_event();
657 if(patch->patchbay->drag_operation != Tracks::NONE)
659 patch->patchbay->drag_operation = Tracks::NONE;
668 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
671 patch->patchbay->get_w() - 10,
675 this->mwindow = mwindow;
679 int TitlePatch::handle_event()
681 strcpy(patch->track->title, get_text());
682 mwindow->update_plugin_titles();
683 mwindow->gui->canvas->draw_overlays();
684 mwindow->gui->canvas->flash();
696 NudgePatch::NudgePatch(MWindow *mwindow,
705 patch->calculate_nudge_text(0))
707 this->mwindow = mwindow;
709 set_tooltip(_("Nudge"));
712 int NudgePatch::handle_event()
714 mwindow->undo->update_undo_before("nudge", LOAD_AUTOMATION);
715 patch->set_nudge_value(get_text());
716 mwindow->undo->update_undo_after();
718 if(patch->track->data_type == TRACK_AUDIO)
720 mwindow->gui->unlock_window();
721 // mwindow->sync_parameters(CHANGE_EDL);
722 mwindow->sync_parameters(CHANGE_PARAMS);
723 mwindow->gui->lock_window("NudgePatch::handle_event 1");
727 mwindow->gui->unlock_window();
728 mwindow->restart_brender();
729 mwindow->sync_parameters(CHANGE_PARAMS);
730 mwindow->gui->lock_window("NudgePatch::handle_event 2");
733 mwindow->session->changes_made = 1;
737 int NudgePatch::button_press_event()
740 if(get_buttonpress() == 3 &&
744 patch->patchbay->nudge_popup->activate_menu(patch);
748 return BC_TextBox::button_press_event();
752 void NudgePatch::update()
755 char *string = patch->calculate_nudge_text(&changed);
757 BC_TextBox::update(string);