3 * Copyright (C) 2010 Adam Williams <broadcast at earthling dot net>
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.
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.
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
21 #include "arraylist.h"
22 #include "batchrender.h"
23 #include "bcsignals.h"
27 #include "filesystem.h"
30 #include "loadfile.inc"
34 #include "mwindowgui.h"
35 #include "pluginserver.h"
36 #include "preferences.h"
37 #include "renderfarmclient.h"
43 #define PACKAGE "cinelerra"
44 #define LOCALEDIR "/locale/"
60 class CommandLineThread : public Thread
63 CommandLineThread(ArrayList<char*> *filenames,
66 this->filenames = filenames;
67 this->mwindow = mwindow;
78 mwindow->gui->lock_window("main");
80 mwindow->load_filenames(filenames, LOADMODE_REPLACE);
82 if(filenames->size() == 1)
83 mwindow->gui->mainmenu->add_load(filenames->get(0));
85 mwindow->gui->unlock_window();
90 ArrayList<char*> *filenames;
94 int main(int argc, char *argv[])
96 // handle command line arguments first
98 ArrayList<char*> filenames;
102 int operation = DO_GUI;
103 int deamon_port = DEAMON_PORT;
104 char deamon_path[BCTEXTLEN];
105 char config_path[BCTEXTLEN];
106 char batch_path[BCTEXTLEN];
107 char locale_path[BCTEXTLEN];
108 char exe_path[BCTEXTLEN];
109 char env_path[BCTEXTLEN];
114 EDL::id_lock = new Mutex("EDL::id_lock");
117 get_exe_path(exe_path);
118 snprintf(env_path, sizeof(env_path), "CINELERRA_PATH=%s", exe_path);
120 sprintf(locale_path, "%s%s", exe_path, LOCALEDIR);
123 // detect an UTF-8 locale and try to use a non-Unicode locale instead
124 // <---Beginning of dirty hack
125 // This hack will be removed as soon as Cinelerra is UTF-8 compliant
126 // char *s, *language;
129 // if ((s = getenv("LC_ALL")) ||
130 // (s = getenv("LC_MESSAGES")) ||
131 // (s = getenv("LC_CTYPE")) ||
132 // (s = getenv ("LANG")))
134 // Test if user locale is set to Unicode
135 // if (strstr(s, ".UTF-8"))
137 // extract language from language-charset@variant
138 // language = strtok (s, ".@");
139 // set language as the default locale
140 // setenv("LANG", language, 1);
143 // End of dirty hack --->
145 bindtextdomain (PACKAGE, locale_path);
146 textdomain (PACKAGE);
147 setlocale (LC_MESSAGES, "");
148 #ifdef X_HAVE_UTF8_STRING
149 char *loc = setlocale(LC_CTYPE, "");
151 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
152 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
154 // Extract from locale language & region
157 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
158 strncpy(locbuf, loc, p - loc);
161 else if(strlen(loc) < sizeof(locbuf)-1)
164 // Locale 'C' does not give useful language info - assume en
165 if(!locbuf[0] || locbuf[0] == 'C')
166 strcpy(locbuf, "en");
168 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
170 strcpy(BC_Resources::language, locbuf);
171 if(strlen(p) < LEN_LANG)
172 strcpy(BC_Resources::region, p);
174 else if(strlen(locbuf) < LEN_LANG)
175 strcpy(BC_Resources::language, locbuf);
178 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
180 setlocale(LC_CTYPE, "");
189 int start_remote_control = 0;
191 for(int i = 1; i < argc; i++)
193 if(!strcmp(argv[i], "-h"))
195 operation = DO_USAGE;
198 if(!strcmp(argv[i], "-z"))
200 start_remote_control = 1;
203 if(!strcmp(argv[i], "-r"))
205 operation = DO_BATCHRENDER;
208 if(argv[i + 1][0] != '-')
210 strcpy(batch_path, argv[i + 1]);
216 if(!strcmp(argv[i], "-c"))
220 strcpy(config_path, argv[i + 1]);
225 fprintf(stderr, _("%s: -c needs a filename.\n"), argv[0]);
229 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
231 if(!strcmp(argv[i], "-d"))
232 operation = DO_DEAMON;
234 operation = DO_DEAMON_FG;
238 if(atol(argv[i + 1]) > 0)
240 deamon_port = atol(argv[i + 1]);
246 if(!strcmp(argv[i], "-b"))
248 operation = DO_BRENDER;
251 fprintf(stderr, _("-b may not be used by the user.\n"));
255 strcpy(deamon_path, argv[i + 1]);
258 if(!strcmp(argv[i], "-n"))
262 nice_value = atol(argv[i + 1]);
267 if(!strcmp(argv[i], "-x"))
274 new_filename = new char[BCTEXTLEN];
275 strcpy(new_filename, argv[i]);
276 fs.complete_path(new_filename);
278 filenames.append(new_filename);
285 if(operation == DO_GUI ||
286 operation == DO_DEAMON ||
287 operation == DO_DEAMON_FG ||
288 operation == DO_USAGE ||
289 operation == DO_BATCHRENDER)
291 _(PROGRAM_NAME " " CINELERRA_VERSION " " "(C)%d Adam Williams\n\n"
292 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
293 "and you are welcome to change it and/or distribute copies of it under\n"
294 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n"),
304 printf(_("\nUsage:\n"));
305 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
306 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
307 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
308 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
309 printf(_("-c = Configuration file to use instead of %s%s.\n"),
312 printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI. batch file is optional.\n"),
315 printf(_("filenames = files to load\n\n\n"));
322 if(operation == DO_DEAMON)
328 // Redhat 9 requires _exit instead of exit here.
333 RenderFarmClient client(deamon_port,
341 // Same thing without detachment
344 RenderFarmClient client(0,
354 BatchRenderThread *thread = new BatchRenderThread;
355 thread->start_rendering(config_path,
362 int restart = 0, done = 0;
364 BC_WindowBase::get_resources()->vframe_shm = 0;
366 mwindow.create_objects(1, !filenames.total, config_path);
368 // load the initial files on seperate tracks
369 // use a new thread so it doesn't block the GUI
373 CommandLineThread *thread = new CommandLineThread(&filenames, &mwindow);
377 // thread is not deleted
381 mwindow.gui->lock_window("main");
382 mwindow.load_backup();
383 mwindow.gui->unlock_window();
385 if( start_remote_control ) {
386 start_remote_control = 0;
387 mwindow.gui->remote_control->activate();
394 restart = mwindow.restart();
396 mwindow.save_backup();
398 start_remote_control =
399 mwindow.gui->remote_control->is_active();
404 mwindow.save_defaults();
406 filenames.remove_all_objects();
410 char exe_path[BCTEXTLEN];
411 int len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)-1);
414 char *av[4] = { 0, }; int ac = 0;
416 if( load_backup ) av[ac++] = (char*) "-x";
417 if( start_remote_control ) av[ac++] = (char*) "-z";