2 #include "automation.h"
4 #include "floatautos.h"
7 #include "edlsession.h"
12 #include "localsession.h"
15 #include "mwindowgui.h"
18 #include "mainsession.h"
21 #include "trackcanvas.h"
23 #include "vpatchgui.h"
30 NudgePopup::NudgePopup(MWindow *mwindow, PatchBay *patchbay)
37 this->mwindow = mwindow;
38 this->patchbay = patchbay;
41 NudgePopup::~NudgePopup()
46 void NudgePopup::create_objects()
48 add_item(seconds_item = new NudgePopupSeconds(this));
49 add_item(native_item = new NudgePopupNative(this));
52 void NudgePopup::activate_menu(PatchGUI *gui)
55 seconds_item->set_checked(mwindow->edl->session->nudge_seconds ? 1 : 0);
56 native_item->set_checked(mwindow->edl->session->nudge_seconds ? 0 : 1);
58 // Set native units to track format
59 native_item->set_text(gui->track->data_type == TRACK_AUDIO ?
64 BC_PopupMenu::activate_menu();
69 NudgePopupSeconds::NudgePopupSeconds(NudgePopup *popup)
70 : BC_MenuItem("Seconds")
75 int NudgePopupSeconds::handle_event()
77 popup->mwindow->edl->session->nudge_seconds = 1;
78 popup->patchbay->update();
86 NudgePopupNative::NudgePopupNative(NudgePopup *popup)
92 int NudgePopupNative::handle_event()
94 popup->mwindow->edl->session->nudge_seconds = 0;
95 popup->patchbay->update();
107 PatchBay::PatchBay(MWindow *mwindow, MWindowGUI *gui)
108 : BC_SubWindow(mwindow->theme->patchbay_x,
109 mwindow->theme->patchbay_y,
110 mwindow->theme->patchbay_w,
111 mwindow->theme->patchbay_h)
113 this->mwindow = mwindow;
116 reconfigure_trigger = 0;
117 drag_operation = Tracks::NONE;
120 PatchBay::~PatchBay()
125 int PatchBay::delete_all_patches()
127 patches.remove_all_objects();
131 int PatchBay::create_objects()
133 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
136 // Create icons for mode types
137 mode_icons[TRANSFER_NORMAL] = new BC_Pixmap(this,
138 mwindow->theme->get_image("mode_normal"),
140 mode_icons[TRANSFER_ADDITION] = new BC_Pixmap(this,
141 mwindow->theme->get_image("mode_add"),
143 mode_icons[TRANSFER_SUBTRACT] = new BC_Pixmap(this,
144 mwindow->theme->get_image("mode_subtract"),
146 mode_icons[TRANSFER_MULTIPLY] = new BC_Pixmap(this,
147 mwindow->theme->get_image("mode_multiply"),
149 mode_icons[TRANSFER_DIVIDE] = new BC_Pixmap(this,
150 mwindow->theme->get_image("mode_divide"),
152 mode_icons[TRANSFER_REPLACE] = new BC_Pixmap(this,
153 mwindow->theme->get_image("mode_replace"),
155 mode_icons[TRANSFER_MAX] = new BC_Pixmap(this,
156 mwindow->theme->get_image("mode_max"),
159 add_subwindow(nudge_popup = new NudgePopup(mwindow, this));
160 nudge_popup->create_objects();
165 BC_Pixmap* PatchBay::mode_to_icon(int mode)
167 return mode_icons[mode];
170 int PatchBay::icon_to_mode(BC_Pixmap *icon)
172 for(int i = 0; i < TRANSFER_TYPES; i++)
173 if(icon == mode_icons[i]) return i;
174 return TRANSFER_NORMAL;
177 void PatchBay::resize_event()
179 reposition_window(mwindow->theme->patchbay_x,
180 mwindow->theme->patchbay_y,
181 mwindow->theme->patchbay_w,
182 mwindow->theme->patchbay_h);
183 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
188 int PatchBay::button_press_event()
191 // Too much junk to support the wheel
196 Track *PatchBay::is_over_track() // called from mwindow
198 int cursor_x = get_relative_cursor_x();
199 int cursor_y = get_relative_cursor_y();
200 Track *over_track = 0;
202 if(get_cursor_over_window() &&
205 cursor_x < get_w() &&
208 // Get track we're inside of
209 for(Track *track = mwindow->edl->tracks->first;
213 int y = track->y_pixel;
214 int h = track->vertical_span(mwindow->theme);
215 if(cursor_y >= y && cursor_y < y + h)
225 int PatchBay::cursor_motion_event()
227 int cursor_x = get_relative_cursor_x();
228 int cursor_y = get_relative_cursor_y();
231 if(drag_operation != Tracks::NONE)
236 // Get track we're inside of
237 for(Track *track = mwindow->edl->tracks->first;
241 int y = track->y_pixel;
242 int h = track->vertical_span(mwindow->theme);
243 if(cursor_y >= y && cursor_y < y + h)
245 switch(drag_operation)
248 if(track->play != new_status)
250 track->play = new_status;
251 mwindow->gui->unlock_window();
252 mwindow->restart_brender();
253 mwindow->sync_parameters(CHANGE_EDL);
254 mwindow->gui->lock_window();
259 if(track->record != new_status)
261 track->record = new_status;
266 if(track->gang != new_status)
268 track->gang = new_status;
273 if(track->draw != new_status)
275 track->draw = new_status;
280 if(track->expand_view != new_status)
282 track->expand_view = new_status;
283 mwindow->trackmovement(mwindow->edl->local_session->track_start);
289 IntAuto *current = 0;
291 double position = mwindow->edl->local_session->get_selectionstart(1);
292 Autos *mute_autos = track->automation->autos[AUTOMATION_MUTE];
294 current = (IntAuto*)mute_autos->get_prev_auto(PLAY_FORWARD,
297 if(current->value != new_status)
300 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
302 current->value = new_status;
304 mwindow->undo->update_undo(_("keyframe"), LOAD_AUTOMATION);
306 mwindow->gui->unlock_window();
307 mwindow->restart_brender();
308 mwindow->sync_parameters(CHANGE_PARAMS);
309 mwindow->gui->lock_window();
311 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
313 mwindow->gui->canvas->draw_overlays();
314 mwindow->gui->canvas->flash();
333 void PatchBay::change_meter_format(int mode, int min, int max)
335 for(int i = 0; i < patches.total; i++)
337 PatchGUI *patchgui = patches.values[i];
338 if(patchgui->data_type == TRACK_AUDIO)
340 APatchGUI *apatchgui = (APatchGUI*)patchgui;
343 apatchgui->meter->change_format(mode, min, max);
349 void PatchBay::update_meters(ArrayList<double> *module_levels)
351 for(int level_number = 0, patch_number = 0;
352 patch_number < patches.total && level_number < module_levels->total;
355 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
357 if(patchgui->data_type == TRACK_AUDIO)
361 double level = module_levels->values[level_number];
362 patchgui->meter->update(level, level > 1);
370 void PatchBay::reset_meters()
372 for(int patch_number = 0;
373 patch_number < patches.total;
376 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
377 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
379 patchgui->meter->reset_over();
384 void PatchBay::stop_meters()
386 for(int patch_number = 0;
387 patch_number < patches.total;
390 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
391 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
393 patchgui->meter->reset();
401 int PatchBay::update()
405 // Every patch has a GUI regardless of whether or not it is visible.
406 // Make sure GUI's are allocated for every patch and deleted for non-existant
408 for(Track *current = mwindow->edl->tracks->first;
410 current = NEXT, patch_count++)
413 int y = current->y_pixel;
415 if(patches.total > patch_count)
417 if(patches.values[patch_count]->track_id != current->get_id())
419 delete patches.values[patch_count];
421 switch(current->data_type)
424 patchgui = patches.values[patch_count] = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
427 patchgui = patches.values[patch_count] = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
430 patchgui->create_objects();
434 patches.values[patch_count]->update(PATCH_X, y);
439 switch(current->data_type)
442 patchgui = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
445 patchgui = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
448 patches.append(patchgui);
449 patchgui->create_objects();
453 while(patches.total > patch_count)
455 delete patches.values[patches.total - 1];
456 patches.remove_number(patches.total - 1);
462 void PatchBay::synchronize_faders(float change, int data_type, Track *skip)
464 for(Track *current = mwindow->edl->tracks->first;
468 if(current->data_type == data_type &&
473 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[AUTOMATION_FADE];
474 double position = mwindow->edl->local_session->get_selectionstart(1);
477 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_for_editing(position);
479 keyframe->value += change;
480 if(data_type == TRACK_AUDIO)
481 CLAMP(keyframe->value,
482 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
483 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
485 CLAMP(keyframe->value,
486 mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_VIDEO_FADE],
487 mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_VIDEO_FADE]);
489 PatchGUI *patch = get_patch_of(current);
490 if(patch) patch->update(patch->x, patch->y);
495 void PatchBay::synchronize_nudge(int64_t value, Track *skip)
497 for(Track *current = mwindow->edl->tracks->first;
501 if(current->data_type == skip->data_type &&
506 current->nudge = value;
507 PatchGUI *patch = get_patch_of(current);
508 if(patch) patch->update(patch->x, patch->y);
513 PatchGUI* PatchBay::get_patch_of(Track *track)
515 for(int i = 0; i < patches.total; i++)
517 if(patches.values[i]->track == track)
518 return patches.values[i];
523 int PatchBay::resize_event(int top, int bottom)
525 reposition_window(mwindow->theme->patchbay_x,
526 mwindow->theme->patchbay_y,
527 mwindow->theme->patchbay_w,
528 mwindow->theme->patchbay_h);