r602: Fix baver's code... don't insert timecode when show_tc is not set
[cinelerra_cv/mob.git] / cinelerra / vwindow.C
blob76256e0e9449e7d40fe853502d0fab26c60843cb
1 #include "asset.h"
2 #include "assets.h"
3 #include "clipedit.h"
4 #include "defaults.h"
5 #include "edl.h"
6 #include "edlsession.h"
7 #include "filesystem.h"
8 #include "filexml.h"
9 #include "language.h"
10 #include "localsession.h"
11 #include "mainclock.h"
12 #include "mwindow.h"
13 #include "mwindowgui.h"
14 #include "playbackengine.h"
15 #include "tracks.h"
16 #include "transportque.h"
17 #include "vplayback.h"
18 #include "vtimebar.h"
19 #include "vtracking.h"
20 #include "vwindow.h"
21 #include "vwindowgui.h"
24 VWindow::VWindow(MWindow *mwindow) : Thread()
26         this->mwindow = mwindow;
27         asset = 0;
31 VWindow::~VWindow()
33 //printf("VWindow::~VWindow 1\n");
34         delete playback_engine;
35 //printf("VWindow::~VWindow 1\n");
36         delete playback_cursor;
37         delete_edl();
38         delete clip_edit;
39 //printf("VWindow::~VWindow 2\n");
42 void VWindow::delete_edl()
44 //printf("VWindow::delete_edl 1\n");
45         if(mwindow->edl->vwindow_edl)
46         {
47                 if (!edl_shared) 
48                         delete mwindow->edl->vwindow_edl;
49                 mwindow->edl->vwindow_edl = 0;
50         }
52         if(asset) delete asset;
53         asset = 0;
54         edl_shared = 0;
58 void VWindow::load_defaults()
62 int VWindow::create_objects()
64 //printf("VWindow::create_objects 1\n");
65         gui = new VWindowGUI(mwindow, this);
66 //printf("VWindow::create_objects 1\n");
67         gui->create_objects();
68 //printf("VWindow::create_objects 1\n");
70         playback_engine = new VPlayback(mwindow, this, gui->canvas);
71 //printf("VWindow::create_objects 1\n");
73 // Start command loop
74         playback_engine->create_objects();
75 //printf("VWindow::create_objects 1\n");
76         gui->transport->set_engine(playback_engine);
77 //printf("VWindow::create_objects 1\n");
78         playback_cursor = new VTracking(mwindow, this);
79 //printf("VWindow::create_objects 1\n");
80         playback_cursor->create_objects();
81 //printf("VWindow::create_objects 2\n");
83         clip_edit = new ClipEdit(mwindow, 0, this);
84         return 0;
87 void VWindow::run()
89         gui->run_window();
92 EDL* VWindow::get_edl()
94 //printf("VWindow::get_edl 1 %p\n", edl);
95         return mwindow->edl->vwindow_edl;
98 Asset* VWindow::get_asset()
100         return this->asset;
103 void VWindow::change_source()
105 //printf("VWindow::change_source() 1 %p\n", mwindow->edl->vwindow_edl);
106         if(mwindow->edl->vwindow_edl)
107         {
108                 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
109                 update_position(CHANGE_ALL, 1, 1);
110         }
111         else
112         {
113                 if(asset) delete asset;
114                 asset = 0;
115                 edl_shared = 0;
116         }
119 void VWindow::change_source(Asset *asset)
121 //printf("VWindow::change_source 1\n");
122 //      if(asset && this->asset &&
123 //              asset->id == this->asset->id &&
124 //              asset == this->asset) return;
126 //printf("VWindow::change_source(Asset *asset) 1\n");
128         char title[BCTEXTLEN];
129         FileSystem fs;
130         fs.extract_name(title, asset->path);
131 //printf("VWindow::change_source 1\n");
133         delete_edl();
134 //printf("VWindow::change_source 1\n");
136 // Generate EDL off of main EDL for cutting
137         this->asset = new Asset;
138         *this->asset = *asset;
139         mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
140         edl_shared = 0;
141         mwindow->edl->vwindow_edl->create_objects();
142         mwindow->asset_to_edl(mwindow->edl->vwindow_edl, asset);
143 //printf("VWindow::change_source 1 %d %d\n", edl->local_session->loop_playback, mwindow->edl->local_session->loop_playback);
144 //edl->dump();
146 // Update GUI
147         gui->change_source(mwindow->edl->vwindow_edl, title);
148         update_position(CHANGE_ALL, 1, 1);
151 // Update master session
152         strcpy(mwindow->edl->session->vwindow_folder, MEDIA_FOLDER);
153         mwindow->edl->session->vwindow_source = 0;
154         int i = 0;
155         for(Asset *current = mwindow->edl->assets->first; 
156                 current;
157                 current = NEXT)
158         {
159                 if(this->asset->equivalent(*current, 0, 0))
160                 {
161                         mwindow->edl->session->vwindow_source = i;
162                         break;
163                 }
164                 i++;
165         }
167 //printf("VWindow::change_source 2\n");
170 void VWindow::change_source(EDL *edl)
172 //printf("VWindow::change_source(EDL *edl) 1\n");
173 //printf("VWindow::change_source %p\n", edl);
174 // EDLs are identical
175         if(edl && mwindow->edl->vwindow_edl && 
176                 edl->id == mwindow->edl->vwindow_edl->id) return;
178         delete_edl();
180         if(edl)
181         {
182                 this->asset = 0;
183                 mwindow->edl->vwindow_edl = edl;
184 // in order not to later delete edl if it is shared
185                 edl_shared = 1;
186 //printf("VWindow::change_source 1\n");
187 //edl->dump();
188 //printf("VWindow::change_source 2\n");
190 // Update GUI
191                 gui->change_source(edl, edl->local_session->clip_title);
192                 update_position(CHANGE_ALL, 1, 1);
194 // Update master session
195                 strcpy(mwindow->edl->session->vwindow_folder, CLIP_FOLDER);
196                 mwindow->edl->session->vwindow_source = 
197                         mwindow->edl->clips.number_of(edl);
198         }
199         else
200                 gui->change_source(edl, _("Viewer"));
204 void VWindow::remove_source()
206         delete_edl();
207         gui->change_source(0, _("Viewer"));
210 void VWindow::change_source(char *folder, int item)
212 //printf("VWindow::change_source(char *folder, int item) 1\n");
213         int result = 0;
214 // Search EDLs
215         if(!strcasecmp(folder, CLIP_FOLDER))
216         {
217                 if(item < mwindow->edl->clips.total)
218                 {
219                         change_source(mwindow->edl->clips.values[item]);
220                         result = 1;
221                 }
222         }
223         else
224 // Search media
225         if(!strcasecmp(folder, MEDIA_FOLDER))
226         {
227                 if(item < mwindow->edl->assets->total())
228                 {
229                         change_source(mwindow->edl->assets->get_item_number(item));
230                         result = 1;
231                 }
232         }
233         else
234 // Search extra clip folders
235         {
236         }
237         
238         if(!result)
239         {
240                 remove_source();
241         }
247 void VWindow::goto_start()
249         if(get_edl())
250         {
251                 get_edl()->local_session->selectionstart = 
252                         get_edl()->local_session->selectionend = 0;
253                 update_position(CHANGE_NONE, 
254                         0, 
255                         1);
256         }
259 void VWindow::goto_end()
261         if(get_edl())
262         {
263                 get_edl()->local_session->selectionstart = 
264                         get_edl()->local_session->selectionend = 
265                         get_edl()->tracks->total_length();
266                 update_position(CHANGE_NONE, 
267                         0, 
268                         1);
269         }
272 void VWindow::update(int do_timebar)
274         if(do_timebar)
275                 gui->timebar->update();
278 void VWindow::update_position(int change_type, 
279         int use_slider, 
280         int update_slider)
282         EDL *edl = get_edl();
283         if(edl)
284         {
285                 Asset *asset = edl->assets->first;
286                 if(use_slider) 
287                 {
288                         edl->local_session->selectionstart = 
289                                 edl->local_session->selectionend = 
290                                 gui->slider->get_value();
291                 }
293                 if(update_slider)
294                 {
295                         gui->slider->set_position();
296                 }
298                 playback_engine->que->send_command(CURRENT_FRAME, 
299                         change_type,
300                         edl,
301                         1);
303                 gui->clock->update(edl->local_session->selectionstart +
304                         asset->tcstart / 
305                         (asset->video_data ? asset->frame_rate : asset->sample_rate));
306         }
309 void VWindow::set_inpoint()
311         EDL *edl = get_edl();
312         if(edl)
313         {
314                 edl->set_inpoint(edl->local_session->selectionstart);
315                 gui->timebar->update();
316         }
319 void VWindow::set_outpoint()
321         EDL *edl = get_edl();
322         if(edl)
323         {
324                 edl->set_outpoint(edl->local_session->selectionstart);
325                 gui->timebar->update();
326         }
329 void VWindow::clear_inpoint()
331         EDL *edl = get_edl();
332         if(edl)
333         {
334                 edl->local_session->in_point = -1;
335                 gui->timebar->update();
336         }
339 void VWindow::clear_outpoint()
341         EDL *edl = get_edl();
342         if(edl)
343         {
344                 edl->local_session->out_point = -1;
345                 gui->timebar->update();
346         }
349 void VWindow::copy()
351         EDL *edl = get_edl();
352         if(edl)
353         {
354                 double start = edl->local_session->get_selectionstart();
355                 double end = edl->local_session->get_selectionend();
356                 FileXML file;
357                 edl->copy(start,
358                         end,
359                         0,
360                         0,
361                         0,
362                         &file,
363                         mwindow->plugindb,
364                         "",
365                         1);
366                 mwindow->gui->lock_window();
367                 mwindow->gui->get_clipboard()->to_clipboard(file.string,
368                         strlen(file.string),
369                         SECONDARY_SELECTION);
370                 mwindow->gui->unlock_window();
371         }
374 void VWindow::splice_selection()
378 void VWindow::overwrite_selection()