Allow adding of content.
authorCarl Hetherington <cth@carlh.net>
Sun, 31 Mar 2013 14:24:38 +0000 (15:24 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 31 Mar 2013 14:24:38 +0000 (15:24 +0100)
src/lib/imagemagick_content.cc
src/lib/imagemagick_content.h
src/lib/sndfile_content.cc
src/lib/sndfile_content.h
src/lib/util.cc
src/lib/util.h
src/wx/film_editor.cc
src/wx/film_editor.h

index d0887c0aa224fb8897863e059629757b3c04dda1..806c8ac5d422e905a00a0a9e0a0db2f0d457f886 100644 (file)
@@ -1,2 +1,27 @@
 #include "imagemagick_content.h"
+#include "compose.hpp"
 
+#include "i18n.h"
+
+using std::string;
+
+ImageMagickContent::ImageMagickContent (boost::filesystem::path f)
+       : Content (f)
+       , VideoContent (f)
+{
+
+}
+
+string
+ImageMagickContent::summary () const
+{
+       return String::compose (_("Image: %1"), file().filename ());
+}
+
+bool
+ImageMagickContent::valid_file (boost::filesystem::path f)
+{
+       string ext = f.extension().string();
+       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+       return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp");
+}
index 985aa0e8d5ab5fec6cec7c6ba33b9435cdd88c38..0dd5baba8e2c6567553a67635f8079da958faffc 100644 (file)
@@ -4,4 +4,8 @@ class ImageMagickContent : public VideoContent
 {
 public:
        ImageMagickContent (boost::filesystem::path);
+
+       std::string summary () const;
+
+       static bool valid_file (boost::filesystem::path);
 };
index 8f5b2890170dc5e1b8dc2879664978d7982ceade..53df4deeacda2ea12d7fa127d80d39c3ac61f4e1 100644 (file)
@@ -5,6 +5,13 @@
 
 using namespace std;
 
+SndfileContent::SndfileContent (boost::filesystem::path f)
+       : Content (f)
+       , AudioContent (f)
+{
+
+}
+
 string
 SndfileContent::summary () const
 {
@@ -39,3 +46,12 @@ SndfileContent::audio_channel_layout () const
        return 0;
 }
        
+
+bool
+SndfileContent::valid_file (boost::filesystem::path f)
+{
+       /* XXX: more extensions */
+       string ext = f.extension().string();
+       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+       return (ext == ".wav" || ext == ".aif" || ext == ".aiff");
+}
index e84617ed3450b14ecdeb45d7ee22225e76753929..10cb428a17c2cbeb509667aa22a53858c70fafd3 100644 (file)
@@ -3,11 +3,15 @@
 class SndfileContent : public AudioContent
 {
 public:
+       SndfileContent (boost::filesystem::path);
+       
        std::string summary () const;
 
-        /* AudioDecoder */
+        /* AudioContent */
         int audio_channels () const;
         ContentAudioFrame audio_length () const;
         int audio_frame_rate () const;
         int64_t audio_channel_layout () const;
+
+       static bool valid_file (boost::filesystem::path);
 };
index 0247408679f172a3ae29b5737083e8e625b0debc..1c020875abd95d5e3c7cd4f90f754d4a42375241 100644 (file)
@@ -878,19 +878,6 @@ video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float fram
        return ((int64_t) v * audio_sample_rate / frames_per_second);
 }
 
-/** @param f Filename.
- *  @return true if this file is a still image, false if it is something else.
- */
-bool
-still_image_file (string f)
-{
-       string ext = boost::filesystem::path(f).extension().string();
-
-       transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
-       
-       return (ext == N_(".tif") || ext == N_(".tiff") || ext == N_(".jpg") || ext == N_(".jpeg") || ext == N_(".png") || ext == N_(".bmp"));
-}
-
 /** @return A pair containing CPU model name and the number of processors */
 pair<string, int>
 cpu_info ()
index 87274cfff1d3b18c5e7e4729eb3f738dca5b7b81..b8c1e31161994eb6c23700efaace20c2281950bc 100644 (file)
@@ -106,11 +106,6 @@ struct FrameRateConversion
 
 int best_dcp_frame_rate (float);
 
