No-op; fix GPL address and use the explicit-program-name version.
[dcpomatic.git] / src / lib / sndfile_content.cc
1 /*
2     Copyright (C) 2013-2016 Carl Hetherington <cth@carlh.net>
3
4     This file is part of DCP-o-matic.
5
6     DCP-o-matic is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     DCP-o-matic is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with DCP-o-matic.  If not, see <http://www.gnu.org/licenses/>.
18
19 */
20
21 #include "sndfile_content.h"
22 #include "sndfile_decoder.h"
23 #include "sndfile_examiner.h"
24 #include "audio_content.h"
25 #include "film.h"
26 #include "compose.hpp"
27 #include "job.h"
28 #include "util.h"
29 #include "safe_stringstream.h"
30 #include "raw_convert.h"
31 #include <libcxml/cxml.h>
32 #include <libxml++/libxml++.h>
33 #include <iostream>
34
35 #include "i18n.h"
36
37 using std::string;
38 using std::cout;
39 using std::vector;
40 using boost::shared_ptr;
41
42 SndfileContent::SndfileContent (shared_ptr<const Film> film, boost::filesystem::path p)
43         : Content (film, p)
44 {
45         audio.reset (new AudioContent (this));
46 }
47
48 SndfileContent::SndfileContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
49         : Content (film, node)
50 {
51         audio = AudioContent::from_xml (this, node);
52
53         if (audio) {
54                 audio->set_stream (
55                         AudioStreamPtr (
56                                 new AudioStream (
57                                         node->number_child<int> ("AudioFrameRate"),
58                                         node->number_child<Frame> ("AudioLength"),
59                                         AudioMapping (node->node_child ("AudioMapping"), version)
60                                         )
61                                 )
62                         );
63         }
64 }
65
66 void
67 SndfileContent::as_xml (xmlpp::Node* node) const
68 {
69         node->add_child("Type")->add_child_text ("Sndfile");
70
71         Content::as_xml (node);
72
73         if (audio) {
74                 audio->as_xml (node);
75                 node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio->stream()->frame_rate ()));
76                 node->add_child("AudioLength")->add_child_text (raw_convert<string> (audio->stream()->length ()));
77                 audio->stream()->mapping().as_xml (node->add_child("AudioMapping"));
78         }
79 }
80
81
82 string
83 SndfileContent::summary () const
84 {
85         /* Get the string() here so that the name does not have quotes around it */
86         return String::compose (_("%1 [audio]"), path_summary ());
87 }
88
89 string
90 SndfileContent::technical_summary () const
91 {
92         return Content::technical_summary() + " - "
93                 + audio->technical_summary ()
94                 + " - sndfile";
95 }
96
97 bool
98 SndfileContent::valid_file (boost::filesystem::path f)
99 {
100         /* XXX: more extensions */
101         string ext = f.extension().string();
102         transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
103         return (ext == ".wav" || ext == ".w64" || ext == ".flac" || ext == ".aif" || ext == ".aiff");
104 }
105
106 void
107 SndfileContent::examine (shared_ptr<Job> job)
108 {
109         job->set_progress_unknown ();
110         Content::examine (job);
111         shared_ptr<AudioExaminer> ex (new SndfileExaminer (shared_from_this ()));
112
113         {
114                 boost::mutex::scoped_lock lm (_mutex);
115                 AudioStreamPtr as (new AudioStream (ex->audio_frame_rate(), ex->audio_length(), ex->audio_channels ()));
116                 audio->set_stream (as);
117                 AudioMapping m = as->mapping ();
118                 film()->make_audio_mapping_default (m);
119                 as->set_mapping (m);
120         }
121
122         signal_changed (AudioContentProperty::STREAMS);
123 }
124
125 DCPTime
126 SndfileContent::full_length () const
127 {
128         FrameRateChange const frc (active_video_frame_rate(), film()->video_frame_rate());
129         return DCPTime::from_frames (audio->stream()->length() / frc.speed_up, audio->stream()->frame_rate ());
130 }