r807: Minor fix...
[cinelerra_cv/mob.git] / cinelerra / cwindow.C
blob50e415d5fe5d4277de09e267929d1740e06391a2
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 "defaults.h"
10 #include "edl.h"
11 #include "edlsession.h"
12 #include "mainmenu.h"
13 #include "mainsession.h"
14 #include "mwindowgui.h"
15 #include "playbackengine.h"
16 #include "playtransport.h"
17 #include "preferences.h"
18 #include "theme.h"
19 #include "track.h"
20 #include "trackcanvas.h"
21 #include "tracks.h"
22 #include "transportque.h"
23 #include "mwindow.h"
27 #include <unistd.h>
31 CWindow::CWindow(MWindow *mwindow)
32  : Thread()
34         this->mwindow = mwindow;
38 CWindow::~CWindow()
40         delete playback_engine;
41         delete playback_cursor;
44 int CWindow::create_objects()
46         destination = mwindow->defaults->get("CWINDOW_DESTINATION", 0);
48         gui = new CWindowGUI(mwindow, this);
49     gui->create_objects();
51         playback_engine = new CPlayback(mwindow, this, gui->canvas);
53 // Start command loop
54         playback_engine->create_objects();
55         gui->transport->set_engine(playback_engine);
56         playback_cursor = new CTracking(mwindow, this);
57         playback_cursor->create_objects();
58     return 0;
62 void CWindow::show_window()
64         gui->lock_window("CWindow::show_cwindow");
65         gui->show_window();
66         gui->raise_window();
67         gui->flush();
68         gui->unlock_window();
70         gui->tool_panel->show_tool();
73 void CWindow::hide_window()
75         gui->hide_window();
76         gui->mwindow->session->show_cwindow = 0;
77 // Unlock in case MWindow is waiting for it.
78         gui->unlock_window();
80         gui->tool_panel->hide_tool();
82         mwindow->gui->lock_window("CWindowGUI::close_event");
83         mwindow->gui->mainmenu->show_cwindow->set_checked(0);
84         mwindow->gui->unlock_window();
85         mwindow->save_defaults();
87         gui->lock_window("CWindow::hide_window");
91 Track* CWindow::calculate_affected_track()
93         Track* affected_track = 0;
94         for(Track *track = mwindow->edl->tracks->first;
95                 track;
96                 track = track->next)
97         {
98                 if(track->data_type == TRACK_VIDEO &&
99                         track->record)
100                 {
101                         affected_track = track;
102                         break;
103                 }
104         }
105         return affected_track;
108 Auto* CWindow::calculate_affected_auto(Autos *autos, int create)
110         Auto* affected_auto = 0;
112         if(create)
113         {
114                 int total = autos->total();
115                 affected_auto = autos->get_auto_for_editing();
117 // Got created
118                 if(total != autos->total())
119                 {
120                         mwindow->gui->lock_window("CWindow::calculate_affected_auto");
121                         mwindow->gui->canvas->draw_overlays();
122                         mwindow->gui->canvas->flash();
123                         mwindow->gui->unlock_window();
124                 }
125         }
126         else
127         {
128                 affected_auto = autos->get_prev_auto(PLAY_FORWARD, affected_auto);
129         }
131         return affected_auto;
136 void CWindow::calculate_affected_autos(FloatAuto **x_auto,
137         FloatAuto **y_auto,
138         FloatAuto **z_auto,
139         Track *track,
140         int use_camera,
141         int create_x,
142         int create_y,
143         int create_z)
145         if(x_auto) (*x_auto) = 0;
146         if(y_auto) (*y_auto) = 0;
147         if(z_auto) (*z_auto) = 0;
149         if(!track) return;
151         if(use_camera)
152         {
153                 if(x_auto) (*x_auto) = (FloatAuto*)calculate_affected_auto(
154                         track->automation->autos[AUTOMATION_CAMERA_X], create_x);
155                 if(y_auto) (*y_auto) = (FloatAuto*)calculate_affected_auto(
156                         track->automation->autos[AUTOMATION_CAMERA_Y], create_y);
157                 if(z_auto) (*z_auto) = (FloatAuto*)calculate_affected_auto(
158                         track->automation->autos[AUTOMATION_CAMERA_Z], create_z);
159         }
160         else
161         {
162                 if(x_auto) (*x_auto) = (FloatAuto*)calculate_affected_auto(
163                         track->automation->autos[AUTOMATION_PROJECTOR_X], create_x);
164                 if(y_auto) (*y_auto) = (FloatAuto*)calculate_affected_auto(
165                         track->automation->autos[AUTOMATION_PROJECTOR_Y], create_y);
166                 if(z_auto) (*z_auto) = (FloatAuto*)calculate_affected_auto(
167                         track->automation->autos[AUTOMATION_PROJECTOR_Z], create_z);
168         }
175 void CWindow::run()
177         gui->run_window();
180 void CWindow::update(int position, 
181         int overlays, 
182         int tool_window, 
183         int operation,
184         int timebar)
186 //TRACE("CWindow::update 1");
188         if(position)
189         {
190 //printf("CWindow::update 2\n");
191                 gui->lock_window("CWindow::update 1");
192                 gui->slider->set_position();
193                 gui->unlock_window();
194 //printf("CWindow::update 2\n");
195                 playback_engine->que->send_command(CURRENT_FRAME, 
196                         CHANGE_NONE,
197                         mwindow->edl,
198                         1);
199 //printf("CWindow::update 3\n");
200         }
201 //TRACE("CWindow::update 4");
203         gui->lock_window("CWindow::update 2");
206 // Create tool window
207         if(operation)
208         {
209                 gui->set_operation(mwindow->edl->session->cwindow_operation);
210         }
212 //TRACE("CWindow::update 5");
214 // Updated by video device.
215         if(overlays && !position)
216         {
217                 gui->canvas->draw_refresh();
218         }
220 //TRACE("CWindow::update 5");
221 // Update tool parameters
222 // Never updated by someone else
223         if(tool_window || position)
224         {
225                 gui->update_tool();
226         }
228         if(timebar)
229         {
230                 gui->timebar->update(1, 1);
231         }
233 //TRACE("CWindow::update 6");
234         if(!mwindow->edl->session->cwindow_scrollbars)
235                 gui->zoom_panel->update(AUTO_ZOOM);
236         else
237                 gui->zoom_panel->update(mwindow->edl->session->cwindow_zoom);
238 //printf("CWindow::update 6\n");
240         gui->canvas->update_zoom(mwindow->edl->session->cwindow_xscroll,
241                         mwindow->edl->session->cwindow_yscroll, 
242                         mwindow->edl->session->cwindow_zoom);
243 //printf("CWindow::update 6\n");
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);
250 //printf("CWindow::update 6\n");
254         gui->unlock_window();
259 //printf("CWindow::update 7\n");