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 track_id = track ? track->get_id() : -1;
88 void PatchGUI::create_objects()
93 int PatchGUI::reposition(int x, int y)
99 if( x != this->x || y != this->y ) {
100 this->x = x; this->y = y;
103 title->reposition_window(title->get_x(), y1 + y, 0);
105 expand->reposition_window(expand->get_x(), y1 + y);
106 y1 += mwindow->theme->title_h;
109 play->reposition_window(play->get_x(), y1 + y);
111 record->reposition_window(record->get_x(), y1 + y);
112 x1 += record->get_w();
113 // automate->reposition_window(x1, y1 + y);
114 // x1 += automate->get_w();
115 gang->reposition_window(gang->get_x(), y1 + y);
117 draw->reposition_window(draw->get_x(), y1 + y);
119 mute->reposition_window(mute->get_x(), y1 + y);
122 y1 += mwindow->theme->play_h;
126 y1 += mwindow->theme->title_h;
128 y1 += mwindow->theme->play_h;
134 int PatchGUI::update(int x, int y)
136 //TRACE("PatchGUI::update 1");
138 //TRACE("PatchGUI::update 10");
140 int h = track->vertical_span(mwindow->theme);
143 //printf("PatchGUI::update 10\n");
145 int y2 = y1 + mwindow->theme->title_h;
148 delete title; title = 0;
149 delete expand; expand = 0;
152 title->update(track->title);
153 expand->update(track->expand_view);
157 VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
158 int x2 = patchbay->get_w() - expandpatch_data[0]->get_w() - 5;
159 patchbay->add_subwindow(title = new TitlePatch(mwindow, this, x1 + x, y1 + y, x2-x1-5));
160 patchbay->add_subwindow(expand = new ExpandPatch(mwindow, this, x2, y1 + y));
166 y2 = y1 + mwindow->theme->play_h;
169 delete play; play = 0;
170 delete record; record = 0;
171 delete gang; gang = 0;
172 delete draw; draw = 0;
173 delete mute; mute = 0;
176 play->update(track->play);
177 record->update(track->record);
178 gang->update(track->gang);
179 draw->update(track->draw);
180 mute->update(mwindow->get_int_auto(this, AUTOMATION_MUTE)->value);
184 patchbay->add_subwindow(play = new PlayPatch(mwindow, this, x1 + x, y1 + y));
185 //printf("PatchGUI::update %d %d\n", __LINE__, play->get_h());
187 patchbay->add_subwindow(record = new RecordPatch(mwindow, this, x1 + x, y1 + y));
188 x1 += record->get_w();
189 patchbay->add_subwindow(gang = new GangPatch(mwindow, this, x1 + x, y1 + y));
191 patchbay->add_subwindow(draw = new DrawPatch(mwindow, this, x1 + x, y1 + y));
193 patchbay->add_subwindow(mute = new MutePatch(mwindow, this, x1 + x, y1 + y));
204 void PatchGUI::toggle_behavior(int type,
209 if(toggle->shift_down()) {
210 int sense = type != Tracks::MUTE ? 1 : 0;
211 // all selected if nothing previously selected or
212 // if this patch was previously the only one selected
213 int total_type = mwindow->edl->tracks->total_of(type);
214 int total_selected = sense ? total_type :
215 mwindow->edl->tracks->total() - total_type;
216 int selected = !total_selected || (total_selected == 1 &&
217 *output == sense ) ? sense : 1-sense;
218 mwindow->edl->tracks->select_all(type, selected);
219 if( selected != sense ) *output = sense;
221 patchbay->drag_operation = type;
222 patchbay->new_status = 1;
227 // Select + drag behavior
228 patchbay->drag_operation = type;
229 patchbay->new_status = value;
235 mwindow->gui->unlock_window();
236 mwindow->restart_brender();
237 mwindow->sync_parameters(CHANGE_EDL);
238 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
242 mwindow->gui->unlock_window();
243 mwindow->restart_brender();
244 mwindow->sync_parameters(CHANGE_PARAMS);
245 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
248 // Update affected tracks in cwindow
250 mwindow->cwindow->update(0, 1, 1);
257 mwindow->gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
265 mwindow->gui->update_patchbay();
269 char* PatchGUI::calculate_nudge_text(int *changed)
271 if(changed) *changed = 0;
272 if(track->edl->session->nudge_format)
274 sprintf(string_return, "%.4f", track->from_units(track->nudge));
275 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
280 sprintf(string_return, "%jd", track->nudge);
281 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
284 return string_return;
288 int64_t PatchGUI::calculate_nudge(const char *string)
290 if(mwindow->edl->session->nudge_format)
293 sscanf(string, "%f", &result);
294 return track->to_units(result, 0);
299 sscanf(string, "%jd", &temp);
305 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
308 mwindow->theme->get_image_set("playpatch_data"),
315 this->mwindow = mwindow;
317 set_tooltip(_("Play track"));
321 int PlayPatch::button_press_event()
323 if(is_event_win() && get_buttonpress() == 1)
325 mwindow->undo->update_undo_before();
326 set_status(BC_Toggle::TOGGLE_DOWN);
327 update(!get_value());
328 patch->toggle_behavior(Tracks::PLAY,
331 &patch->track->play);
337 int PlayPatch::button_release_event()
339 int result = BC_Toggle::button_release_event();
340 if(patch->patchbay->drag_operation == Tracks::PLAY)
342 mwindow->undo->update_undo_after(_("play patch"), LOAD_PATCHES);
343 patch->patchbay->drag_operation = Tracks::NONE;
358 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
361 mwindow->theme->get_image_set("recordpatch_data"),
362 patch->track->record,
368 this->mwindow = mwindow;
370 set_tooltip(_("Arm track"));
374 int RecordPatch::button_press_event()
376 if(is_event_win() && get_buttonpress() == 1)
378 mwindow->undo->update_undo_before();
379 set_status(BC_Toggle::TOGGLE_DOWN);
380 update(!get_value());
381 patch->toggle_behavior(Tracks::RECORD,
384 &patch->track->record);
385 patch->title->set_back_color(patch->track->record ?
386 get_resources()->text_background :
387 get_resources()->text_background_disarmed);
388 patch->title->set_text_row(0);
389 mwindow->gui->draw_overlays(1);
395 int RecordPatch::button_release_event()
397 int result = BC_Toggle::button_release_event();
398 if(patch->patchbay->drag_operation == Tracks::RECORD)
400 mwindow->undo->update_undo_after(_("record patch"), LOAD_PATCHES);
401 patch->patchbay->drag_operation = Tracks::NONE;
416 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
418 mwindow->theme->get_image_set("gangpatch_data"),
425 this->mwindow = mwindow;
427 set_tooltip(_("Gang faders"));
431 int GangPatch::button_press_event()
433 if(is_event_win() && get_buttonpress() == 1)
435 mwindow->undo->update_undo_before();
436 set_status(BC_Toggle::TOGGLE_DOWN);
437 update(!get_value());
438 patch->toggle_behavior(Tracks::GANG,
441 &patch->track->gang);
447 int GangPatch::button_release_event()
449 int result = BC_Toggle::button_release_event();
450 if(patch->patchbay->drag_operation == Tracks::GANG)
452 mwindow->undo->update_undo_after(_("gang patch"), LOAD_PATCHES);
453 patch->patchbay->drag_operation = Tracks::NONE;
468 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
470 mwindow->theme->get_image_set("drawpatch_data"),
477 this->mwindow = mwindow;
479 set_tooltip(_("Draw media"));
483 int DrawPatch::button_press_event()
485 if(is_event_win() && get_buttonpress() == 1)
487 mwindow->undo->update_undo_before();
488 set_status(BC_Toggle::TOGGLE_DOWN);
489 update(!get_value());
490 patch->toggle_behavior(Tracks::DRAW,
493 &patch->track->draw);
499 int DrawPatch::button_release_event()
501 int result = BC_Toggle::button_release_event();
502 if(patch->patchbay->drag_operation == Tracks::DRAW)
504 mwindow->undo->update_undo_after(_("draw patch"), LOAD_PATCHES);
505 patch->patchbay->drag_operation = Tracks::NONE;
519 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
521 mwindow->theme->get_image_set("mutepatch_data"),
522 mwindow->get_int_auto(patch, AUTOMATION_MUTE)->value,
528 this->mwindow = mwindow;
530 set_tooltip(_("Don't send to output"));
534 int MutePatch::button_press_event()
536 if(is_event_win() && get_buttonpress() == 1)
538 mwindow->undo->update_undo_before();
539 set_status(BC_Toggle::TOGGLE_DOWN);
540 update(!get_value());
542 double position = mwindow->edl->local_session->get_selectionstart(1);
543 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
546 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
547 current->value = get_value();
549 patch->toggle_behavior(Tracks::MUTE,
556 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
558 mwindow->gui->draw_overlays(1);
565 int MutePatch::button_release_event()
567 int result = BC_Toggle::button_release_event();
568 if(patch->patchbay->drag_operation == Tracks::MUTE)
570 mwindow->undo->update_undo_after(_("mute patch"), LOAD_PATCHES);
571 patch->patchbay->drag_operation = Tracks::NONE;
578 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
581 mwindow->theme->get_image_set("expandpatch_data"),
582 patch->track->expand_view,
588 this->mwindow = mwindow;
593 int ExpandPatch::button_press_event()
595 if(is_event_win() && get_buttonpress() == 1)
597 mwindow->undo->update_undo_before();
598 set_status(BC_Toggle::TOGGLE_DOWN);
599 update(!get_value());
600 patch->toggle_behavior(Tracks::EXPAND,
603 &patch->track->expand_view);
604 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
605 mwindow->gui->draw_trackmovement();
611 int ExpandPatch::button_release_event()
613 int result = BC_Toggle::button_release_event();
614 if(patch->patchbay->drag_operation == Tracks::EXPAND)
616 mwindow->undo->update_undo_after(_("expand patch"), LOAD_PATCHES);
617 patch->patchbay->drag_operation = Tracks::NONE;
623 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y, int w)
624 : BC_TextBox(x, y, w, 1, patch->track->title, 1, MEDIUMFONT, 1)
626 this->mwindow = mwindow;
628 set_back_color(patch->track->record ?
629 get_resources()->text_background :
630 get_resources()->text_background_disarmed);
633 void TitlePatch::update(const char *text)
635 set_back_color(patch->track->record ?
636 get_resources()->text_background :
637 get_resources()->text_background_disarmed);
638 BC_TextBox::update(text);
641 int TitlePatch::handle_event()
643 mwindow->undo->update_undo_before(_("track title"), this);
644 strcpy(patch->track->title, get_text());
645 mwindow->update_plugin_titles();
646 mwindow->gui->draw_overlays(1);
647 mwindow->undo->update_undo_after(_("track title"), LOAD_PATCHES);
652 NudgePatch::NudgePatch(MWindow *mwindow,
661 patch->calculate_nudge_text(0))
663 this->mwindow = mwindow;
665 set_tooltip(_("Nudge"));
668 int NudgePatch::handle_event()
670 set_value(patch->calculate_nudge(get_text()));
674 void NudgePatch::set_value(int64_t value)
676 mwindow->undo->update_undo_before(_("nudge."), this);
677 patch->track->nudge = value;
679 if(patch->track->gang && patch->track->record)
680 patch->patchbay->synchronize_nudge(patch->track->nudge, patch->track);
682 mwindow->undo->update_undo_after(_("nudge."), LOAD_PATCHES);
684 mwindow->gui->unlock_window();
685 if(patch->track->data_type == TRACK_VIDEO)
686 mwindow->restart_brender();
687 mwindow->sync_parameters(CHANGE_PARAMS);
688 mwindow->gui->lock_window("NudgePatch::handle_event 2");
690 mwindow->session->changes_made = 1;
694 int NudgePatch::button_press_event()
698 if(is_event_win() && cursor_inside())
700 if(get_buttonpress() == 4)
702 int value = patch->calculate_nudge(get_text());
703 value += calculate_increment();
709 if(get_buttonpress() == 5)
711 int value = patch->calculate_nudge(get_text());
712 value -= calculate_increment();
718 if(get_buttonpress() == 3)
720 patch->patchbay->nudge_popup->activate_menu(patch);
726 return BC_TextBox::button_press_event();
731 int64_t NudgePatch::calculate_increment()
733 if(patch->track->data_type == TRACK_AUDIO)
735 return (int64_t)ceil(patch->track->edl->session->sample_rate / 10.0);
739 return (int64_t)ceil(1.0 / patch->track->edl->session->frame_rate);
743 void NudgePatch::update()
746 char *string = patch->calculate_nudge_text(&changed);
748 BC_TextBox::update(string);
752 MixPatch::MixPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
753 : BC_Toggle(x, y, mwindow->theme->get_image_set("mixpatch_data"),
754 patch->mixer, "", 0, 0, 0)
756 this->mwindow = mwindow;
760 MixPatch::~MixPatch()
764 int MixPatch::handle_event()
766 int v = patch->track ? get_value() : 0;
767 if( patch->mixer != v ) {
769 mwindow->gui->update_mixers(patch->track, v);
772 mwindow->update_mixer_tracks();
777 void MixPatch::update(int v)
780 BC_Toggle::update(v);