r870: Merge 2.1:
[cinelerra_cv.git] / cinelerra / cwindow.C
blob54f26b206068f05c79611f62b3dc53ec77509474
1 #include "autos.h"
2 #include "bcsignals.h"
3 #include "cplayback.h"
4 #include "ctimebar.h"
5 #include "ctracking.h"
6 #include "cwindow.h"
7 #include "cwindowgui.h"
8 #include "cwindowtool.h"
9 #include "bchash.h"
10 #include "edl.h"
11 #include "edlsession.h"
12 #include "localsession.h"
13 #include "mainmenu.h"
14 #include "mainsession.h"
15 #include "mwindowgui.h"
16 #include "playbackengine.h"
17 #include "playtransport.h"
18 #include "preferences.h"
19 #include "theme.h"
20 #include "track.h"
21 #include "trackcanvas.h"
22 #include "tracks.h"
23 #include "transportque.h"
24 #include "mwindow.h"
28 #include <unistd.h>
32 CWindow::CWindow(MWindow *mwindow)
33  : Thread()
35         this->mwindow = mwindow;
39 CWindow::~CWindow()
41         delete playback_engine;
42         delete playback_cursor;
45 int CWindow::create_objects()
47         destination = mwindow->defaults->get("CWINDOW_DESTINATION", 0);
49         gui = new CWindowGUI(mwindow, this);
50     gui->create_objects();
52         playback_engine = new CPlayback(mwindow, this, gui->canvas);
54 // Start command loop
55         playback_engine->create_objects();
56         gui->transport->set_engine(playback_engine);
57         playback_cursor = new CTracking(mwindow, this);
58         playback_cursor->create_objects();
59     return 0;
63 void CWindow::show_window()
65         gui->lock_window("CWindow::show_cwindow");
66         gui->show_window();
67         gui->raise_window();
68         gui->flush();
69         gui->unlock_window();
71         gui->tool_panel->show_tool();
74 void CWindow::hide_window()
76         gui->hide_window();
77         gui->mwindow->session->show_cwindow = 0;
78 // Unlock in case MWindow is waiting for it.
79         gui->unlock_window();
81         gui->tool_panel->hide_tool();
83         mwindow->gui->lock_window("CWindowGUI::close_event");
84         mwindow->gui->mainmenu->show_cwindow->set_checked(0);
85         mwindow->gui->unlock_window();
86         mwindow->save_defaults();
88         gui->lock_window("CWindow::hide_window");
92 Track* CWindow::calculate_affected_track()
94         Track* affected_track = 0;
95         for(Track *track = mwindow->edl->tracks->first;
96                 track;
97                 track = track->next)
98         {
99                 if(track->data_type == TRACK_VIDEO &&
100                         track->record)
101                 {
102                         affected_track = track;
103                         break;
104                 }
105         }
106         return affected_track;
109 Auto* CWindow::calculate_affected_auto(Autos *autos, 
110         int create,
111         int *created,
112         int redraw)
114         Auto* affected_auto = 0;
115         if(created) *created = 0;
117         if(create)
118         {
119                 int total = autos->total();
120                 affected_auto = autos->get_auto_for_editing();
122 // Got created
123                 if(total != autos->total())
124                 {
125                         if(created) *created = 1;
126                         if(redraw)
127                         {
128                                 mwindow->gui->lock_window("CWindow::calculate_affected_auto");
129                                 mwindow->gui->canvas->draw_overlays();
130                                 mwindow->gui->canvas->flash();
131                                 mwindow->gui->unlock_window();
132                         }
133                 }
134         }
135         else
136         {
137                 affected_auto = autos->get_prev_auto(PLAY_FORWARD, affected_auto);
138         }
140         return affected_auto;
145 void CWindow::calculate_affected_autos(FloatAuto **x_auto,
146         FloatAuto **y_auto,
147         FloatAuto **z_auto,
148         Track *track,
149         int use_camera,
150         int create_x,
151         int create_y,
152         int create_z)
154         if(x_auto) (*x_auto) = 0;
155         if(y_auto) (*y_auto) = 0;
156         if(z_auto) (*z_auto) = 0;
158         if(!track) return;
160         if(use_camera)
161         {
162                 if(x_auto) (*x_auto) = (FloatAuto*)calculate_affected_auto(
163                         track->automation->autos[AUTOMATION_CAMERA_X], create_x);
164                 if(y_auto) (*y_auto) = (FloatAuto*)calculate_affected_auto(
165                         track->automation->autos[AUTOMATION_CAMERA_Y], create_y);
166                 if(z_auto) (*z_auto) = (FloatAuto*)calculate_affected_auto(
167                         track->automation->autos[AUTOMATION_CAMERA_Z], create_z);
168         }
169         else
170         {
171                 if(x_auto) (*x_auto) = (FloatAuto*)calculate_affected_auto(
172                         track->automation->autos[AUTOMATION_PROJECTOR_X], create_x);
173                 if(y_auto) (*y_auto) = (FloatAuto*)calculate_affected_auto(
174                         track->automation->autos[AUTOMATION_PROJECTOR_Y], create_y);
175                 if(z_auto) (*z_auto) = (FloatAuto*)calculate_affected_auto(
176                         track->automation->autos[AUTOMATION_PROJECTOR_Z], create_z);
177         }
184 void CWindow::run()
186         gui->run_window();
189 void CWindow::update(int position, 
190         int overlays, 
191         int tool_window, 
192         int operation,
193         int timebar)
196         if(position)
197         {
198                 gui->lock_window("CWindow::update 1");
199                 gui->slider->set_position();
200                 gui->unlock_window();
202                 playback_engine->que->send_command(CURRENT_FRAME, 
203                         CHANGE_NONE,
204                         mwindow->edl,
205                         1);
206         }
208         gui->lock_window("CWindow::update 2");
211 // Create tool window
212         if(operation)
213         {
214                 gui->set_operation(mwindow->edl->session->cwindow_operation);
215         }
218 // Updated by video device.
219         if(overlays && !position)
220         {
221                 gui->canvas->draw_refresh();
222         }
224 // Update tool parameters
225 // Never updated by someone else
226         if(tool_window || position)
227         {
228                 gui->update_tool();
229         }
231         if(timebar)
232         {
233                 gui->timebar->update(1, 1);
234         }
236         if(!mwindow->edl->session->cwindow_scrollbars)
237                 gui->zoom_panel->update(AUTO_ZOOM);
238         else
239                 gui->zoom_panel->update(mwindow->edl->session->cwindow_zoom);
241         gui->canvas->update_zoom(mwindow->edl->session->cwindow_xscroll,
242                         mwindow->edl->session->cwindow_yscroll, 
243                         mwindow->edl->session->cwindow_zoom);
244         gui->canvas->reposition_window(mwindow->edl, 
245                         mwindow->theme->ccanvas_x,
246                         mwindow->theme->ccanvas_y,
247                         mwindow->theme->ccanvas_w,
248                         mwindow->theme->ccanvas_h);
253         gui->unlock_window();