Do not try to restore Route solo state after clearing all solo state
[ardour.git] / gtk2_ardour / add_video_dialog.cc
1 /*
2     Copyright (C) 2010-2013 Paul Davis
3     Author: Robin Gareus <robin@gareus.org>
4
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
19 */
20 #include <cstdio>
21 #include <cmath>
22
23 #include <sigc++/bind.h>
24 #include <curl/curl.h>
25
26 #include "pbd/error.h"
27 #include "pbd/convert.h"
28 #include "gtkmm2ext/utils.h"
29 #include "gtkmm2ext/rgb_macros.h"
30 #include "ardour/session_directory.h"
31 #include "ardour/profile.h"
32 #include "ardour/template_utils.h"
33 #include "ardour/session.h"
34 #include "ardour_ui.h"
35
36 #include "add_video_dialog.h"
37 #include "ardour_http.h"
38 #include "utils_videotl.h"
39 #include "pbd/i18n.h"
40
41 using namespace Gtk;
42 using namespace std;
43 using namespace PBD;
44 using namespace ARDOUR;
45 using namespace VideoUtils;
46
47 #define PREVIEW_WIDTH (240)
48 #define PREVIEW_HEIGHT (180)
49
50 #ifndef MIN
51 #define MIN(a,b) ( (a) < (b) ? (a) : (b) )
52 #endif
53
54 AddVideoDialog::AddVideoDialog (Session* s)
55         : ArdourDialog (_("Set Video Track"))
56         , seek_slider (0,1000,1)
57         , preview_path ("")
58         , pi_tcin ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
59         , pi_tcout ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
60         , pi_aspect ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
61         , pi_fps ("-", Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false)
62         , chooser (FILE_CHOOSER_ACTION_OPEN)
63         , xjadeo_checkbox (_("Open Video Monitor Window"))
64         , set_session_fps_checkbox (_("Adjust Session Framerate to Match Video Framerate"))
65         , harvid_path ("")
66         , harvid_reset (_("Reload docroot"))
67         , harvid_list (ListStore::create(harvid_list_columns))
68         , harvid_list_view (harvid_list)
69         , show_advanced(false)
70         , loaded_docroot(false)
71 {
72         set_session (s);
73         set_name ("AddVideoDialog");
74         set_modal (true);
75         set_skip_taskbar_hint (true);
76         set_resizable (true);
77         set_size_request (800, -1);
78
79         harvid_initialized = false;
80         std::string dstdir = video_dest_dir(_session->session_directory().video_path(), video_get_docroot(Config));
81
82         /* Harvid Browser */
83         harvid_list_view.append_column("", pixBufRenderer);
84         harvid_list_view.append_column(_("Filename"), harvid_list_columns.filename);
85
86         harvid_list_view.get_column(0)->set_alignment(0.5);
87         harvid_list_view.get_column(0)->add_attribute(pixBufRenderer, "stock-id", harvid_list_columns.id);
88         harvid_list_view.get_column(1)->set_expand(true);
89         harvid_list_view.get_column(1)->set_sort_column(harvid_list_columns.filename);
90         harvid_list_view.set_enable_search(true);
91         harvid_list_view.set_search_column(1);
92
93         harvid_list_view.get_selection()->set_mode (SELECTION_SINGLE);
94
95         harvid_list_view.get_selection()->signal_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::harvid_list_view_selected));
96         harvid_list_view.signal_row_activated().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_list_view_activated));
97
98         Gtk::ScrolledWindow *scroll = manage(new ScrolledWindow);
99         scroll->add(harvid_list_view);
100         scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
101
102         HBox* hbox = manage (new HBox);
103         harvid_path.set_alignment (0, 0.5);
104         hbox->pack_start (harvid_path, true, true);
105         hbox->pack_start (harvid_reset, false, false);
106
107         server_index_box.pack_start (*hbox, false, false);
108         server_index_box.pack_start (*scroll, true, true);
109
110         /* file chooser */
111         chooser.set_border_width (4);
112 #ifdef __APPLE__
113         /* some broken redraw behaviour - this is a bandaid */
114         chooser.signal_selection_changed().connect (mem_fun (chooser, &Widget::queue_draw));
115 #endif
116         chooser.set_current_folder (dstdir);
117
118         Gtk::FileFilter video_filter;
119         Gtk::FileFilter matchall_filter;
120         video_filter.add_custom (FILE_FILTER_FILENAME, mem_fun(*this, &AddVideoDialog::on_video_filter));
121         video_filter.set_name (_("Video files"));
122
123         matchall_filter.add_pattern ("*.*");
124         matchall_filter.set_name (_("All files"));
125
126         chooser.add_filter (video_filter);
127         chooser.add_filter (matchall_filter);
128         chooser.set_select_multiple (false);
129
130         file_chooser_box.pack_start (chooser, true, true, 0);
131
132         /* Global Options*/
133         Gtk::Label* l;
134         VBox* options_box = manage (new VBox);
135
136         l = manage (new Label (_("<b>Options</b>"), Gtk::ALIGN_LEFT, Gtk::ALIGN_CENTER, false));
137         l->set_use_markup ();
138
139         options_box->pack_start (*l, false, true, 4);
140         options_box->pack_start (xjadeo_checkbox, false, true, 2);
141         options_box->pack_start (set_session_fps_checkbox, false, true, 2);
142
143         /* preview pane */
144         VBox* previewpane = manage (new VBox);
145         Gtk::Table *table = manage(new Table(5,2));
146
147         table->set_row_spacings(2);
148         table->set_col_spacings(4);
149
150         l = manage (new Label (_("<b>Video Information</b>"), Gtk::ALIGN_CENTER, Gtk::ALIGN_CENTER, false));
151         l->set_use_markup ();
152         table->attach (*l, 0, 2, 0, 1, FILL, FILL);
153         l = manage (new Label (_("Start:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
154         table->attach (*l, 0, 1, 1, 2, FILL, FILL);
155         table->attach (pi_tcin, 1, 2, 1, 2, FILL, FILL);
156         l = manage (new Label (_("End:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
157         table->attach (*l, 0, 1, 2, 3, FILL, FILL);
158         table->attach (pi_tcout, 1, 2, 2, 3, FILL, FILL);
159         l = manage (new Label (_("Frame rate:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
160         table->attach (*l, 0, 1, 3, 4, FILL, FILL);
161         table->attach (pi_fps, 1, 2, 3, 4, FILL, FILL);
162         l = manage (new Label (_("Aspect Ratio:"), Gtk::ALIGN_RIGHT, Gtk::ALIGN_CENTER, false));
163         table->attach (*l, 0, 1, 4, 5, FILL, FILL);
164         table->attach (pi_aspect, 1, 2, 4, 5, FILL, FILL);
165
166         preview_image = manage(new Gtk::Image);
167
168         imgbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, PREVIEW_WIDTH, PREVIEW_HEIGHT);
169         imgbuf->fill(RGBA_TO_UINT(127,0,0,255));
170         preview_image->set(imgbuf);
171         seek_slider.set_draw_value(false);
172
173         hbox = manage (new HBox);
174         hbox->pack_start (*table, true, false);
175
176         Gtk::Alignment *al = manage(new Gtk::Alignment());
177         al->set_size_request(-1, 20);
178
179         previewpane->pack_start (*preview_image, false, false);
180         previewpane->pack_start (seek_slider, false, false);
181         previewpane->pack_start (*al, false, false);
182         previewpane->pack_start (*hbox, true, true, 6);
183
184         /* Prepare Overall layout */
185
186         hbox = manage (new HBox);
187         hbox->pack_start (browser_container, true, true);
188         hbox->pack_start (*previewpane, false, false);
189
190         get_vbox()->set_spacing (4);
191         get_vbox()->pack_start (*hbox, true, true);
192         get_vbox()->pack_start (*options_box, false, false);
193
194         /* xjadeo checkbox */
195         if (ARDOUR_UI::instance()->video_timeline->found_xjadeo()
196                         /* TODO xjadeo setup w/ xjremote */
197                         && video_get_docroot(Config).size() > 0) {
198                 xjadeo_checkbox.set_active(true);  /* set in ardour_ui.cpp ?! */
199         } else {
200                 printf("xjadeo was not found or video-server docroot is unset (remote video-server)\n");
201                 xjadeo_checkbox.set_active(false);
202                 xjadeo_checkbox.set_sensitive(false);
203         }
204
205         /* FPS checkbox */
206         set_session_fps_checkbox.set_active(true);
207
208         /* Buttons */
209         add_button (Stock::CANCEL, RESPONSE_CANCEL);
210         ok_button = add_button (Stock::OK, RESPONSE_ACCEPT);
211         //ok_button->set_sensitive(false);
212         set_action_ok(false);
213
214         /* connect signals after eveything has been initialized */
215         chooser.signal_selection_changed().connect (mem_fun (*this, &AddVideoDialog::file_selection_changed));
216         chooser.signal_file_activated().connect (mem_fun (*this, &AddVideoDialog::file_activated));
217         //chooser.signal_update_preview().connect(sigc::mem_fun(*this, &AddVideoDialog::update_preview));
218         notebook.signal_switch_page().connect (sigc::hide_return (sigc::hide (sigc::hide (sigc::mem_fun (*this, &AddVideoDialog::page_switch)))));
219         seek_slider.signal_value_changed().connect(sigc::mem_fun(*this, &AddVideoDialog::seek_preview));
220         harvid_reset.signal_clicked().connect (sigc::mem_fun (*this, &AddVideoDialog::harvid_load_docroot));
221 }
222
223 AddVideoDialog::~AddVideoDialog ()
224 {
225 }
226
227 void
228 AddVideoDialog::on_show ()
229 {
230         /* overall layout depending on get_video_advanced_setup() and docroot */
231         for (int i = notebook.get_n_pages(); i > 0 ; --i) {
232                 notebook.remove_page(i);
233         }
234         if (server_index_box.get_parent()) {
235                 server_index_box.get_parent()->remove(server_index_box);
236         }
237         if (file_chooser_box.get_parent()) {
238                 file_chooser_box.get_parent()->remove(file_chooser_box);
239         }
240         if (notebook.get_parent()) {
241                 notebook.get_parent()->remove(notebook);
242         }
243
244         if (Config->get_video_advanced_setup()) {
245                 notebook.append_page (server_index_box, _("VideoServerIndex"));
246                 if (video_get_docroot(Config).size() > 0) {
247                         notebook.append_page (file_chooser_box, _("Browse Files"));
248                 }
249                 browser_container.pack_start (notebook, true, true);
250                 show_advanced = true;
251                 if (!loaded_docroot) {
252                         harvid_load_docroot();
253                 }
254         } else {
255                 browser_container.pack_start (file_chooser_box, true, true);
256                 show_advanced = false;
257                 loaded_docroot = false;
258         }
259
260         show_all_children ();
261
262         Dialog::on_show ();
263 }
264
265 static bool check_video_file_extension(std::string file)
266 {
267         const char* suffixes[] = {
268                 ".avi"     , ".AVI"     ,
269                 ".mov"     , ".MOV"     ,
270                 ".ogg"     , ".OGG"     ,
271                 ".ogv"     , ".OGV"     ,
272                 ".mpg"     , ".MPG"     ,
273                 ".mpeg"    , ".MPEG"    ,
274                 ".mts"     , ".MTS"     ,
275                 ".m2t"     , ".M2T"     ,
276                 ".mov"     , ".MOV"     ,
277                 ".mp4"     , ".MP4"     ,
278                 ".mkv"     , ".MKV"     ,
279                 ".vob"     , ".VOB"     ,
280                 ".asf"     , ".ASF"     ,
281                 ".avs"     , ".AVS"     ,
282                 ".dts"     , ".DTS"     ,
283                 ".flv"     , ".FLV"     ,
284                 ".m4v"     , ".M4V"     ,
285                 ".matroska", ".MATROSKA",
286                 ".h264"    , ".H264"    ,
287                 ".dv"      , ".DV"      ,
288                 ".dirac"   , ".DIRAC"   ,
289                 ".webm"    , ".WEBM"    ,
290                 ".wmv"     , ".WMV"     ,
291                 ".ts"      , ".TS"      ,
292                 ".mxf"     , ".MXF"     ,
293         };
294
295         for (size_t n = 0; n < sizeof(suffixes)/sizeof(suffixes[0]); ++n) {
296                 if (file.rfind (suffixes[n]) == file.length() - strlen (suffixes[n])) {
297                         return true;
298                 }
299         }
300
301         return false;
302 }
303
304 bool
305 AddVideoDialog::on_video_filter (const FileFilter::Info& filter_info)
306 {
307         return check_video_file_extension(filter_info.filename);
308 }
309
310 std::string
311 AddVideoDialog::file_name (bool &local_file)
312 {
313         int n = notebook.get_current_page ();
314         if (n == 1 || !show_advanced) {
315                 local_file = true;
316                 return chooser.get_filename();
317         } else {
318                 local_file = false;
319                 Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
320                 if(!iter) return "";
321
322                 std::string uri = (*iter)[harvid_list_columns.uri];
323                 std::string video_server_url = video_get_server_url(Config);
324
325                 /* check if video server is running locally */
326                 if (video_get_docroot(Config).size() > 0 &&
327                         (0 == video_server_url.compare (0, 16, "http://127.0.0.1") || 0 == video_server_url.compare (0, 16, "http://localhost"))
328                    )
329                 {
330                         /* check if the file can be accessed */
331                         int plen;
332                         CURL *curl;
333                         curl = curl_easy_init();
334                         char *ue = curl_easy_unescape(curl, uri.c_str(), uri.length(), &plen);
335 #ifdef PLATFORM_WINDOWS
336                         char *tmp;
337                         while ((tmp = strchr(ue, '/'))) *tmp = '\\';
338 #endif
339                         std::string path = video_get_docroot(Config) + ue;
340                         if (!::access(path.c_str(), R_OK)) {
341                                 uri = path;
342                                 local_file = true;
343                         }
344                         curl_easy_cleanup(curl);
345                         curl_free(ue);
346                 }
347                 return uri;
348         }
349 }
350
351 enum VtlImportOption
352 AddVideoDialog::import_option ()
353 {
354         int n = notebook.get_current_page ();
355         if (n == 0 && show_advanced) { return VTL_IMPORT_NONE; }
356         return VTL_IMPORT_TRANSCODE;
357 }
358
359 bool
360 AddVideoDialog::launch_xjadeo ()
361 {
362         return xjadeo_checkbox.get_active();
363 }
364
365 bool
366 AddVideoDialog::auto_set_session_fps ()
367 {
368         return set_session_fps_checkbox.get_active();
369 }
370
371 void
372 AddVideoDialog::clear_preview_image ()
373 {
374         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
375         video_draw_cross(imgbuf);
376         preview_image->set(imgbuf);
377         preview_image->show();
378 }
379
380 void
381 AddVideoDialog::set_action_ok (bool yn)
382 {
383         if (yn) {
384                 ok_button->set_sensitive(true);
385         } else {
386                 preview_path = "";
387                 pi_tcin.set_text("-");
388                 pi_tcout.set_text("-");
389                 pi_aspect.set_text("-");
390                 pi_fps.set_text("-");
391                 ok_button->set_sensitive(false);
392                 clear_preview_image();
393         }
394 }
395
396 void
397 AddVideoDialog::file_selection_changed ()
398 {
399         if (chooser.get_filename().size() > 0) {
400                 std::string path = chooser.get_filename();
401                 bool ok =
402                                 Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
403                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
404                 set_action_ok(ok);
405                 if (ok) {
406                         seek_slider.set_value(0);
407                         request_preview(video_map_path(video_get_docroot(Config), path));
408                 }
409         } else {
410                 set_action_ok(false);
411         }
412 }
413
414 void
415 AddVideoDialog::file_activated ()
416 {
417         if (chooser.get_filename().size() > 0) {
418                 std::string path = chooser.get_filename();
419                 // TODO check docroot -> set import options
420                 bool ok =
421                                 Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_REGULAR | Glib::FILE_TEST_IS_SYMLINK)
422                                 && !Glib::file_test(path.c_str(), Glib::FILE_TEST_IS_DIR);
423                 if (ok) {
424                         Gtk::Dialog::response(RESPONSE_ACCEPT);
425                 }
426         }
427 }
428
429 /**** Tree List Interaction ***/
430
431 void
432 AddVideoDialog::harvid_list_view_selected () {
433         Gtk::TreeModel::iterator iter = harvid_list_view.get_selection()->get_selected();
434         // TODO check docroot -> set import options, xjadeo
435         if(!iter) {
436                 set_action_ok(false);
437                 return;
438         }
439         if ((std::string)((*iter)[harvid_list_columns.id]) == Stock::DIRECTORY.id) {
440                 set_action_ok(false);
441         } else {
442                 set_action_ok(true);
443                 seek_slider.set_value(0);
444                 request_preview((*iter)[harvid_list_columns.uri]);
445         }
446 }
447
448 void
449 AddVideoDialog::harvid_list_view_activated (const Gtk::TreeModel::Path& path, Gtk::TreeViewColumn*) {
450         Gtk::TreeModel::iterator iter = harvid_list->get_iter(path);
451         if (!iter) return;
452         std::string type = (*iter)[harvid_list_columns.id];
453         std::string url = (*iter)[harvid_list_columns.uri];
454
455 #if 0
456         printf ("A: %s %s %s\n",
457                         ((std::string)((*iter)[harvid_list_columns.id])).c_str(),
458                         ((std::string)((*iter)[harvid_list_columns.uri])).c_str(),
459                         ((std::string)((*iter)[harvid_list_columns.filename])).c_str());
460 #endif
461
462         if (type == Gtk::Stock::DIRECTORY.id) {
463                 harvid_request(url.c_str());
464         } else {
465                 Gtk::Dialog::response(RESPONSE_ACCEPT);
466         }
467 }
468
469 void
470 AddVideoDialog::harvid_load_docroot() {
471         set_action_ok(false);
472         loaded_docroot = true;
473
474         std::string video_server_url = video_get_server_url(Config);
475         char url[2048];
476         snprintf(url, sizeof(url), "%s%sindex/"
477                 , video_server_url.c_str()
478                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/");
479         harvid_request(url);
480         harvid_initialized = true;
481 }
482
483 bool
484 AddVideoDialog::page_switch() {
485         if (notebook.get_current_page () == 1 || show_advanced) {
486                 file_selection_changed();
487                 return true;
488         }
489
490         if (harvid_initialized) {
491                 harvid_list_view_selected();
492         } else {
493                 harvid_load_docroot();
494         }
495         return true;
496 }
497
498 /**** Harvid HTTP interface ***/
499 void
500 AddVideoDialog::harvid_request(std::string u)
501 {
502         char url[2048];
503         int status;
504         snprintf(url, sizeof(url), "%s?format=csv", u.c_str());
505
506         harvid_list->clear();
507
508         char* res = ArdourCurl::http_get (url, &status);
509         if (status != 200) {
510                 printf("request failed\n"); // XXX
511                 harvid_path.set_text(" - request failed -");
512                 free(res);
513                 return;
514         }
515
516         /* add up-to-parent */
517         size_t se = u.find_last_of("/", u.size()-2);
518         size_t ss = u.find("/index/");
519         if (se != string::npos && ss != string::npos && se > ss) {
520                 TreeModel::iterator new_row = harvid_list->append();
521                 TreeModel::Row row = *new_row;
522                 row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
523                 row[harvid_list_columns.uri     ] = u.substr(0, se + 1);
524                 row[harvid_list_columns.filename] = X_("..");
525         }
526         if (se != string::npos) {
527                 int plen;
528                 std::string path = u.substr(ss + 6);
529                 CURL *curl;
530                 curl = curl_easy_init();
531                 char *ue = curl_easy_unescape(curl, path.c_str(), path.length(), &plen);
532                 harvid_path.set_text(std::string(ue));
533                 curl_easy_cleanup(curl);
534                 curl_free(ue);
535         } else {
536                 harvid_path.set_text(" ??? ");
537         }
538
539         if (!res) return;
540
541         std::vector<std::vector<std::string> > lines;
542         ParseCSV(std::string(res), lines);
543         for (std::vector<std::vector<std::string> >::iterator i = lines.begin(); i != lines.end(); ++i) {
544                 TreeModel::iterator new_row = harvid_list->append();
545                 TreeModel::Row row = *new_row;
546
547                 if (i->at(0) == X_("D")) {
548                         row[harvid_list_columns.id      ] = Gtk::Stock::DIRECTORY.id;
549                         row[harvid_list_columns.uri     ] = i->at(1).c_str();
550                         row[harvid_list_columns.filename] = i->at(2).c_str();
551                 } else {
552                         row[harvid_list_columns.id      ] = Gtk::Stock::MEDIA_PLAY.id;
553                         row[harvid_list_columns.uri     ] = i->at(2).c_str();
554                         row[harvid_list_columns.filename] = i->at(3).c_str();
555                 }
556         }
557
558         free(res);
559 }
560
561 void
562 AddVideoDialog::seek_preview()
563 {
564         if (preview_path.size() > 0)
565                 request_preview(preview_path);
566 }
567
568 void
569 AddVideoDialog::request_preview(std::string u)
570 {
571         std::string video_server_url = video_get_server_url(Config);
572
573         double video_file_fps;
574         long long int video_duration;
575         double video_start_offset;
576         double video_aspect_ratio;
577
578         int clip_width = PREVIEW_WIDTH;
579         int clip_height = PREVIEW_HEIGHT;
580         int clip_xoff, clip_yoff;
581
582         if (!video_query_info(video_server_url, u,
583                         video_file_fps, video_duration, video_start_offset, video_aspect_ratio))
584         {
585                 printf("image preview info request failed\n");
586                 // set_action_ok(false); // XXX only if docroot mismatch
587                 preview_path = "";
588                 pi_tcin.set_text("-");
589                 pi_tcout.set_text("-");
590                 pi_aspect.set_text("-");
591                 pi_fps.set_text("-");
592
593                 clear_preview_image();
594                 return;
595         }
596
597         if ((PREVIEW_WIDTH / (double)PREVIEW_HEIGHT) > video_aspect_ratio ) {
598                 clip_width = MIN(PREVIEW_WIDTH, rint(clip_height * video_aspect_ratio));
599         } else {
600                 clip_height = MIN(PREVIEW_HEIGHT, rint(clip_width / video_aspect_ratio));
601         }
602
603         pi_tcin.set_text(Timecode::timecode_format_sampletime(
604                                 video_start_offset, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
605         pi_tcout.set_text(Timecode::timecode_format_sampletime(
606                                 video_start_offset + video_duration, video_file_fps, video_file_fps, rint(video_file_fps*100.0)==2997));
607
608         /* todo break out this code -> re-usability */
609         const int arc = rint(video_aspect_ratio*100);
610
611         switch (arc) {
612                 case 100:
613                         pi_aspect.set_text(X_(" 1:1"));  // square (large format stills)
614                         break;
615                 case 125:
616                         pi_aspect.set_text(X_(" 5:4"));
617                         break;
618                 case 133:
619                         pi_aspect.set_text(X_(" 4:3"));
620                         break;
621                 case 134:
622                         pi_aspect.set_text(X_(" 47:35")); // 752x560, Super8-scans
623                         break;
624                 case 137:
625                 case 138:
626                         pi_aspect.set_text(X_(" 1.37:1")); // 'Academy ratio' <= 1953
627                         break;
628                 case 141:
629                         pi_aspect.set_text(X_(" 1.41:1")); //  Lichtenberg ratio
630                         break;
631                 case 150:
632                         pi_aspect.set_text(X_(" 3:2"));  // classic 35mm
633                         break;
634                 case 160:
635                         pi_aspect.set_text(X_(" 8:5"));  // credit-card size
636                         break;
637                 case 162:
638                         pi_aspect.set_text(X_(" 16:10")); // golden ratio 1.61803..
639                         break;
640                 case 166:
641                 case 167:
642                         pi_aspect.set_text(X_(" 5:3")); // Super16, EU-widescreen
643                         break;
644                 case 177:
645                 case 178:
646                         pi_aspect.set_text(X_(" 16:9")); // HD video
647                         break;
648                 case 180:
649                         pi_aspect.set_text(X_(" 9:5"));
650                         break;
651                 case 185:
652                         pi_aspect.set_text(X_(" 1.85:1")); // US widescreen cinema
653                         break;
654                 case 200:
655                         pi_aspect.set_text(X_(" 2:1"));
656                         break;
657                 case 239:
658                 case 240:
659                         pi_aspect.set_text(X_(" 2.40:1")); // Anamorphic
660                         break;
661                 case 266:
662                 case 267:
663                         pi_aspect.set_text(X_(" 2.66:1")); // CinemaScope
664                         break;
665                 case 275:
666                         pi_aspect.set_text(X_(" 2.75:1")); // Ultra Panavision
667                         break;
668                 case 400:
669                         pi_aspect.set_text(X_(" 4.00:1")); // three 35mm 1.33:1 polyvision
670                         break;
671                 default:
672                         pi_aspect.set_text(string_compose(X_(" %1:1"), video_aspect_ratio));
673                 break;
674         }
675
676         pi_fps.set_text(string_compose(_(" %1 fps"), video_file_fps));
677
678         clip_xoff = (PREVIEW_WIDTH - clip_width)/2;
679         clip_yoff = (PREVIEW_HEIGHT - clip_height)/2;
680
681         char url[2048];
682         snprintf(url, sizeof(url), "%s%s?frame=%lli&w=%d&h=%di&file=%s&format=rgb"
683                 , video_server_url.c_str()
684                 , (video_server_url.length()>0 && video_server_url.at(video_server_url.length()-1) == '/')?"":"/"
685                 , (long long) (video_duration * seek_slider.get_value() / 1000.0)
686                 , clip_width, clip_height, u.c_str());
687
688         char* data = ArdourCurl::http_get (url, NULL);
689         if (!data) {
690                 printf("image preview request failed %s\n", url);
691                 imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
692                 video_draw_cross(imgbuf);
693                 preview_path = "";
694         } else {
695                 Glib::RefPtr<Gdk::Pixbuf> tmp;
696                 tmp = Gdk::Pixbuf::create_from_data ((guint8*) data, Gdk::COLORSPACE_RGB, false, 8, clip_width, clip_height, clip_width*3);
697                 if (clip_width != PREVIEW_WIDTH || clip_height != PREVIEW_HEIGHT) {
698                         imgbuf->fill(RGBA_TO_UINT(0,0,0,255));
699                 }
700                 tmp->copy_area (0, 0, clip_width, clip_height, imgbuf, clip_xoff, clip_yoff);
701                 preview_path = u;
702                 free(data);
703         }
704         preview_image->set(imgbuf);
705         preview_image->show();
706 }