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];
111 int start_remote_control = 0;
115 EDL::id_lock = new Mutex("EDL::id_lock");
118 get_exe_path(exe_path);
119 snprintf(env_path, sizeof(env_path), "CINELERRA_PATH=%s", exe_path);
121 sprintf(locale_path, "%s%s", exe_path, LOCALEDIR);
124 // detect an UTF-8 locale and try to use a non-Unicode locale instead
125 // <---Beginning of dirty hack
126 // This hack will be removed as soon as Cinelerra is UTF-8 compliant
127 // char *s, *language;
130 // if ((s = getenv("LC_ALL")) ||
131 // (s = getenv("LC_MESSAGES")) ||
132 // (s = getenv("LC_CTYPE")) ||
133 // (s = getenv ("LANG")))
135 // Test if user locale is set to Unicode
136 // if (strstr(s, ".UTF-8"))
138 // extract language from language-charset@variant
139 // language = strtok (s, ".@");
140 // set language as the default locale
141 // setenv("LANG", language, 1);
144 // End of dirty hack --->
146 bindtextdomain (PACKAGE, locale_path);
147 textdomain (PACKAGE);
148 setlocale (LC_MESSAGES, "");
149 #ifdef X_HAVE_UTF8_STRING
150 char *loc = setlocale(LC_CTYPE, "");
152 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
153 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
155 // Extract from locale language & region
158 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
159 strncpy(locbuf, loc, p - loc);
162 else if(strlen(loc) < sizeof(locbuf)-1)
165 // Locale 'C' does not give useful language info - assume en
166 if(!locbuf[0] || locbuf[0] == 'C')
167 strcpy(locbuf, "en");
169 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
171 strcpy(BC_Resources::language, locbuf);
172 if(strlen(p) < LEN_LANG)
173 strcpy(BC_Resources::region, p);
175 else if(strlen(locbuf) < LEN_LANG)
176 strcpy(BC_Resources::language, locbuf);
179 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
181 setlocale(LC_CTYPE, "");
190 for(int i = 1; i < argc; i++)
192 if(!strcmp(argv[i], "-h"))
194 operation = DO_USAGE;
197 if(!strcmp(argv[i], "-z"))
199 start_remote_control = 1;
202 if(!strcmp(argv[i], "-r"))
204 operation = DO_BATCHRENDER;
207 if(argv[i + 1][0] != '-')
209 strcpy(batch_path, argv[i + 1]);
215 if(!strcmp(argv[i], "-c"))
219 strcpy(config_path, argv[i + 1]);
224 fprintf(stderr, _("%s: -c needs a filename.\n"), argv[0]);
228 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
230 if(!strcmp(argv[i], "-d"))
231 operation = DO_DEAMON;
233 operation = DO_DEAMON_FG;
237 if(atol(argv[i + 1]) > 0)
239 deamon_port = atol(argv[i + 1]);
245 if(!strcmp(argv[i], "-b"))
247 operation = DO_BRENDER;
250 fprintf(stderr, _("-b may not be used by the user.\n"));
254 strcpy(deamon_path, argv[i + 1]);
257 if(!strcmp(argv[i], "-n"))
261 nice_value = atol(argv[i + 1]);
268 new_filename = new char[BCTEXTLEN];
269 strcpy(new_filename, argv[i]);
270 fs.complete_path(new_filename);
272 filenames.append(new_filename);
279 if(operation == DO_GUI ||
280 operation == DO_DEAMON ||
281 operation == DO_DEAMON_FG ||
282 operation == DO_USAGE ||
283 operation == DO_BATCHRENDER)
285 _(PROGRAM_NAME " " CINELERRA_VERSION " " "(C)%d Adam Williams\n\n"
286 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
287 "and you are welcome to change it and/or distribute copies of it under\n"
288 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n"),
298 printf(_("\nUsage:\n"));
299 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
300 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
301 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
302 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
303 printf(_("-c = Configuration file to use instead of %s%s.\n"),
306 printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI. batch file is optional.\n"),
309 printf(_("filenames = files to load\n\n\n"));
316 if(operation == DO_DEAMON)
322 // Redhat 9 requires _exit instead of exit here.
327 RenderFarmClient client(deamon_port,
335 // Same thing without detachment
338 RenderFarmClient client(0,
348 BatchRenderThread *thread = new BatchRenderThread;
349 thread->start_rendering(config_path,
359 BC_WindowBase::get_resources()->vframe_shm = 0;
361 mwindow.create_objects(1, !filenames.total, config_path);
363 // load the initial files on seperate tracks
364 // use a new thread so it doesn't block the GUI
368 CommandLineThread *thread = new CommandLineThread(&filenames, &mwindow);
372 // thread is not deleted
376 mwindow.gui->lock_window("main");
377 mwindow.load_backup();
378 mwindow.gui->unlock_window();
380 if( start_remote_control ) {
381 start_remote_control = 0;
382 mwindow.gui->remote_control->activate();
389 if( mwindow.reload() )
390 start_remote_control =
391 mwindow.gui->remote_control->is_active();
395 mwindow.save_backup();
399 mwindow.save_defaults();
401 filenames.remove_all_objects();