Merge master.
[dcpomatic.git] / src / lib / single_stream_audio_content.cc
1 /*
2     Copyright (C) 2014 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 <dcp/raw_convert.h>
21 #include "single_stream_audio_content.h"
22 #include "audio_examiner.h"
23 #include "film.h"
24
25 using std::string;
26 using std::cout;
27 using boost::shared_ptr;
28 using dcp::raw_convert;
29
30 SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr<const Film> f)
31         : Content (f)
32         , AudioContent (f)
33         , _audio_channels (0)
34         , _audio_length (0)
35         , _audio_frame_rate (0)
36 {
37
38 }
39
40 SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr<const Film> f, boost::filesystem::path p)
41         : Content (f, p)
42         , AudioContent (f, p)
43         , _audio_channels (0)
44         , _audio_length (0)
45         , _audio_frame_rate (0)
46 {
47
48 }
49
50 SingleStreamAudioContent::SingleStreamAudioContent (shared_ptr<const Film> f, cxml::ConstNodePtr node, int version)
51         : Content (f, node)
52         , AudioContent (f, node)
53         , _audio_mapping (node->node_child ("AudioMapping"), version)
54 {
55         _audio_channels = node->number_child<int> ("AudioChannels");
56         _audio_length = ContentTime (node->number_child<ContentTime::Type> ("AudioLength"));
57         _audio_frame_rate = node->number_child<int> ("AudioFrameRate");
58 }
59
60 void
61 SingleStreamAudioContent::set_audio_mapping (AudioMapping m)
62 {
63         {
64                 boost::mutex::scoped_lock lm (_mutex);
65                 _audio_mapping = m;
66         }
67
68         AudioContent::set_audio_mapping (m);
69 }
70
71
72 void
73 SingleStreamAudioContent::as_xml (xmlpp::Node* node) const
74 {
75         AudioContent::as_xml (node);
76         node->add_child("AudioChannels")->add_child_text (raw_convert<string> (audio_channels ()));
77         node->add_child("AudioLength")->add_child_text (raw_convert<string> (audio_length().get ()));
78         node->add_child("AudioFrameRate")->add_child_text (raw_convert<string> (audio_frame_rate ()));
79         _audio_mapping.as_xml (node->add_child("AudioMapping"));
80 }
81
82 void
83 SingleStreamAudioContent::take_from_audio_examiner (shared_ptr<AudioExaminer> examiner)
84 {
85         {
86                 boost::mutex::scoped_lock lm (_mutex);
87                 _audio_channels = examiner->audio_channels ();
88                 _audio_length = examiner->audio_length ();
89                 _audio_frame_rate = examiner->audio_frame_rate ();
90         }
91
92         signal_changed (AudioContentProperty::AUDIO_CHANNELS);
93         signal_changed (AudioContentProperty::AUDIO_LENGTH);
94         signal_changed (AudioContentProperty::AUDIO_FRAME_RATE);
95
96         int const p = processed_audio_channels ();
97
98         {
99                 boost::mutex::scoped_lock lm (_mutex);
100                 /* XXX: do this in signal_changed...? */
101                 _audio_mapping = AudioMapping (p);
102                 _audio_mapping.make_default ();
103         }
104         
105         signal_changed (AudioContentProperty::AUDIO_MAPPING);
106 }