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"
26 #include "fileserver.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 void get_exe_path(char *result)
96 // Get executable path
98 char proc_path[BCTEXTLEN];
101 sprintf(proc_path, "/proc/%d/exe", pid);
102 if((len = readlink(proc_path, result, BCTEXTLEN)) >= 0)
105 //printf("Preferences::Preferences %d %s\n", __LINE__, result);
106 char *ptr = strrchr(result, '/');
113 int main(int argc, char *argv[])
115 // handle command line arguments first
117 ArrayList<char*> filenames;
121 int operation = DO_GUI;
122 int deamon_port = DEAMON_PORT;
123 char deamon_path[BCTEXTLEN];
124 char config_path[BCTEXTLEN];
125 char batch_path[BCTEXTLEN];
126 char locale_path[BCTEXTLEN];
127 char exe_path[BCTEXTLEN];
129 int start_remote_control = 0;
133 EDL::id_lock = new Mutex("EDL::id_lock");
136 get_exe_path(exe_path);
137 sprintf(locale_path, "%s%s", exe_path, LOCALEDIR);
140 // detect an UTF-8 locale and try to use a non-Unicode locale instead
141 // <---Beginning of dirty hack
142 // This hack will be removed as soon as Cinelerra is UTF-8 compliant
143 // char *s, *language;
146 // if ((s = getenv("LC_ALL")) ||
147 // (s = getenv("LC_MESSAGES")) ||
148 // (s = getenv("LC_CTYPE")) ||
149 // (s = getenv ("LANG")))
151 // Test if user locale is set to Unicode
152 // if (strstr(s, ".UTF-8"))
154 // extract language from language-charset@variant
155 // language = strtok (s, ".@");
156 // set language as the default locale
157 // setenv("LANG", language, 1);
160 // End of dirty hack --->
162 bindtextdomain (PACKAGE, locale_path);
163 textdomain (PACKAGE);
164 setlocale (LC_MESSAGES, "");
165 #ifdef X_HAVE_UTF8_STRING
166 char *loc = setlocale(LC_CTYPE, "");
168 strcpy(BC_Resources::encoding, nl_langinfo(CODESET));
169 BC_Resources::locale_utf8 = !strcmp(BC_Resources::encoding, "UTF-8");
171 // Extract from locale language & region
174 if((p = strchr(loc, '.')) != 0 && (p - loc) < (int)sizeof(locbuf)-1) {
175 strncpy(locbuf, loc, p - loc);
178 else if(strlen(loc) < sizeof(locbuf)-1)
181 // Locale 'C' does not give useful language info - assume en
182 if(!locbuf[0] || locbuf[0] == 'C')
183 strcpy(locbuf, "en");
185 if((p = strchr(locbuf, '_')) && p - locbuf < LEN_LANG) {
187 strcpy(BC_Resources::language, locbuf);
188 if(strlen(p) < LEN_LANG)
189 strcpy(BC_Resources::region, p);
191 else if(strlen(locbuf) < LEN_LANG)
192 strcpy(BC_Resources::language, locbuf);
195 printf(PROGRAM_NAME ": Could not set locale.\n");
197 setlocale(LC_CTYPE, "");
206 for(int i = 1; i < argc; i++)
208 if(!strcmp(argv[i], "-h"))
210 operation = DO_USAGE;
213 if(!strcmp(argv[i], "-z"))
215 start_remote_control = 1;
218 if(!strcmp(argv[i], "-r"))
220 operation = DO_BATCHRENDER;
223 if(argv[i + 1][0] != '-')
225 strcpy(batch_path, argv[i + 1]);
231 if(!strcmp(argv[i], "-c"))
235 strcpy(config_path, argv[i + 1]);
240 fprintf(stderr, "%s: -c needs a filename.\n", argv[0]);
244 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
246 if(!strcmp(argv[i], "-d"))
247 operation = DO_DEAMON;
249 operation = DO_DEAMON_FG;
253 if(atol(argv[i + 1]) > 0)
255 deamon_port = atol(argv[i + 1]);
261 if(!strcmp(argv[i], "-b"))
263 operation = DO_BRENDER;
266 fprintf(stderr, "-b may not be used by the user.\n");
270 strcpy(deamon_path, argv[i + 1]);
273 if(!strcmp(argv[i], "-n"))
277 nice_value = atol(argv[i + 1]);
284 new_filename = new char[BCTEXTLEN];
285 strcpy(new_filename, argv[i]);
286 fs.complete_path(new_filename);
288 filenames.append(new_filename);
295 if(operation == DO_GUI ||
296 operation == DO_DEAMON ||
297 operation == DO_DEAMON_FG ||
298 operation == DO_USAGE ||
299 operation == DO_BATCHRENDER)
302 CINELERRA_VERSION " "
303 "(C)%d Adam Williams\n\n"
305 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
306 "and you are welcome to change it and/or distribute copies of it under\n"
307 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n",
317 printf(_("\nUsage:\n"));
318 printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
319 printf(_("-d = Run in the background as renderfarm client. The port (400) is optional.\n"));
320 printf(_("-f = Run in the foreground as renderfarm client. Substitute for -d.\n"));
321 printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
322 printf(_("-c = Configuration file to use instead of %s%s.\n"),
325 printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI. batch file is optional.\n"),
328 printf(_("filenames = files to load\n\n\n"));
335 if(operation == DO_DEAMON)
341 // Redhat 9 requires _exit instead of exit here.
346 RenderFarmClient client(deamon_port,
354 // Same thing without detachment
357 RenderFarmClient client(0,
367 BatchRenderThread *thread = new BatchRenderThread;
368 thread->start_rendering(config_path,
370 delete MWindow::file_server;
379 BC_WindowBase::get_resources()->vframe_shm = 0;
381 mwindow.create_objects(1, !filenames.total, config_path);
383 // load the initial files on seperate tracks
384 // use a new thread so it doesn't block the GUI
388 CommandLineThread *thread = new CommandLineThread(&filenames, &mwindow);
392 // thread is not deleted
396 mwindow.gui->lock_window("main");
397 mwindow.load_backup();
398 mwindow.gui->unlock_window();
400 if( start_remote_control ) {
401 start_remote_control = 0;
402 mwindow.gui->remote_control->activate();
409 if( mwindow.reload() )
410 start_remote_control =
411 mwindow.gui->remote_control->is_active();
415 mwindow.save_backup();
419 mwindow.save_defaults();
421 filenames.remove_all_objects();