r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / main.C
blob668d1e843d8e30c7cd53fb2a211e175cd8c7bbe9
1 #include "arraylist.h"
2 #include "batchrender.h"
3 #include "bcsignals.h"
4 #include "builddate.h"
5 #include "filexml.h"
6 #include "filesystem.h"
7 #include "language.h"
8 #include "loadfile.inc"
9 #include "mainmenu.h"
10 #include "mwindow.h"
11 #include "mwindowgui.h"
12 #include "pluginserver.h"
13 #include "preferences.h"
14 #include "renderfarmclient.h"
15 #include <stdlib.h>
16 #include <string.h>
18 #include <locale.h>
20 #define PACKAGE "cinelerra"
21 #define LOCALEDIR "/usr/share/locale"
24 enum
26         DO_GUI,
27         DO_DEAMON,
28         DO_DEAMON_FG,
29         DO_BRENDER,
30         DO_USAGE,
31         DO_BATCHRENDER
34 #include "thread.h"
36 int main(int argc, char *argv[])
38 // handle command line arguments first
39         srand(time(0));
40         ArrayList<char*> filenames;
41         FileSystem fs;
43         int operation = DO_GUI;
44         int deamon_port = DEAMON_PORT;
45         char deamon_path[BCTEXTLEN];
46         char config_path[BCTEXTLEN];
47         char batch_path[BCTEXTLEN];
48         int nice_value = 20;
49         config_path[0] = 0;
50         batch_path[0] = 0;
51         deamon_path[0] = 0;
55 // detect an UTF-8 locale and try to use a non-Unicode locale instead
56 // <---Beginning of dirty hack
57 // This hack will be removed as soon as Cinelerra is UTF-8 compliant
58     char *s, *language;
60 // Query user locale
61     if ((s = getenv("LC_ALL"))  || 
62                 (s = getenv("LC_MESSAGES")) || 
63                 (s = getenv("LC_CTYPE")) || 
64                 (s = getenv ("LANG")))
65     {
66 // Test if user locale is set to Unicode        
67         if (strstr(s, ".UTF-8"))
68         {
69 // extract language  from language-charset@variant
70           language = strtok (s, ".@");
71 // set language as the default locale
72           setenv("LANG", language, 1);
73         }
74     }
75 // End of dirty hack --->
80         bindtextdomain (PACKAGE, LOCALEDIR);
81         textdomain (PACKAGE);
82         setlocale (LC_MESSAGES, "");
83         setlocale (LC_CTYPE, "");
85         for(int i = 1; i < argc; i++)
86         {
87                 if(!strcmp(argv[i], "-h"))
88                 {
89                         operation = DO_USAGE;
90                 }
91                 else
92                 if(!strcmp(argv[i], "-r"))
93                 {
94                         operation = DO_BATCHRENDER;
95                         if(argc > i + 1)
96                         {
97                                 if(argv[i + 1][0] != '-')
98                                 {
99                                         strcpy(batch_path, argv[i + 1]);
100                                         i++;
101                                 }
102                         }
103                 }
104                 else
105                 if(!strcmp(argv[i], "-c"))
106                 {
107                         if(argc > i + 1)
108                         {
109                                 strcpy(config_path, argv[i + 1]);
110                                 i++;
111                         }
112                         else
113                         {
114                                 fprintf(stderr, "%s: -c needs a filename.\n", argv[0]);
115                         }
116                 }
117                 else
118                 if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "-f"))
119                 {
120                         if(!strcmp(argv[i], "-d"))
121                                 operation = DO_DEAMON;
122                         else
123                                 operation = DO_DEAMON_FG;
125                         if(argc > i + 1)
126                         {
127                                 if(atol(argv[i + 1]) > 0)
128                                 {
129                                         deamon_port = atol(argv[i + 1]);
130                                         i++;
131                                 }
132                         }
133                 }
134                 else
135                 if(!strcmp(argv[i], "-b"))
136                 {
137                         operation = DO_BRENDER;
138                         if(i > argc - 2)
139                         {
140                                 fprintf(stderr, "-b may not be used by the user.\n");
141                                 exit(1);
142                         }
143                         else
144                                 strcpy(deamon_path, argv[i + 1]);
145                 }
146                 else
147                 if(!strcmp(argv[i], "-n"))
148                 {
149                         if(argc > i + 1)
150                         {
151                                 nice_value = atol(argv[i + 1]);
152                                 i++;
153                         }
154                 }
155                 else
156                 {
157                         char *new_filename;
158                         new_filename = new char[1024];
159                         strcpy(new_filename, argv[i]);
160             fs.complete_path(new_filename);
162                         filenames.append(new_filename);
163                 }
164         }
169         if(operation == DO_GUI || 
170                 operation == DO_DEAMON || 
171                 operation == DO_DEAMON_FG || 
172                 operation == DO_USAGE ||
173                 operation == DO_BATCHRENDER)
174         fprintf(stderr, 
175                 PROGRAM_NAME " " 
176                 CINELERRA_VERSION " " 
177                 BUILDDATE 
178                 " (C)2005 Heroine Virtual Ltd.\n\n"
180 PROGRAM_NAME " is free software, covered by the GNU General Public License,\n"
181 "and you are welcome to change it and/or distribute copies of it under\n"
182 "certain conditions. There is absolutely no warranty for " PROGRAM_NAME ".\n");
188         switch(operation)
189         {
190                 case DO_USAGE:
191                         printf(_("\nUsage:\n"));
192                         printf(_("%s [-f] [-c configuration] [-d port] [-n nice] [-r batch file] [filenames]\n\n"), argv[0]);
193                         printf(_("-d = Run in the background as renderfarm client.  The port (400) is optional.\n"));
194                         printf(_("-f = Run in the foreground as renderfarm client.  Substitute for -d.\n"));
195                         printf(_("-n = Nice value if running as renderfarm client. (20)\n"));
196                         printf(_("-c = Configuration file to use instead of %s%s.\n"), 
197                                 BCASTDIR, 
198                                 CONFIG_FILE);
199                         printf(_("-r = batch render the contents of the batch file (%s%s) with no GUI.  batch file is optional.\n"), 
200                                 BCASTDIR, 
201                                 BATCH_PATH);
202                         printf(_("filenames = files to load\n\n\n"));
203                         exit(0);
204                         break;
206                 case DO_DEAMON:
207                 case DO_DEAMON_FG:
208                 {
209                         if(operation == DO_DEAMON)
210                         {
211                                 int pid = fork();
213                                 if(pid)
214                                 {
215 // Redhat 9 requires _exit instead of exit here.
216                                         _exit(0);
217                                 }
218                         }
220                         RenderFarmClient client(deamon_port, 
221                                 0, 
222                                 nice_value, 
223                                 config_path);
224                         client.main_loop();
225                         break;
226                 }
228 // Same thing without detachment
229                 case DO_BRENDER:
230                 {
231                         RenderFarmClient client(0, 
232                                 deamon_path, 
233                                 20,
234                                 config_path);
235                         client.main_loop();
236                         break;
237                 }
239                 case DO_BATCHRENDER:
240                 {
241                         BatchRenderThread *thread = new BatchRenderThread;
242                         thread->start_rendering(config_path, 
243                                 batch_path);
244                         break;
245                 }
247                 case DO_GUI:
248                 {
249                         MWindow mwindow;
250                         mwindow.create_objects(1, 
251                                 !filenames.total,
252                                 config_path);
254 // load the initial files on seperate tracks
255                         if(filenames.total)
256                         {
257                                 mwindow.gui->lock_window();
258                                 mwindow.load_filenames(&filenames, LOAD_REPLACE);
259                                 if(filenames.total == 1)
260                                         mwindow.gui->mainmenu->add_load(filenames.values[0]);
261                                 mwindow.gui->unlock_window();
262                         }
264 // run the program
265                         mwindow.start();
266                         mwindow.save_defaults();
267 DISABLE_BUFFER
268                         break;
269                 }
270         }
272         filenames.remove_all_objects();
273         return 0;