9604ee7cc4a0cf2c1ffc2a729f5e13ec61f34d5b
[dcpomatic.git] / src / wx / content_timeline_audio_view.cc
1 /*
2     Copyright (C) 2013-2018 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
22 #include "content_timeline_audio_view.h"
23 #include "wx_util.h"
24 #include "lib/audio_content.h"
25 #include "lib/util.h"
26
27
28 using std::dynamic_pointer_cast;
29 using std::list;
30 using std::shared_ptr;
31
32
33 /** @class ContentTimelineAudioView
34  *  @brief Content timeline view for AudioContent.
35  */
36
37
38 ContentTimelineAudioView::ContentTimelineAudioView(ContentTimeline& tl, shared_ptr<Content> c)
39         : TimelineContentView (tl, c)
40 {
41
42 }
43
44 wxColour
45 ContentTimelineAudioView::background_colour () const
46 {
47         return wxColour (149, 121, 232, 255);
48 }
49
50 wxColour
51 ContentTimelineAudioView::foreground_colour () const
52 {
53         return wxColour (0, 0, 0, 255);
54 }
55
56 wxString
57 ContentTimelineAudioView::label () const
58 {
59         wxString s = TimelineContentView::label ();
60         shared_ptr<AudioContent> ac = content()->audio;
61         DCPOMATIC_ASSERT (ac);
62
63         if (ac->gain() > 0.01) {
64                 s += wxString::Format (" +%.1fdB", ac->gain());
65         } else if (ac->gain() < -0.01) {
66                 s += wxString::Format (" %.1fdB", ac->gain());
67         }
68
69         if (ac->delay() > 0) {
70                 s += wxString::Format (_(" delayed by %dms"), ac->delay());
71         } else if (ac->delay() < 0) {
72                 s += wxString::Format (_(" advanced by %dms"), -ac->delay());
73         }
74
75         list<int> mapped = ac->mapping().mapped_output_channels();
76         if (!mapped.empty ()) {
77                 s += wxString::FromUTF8(" → ");
78                 for (auto i: mapped) {
79                         s += std_to_wx(short_audio_channel_name(i)) + ", ";
80                 }
81                 s = s.Left(s.Length() - 2);
82         }
83
84         return s;
85 }