r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / cinelerra / mwindowmove.C
blob11e66652b13773a90a37b1934bacf33a1ce861cc
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 //printf("MWindow::samplemovement 1\n");
243         edl->local_session->view_start = view_start;
244 //printf("MWindow::samplemovement 2\n");
245         if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
246 //printf("MWindow::samplemovement 3\n");
247         gui->canvas->draw();
248 //printf("MWindow::samplemovement 4\n");
249         gui->cursor->show();
250 //printf("MWindow::samplemovement 5\n");
251         gui->canvas->flash();
252 //printf("MWindow::samplemovement 6\n");
253         gui->timebar->update();
254 //printf("MWindow::samplemovement 7\n");
255         gui->zoombar->update();
256 //printf("MWindow::samplemovement 8\n");
258         if(gui->samplescroll) gui->samplescroll->set_position();
259 //printf("MWindow::samplemovement 9\n");
260         return 0;
263 int MWindow::move_left(int64_t distance)
265         if(!distance) 
266                 distance = gui->canvas->get_w() / 
267                         10;
268         edl->local_session->view_start -= distance;
269         if(edl->local_session->view_start < 0) edl->local_session->view_start = 0;
270         samplemovement(edl->local_session->view_start);
271         return 0;
274 int MWindow::move_right(int64_t distance)
276         if(!distance) 
277                 distance = gui->canvas->get_w() / 
278                         10;
279         edl->local_session->view_start += distance;
280         samplemovement(edl->local_session->view_start);
281         return 0;
284 void MWindow::select_all()
286         edl->local_session->selectionstart = 0;
287         edl->local_session->selectionend = edl->tracks->total_length();
288         gui->update(0, 1, 1, 1, 0, 1, 0);
289         gui->canvas->activate();
290         cwindow->update(1, 0, 0);
293 int MWindow::next_label()
295         Label *current;
296         Labels *labels = edl->labels;
298 // Test for label under cursor position
299         for(current = labels->first; 
300                 current && !edl->equivalent(current->position, edl->local_session->selectionend); 
301                 current = NEXT)
302                 ;
304 // Test for label before cursor position
305         if(!current)
306                 for(current = labels->last;
307                         current && current->position > edl->local_session->selectionend;
308                         current = PREVIOUS)
309                         ;
311 // Test for label after cursor position
312         if(!current)
313                 current = labels->first;
314         else
315 // Get next label
316                 current = NEXT;
318         if(current)
319         {
321                 edl->local_session->selectionend = current->position;
322                 if(!gui->shift_down()) edl->local_session->selectionstart = edl->local_session->selectionend;
324                 if(edl->local_session->selectionend >= (double)edl->local_session->view_start *
325                         edl->local_session->zoom_sample /
326                         edl->session->sample_rate + 
327                         gui->canvas->time_visible() ||
328                         edl->local_session->selectionend < (double)edl->local_session->view_start *
329                         edl->local_session->zoom_sample /
330                         edl->session->sample_rate)
331                 {
332                         samplemovement((int64_t)(edl->local_session->selectionend *
333                                 edl->session->sample_rate /
334                                 edl->local_session->zoom_sample - 
335                                 gui->canvas->get_w() / 
336                                 2));
337                         cwindow->update(1, 0, 0, 0, 0);
338                 }
339                 else
340                 {
341                         update_plugin_guis();
342                         gui->patchbay->update();
343                         gui->timebar->update();
344                         gui->cursor->hide();
345                         gui->cursor->draw();
346                         gui->zoombar->update();
347                         gui->canvas->flash();
348                         gui->flush();
349                         cwindow->update(1, 0, 0);
350                 }
351         }
352         else
353         {
354                 goto_end();
355         }
356         return 0;
359 int MWindow::prev_label()
361         Label *current;
362         Labels *labels = edl->labels;
364 // Test for label under cursor position
365         for(current = labels->first; 
366                 current && !edl->equivalent(current->position, edl->local_session->selectionstart); 
367                 current = NEXT)
368                 ;
370 // Test for label after cursor position
371         if(!current)
372                 for(current = labels->first;
373                         current && current->position < edl->local_session->selectionstart;
374                         current = NEXT)
375                         ;
377 // Test for label before cursor position
378         if(!current) 
379                 current = labels->last;
380         else
381 // Get previous label
382                 current = PREVIOUS;
384         if(current)
385         {
386                 edl->local_session->selectionstart = current->position;
387                 if(!gui->shift_down()) edl->local_session->selectionend = edl->local_session->selectionstart;
389 // Scroll the display
390                 if(edl->local_session->selectionstart >= edl->local_session->view_start *
391                         edl->local_session->zoom_sample /
392                         edl->session->sample_rate + 
393                         gui->canvas->time_visible() 
394                 ||
395                         edl->local_session->selectionstart < edl->local_session->view_start *
396                         edl->local_session->zoom_sample /
397                         edl->session->sample_rate)
398                 {
399                         samplemovement((int64_t)(edl->local_session->selectionstart *
400                                 edl->session->sample_rate /
401                                 edl->local_session->zoom_sample - 
402                                 gui->canvas->get_w() / 
403                                 2));
404                         cwindow->update(1, 0, 0, 0, 0);
405                 }
406                 else
407 // Don't scroll the display
408                 {
409                         update_plugin_guis();
410                         gui->patchbay->update();
411                         gui->timebar->update();
412                         gui->cursor->hide();
413                         gui->cursor->draw();
414                         gui->zoombar->update();
415                         gui->canvas->flash();
416                         gui->flush();
417                         cwindow->update(1, 0, 0);
418                 }
419         }
420         else
421         {
422                 goto_start();
423         }
424         return 0;
427 int MWindow::expand_y()
429         int result = edl->local_session->zoom_y * 2;
430         result = MIN(result, MAX_AMP_ZOOM);
431         zoom_amp(result);
432         gui->zoombar->update();
433         return 0;
436 int MWindow::zoom_in_y()
438         int result = edl->local_session->zoom_y / 2;
439         result = MAX(result, MIN_AMP_ZOOM);
440         zoom_amp(result);
441         gui->zoombar->update();
442         return 0;
445 int MWindow::expand_t()
447         int result = edl->local_session->zoom_track * 2;
448         result = MIN(result, MAX_TRACK_ZOOM);
449         zoom_track(result);
450         gui->zoombar->update();
451         return 0;
454 int MWindow::zoom_in_t()
456         int result = edl->local_session->zoom_track / 2;
457         result = MAX(result, MIN_TRACK_ZOOM);
458         zoom_track(result);
459         gui->zoombar->update();
460         return 0;