transportque tweaks for shuttle, fixes videoscope/undo hangs
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / apatchgui.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #include "apatchgui.h"
23 #include "atrack.h"
24 #include "autoconf.h"
25 #include "automation.h"
26 #include "edl.h"
27 #include "edlsession.h"
28 #include "floatauto.h"
29 #include "floatautos.h"
30 #include "gwindowgui.h"
31 #include "intauto.h"
32 #include "intautos.h"
33 #include "keys.h"
34 #include "language.h"
35 #include "localsession.h"
36 #include "mainsession.h"
37 #include "mainundo.h"
38 #include "mwindow.h"
39 #include "mwindowgui.h"
40 #include "panauto.h"
41 #include "panautos.h"
42 #include "patchbay.h"
43 #include "theme.h"
44 #include "trackcanvas.h"
45 #include "zwindow.h"
46
47 APatchGUI::APatchGUI(MWindow *mwindow, PatchBay *patchbay,
48                 ATrack *track, int x, int y)
49  : PatchGUI(mwindow, patchbay, track, x, y)
50 {
51         data_type = TRACK_AUDIO;
52         this->atrack = track;
53         meter = 0;
54         pan = 0;
55         fade = 0;
56 }
57
58 APatchGUI::~APatchGUI()
59 {
60         if( fade ) delete fade;
61         if( meter ) delete meter;
62         if( pan ) delete pan;
63 }
64
65 void APatchGUI::create_objects()
66 {
67         update(x, y);
68 }
69
70 int APatchGUI::reposition(int x, int y)
71 {
72         int y1 = PatchGUI::reposition(x, y);
73
74         if( fade )
75                 fade->reposition_window(fade->get_x(), y1+y);
76         y1 += mwindow->theme->fade_h;
77         if( meter )
78                 meter->reposition_window(meter->get_x(), y1+y, -1, meter->get_w());
79         y1 += mwindow->theme->meter_h;
80         if( mix )
81                 mix->reposition_window(mix->get_x(), y1+y);
82         if( pan )
83                 pan->reposition_window(pan->get_x(), y1+y);
84         if( nudge )
85                 nudge->reposition_window(nudge->get_x(), y1+y);
86         y1 += mwindow->theme->pan_h;
87
88         return y1;
89 }
90
91 int APatchGUI::update(int x, int y)
92 {
93         int h = track->vertical_span(mwindow->theme);
94         int x1 = 0;
95         int y1 = PatchGUI::update(x, y);
96
97         int y2 = y1 + mwindow->theme->fade_h;
98         if( fade ) {
99                 if( h < y2 ) {
100                         delete fade;
101                         fade = 0;
102                 }
103                 else {
104                         FloatAuto *previous = 0, *next = 0;
105                         double unit_position = mwindow->edl->local_session->get_selectionstart(1);
106                         unit_position = mwindow->edl->align_to_frame(unit_position, 0);
107                         unit_position = atrack->to_units(unit_position, 0);
108                         FloatAutos *ptr = (FloatAutos*)atrack->automation->autos[AUTOMATION_FADE];
109                         float value = ptr->get_value((long)unit_position, PLAY_FORWARD, previous, next);
110                         fade->update(fade->get_w(), value,
111                                      mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
112                                      mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE]);
113                 }
114         }
115         else if( h >= y2 ) {
116                 float v = mwindow->get_float_auto(this, AUTOMATION_FADE)->get_value();
117                 patchbay->add_subwindow(fade = new AFadePatch(this, x1+x, y1+y,
118                         patchbay->get_w() - 10, v));
119         }
120         y1 = y2;
121
122         y2 = y1 + mwindow->theme->meter_h;
123         if( meter ) {
124                 if( h < y2 ) {
125                         delete meter;  meter = 0;
126                 }
127         }
128         else if( h >= y2 ) {
129                 patchbay->add_subwindow(meter = new AMeterPatch(mwindow, this, x1+x, y1+y));
130         }
131         y1 = y2;
132
133         y2 = y1 + mwindow->theme->pan_h;
134         if( pan ) {
135                 if( h < y2 ) {
136                         delete mix;    mix = 0;
137                         delete pan;    pan = 0;
138                         delete nudge;  nudge = 0;
139                 }
140                 else {
141                         if( mwindow->session->selected_zwindow >= 0 ) {
142                                 int v = mwindow->mixer_track_active(track);
143                                 mix->update(v);
144                         }
145                         if( pan->get_total_values() != mwindow->edl->session->audio_channels ) {
146                                 pan->change_channels(mwindow->edl->session->audio_channels,
147                                         mwindow->edl->session->achannel_positions);
148                         }
149                         else {
150                                 int handle_x, handle_y;
151                                 PanAuto *previous = 0, *next = 0;
152                                 double unit_position = mwindow->edl->local_session->get_selectionstart(1);
153                                 unit_position = mwindow->edl->align_to_frame(unit_position, 0);
154                                 unit_position = atrack->to_units(unit_position, 0);
155                                 PanAutos *ptr = (PanAutos*)atrack->automation->autos[AUTOMATION_PAN];
156                                 ptr->get_handle(handle_x, handle_y, (long)unit_position,
157                                                 PLAY_FORWARD, previous, next);
158                                 pan->update(handle_x, handle_y);
159                         }
160                         nudge->update();
161                 }
162         }
163         else if( h >= y2 ) {
164                 patchbay->add_subwindow(mix = new AMixPatch(mwindow, this, x1+x, y1+y+5));
165                 x1 += mix->get_w() + 10;
166                 patchbay->add_subwindow(pan = new APanPatch(mwindow, this, x1+x, y1+y));
167                 x1 += pan->get_w() + 20;
168                 patchbay->add_subwindow(nudge = new NudgePatch(mwindow, this, x1+x, y1+y,
169                                 patchbay->get_w() - x1-x - 10));
170         }
171         y1 = y2;
172
173         return y1;
174 }
175
176 void APatchGUI::update_faders(float v)
177 {
178         if( fade )
179                 fade->update(v);
180
181         change_source = 1;
182         double position = mwindow->edl->local_session->get_selectionstart(1);
183         Autos *fade_autos = atrack->automation->autos[AUTOMATION_FADE];
184         int need_undo = !fade_autos->auto_exists_for_editing(position);
185
186         mwindow->undo->update_undo_before(_("fade"), need_undo ? 0 : this);
187         FloatAuto *current = (FloatAuto*)fade_autos->get_auto_for_editing(position);
188         float change = v - current->get_value();
189         current->set_value(v);
190
191         if( track->gang && track->record )
192                 patchbay->synchronize_faders(change, TRACK_AUDIO, track);
193         mwindow->undo->update_undo_after(_("fade"), LOAD_AUTOMATION);
194         change_source = 0;
195
196         mwindow->sync_parameters(CHANGE_PARAMS);
197
198         if( mwindow->edl->session->auto_conf->autos[AUTOMATION_FADE] ) {
199                 mwindow->gui->draw_overlays(1);
200         }
201 }
202
203 AFadePatch::AFadePatch(APatchGUI *patch, int x, int y, int w, float v)
204  : BC_FSlider(x, y, 0, w, w,
205         patch->mwindow->edl->local_session->automation_mins[AUTOGROUPTYPE_AUDIO_FADE],
206         patch->mwindow->edl->local_session->automation_maxs[AUTOGROUPTYPE_AUDIO_FADE],
207         v)
208 {
209         this->patch = patch;
210 }
211
212
213 int AFadePatch::handle_event()
214 {
215         if( shift_down() ) {
216                 update(0.0);
217                 set_tooltip(get_caption());
218         }
219         patch->update_faders(get_value());
220         return 1;
221 }
222
223 AKeyFadePatch::AKeyFadePatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
224  : BC_SubWindow(x,y, 200,20, GWindowGUI::auto_colors[AUTOMATION_FADE])
225 {
226         this->mwindow = mwindow;
227         this->patch = patch;
228 }
229
230 void AKeyFadePatch::create_objects()
231 {
232         int x = 0, y = 0;
233         float v = mwindow->get_float_auto(patch, AUTOMATION_FADE)->get_value();
234         add_subwindow(akey_fade_text = new AKeyFadeText(this, x, y, 64, v));
235         x += akey_fade_text->get_w();
236         VFrame **lok_images = mwindow->theme->get_image_set("lok");
237         int w1 = get_w() - x - lok_images[0]->get_w();
238         add_subwindow(akey_fade_slider = new AKeyFadeSlider(this, x, y, w1, v));
239         x += akey_fade_slider->get_w();
240         add_subwindow(akey_fade_ok = new AKeyFadeOK(this, x, y, lok_images));
241         activate();
242         show_window();
243 }
244
245 void AKeyFadePatch::update(float v)
246 {
247         akey_fade_text->update(v);
248         akey_fade_slider->update(v);
249         patch->update_faders(v);
250 }
251
252 AKeyFadeOK::AKeyFadeOK(AKeyFadePatch *akey_fade_patch, int x, int y, VFrame **images)
253  : BC_Button(x, y, images)
254 {
255         this->akey_fade_patch = akey_fade_patch;
256 }
257
258 int AKeyFadeOK::handle_event()
259 {
260         MWindowGUI *mgui = akey_fade_patch->mwindow->gui;
261         delete mgui->keyvalue_popup;
262         mgui->keyvalue_popup = 0;
263         return 1;
264 }
265
266 AKeyFadeText::AKeyFadeText(AKeyFadePatch *akey_fade_patch, int x, int y, int w, float v)
267  : BC_TextBox(x, y, w, 1, v, 1, MEDIUMFONT, 2)
268 {
269         this->akey_fade_patch = akey_fade_patch;
270 }
271
272 int AKeyFadeText::handle_event()
273 {
274         float v = atof(get_text());
275         akey_fade_patch->update(v);
276         return get_keypress() != RETURN ? 1 :
277                 akey_fade_patch->akey_fade_ok->handle_event();
278 }
279
280 AKeyFadeSlider::AKeyFadeSlider(AKeyFadePatch *akey_fade_patch, int x, int y, int w, float v)
281  : AFadePatch(akey_fade_patch->patch, x, y, w, v)
282 {
283         this->akey_fade_patch = akey_fade_patch;
284 }
285
286 int AKeyFadeSlider::handle_event()
287 {
288         float v = get_value();
289         akey_fade_patch->update(v);
290         return 1;
291 }
292
293
294 APanPatch::APanPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
295  : BC_Pan(x, y, PAN_RADIUS, MAX_PAN,
296         mwindow->edl->session->audio_channels,
297         mwindow->edl->session->achannel_positions,
298         mwindow->get_pan_auto(patch)->handle_x,
299         mwindow->get_pan_auto(patch)->handle_y,
300         mwindow->get_pan_auto(patch)->values)
301 {
302         this->mwindow = mwindow;
303         this->patch = patch;
304         set_tooltip(_("Pan"));
305 }
306
307 int APanPatch::handle_event()
308 {
309         PanAuto *current;
310         double position = mwindow->edl->local_session->get_selectionstart(1);
311         Autos *pan_autos = patch->atrack->automation->autos[AUTOMATION_PAN];
312         int need_undo = !pan_autos->auto_exists_for_editing(position);
313
314         mwindow->undo->update_undo_before(_("pan"), need_undo ? 0 : this);
315
316         current = (PanAuto*)pan_autos->get_auto_for_editing(position);
317
318         current->handle_x = get_stick_x();
319         current->handle_y = get_stick_y();
320         memcpy(current->values, get_values(), sizeof(float) * mwindow->edl->session->audio_channels);
321
322         mwindow->undo->update_undo_after(_("pan"), LOAD_AUTOMATION);
323
324         mwindow->sync_parameters(CHANGE_PARAMS);
325
326         if( need_undo && mwindow->edl->session->auto_conf->autos[AUTOMATION_PAN] ) {
327                 mwindow->gui->draw_overlays(1);
328         }
329         return 1;
330 }
331
332 AKeyPanPatch::AKeyPanPatch(MWindow *mwindow, APatchGUI *patch)
333  : APanPatch(mwindow, patch, -1,-1)
334 {
335 }
336
337 int AKeyPanPatch::handle_event()
338 {
339         int ret = APanPatch::handle_event();
340         APanPatch *pan = patch->pan;
341         if( pan )
342                 pan->update(get_stick_x(), get_stick_y());
343         return ret;
344 }
345
346
347 AMeterPatch::AMeterPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
348  : BC_Meter(x, y, METER_HORIZ, patch->patchbay->get_w() - 10,
349         mwindow->edl->session->min_meter_db, mwindow->edl->session->max_meter_db,
350         mwindow->edl->session->meter_format, 0, -1)
351 {
352         this->mwindow = mwindow;
353         this->patch = patch;
354         set_delays(TRACKING_RATE * 10,
355                         TRACKING_RATE);
356 }
357
358 int AMeterPatch::button_press_event()
359 {
360         if( cursor_inside() && is_event_win() && get_buttonpress() == 1 ) {
361                 mwindow->reset_meters();
362                 return 1;
363         }
364
365         return 0;
366 }
367
368 AMixPatch::AMixPatch(MWindow *mwindow, APatchGUI *patch, int x, int y)
369  : MixPatch(mwindow, patch, x, y)
370 {
371         set_tooltip(_("Mixer"));
372 }
373
374 AMixPatch::~AMixPatch()
375 {
376 }
377