1 #include "apatchgui.h"#include "atrack.inc"
2 #include "automation.h"
4 #include "floatautos.h"
7 #include "edlsession.h"
11 #include "localsession.h"
14 #include "mwindowgui.h"
17 #include "mainsession.h"
20 #include "trackcanvas.h"
22 #include "vpatchgui.h"
26 #define _(String) gettext(String)
27 #define gettext_noop(String) String
28 #define N_(String) gettext_noop (String)
31 PatchBay::PatchBay(MWindow *mwindow, MWindowGUI *gui)
32 : BC_SubWindow(mwindow->theme->patchbay_x,
33 mwindow->theme->patchbay_y,
34 mwindow->theme->patchbay_w,
35 mwindow->theme->patchbay_h)
37 this->mwindow = mwindow;
40 reconfigure_trigger = 0;
41 drag_operation = Tracks::NONE;
49 int PatchBay::delete_all_patches()
51 patches.remove_all_objects();
55 int PatchBay::create_objects()
57 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
62 void PatchBay::resize_event()
64 reposition_window(mwindow->theme->patchbay_x,
65 mwindow->theme->patchbay_y,
66 mwindow->theme->patchbay_w,
67 mwindow->theme->patchbay_h);
68 draw_top_background(get_parent(), 0, 0, get_w(), get_h());
73 int PatchBay::button_press_event()
76 // Too much junk to support the wheel
80 int PatchBay::cursor_motion_event()
82 int cursor_x = get_relative_cursor_x();
83 int cursor_y = get_relative_cursor_y();
86 if(drag_operation != Tracks::NONE)
91 // Get track we're inside of
92 for(Track *track = mwindow->edl->tracks->first;
96 int y = track->y_pixel;
97 int h = track->vertical_span(mwindow->theme);
98 if(cursor_y >= y && cursor_y < y + h)
100 switch(drag_operation)
103 if(track->play != new_status)
105 track->play = new_status;
106 mwindow->gui->unlock_window();
107 mwindow->restart_brender();
108 mwindow->sync_parameters(CHANGE_EDL);
109 mwindow->gui->lock_window();
114 if(track->record != new_status)
116 track->record = new_status;
121 if(track->gang != new_status)
123 track->gang = new_status;
128 if(track->draw != new_status)
130 track->draw = new_status;
135 if(track->expand_view != new_status)
137 track->expand_view = new_status;
138 mwindow->trackmovement(mwindow->edl->local_session->track_start);
144 IntAuto *current = 0;
146 double position = mwindow->edl->local_session->selectionstart;
147 Autos *mute_autos = track->automation->mute_autos;
149 current = (IntAuto*)mute_autos->get_prev_auto(PLAY_FORWARD,
152 if(current->value != new_status)
154 mwindow->undo->update_undo_before(_("keyframe"), LOAD_AUTOMATION);
156 current = (IntAuto*)mute_autos->get_auto_for_editing(position);
158 current->value = new_status;
160 mwindow->undo->update_undo_after();
162 mwindow->gui->unlock_window();
163 mwindow->restart_brender();
164 mwindow->sync_parameters(CHANGE_PARAMS);
165 mwindow->gui->lock_window();
167 if(mwindow->edl->session->auto_conf->mute)
169 mwindow->gui->canvas->draw_overlays();
170 mwindow->gui->canvas->flash();
189 void PatchBay::change_meter_format(int mode, float min)
191 for(int i = 0; i < patches.total; i++)
193 PatchGUI *patchgui = patches.values[i];
194 if(patchgui->data_type == TRACK_AUDIO)
196 APatchGUI *apatchgui = (APatchGUI*)patchgui;
199 apatchgui->meter->change_format(mode, min);
205 void PatchBay::update_meters(ArrayList<double> *module_levels)
207 for(int level_number = 0, patch_number = 0;
208 patch_number < patches.total && level_number < module_levels->total;
211 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
213 if(patchgui->data_type == TRACK_AUDIO)
217 double level = module_levels->values[level_number];
218 patchgui->meter->update(level, level > 1);
226 void PatchBay::reset_meters()
228 for(int patch_number = 0;
229 patch_number < patches.total;
232 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
233 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
235 patchgui->meter->reset_over();
240 void PatchBay::stop_meters()
242 for(int patch_number = 0;
243 patch_number < patches.total;
246 APatchGUI *patchgui = (APatchGUI*)patches.values[patch_number];
247 if(patchgui->data_type == TRACK_AUDIO && patchgui->meter)
249 patchgui->meter->reset();
257 int PatchBay::update()
261 // Every patch has a GUI regardless of whether or not it is visible.
262 // Make sure GUI's are allocated for every patch and deleted for non-existant
264 for(Track *current = mwindow->edl->tracks->first;
266 current = NEXT, patch_count++)
269 int y = current->y_pixel;
271 if(patches.total > patch_count)
273 if(patches.values[patch_count]->track_id != current->get_id())
275 delete patches.values[patch_count];
277 switch(current->data_type)
280 patchgui = patches.values[patch_count] = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
283 patchgui = patches.values[patch_count] = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
286 patchgui->create_objects();
290 patches.values[patch_count]->update(PATCH_X, y);
295 switch(current->data_type)
298 patchgui = new APatchGUI(mwindow, this, (ATrack*)current, PATCH_X, y);
301 patchgui = new VPatchGUI(mwindow, this, (VTrack*)current, PATCH_X, y);
304 patches.append(patchgui);
305 patchgui->create_objects();
309 while(patches.total > patch_count)
311 delete patches.values[patches.total - 1];
312 patches.remove_number(patches.total - 1);
318 void PatchBay::synchronize_faders(float change, int data_type, Track *skip)
320 for(Track *current = mwindow->edl->tracks->first;
324 if(current->data_type == data_type &&
329 FloatAutos *fade_autos = current->automation->fade_autos;
330 double position = mwindow->edl->local_session->selectionstart;
331 int update_undo = !fade_autos->auto_exists_for_editing(position);
334 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
336 FloatAuto *keyframe = (FloatAuto*)fade_autos->get_auto_for_editing(position);
338 keyframe->value += change;
339 if(data_type == TRACK_AUDIO)
340 CLAMP(keyframe->value, INFINITYGAIN, MAX_AUDIO_FADE);
342 CLAMP(keyframe->value, 0, MAX_VIDEO_FADE);
344 mwindow->undo->update_undo_after();
347 for(int i = 0; i < patches.total; i++)
349 if(patches.values[i]->track == current)
350 patches.values[i]->update(patches.values[i]->x,
351 patches.values[i]->y);
359 int PatchBay::resize_event(int top, int bottom)
361 reposition_window(mwindow->theme->patchbay_x,
362 mwindow->theme->patchbay_y,
363 mwindow->theme->patchbay_w,
364 mwindow->theme->patchbay_h);