r689: Fixed that changes made by dragging a control would often store each
[cinelerra_cv.git] / cinelerra / vwindow.C
blobe8ef7aa4404b3c79d1d2a4fc09fcc6241fb85450
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;
187 // Update GUI
188                 gui->change_source(edl, edl->local_session->clip_title);
189                 update_position(CHANGE_ALL, 1, 1);
191 // Update master session
192                 strcpy(mwindow->edl->session->vwindow_folder, CLIP_FOLDER);
193                 mwindow->edl->session->vwindow_source = 
194                         mwindow->edl->clips.number_of(edl);
195         }
196         else
197                 gui->change_source(edl, _("Viewer"));
201 void VWindow::remove_source()
203         delete_edl();
204         gui->change_source(0, _("Viewer"));
207 void VWindow::change_source(char *folder, int item)
209 //printf("VWindow::change_source(char *folder, int item) 1\n");
210         int result = 0;
211 // Search EDLs
212         if(!strcasecmp(folder, CLIP_FOLDER))
213         {
214                 if(item < mwindow->edl->clips.total)
215                 {
216                         change_source(mwindow->edl->clips.values[item]);
217                         result = 1;
218                 }
219         }
220         else
221 // Search media
222         if(!strcasecmp(folder, MEDIA_FOLDER))
223         {
224                 if(item < mwindow->edl->assets->total())
225                 {
226                         change_source(mwindow->edl->assets->get_item_number(item));
227                         result = 1;
228                 }
229         }
230         else
231 // Search extra clip folders
232         {
233         }
234         
235         if(!result)
236         {
237                 remove_source();
238         }
244 void VWindow::goto_start()
246         if(get_edl())
247         {
248                 get_edl()->local_session->set_selectionstart(0);
249                 get_edl()->local_session->set_selectionend(0);
250                 update_position(CHANGE_NONE, 
251                         0, 
252                         1);
253         }
256 void VWindow::goto_end()
258         if(get_edl())
259         {
260                 double position = get_edl()->tracks->total_length();
261                 get_edl()->local_session->set_selectionstart(position);
262                 get_edl()->local_session->set_selectionend(position);
263                 update_position(CHANGE_NONE, 
264                         0, 
265                         1);
266         }
269 void VWindow::update(int do_timebar)
271         if(do_timebar)
272                 gui->timebar->update();
275 void VWindow::update_position(int change_type, 
276         int use_slider, 
277         int update_slider)
279         EDL *edl = get_edl();
280         if(edl)
281         {
282                 Asset *asset = edl->assets->first;
283                 if(use_slider) 
284                 {
285                         edl->local_session->set_selectionstart(gui->slider->get_value());
286                         edl->local_session->set_selectionend(gui->slider->get_value());
287                 }
289                 if(update_slider)
290                 {
291                         gui->slider->set_position();
292                 }
294                 playback_engine->que->send_command(CURRENT_FRAME, 
295                         change_type,
296                         edl,
297                         1);
299                 gui->clock->update(edl->local_session->get_selectionstart(1) +
300                         asset->tcstart / 
301                         (asset->video_data ? asset->frame_rate : asset->sample_rate));
302         }
305 void VWindow::set_inpoint()
307         EDL *edl = get_edl();
308         if(edl)
309         {
310                 edl->set_inpoint(edl->local_session->get_selectionstart(1));
311                 gui->timebar->update();
312         }
315 void VWindow::set_outpoint()
317         EDL *edl = get_edl();
318         if(edl)
319         {
320                 edl->set_outpoint(edl->local_session->get_selectionstart(1));
321                 gui->timebar->update();
322         }
325 void VWindow::clear_inpoint()
327         EDL *edl = get_edl();
328         if(edl)
329         {
330                 edl->local_session->unset_inpoint();
331                 gui->timebar->update();
332         }
335 void VWindow::clear_outpoint()
337         EDL *edl = get_edl();
338         if(edl)
339         {
340                 edl->local_session->unset_outpoint();
341                 gui->timebar->update();
342         }
345 void VWindow::copy()
347         EDL *edl = get_edl();
348         if(edl)
349         {
350                 double start = edl->local_session->get_selectionstart();
351                 double end = edl->local_session->get_selectionend();
352                 FileXML file;
353                 edl->copy(start,
354                         end,
355                         0,
356                         0,
357                         0,
358                         &file,
359                         mwindow->plugindb,
360                         "",
361                         1);
362                 mwindow->gui->lock_window();
363                 mwindow->gui->get_clipboard()->to_clipboard(file.string,
364                         strlen(file.string),
365                         SECONDARY_SELECTION);
366                 mwindow->gui->unlock_window();
367         }
370 void VWindow::splice_selection()
374 void VWindow::overwrite_selection()