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->selectionstart;
289 Autos *mute_autos = track->automation->mute_autos;
291 current = (IntAuto*)mute_autos->get_prev_auto(PLAY_FORWARD,
294 if(current->value != new_status)
296 mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
298 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
300 current->value = new_status;
302 mwindow->undo->update_undo_after();
304 mwindow->gui->unlock_window();
305 mwindow->restart_brender();
306 mwindow->sync_parameters(CHANGE_PARAMS);
307 mwindow->gui->lock_window();
309 if(mwindow->edl->session->auto_conf->mute)
311 mwindow->gui->canvas->draw_overlays();
312 mwindow->gui->canvas->flash();
331 void PatchBay::change_meter_format(int mode, int min, int max)
333 for(int i = 0; i < patches.total; i++)
335 PatchGUI *patchgui = patches.values[i];
336 if(patchgui->data_type == TRACK_AUDIO)
338 APatchGUI *apatchgui = (APatchGUI*)patchgui;
341 apatchgui->meter->change_format(mode, min, max);
347 void PatchBay::update_meters(ArrayList<double> *module_levels)
349 for(int level_number = 0, patch_number = 0;
350 patch_number < patches.total && level_number < module_levels->total;
353 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
355 if(patchgui->data_type == TRACK_AUDIO)
359 double level = module_levels->values[level_number];
360 patchgui->meter->update(level, level > 1);
368 void PatchBay::reset_meters()
370 for(int patch_number = 0;
371 patch_number < patches.total;
374 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
375 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
377 patchgui->meter->reset_over();
382 void PatchBay::stop_meters()
384 for(int patch_number = 0;
385 patch_number < patches.total;
388 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
389 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
391 patchgui->meter->reset();
399 int PatchBay::update()
403 // Every patch has a GUI regardless of whether or not it is visible.
404 // Make sure GUI's are allocated for every patch and deleted for non-existant
406 for(Track *current = mwindow->edl->tracks->first;
408 current = NEXT, patch_count++)
411 int y = current->y_pixel;
413 if(patches.total > patch_count)
415 if(patches.values[patch_count]->track_id != current->get_id())
417 delete patches.values[patch_count];
419 switch(current->data_type)
422 patchgui = patches.values[patch_count] = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
425 patchgui = patches.values[patch_count] = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
428 patchgui->create_objects();
432 patches.values[patch_count]->update(PATCH_X, y);
437 switch(current->data_type)
440 patchgui = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
443 patchgui = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
446 patches.append(patchgui);
447 patchgui->create_objects();
451 while(patches.total > patch_count)
453 delete patches.values[patches.total - 1];
454 patches.remove_number(patches.total - 1);
460 void PatchBay::synchronize_faders(float change, int data_type, Track *skip)
462 for(Track *current = mwindow->edl->tracks->first;
466 if(current->data_type == data_type &&
471 FloatAutos *fade_autos = current->automation->fade_autos;
472 double position = mwindow->edl->local_session->selectionstart;
473 int update_undo = !fade_autos->auto_exists_for_editing(position);
476 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
478 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_for_editing(position);
480 keyframe->value += change;
481 if(data_type == TRACK_AUDIO)
482 CLAMP(keyframe->value, INFINITYGAIN, MAX_AUDIO_FADE);
484 CLAMP(keyframe->value, 0, MAX_VIDEO_FADE);
486 mwindow->undo->update_undo_after();
489 for(int i = 0; i < patches.total; i++)
491 if(patches.values[i]->track == current)
492 patches.values[i]->update(patches.values[i]->x,
493 patches.values[i]->y);
501 int PatchBay::resize_event(int top, int bottom)
503 reposition_window(mwindow->theme->patchbay_x,
504 mwindow->theme->patchbay_y,
505 mwindow->theme->patchbay_w,
506 mwindow->theme->patchbay_h);