-enum ContentType {
-       STILL, ///< content is still images
-       VIDEO  ///< content is a video
-};
-
 /** @struct Crop
  *  @brief A description of the crop of an image or video.
  */
@@ -292,7 +287,6 @@ private:
 };
 
 extern int64_t video_frames_to_audio_frames (SourceFrame v, float audio_sample_rate, float frames_per_second);
-extern bool still_image_file (std::string);
 extern std::pair<std::string, int> cpu_info ();
 
 #endif
index 7dfbf6c5040897f66f1b448a0391e8be6d06e7b7..ce1c1abe8bb77610c5886b4893ba40c71d7106ed 100644 (file)
@@ -38,6 +38,8 @@
 #include "lib/filter.h"
 #include "lib/config.h"
 #include "lib/ffmpeg_decoder.h"
+#include "lib/imagemagick_content.h"
+#include "lib/sndfile_content.h"
 #include "filter_dialog.h"
 #include "wx_util.h"
 #include "film_editor.h"
@@ -201,6 +203,10 @@ FilmEditor::connect_to_widgets ()
        _edit_dci_button->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::edit_dci_button_clicked), 0, this);
        _format->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FilmEditor::format_changed), 0, this);
        _trust_content_header->Connect (wxID_ANY, wxEVT_COMMAND_CHECKBOX_CLICKED, wxCommandEventHandler (FilmEditor::trust_content_header_changed), 0, this);
+       _content_add->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
+       _content_remove->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
+       _content_earlier->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
+       _content_later->Connect (wxID_ANY, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler (FilmEditor::content_add_clicked), 0, this);
        _left_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::left_crop_changed), 0, this);
        _right_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::right_crop_changed), 0, this);
        _top_crop->Connect (wxID_ANY, wxEVT_COMMAND_SPINCTRL_UPDATED, wxCommandEventHandler (FilmEditor::top_crop_changed), 0, this);
@@ -834,6 +840,11 @@ FilmEditor::set_things_sensitive (bool s)
        _format->Enable (s);
        _content->Enable (s);
        _trust_content_header->Enable (s);
+       _content->Enable (s);
+       _content_add->Enable (s);
+       _content_remove->Enable (s);
+       _content_earlier->Enable (s);
+       _content_later->Enable (s);
        _left_crop->Enable (s);
        _right_crop->Enable (s);
        _top_crop->Enable (s);
@@ -1150,3 +1161,43 @@ FilmEditor::setup_content ()
        }
 }
 
+void
+FilmEditor::content_add_clicked (wxCommandEvent &)
+{
+       wxFileDialog* d = new wxFileDialog (this);
+       int const r = d->ShowModal ();
+       d->Destroy ();
+
+       if (r != wxID_OK) {
+               return;
+       }
+
+       boost::filesystem::path p (wx_to_std (d->GetPath()));
+
+       if (ImageMagickContent::valid_file (p)) {
+               _film->add_content (shared_ptr<ImageMagickContent> (new ImageMagickContent (p)));
+       } else if (SndfileContent::valid_file (p)) {
+               _film->add_content (shared_ptr<SndfileContent> (new SndfileContent (p)));
+       } else {
+               _film->add_content (shared_ptr<FFmpegContent> (new FFmpegContent (p)));
+       }
+       
+}
+
+void
+FilmEditor::content_remove_clicked (wxCommandEvent &)
+{
+
+}
+
+void
+FilmEditor::content_earlier_clicked (wxCommandEvent &)
+{
+
+}
+
+void
+FilmEditor::content_later_clicked (wxCommandEvent &)
+{
+
+}
index 6b1d98ea64603ce5499a21ed5681c8c4ff46e625..52854b894436a1cc1ed876f45ced463f09c9a3bb 100644 (file)
@@ -62,6 +62,10 @@ private:
        void top_crop_changed (wxCommandEvent &);
        void bottom_crop_changed (wxCommandEvent &);
        void trust_content_header_changed (wxCommandEvent &);
+       void content_add_clicked (wxCommandEvent &);
+       void content_remove_clicked (wxCommandEvent &);
+       void content_earlier_clicked (wxCommandEvent &);
+       void content_later_clicked (wxCommandEvent &);
        void format_changed (wxCommandEvent &);
        void trim_start_changed (wxCommandEvent &);
        void trim_end_changed (wxCommandEvent &);