r370: Heroine Virutal's official release 1.2.1
[cinelerra_cv/mob.git] / hvirtual / cinelerra / assetedit.C
blobcda7119c65fb41dddd4b121bdf58a79a78723789
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 "new.h"
18 #include "preferences.h"
19 #include "transportque.h"
21 #include <string.h>
25 AssetEdit::AssetEdit(MWindow *mwindow)
26  : Thread()
28         this->mwindow = mwindow;
29         asset = 0;
30         window = 0;
31         set_synchronous(0);
35 AssetEdit::~AssetEdit()
40 void AssetEdit::edit_asset(Asset *asset)
42         if(asset)
43         {
44 // Allow more than one window
45                 this->asset = asset;
46                 Thread::start();
47         }
51 int AssetEdit::set_asset(Asset *asset)
53         this->asset = asset;
54         return 0;
57 void AssetEdit::run()
59         if(asset)
60         {
61                 new_asset = new Asset(asset->path);
62                 *new_asset = *asset;
63                 int result = 0;
65                 window = new AssetEditWindow(mwindow, this);
66                 window->create_objects();
67                 result = window->run_window();
69                 if(!result)
70                 {
71                         if(!asset->equivalent(*new_asset, 1, 1))
72                         {
73                                 mwindow->gui->lock_window();
74 // Omit index status from copy since an index rebuild may have been
75 // happening when new_asset was created but not be happening anymore.
76                                 asset->copy_from(new_asset, 0);
78                                 mwindow->gui->update(0,
79                                         2,
80                                         0,
81                                         0,
82                                         0, 
83                                         0,
84                                         0);
86 // Start index rebuilding
87                                 if(asset->audio_data)
88                                 {
89                                         char source_filename[BCTEXTLEN];
90                                         char index_filename[BCTEXTLEN];
91                                         IndexFile::get_index_filename(source_filename, 
92                                                 mwindow->preferences->index_directory,
93                                                 index_filename, 
94                                                 asset->path);
95                                         remove(index_filename);
96                                         asset->index_status = INDEX_NOTTESTED;
97                                         mwindow->mainindexes->add_next_asset(asset);
98                                         mwindow->mainindexes->start_build();
99                                 }
100                                 mwindow->gui->unlock_window();
103                                 mwindow->awindow->gui->lock_window();
104                                 mwindow->awindow->gui->update_assets();
105                                 mwindow->awindow->gui->unlock_window();
107                                 mwindow->restart_brender();
108                                 mwindow->sync_parameters(CHANGE_ALL);
109                         }
110                 }
112                 delete new_asset;
113                 delete window;
114                 window = 0;
115         }
125 AssetEditWindow::AssetEditWindow(MWindow *mwindow, AssetEdit *asset_edit)
126  : BC_Window(PROGRAM_NAME ": Asset Info", 
127         mwindow->gui->get_abs_cursor_x(1) - 400 / 2, 
128         mwindow->gui->get_abs_cursor_y(1) - 500 / 2, 
129         400, 
130         500,
131         400,
132         500,
133         0,
134         0,
135         1)
137         this->mwindow = mwindow;
138         this->asset_edit = asset_edit;
139         this->asset = asset_edit->new_asset;
140         bitspopup = 0;
141         if(asset->format == FILE_PCM)
142                 allow_edits = 1;
143         else
144                 allow_edits = 0;
151 AssetEditWindow::~AssetEditWindow()
153         if(bitspopup) delete bitspopup;
156 int AssetEditWindow::create_objects()
158         int y = 10, x = 10, x1 = 10, x2 = 150;
159         char string[1024];
160         int vmargin;
161         int hmargin1 = 180, hmargin2 = 290;
162         FileSystem fs;
164         if(allow_edits) 
165                 vmargin = 30;
166         else
167                 vmargin = 20;
169         add_subwindow(path_text = new AssetEditPathText(this, y));
170         add_subwindow(path_button = new AssetEditPath(mwindow, 
171                 this, 
172                 path_text, 
173                 y, 
174                 asset->path, 
175                 PROGRAM_NAME ": Asset path", _("Select a file for this asset:")));
176         y += 30;
178         add_subwindow(new BC_Title(x, y, _("File format:")));
179         x = x2;
180         add_subwindow(new BC_Title(x, y, File::formattostr(mwindow->plugindb, asset->format), MEDIUMFONT, YELLOW));
181         x = x1;
182         y += 20;
184         add_subwindow(new BC_Title(x, y, _("Bytes:")));
185         sprintf(string, "%lld", fs.get_size(asset->path));
186 // Do commas
187         int len = strlen(string);
188         int commas = (len - 1) / 3;
189         for(int i = len + commas, j = len, k; j >= 0 && i >= 0; i--, j--)
190         {
191                 k = (len - j - 1) / 3;
192                 if(k * 3 == len - j - 1 && j != len - 1 && string[j] != 0)
193                 {
194                         string[i--] = ',';
195                 }
197                 string[i] = string[j];
198         }
200         x = x2;
201         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
202         y += 30;
203         x = x1;
205         if(asset->audio_data)
206         {
207                 add_subwindow(new BC_Title(x, y, _("Audio:"), LARGEFONT, RED));
209                 y += 30;
211                 if(asset->acodec[0])
212                 {
213                         add_subwindow(new BC_Title(x, y, _("Compression:")));
214                         sprintf(string, "%c%c%c%c", 
215                                 asset->acodec[0], 
216                                 asset->acodec[1], 
217                                 asset->acodec[2], 
218                                 asset->acodec[3]);
219                         x = x2;
220                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
221                         y += vmargin;
222                         x = x1;
223                 }
225                 add_subwindow(new BC_Title(x, y, _("Channels:")));
226                 sprintf(string, "%d", asset->channels);
228                 x = x2;
229                 if(allow_edits)
230                 {
231                         BC_TumbleTextBox *textbox = new AssetEditChannels(this, string, x, y);
232                         textbox->create_objects();
233                         y += vmargin;
234                 }
235                 else
236                 {
237                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
238                         y += 20;
239                 }
241                 x = x1;
242                 add_subwindow(new BC_Title(x, y, _("Sample rate:")));
243                 sprintf(string, "%d", asset->sample_rate);
245                 x = x2;
246 //              if(allow_edits)
247                 if(1)
248                 {
249                         BC_TextBox *textbox;
250                         add_subwindow(textbox = new AssetEditRate(this, string, x, y));
251                         x += textbox->get_w();
252                         add_subwindow(new SampleRatePulldown(mwindow, textbox, x, y));
253                 }
254                 else
255                 {
256                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
257                 }
259                 y += 30;
260                 x = x1;
262                 add_subwindow(new BC_Title(x, y, _("Bits:")));
263                 x = x2;
264                 if(allow_edits)
265                 {
266                         bitspopup = new BitsPopup(this, 
267                                 x, 
268                                 y, 
269                                 &asset->bits, 
270                                 1, 
271                                 1, 
272                                 1,
273                                 0,
274                                 1);
275                         bitspopup->create_objects();
276                 }
277                 else
278                         add_subwindow(new BC_Title(x, y, File::bitstostr(asset->bits), MEDIUMFONT, YELLOW));
281                 x = x1;
282                 y += vmargin;
283                 add_subwindow(new BC_Title(x, y, _("Header length:")));
284                 sprintf(string, "%d", asset->header);
286                 x = x2;
287                 if(allow_edits)
288                         add_subwindow(new AssetEditHeader(this, string, x, y));
289                 else
290                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
292                 y += vmargin;
293                 x = x1;
295                 add_subwindow(new BC_Title(x, y, _("Byte order:")));
297                 if(allow_edits)
298                 {
299                         x = x2;
301                         add_subwindow(lohi = new AssetEditByteOrderLOHI(this, 
302                                 asset->byte_order, 
303                                 x, 
304                                 y));
305                         x += 70;
306                         add_subwindow(hilo = new AssetEditByteOrderHILO(this, 
307                                 !asset->byte_order, 
308                                 x, 
309                                 y));
310                         y += vmargin;
311                 }
312                 else
313                 {
314                         x = x2;
315                         if(asset->byte_order)
316                                 add_subwindow(new BC_Title(x, y, _("Lo-Hi"), MEDIUMFONT, YELLOW));
317                         else
318                                 add_subwindow(new BC_Title(x, y, _("Hi-Lo"), MEDIUMFONT, YELLOW));
319                         y += vmargin;
320                 }
323                 x = x1;
324                 if(allow_edits)
325                 {
326 //                      add_subwindow(new BC_Title(x, y, _("Values are signed:")));
327                         add_subwindow(new AssetEditSigned(this, asset->signed_, x, y));
328                 }
329                 else
330                 {
331                         if(!asset->signed_ && asset->bits == 8)
332                                 add_subwindow(new BC_Title(x, y, _("Values are unsigned")));
333                         else
334                                 add_subwindow(new BC_Title(x, y, _("Values are signed")));
335                 }
337                 y += 30;
338         }
340         x = x1;
341         if(asset->video_data)
342         {
343                 add_subwindow(new BC_Title(x, y, _("Video:"), LARGEFONT, RED));
345                 y += 30;
346                 x = x1;
347                 if(asset->vcodec[0])
348                 {
349                         add_subwindow(new BC_Title(x, y, _("Compression:")));
350                         sprintf(string, "%c%c%c%c", 
351                                 asset->vcodec[0], 
352                                 asset->vcodec[1], 
353                                 asset->vcodec[2], 
354                                 asset->vcodec[3]);
355                         x = x2;
356                         add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
357                         y += vmargin;
358                         x = x1;
359                 }
361                 add_subwindow(new BC_Title(x, y, _("Frame rate:")));
362                 x = x2;
363                 sprintf(string, "%.2f", asset->frame_rate);
364                 BC_TextBox *framerate;
365                 add_subwindow(framerate = new AssetEditFRate(this, string, x, y));
366                 x += 105;
367                 add_subwindow(new FrameRatePulldown(mwindow, framerate, x, y));
368                 
369                 y += 30;
370                 x = x1;
371                 add_subwindow(new BC_Title(x, y, _("Width:")));
372                 x = x2;
373                 sprintf(string, "%d", asset->width);
374                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
375                 
376                 y += vmargin;
377                 x = x1;
378                 add_subwindow(new BC_Title(x, y, _("Height:")));
379                 x = x2;
380                 sprintf(string, "%d", asset->height);
381                 add_subwindow(new BC_Title(x, y, string, MEDIUMFONT, YELLOW));
382                 y += 30;
383         }
385         add_subwindow(new BC_OKButton(this));
386         add_subwindow(new BC_CancelButton(this));
387         show_window();
388         flush();
389         return 0;
392 AssetEditChannels::AssetEditChannels(AssetEditWindow *fwindow, 
393         char *text, 
394         int x,
395         int y)
396  : BC_TumbleTextBox(fwindow, 
397                 (int)atol(text),
398                 (int)1,
399                 (int)MAXCHANNELS,
400                 x, 
401                 y, 
402                 50)
404         this->fwindow = fwindow;
407 int AssetEditChannels::handle_event()
409         fwindow->asset->channels = atol(get_text());
410         return 1;
413 AssetEditRate::AssetEditRate(AssetEditWindow *fwindow, char *text, int x, int y)
414  : BC_TextBox(x, y, 100, 1, text)
416         this->fwindow = fwindow;
419 int AssetEditRate::handle_event()
421         fwindow->asset->sample_rate = atol(get_text());
422         return 1;
425 AssetEditFRate::AssetEditFRate(AssetEditWindow *fwindow, char *text, int x, int y)
426  : BC_TextBox(x, y, 100, 1, text)
428         this->fwindow = fwindow;
431 int AssetEditFRate::handle_event()
433         fwindow->asset->frame_rate = atof(get_text());
434         return 1;
437 AssetEditHeader::AssetEditHeader(AssetEditWindow *fwindow, char *text, int x, int y)
438  : BC_TextBox(x, y, 100, 1, text)
440         this->fwindow = fwindow;
443 int AssetEditHeader::handle_event()
445         fwindow->asset->header = atol(get_text());
446         return 1;
449 AssetEditByteOrderLOHI::AssetEditByteOrderLOHI(AssetEditWindow *fwindow, 
450         int value, 
451         int x,
452         int y)
453  : BC_Radial(x, y, value, _("Lo-Hi"))
455         this->fwindow = fwindow;
458 int AssetEditByteOrderLOHI::handle_event()
460         fwindow->asset->byte_order = 1;
461         fwindow->hilo->update(0);
462         update(1);
463         return 1;
466 AssetEditByteOrderHILO::AssetEditByteOrderHILO(AssetEditWindow *fwindow, 
467         int value, 
468         int x, 
469         int y)
470  : BC_Radial(x, y, value, _("Hi-Lo"))
472         this->fwindow = fwindow;
475 int AssetEditByteOrderHILO::handle_event()
477         fwindow->asset->byte_order = 0;
478         fwindow->lohi->update(0);
479         update(1);
480         return 1;
483 AssetEditSigned::AssetEditSigned(AssetEditWindow *fwindow, 
484         int value, 
485         int x, 
486         int y)
487  : BC_CheckBox(x, y, value, _("Values are signed"))
489         this->fwindow = fwindow;
492 int AssetEditSigned::handle_event()
494         fwindow->asset->signed_ = get_value();
495         return 1;
504 AssetEditPathText::AssetEditPathText(AssetEditWindow *fwindow, int y)
505  : BC_TextBox(5, y, 300, 1, fwindow->asset->path) 
507         this->fwindow = fwindow; 
509 AssetEditPathText::~AssetEditPathText() 
512 int AssetEditPathText::handle_event() 
514         strcpy(fwindow->asset->path, get_text());
515         return 1;
518 AssetEditPath::AssetEditPath(MWindow *mwindow, AssetEditWindow *fwindow, BC_TextBox *textbox, int y, char *text, char *window_title, char *window_caption)
519  : BrowseButton(mwindow, fwindow, textbox, 310, y, text, window_title, window_caption, 0) 
521         this->fwindow = fwindow; 
523 AssetEditPath::~AssetEditPath() {}
530 AssetEditFormat::AssetEditFormat(AssetEditWindow *fwindow, char* default_, int y)
531  : FormatPopup(fwindow->mwindow->plugindb, 90, y)
533         this->fwindow = fwindow; 
535 AssetEditFormat::~AssetEditFormat() 
538 int AssetEditFormat::handle_event()
540         fwindow->asset->format = File::strtoformat(fwindow->mwindow->plugindb, get_selection(0, 0)->get_text());
541         return 1;