0eb7efb2f92bd5d96181c9cdf352e7f585cd9760
[dcpomatic.git] / src / lib / sndfile_content.cc
1 /*
2     Copyright (C) 2013-2015 Carl Hetherington <cth@carlh.net>
3
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17
18 */
19
20 #include <libcxml/cxml.h>
21 #include "sndfile_content.h"
22 #include "sndfile_decoder.h"
23 #include "film.h"
24 #include "compose.hpp"
25 #include "job.h"
26 #include "util.h"
27 #include "safe_stringstream.h"
28
29 #include "i18n.h"
30
31 using std::string;
32 using std::cout;
33 using boost::shared_ptr;
34
35 SndfileContent::SndfileContent (shared_ptr<const Film> f, boost::filesystem::path p)
36         : Content (f, p)
37         , SingleStreamAudioContent (f, p)
38 {
39
40 }
41
42 SndfileContent::SndfileContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, int version)
43         : Content (f, node)
44         , SingleStreamAudioContent (f, node, version)
45 {
46         
47 }
48
49 void
50 SndfileContent::as_xml (xmlpp::Node* node) const
51 {
52         node->add_child("Type")->add_child_text ("Sndfile");
53         Content::as_xml (node);
54         SingleStreamAudioContent::as_xml (node);
55 }
56
57
58 string
59 SndfileContent::summary () const
60 {
61         /* Get the string() here so that the name does not have quotes around it */
62         return String::compose (_("%1 [audio]"), path_summary ());
63 }
64
65 string
66 SndfileContent::technical_summary () const
67 {
68         return Content::technical_summary() + " - "
69                 + AudioContent::technical_summary ()
70                 + " - sndfile";
71 }
72
73 bool
74 SndfileContent::valid_file (boost::filesystem::path f)
75 {
76         /* XXX: more extensions */
77         string ext = f.extension().string();
78         transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
79         return (ext == ".wav" || ext == ".aif" || ext == ".aiff");
80 }
81
82 void
83 SndfileContent::examine (shared_ptr<Job> job)
84 {
85         job->set_progress_unknown ();
86         Content::examine (job);
87         shared_ptr<AudioExaminer> dec (new SndfileDecoder (shared_from_this()));
88         take_from_audio_examiner (dec);
89 }
90
91 DCPTime
92 SndfileContent::full_length () const
93 {
94         shared_ptr<const Film> film = _film.lock ();
95         DCPOMATIC_ASSERT (film);
96         FrameRateChange const frc = film->active_frame_rate_change (position ());
97         return DCPTime::from_frames (audio_length() / frc.speed_up, audio_frame_rate ());
98 }
99