r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / apatchgui.C
blob41c283c42b1fc3f70ce033d0e25583ccd38cfbee
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 "localsession.h"
11 #include "mainundo.h"
12 #include "mwindow.h"
13 #include "mwindowgui.h"
14 #include "panauto.h"
15 #include "panautos.h"
16 #include "patchbay.h"
17 #include "theme.h"
18 #include "trackcanvas.h"
21 #include <libintl.h>
22 #define _(String) gettext(String)
23 #define gettext_noop(String) String
24 #define N_(String) gettext_noop (String)
27 APatchGUI::APatchGUI(MWindow *mwindow, PatchBay *patchbay, ATrack *track, int x, int y)
28  : PatchGUI(mwindow, patchbay, track, x, y)
30         data_type = TRACK_AUDIO;
31         this->atrack = track;
32         meter = 0;
33         pan = 0;
34         fade = 0;
36 APatchGUI::~APatchGUI()
38         if(fade) delete fade;
39         if(meter) delete meter;
40         if(pan) delete pan;
43 int APatchGUI::create_objects()
45         return update(x, y);
48 int APatchGUI::reposition(int x, int y)
50         int x1 = 0;
51         int y1 = PatchGUI::reposition(x, y);
53         if(fade) fade->reposition_window(x1 + x, 
54                 y1 + y);
55         y1 += mwindow->theme->fade_h;
57         if(meter) meter->reposition_window(x1 + x,
58                 y1 + y,
59                 meter->get_w());
60         y1 += mwindow->theme->meter_h;
62         if(pan) pan->reposition_window(x1 + x + mwindow->theme->pan_x,
63                 y1 + y);
64         y1 += mwindow->theme->pan_h;
65         return y1;
68 int APatchGUI::update(int x, int y)
70         int h = track->vertical_span(mwindow->theme);
71         int x1 = 0;
72         int y1 = PatchGUI::update(x, y);
74         if(fade)
75         {
76                 if(h - y1 < mwindow->theme->fade_h)
77                 {
78                         delete fade;
79                         fade = 0;
80                 }
81                 else
82                 {
83 //printf("APatchGUI::update %f\n", fade->get_keyframe(mwindow, this)->value);
84                         FloatAuto *previous = 0, *next = 0;
85                         double unit_position = mwindow->edl->local_session->selectionstart;
86                         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
87                         unit_position = atrack->to_units(unit_position, 0);
88                         float value = atrack->automation->fade_autos->get_value(
89                                 (long)unit_position,
90                                 PLAY_FORWARD, 
91                                 previous, 
92                                 next);
93                         fade->update(value);
94 //                      fade->update(fade->get_keyframe(mwindow, this)->value);
95                 }
96         }
97         else
98         if(h - y1 >= mwindow->theme->fade_h)
99         {
100                 patchbay->add_subwindow(fade = new AFadePatch(mwindow, 
101                         this, 
102                         x1 + x, 
103                         y1 + y, 
104                         patchbay->get_w() - 10));
105         }
106         y1 += mwindow->theme->fade_h;
108         if(meter)
109         {
110                 if(h - y1 < mwindow->theme->meter_h)
111                 {
112                         delete meter;
113                         meter = 0;
114                 }
115         }
116         else
117         if(h - y1 >= mwindow->theme->meter_h)
118         {
119                 patchbay->add_subwindow(meter = new AMeterPatch(mwindow,
120                         this,
121                         x1 + x, 
122                         y1 + y));
123         }
124         y1 += mwindow->theme->meter_h;
126         if(pan)
127         {
128                 if(h - y1 < mwindow->theme->pan_h)
129                 {
130                         delete pan;
131                         pan = 0;
132                 }
133                 else
134                 if(pan->get_total_values() != mwindow->edl->session->audio_channels)
135                 {
136                         pan->change_channels(mwindow->edl->session->audio_channels,
137                                 mwindow->edl->session->achannel_positions);
138                 }
139                 else
140                 {
141                         int handle_x, handle_y;
142                         PanAuto *previous = 0, *next = 0;
143                         double unit_position = mwindow->edl->local_session->selectionstart;
144                         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
145                         unit_position = atrack->to_units(unit_position, 0);
146                         atrack->automation->pan_autos->get_handle(handle_x,
147                                 handle_y,
148                                 (long)unit_position, 
149                                 PLAY_FORWARD,
150                                 previous,
151                                 next);
152                         pan->update(handle_x, handle_y);
153                 }
154         }
155         else
156         if(h - y1 >= mwindow->theme->pan_h)
157         {
158                 patchbay->add_subwindow(pan = new APanPatch(mwindow,
159                         this,
160                         x1 + x + mwindow->theme->pan_x, 
161                         y1 + y));
162         }
163         y1 += mwindow->theme->pan_h;
165         return y1;
168 void APatchGUI::synchronize_fade(float value_change)
170         if(fade && !change_source) 
171         {
172                 fade->update(fade->get_value() + value_change);
173                 fade->update_edl();
174         }
179 AFadePatch::AFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y, int w)
180  : BC_FSlider(x, 
181                         y, 
182                         0, 
183                         w, 
184                         w, 
185                         (float)INFINITYGAIN, 
186                         (float)MAX_AUDIO_FADE, 
187                         get_keyframe(mwindow, patch)->value)
189 //printf("AFadePatch::AFadePatch 1 %p %f\n", patch->track, get_keyframe(mwindow, patch)->value);
190 //printf("AFadePatch::AFadePatch 2 %f\n", ((FloatAuto*)patch->track->automation->fade_autos->first)->value);
191         this->mwindow = mwindow;
192         this->patch = patch;
195 float AFadePatch::update_edl()
197         FloatAuto *current;
198         double position = mwindow->edl->local_session->selectionstart;
199         Autos *fade_autos = patch->atrack->automation->fade_autos;
200         int update_undo = !fade_autos->auto_exists_for_editing(position);
202 //printf("AFadePatch::update_edl 1 %d\n", update_undo);
203         if(update_undo)
204                 mwindow->undo->update_undo_before(_("fade"), LOAD_AUTOMATION);
206         current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
208         float result = get_value() - current->value;
209         current->value = get_value();
211         if(update_undo)
212                 mwindow->undo->update_undo_after();
214         return result;
218 int AFadePatch::handle_event()
220         if(shift_down()) 
221         {
222                 update(0.0);
223                 set_tooltip(get_caption());
224         }
226         patch->change_source = 1;
227         float change = update_edl();
228         if(patch->track->gang) 
229                 patch->patchbay->synchronize_faders(change, TRACK_AUDIO, patch->track);
230         patch->change_source = 0;
232         mwindow->sync_parameters(CHANGE_PARAMS);
234         if(mwindow->edl->session->auto_conf->fade)
235         {
236                 mwindow->gui->canvas->draw_overlays();
237                 mwindow->gui->canvas->flash();
238         }
239         return 1;
242 FloatAuto* AFadePatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
244         Auto *current = 0;
245         double unit_position = mwindow->edl->local_session->selectionstart;
246         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
247         unit_position = patch->atrack->to_units(unit_position, 0);
249         return (FloatAuto*)patch->atrack->automation->fade_autos->get_prev_auto(
250                 (long)unit_position, 
251                 PLAY_FORWARD,
252                 current);
256 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
257  : BC_Pan(x, 
258                 y, 
259                 PAN_RADIUS, 
260                 1, 
261                 mwindow->edl->session->audio_channels, 
262                 mwindow->edl->session->achannel_positions, 
263                 get_keyframe(mwindow, patch)->handle_x, 
264                 get_keyframe(mwindow, patch)->handle_y,
265                 get_keyframe(mwindow, patch)->values)
267         this->mwindow = mwindow;
268         this->patch = patch;
269 //printf("APanPatch::APanPatch %d %d\n", get_keyframe(mwindow, patch)->handle_x, get_keyframe(mwindow, patch)->handle_y);
272 int APanPatch::handle_event()
274         PanAuto *current;
275         double position = mwindow->edl->local_session->selectionstart;
276         Autos *pan_autos = patch->atrack->automation->pan_autos;
277         int update_undo = !pan_autos->auto_exists_for_editing(position);
279         if(update_undo)
280                 mwindow->undo->update_undo_before(_("pan"), LOAD_AUTOMATION);
282         current = (PanAuto*)pan_autos->get_auto_for_editing(position);
284         current->handle_x = get_stick_x();
285         current->handle_y = get_stick_y();
286         memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
288         if(update_undo)
289                 mwindow->undo->update_undo_after();
291         mwindow->sync_parameters(CHANGE_PARAMS);
293         if(update_undo && mwindow->edl->session->auto_conf->pan)
294         {
295                 mwindow->gui->canvas->draw_overlays();
296                 mwindow->gui->canvas->flash();
297         }
298         return 1;
301 PanAuto* APanPatch::get_keyframe(MWindow *mwindow, APatchGUI *patch)
303         Auto *current = 0;
304         double unit_position = mwindow->edl->local_session->selectionstart;
305         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
306         unit_position = patch->atrack->to_units(unit_position, 0);
308         return (PanAuto*)patch->atrack->automation->pan_autos->get_prev_auto(
309                 (long)unit_position, 
310                 PLAY_FORWARD,
311                 current);
317 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
318  : BC_Meter(x, 
319                         y, 
320                         METER_HORIZ, 
321                         patch->patchbay->get_w() - 10, 
322                         mwindow->edl->session->min_meter_db, 
323                         mwindow->edl->session->meter_format, 
324                         0,
325                         mwindow->edl->session->record_speed * 10,
326                         mwindow->edl->session->record_speed)
328         this->mwindow = mwindow;
329         this->patch = patch;
332 int AMeterPatch::button_press_event()
334         if(cursor_inside() && is_event_win() && get_buttonpress() == 1)
335         {
336                 mwindow->reset_meters();
337                 return 1;
338         }
340         return 0;