4 #include "cwindowgui.h"
6 #include "edlsession.h"
8 #include "localsession.h"
9 #include "mainsession.h"
12 #include "mwindowgui.h"
14 #include "playbackengine.h"
16 #include "samplescroll.h"
17 #include "trackcanvas.h"
19 #include "transportque.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()
34 if(edl->local_session->zoom_sample < 0x100000)
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);
44 int MWindow::zoom_in_sample()
48 if(edl->local_session->zoom_sample > 1)
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);
58 int MWindow::zoom_sample(int64_t zoom_sample)
60 CLIP(zoom_sample, 1, 0x100000);
61 edl->local_session->zoom_sample = zoom_sample;
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);
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))
82 edl->local_session->view_start = Units::round((edl->local_session->selectionend +
83 edl->local_session->selectionstart) /
85 edl->session->sample_rate /
86 edl->local_session->zoom_sample -
87 (double)gui->canvas->get_w() /
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)
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)
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)
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();
130 void MWindow::zoom_track(int64_t zoom_track)
132 edl->local_session->zoom_y = (int64_t)((float)edl->local_session->zoom_y *
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();
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)
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() /
186 edl->local_session->view_start = 0;
189 if(gui->shift_down())
191 edl->local_session->selectionend = edl->tracks->total_length();
195 edl->local_session->selectionstart =
196 edl->local_session->selectionend =
197 edl->tracks->total_length();
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);
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())
219 edl->local_session->selectionstart = 0;
223 edl->local_session->selectionstart =
224 edl->local_session->selectionend =
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);
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");
248 //printf("MWindow::samplemovement 4\n");
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");
263 int MWindow::move_left(int64_t distance)
266 distance = gui->canvas->get_w() /
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);
274 int MWindow::move_right(int64_t distance)
277 distance = gui->canvas->get_w() /
279 edl->local_session->view_start += distance;
280 samplemovement(edl->local_session->view_start);
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()
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);
304 // Test for label before cursor position
306 for(current = labels->last;
307 current && current->position > edl->local_session->selectionend;
311 // Test for label after cursor position
313 current = labels->first;
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)
332 samplemovement((int64_t)(edl->local_session->selectionend *
333 edl->session->sample_rate /
334 edl->local_session->zoom_sample -
335 gui->canvas->get_w() /
337 cwindow->update(1, 0, 0, 0, 0);
341 update_plugin_guis();
342 gui->patchbay->update();
343 gui->timebar->update();
346 gui->zoombar->update();
347 gui->canvas->flash();
349 cwindow->update(1, 0, 0);
359 int MWindow::prev_label()
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);
370 // Test for label after cursor position
372 for(current = labels->first;
373 current && current->position < edl->local_session->selectionstart;
377 // Test for label before cursor position
379 current = labels->last;
381 // Get previous label
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()
395 edl->local_session->selectionstart < edl->local_session->view_start *
396 edl->local_session->zoom_sample /
397 edl->session->sample_rate)
399 samplemovement((int64_t)(edl->local_session->selectionstart *
400 edl->session->sample_rate /
401 edl->local_session->zoom_sample -
402 gui->canvas->get_w() /
404 cwindow->update(1, 0, 0, 0, 0);
407 // Don't scroll the display
409 update_plugin_guis();
410 gui->patchbay->update();
411 gui->timebar->update();
414 gui->zoombar->update();
415 gui->canvas->flash();
417 cwindow->update(1, 0, 0);
427 int MWindow::expand_y()
429 int result = edl->local_session->zoom_y * 2;
430 result = MIN(result, MAX_AMP_ZOOM);
432 gui->zoombar->update();
436 int MWindow::zoom_in_y()
438 int result = edl->local_session->zoom_y / 2;
439 result = MAX(result, MIN_AMP_ZOOM);
441 gui->zoombar->update();
445 int MWindow::expand_t()
447 int result = edl->local_session->zoom_track * 2;
448 result = MIN(result, MAX_TRACK_ZOOM);
450 gui->zoombar->update();
454 int MWindow::zoom_in_t()
456 int result = edl->local_session->zoom_track / 2;
457 result = MAX(result, MIN_TRACK_ZOOM);
459 gui->zoombar->update();