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;
141 // *** CONTEXT_HELP ***
142 context_help_set_keyword("The Patchbay");
145 PatchBay::PatchBay(MWindow *mwindow,
156 this->mwindow = mwindow;
157 this->gui = mwindow->gui;
159 drag_operation = Tracks::NONE;
160 for(int i = 0; i < TRANSFER_TYPES; i++) mode_icons[i] = 0;
161 // *** CONTEXT_HELP ***
162 context_help_set_keyword("The Patchbay");
163 // printf("PatchBay::PatchBay %d %d %d %d %d\n",
171 PatchBay::~PatchBay()
173 delete_all_patches();
174 for(int i = 0; i < TRANSFER_TYPES; i++) delete mode_icons[i];
178 int PatchBay::delete_all_patches()
180 patches.remove_all_objects();
184 void PatchBay::create_objects()
186 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
189 // Create icons for mode types
190 static const char *mode_types[] = {
222 for( int mode=0; mode<TRANSFER_TYPES; ++mode ) {
223 mode_icons[mode] = new BC_Pixmap(this,
224 mwindow->theme->get_image(mode_types[mode]),
228 add_subwindow(nudge_popup = new NudgePopup(mwindow, this));
229 nudge_popup->create_objects();
233 BC_Pixmap* PatchBay::mode_to_icon(int mode)
235 return mode_icons[mode];
238 int PatchBay::icon_to_mode(BC_Pixmap *icon)
240 for(int i = 0; i < TRANSFER_TYPES; i++)
241 if(icon == mode_icons[i]) return i;
242 return TRANSFER_NORMAL;
245 void PatchBay::resize_event()
247 reposition_window(mwindow->theme->patchbay_x,
248 mwindow->theme->patchbay_y,
249 mwindow->theme->patchbay_w,
250 mwindow->theme->patchbay_h);
251 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
256 void PatchBay::resize_event(int x, int y, int w, int h)
262 draw_top_background(get_parent(), 0, 0, w, h);
267 int PatchBay::button_press_event()
270 // Too much junk to support the wheel
274 int PatchBay::cursor_motion_event()
276 //int cursor_x = get_relative_cursor_x();
277 int cursor_y = get_relative_cursor_y();
280 if(drag_operation != Tracks::NONE)
285 // Get track we're inside of
286 for(Track *track = mwindow->edl->tracks->first;
290 if( track->is_hidden() ) continue;
291 int y = track->y_pixel - mwindow->edl->local_session->track_start[pane->number];
292 int h = track->vertical_span(mwindow->theme);
293 if(cursor_y >= y && cursor_y < y + h)
295 switch(drag_operation)
298 if(track->play != new_status)
300 track->play = new_status;
301 mwindow->gui->unlock_window();
302 mwindow->restart_brender();
303 mwindow->sync_parameters(CHANGE_EDL);
304 mwindow->gui->lock_window();
309 if(track->armed != new_status)
311 track->armed = new_status;
316 if(track->ganged != new_status)
318 track->ganged = new_status;
323 if(track->draw != new_status)
325 track->draw = new_status;
330 if(track->expand_view != new_status)
332 track->expand_view = new_status;
333 mwindow->edl->tracks->update_y_pixels(mwindow->theme);
334 gui->draw_trackmovement();
340 IntAuto *current = 0;
342 double position = mwindow->edl->local_session->get_selectionstart(1);
343 Autos *mute_autos = track->automation->autos[AUTOMATION_MUTE];
345 current = (IntAuto*)mute_autos->get_prev_auto(PLAY_FORWARD,
348 if(current->value != new_status)
351 // mwindow->undo->update_undo_before(_("keyframe"), this);
352 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
354 current->value = new_status;
356 // mwindow->undo->update_undo_after(_("keyframe"), LOAD_AUTOMATION);
358 mwindow->gui->unlock_window();
359 mwindow->restart_brender();
360 mwindow->sync_parameters(CHANGE_PARAMS);
361 mwindow->gui->lock_window();
363 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
365 gui->draw_overlays(1);
379 gui->update_patchbay();
384 void PatchBay::set_meter_format(int mode, int min, int max)
386 for(int i = 0; i < patches.total; i++)
388 PatchGUI *patchgui = patches.values[i];
389 if(patchgui->data_type == TRACK_AUDIO)
391 APatchGUI *apatchgui = (APatchGUI*)patchgui;
394 apatchgui->meter->change_format(mode, min, max);
400 void PatchBay::update_meters(ArrayList<double> *module_levels)
402 for(int level_number = 0, patch_number = 0;
403 patch_number < patches.total && level_number < module_levels->total;
406 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
408 if(patchgui->data_type == TRACK_AUDIO)
412 double level = module_levels->values[level_number];
413 patchgui->meter->update(level, level > 1);
421 void PatchBay::reset_meters()
423 for(int patch_number = 0;
424 patch_number < patches.total;
427 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
428 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
430 patchgui->meter->reset_over();
435 void PatchBay::stop_meters()
437 for(int patch_number = 0;
438 patch_number < patches.total;
441 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
442 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
444 patchgui->meter->reset();
452 int PatchBay::update()
456 // Every patch has a GUI regardless of whether or not it is visible.
457 // Make sure GUI's are allocated for every patch and deleted for non-existant
459 for(Track *current = mwindow->edl->tracks->first; current; current = NEXT)
461 if( current->is_hidden() ) continue;
462 PatchGUI *patchgui = 0;
463 int y = current->y_pixel;
464 y -= mwindow->edl->local_session->track_start[pane->number];
466 //printf("PatchBay::update %d %d\n", __LINE__, y);
467 if(patches.total > patch_count)
469 if(patches.values[patch_count]->track_id != current->get_id())
471 delete patches.values[patch_count];
473 switch(current->data_type)
476 patchgui = patches.values[patch_count] = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
479 patchgui = patches.values[patch_count] = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
482 patchgui = patches.values[patch_count] = new SPatchGUI(mwindow, this, (STrack*)current, PATCH_X, y);
485 patchgui->create_objects();
489 patches.values[patch_count]->update(PATCH_X, y);
494 switch(current->data_type)
497 patchgui = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
500 patchgui = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
503 patchgui = new SPatchGUI(mwindow, this, (STrack*)current, PATCH_X, y);
506 patches.append(patchgui);
507 patchgui->create_objects();
512 while(patches.total > patch_count)
514 delete patches.values[patches.total - 1];
515 patches.remove_number(patches.total - 1);
522 void PatchBay::synchronize_faders(float dv, int data_type, Track *skip, int edge, int span)
524 for( Track *current=mwindow->edl->tracks->first; current; current=NEXT ) {
525 if( current == skip ) continue;
526 if( skip && !current->armed_gang(skip) ) continue;
527 if( current->data_type != data_type ) continue;
528 if( !current->is_armed() ) continue;
529 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[AUTOMATION_FADE];
530 double position = mwindow->edl->local_session->get_selectionstart(1);
531 FloatAuto *float_auto = (FloatAuto*)fade_autos->get_auto_for_editing(position);
532 int64_t pos = float_auto->position;
533 float_auto->bump_update(pos, dv, edge, span);
534 PatchGUI *patch = get_patch_of(current);
535 if( patch ) patch->update(patch->x, patch->y);
539 void PatchBay::synchronize_nudge(int64_t value, Track *skip)
541 Track *current = mwindow->edl->tracks->first;
542 for( ; current; current = NEXT ) {
543 if( current->data_type == skip->data_type &&
544 current->armed_gang(skip) && current->is_armed() &&
546 current->nudge = value;
547 PatchGUI *patch = get_patch_of(current);
548 if(patch) patch->update(patch->x, patch->y);
553 PatchGUI* PatchBay::get_patch_of(Track *track)
555 for(int i = 0; i < patches.total; i++)
557 if(patches.values[i]->track == track)
558 return patches.values[i];
563 int PatchBay::resize_event(int top, int bottom)
565 reposition_window(mwindow->theme->patchbay_x,
566 mwindow->theme->patchbay_y,
567 mwindow->theme->patchbay_w,
568 mwindow->theme->patchbay_h);