r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / assetedit.C
blob969344bfbabbefa90ee787873977b5865a372ad5
1 #include "assetedit.h"
2 #include "assets.h"
3 #include "awindow.h"
4 #include "awindowgui.h"
5 #include "bcprogressbox.h"
6 #include "bitspopup.h"
7 #include "cache.h"
8 #include "cplayback.h"
9 #include "cwindow.h"
10 #include "file.h"
11 #include "filesystem.h"
12 #include "indexfile.h"
13 #include "mainindexes.h"
14 #include "mwindow.h"
15 #include "mwindowgui.h"
16 #include "new.h"
17 #include "preferences.h"
18 #include "transportque.h"
20 #include <string.h>
22 #include <libintl.h>
23 #define _(String) gettext(String)
24 #define gettext_noop(String) String
25 #define N_(String) gettext_noop (String)
28 AssetEdit::AssetEdit(MWindow *mwindow)
29  : Thread()
31         this->mwindow = mwindow;
32         asset = 0;
33         window = 0;
34         set_synchronous(0);
38 AssetEdit::~AssetEdit()
43 void AssetEdit::edit_asset(Asset *asset)
45         if(asset)
46         {
47 // Allow more than one window
48                 this->asset = asset;
49                 Thread::start();
50         }
54 int AssetEdit::set_asset(Asset *asset)
56         this->asset = asset;
57         return 0;
60 void AssetEdit::run()
62         if(asset)
63         {
64                 new_asset = new Asset(asset->path);
65                 *new_asset = *asset;
66                 int result = 0;
68                 window = new AssetEditWindow(mwindow, this);
69                 window->create_objects();
70                 result = window->run_window();
72                 if(!result)
73                 {
74                         if(!asset->equivalent(*new_asset, 1, 1))
75                         {
76                                 mwindow->gui->lock_window();
77 // Omit index status from copy since an index rebuild may have been
78 // happening when new_asset was created but not be happening anymore.
79                                 asset->copy_from(new_asset, 0);
81                                 mwindow->gui->update(0,
82                                         2,
83                                         0,
84                                         0,
85                                         0, 
86                                         0,
87                                         0);
89 // Start index rebuilding
90                                 if(asset->audio_data)
91                                 {
92                                         char source_filename[BCTEXTLEN];
93                                         char index_filename[BCTEXTLEN];
94                                         IndexFile::get_index_filename(source_filename, 
95                                                 mwindow->preferences->index_directory,
96                                                 index_filename, 
97                                                 asset->path);
98                                         remove(index_filename);
99                                         asset->index_status = INDEX_NOTTESTED;
100                                         mwindow->mainindexes->add_next_asset(asset);
101                                         mwindow->mainindexes->start_build();
102                                 }
103                                 mwindow->gui->unlock_window();
106                                 mwindow->awindow->gui->lock_window();
107                                 mwindow->awindow->gui->update_assets();
108                                 mwindow->awindow->gui->unlock_window();
110                                 mwindow->restart_brender();
111                                 mwindow->sync_parameters(CHANGE_ALL);
112                         }
113                 }
115                 delete new_asset;
116                 delete window;
117                 window = 0;
118         }
128 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
129  : BC_Window(PROGRAM_NAME ": Asset Info", 
130         mwindow->gui->get_abs_cursor_x() - 400 / 2, 
131         mwindow->gui->get_abs_cursor_y() - 500 / 2, 
132         400, 
133         500,
134         400,
135         500,
136         0,
137         0,
138         1)
140         this->mwindow = mwindow;
141         this->asset_edit = asset_edit;
142         this->asset = asset_edit->new_asset;
143         bitspopup = 0;
144         if(asset->format == FILE_PCM)
145                 allow_edits = 1;
146         else
147                 allow_edits = 0;
154 AssetEditWindow::~AssetEditWindow()
156         if(bitspopup) delete bitspopup;
159 int AssetEditWindow::create_objects()
161         int y = 10, x = 10, x1 = 10, x2 = 150;
162         char string[1024];
163         int vmargin;
164         int hmargin1 = 180, hmargin2 = 290;
165         FileSystem fs;
167         if(allow_edits) 
168                 vmargin = 30;
169         else
170                 vmargin = 20;
172         add_subwindow(path_text = new AssetEditPathText(this, y));
173         add_subwindow(path_button = new AssetEditPath(mwindow, 
174                 this, 
175                 path_text, 
176                 y, 
177                 asset->path, 
178                 PROGRAM_NAME ": Asset path", _("Select a file for this asset:")));
179         y += 30;
181         add_subwindow(new BC_Title(x, y, _("File format:")));
182         x = x2;
183         File file;
184         add_subwindow(new BC_Title(x, y, file.formattostr(mwindow->plugindb, asset->format), MEDIUMFONT, YELLOW));
185         x = x1;
186         y += 20;
188         add_subwindow(new BC_Title(x, y, _("Bytes:")));
189         sprintf(string, "%lld", fs.get_size(asset->path));
190 // Do commas
191         int len = strlen(string);
192         int commas = (len - 1) / 3;
193         for(int i = len + commas, j = len, k; j >= 0 && i >= 0; i--, j--)
194         {
195                 k = (len - j - 1) / 3;
196                 if(k * 3 == len - j - 1 && j != len - 1 && string[j] != 0)
197                 {
198                         string[i--] = ',';
199                 }
201                 string[i] = string[j];
202         }
204         x = x2;
205         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
206         y += 30;
207         x = x1;
209         if(asset->audio_data)
210         {
211                 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
213                 y += 30;
215                 if(asset->acodec[0])
216                 {
217                         add_subwindow(new BC_Title(x, y, _("Compression:")));
218                         sprintf(string, "%c%c%c%c", 
219                                 asset->acodec[0], 
220                                 asset->acodec[1], 
221                                 asset->acodec[2], 
222                                 asset->acodec[3]);
223                         x = x2;
224                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
225                         y += vmargin;
226                         x = x1;
227                 }
229                 add_subwindow(new BC_Title(x, y, _("Channels:")));
230                 sprintf(string, "%d", asset->channels);
232                 x = x2;
233                 if(allow_edits)
234                 {
235                         BC_TumbleTextBox *textbox = new AssetEditChannels(this, string, x, y);
236                         textbox->create_objects();
237                         y += vmargin;
238                 }
239                 else
240                 {
241                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
242                         y += 20;
243                 }
245                 x = x1;
246                 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
247                 sprintf(string, "%d", asset->sample_rate);
249                 x = x2;
250 //              if(allow_edits)
251                 if(1)
252                 {
253                         BC_TextBox *textbox;
254                         add_subwindow(textbox = new AssetEditRate(this, string, x, y));
255                         x += textbox->get_w();
256                         add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
257                 }
258                 else
259                 {
260                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
261                 }
263                 y += 30;
264                 x = x1;
266                 add_subwindow(new BC_Title(x, y, _("Bits:")));
267                 x = x2;
268                 if(allow_edits)
269                 {
270                         bitspopup = new BitsPopup(this, 
271                                 x, 
272                                 y, 
273                                 &asset->bits, 
274                                 1, 
275                                 1, 
276                                 1,
277                                 0,
278                                 1);
279                         bitspopup->create_objects();
280                 }
281                 else
282                         add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, YELLOW));
285                 x = x1;
286                 y += vmargin;
287                 add_subwindow(new BC_Title(x, y, _("Header length:")));
288                 sprintf(string, "%d", asset->header);
290                 x = x2;
291                 if(allow_edits)
292                         add_subwindow(new AssetEditHeader(this, string, x, y));
293                 else
294                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
296                 y += vmargin;
297                 x = x1;
299                 add_subwindow(new BC_Title(x, y, _("Byte order:")));
301                 if(allow_edits)
302                 {
303                         x = x2;
304                         add_subwindow(hilo = new AssetEditByteOrderHILO(this, 
305                                 !asset->byte_order, 
306                                 x, 
307                                 y));
308                         x += 70;
309                         add_subwindow(lohi = new AssetEditByteOrderLOHI(this, 
310                                 asset->byte_order, 
311                                 x, 
312                                 y));
313                         y += vmargin;
314                 }
315                 else
316                 {
317                         x = x2;
318                         if(asset->byte_order)
319                                 add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, YELLOW));
320                         else
321                                 add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, YELLOW));
322                         y += vmargin;
323                 }
326                 x = x1;
327                 if(allow_edits)
328                 {
329 //                      add_subwindow(new BC_Title(x, y, _("Values are signed:")));
330                         add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
331                 }
332                 else
333                 {
334                         if(!asset->signed_ && asset->bits == 8)
335                                 add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
336                         else
337                                 add_subwindow(new BC_Title(x, y, _("Values are signed")));
338                 }
340                 y += 30;
341         }
343         x = x1;
344         if(asset->video_data)
345         {
346                 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
348                 y += 30;
349                 x = x1;
350                 if(asset->vcodec[0])
351                 {
352                         add_subwindow(new BC_Title(x, y, _("Compression:")));
353                         sprintf(string, "%c%c%c%c", 
354                                 asset->vcodec[0], 
355                                 asset->vcodec[1], 
356                                 asset->vcodec[2], 
357                                 asset->vcodec[3]);
358                         x = x2;
359                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
360                         y += vmargin;
361                         x = x1;
362                 }
364                 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
365                 x = x2;
366                 sprintf(string, "%.2f", asset->frame_rate);
367                 BC_TextBox *framerate;
368                 add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
369                 x += 105;
370                 add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
371                 
372                 y += 30;
373                 x = x1;
374                 add_subwindow(new BC_Title(x, y, _("Width:")));
375                 x = x2;
376                 sprintf(string, "%d", asset->width);
377                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
378                 
379                 y += vmargin;
380                 x = x1;
381                 add_subwindow(new BC_Title(x, y, _("Height:")));
382                 x = x2;
383                 sprintf(string, "%d", asset->height);
384                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
385                 y += 30;
386         }
388         add_subwindow(new BC_OKButton(this));
389         add_subwindow(new BC_CancelButton(this));
390         show_window();
391         flush();
392         return 0;
395 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow, 
396         char *text, 
397         int x,
398         int y)
399  : BC_TumbleTextBox(fwindow, 
400                 (int)atol(text),
401                 (int)1,
402                 (int)MAXCHANNELS,
403                 x, 
404                 y, 
405                 50)
407         this->fwindow = fwindow;
410 int AssetEditChannels::handle_event()
412         fwindow->asset->channels = atol(get_text());
413         return 1;
416 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
417  : BC_TextBox(x, y, 100, 1, text)
419         this->fwindow = fwindow;
422 int AssetEditRate::handle_event()
424         fwindow->asset->sample_rate = atol(get_text());
425         return 1;
428 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
429  : BC_TextBox(x, y, 100, 1, text)
431         this->fwindow = fwindow;
434 int AssetEditFRate::handle_event()
436         fwindow->asset->frame_rate = atof(get_text());
437         return 1;
440 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
441  : BC_TextBox(x, y, 100, 1, text)
443         this->fwindow = fwindow;
446 int AssetEditHeader::handle_event()
448         fwindow->asset->header = atol(get_text());
449         return 1;
452 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow, 
453         int value, 
454         int x,
455         int y)
456  : BC_Radial(x, y, value, _("Lo-Hi"))
458         this->fwindow = fwindow;
461 int AssetEditByteOrderLOHI::handle_event()
463         fwindow->asset->byte_order = 1;
464         fwindow->hilo->update(0);
465         update(1);
466         return 1;
469 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow, 
470         int value, 
471         int x, 
472         int y)
473  : BC_Radial(x, y, value, _("Hi-Lo"))
475         this->fwindow = fwindow;
478 int AssetEditByteOrderHILO::handle_event()
480         fwindow->asset->byte_order = 0;
481         fwindow->lohi->update(0);
482         update(1);
483         return 1;
486 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow, 
487         int value, 
488         int x, 
489         int y)
490  : BC_CheckBox(x, y, value, _("Values are signed"))
492         this->fwindow = fwindow;
495 int AssetEditSigned::handle_event()
497         fwindow->asset->signed_ = get_value();
498         return 1;
507 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
508  : BC_TextBox(5, y, 300, 1, fwindow->asset->path) 
510         this->fwindow = fwindow; 
512 AssetEditPathText::~AssetEditPathText() 
515 int AssetEditPathText::handle_event() 
517         strcpy(fwindow->asset->path, get_text());
518         return 1;
521 AssetEditPath::AssetEditPath(MWindow *mwindow, AssetEditWindow *fwindow, BC_TextBox *textbox, int y, char *text, char *window_title, char *window_caption)
522  : BrowseButton(mwindow, fwindow, textbox, 310, y, text, window_title, window_caption, 0) 
524         this->fwindow = fwindow; 
526 AssetEditPath::~AssetEditPath() {}
533 AssetEditFormat::AssetEditFormat(AssetEditWindow *fwindow, char* default_, int y)
534  : FormatPopup(fwindow->mwindow->plugindb, 90, y)
536         this->fwindow = fwindow; 
538 AssetEditFormat::~AssetEditFormat() 
541 int AssetEditFormat::handle_event()
543         fwindow->asset->format = File::strtoformat(fwindow->mwindow->plugindb, get_selection(0, 0)->get_text());
544         return 1;