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 "fileserver.h"
28 #include "filesystem.h"
31 #include "loadfile.inc"
35 #include "mwindowgui.h"
36 #include "pluginserver.h"
37 #include "preferences.h"
38 #include "renderfarmclient.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];
112 int start_remote_control = 0;
116 EDL::id_lock = new Mutex("EDL::id_lock");
119 get_exe_path(exe_path);
120 snprintf(env_path, sizeof(env_path), "CINELERRA_PATH=%s", exe_path);
122 sprintf(locale_path, "%s%s", exe_path, LOCALEDIR);
125 // detect an UTF-8 locale and try to use a non-Unicode locale instead
126 // <---Beginning of dirty hack
127 // This hack will be removed as soon as Cinelerra is UTF-8 compliant
128 // char *s, *language;
131 // if ((s = getenv("LC_ALL")) ||
132 // (s = getenv("LC_MESSAGES")) ||
133 // (s = getenv("LC_CTYPE")) ||
134 // (s = getenv ("LANG")))
136 // Test if user locale is set to Unicode
137 // if (strstr(s, ".UTF-8"))
139 // extract language from language-charset@variant
140 // language = strtok (s, ".@");
141 // set language as the default locale
142 // setenv("LANG", language, 1);
145 // End of dirty hack --->
147 bindtextdomain (PACKAGE, locale_path);
148 textdomain (PACKAGE);
149 setlocale (LC_MESSAGES, "");
150 #ifdef X_HAVE_UTF8_STRING
151 char *loc = setlocale(LC_CTYPE, "");
153 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
154 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
156 // Extract from locale language & region
159 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
160 strncpy(locbuf, loc, p - loc);
163 else if(strlen(loc) < sizeof(locbuf)-1)
166 // Locale 'C' does not give useful language info - assume en
167 if(!locbuf[0] || locbuf[0] == 'C')
168 strcpy(locbuf, "en");
170 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
172 strcpy(BC_Resources::language, locbuf);
173 if(strlen(p) < LEN_LANG)
174 strcpy(BC_Resources::region, p);
176 else if(strlen(locbuf) < LEN_LANG)
177 strcpy(BC_Resources::language, locbuf);
180 printf(_(PROGRAM_NAME ": Could not set locale.\n"));
182 setlocale(LC_CTYPE, "");
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]);
269 new_filename = new char[BCTEXTLEN];
270 strcpy(new_filename, argv[i]);
271 fs.complete_path(new_filename);
273 filenames.append(new_filename);
280 if(operation == DO_GUI ||
281 operation == DO_DEAMON ||
282 operation == DO_DEAMON_FG ||
283 operation == DO_USAGE ||
284 operation == DO_BATCHRENDER)
286 _(PROGRAM_NAME " " CINELERRA_VERSION " " "(C)%d Adam Williams\n\n"
287 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
288 "and you are welcome to change it and/or distribute copies of it under\n"
289 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n"),
299 printf(_("\nUsage:\n"));
300 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
301 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
302 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
303 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
304 printf(_("-c = Configuration file to use instead of %s%s.\n"),
307 printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI. batch file is optional.\n"),
310 printf(_("filenames = files to load\n\n\n"));
317 if(operation == DO_DEAMON)
323 // Redhat 9 requires _exit instead of exit here.
328 RenderFarmClient client(deamon_port,
336 // Same thing without detachment
339 RenderFarmClient client(0,
349 BatchRenderThread *thread = new BatchRenderThread;
350 thread->start_rendering(config_path,
352 delete MWindow::file_server;
361 BC_WindowBase::get_resources()->vframe_shm = 0;
363 mwindow.create_objects(1, !filenames.total, config_path);
365 // load the initial files on seperate tracks
366 // use a new thread so it doesn't block the GUI
370 CommandLineThread *thread = new CommandLineThread(&filenames, &mwindow);
374 // thread is not deleted
378 mwindow.gui->lock_window("main");
379 mwindow.load_backup();
380 mwindow.gui->unlock_window();
382 if( start_remote_control ) {
383 start_remote_control = 0;
384 mwindow.gui->remote_control->activate();
391 if( mwindow.reload() )
392 start_remote_control =
393 mwindow.gui->remote_control->is_active();
397 mwindow.save_backup();
401 mwindow.save_defaults();
403 filenames.remove_all_objects();