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 draw->reposition_window(draw->get_x(), y1 + y);
122 mute->reposition_window(mute->get_x(), y1 + y);
124 gang->reposition_window(gang->get_x(), y1 + y);
126 master->reposition_window(master->get_x(), y1 + y);
127 x1 += master->get_w();
128 zoom->reposition_window(zoom->get_x(), y1 + y);
129 // x1 += zoom->get_w();
131 y1 += mwindow->theme->play_h;
135 y1 += mwindow->theme->title_h;
137 y1 += mwindow->theme->play_h;
143 int PatchGUI::update(int x, int y)
145 if( track->is_hidden() ) return 0;
146 //TRACE("PatchGUI::update 1");
148 //TRACE("PatchGUI::update 10");
150 int h = track->vertical_span(mwindow->theme);
153 //printf("PatchGUI::update 10\n");
155 int y2 = y1 + mwindow->theme->title_h;
158 delete title; title = 0;
159 delete expand; expand = 0;
162 title->update(track->title);
163 expand->update(track->expand_view);
167 VFrame **expandpatch_data = mwindow->theme->get_image_set("expandpatch_data");
168 int x2 = patchbay->get_w() - expandpatch_data[0]->get_w() - 5;
169 patchbay->add_subwindow(title = new TitlePatch(mwindow, this, x1 + x, y1 + y, x2-x1-5));
170 patchbay->add_subwindow(expand = new ExpandPatch(mwindow, this, x2, y1 + y));
176 y2 = y1 + mwindow->theme->play_h;
179 delete play; play = 0;
180 delete record; record = 0;
181 delete draw; draw = 0;
182 delete mute; mute = 0;
183 delete gang; gang = 0;
184 delete master; master = 0;
185 delete zoom; zoom = 0;
188 play->update(track->play);
189 record->update(track->armed);
190 draw->update(track->draw);
191 mute->update(mwindow->get_int_auto(this, AUTOMATION_MUTE)->value);
192 gang->update(track->ganged);
193 master->update(track->master);
197 patchbay->add_subwindow(play = new PlayPatch(mwindow, this, x1 + x, y1 + y));
198 //printf("PatchGUI::update %d %d\n", __LINE__, play->get_h());
200 patchbay->add_subwindow(record = new RecordPatch(mwindow, this, x1 + x, y1 + y));
201 x1 += record->get_w();
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(gang = new GangPatch(mwindow, this, x1 + x, y1 + y));
208 patchbay->add_subwindow(master = new MasterPatch(mwindow, this, x1 + x, y1 + y));
209 x1 += master->get_w();
210 patchbay->add_subwindow(zoom = new ZoomPatch(mwindow, this, x1 + x, y1 + y));
211 // x1 += zoom->get_w();
221 void PatchGUI::toggle_behavior(int type,
226 if(toggle->shift_down()) {
227 int sense = type != Tracks::MUTE ? 1 : 0;
228 // all selected if nothing previously selected or
229 // if this patch was previously the only one selected
230 int total_type = mwindow->edl->tracks->total_of(type);
231 int total_selected = sense ? total_type :
232 mwindow->edl->tracks->total() - total_type;
233 int selected = !total_selected || (total_selected == 1 &&
234 *output == sense ) ? sense : 1-sense;
235 mwindow->edl->tracks->select_all(type, selected);
236 if( selected != sense ) *output = sense;
238 patchbay->drag_operation = type;
239 patchbay->new_status = 1;
244 // Select + drag behavior
245 patchbay->drag_operation = type;
246 patchbay->new_status = value;
252 mwindow->gui->unlock_window();
253 mwindow->restart_brender();
254 mwindow->sync_parameters(CHANGE_EDL);
255 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
259 mwindow->gui->unlock_window();
260 mwindow->restart_brender();
261 mwindow->sync_parameters(CHANGE_PARAMS);
262 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
265 // Update affected tracks in cwindow
267 mwindow->cwindow->update(0, 1, 1);
274 mwindow->gui->update(0, NORMAL_DRAW, 0, 0, 0, 0, 0);
282 mwindow->gui->update_patchbay();
286 char* PatchGUI::calculate_nudge_text(int *changed)
288 if(changed) *changed = 0;
289 if(track->edl->session->nudge_format)
291 sprintf(string_return, "%.4f", track->from_units(track->nudge));
292 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
297 sprintf(string_return, "%jd", track->nudge);
298 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
301 return string_return;
305 int64_t PatchGUI::calculate_nudge(const char *string)
307 if(mwindow->edl->session->nudge_format)
310 sscanf(string, "%f", &result);
311 return track->to_units(result, 0);
316 sscanf(string, "%jd", &temp);
322 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
325 mwindow->theme->get_image_set("playpatch_data"),
332 this->mwindow = mwindow;
334 set_tooltip(_("Play track"));
338 int PlayPatch::button_press_event()
340 if(is_event_win() && get_buttonpress() == 1)
342 mwindow->undo->update_undo_before();
343 set_status(BC_Toggle::TOGGLE_DOWN);
344 update(!get_value());
345 patch->toggle_behavior(Tracks::PLAY,
348 &patch->track->play);
354 int PlayPatch::button_release_event()
356 int result = BC_Toggle::button_release_event();
357 if(patch->patchbay->drag_operation == Tracks::PLAY)
359 mwindow->undo->update_undo_after(_("play patch"), LOAD_PATCHES);
360 patch->patchbay->drag_operation = Tracks::NONE;
375 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
378 mwindow->theme->get_image_set("recordpatch_data"),
385 this->mwindow = mwindow;
387 set_tooltip(_("Arm track"));
391 int RecordPatch::button_press_event()
393 if(is_event_win() && get_buttonpress() == 1)
395 mwindow->undo->update_undo_before();
396 set_status(BC_Toggle::TOGGLE_DOWN);
397 update(!get_value());
398 patch->toggle_behavior(Tracks::RECORD,
401 &patch->track->armed);
402 patch->title->set_back_color(patch->track->armed ?
403 get_resources()->text_background :
404 get_resources()->text_background_disarmed);
405 patch->title->set_text_row(0);
406 mwindow->gui->draw_overlays(1);
412 int RecordPatch::button_release_event()
414 int result = BC_Toggle::button_release_event();
415 if(patch->patchbay->drag_operation == Tracks::RECORD)
417 mwindow->undo->update_undo_after(_("record patch"), LOAD_PATCHES);
418 patch->patchbay->drag_operation = Tracks::NONE;
433 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
435 mwindow->theme->get_image_set("gangpatch_data"),
436 patch->track->ganged,
442 this->mwindow = mwindow;
444 set_tooltip(_("Gang faders"));
448 int GangPatch::button_press_event()
450 if(is_event_win() && get_buttonpress() == 1)
452 mwindow->undo->update_undo_before();
453 set_status(BC_Toggle::TOGGLE_DOWN);
454 update(!get_value());
455 patch->toggle_behavior(Tracks::GANG,
458 &patch->track->ganged);
464 int GangPatch::button_release_event()
466 int result = BC_Toggle::button_release_event();
467 if(patch->patchbay->drag_operation == Tracks::GANG)
469 mwindow->undo->update_undo_after(_("gang patch"), LOAD_PATCHES);
470 patch->patchbay->drag_operation = Tracks::NONE;
485 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
487 mwindow->theme->get_image_set("drawpatch_data"),
494 this->mwindow = mwindow;
496 set_tooltip(_("Draw media"));
500 int DrawPatch::button_press_event()
502 if(is_event_win() && get_buttonpress() == 1)
504 mwindow->undo->update_undo_before();
505 set_status(BC_Toggle::TOGGLE_DOWN);
506 update(!get_value());
507 patch->toggle_behavior(Tracks::DRAW,
510 &patch->track->draw);
516 int DrawPatch::button_release_event()
518 int result = BC_Toggle::button_release_event();
519 if(patch->patchbay->drag_operation == Tracks::DRAW)
521 mwindow->undo->update_undo_after(_("draw patch"), LOAD_PATCHES);
522 patch->patchbay->drag_operation = Tracks::NONE;
536 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
538 mwindow->theme->get_image_set("mutepatch_data"),
539 mwindow->get_int_auto(patch, AUTOMATION_MUTE)->value,
545 this->mwindow = mwindow;
547 set_tooltip(_("Don't send to output"));
551 int MutePatch::button_press_event()
553 if(is_event_win() && get_buttonpress() == 1)
555 mwindow->undo->update_undo_before();
556 set_status(BC_Toggle::TOGGLE_DOWN);
557 update(!get_value());
559 double position = mwindow->edl->local_session->get_selectionstart(1);
560 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
563 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
564 current->value = get_value();
566 patch->toggle_behavior(Tracks::MUTE,
573 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
575 mwindow->gui->draw_overlays(1);
582 int MutePatch::button_release_event()
584 int result = BC_Toggle::button_release_event();
585 if(patch->patchbay->drag_operation == Tracks::MUTE)
587 mwindow->undo->update_undo_after(_("mute patch"), LOAD_PATCHES);
588 patch->patchbay->drag_operation = Tracks::NONE;
594 ZoomPatch::ZoomPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
595 : BC_Tumbler(x, y, mwindow->theme->get_image_set("tumblepatch_data"))
597 this->mwindow = mwindow;
599 set_tooltip(_("Track Data Height"));
602 int ZoomPatch::handle_up_event()
604 patch->track->data_h *= 2;
605 bclamp(patch->track->data_h, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM);
606 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
607 mwindow->gui->draw_trackmovement();
610 int ZoomPatch::handle_down_event()
612 patch->track->data_h /= 2;
613 bclamp(patch->track->data_h, MIN_TRACK_ZOOM, MAX_TRACK_ZOOM);
614 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
615 mwindow->gui->draw_trackmovement();
620 MasterPatch::MasterPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
621 : BC_Toggle(x, y, mwindow->theme->get_image_set("masterpatch_data"),
622 patch->track->master, "", 0, 0, 0)
624 this->mwindow = mwindow;
626 set_tooltip(_("Master Track"));
629 int MasterPatch::handle_event()
631 patch->track->master = patch->track->master ? 0 : 1;
632 mwindow->draw_trackmovement(); // delayed, can delete *this
637 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
638 : BC_Toggle(x, y, mwindow->theme->get_image_set("expandpatch_data"),
639 patch->track->expand_view, "", 0, 0, 0)
641 this->mwindow = mwindow;
646 int ExpandPatch::button_press_event()
648 if(is_event_win() && get_buttonpress() == 1)
650 mwindow->undo->update_undo_before();
651 set_status(BC_Toggle::TOGGLE_DOWN);
652 update(!get_value());
653 patch->toggle_behavior(Tracks::EXPAND,
656 &patch->track->expand_view);
657 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
658 mwindow->gui->draw_trackmovement();
664 int ExpandPatch::button_release_event()
666 int result = BC_Toggle::button_release_event();
667 if(patch->patchbay->drag_operation == Tracks::EXPAND)
669 mwindow->undo->update_undo_after(_("expand patch"), LOAD_PATCHES);
670 patch->patchbay->drag_operation = Tracks::NONE;
676 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y, int w)
677 : BC_TextBox(x, y, w, 1, patch->track->title, 1, MEDIUMFONT, 1)
679 this->mwindow = mwindow;
681 set_back_color(patch->track->armed ?
682 get_resources()->text_background :
683 get_resources()->text_background_disarmed);
686 void TitlePatch::update(const char *text)
688 set_back_color(patch->track->armed ?
689 get_resources()->text_background :
690 get_resources()->text_background_disarmed);
691 BC_TextBox::update(text);
694 int TitlePatch::handle_event()
696 mwindow->undo->update_undo_before(_("track title"), this);
697 strcpy(patch->track->title, get_text());
698 mwindow->update_plugin_titles();
699 mwindow->gui->draw_overlays(1);
700 mwindow->undo->update_undo_after(_("track title"), LOAD_PATCHES);
705 NudgePatch::NudgePatch(MWindow *mwindow,
714 patch->calculate_nudge_text(0))
716 this->mwindow = mwindow;
718 set_tooltip(_("Nudge"));
721 int NudgePatch::handle_event()
723 set_value(patch->calculate_nudge(get_text()));
727 void NudgePatch::set_value(int64_t value)
729 mwindow->undo->update_undo_before(_("nudge."), this);
730 patch->track->nudge = value;
732 if(patch->track->is_ganged() && patch->track->is_armed())
733 patch->patchbay->synchronize_nudge(patch->track->nudge, patch->track);
735 mwindow->undo->update_undo_after(_("nudge."), LOAD_PATCHES);
737 mwindow->gui->unlock_window();
738 if(patch->track->data_type == TRACK_VIDEO)
739 mwindow->restart_brender();
740 mwindow->sync_parameters(CHANGE_PARAMS);
741 mwindow->gui->lock_window("NudgePatch::handle_event 2");
743 mwindow->session->changes_made = 1;
747 int NudgePatch::button_press_event()
751 if(is_event_win() && cursor_inside())
753 if(get_buttonpress() == 4)
755 int value = patch->calculate_nudge(get_text());
756 value += calculate_increment();
762 if(get_buttonpress() == 5)
764 int value = patch->calculate_nudge(get_text());
765 value -= calculate_increment();
771 if(get_buttonpress() == 3)
773 patch->patchbay->nudge_popup->activate_menu(patch);
779 return BC_TextBox::button_press_event();
784 int64_t NudgePatch::calculate_increment()
786 if(patch->track->data_type == TRACK_AUDIO)
788 return (int64_t)ceil(patch->track->edl->session->sample_rate / 10.0);
792 return (int64_t)ceil(1.0 / patch->track->edl->session->frame_rate);
796 void NudgePatch::update()
799 char *string = patch->calculate_nudge_text(&changed);
801 BC_TextBox::update(string);
805 MixPatch::MixPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
806 : BC_Toggle(x, y, mwindow->theme->get_image_set("mixpatch_data"),
807 patch->mixer, "", 0, 0, 0)
809 this->mwindow = mwindow;
813 MixPatch::~MixPatch()
817 int MixPatch::handle_event()
819 int v = patch->track ? get_value() : 0;
820 if( patch->mixer != v ) {
822 mwindow->gui->update_mixers(patch->track, v);
825 mwindow->update_mixer_tracks();
830 void MixPatch::update(int v)
833 BC_Toggle::update(v);