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