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"
31 #include "localsession.h"
32 #include "mainsession.h"
35 #include "mwindowgui.h"
38 #include "playbackengine.h"
41 #include "trackcanvas.h"
43 #include "transportque.h"
48 PatchGUI::PatchGUI(MWindow *mwindow,
54 this->mwindow = mwindow;
55 this->patchbay = patchbay;
70 if(track) track_id = track->get_id();
75 if(title) delete title;
76 if(record) delete record;
78 // if(automate) delete automate;
82 if(expand) delete expand;
83 if(nudge) delete nudge;
86 void PatchGUI::create_objects()
91 int PatchGUI::reposition(int x, int y)
97 if(x != this->x || y != this->y)
104 TRACE("PatchGUI::reposition 1\n");
105 title->reposition_window(title->get_x(), y1 + y, 0);
106 TRACE("PatchGUI::reposition 2\n");
108 y1 += mwindow->theme->title_h;
112 TRACE("PatchGUI::reposition 3\n");
113 play->reposition_window(play->get_x(), y1 + y);
115 TRACE("PatchGUI::reposition 4\n");
116 record->reposition_window(record->get_x(), y1 + y);
117 x1 += record->get_w();
118 TRACE("PatchGUI::reposition 5\n");
119 // automate->reposition_window(x1, y1 + y);
120 // x1 += automate->get_w();
121 gang->reposition_window(gang->get_x(), y1 + y);
123 TRACE("PatchGUI::reposition 6\n");
124 draw->reposition_window(draw->get_x(), y1 + y);
126 TRACE("PatchGUI::reposition 7\n");
127 mute->reposition_window(mute->get_x(), y1 + y);
129 TRACE("PatchGUI::reposition 8\n");
133 TRACE("PatchGUI::reposition 9\n");
134 // VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
135 // int x = patchbay->get_w() - 10 - expandpatch_data[0]->get_w();
136 expand->reposition_window(
139 TRACE("PatchGUI::reposition 10\n");
140 x1 += expand->get_w();
141 TRACE("PatchGUI::reposition 11\n");
144 y1 += mwindow->theme->play_h;
148 y1 += mwindow->theme->title_h;
149 y1 += mwindow->theme->play_h;
155 int PatchGUI::update(int x, int y)
157 //TRACE("PatchGUI::update 1");
159 //TRACE("PatchGUI::update 10");
161 int h = track->vertical_span(mwindow->theme);
164 //printf("PatchGUI::update 10\n");
175 title->update(track->title);
181 patchbay->add_subwindow(title = new TitlePatch(mwindow, this, x1 + x, y1 + y));
183 y1 += mwindow->theme->title_h;
187 if(h - y1 < mwindow->theme->play_h)
189 delete play; play = 0;
190 delete record; record = 0;
191 delete gang; gang = 0;
192 delete draw; draw = 0;
193 delete mute; mute = 0;
194 delete expand; expand = 0;
198 play->update(track->play);
199 record->update(track->record);
200 gang->update(track->gang);
201 draw->update(track->draw);
202 mute->update(mute->get_keyframe(mwindow, this)->value);
203 expand->update(track->expand_view);
207 if(h - y1 >= mwindow->theme->play_h)
209 patchbay->add_subwindow(play = new PlayPatch(mwindow, this, x1 + x, y1 + y));
210 //printf("PatchGUI::update %d %d\n", __LINE__, play->get_h());
212 patchbay->add_subwindow(record = new RecordPatch(mwindow, this, x1 + x, y1 + y));
213 x1 += record->get_w();
214 patchbay->add_subwindow(gang = new GangPatch(mwindow, this, x1 + x, y1 + y));
216 patchbay->add_subwindow(draw = new DrawPatch(mwindow, this, x1 + x, y1 + y));
218 patchbay->add_subwindow(mute = new MutePatch(mwindow, this, x1 + x, y1 + y));
221 VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
222 patchbay->add_subwindow(expand = new ExpandPatch(mwindow,
224 patchbay->get_w() - 10 - expandpatch_data[0]->get_w(),
226 x1 += expand->get_w();
228 y1 += mwindow->theme->play_h;
235 void PatchGUI::toggle_behavior(int type,
240 if(toggle->shift_down())
242 int total_selected = mwindow->edl->tracks->total_of(type);
244 // nothing previously selected
245 if(total_selected == 0)
247 mwindow->edl->tracks->select_all(type,
251 if(total_selected == 1)
253 // this patch was previously the only one on
256 mwindow->edl->tracks->select_all(type,
259 // another patch was previously the only one on
262 mwindow->edl->tracks->select_all(type,
268 if(total_selected > 1)
270 mwindow->edl->tracks->select_all(type,
274 toggle->set_value(*output);
276 patchbay->drag_operation = type;
277 patchbay->new_status = 1;
282 // Select + drag behavior
283 patchbay->drag_operation = type;
284 patchbay->new_status = value;
290 mwindow->gui->unlock_window();
291 mwindow->restart_brender();
292 mwindow->sync_parameters(CHANGE_EDL);
293 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
297 mwindow->gui->unlock_window();
298 mwindow->restart_brender();
299 mwindow->sync_parameters(CHANGE_PARAMS);
300 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
303 // Update affected tracks in cwindow
305 mwindow->cwindow->update(0, 1, 1);
312 mwindow->gui->update(0, 1, 0, 0, 0, 0, 0);
320 mwindow->gui->update_patchbay();
324 char* PatchGUI::calculate_nudge_text(int *changed)
326 if(changed) *changed = 0;
327 if(track->edl->session->nudge_format)
329 sprintf(string_return, "%.4f", track->from_units(track->nudge));
330 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
335 sprintf(string_return, "%jd", track->nudge);
336 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
339 return string_return;
343 int64_t PatchGUI::calculate_nudge(const char *string)
345 if(mwindow->edl->session->nudge_format)
348 sscanf(string, "%f", &result);
349 return track->to_units(result, 0);
354 sscanf(string, "%jd", &temp);
370 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
373 mwindow->theme->get_image_set("playpatch_data"),
380 this->mwindow = mwindow;
382 set_tooltip(_("Play track"));
386 int PlayPatch::button_press_event()
388 if(is_event_win() && get_buttonpress() == 1)
390 mwindow->undo->update_undo_before();
391 set_status(BC_Toggle::TOGGLE_DOWN);
392 update(!get_value());
393 patch->toggle_behavior(Tracks::PLAY,
396 &patch->track->play);
402 int PlayPatch::button_release_event()
404 int result = BC_Toggle::button_release_event();
405 if(patch->patchbay->drag_operation == Tracks::PLAY)
407 mwindow->undo->update_undo_after(_("play patch"), LOAD_PATCHES);
408 patch->patchbay->drag_operation = Tracks::NONE;
423 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
426 mwindow->theme->get_image_set("recordpatch_data"),
427 patch->track->record,
433 this->mwindow = mwindow;
435 set_tooltip(_("Arm track"));
439 int RecordPatch::button_press_event()
441 if(is_event_win() && get_buttonpress() == 1)
443 mwindow->undo->update_undo_before();
444 set_status(BC_Toggle::TOGGLE_DOWN);
445 update(!get_value());
446 patch->toggle_behavior(Tracks::RECORD,
449 &patch->track->record);
455 int RecordPatch::button_release_event()
457 int result = BC_Toggle::button_release_event();
458 if(patch->patchbay->drag_operation == Tracks::RECORD)
460 mwindow->undo->update_undo_after(_("record patch"), LOAD_PATCHES);
461 patch->patchbay->drag_operation = Tracks::NONE;
476 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
478 mwindow->theme->get_image_set("gangpatch_data"),
485 this->mwindow = mwindow;
487 set_tooltip(_("Gang faders"));
491 int GangPatch::button_press_event()
493 if(is_event_win() && get_buttonpress() == 1)
495 mwindow->undo->update_undo_before();
496 set_status(BC_Toggle::TOGGLE_DOWN);
497 update(!get_value());
498 patch->toggle_behavior(Tracks::GANG,
501 &patch->track->gang);
507 int GangPatch::button_release_event()
509 int result = BC_Toggle::button_release_event();
510 if(patch->patchbay->drag_operation == Tracks::GANG)
512 mwindow->undo->update_undo_after(_("gang patch"), LOAD_PATCHES);
513 patch->patchbay->drag_operation = Tracks::NONE;
528 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
530 mwindow->theme->get_image_set("drawpatch_data"),
537 this->mwindow = mwindow;
539 set_tooltip(_("Draw media"));
543 int DrawPatch::button_press_event()
545 if(is_event_win() && get_buttonpress() == 1)
547 mwindow->undo->update_undo_before();
548 set_status(BC_Toggle::TOGGLE_DOWN);
549 update(!get_value());
550 patch->toggle_behavior(Tracks::DRAW,
553 &patch->track->draw);
559 int DrawPatch::button_release_event()
561 int result = BC_Toggle::button_release_event();
562 if(patch->patchbay->drag_operation == Tracks::DRAW)
564 mwindow->undo->update_undo_after(_("draw patch"), LOAD_PATCHES);
565 patch->patchbay->drag_operation = Tracks::NONE;
579 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
581 mwindow->theme->get_image_set("mutepatch_data"),
582 get_keyframe(mwindow, patch)->value,
588 this->mwindow = mwindow;
590 set_tooltip(_("Don't send to output"));
594 int MutePatch::button_press_event()
596 if(is_event_win() && get_buttonpress() == 1)
598 mwindow->undo->update_undo_before();
599 set_status(BC_Toggle::TOGGLE_DOWN);
600 update(!get_value());
602 double position = mwindow->edl->local_session->get_selectionstart(1);
603 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
606 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
607 current->value = get_value();
609 patch->toggle_behavior(Tracks::MUTE,
616 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
618 mwindow->gui->draw_overlays(1);
625 int MutePatch::button_release_event()
627 int result = BC_Toggle::button_release_event();
628 if(patch->patchbay->drag_operation == Tracks::MUTE)
630 mwindow->undo->update_undo_after(_("mute patch"), LOAD_PATCHES);
631 patch->patchbay->drag_operation = Tracks::NONE;
636 IntAuto* MutePatch::get_keyframe(MWindow *mwindow, PatchGUI *patch)
639 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
640 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
641 unit_position = patch->track->to_units(unit_position, 0);
642 return (IntAuto*)patch->track->automation->autos[AUTOMATION_MUTE]->get_prev_auto(
643 (int64_t)unit_position,
659 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
662 mwindow->theme->get_image_set("expandpatch_data"),
663 patch->track->expand_view,
669 this->mwindow = mwindow;
674 int ExpandPatch::button_press_event()
676 if(is_event_win() && get_buttonpress() == 1)
678 mwindow->undo->update_undo_before();
679 set_status(BC_Toggle::TOGGLE_DOWN);
680 update(!get_value());
681 patch->toggle_behavior(Tracks::EXPAND,
684 &patch->track->expand_view);
685 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
686 mwindow->gui->draw_trackmovement();
692 int ExpandPatch::button_release_event()
694 int result = BC_Toggle::button_release_event();
695 if(patch->patchbay->drag_operation == Tracks::EXPAND)
697 mwindow->undo->update_undo_after(_("expand patch"), LOAD_PATCHES);
698 patch->patchbay->drag_operation = Tracks::NONE;
707 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
710 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.0);
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);