r553: Modern gccs require __attribute__((used)) for variables used only in assembly.
[cinelerra_cv/mob.git] / cinelerra / mwindowmove.C
blob48bf7f6f1f62b6d8ffa7ae4609b44aa2c651aa14
1 #include "clip.h"
2 #include "cplayback.h"
3 #include "cwindow.h"
4 #include "cwindowgui.h"
5 #include "edl.h"
6 #include "edlsession.h"
7 #include "labels.h"
8 #include "localsession.h"
9 #include "mainsession.h"
10 #include "mtimebar.h"
11 #include "mwindow.h"
12 #include "mwindowgui.h"
13 #include "patchbay.h"
14 #include "playbackengine.h"
15 #include "plugin.h"
16 #include "samplescroll.h"
17 #include "trackcanvas.h"
18 #include "tracks.h"
19 #include "transportque.h"
20 #include "zoombar.h"
23 void MWindow::update_plugins()
25 // Show plugins which are visible and hide plugins which aren't
26 // Update plugin pointers in plugin servers
30 int MWindow::expand_sample()
32         if(gui)
33         {
34                 if(edl->local_session->zoom_sample < 0x100000)
35                 {
36                         edl->local_session->zoom_sample *= 2;
37                         gui->zoombar->sample_zoom->update(edl->local_session->zoom_sample);
38                         zoom_sample(edl->local_session->zoom_sample);
39                 }
40         }
41         return 0;
44 int MWindow::zoom_in_sample()
46         if(gui)
47         {
48                 if(edl->local_session->zoom_sample > 1)
49                 {
50                         edl->local_session->zoom_sample /= 2;
51                         gui->zoombar->sample_zoom->update(edl->local_session->zoom_sample);
52                         zoom_sample(edl->local_session->zoom_sample);
53                 }
54         }
55         return 0;
58 int MWindow::zoom_sample(int64_t zoom_sample)
60         CLIP(zoom_sample, 1, 0x100000);
61         edl->local_session->zoom_sample = zoom_sample;
62         find_cursor();
63         gui->get_scrollbars();
65         if(!gui->samplescroll) edl->local_session->view_start = 0;
66         samplemovement(edl->local_session->view_start);
67         gui->zoombar->sample_zoom->update(zoom_sample);
68         return 0;
71 void MWindow::find_cursor()
73 //      if((edl->local_session->selectionend > 
74 //              (double)gui->canvas->get_w() * 
75 //              edl->local_session->zoom_sample / 
76 //              edl->session->sample_rate) ||
77 //              (edl->local_session->selectionstart > 
78 //              (double)gui->canvas->get_w() * 
79 //              edl->local_session->zoom_sample / 
80 //              edl->session->sample_rate))
81 //      {
82                 edl->local_session->view_start = Units::round((edl->local_session->selectionend + 
83                         edl->local_session->selectionstart) / 
84                         2 *
85                         edl->session->sample_rate /
86                         edl->local_session->zoom_sample - 
87                         (double)gui->canvas->get_w() / 
88                         2);
89 //      }
90 //      else
91 //              edl->local_session->view_start = 0;
93 //printf("MWindow::find_cursor %f\n", edl->local_session->view_start);
94         if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
98 void MWindow::fit_selection()
100         if(edl->local_session->selectionstart == edl->local_session->selectionend)
101         {
102                 double total_samples = edl->tracks->total_length() * edl->session->sample_rate;
103                 for(edl->local_session->zoom_sample = 1; 
104                         gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples; 
105                         edl->local_session->zoom_sample *= 2)
106                         ;
107         }
108         else
109         {
110                 double total_samples = (edl->local_session->selectionend - edl->local_session->selectionstart) * edl->session->sample_rate;
111                 for(edl->local_session->zoom_sample = 1; 
112                         gui->canvas->get_w() * edl->local_session->zoom_sample < total_samples; 
113                         edl->local_session->zoom_sample *= 2)
114                         ;
115         }
117         edl->local_session->zoom_sample = MIN(0x100000, edl->local_session->zoom_sample);
118         zoom_sample(edl->local_session->zoom_sample);
121 void MWindow::zoom_amp(int64_t zoom_amp)
123         edl->local_session->zoom_y = zoom_amp;
124         gui->canvas->draw(0, 0);
125         gui->canvas->flash();
126         gui->patchbay->update();
127         gui->flush();
130 void MWindow::zoom_track(int64_t zoom_track)
132         edl->local_session->zoom_y = (int64_t)((float)edl->local_session->zoom_y * 
133                 zoom_track / 
134                 edl->local_session->zoom_track);
135         CLAMP(edl->local_session->zoom_y, MIN_AMP_ZOOM, MAX_AMP_ZOOM);
136         edl->local_session->zoom_track = zoom_track;
137         trackmovement(edl->local_session->track_start);
138 //printf("MWindow::zoom_track %d %d\n", edl->local_session->zoom_y, edl->local_session->zoom_track);
141 void MWindow::trackmovement(int track_start)
143         edl->local_session->track_start = track_start;
144         if(edl->local_session->track_start < 0) edl->local_session->track_start = 0;
145         edl->tracks->update_y_pixels(theme);
146         gui->get_scrollbars();
147         gui->canvas->draw(0, 0);
148         gui->patchbay->update();
149         gui->canvas->flash();
150         gui->flush();
153 void MWindow::move_up(int64_t distance)
155         if(!gui->trackscroll) return;
156         if(distance == 0) distance = edl->local_session->zoom_track;
157         edl->local_session->track_start -= distance;
158         trackmovement(edl->local_session->track_start);
161 void MWindow::move_down(int64_t distance)
163         if(!gui->trackscroll) return;
164         if(distance == 0) distance = edl->local_session->zoom_track;
165         edl->local_session->track_start += distance;
166         trackmovement(edl->local_session->track_start);
169 int MWindow::goto_end()
171         int64_t old_view_start = edl->local_session->view_start;
173         if(edl->tracks->total_length() > (double)gui->canvas->get_w() * 
174                 edl->local_session->zoom_sample / 
175                 edl->session->sample_rate)
176         {
177                 edl->local_session->view_start = 
178                         Units::round(edl->tracks->total_length() * 
179                                 edl->session->sample_rate /
180                                 edl->local_session->zoom_sample - 
181                                 gui->canvas->get_w() / 
182                                 2);
183         }
184         else
185         {
186                 edl->local_session->view_start = 0;
187         }
189         if(gui->shift_down())
190         {
191                 edl->local_session->selectionend = edl->tracks->total_length();
192         }
193         else
194         {
195                 edl->local_session->selectionstart = 
196                         edl->local_session->selectionend = 
197                         edl->tracks->total_length();
198         }
200         if(edl->local_session->view_start != old_view_start) 
201                 samplemovement(edl->local_session->view_start);
203         update_plugin_guis();
204         gui->patchbay->update();
205         gui->cursor->update();
206         gui->canvas->activate();
207         gui->zoombar->update();
208         cwindow->update(1, 0, 0, 0, 0);
209         return 0;
212 int MWindow::goto_start()
214         int64_t old_view_start = edl->local_session->view_start;
216         edl->local_session->view_start = 0;
217         if(gui->shift_down())
218         {
219                 edl->local_session->selectionstart = 0;
220         }
221         else
222         {
223                 edl->local_session->selectionstart = 
224                         edl->local_session->selectionend = 
225                         0;
226         }
228         if(edl->local_session->view_start != old_view_start)
229                 samplemovement(edl->local_session->view_start);
231         update_plugin_guis();
232         gui->patchbay->update();
233         gui->cursor->update();
234         gui->canvas->activate();
235         gui->zoombar->update();
236         cwindow->update(1, 0, 0, 0, 0);
237         return 0;
240 int MWindow::samplemovement(int64_t view_start)
242         edl->local_session->view_start = view_start;
243         if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
244         gui->canvas->draw();
245         gui->cursor->show();
246         gui->canvas->flash();
247         gui->timebar->update();
248         gui->zoombar->update();
250         if(gui->samplescroll) gui->samplescroll->set_position();
251         return 0;
254 int MWindow::move_left(int64_t distance)
256         if(!distance) 
257                 distance = gui->canvas->get_w() / 
258                         10;
259         edl->local_session->view_start -= distance;
260         if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
261         samplemovement(edl->local_session->view_start);
262         return 0;
265 int MWindow::move_right(int64_t distance)
267         if(!distance) 
268                 distance = gui->canvas->get_w() / 
269                         10;
270         edl->local_session->view_start += distance;
271         samplemovement(edl->local_session->view_start);
272         return 0;
275 void MWindow::select_all()
277         edl->local_session->selectionstart = 0;
278         edl->local_session->selectionend = edl->tracks->total_length();
279         gui->update(0, 1, 1, 1, 0, 1, 0);
280         gui->canvas->activate();
281         cwindow->update(1, 0, 0);
284 int MWindow::next_label()
286         Label *current;
287         Labels *labels = edl->labels;
289 // Test for label under cursor position
290         for(current = labels->first; 
291                 current && !edl->equivalent(current->position, edl->local_session->selectionend); 
292                 current = NEXT)
293                 ;
295 // Test for label before cursor position
296         if(!current)
297                 for(current = labels->last;
298                         current && current->position > edl->local_session->selectionend;
299                         current = PREVIOUS)
300                         ;
302 // Test for label after cursor position
303         if(!current)
304                 current = labels->first;
305         else
306 // Get next label
307                 current = NEXT;
309         if(current)
310         {
312                 edl->local_session->selectionend = current->position;
313                 if(!gui->shift_down()) edl->local_session->selectionstart = edl->local_session->selectionend;
315                 if(edl->local_session->selectionend >= (double)edl->local_session->view_start *
316                         edl->local_session->zoom_sample /
317                         edl->session->sample_rate + 
318                         gui->canvas->time_visible() ||
319                         edl->local_session->selectionend < (double)edl->local_session->view_start *
320                         edl->local_session->zoom_sample /
321                         edl->session->sample_rate)
322                 {
323                         samplemovement((int64_t)(edl->local_session->selectionend *
324                                 edl->session->sample_rate /
325                                 edl->local_session->zoom_sample - 
326                                 gui->canvas->get_w() / 
327                                 2));
328                         cwindow->update(1, 0, 0, 0, 0);
329                 }
330                 else
331                 {
332                         update_plugin_guis();
333                         gui->patchbay->update();
334                         gui->timebar->update();
335                         gui->cursor->hide();
336                         gui->cursor->draw();
337                         gui->zoombar->update();
338                         gui->canvas->flash();
339                         gui->flush();
340                         cwindow->update(1, 0, 0);
341                 }
342         }
343         else
344         {
345                 goto_end();
346         }
347         return 0;
350 int MWindow::prev_label()
352         Label *current;
353         Labels *labels = edl->labels;
355 // Test for label under cursor position
356         for(current = labels->first; 
357                 current && !edl->equivalent(current->position, edl->local_session->selectionstart); 
358                 current = NEXT)
359                 ;
361 // Test for label after cursor position
362         if(!current)
363                 for(current = labels->first;
364                         current && current->position < edl->local_session->selectionstart;
365                         current = NEXT)
366                         ;
368 // Test for label before cursor position
369         if(!current) 
370                 current = labels->last;
371         else
372 // Get previous label
373                 current = PREVIOUS;
375         if(current)
376         {
377                 edl->local_session->selectionstart = current->position;
378                 if(!gui->shift_down()) edl->local_session->selectionend = edl->local_session->selectionstart;
380 // Scroll the display
381                 if(edl->local_session->selectionstart >= edl->local_session->view_start *
382                         edl->local_session->zoom_sample /
383                         edl->session->sample_rate + 
384                         gui->canvas->time_visible() 
385                 ||
386                         edl->local_session->selectionstart < edl->local_session->view_start *
387                         edl->local_session->zoom_sample /
388                         edl->session->sample_rate)
389                 {
390                         samplemovement((int64_t)(edl->local_session->selectionstart *
391                                 edl->session->sample_rate /
392                                 edl->local_session->zoom_sample - 
393                                 gui->canvas->get_w() / 
394                                 2));
395                         cwindow->update(1, 0, 0, 0, 0);
396                 }
397                 else
398 // Don't scroll the display
399                 {
400                         update_plugin_guis();
401                         gui->patchbay->update();
402                         gui->timebar->update();
403                         gui->cursor->hide();
404                         gui->cursor->draw();
405                         gui->zoombar->update();
406                         gui->canvas->flash();
407                         gui->flush();
408                         cwindow->update(1, 0, 0);
409                 }
410         }
411         else
412         {
413                 goto_start();
414         }
415         return 0;
418 int MWindow::expand_y()
420         int result = edl->local_session->zoom_y * 2;
421         result = MIN(result, MAX_AMP_ZOOM);
422         zoom_amp(result);
423         gui->zoombar->update();
424         return 0;
427 int MWindow::zoom_in_y()
429         int result = edl->local_session->zoom_y / 2;
430         result = MAX(result, MIN_AMP_ZOOM);
431         zoom_amp(result);
432         gui->zoombar->update();
433         return 0;
436 int MWindow::expand_t()
438         int result = edl->local_session->zoom_track * 2;
439         result = MIN(result, MAX_TRACK_ZOOM);
440         zoom_track(result);
441         gui->zoombar->update();
442         return 0;
445 int MWindow::zoom_in_t()
447         int result = edl->local_session->zoom_track / 2;
448         result = MAX(result, MIN_TRACK_ZOOM);
449         zoom_track(result);
450         gui->zoombar->update();
451         return 0;