617989d207efbbddcb0e2a782f0b1efa6daf2acc
[dcpomatic.git] / src / lib / single_stream_audio_content.cc
1 /*
2     Copyright (C) 2014-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 "single_stream_audio_content.h"
21 #include "audio_examiner.h"
22 #include "film.h"
23 #include "raw_convert.h"
24 #include <libxml++/libxml++.h>
25
26 #include "i18n.h"
27
28 using std::string;
29 using std::cout;
30 using std::vector;
31 using std::list;
32 using std::pair;
33 using boost::shared_ptr;
34
35 SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr<const Film> film)
36         : Content (film)
37         , AudioContent (film)
38 {
39
40 }
41
42 SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr<const Film> film, boost::filesystem::path p)
43         : Content (film, p)
44         , AudioContent (film, p)
45 {
46
47 }
48
49 SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr<const Film> film, cxml::ConstNodePtr node, int version)
50         : Content (film, node)
51         , AudioContent (film, node)
52         , _audio_stream (new AudioStream (node->number_child<int> ("AudioFrameRate"), AudioMapping (node->node_child ("AudioMapping"), version)))
53 {
54
55 }
56
57 void
58 SingleStreamAudioContent::as_xml (xmlpp::Node* node) const
59 {
60         AudioContent::as_xml (node);
61         node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio_stream()->frame_rate ()));
62         audio_stream()->mapping().as_xml (node->add_child("AudioMapping"));
63 }
64
65 void
66 SingleStreamAudioContent::take_from_audio_examiner (shared_ptr<AudioExaminer> examiner)
67 {
68         shared_ptr<const Film> film = _film.lock ();
69         DCPOMATIC_ASSERT (film);
70
71         {
72                 boost::mutex::scoped_lock lm (_mutex);
73                 _audio_stream.reset (new AudioStream (examiner->audio_frame_rate(), examiner->audio_channels ()));
74                 AudioMapping m = _audio_stream->mapping ();
75                 film->make_audio_mapping_default (m);
76                 _audio_stream->set_mapping (m);
77         }
78
79         signal_changed (AudioContentProperty::AUDIO_STREAMS);
80 }
81
82 vector<AudioStreamPtr>
83 SingleStreamAudioContent::audio_streams () const
84 {
85         vector<AudioStreamPtr> s;
86         s.push_back (_audio_stream);
87         return s;
88 }
89
90 void
91 SingleStreamAudioContent::add_properties (list<pair<string, string> >& p) const
92 {
93         /* XXX: this could be better wrt audio streams */
94         p.push_back (make_pair (_("Audio channels"), raw_convert<string> (audio_stream()->channels ())));
95 }