Merge branch 'master' of git://git.pipapo.org/cinelerra/svn into ct
[cinelerra_cv/ct.git] / cinelerra / vwindow.C
blob04ce8b20ec816630c3bbf4809abb7a52c857df72
1 #include "asset.h"
2 #include "assets.h"
3 #include "clipedit.h"
4 #include "bchash.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.reset();
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 && !mwindow->edl->vwindow_edl_shared)
46         {
47                 delete mwindow->edl->vwindow_edl;
48                 mwindow->edl->vwindow_edl = 0;
49                 mwindow->edl->vwindow_edl_shared = 0;
50         }
52         asset.reset();
56 void VWindow::load_defaults()
60 int VWindow::create_objects()
62 //printf("VWindow::create_objects 1\n");
63         gui = new VWindowGUI(mwindow, this);
64 //printf("VWindow::create_objects 1\n");
65         gui->create_objects();
66 //printf("VWindow::create_objects 1\n");
68         playback_engine = new VPlayback(mwindow, this, gui->canvas);
69 //printf("VWindow::create_objects 1\n");
71 // Start command loop
72         playback_engine->create_objects();
73 //printf("VWindow::create_objects 1\n");
74         gui->transport->set_engine(playback_engine);
75 //printf("VWindow::create_objects 1\n");
76         playback_cursor = new VTracking(mwindow, this);
77 //printf("VWindow::create_objects 1\n");
78         playback_cursor->create_objects();
79 //printf("VWindow::create_objects 2\n");
81         clip_edit = new ClipEdit(mwindow, 0, this);
82         return 0;
85 void VWindow::run()
87         gui->run_window();
90 EDL* VWindow::get_edl()
92 //printf("VWindow::get_edl 1 %p\n", edl);
93         return mwindow->edl->vwindow_edl;
96 Asset_GC VWindow::get_asset()
98         return this->asset;
101 void VWindow::change_source()
103 //printf("VWindow::change_source() 1 %p\n", mwindow->edl->vwindow_edl);
104         if(mwindow->edl->vwindow_edl)
105         {
106                 gui->change_source(get_edl(), get_edl()->local_session->clip_title);
107                 update_position(CHANGE_ALL, 1, 1);
108         }
109         else
110         {
111                 asset.reset();
112                 mwindow->edl->vwindow_edl_shared = 0;
113         }
116 void VWindow::change_source(Asset_GC asset)
118 //printf("VWindow::change_source 1\n");
119 //      if(asset && this->asset &&
120 //              asset->id == this->asset->id &&
121 //              asset == this->asset) return;
123 //printf("VWindow::change_source(Asset_GC asset) 1\n");
125         char title[BCTEXTLEN];
126         FileSystem fs;
127         fs.extract_name(title, asset->path);
128 //printf("VWindow::change_source 1\n");
130         delete_edl();
131 //printf("VWindow::change_source 1\n");
133 // Generate EDL off of main EDL for cutting
134         this->asset = Asset_GC(new Asset);
135         *this->asset = *asset;
136         mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
137         mwindow->edl->vwindow_edl_shared = 0;
138         mwindow->edl->vwindow_edl->create_objects();
139         mwindow->asset_to_edl(mwindow->edl->vwindow_edl, asset);
140 //printf("VWindow::change_source 1 %d %d\n", edl->local_session->loop_playback, mwindow->edl->local_session->loop_playback);
141 //edl->dump();
143 // Update GUI
144         gui->change_source(mwindow->edl->vwindow_edl, title);
145         update_position(CHANGE_ALL, 1, 1);
148 // Update master session
149         strcpy(mwindow->edl->session->vwindow_folder, MEDIA_FOLDER);
150         mwindow->edl->session->vwindow_source = 0;
151         int i = 0;
152         for(Assets_list::iterator current = mwindow->edl->assets->begin();
153             current == mwindow->edl->assets->end();
154             ++current)
155         {
156                 if(this->asset->equivalent(**current, 0, 0))
157                 {
158                         mwindow->edl->session->vwindow_source = i;
159                         break;
160                 }
161                 i++;
162         }
164 //printf("VWindow::change_source 2\n");
167 void VWindow::change_source(EDL *edl)
169 //printf("VWindow::change_source(EDL *edl) 1\n");
170 //printf("VWindow::change_source %p\n", edl);
171 // EDLs are identical
172         if(edl && mwindow->edl->vwindow_edl && 
173                 edl->id == mwindow->edl->vwindow_edl->id) return;
175         delete_edl();
177         if(edl)
178         {
179                 this->asset.reset();
180                 mwindow->edl->vwindow_edl = edl;
181 // in order not to later delete edl if it is shared
182                 mwindow->edl->vwindow_edl_shared = 1;
184 // Update GUI
185                 gui->change_source(edl, edl->local_session->clip_title);
186                 update_position(CHANGE_ALL, 1, 1);
188 // Update master session
189                 strcpy(mwindow->edl->session->vwindow_folder, CLIP_FOLDER);
190                 mwindow->edl->session->vwindow_source = 
191                         mwindow->edl->clips.number_of(edl);
192         }
193         else
194                 gui->change_source(edl, _("Viewer"));
198 void VWindow::remove_source()
200         delete_edl();
201         gui->change_source(0, _("Viewer"));
204 void VWindow::change_source(char *folder, int item)
206 //printf("VWindow::change_source(char *folder, int item) 1\n");
207         int result = 0;
208 // Search EDLs
209         if(!strcasecmp(folder, CLIP_FOLDER))
210         {
211                 if(item < mwindow->edl->clips.total)
212                 {
213                         change_source(mwindow->edl->clips.values[item]);
214                         result = 1;
215                 }
216         }
217         else
218 // Search media
219         if(!strcasecmp(folder, MEDIA_FOLDER))
220         {
221                 if(item < mwindow->edl->assets->size())
222                 {
223                         Assets_list::iterator asset = mwindow->edl->assets->begin();
224                         advance(asset,item);
225                         change_source(*asset);
226                         result = 1;
227                 }
228         }
229         else
230 // Search extra clip folders
231         {
232         }
233         
234         if(!result)
235         {
236                 remove_source();
237         }
243 void VWindow::goto_start()
245         if(get_edl())
246         {
247                 get_edl()->local_session->set_selectionstart(0);
248                 get_edl()->local_session->set_selectionend(0);
249                 update_position(CHANGE_NONE, 
250                         0, 
251                         1);
252         }
255 void VWindow::goto_end()
257         if(get_edl())
258         {
259                 double position = get_edl()->tracks->total_length();
260                 get_edl()->local_session->set_selectionstart(position);
261                 get_edl()->local_session->set_selectionend(position);
262                 update_position(CHANGE_NONE, 
263                         0, 
264                         1);
265         }
268 void VWindow::update(int do_timebar)
270         if(do_timebar)
271                 gui->timebar->update();
274 void VWindow::update_position(int change_type, 
275         int use_slider, 
276         int update_slider)
278         EDL *edl = get_edl();
279         if(edl)
280         {
281                 Asset_GC asset = *edl->assets->begin();
282                 if(use_slider) 
283                 {
284                         edl->local_session->set_selectionstart(gui->slider->get_value());
285                         edl->local_session->set_selectionend(gui->slider->get_value());
286                 }
288                 if(update_slider)
289                 {
290                         gui->slider->set_position();
291                 }
293                 playback_engine->que->send_command(CURRENT_FRAME, 
294                         change_type,
295                         edl,
296                         1);
298                 gui->clock->update(edl->local_session->get_selectionstart(1) +
299                         asset->tcstart / 
300                         (asset->video_data ? asset->frame_rate : asset->sample_rate));
301         }
304 void VWindow::set_inpoint()
306         EDL *edl = get_edl();
307         if(edl)
308         {
309                 edl->set_inpoint(edl->local_session->get_selectionstart(1));
310                 gui->timebar->update();
311         }
314 void VWindow::set_outpoint()
316         EDL *edl = get_edl();
317         if(edl)
318         {
319                 edl->set_outpoint(edl->local_session->get_selectionstart(1));
320                 gui->timebar->update();
321         }
324 void VWindow::clear_inpoint()
326         EDL *edl = get_edl();
327         if(edl)
328         {
329                 edl->local_session->unset_inpoint();
330                 gui->timebar->update();
331         }
334 void VWindow::clear_outpoint()
336         EDL *edl = get_edl();
337         if(edl)
338         {
339                 edl->local_session->unset_outpoint();
340                 gui->timebar->update();
341         }
344 void VWindow::copy()
346         EDL *edl = get_edl();
347         if(edl)
348         {
349                 double start = edl->local_session->get_selectionstart();
350                 double end = edl->local_session->get_selectionend();
351                 FileXML file;
352                 edl->copy(start,
353                         end,
354                         0,
355                         0,
356                         0,
357                         &file,
358                         mwindow->plugindb,
359                         "",
360                         1);
361                 mwindow->gui->lock_window();
362                 mwindow->gui->get_clipboard()->to_clipboard(file.string,
363                         strlen(file.string),
364                         SECONDARY_SELECTION);
365                 mwindow->gui->unlock_window();
366         }
369 void VWindow::splice_selection()
373 void VWindow::overwrite_selection()
380 //      Local Variables:
381 //      mode: C++
382 //      c-file-style: "linux"
383 //      End: