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[] = {
211 for( int mode=0; mode<TRANSFER_TYPES; ++mode ) {
212 mode_icons[mode] = new BC_Pixmap(this,
213 mwindow->theme->get_image(mode_types[mode]),
217 add_subwindow(nudge_popup = new NudgePopup(mwindow, this));
218 nudge_popup->create_objects();
222 BC_Pixmap* PatchBay::mode_to_icon(int mode)
224 return mode_icons[mode];
227 int PatchBay::icon_to_mode(BC_Pixmap *icon)
229 for(int i = 0; i < TRANSFER_TYPES; i++)
230 if(icon == mode_icons[i]) return i;
231 return TRANSFER_NORMAL;
234 void PatchBay::resize_event()
236 reposition_window(mwindow->theme->patchbay_x,
237 mwindow->theme->patchbay_y,
238 mwindow->theme->patchbay_w,
239 mwindow->theme->patchbay_h);
240 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
245 void PatchBay::resize_event(int x, int y, int w, int h)
251 draw_top_background(get_parent(), 0, 0, w, h);
256 int PatchBay::button_press_event()
259 // Too much junk to support the wheel
263 int PatchBay::cursor_motion_event()
265 //int cursor_x = get_relative_cursor_x();
266 int cursor_y = get_relative_cursor_y();
269 if(drag_operation != Tracks::NONE)
274 // Get track we're inside of
275 for(Track *track = mwindow->edl->tracks->first;
279 int y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
280 int h = track->vertical_span(mwindow->theme);
281 if(cursor_y >= y && cursor_y < y + h)
283 switch(drag_operation)
286 if(track->play != new_status)
288 track->play = new_status;
289 mwindow->gui->unlock_window();
290 mwindow->restart_brender();
291 mwindow->sync_parameters(CHANGE_EDL);
292 mwindow->gui->lock_window();
297 if(track->record != new_status)
299 track->record = new_status;
304 if(track->gang != new_status)
306 track->gang = new_status;
311 if(track->draw != new_status)
313 track->draw = new_status;
318 if(track->expand_view != new_status)
320 track->expand_view = new_status;
321 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
322 gui->draw_trackmovement();
328 IntAuto *current = 0;
330 double position = mwindow->edl->local_session->get_selectionstart(1);
331 Autos *mute_autos = track->automation->autos[AUTOMATION_MUTE];
333 current = (IntAuto*)mute_autos->get_prev_auto(PLAY_FORWARD,
336 if(current->value != new_status)
339 // mwindow->undo->update_undo_before(_("keyframe"), this);
340 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
342 current->value = new_status;
344 // mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
346 mwindow->gui->unlock_window();
347 mwindow->restart_brender();
348 mwindow->sync_parameters(CHANGE_PARAMS);
349 mwindow->gui->lock_window();
351 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
353 gui->draw_overlays(1);
367 gui->update_patchbay();
372 void PatchBay::set_meter_format(int mode, int min, int max)
374 for(int i = 0; i < patches.total; i++)
376 PatchGUI *patchgui = patches.values[i];
377 if(patchgui->data_type == TRACK_AUDIO)
379 APatchGUI *apatchgui = (APatchGUI*)patchgui;
382 apatchgui->meter->change_format(mode, min, max);
388 void PatchBay::update_meters(ArrayList<double> *module_levels)
390 for(int level_number = 0, patch_number = 0;
391 patch_number < patches.total && level_number < module_levels->total;
394 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
396 if(patchgui->data_type == TRACK_AUDIO)
400 double level = module_levels->values[level_number];
401 patchgui->meter->update(level, level > 1);
409 void PatchBay::reset_meters()
411 for(int patch_number = 0;
412 patch_number < patches.total;
415 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
416 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
418 patchgui->meter->reset_over();
423 void PatchBay::stop_meters()
425 for(int patch_number = 0;
426 patch_number < patches.total;
429 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
430 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
432 patchgui->meter->reset();
440 int PatchBay::update()
444 // Every patch has a GUI regardless of whether or not it is visible.
445 // Make sure GUI's are allocated for every patch and deleted for non-existant
447 for(Track *current = mwindow->edl->tracks->first;
449 current = NEXT, patch_count++)
451 PatchGUI *patchgui = 0;
452 int y = current->y_pixel;
453 y -= mwindow->edl->local_session->track_start[pane->number];
455 //printf("PatchBay::update %d %d\n", __LINE__, y);
456 if(patches.total > patch_count)
458 if(patches.values[patch_count]->track_id != current->get_id())
460 delete patches.values[patch_count];
462 switch(current->data_type)
465 patchgui = patches.values[patch_count] = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
468 patchgui = patches.values[patch_count] = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
471 patchgui = patches.values[patch_count] = new SPatchGUI(mwindow, this, (STrack*)current, PATCH_X, y);
474 patchgui->create_objects();
478 patches.values[patch_count]->update(PATCH_X, y);
483 switch(current->data_type)
486 patchgui = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
489 patchgui = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
492 patchgui = new SPatchGUI(mwindow, this, (STrack*)current, PATCH_X, y);
495 patches.append(patchgui);
496 patchgui->create_objects();
500 while(patches.total > patch_count)
502 delete patches.values[patches.total - 1];
503 patches.remove_number(patches.total - 1);
510 void PatchBay::synchronize_faders(float change, int data_type, Track *skip)
512 for(Track *current = mwindow->edl->tracks->first;
516 if(current->data_type == data_type &&
521 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[AUTOMATION_FADE];
522 double position = mwindow->edl->local_session->get_selectionstart(1);
525 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_for_editing(position);
527 float new_value = keyframe->get_value() + change;
528 if(data_type == TRACK_AUDIO)
530 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
531 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
534 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
535 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
537 keyframe->set_value(new_value);
539 PatchGUI *patch = get_patch_of(current);
540 if(patch) patch->update(patch->x, patch->y);
545 void PatchBay::synchronize_nudge(int64_t value, Track *skip)
547 for(Track *current = mwindow->edl->tracks->first;
551 if(current->data_type == skip->data_type &&
556 current->nudge = value;
557 PatchGUI *patch = get_patch_of(current);
558 if(patch) patch->update(patch->x, patch->y);
563 PatchGUI* PatchBay::get_patch_of(Track *track)
565 for(int i = 0; i < patches.total; i++)
567 if(patches.values[i]->track == track)
568 return patches.values[i];
573 int PatchBay::resize_event(int top, int bottom)
575 reposition_window(mwindow->theme->patchbay_x,
576 mwindow->theme->patchbay_y,
577 mwindow->theme->patchbay_w,
578 mwindow->theme->patchbay_h);