r499: This commit was manufactured by cvs2svn to create tag 'r1_2_1-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / assetedit.C
blobc6f94fcb54c90c68e95678873be2772627b19297
1 #include "asset.h"
2 #include "assetedit.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 "language.h"
14 #include "mainindexes.h"
15 #include "mwindow.h"
16 #include "mwindowgui.h"
17 #include "theme.h"
18 #include "new.h"
19 #include "preferences.h"
20 #include "transportque.h"
22 #include <string.h>
26 AssetEdit::AssetEdit(MWindow *mwindow)
27  : Thread()
29         this->mwindow = mwindow;
30         asset = 0;
31         window = 0;
32         set_synchronous(0);
36 AssetEdit::~AssetEdit()
41 void AssetEdit::edit_asset(Asset *asset)
43         if(asset)
44         {
45 // Allow more than one window
46                 this->asset = asset;
47                 Thread::start();
48         }
52 int AssetEdit::set_asset(Asset *asset)
54         this->asset = asset;
55         return 0;
58 void AssetEdit::run()
60         if(asset)
61         {
62                 new_asset = new Asset(asset->path);
63                 *new_asset = *asset;
64                 int result = 0;
66                 window = new AssetEditWindow(mwindow, this);
67                 window->create_objects();
68                 result = window->run_window();
70                 if(!result)
71                 {
72                         if(!asset->equivalent(*new_asset, 1, 1))
73                         {
74                                 mwindow->gui->lock_window();
75 // Omit index status from copy since an index rebuild may have been
76 // happening when new_asset was created but not be happening anymore.
77                                 asset->copy_from(new_asset, 0);
79                                 mwindow->gui->update(0,
80                                         2,
81                                         0,
82                                         0,
83                                         0, 
84                                         0,
85                                         0);
87 // Start index rebuilding
88                                 if(asset->audio_data)
89                                 {
90                                         char source_filename[BCTEXTLEN];
91                                         char index_filename[BCTEXTLEN];
92                                         IndexFile::get_index_filename(source_filename, 
93                                                 mwindow->preferences->index_directory,
94                                                 index_filename, 
95                                                 asset->path);
96                                         remove(index_filename);
97                                         asset->index_status = INDEX_NOTTESTED;
98                                         mwindow->mainindexes->add_next_asset(asset);
99                                         mwindow->mainindexes->start_build();
100                                 }
101                                 mwindow->gui->unlock_window();
104                                 mwindow->awindow->gui->lock_window();
105                                 mwindow->awindow->gui->update_assets();
106                                 mwindow->awindow->gui->unlock_window();
108                                 mwindow->restart_brender();
109                                 mwindow->sync_parameters(CHANGE_ALL);
110                         }
111                 }
113                 delete new_asset;
114                 delete window;
115                 window = 0;
116         }
126 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
127  : BC_Window(PROGRAM_NAME ": Asset Info", 
128         mwindow->gui->get_abs_cursor_x(1) - 400 / 2, 
129         mwindow->gui->get_abs_cursor_y(1) - 500 / 2, 
130         400, 
131         600,
132         400,
133         500,
134         0,
135         0,
136         1)
138         this->mwindow = mwindow;
139         this->asset_edit = asset_edit;
140         this->asset = asset_edit->new_asset;
141         bitspopup = 0;
142         if(asset->format == FILE_PCM)
143                 allow_edits = 1;
144         else
145                 allow_edits = 0;
152 AssetEditWindow::~AssetEditWindow()
154         if(bitspopup) delete bitspopup;
157 int AssetEditWindow::create_objects()
159         int y = 10, x = 10, x1 = 10, x2 = 150;
160         char string[1024];
161         int vmargin;
162         int hmargin1 = 180, hmargin2 = 290;
163         FileSystem fs;
165         if(allow_edits) 
166                 vmargin = 30;
167         else
168                 vmargin = 20;
170         add_subwindow(path_text = new AssetEditPathText(this, y));
171         add_subwindow(path_button = new AssetEditPath(mwindow, 
172                 this, 
173                 path_text, 
174                 y, 
175                 asset->path, 
176                 PROGRAM_NAME ": Asset path", _("Select a file for this asset:")));
177         y += 30;
179         add_subwindow(new BC_Title(x, y, _("File format:")));
180         x = x2;
181         add_subwindow(new BC_Title(x, y, File::formattostr(mwindow->plugindb, asset->format), MEDIUMFONT, mwindow->theme->edit_font_color));
182         x = x1;
183         y += 20;
185         add_subwindow(new BC_Title(x, y, _("Bytes:")));
186         sprintf(string, "%lld", fs.get_size(asset->path));
187 // Do commas
188         int len = strlen(string);
189         int commas = (len - 1) / 3;
190         for(int i = len + commas, j = len, k; j >= 0 && i >= 0; i--, j--)
191         {
192                 k = (len - j - 1) / 3;
193                 if(k * 3 == len - j - 1 && j != len - 1 && string[j] != 0)
194                 {
195                         string[i--] = ',';
196                 }
198                 string[i] = string[j];
199         }
201         x = x2;
202         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
203         y += 30;
204         x = x1;
206         if(asset->audio_data)
207         {
208                 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
210                 y += 30;
212                 if(asset->acodec[0])
213                 {
214                         add_subwindow(new BC_Title(x, y, _("Compression:")));
215                         sprintf(string, "%c%c%c%c", 
216                                 asset->acodec[0], 
217                                 asset->acodec[1], 
218                                 asset->acodec[2], 
219                                 asset->acodec[3]);
220                         x = x2;
221                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
222                         y += vmargin;
223                         x = x1;
224                 }
226                 add_subwindow(new BC_Title(x, y, _("Channels:")));
227                 sprintf(string, "%d", asset->channels);
229                 x = x2;
230                 if(allow_edits)
231                 {
232                         BC_TumbleTextBox *textbox = new AssetEditChannels(this, string, x, y);
233                         textbox->create_objects();
234                         y += vmargin;
235                 }
236                 else
237                 {
238                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
239                         y += 20;
240                 }
242                 x = x1;
243                 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
244                 sprintf(string, "%d", asset->sample_rate);
246                 x = x2;
247 //              if(allow_edits)
248                 if(1)
249                 {
250                         BC_TextBox *textbox;
251                         add_subwindow(textbox = new AssetEditRate(this, string, x, y));
252                         x += textbox->get_w();
253                         add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
254                 }
255                 else
256                 {
257                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
258                 }
260                 y += 30;
261                 x = x1;
263                 add_subwindow(new BC_Title(x, y, _("Bits:")));
264                 x = x2;
265                 if(allow_edits)
266                 {
267                         bitspopup = new BitsPopup(this, 
268                                 x, 
269                                 y, 
270                                 &asset->bits, 
271                                 1, 
272                                 1, 
273                                 1,
274                                 0,
275                                 1);
276                         bitspopup->create_objects();
277                 }
278                 else
279                         add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, mwindow->theme->edit_font_color));
282                 x = x1;
283                 y += vmargin;
284                 add_subwindow(new BC_Title(x, y, _("Header length:")));
285                 sprintf(string, "%d", asset->header);
287                 x = x2;
288                 if(allow_edits)
289                         add_subwindow(new AssetEditHeader(this, string, x, y));
290                 else
291                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
293                 y += vmargin;
294                 x = x1;
296                 add_subwindow(new BC_Title(x, y, _("Byte order:")));
298                 if(allow_edits)
299                 {
300                         x = x2;
302                         add_subwindow(lohi = new AssetEditByteOrderLOHI(this, 
303                                 asset->byte_order, 
304                                 x, 
305                                 y));
306                         x += 70;
307                         add_subwindow(hilo = new AssetEditByteOrderHILO(this, 
308                                 !asset->byte_order, 
309                                 x, 
310                                 y));
311                         y += vmargin;
312                 }
313                 else
314                 {
315                         x = x2;
316                         if(asset->byte_order)
317                                 add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, mwindow->theme->edit_font_color));
318                         else
319                                 add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, mwindow->theme->edit_font_color));
320                         y += vmargin;
321                 }
324                 x = x1;
325                 if(allow_edits)
326                 {
327 //                      add_subwindow(new BC_Title(x, y, _("Values are signed:")));
328                         add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
329                 }
330                 else
331                 {
332                         if(!asset->signed_ && asset->bits == 8)
333                                 add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
334                         else
335                                 add_subwindow(new BC_Title(x, y, _("Values are signed")));
336                 }
338                 y += 30;
339         }
341         x = x1;
342         if(asset->video_data)
343         {
344                 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
346                 y += 30;
347                 x = x1;
348                 if(asset->vcodec[0])
349                 {
350                         add_subwindow(new BC_Title(x, y, _("Compression:")));
351                         sprintf(string, "%c%c%c%c", 
352                                 asset->vcodec[0], 
353                                 asset->vcodec[1], 
354                                 asset->vcodec[2], 
355                                 asset->vcodec[3]);
356                         x = x2;
357                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
358                         y += vmargin;
359                         x = x1;
360                 }
362                 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
363                 x = x2;
364                 sprintf(string, "%.2f", asset->frame_rate);
365                 BC_TextBox *framerate;
366                 add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
367                 x += 105;
368                 add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
369                 
370                 y += 30;
371                 x = x1;
372                 add_subwindow(new BC_Title(x, y, _("Width:")));
373                 x = x2;
374                 sprintf(string, "%d", asset->width);
375                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
376                 
377                 y += vmargin;
378                 x = x1;
379                 add_subwindow(new BC_Title(x, y, _("Height:")));
380                 x = x2;
381                 sprintf(string, "%d", asset->height);
382                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, mwindow->theme->edit_font_color));
383                 y += 30;
384                 
385                 x = x1;
386                 add_subwindow(new BC_Title(x, y, _("Reel Name:")));
387                 x = x2;
388                 add_subwindow(new AssetEditReelName(this, x, y));
389                 y += 30;
390                 
391                 x = x1;
392                 add_subwindow(new BC_Title(x, y, _("Reel Number:")));
393                 x = x2;
394                 add_subwindow(new AssetEditReelNumber(this, x, y));
395                 y += 30;
396                 
397                 x = x1;
398                 add_subwindow(new BC_Title(x, y, _("Time Code Start:")));
399                 x = x2;
401 // Calculate values to enter into textboxes
402                 char tc[12];
403                 
404                 Units::totext(tc,
405                         asset->tcstart / asset->frame_rate,
406                         TIME_HMSF,
407                         asset->sample_rate,
408                         asset->frame_rate);
409                 
410                 tc[1] = '\0';
411                 tc[4] = '\0';
412                 tc[7] = '\0';
413                 
414                 add_subwindow(new AssetEditTCStartTextBox(this, atoi(tc), x, y,
415                         (int) (asset->frame_rate * 60 * 60)));
416                 x += 30;
417                 add_subwindow(new BC_Title(x, y, ":"));
418                 x += 10;
419                 add_subwindow(new AssetEditTCStartTextBox(this, atoi(tc + 2), x, y,
420                         (int) (asset->frame_rate * 60)));
421                 x += 30;
422                 add_subwindow(new BC_Title(x, y, ":"));
423                 x += 10;
424                 add_subwindow(new AssetEditTCStartTextBox(this, atoi(tc + 5), x, y,
425                         (int) (asset->frame_rate)));
426                 x += 30;
427                 add_subwindow(new BC_Title(x, y, ":"));
428                 x += 10;
429                 add_subwindow(new AssetEditTCStartTextBox(this, atoi(tc + 8), x, y, 1));
432                 y += 30;
433         }
435         add_subwindow(new BC_OKButton(this));
436         add_subwindow(new BC_CancelButton(this));
437         show_window();
438         flush();
439         return 0;
442 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow, 
443         char *text, 
444         int x,
445         int y)
446  : BC_TumbleTextBox(fwindow, 
447                 (int)atol(text),
448                 (int)1,
449                 (int)MAXCHANNELS,
450                 x, 
451                 y, 
452                 50)
454         this->fwindow = fwindow;
457 int AssetEditChannels::handle_event()
459         fwindow->asset->channels = atol(get_text());
460         return 1;
463 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
464  : BC_TextBox(x, y, 100, 1, text)
466         this->fwindow = fwindow;
469 int AssetEditRate::handle_event()
471         fwindow->asset->sample_rate = atol(get_text());
472         return 1;
475 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
476  : BC_TextBox(x, y, 100, 1, text)
478         this->fwindow = fwindow;
481 int AssetEditFRate::handle_event()
483         fwindow->asset->frame_rate = atof(get_text());
484         return 1;
487 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
488  : BC_TextBox(x, y, 100, 1, text)
490         this->fwindow = fwindow;
493 int AssetEditHeader::handle_event()
495         fwindow->asset->header = atol(get_text());
496         return 1;
499 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow, 
500         int value, 
501         int x,
502         int y)
503  : BC_Radial(x, y, value, _("Lo-Hi"))
505         this->fwindow = fwindow;
508 int AssetEditByteOrderLOHI::handle_event()
510         fwindow->asset->byte_order = 1;
511         fwindow->hilo->update(0);
512         update(1);
513         return 1;
516 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow, 
517         int value, 
518         int x, 
519         int y)
520  : BC_Radial(x, y, value, _("Hi-Lo"))
522         this->fwindow = fwindow;
525 int AssetEditByteOrderHILO::handle_event()
527         fwindow->asset->byte_order = 0;
528         fwindow->lohi->update(0);
529         update(1);
530         return 1;
533 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow, 
534         int value, 
535         int x, 
536         int y)
537  : BC_CheckBox(x, y, value, _("Values are signed"))
539         this->fwindow = fwindow;
542 int AssetEditSigned::handle_event()
544         fwindow->asset->signed_ = get_value();
545         return 1;
554 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
555  : BC_TextBox(5, y, 300, 1, fwindow->asset->path) 
557         this->fwindow = fwindow; 
559 AssetEditPathText::~AssetEditPathText() 
562 int AssetEditPathText::handle_event() 
564         strcpy(fwindow->asset->path, get_text());
565         return 1;
568 AssetEditPath::AssetEditPath(MWindow *mwindow, AssetEditWindow *fwindow, BC_TextBox *textbox, int y, char *text, char *window_title, char *window_caption)
569  : BrowseButton(mwindow, fwindow, textbox, 310, y, text, window_title, window_caption, 0) 
571         this->fwindow = fwindow; 
573 AssetEditPath::~AssetEditPath() {}
580 AssetEditFormat::AssetEditFormat(AssetEditWindow *fwindow, char* default_, int y)
581  : FormatPopup(fwindow->mwindow->plugindb, 90, y)
583         this->fwindow = fwindow; 
585 AssetEditFormat::~AssetEditFormat() 
588 int AssetEditFormat::handle_event()
590         fwindow->asset->format = File::strtoformat(fwindow->mwindow->plugindb, get_selection(0, 0)->get_text());
591         return 1;
597 AssetEditReelName::AssetEditReelName(AssetEditWindow *fwindow, int x, int y)
598  : BC_TextBox(x, y, 300, 1, fwindow->asset->reel_name)
600         this->fwindow = fwindow;
602 AssetEditReelName::~AssetEditReelName()
605 int AssetEditReelName::handle_event()
607         strcpy(fwindow->asset->reel_name, get_text());
614 AssetEditReelNumber::AssetEditReelNumber(AssetEditWindow *fwindow, int x, int y)
615  : BC_TextBox(x, y, 200, 1, fwindow->asset->reel_number)
617         this->fwindow = fwindow;
619 AssetEditReelNumber::~AssetEditReelNumber()
622 int AssetEditReelNumber::handle_event()
624         char *text = get_text() + strlen(get_text()) - 1;
625         
626         // Don't let user enter an invalid character -- only numbers here
627         if(*text < 48 ||
628                 *text > 57)
629         {
630                 *text = '\0';
631         }
633         fwindow->asset->reel_number = atoi(get_text());
640 AssetEditTCStartTextBox::AssetEditTCStartTextBox(AssetEditWindow *fwindow, int value, int x, int y, int multiplier)
641  : BC_TextBox(x, y, 30, 1, value)
643         this->fwindow = fwindow;
644         this->multiplier = multiplier;
645         previous = value;
647 AssetEditTCStartTextBox::~AssetEditTCStartTextBox()
650 int AssetEditTCStartTextBox::handle_event()
652         fwindow->asset->tcstart -= previous * multiplier;
653         fwindow->asset->tcstart += atoi(get_text()) * multiplier;
654         previous = atoi(get_text());