r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / apatchgui.C
blob67b328601d122f118b711997826fbfe49c4fef74
1 #include "apatchgui.h"
2 #include "apatchgui.inc"
3 #include "atrack.h"
4 #include "autoconf.h"
5 #include "automation.h"
6 #include "edl.h"
7 #include "edlsession.h"
8 #include "floatauto.h"
9 #include "floatautos.h"
10 #include "language.h"
11 #include "localsession.h"
12 #include "mainundo.h"
13 #include "mwindow.h"
14 #include "mwindowgui.h"
15 #include "panauto.h"
16 #include "panautos.h"
17 #include "patchbay.h"
18 #include "theme.h"
19 #include "trackcanvas.h"
24 APatchGUI::APatchGUI(MWindow *mwindow, 
25         PatchBay *patchbay, 
26         ATrack *track, 
27         int x, 
28         int y)
29  : PatchGUI(mwindow, 
30         patchbay, 
31         track, 
32         x, 
33         y)
35         data_type = TRACK_AUDIO;
36         this->atrack = track;
37         meter = 0;
38         pan = 0;
39         fade = 0;
41 APatchGUI::~APatchGUI()
43         if(fade) delete fade;
44         if(meter) delete meter;
45         if(pan) delete pan;
48 int APatchGUI::create_objects()
50         return update(x, y);
53 int APatchGUI::reposition(int x, int y)
55         int x1 = 0;
56         int y1 = PatchGUI::reposition(x, y);
58         if(fade) fade->reposition_window(fade->get_x(), 
59                 y1 + y);
60         y1 += mwindow->theme->fade_h;
62         if(meter) meter->reposition_window(meter->get_x(),
63                 y1 + y,
64                 meter->get_w());
65         y1 += mwindow->theme->meter_h;
67         if(pan) pan->reposition_window(pan->get_x(),
68                 y1 + y);
70         if(nudge) nudge->reposition_window(nudge->get_x(),
71                 y1 + y);
73         y1 += mwindow->theme->pan_h;
74         return y1;
77 int APatchGUI::update(int x, int y)
79         int h = track->vertical_span(mwindow->theme);
80         int x1 = 0;
81         int y1 = PatchGUI::update(x, y);
83         if(fade)
84         {
85                 if(h - y1 < mwindow->theme->fade_h)
86                 {
87                         delete fade;
88                         fade = 0;
89                 }
90                 else
91                 {
92 //printf("APatchGUI::update %f\n", fade->get_keyframe(mwindow, this)->value);
93                         FloatAuto *previous = 0, *next = 0;
94                         double unit_position = mwindow->edl->local_session->selectionstart;
95                         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
96                         unit_position = atrack->to_units(unit_position, 0);
97                         float value = atrack->automation->fade_autos->get_value(
98                                 (long)unit_position,
99                                 PLAY_FORWARD, 
100                                 previous, 
101                                 next);
102                         fade->update(value);
103 //                      fade->update(fade->get_keyframe(mwindow, this)->value);
104                 }
105         }
106         else
107         if(h - y1 >= mwindow->theme->fade_h)
108         {
109                 patchbay->add_subwindow(fade = new AFadePatch(mwindow, 
110                         this, 
111                         x1 + x, 
112                         y1 + y, 
113                         patchbay->get_w() - 10));
114         }
115         y1 += mwindow->theme->fade_h;
117         if(meter)
118         {
119                 if(h - y1 < mwindow->theme->meter_h)
120                 {
121                         delete meter;
122                         meter = 0;
123                 }
124         }
125         else
126         if(h - y1 >= mwindow->theme->meter_h)
127         {
128                 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
129                         this,
130                         x1 + x, 
131                         y1 + y));
132         }
133         y1 += mwindow->theme->meter_h;
134         x1 += 10;
136         if(pan)
137         {
138                 if(h - y1 < mwindow->theme->pan_h)
139                 {
140                         delete pan;
141                         pan = 0;
142                         delete nudge;
143                         nudge = 0;
144                 }
145                 else
146                 {
147                         if(pan->get_total_values() != mwindow->edl->session->audio_channels)
148                         {
149                                 pan->change_channels(mwindow->edl->session->audio_channels,
150                                         mwindow->edl->session->achannel_positions);
151                         }
152                         else
153                         {
154                                 int handle_x, handle_y;
155                                 PanAuto *previous = 0, *next = 0;
156                                 double unit_position = mwindow->edl->local_session->selectionstart;
157                                 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
158                                 unit_position = atrack->to_units(unit_position, 0);
159                                 atrack->automation->pan_autos->get_handle(handle_x,
160                                         handle_y,
161                                         (long)unit_position, 
162                                         PLAY_FORWARD,
163                                         previous,
164                                         next);
165                                 pan->update(handle_x, handle_y);
166                         }
167                         nudge->update();
168                 }
169         }
170         else
171         if(h - y1 >= mwindow->theme->pan_h)
172         {
173                 patchbay->add_subwindow(pan = new APanPatch(mwindow,
174                         this,
175                         x1 + x, 
176                         y1 + y));
177                 x1 += pan->get_w() + 10;
178                 patchbay->add_subwindow(nudge = new NudgePatch(mwindow,
179                         this,
180                         x1 + x,
181                         y1 + y,
182                         patchbay->get_w() - x1 - 10));
183         }
184         y1 += mwindow->theme->pan_h;
186         return y1;
189 void APatchGUI::synchronize_fade(float value_change)
191         if(fade && !change_source) 
192         {
193                 fade->update(fade->get_value() + value_change);
194                 fade->update_edl();
195         }
200 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
201  : BC_FSlider(x, 
202                         y, 
203                         0, 
204                         w, 
205                         w, 
206                         (float)INFINITYGAIN, 
207                         (float)MAX_AUDIO_FADE, 
208                         get_keyframe(mwindow, patch)->value)
210 //printf("AFadePatch::AFadePatch 1 %p %f\n", patch->track, get_keyframe(mwindow, patch)->value);
211 //printf("AFadePatch::AFadePatch 2 %f\n", ((FloatAuto*)patch->track->automation->fade_autos->first)->value);
212         this->mwindow = mwindow;
213         this->patch = patch;
216 float AFadePatch::update_edl()
218         FloatAuto *current;
219         double position = mwindow->edl->local_session->selectionstart;
220         Autos *fade_autos = patch->atrack->automation->fade_autos;
221         int update_undo = !fade_autos->auto_exists_for_editing(position);
223 //printf("AFadePatch::update_edl 1 %d\n", update_undo);
224         if(update_undo)
225                 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
227         current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
229         float result = get_value() - current->value;
230         current->value = get_value();
232         if(update_undo)
233                 mwindow->undo->update_undo_after();
235         return result;
239 int AFadePatch::handle_event()
241         if(shift_down()) 
242         {
243                 update(0.0);
244                 set_tooltip(get_caption());
245         }
247         patch->change_source = 1;
248         float change = update_edl();
249         if(patch->track->gang) 
250                 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
251         patch->change_source = 0;
253         mwindow->sync_parameters(CHANGE_PARAMS);
255         if(mwindow->edl->session->auto_conf->fade)
256         {
257                 mwindow->gui->canvas->draw_overlays();
258                 mwindow->gui->canvas->flash();
259         }
260         return 1;
263 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
265         Auto *current = 0;
266         double unit_position = mwindow->edl->local_session->selectionstart;
267         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
268         unit_position = patch->atrack->to_units(unit_position, 0);
270         return (FloatAuto*)patch->atrack->automation->fade_autos->get_prev_auto(
271                 (long)unit_position, 
272                 PLAY_FORWARD,
273                 current);
277 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
278  : BC_Pan(x, 
279                 y, 
280                 PAN_RADIUS, 
281                 1, 
282                 mwindow->edl->session->audio_channels, 
283                 mwindow->edl->session->achannel_positions, 
284                 get_keyframe(mwindow, patch)->handle_x, 
285                 get_keyframe(mwindow, patch)->handle_y,
286                 get_keyframe(mwindow, patch)->values)
288         this->mwindow = mwindow;
289         this->patch = patch;
290         set_tooltip("Pan");
293 int APanPatch::handle_event()
295         PanAuto *current;
296         double position = mwindow->edl->local_session->selectionstart;
297         Autos *pan_autos = patch->atrack->automation->pan_autos;
298         int update_undo = !pan_autos->auto_exists_for_editing(position);
300         if(update_undo)
301                 mwindow->undo->update_undo_before(_("pan"), LOAD_AUTOMATION);
303         current = (PanAuto*)pan_autos->get_auto_for_editing(position);
305         current->handle_x = get_stick_x();
306         current->handle_y = get_stick_y();
307         memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
309         if(update_undo)
310                 mwindow->undo->update_undo_after();
312         mwindow->sync_parameters(CHANGE_PARAMS);
314         if(update_undo && mwindow->edl->session->auto_conf->pan)
315         {
316                 mwindow->gui->canvas->draw_overlays();
317                 mwindow->gui->canvas->flash();
318         }
319         return 1;
322 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
324         Auto *current = 0;
325         double unit_position = mwindow->edl->local_session->selectionstart;
326         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
327         unit_position = patch->atrack->to_units(unit_position, 0);
329         return (PanAuto*)patch->atrack->automation->pan_autos->get_prev_auto(
330                 (long)unit_position, 
331                 PLAY_FORWARD,
332                 current);
338 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
339  : BC_Meter(x, 
340                         y, 
341                         METER_HORIZ, 
342                         patch->patchbay->get_w() - 10, 
343                         mwindow->edl->session->min_meter_db, 
344                         mwindow->edl->session->max_meter_db, 
345                         mwindow->edl->session->meter_format, 
346                         0,
347                         TRACKING_RATE * 10,
348                         TRACKING_RATE)
350         this->mwindow = mwindow;
351         this->patch = patch;
354 int AMeterPatch::button_press_event()
356         if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
357         {
358                 mwindow->reset_meters();
359                 return 1;
360         }
362         return 0;