4 * Copyright (C) 1997-2014 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 "apatchgui.h"
23 #include "automation.h"
24 #include "floatauto.h"
25 #include "floatautos.h"
28 #include "edlsession.h"
33 #include "localsession.h"
36 #include "mwindowgui.h"
39 #include "mainsession.h"
42 #include "timelinepane.h"
44 #include "trackcanvas.h"
46 #include "vpatchgui.h"
53 NudgePopup::NudgePopup(MWindow *mwindow, PatchBay *patchbay)
60 this->mwindow = mwindow;
61 this->patchbay = patchbay;
64 NudgePopup::~NudgePopup()
69 void NudgePopup::create_objects()
71 add_item(seconds_item = new NudgePopupSeconds(this));
72 add_item(native_item = new NudgePopupNative(this));
75 void NudgePopup::activate_menu(PatchGUI *gui)
78 seconds_item->set_checked(mwindow->edl->session->nudge_format ? 1 : 0);
79 native_item->set_checked(mwindow->edl->session->nudge_format ? 0 : 1);
81 // Set native units to track format
82 native_item->set_text(gui->track->data_type == TRACK_AUDIO ?
87 BC_PopupMenu::activate_menu();
92 NudgePopupSeconds::NudgePopupSeconds(NudgePopup *popup)
93 : BC_MenuItem(_("Seconds"))
98 int NudgePopupSeconds::handle_event()
100 popup->mwindow->edl->session->nudge_format = 1;
101 popup->mwindow->gui->update_patchbay();
109 NudgePopupNative::NudgePopupNative(NudgePopup *popup)
115 int NudgePopupNative::handle_event()
117 popup->mwindow->edl->session->nudge_format = 0;
118 popup->mwindow->gui->update_patchbay();
130 PatchBay::PatchBay(MWindow *mwindow, MWindowGUI *gui)
131 : BC_SubWindow(mwindow->theme->patchbay_x,
132 mwindow->theme->patchbay_y,
133 mwindow->theme->patchbay_w,
134 mwindow->theme->patchbay_h)
136 this->mwindow = mwindow;
139 drag_operation = Tracks::NONE;
140 for(int i = 0; i < TRANSFER_TYPES; i++) mode_icons[i] = 0;
143 PatchBay::PatchBay(MWindow *mwindow,
154 this->mwindow = mwindow;
155 this->gui = mwindow->gui;
157 drag_operation = Tracks::NONE;
158 for(int i = 0; i < TRANSFER_TYPES; i++) mode_icons[i] = 0;
159 // printf("PatchBay::PatchBay %d %d %d %d %d\n",
167 PatchBay::~PatchBay()
169 delete_all_patches();
170 for(int i = 0; i < TRANSFER_TYPES; i++) delete mode_icons[i];
174 int PatchBay::delete_all_patches()
176 patches.remove_all_objects();
180 void PatchBay::create_objects()
182 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
185 // Create icons for mode types
186 static const char *mode_types[] = {
218 for( int mode=0; mode<TRANSFER_TYPES; ++mode ) {
219 mode_icons[mode] = new BC_Pixmap(this,
220 mwindow->theme->get_image(mode_types[mode]),
224 add_subwindow(nudge_popup = new NudgePopup(mwindow, this));
225 nudge_popup->create_objects();
229 BC_Pixmap* PatchBay::mode_to_icon(int mode)
231 return mode_icons[mode];
234 int PatchBay::icon_to_mode(BC_Pixmap *icon)
236 for(int i = 0; i < TRANSFER_TYPES; i++)
237 if(icon == mode_icons[i]) return i;
238 return TRANSFER_NORMAL;
241 void PatchBay::resize_event()
243 reposition_window(mwindow->theme->patchbay_x,
244 mwindow->theme->patchbay_y,
245 mwindow->theme->patchbay_w,
246 mwindow->theme->patchbay_h);
247 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
252 void PatchBay::resize_event(int x, int y, int w, int h)
258 draw_top_background(get_parent(), 0, 0, w, h);
263 int PatchBay::button_press_event()
266 // Too much junk to support the wheel
270 int PatchBay::cursor_motion_event()
272 //int cursor_x = get_relative_cursor_x();
273 int cursor_y = get_relative_cursor_y();
276 if(drag_operation != Tracks::NONE)
281 // Get track we're inside of
282 for(Track *track = mwindow->edl->tracks->first;
286 int y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
287 int h = track->vertical_span(mwindow->theme);
288 if(cursor_y >= y && cursor_y < y + h)
290 switch(drag_operation)
293 if(track->play != new_status)
295 track->play = new_status;
296 mwindow->gui->unlock_window();
297 mwindow->restart_brender();
298 mwindow->sync_parameters(CHANGE_EDL);
299 mwindow->gui->lock_window();
304 if(track->record != new_status)
306 track->record = new_status;
311 if(track->gang != new_status)
313 track->gang = new_status;
318 if(track->draw != new_status)
320 track->draw = new_status;
325 if(track->expand_view != new_status)
327 track->expand_view = new_status;
328 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
329 gui->draw_trackmovement();
335 IntAuto *current = 0;
337 double position = mwindow->edl->local_session->get_selectionstart(1);
338 Autos *mute_autos = track->automation->autos[AUTOMATION_MUTE];
340 current = (IntAuto*)mute_autos->get_prev_auto(PLAY_FORWARD,
343 if(current->value != new_status)
346 // mwindow->undo->update_undo_before(_("keyframe"), this);
347 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
349 current->value = new_status;
351 // mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
353 mwindow->gui->unlock_window();
354 mwindow->restart_brender();
355 mwindow->sync_parameters(CHANGE_PARAMS);
356 mwindow->gui->lock_window();
358 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
360 gui->draw_overlays(1);
374 gui->update_patchbay();
379 void PatchBay::set_meter_format(int mode, int min, int max)
381 for(int i = 0; i < patches.total; i++)
383 PatchGUI *patchgui = patches.values[i];
384 if(patchgui->data_type == TRACK_AUDIO)
386 APatchGUI *apatchgui = (APatchGUI*)patchgui;
389 apatchgui->meter->change_format(mode, min, max);
395 void PatchBay::update_meters(ArrayList<double> *module_levels)
397 for(int level_number = 0, patch_number = 0;
398 patch_number < patches.total && level_number < module_levels->total;
401 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
403 if(patchgui->data_type == TRACK_AUDIO)
407 double level = module_levels->values[level_number];
408 patchgui->meter->update(level, level > 1);
416 void PatchBay::reset_meters()
418 for(int patch_number = 0;
419 patch_number < patches.total;
422 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
423 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
425 patchgui->meter->reset_over();
430 void PatchBay::stop_meters()
432 for(int patch_number = 0;
433 patch_number < patches.total;
436 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
437 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
439 patchgui->meter->reset();
447 int PatchBay::update()
451 // Every patch has a GUI regardless of whether or not it is visible.
452 // Make sure GUI's are allocated for every patch and deleted for non-existant
454 for(Track *current = mwindow->edl->tracks->first;
456 current = NEXT, patch_count++)
458 PatchGUI *patchgui = 0;
459 int y = current->y_pixel;
460 y -= mwindow->edl->local_session->track_start[pane->number];
462 //printf("PatchBay::update %d %d\n", __LINE__, y);
463 if(patches.total > patch_count)
465 if(patches.values[patch_count]->track_id != current->get_id())
467 delete patches.values[patch_count];
469 switch(current->data_type)
472 patchgui = patches.values[patch_count] = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
475 patchgui = patches.values[patch_count] = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
478 patchgui = patches.values[patch_count] = new SPatchGUI(mwindow, this, (STrack*)current, PATCH_X, y);
481 patchgui->create_objects();
485 patches.values[patch_count]->update(PATCH_X, y);
490 switch(current->data_type)
493 patchgui = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
496 patchgui = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
499 patchgui = new SPatchGUI(mwindow, this, (STrack*)current, PATCH_X, y);
502 patches.append(patchgui);
503 patchgui->create_objects();
507 while(patches.total > patch_count)
509 delete patches.values[patches.total - 1];
510 patches.remove_number(patches.total - 1);
517 void PatchBay::synchronize_faders(float change, int data_type, Track *skip)
519 for(Track *current = mwindow->edl->tracks->first;
523 if(current->data_type == data_type &&
528 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[AUTOMATION_FADE];
529 double position = mwindow->edl->local_session->get_selectionstart(1);
532 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_for_editing(position);
534 float new_value = keyframe->get_value() + change;
535 if(data_type == TRACK_AUDIO)
537 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
538 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
541 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
542 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
544 keyframe->set_value(new_value);
546 PatchGUI *patch = get_patch_of(current);
547 if(patch) patch->update(patch->x, patch->y);
552 void PatchBay::synchronize_nudge(int64_t value, Track *skip)
554 for(Track *current = mwindow->edl->tracks->first;
558 if(current->data_type == skip->data_type &&
563 current->nudge = value;
564 PatchGUI *patch = get_patch_of(current);
565 if(patch) patch->update(patch->x, patch->y);
570 PatchGUI* PatchBay::get_patch_of(Track *track)
572 for(int i = 0; i < patches.total; i++)
574 if(patches.values[i]->track == track)
575 return patches.values[i];
580 int PatchBay::resize_event(int top, int bottom)
582 reposition_window(mwindow->theme->patchbay_x,
583 mwindow->theme->patchbay_y,
584 mwindow->theme->patchbay_w,
585 mwindow->theme->patchbay_h);