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