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;
72 track_id = track ? track->get_id() : -1;
92 void PatchGUI::create_objects()
97 int PatchGUI::reposition(int x, int y)
99 if( track->is_hidden() ) return 0;
104 if( x != this->x || y != this->y ) {
105 this->x = x; this->y = y;
108 title->reposition_window(title->get_x(), y1 + y, 0);
110 expand->reposition_window(expand->get_x(), y1 + y);
111 y1 += mwindow->theme->title_h;
114 play->reposition_window(play->get_x(), y1 + y);
116 record->reposition_window(record->get_x(), y1 + y);
117 x1 += record->get_w();
118 // automate->reposition_window(x1, y1 + y);
119 // x1 += automate->get_w();
120 gang->reposition_window(gang->get_x(), y1 + y);
122 draw->reposition_window(draw->get_x(), y1 + y);
124 mute->reposition_window(mute->get_x(), y1 + y);
126 zoom->reposition_window(zoom->get_x(), y1 + y);
128 master->reposition_window(master->get_x(), y1 + y);
130 y1 += mwindow->theme->play_h;
134 y1 += mwindow->theme->title_h;
136 y1 += mwindow->theme->play_h;
142 int PatchGUI::update(int x, int y)
144 if( track->is_hidden() ) return 0;
145 //TRACE("PatchGUI::update 1");
147 //TRACE("PatchGUI::update 10");
149 int h = track->vertical_span(mwindow->theme);
152 //printf("PatchGUI::update 10\n");
154 int y2 = y1 + mwindow->theme->title_h;
157 delete title; title = 0;
158 delete expand; expand = 0;
161 title->update(track->title);
162 expand->update(track->expand_view);
166 VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
167 int x2 = patchbay->get_w() - expandpatch_data[0]->get_w() - 5;
168 patchbay->add_subwindow(title = new TitlePatch(mwindow, this, x1 + x, y1 + y, x2-x1-5));
169 patchbay->add_subwindow(expand = new ExpandPatch(mwindow, this, x2, y1 + y));
175 y2 = y1 + mwindow->theme->play_h;
178 delete play; play = 0;
179 delete record; record = 0;
180 delete gang; gang = 0;
181 delete draw; draw = 0;
182 delete mute; mute = 0;
183 delete zoom; zoom = 0;
184 delete master; master = 0;
187 play->update(track->play);
188 record->update(track->armed);
189 gang->update(track->ganged);
190 draw->update(track->draw);
191 mute->update(mwindow->get_int_auto(this, AUTOMATION_MUTE)->value);
195 patchbay->add_subwindow(play = new PlayPatch(mwindow, this, x1 + x, y1 + y));
196 //printf("PatchGUI::update %d %d\n", __LINE__, play->get_h());
198 patchbay->add_subwindow(record = new RecordPatch(mwindow, this, x1 + x, y1 + y));
199 x1 += record->get_w();
200 patchbay->add_subwindow(gang = new GangPatch(mwindow, this, x1 + x, y1 + y));
202 patchbay->add_subwindow(draw = new DrawPatch(mwindow, this, x1 + x, y1 + y));
204 patchbay->add_subwindow(mute = new MutePatch(mwindow, this, x1 + x, y1 + y));
206 patchbay->add_subwindow(zoom = new ZoomPatch(mwindow, this, x1 + x, y1 + y));
208 patchbay->add_subwindow(master = new MasterPatch(mwindow, this, x1 + x, y1 + y));
218 void PatchGUI::toggle_behavior(int type,
223 if(toggle->shift_down()) {
224 int sense = type != Tracks::MUTE ? 1 : 0;
225 // all selected if nothing previously selected or
226 // if this patch was previously the only one selected
227 int total_type = mwindow->edl->tracks->total_of(type);
228 int total_selected = sense ? total_type :
229 mwindow->edl->tracks->total() - total_type;
230 int selected = !total_selected || (total_selected == 1 &&
231 *output == sense ) ? sense : 1-sense;
232 mwindow->edl->tracks->select_all(type, selected);
233 if( selected != sense ) *output = sense;
235 patchbay->drag_operation = type;
236 patchbay->new_status = 1;
241 // Select + drag behavior
242 patchbay->drag_operation = type;
243 patchbay->new_status = value;
249 mwindow->gui->unlock_window();
250 mwindow->restart_brender();
251 mwindow->sync_parameters(CHANGE_EDL);
252 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
256 mwindow->gui->unlock_window();
257 mwindow->restart_brender();
258 mwindow->sync_parameters(CHANGE_PARAMS);
259 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
262 // Update affected tracks in cwindow
264 mwindow->cwindow->update(0, 1, 1);
271 mwindow->gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
279 mwindow->gui->update_patchbay();
283 char* PatchGUI::calculate_nudge_text(int *changed)
285 if(changed) *changed = 0;
286 if(track->edl->session->nudge_format)
288 sprintf(string_return, "%.4f", track->from_units(track->nudge));
289 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
294 sprintf(string_return, "%jd", track->nudge);
295 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
298 return string_return;
302 int64_t PatchGUI::calculate_nudge(const char *string)
304 if(mwindow->edl->session->nudge_format)
307 sscanf(string, "%f", &result);
308 return track->to_units(result, 0);
313 sscanf(string, "%jd", &temp);
319 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
322 mwindow->theme->get_image_set("playpatch_data"),
329 this->mwindow = mwindow;
331 set_tooltip(_("Play track"));
335 int PlayPatch::button_press_event()
337 if(is_event_win() && get_buttonpress() == 1)
339 mwindow->undo->update_undo_before();
340 set_status(BC_Toggle::TOGGLE_DOWN);
341 update(!get_value());
342 patch->toggle_behavior(Tracks::PLAY,
345 &patch->track->play);
351 int PlayPatch::button_release_event()
353 int result = BC_Toggle::button_release_event();
354 if(patch->patchbay->drag_operation == Tracks::PLAY)
356 mwindow->undo->update_undo_after(_("play patch"), LOAD_PATCHES);
357 patch->patchbay->drag_operation = Tracks::NONE;
372 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
375 mwindow->theme->get_image_set("recordpatch_data"),
382 this->mwindow = mwindow;
384 set_tooltip(_("Arm track"));
388 int RecordPatch::button_press_event()
390 if(is_event_win() && get_buttonpress() == 1)
392 mwindow->undo->update_undo_before();
393 set_status(BC_Toggle::TOGGLE_DOWN);
394 update(!get_value());
395 patch->toggle_behavior(Tracks::RECORD,
398 &patch->track->armed);
399 patch->title->set_back_color(patch->track->armed ?
400 get_resources()->text_background :
401 get_resources()->text_background_disarmed);
402 patch->title->set_text_row(0);
403 mwindow->gui->draw_overlays(1);
409 int RecordPatch::button_release_event()
411 int result = BC_Toggle::button_release_event();
412 if(patch->patchbay->drag_operation == Tracks::RECORD)
414 mwindow->undo->update_undo_after(_("record patch"), LOAD_PATCHES);
415 patch->patchbay->drag_operation = Tracks::NONE;
430 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
432 mwindow->theme->get_image_set("gangpatch_data"),
433 patch->track->ganged,
439 this->mwindow = mwindow;
441 set_tooltip(_("Gang faders"));
445 int GangPatch::button_press_event()
447 if(is_event_win() && get_buttonpress() == 1)
449 mwindow->undo->update_undo_before();
450 set_status(BC_Toggle::TOGGLE_DOWN);
451 update(!get_value());
452 patch->toggle_behavior(Tracks::GANG,
455 &patch->track->ganged);
461 int GangPatch::button_release_event()
463 int result = BC_Toggle::button_release_event();
464 if(patch->patchbay->drag_operation == Tracks::GANG)
466 mwindow->undo->update_undo_after(_("gang patch"), LOAD_PATCHES);
467 patch->patchbay->drag_operation = Tracks::NONE;
482 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
484 mwindow->theme->get_image_set("drawpatch_data"),
491 this->mwindow = mwindow;
493 set_tooltip(_("Draw media"));
497 int DrawPatch::button_press_event()
499 if(is_event_win() && get_buttonpress() == 1)
501 mwindow->undo->update_undo_before();
502 set_status(BC_Toggle::TOGGLE_DOWN);
503 update(!get_value());
504 patch->toggle_behavior(Tracks::DRAW,
507 &patch->track->draw);
513 int DrawPatch::button_release_event()
515 int result = BC_Toggle::button_release_event();
516 if(patch->patchbay->drag_operation == Tracks::DRAW)
518 mwindow->undo->update_undo_after(_("draw patch"), LOAD_PATCHES);
519 patch->patchbay->drag_operation = Tracks::NONE;
533 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
535 mwindow->theme->get_image_set("mutepatch_data"),
536 mwindow->get_int_auto(patch, AUTOMATION_MUTE)->value,
542 this->mwindow = mwindow;
544 set_tooltip(_("Don't send to output"));
548 int MutePatch::button_press_event()
550 if(is_event_win() && get_buttonpress() == 1)
552 mwindow->undo->update_undo_before();
553 set_status(BC_Toggle::TOGGLE_DOWN);
554 update(!get_value());
556 double position = mwindow->edl->local_session->get_selectionstart(1);
557 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
560 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
561 current->value = get_value();
563 patch->toggle_behavior(Tracks::MUTE,
570 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
572 mwindow->gui->draw_overlays(1);
579 int MutePatch::button_release_event()
581 int result = BC_Toggle::button_release_event();
582 if(patch->patchbay->drag_operation == Tracks::MUTE)
584 mwindow->undo->update_undo_after(_("mute patch"), LOAD_PATCHES);
585 patch->patchbay->drag_operation = Tracks::NONE;
591 ZoomPatch::ZoomPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
592 : BC_Tumbler(x, y, mwindow->theme->get_image_set("tumblepatch_data"))
594 this->mwindow = mwindow;
596 set_tooltip(_("Track Data Height"));
599 int ZoomPatch::handle_up_event()
601 patch->track->data_h *= 2;
602 bclamp(patch->track->data_h, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM);
603 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
604 mwindow->gui->draw_trackmovement();
607 int ZoomPatch::handle_down_event()
609 patch->track->data_h /= 2;
610 bclamp(patch->track->data_h, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM);
611 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
612 mwindow->gui->draw_trackmovement();
617 MasterPatch::MasterPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
618 : BC_Toggle(x, y, mwindow->theme->get_image_set("masterpatch_data"),
619 patch->track->master, "", 0, 0, 0)
621 this->mwindow = mwindow;
623 set_tooltip(_("Master Track"));
626 int MasterPatch::handle_event()
628 patch->track->master = patch->track->master ? 0 : 1;
629 mwindow->draw_trackmovement(); // delayed, can delete *this
634 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
635 : BC_Toggle(x, y, mwindow->theme->get_image_set("expandpatch_data"),
636 patch->track->expand_view, "", 0, 0, 0)
638 this->mwindow = mwindow;
643 int ExpandPatch::button_press_event()
645 if(is_event_win() && get_buttonpress() == 1)
647 mwindow->undo->update_undo_before();
648 set_status(BC_Toggle::TOGGLE_DOWN);
649 update(!get_value());
650 patch->toggle_behavior(Tracks::EXPAND,
653 &patch->track->expand_view);
654 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
655 mwindow->gui->draw_trackmovement();
661 int ExpandPatch::button_release_event()
663 int result = BC_Toggle::button_release_event();
664 if(patch->patchbay->drag_operation == Tracks::EXPAND)
666 mwindow->undo->update_undo_after(_("expand patch"), LOAD_PATCHES);
667 patch->patchbay->drag_operation = Tracks::NONE;
673 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y, int w)
674 : BC_TextBox(x, y, w, 1, patch->track->title, 1, MEDIUMFONT, 1)
676 this->mwindow = mwindow;
678 set_back_color(patch->track->armed ?
679 get_resources()->text_background :
680 get_resources()->text_background_disarmed);
683 void TitlePatch::update(const char *text)
685 set_back_color(patch->track->armed ?
686 get_resources()->text_background :
687 get_resources()->text_background_disarmed);
688 BC_TextBox::update(text);
691 int TitlePatch::handle_event()
693 mwindow->undo->update_undo_before(_("track title"), this);
694 strcpy(patch->track->title, get_text());
695 mwindow->update_plugin_titles();
696 mwindow->gui->draw_overlays(1);
697 mwindow->undo->update_undo_after(_("track title"), LOAD_PATCHES);
702 NudgePatch::NudgePatch(MWindow *mwindow,
711 patch->calculate_nudge_text(0))
713 this->mwindow = mwindow;
715 set_tooltip(_("Nudge"));
718 int NudgePatch::handle_event()
720 set_value(patch->calculate_nudge(get_text()));
724 void NudgePatch::set_value(int64_t value)
726 mwindow->undo->update_undo_before(_("nudge."), this);
727 patch->track->nudge = value;
729 if(patch->track->is_ganged() && patch->track->is_armed())
730 patch->patchbay->synchronize_nudge(patch->track->nudge, patch->track);
732 mwindow->undo->update_undo_after(_("nudge."), LOAD_PATCHES);
734 mwindow->gui->unlock_window();
735 if(patch->track->data_type == TRACK_VIDEO)
736 mwindow->restart_brender();
737 mwindow->sync_parameters(CHANGE_PARAMS);
738 mwindow->gui->lock_window("NudgePatch::handle_event 2");
740 mwindow->session->changes_made = 1;
744 int NudgePatch::button_press_event()
748 if(is_event_win() && cursor_inside())
750 if(get_buttonpress() == 4)
752 int value = patch->calculate_nudge(get_text());
753 value += calculate_increment();
759 if(get_buttonpress() == 5)
761 int value = patch->calculate_nudge(get_text());
762 value -= calculate_increment();
768 if(get_buttonpress() == 3)
770 patch->patchbay->nudge_popup->activate_menu(patch);
776 return BC_TextBox::button_press_event();
781 int64_t NudgePatch::calculate_increment()
783 if(patch->track->data_type == TRACK_AUDIO)
785 return (int64_t)ceil(patch->track->edl->session->sample_rate / 10.0);
789 return (int64_t)ceil(1.0 / patch->track->edl->session->frame_rate);
793 void NudgePatch::update()
796 char *string = patch->calculate_nudge_text(&changed);
798 BC_TextBox::update(string);
802 MixPatch::MixPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
803 : BC_Toggle(x, y, mwindow->theme->get_image_set("mixpatch_data"),
804 patch->mixer, "", 0, 0, 0)
806 this->mwindow = mwindow;
810 MixPatch::~MixPatch()
814 int MixPatch::handle_event()
816 int v = patch->track ? get_value() : 0;
817 if( patch->mixer != v ) {
819 mwindow->gui->update_mixers(patch->track, v);
822 mwindow->update_mixer_tracks();
827 void MixPatch::update(int v)
830 BC_Toggle::update(v);