r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / vwindow.C
blob83d127131f53bdf04da0711ed1209b0fbf0d382b
1 #include "assets.h"
2 #include "clipedit.h"
3 #include "defaults.h"
4 #include "edl.h"
5 #include "edlsession.h"
6 #include "filesystem.h"
7 #include "filexml.h"
8 #include "localsession.h"
9 #include "mainclock.h"
10 #include "mwindow.h"
11 #include "mwindowgui.h"
12 #include "playbackengine.h"
13 #include "tracks.h"
14 #include "transportque.h"
15 #include "vplayback.h"
16 #include "vtimebar.h"
17 #include "vtracking.h"
18 #include "vwindow.h"
19 #include "vwindowgui.h"
21 #include <libintl.h>
22 #define _(String) gettext(String)
23 #define gettext_noop(String) String
24 #define N_(String) gettext_noop (String)
27 VWindow::VWindow(MWindow *mwindow) : Thread()
29         this->mwindow = mwindow;
30         edl = 0;
31         asset = 0;
35 VWindow::~VWindow()
37 //printf("VWindow::~VWindow 1\n");
38         delete playback_engine;
39 //printf("VWindow::~VWindow 1\n");
40         delete playback_cursor;
41         delete_edl();
42         delete clip_edit;
43 //printf("VWindow::~VWindow 2\n");
46 void VWindow::delete_edl()
48 //printf("VWindow::delete_edl 1\n");
49         if(mwindow->edl->vwindow_edl)
50         {
51                 delete mwindow->edl->vwindow_edl;
52                 mwindow->edl->vwindow_edl = 0;
53         }
55         if(asset) delete asset;
56         asset = 0;
57         edl_shared = 0;
58         edl = 0;
62 void VWindow::load_defaults()
66 int VWindow::create_objects()
68 //printf("VWindow::create_objects 1\n");
69         gui = new VWindowGUI(mwindow, this);
70 //printf("VWindow::create_objects 1\n");
71         gui->create_objects();
72 //printf("VWindow::create_objects 1\n");
74         playback_engine = new VPlayback(mwindow, this, gui->canvas);
75 //printf("VWindow::create_objects 1\n");
77 // Start command loop
78         playback_engine->create_objects();
79 //printf("VWindow::create_objects 1\n");
80         gui->transport->set_engine(playback_engine);
81 //printf("VWindow::create_objects 1\n");
82         playback_cursor = new VTracking(mwindow, this);
83 //printf("VWindow::create_objects 1\n");
84         playback_cursor->create_objects();
85 //printf("VWindow::create_objects 2\n");
87         clip_edit = new ClipEdit(mwindow, 0, this);
88         return 0;
91 void VWindow::run()
93         gui->run_window();
96 EDL* VWindow::get_edl()
98 //printf("VWindow::get_edl 1 %p\n", edl);
99         return edl;
102 Asset* VWindow::get_asset()
104         return this->asset;
107 void VWindow::change_source()
109 //printf("VWindow::change_source() 1 %p\n", mwindow->edl->vwindow_edl);
110         if(mwindow->edl->vwindow_edl)
111         {
112                 this->edl = mwindow->edl->vwindow_edl;
113                 gui->change_source(edl, "");
114                 update_position(CHANGE_ALL, 1, 1);
115         }
116         else
117         {
118                 if(asset) delete asset;
119                 asset = 0;
120                 edl_shared = 0;
121                 edl = 0;
122         }
125 void VWindow::change_source(Asset *asset)
127 //printf("VWindow::change_source 1\n");
128 //      if(asset && this->asset &&
129 //              asset->id == this->asset->id &&
130 //              asset == this->asset) return;
132 //printf("VWindow::change_source(Asset *asset) 1\n");
134         char title[BCTEXTLEN];
135         FileSystem fs;
136         fs.extract_name(title, asset->path);
137 //printf("VWindow::change_source 1\n");
139         delete_edl();
140 //printf("VWindow::change_source 1\n");
142 // Generate EDL off of main EDL for cutting
143         this->asset = new Asset;
144         *this->asset = *asset;
145         edl = mwindow->edl->vwindow_edl = new EDL(mwindow->edl);
146         edl_shared = 0;
147         edl->create_objects();
148         mwindow->asset_to_edl(edl, asset);
149 //printf("VWindow::change_source 1 %d %d\n", edl->local_session->loop_playback, mwindow->edl->local_session->loop_playback);
150 //edl->dump();
152 // Update GUI
153         gui->change_source(edl, title);
154         update_position(CHANGE_ALL, 1, 1);
157 // Update master session
158         strcpy(mwindow->edl->session->vwindow_folder, MEDIA_FOLDER);
159         mwindow->edl->session->vwindow_source = 0;
160         int i = 0;
161         for(Asset *current = mwindow->edl->assets->first; 
162                 current;
163                 current = NEXT)
164         {
165                 if(this->asset->equivalent(*current, 0, 0))
166                 {
167                         mwindow->edl->session->vwindow_source = i;
168                         break;
169                 }
170                 i++;
171         }
173 //printf("VWindow::change_source 2\n");
176 void VWindow::change_source(EDL *edl)
178 //printf("VWindow::change_source(EDL *edl) 1\n");
179 //printf("VWindow::change_source %p\n", edl);
180 // EDLs are identical
181         if(edl && mwindow->edl->vwindow_edl && 
182                 edl->id == mwindow->edl->vwindow_edl->id) return;
184         delete_edl();
186         if(edl)
187         {
188                 this->asset = 0;
189                 this->edl = edl;
190                 edl_shared = 1;
191 //printf("VWindow::change_source 1\n");
192 //edl->dump();
193 //printf("VWindow::change_source 2\n");
195 // Update GUI
196                 gui->change_source(edl, edl->local_session->clip_title);
197                 update_position(CHANGE_ALL, 1, 1);
199 // Update master session
200                 strcpy(mwindow->edl->session->vwindow_folder, CLIP_FOLDER);
201                 mwindow->edl->session->vwindow_source = 
202                         mwindow->edl->clips.number_of(edl);
203         }
204         else
205                 gui->change_source(edl, _("Viewer"));
209 void VWindow::remove_source()
211         delete_edl();
212         gui->change_source(0, _("Viewer"));
215 void VWindow::change_source(char *folder, int item)
217 //printf("VWindow::change_source(char *folder, int item) 1\n");
218         int result = 0;
219 // Search EDLs
220         if(!strcasecmp(folder, CLIP_FOLDER))
221         {
222                 if(item < mwindow->edl->clips.total)
223                 {
224                         change_source(mwindow->edl->clips.values[item]);
225                         result = 1;
226                 }
227         }
228         else
229 // Search media
230         if(!strcasecmp(folder, MEDIA_FOLDER))
231         {
232                 if(item < mwindow->edl->assets->total())
233                 {
234                         change_source(mwindow->edl->assets->get_item_number(item));
235                         result = 1;
236                 }
237         }
238         else
239 // Search extra clip folders
240         {
241         }
242         
243         if(!result)
244         {
245                 remove_source();
246         }
252 void VWindow::goto_start()
254         if(edl)
255         {
256                 edl->local_session->selectionstart = 
257                         edl->local_session->selectionend = 0;
258                 update_position(CHANGE_NONE, 
259                         0, 
260                         1);
261         }
264 void VWindow::goto_end()
266         if(edl)
267         {
268                 edl->local_session->selectionstart = 
269                         edl->local_session->selectionend = 
270                         edl->tracks->total_length();
271                 update_position(CHANGE_NONE, 
272                         0, 
273                         1);
274         }
277 void VWindow::update(int do_timebar)
279         if(do_timebar)
280                 gui->timebar->update();
283 void VWindow::update_position(int change_type, 
284         int use_slider, 
285         int update_slider)
287         EDL *edl = get_edl();
288         if(edl)
289         {
290                 if(use_slider) 
291                 {
292                         edl->local_session->selectionstart = 
293                                 edl->local_session->selectionend = 
294                                 gui->slider->get_value();
295                 }
297                 if(update_slider)
298                 {
299                         gui->slider->set_position();
300                 }
302                 playback_engine->que->send_command(CURRENT_FRAME, 
303                         change_type,
304                         edl,
305                         1);
307                 gui->clock->update(edl->local_session->selectionstart);
308         }
311 void VWindow::set_inpoint()
313         EDL *edl = get_edl();
314         if(edl)
315         {
316                 edl->set_inpoint(edl->local_session->selectionstart);
317                 gui->timebar->update();
318         }
321 void VWindow::set_outpoint()
323         EDL *edl = get_edl();
324         if(edl)
325         {
326                 edl->set_outpoint(edl->local_session->selectionstart);
327                 gui->timebar->update();
328         }
331 void VWindow::clear_inpoint()
333         EDL *edl = get_edl();
334         if(edl)
335         {
336                 edl->local_session->in_point = -1;
337                 gui->timebar->update();
338         }
341 void VWindow::clear_outpoint()
343         EDL *edl = get_edl();
344         if(edl)
345         {
346                 edl->local_session->out_point = -1;
347                 gui->timebar->update();
348         }
351 void VWindow::copy()
353         EDL *edl = get_edl();
354         if(edl)
355         {
356                 double start = edl->local_session->get_selectionstart();
357                 double end = edl->local_session->get_selectionend();
358                 FileXML file;
359                 edl->copy(start,
360                         end,
361                         0,
362                         0,
363                         0,
364                         &file,
365                         mwindow->plugindb,
366                         "",
367                         1);
368                 mwindow->gui->lock_window();
369                 mwindow->gui->get_clipboard()->to_clipboard(file.string,
370                         strlen(file.string),
371                         SECONDARY_SELECTION);
372                 mwindow->gui->unlock_window();
373         }
376 void VWindow::splice_selection()
380 void VWindow::overwrite_selection()