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"),
156 add_subwindow(nudge_popup = new NudgePopup(mwindow, this));
157 nudge_popup->create_objects();
162 BC_Pixmap* PatchBay::mode_to_icon(int mode)
164 return mode_icons[mode];
167 int PatchBay::icon_to_mode(BC_Pixmap *icon)
169 for(int i = 0; i < TRANSFER_TYPES; i++)
170 if(icon == mode_icons[i]) return i;
171 return TRANSFER_NORMAL;
174 void PatchBay::resize_event()
176 reposition_window(mwindow->theme->patchbay_x,
177 mwindow->theme->patchbay_y,
178 mwindow->theme->patchbay_w,
179 mwindow->theme->patchbay_h);
180 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
185 int PatchBay::button_press_event()
188 // Too much junk to support the wheel
193 Track *PatchBay::is_over_track() // called from mwindow
195 int cursor_x = get_relative_cursor_x();
196 int cursor_y = get_relative_cursor_y();
197 Track *over_track = 0;
199 if(get_cursor_over_window() &&
202 cursor_x < get_w() &&
205 // Get track we're inside of
206 for(Track *track = mwindow->edl->tracks->first;
210 int y = track->y_pixel;
211 int h = track->vertical_span(mwindow->theme);
212 if(cursor_y >= y && cursor_y < y + h)
222 int PatchBay::cursor_motion_event()
224 int cursor_x = get_relative_cursor_x();
225 int cursor_y = get_relative_cursor_y();
228 if(drag_operation != Tracks::NONE)
233 // Get track we're inside of
234 for(Track *track = mwindow->edl->tracks->first;
238 int y = track->y_pixel;
239 int h = track->vertical_span(mwindow->theme);
240 if(cursor_y >= y && cursor_y < y + h)
242 switch(drag_operation)
245 if(track->play != new_status)
247 track->play = new_status;
248 mwindow->gui->unlock_window();
249 mwindow->restart_brender();
250 mwindow->sync_parameters(CHANGE_EDL);
251 mwindow->gui->lock_window();
256 if(track->record != new_status)
258 track->record = new_status;
263 if(track->gang != new_status)
265 track->gang = new_status;
270 if(track->draw != new_status)
272 track->draw = new_status;
277 if(track->expand_view != new_status)
279 track->expand_view = new_status;
280 mwindow->trackmovement(mwindow->edl->local_session->track_start);
286 IntAuto *current = 0;
288 double position = mwindow->edl->local_session->get_selectionstart(1);
289 Autos *mute_autos = track->automation->autos[AUTOMATION_MUTE];
291 current = (IntAuto*)mute_autos->get_prev_auto(PLAY_FORWARD,
294 if(current->value != new_status)
297 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
299 current->value = new_status;
301 mwindow->undo->update_undo(_("keyframe"), LOAD_AUTOMATION);
303 mwindow->gui->unlock_window();
304 mwindow->restart_brender();
305 mwindow->sync_parameters(CHANGE_PARAMS);
306 mwindow->gui->lock_window();
308 if(mwindow->edl->session->auto_conf->autos[AUTOMATION_MUTE])
310 mwindow->gui->canvas->draw_overlays();
311 mwindow->gui->canvas->flash();
330 void PatchBay::change_meter_format(int mode, int min, int max)
332 for(int i = 0; i < patches.total; i++)
334 PatchGUI *patchgui = patches.values[i];
335 if(patchgui->data_type == TRACK_AUDIO)
337 APatchGUI *apatchgui = (APatchGUI*)patchgui;
340 apatchgui->meter->change_format(mode, min, max);
346 void PatchBay::update_meters(ArrayList<double> *module_levels)
348 for(int level_number = 0, patch_number = 0;
349 patch_number < patches.total && level_number < module_levels->total;
352 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
354 if(patchgui->data_type == TRACK_AUDIO)
358 double level = module_levels->values[level_number];
359 patchgui->meter->update(level, level > 1);
367 void PatchBay::reset_meters()
369 for(int patch_number = 0;
370 patch_number < patches.total;
373 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
374 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
376 patchgui->meter->reset_over();
381 void PatchBay::stop_meters()
383 for(int patch_number = 0;
384 patch_number < patches.total;
387 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
388 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
390 patchgui->meter->reset();
398 int PatchBay::update()
402 // Every patch has a GUI regardless of whether or not it is visible.
403 // Make sure GUI's are allocated for every patch and deleted for non-existant
405 for(Track *current = mwindow->edl->tracks->first;
407 current = NEXT, patch_count++)
410 int y = current->y_pixel;
412 if(patches.total > patch_count)
414 if(patches.values[patch_count]->track_id != current->get_id())
416 delete patches.values[patch_count];
418 switch(current->data_type)
421 patchgui = patches.values[patch_count] = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
424 patchgui = patches.values[patch_count] = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
427 patchgui->create_objects();
431 patches.values[patch_count]->update(PATCH_X, y);
436 switch(current->data_type)
439 patchgui = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
442 patchgui = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
445 patches.append(patchgui);
446 patchgui->create_objects();
450 while(patches.total > patch_count)
452 delete patches.values[patches.total - 1];
453 patches.remove_number(patches.total - 1);
459 void PatchBay::synchronize_faders(float change, int data_type, Track *skip)
461 for(Track *current = mwindow->edl->tracks->first;
465 if(current->data_type == data_type &&
470 FloatAutos *fade_autos = (FloatAutos*)current->automation->autos[AUTOMATION_FADE];
471 double position = mwindow->edl->local_session->get_selectionstart(1);
474 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_for_editing(position);
476 keyframe->value += change;
477 if(data_type == TRACK_AUDIO)
478 CLAMP(keyframe->value, INFINITYGAIN, MAX_AUDIO_FADE);
480 CLAMP(keyframe->value, 0, MAX_VIDEO_FADE);
483 PatchGUI *patch = get_patch_of(current);
484 if(patch) patch->update(patch->x, patch->y);
489 void PatchBay::synchronize_nudge(int64_t value, Track *skip)
491 for(Track *current = mwindow->edl->tracks->first;
495 if(current->data_type == skip->data_type &&
500 current->nudge = value;
501 PatchGUI *patch = get_patch_of(current);
502 if(patch) patch->update(patch->x, patch->y);
507 PatchGUI* PatchBay::get_patch_of(Track *track)
509 for(int i = 0; i < patches.total; i++)
511 if(patches.values[i]->track == track)
512 return patches.values[i];
517 int PatchBay::resize_event(int top, int bottom)
519 reposition_window(mwindow->theme->patchbay_x,
520 mwindow->theme->patchbay_y,
521 mwindow->theme->patchbay_w,
522 mwindow->theme->patchbay_h);