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(mwindow->get_int_auto(this, AUTOMATION_MUTE)->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()) {
241 int sense = type != Tracks::MUTE ? 1 : 0;
242 // all selected if nothing previously selected or
243 // if this patch was previously the only one selected
244 int total_type = mwindow->edl->tracks->total_of(type);
245 int total_selected = sense ? total_type :
246 mwindow->edl->tracks->total() - total_type;
247 int selected = !total_selected || (total_selected == 1 &&
248 *output == sense ) ? sense : 1-sense;
249 mwindow->edl->tracks->select_all(type, selected);
250 if( selected != sense ) *output = sense;
252 patchbay->drag_operation = type;
253 patchbay->new_status = 1;
258 // Select + drag behavior
259 patchbay->drag_operation = type;
260 patchbay->new_status = value;
266 mwindow->gui->unlock_window();
267 mwindow->restart_brender();
268 mwindow->sync_parameters(CHANGE_EDL);
269 mwindow->gui->lock_window("PatchGUI::toggle_behavior 1");
273 mwindow->gui->unlock_window();
274 mwindow->restart_brender();
275 mwindow->sync_parameters(CHANGE_PARAMS);
276 mwindow->gui->lock_window("PatchGUI::toggle_behavior 2");
279 // Update affected tracks in cwindow
281 mwindow->cwindow->update(0, 1, 1);
288 mwindow->gui->update(0, 1, 0, 0, 0, 0, 0);
296 mwindow->gui->update_patchbay();
300 char* PatchGUI::calculate_nudge_text(int *changed)
302 if(changed) *changed = 0;
303 if(track->edl->session->nudge_format)
305 sprintf(string_return, "%.4f", track->from_units(track->nudge));
306 if(changed && nudge && atof(nudge->get_text()) - atof(string_return) != 0)
311 sprintf(string_return, "%jd", track->nudge);
312 if(changed && nudge && atoi(nudge->get_text()) - atoi(string_return) != 0)
315 return string_return;
319 int64_t PatchGUI::calculate_nudge(const char *string)
321 if(mwindow->edl->session->nudge_format)
324 sscanf(string, "%f", &result);
325 return track->to_units(result, 0);
330 sscanf(string, "%jd", &temp);
346 PlayPatch::PlayPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
349 mwindow->theme->get_image_set("playpatch_data"),
356 this->mwindow = mwindow;
358 set_tooltip(_("Play track"));
362 int PlayPatch::button_press_event()
364 if(is_event_win() && get_buttonpress() == 1)
366 mwindow->undo->update_undo_before();
367 set_status(BC_Toggle::TOGGLE_DOWN);
368 update(!get_value());
369 patch->toggle_behavior(Tracks::PLAY,
372 &patch->track->play);
378 int PlayPatch::button_release_event()
380 int result = BC_Toggle::button_release_event();
381 if(patch->patchbay->drag_operation == Tracks::PLAY)
383 mwindow->undo->update_undo_after(_("play patch"), LOAD_PATCHES);
384 patch->patchbay->drag_operation = Tracks::NONE;
399 RecordPatch::RecordPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
402 mwindow->theme->get_image_set("recordpatch_data"),
403 patch->track->record,
409 this->mwindow = mwindow;
411 set_tooltip(_("Arm track"));
415 int RecordPatch::button_press_event()
417 if(is_event_win() && get_buttonpress() == 1)
419 mwindow->undo->update_undo_before();
420 set_status(BC_Toggle::TOGGLE_DOWN);
421 update(!get_value());
422 patch->toggle_behavior(Tracks::RECORD,
425 &patch->track->record);
431 int RecordPatch::button_release_event()
433 int result = BC_Toggle::button_release_event();
434 if(patch->patchbay->drag_operation == Tracks::RECORD)
436 mwindow->undo->update_undo_after(_("record patch"), LOAD_PATCHES);
437 patch->patchbay->drag_operation = Tracks::NONE;
452 GangPatch::GangPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
454 mwindow->theme->get_image_set("gangpatch_data"),
461 this->mwindow = mwindow;
463 set_tooltip(_("Gang faders"));
467 int GangPatch::button_press_event()
469 if(is_event_win() && get_buttonpress() == 1)
471 mwindow->undo->update_undo_before();
472 set_status(BC_Toggle::TOGGLE_DOWN);
473 update(!get_value());
474 patch->toggle_behavior(Tracks::GANG,
477 &patch->track->gang);
483 int GangPatch::button_release_event()
485 int result = BC_Toggle::button_release_event();
486 if(patch->patchbay->drag_operation == Tracks::GANG)
488 mwindow->undo->update_undo_after(_("gang patch"), LOAD_PATCHES);
489 patch->patchbay->drag_operation = Tracks::NONE;
504 DrawPatch::DrawPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
506 mwindow->theme->get_image_set("drawpatch_data"),
513 this->mwindow = mwindow;
515 set_tooltip(_("Draw media"));
519 int DrawPatch::button_press_event()
521 if(is_event_win() && get_buttonpress() == 1)
523 mwindow->undo->update_undo_before();
524 set_status(BC_Toggle::TOGGLE_DOWN);
525 update(!get_value());
526 patch->toggle_behavior(Tracks::DRAW,
529 &patch->track->draw);
535 int DrawPatch::button_release_event()
537 int result = BC_Toggle::button_release_event();
538 if(patch->patchbay->drag_operation == Tracks::DRAW)
540 mwindow->undo->update_undo_after(_("draw patch"), LOAD_PATCHES);
541 patch->patchbay->drag_operation = Tracks::NONE;
555 MutePatch::MutePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
557 mwindow->theme->get_image_set("mutepatch_data"),
558 mwindow->get_int_auto(patch, AUTOMATION_MUTE)->value,
564 this->mwindow = mwindow;
566 set_tooltip(_("Don't send to output"));
570 int MutePatch::button_press_event()
572 if(is_event_win() && get_buttonpress() == 1)
574 mwindow->undo->update_undo_before();
575 set_status(BC_Toggle::TOGGLE_DOWN);
576 update(!get_value());
578 double position = mwindow->edl->local_session->get_selectionstart(1);
579 Autos *mute_autos = patch->track->automation->autos[AUTOMATION_MUTE];
582 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
583 current->value = get_value();
585 patch->toggle_behavior(Tracks::MUTE,
592 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
594 mwindow->gui->draw_overlays(1);
601 int MutePatch::button_release_event()
603 int result = BC_Toggle::button_release_event();
604 if(patch->patchbay->drag_operation == Tracks::MUTE)
606 mwindow->undo->update_undo_after(_("mute patch"), LOAD_PATCHES);
607 patch->patchbay->drag_operation = Tracks::NONE;
614 ExpandPatch::ExpandPatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
617 mwindow->theme->get_image_set("expandpatch_data"),
618 patch->track->expand_view,
624 this->mwindow = mwindow;
629 int ExpandPatch::button_press_event()
631 if(is_event_win() && get_buttonpress() == 1)
633 mwindow->undo->update_undo_before();
634 set_status(BC_Toggle::TOGGLE_DOWN);
635 update(!get_value());
636 patch->toggle_behavior(Tracks::EXPAND,
639 &patch->track->expand_view);
640 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
641 mwindow->gui->draw_trackmovement();
647 int ExpandPatch::button_release_event()
649 int result = BC_Toggle::button_release_event();
650 if(patch->patchbay->drag_operation == Tracks::EXPAND)
652 mwindow->undo->update_undo_after(_("expand patch"), LOAD_PATCHES);
653 patch->patchbay->drag_operation = Tracks::NONE;
662 TitlePatch::TitlePatch(MWindow *mwindow, PatchGUI *patch, int x, int y)
665 patch->patchbay->get_w() - 10,
670 this->mwindow = mwindow;
674 int TitlePatch::handle_event()
676 mwindow->undo->update_undo_before(_("track title"), this);
677 strcpy(patch->track->title, get_text());
678 mwindow->update_plugin_titles();
679 mwindow->gui->draw_overlays(1);
680 mwindow->undo->update_undo_after(_("track title"), LOAD_PATCHES);
692 NudgePatch::NudgePatch(MWindow *mwindow,
701 patch->calculate_nudge_text(0))
703 this->mwindow = mwindow;
705 set_tooltip(_("Nudge"));
708 int NudgePatch::handle_event()
710 set_value(patch->calculate_nudge(get_text()));
714 void NudgePatch::set_value(int64_t value)
716 mwindow->undo->update_undo_before(_("nudge"), this);
717 patch->track->nudge = value;
719 if(patch->track->gang && patch->track->record)
720 patch->patchbay->synchronize_nudge(patch->track->nudge, patch->track);
722 mwindow->undo->update_undo_after(_("nudge"), LOAD_PATCHES);
724 mwindow->gui->unlock_window();
725 if(patch->track->data_type == TRACK_VIDEO)
726 mwindow->restart_brender();
727 mwindow->sync_parameters(CHANGE_PARAMS);
728 mwindow->gui->lock_window("NudgePatch::handle_event 2");
730 mwindow->session->changes_made = 1;
734 int NudgePatch::button_press_event()
738 if(is_event_win() && cursor_inside())
740 if(get_buttonpress() == 4)
742 int value = patch->calculate_nudge(get_text());
743 value += calculate_increment();
749 if(get_buttonpress() == 5)
751 int value = patch->calculate_nudge(get_text());
752 value -= calculate_increment();
758 if(get_buttonpress() == 3)
760 patch->patchbay->nudge_popup->activate_menu(patch);
766 return BC_TextBox::button_press_event();
771 int64_t NudgePatch::calculate_increment()
773 if(patch->track->data_type == TRACK_AUDIO)
775 return (int64_t)ceil(patch->track->edl->session->sample_rate / 10.0);
779 return (int64_t)ceil(1.0 / patch->track->edl->session->frame_rate);
783 void NudgePatch::update()
786 char *string = patch->calculate_nudge_text(&changed);
788 BC_TextBox::update(string);