no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / motion51 / motionwindow51.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2020 William Morrow
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20
21 #include "bcdisplayinfo.h"
22 #include "clip.h"
23 #include "cstrdup.h"
24 #include "edl.h"
25 #include "fonts.h"
26 #include "edlsession.h"
27 #include "language.h"
28 #include "motion51.h"
29 #include "motionwindow51.h"
30 #include "mwindow.h"
31 #include "pluginserver.h"
32
33 Motion51Window::Motion51Window(Motion51Main *plugin)
34  : PluginClientWindow(plugin, xS(600), yS(400), xS(600), yS(400), 0)
35 {
36         this->plugin = plugin;
37 }
38
39 Motion51Window::~Motion51Window()
40 {
41 }
42
43 void Motion51Window::create_objects()
44 {
45         int xs10 = xS(10), xs30 = xS(30), xs120 = xS(120);
46         int ys5 = yS(5), ys10 = yS(10), ys20 = yS(20);
47         int x = xs10, y = ys20, xs72 = xS(72);
48         int x0 = x, x1 = get_w()/2;
49         add_subwindow(sample_steps = new Motion51SampleSteps(plugin, x0=x, y, xs120));
50         BC_Title *title = new BC_Title(x0+=sample_steps->get_w()+xs10, y, _("Samples"));
51         add_subwindow(title);
52         sample_steps->create_objects();
53         sample_r = new Motion51Limits(plugin, this, x1,y, _("Sample Radius%"),
54                 &plugin->config.sample_r, 0.f,100.f, xs72);
55         sample_r->create_objects();
56         y += sample_r->get_h() + ys20;
57
58         block_x = new Motion51Limits(plugin, this, x0=x,y, _("Center X%"),
59                 &plugin->config.block_x, 0.f, 100.f, xs72);
60         block_x->create_objects();
61         block_y = new Motion51Limits(plugin, this, x1,y, _("Center Y%"),
62                 &plugin->config.block_y, 0.f, 100.f, xs72);
63         block_y->create_objects();
64         y += block_x->get_h() + ys10;
65         block_w = new Motion51Limits(plugin, this, x0,y, _("Search W%"),
66                 &plugin->config.block_w, 0.f,100.f, xs72);
67         block_w->create_objects();
68         block_h = new Motion51Limits(plugin, this, x1,y, _("Search H%"),
69                 &plugin->config.block_h, 0.f,100.f, xs72);
70         block_h->create_objects();
71         y += block_w->get_h() + ys10;
72
73         horiz_limit = new Motion51Limits(plugin, this, x0=x,y, _("Horiz shake limit%"),
74                 &plugin->config.horiz_limit, 0.f, 75.f, xs72);
75         horiz_limit->create_objects();
76         shake_fade = new Motion51Limits(plugin, this, x1,y, _("Shake fade%"),
77                 &plugin->config.shake_fade, 0.f, 75.f, xs72);
78         shake_fade->create_objects();
79         y += horiz_limit->get_h() + ys10;
80         vert_limit = new Motion51Limits(plugin, this, x0,y, _("Vert shake limit%"),
81                 &plugin->config.vert_limit, 0.f, 75.f, xs72);
82         vert_limit->create_objects();
83         y += vert_limit->get_h() + ys10;
84         twist_limit = new Motion51Limits(plugin, this, x0,y, _("Twist limit%"),
85                 &plugin->config.twist_limit, 0.f, 75.f, xs72);
86         twist_limit->create_objects();
87         twist_fade = new Motion51Limits(plugin, this, x1,y, _("Twist fade%"),
88                 &plugin->config.twist_fade, 0.f, 75.f, xs72);
89         twist_fade->create_objects();
90         y += twist_fade->get_h() + ys20;
91
92         add_subwindow(draw_vectors = new Motion51DrawVectors(plugin, this, x, y));
93         add_subwindow(title = new BC_Title(x1, y, _("Tracking file:")));
94         y += draw_vectors->get_h() + ys5;
95         add_subwindow(enable_tracking = new Motion51EnableTracking(plugin, this, x, y));
96         add_subwindow(tracking_file = new Motion51TrackingFile(plugin,
97                 plugin->config.tracking_file, this, x1, y, get_w()-xs30-x1));
98         y += enable_tracking->get_h() + ys20;
99
100         add_subwindow(reset_config = new Motion51ResetConfig(plugin, this, x0=x, y));
101         add_subwindow(reset_tracking = new Motion51ResetTracking(plugin, this, x1, y));
102         y += reset_config->get_h()+ys20;
103
104         int pef = client->server->mwindow->edl->session->video_every_frame;
105         add_subwindow(pef_title = new BC_Title(x, y,
106                 !pef ?  _("For best results\n"
107                                 " Set: Play every frame\n"
108                                 " Preferences-> Playback-> Video Out") :
109                         _("Currently using: Play every frame"), MEDIUMFONT,
110                 !pef ? RED : GREEN));
111
112         show_window(1);
113 }
114
115 void Motion51Window::update_gui()
116 {
117         Motion51Config &config = plugin->config;
118         horiz_limit->update(config.horiz_limit);
119         vert_limit->update(config.vert_limit);
120         twist_limit->update(config.twist_limit);
121         shake_fade->update(config.shake_fade);
122         twist_fade->update(config.twist_fade);
123
124         sample_r->update(config.sample_r);
125         char string[BCTEXTLEN];
126         sprintf(string, "%d", config.sample_steps);
127         sample_steps->set_text(string);
128
129         block_w->update(config.block_w);
130         block_h->update(config.block_h);
131         block_x->update(config.block_x);
132         block_y->update(config.block_y);
133
134         draw_vectors->update(config.draw_vectors);
135         tracking_file->update(config.tracking_file);
136         enable_tracking->update(config.tracking);
137 }
138
139 Motion51Limits::Motion51Limits(Motion51Main *plugin, Motion51Window *gui, int x, int y,
140         const char *ttext, float *value, float min, float max, int ttbox_w)
141  : BC_TumbleTextBox(gui, *value, min, max, x, y, ttbox_w)
142 {
143         this->plugin = plugin;
144         this->gui = gui;
145         this->ttext = cstrdup(ttext);
146         this->value = value;
147         title = 0;
148 }
149
150 Motion51Limits::~Motion51Limits()
151 {
152         delete [] ttext;
153 }
154
155 void Motion51Limits::create_objects()
156 {
157         BC_TumbleTextBox::create_objects();
158         int tx = BC_TumbleTextBox::get_x() + BC_TumbleTextBox::get_w() + xS(5);
159         int ty = BC_TumbleTextBox::get_y();
160         gui->add_subwindow(title = new BC_Title(tx,ty,ttext));
161 }
162
163 int Motion51Limits::handle_event()
164 {
165         *value = atof(get_text());
166         plugin->send_configure_change();
167         return 1;
168 }
169
170 Motion51TrackingFile::Motion51TrackingFile(Motion51Main *plugin,
171         const char *filename, Motion51Window *gui, int x, int y, int w)
172  : BC_TextBox(x, y, w, 1, filename)
173 {
174         this->plugin = plugin;
175         this->gui = gui;
176 };
177
178 int Motion51TrackingFile::handle_event()
179 {
180         strcpy(plugin->config.tracking_file, get_text());
181         plugin->send_configure_change();
182         return 1;
183 }
184
185
186 Motion51SampleSteps::Motion51SampleSteps(Motion51Main *plugin,
187         int x, int y, int w)
188  : BC_PopupMenu(x, y, w, "", 1)
189 {
190         this->plugin = plugin;
191 }
192
193 void Motion51SampleSteps::create_objects()
194 {
195         add_item(new BC_MenuItem("16"));
196         add_item(new BC_MenuItem("32"));
197         add_item(new BC_MenuItem("64"));
198         add_item(new BC_MenuItem("128"));
199         add_item(new BC_MenuItem("256"));
200         add_item(new BC_MenuItem("512"));
201         add_item(new BC_MenuItem("1024"));
202         add_item(new BC_MenuItem("2048"));
203         add_item(new BC_MenuItem("4096"));
204         add_item(new BC_MenuItem("8192"));
205         add_item(new BC_MenuItem("16384"));
206         add_item(new BC_MenuItem("32768"));
207         char string[BCTEXTLEN];
208         sprintf(string, "%d", plugin->config.sample_steps);
209         set_text(string);
210 }
211
212 int Motion51SampleSteps::handle_event()
213 {
214         plugin->config.sample_steps = atoi(get_text());
215         plugin->send_configure_change();
216         return 1;
217 }
218
219
220
221 Motion51DrawVectors::Motion51DrawVectors(Motion51Main *plugin,
222         Motion51Window *gui, int x, int y)
223  : BC_CheckBox(x, y, plugin->config.draw_vectors, _("Draw vectors"))
224 {
225         this->gui = gui;
226         this->plugin = plugin;
227 }
228
229 int Motion51DrawVectors::handle_event()
230 {
231         plugin->config.draw_vectors = get_value();
232         plugin->send_configure_change();
233         return 1;
234 }
235
236
237 Motion51ResetConfig::Motion51ResetConfig(Motion51Main *plugin, Motion51Window *gui, int x, int y)
238  : BC_GenericButton(x, y, _("Reset defaults"))
239 {
240         this->plugin = plugin;
241         this->gui = gui;
242 }
243
244 int Motion51ResetConfig::handle_event()
245 {
246         plugin->config.init();
247         gui->update_gui();
248         plugin->send_configure_change();
249         return 1;
250 }
251
252 Motion51ResetTracking::Motion51ResetTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
253  : BC_GenericButton(x, y, _("Reset Tracking"))
254 {
255         this->plugin = plugin;
256         this->gui = gui;
257 }
258
259 int Motion51ResetTracking::handle_event()
260 {
261         plugin->set_tracking_path();
262         gui->tracking_file->update(plugin->config.tracking_file);
263         plugin->config.tracking = 0;
264         plugin->send_configure_change();
265         gui->enable_tracking->update(0);
266         ::remove(plugin->config.tracking_file);
267         return 1;
268 }
269
270 Motion51EnableTracking::Motion51EnableTracking(Motion51Main *plugin, Motion51Window *gui, int x, int y)
271  : BC_CheckBox(x, y, plugin->config.tracking,_("Enable Tracking"))
272 {
273         this->plugin = plugin;
274         this->gui = gui;
275 }
276
277 int Motion51EnableTracking::handle_event()
278 {
279         plugin->config.tracking = get_value();
280         plugin->send_configure_change();
281         return 1;
282 }
283