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"
38 #include "versioninfo.h"
44 #define PACKAGE "cinelerra"
45 #define LOCALEDIR "/locale/"
61 class CommandLineThread : public Thread
64 CommandLineThread(ArrayList<char*> *filenames,
67 this->filenames = filenames;
68 this->mwindow = mwindow;
79 mwindow->gui->lock_window("main");
81 mwindow->load_filenames(filenames, LOADMODE_REPLACE);
83 if(filenames->size() == 1)
84 mwindow->gui->mainmenu->add_load(filenames->get(0));
86 mwindow->gui->unlock_window();
91 ArrayList<char*> *filenames;
95 int main(int argc, char *argv[])
97 // handle command line arguments first
99 ArrayList<char*> filenames;
103 int operation = DO_GUI;
104 int deamon_port = DEAMON_PORT;
105 char deamon_path[BCTEXTLEN];
106 char config_path[BCTEXTLEN];
107 char batch_path[BCTEXTLEN];
108 char locale_path[BCTEXTLEN];
109 char exe_path[BCTEXTLEN];
110 char env_path[BCTEXTLEN];
115 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);
122 // detect an UTF-8 locale and try to use a non-Unicode locale instead
123 // <---Beginning of dirty hack
124 // This hack will be removed as soon as Cinelerra is UTF-8 compliant
125 // char *s, *language;
128 // if ((s = getenv("LC_ALL")) ||
129 // (s = getenv("LC_MESSAGES")) ||
130 // (s = getenv("LC_CTYPE")) ||
131 // (s = getenv ("LANG")))
133 // Test if user locale is set to Unicode
134 // if (strstr(s, ".UTF-8"))
136 // extract language from language-charset@variant
137 // language = strtok (s, ".@");
138 // set language as the default locale
139 // setenv("LANG", language, 1);
142 // End of dirty hack --->
144 bindtextdomain (PACKAGE, locale_path);
145 textdomain (PACKAGE);
146 setlocale (LC_MESSAGES, "");
147 #ifdef X_HAVE_UTF8_STRING
148 char *loc = setlocale(LC_CTYPE, "");
150 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
151 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
153 // Extract from locale language & region
156 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
157 strncpy(locbuf, loc, p - loc);
160 else if(strlen(loc) < sizeof(locbuf)-1)
163 // Locale 'C' does not give useful language info - assume en
164 if(!locbuf[0] || locbuf[0] == 'C')
165 strcpy(locbuf, "en");
167 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
169 strcpy(BC_Resources::language, locbuf);
170 if(strlen(p) < LEN_LANG)
171 strcpy(BC_Resources::region, p);
173 else if(strlen(locbuf) < LEN_LANG)
174 strcpy(BC_Resources::language, locbuf);
177 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
179 setlocale(LC_CTYPE, "");
184 int start_remote_control = 0;
186 for(int i = 1; i < argc; i++)
188 if(!strcmp(argv[i], "-h"))
190 operation = DO_USAGE;
193 if(!strcmp(argv[i], "-z"))
195 start_remote_control = 1;
198 if(!strcmp(argv[i], "-r"))
200 operation = DO_BATCHRENDER;
203 if(argv[i + 1][0] != '-')
205 strcpy(batch_path, argv[i + 1]);
211 if(!strcmp(argv[i], "-c"))
215 strcpy(config_path, argv[i + 1]);
220 fprintf(stderr, _("%s: -c needs a filename.\n"), argv[0]);
224 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
226 if(!strcmp(argv[i], "-d"))
227 operation = DO_DEAMON;
229 operation = DO_DEAMON_FG;
233 if(atol(argv[i + 1]) > 0)
235 deamon_port = atol(argv[i + 1]);
241 if(!strcmp(argv[i], "-b"))
243 operation = DO_BRENDER;
246 fprintf(stderr, _("-b may not be used by the user.\n"));
250 strcpy(deamon_path, argv[i + 1]);
253 if(!strcmp(argv[i], "-n"))
257 nice_value = atol(argv[i + 1]);
262 if(!strcmp(argv[i], "-x"))
269 new_filename = new char[BCTEXTLEN];
270 strcpy(new_filename, argv[i]);
271 fs.complete_path(new_filename);
272 filenames.append(new_filename);
278 if(operation == DO_GUI ||
279 operation == DO_DEAMON ||
280 operation == DO_DEAMON_FG ||
281 operation == DO_USAGE ||
282 operation == DO_BATCHRENDER) {
284 fprintf(stderr, PROGRAM_NAME " " CINELERRA_VERSION);
286 #define REPOMAINTXT ""
288 #ifndef COPYRIGHTTEXT1
289 #define COPYRIGHTTEXT1 ""
291 #ifndef COPYRIGHTTEXT2
292 #define COPYRIGHTTEXT2 ""
295 #define COMPILEDATE ""
297 fprintf(stderr, REPOMAINTXT COPYRIGHTTEXT1 COPYRIGHTTEXT2 COMPILEDATE
298 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
299 "and you are welcome to change it and/or distribute copies of it under\n"
300 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n\n");
306 printf(_("\nUsage:\n"));
307 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
308 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
309 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
310 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
311 printf(_("-c = Configuration file to use instead of %s%s.\n"),
314 printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI. batch file is optional.\n"),
317 printf(_("filenames = files to load\n\n\n"));
324 if(operation == DO_DEAMON)
330 // Redhat 9 requires _exit instead of exit here.
335 RenderFarmClient client(deamon_port,
343 // Same thing without detachment
346 RenderFarmClient client(0,
356 BatchRenderThread *thread = new BatchRenderThread;
357 thread->start_rendering(config_path,
364 int restart = 0, done = 0;
366 BC_WindowBase::get_resources()->vframe_shm = 0;
368 mwindow.create_objects(1, !filenames.total, config_path);
369 CommandLineThread *thread = 0;
371 // load the initial files on seperate tracks
372 // use a new thread so it doesn't block the GUI
373 if( filenames.total ) {
374 thread = new CommandLineThread(&filenames, &mwindow);
380 mwindow.gui->lock_window("main");
381 mwindow.load_backup();
382 mwindow.gui->unlock_window();
384 if( start_remote_control ) {
385 start_remote_control = 0;
386 mwindow.gui->remote_control->activate();
393 restart = mwindow.restart();
395 mwindow.save_backup();
397 start_remote_control =
398 mwindow.gui->remote_control->is_active();
403 mwindow.save_defaults();
405 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";
427 filenames.remove_all_objects();
428 delete EDL::id_lock; EDL::id_lock = 0;