Add basic timeline window.
[dcpomatic.git] / src / wx / ffmpeg_content_dialog.cc
1 /*
2     Copyright (C) 2013 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 <boost/lexical_cast.hpp>
21 #include "lib/ffmpeg_content.h"
22 #include "ffmpeg_content_dialog.h"
23 #include "wx_util.h"
24
25 using std::vector;
26 using std::string;
27 using boost::shared_ptr;
28 using boost::lexical_cast;
29
30 FFmpegContentDialog::FFmpegContentDialog (wxWindow* parent, shared_ptr<FFmpegContent> content)
31         : wxDialog (parent, wxID_ANY, _("Video"))
32 {
33         wxFlexGridSizer* grid = new wxFlexGridSizer (3, 6, 6);
34         grid->AddGrowableCol (1, 1);
35
36         add_label_to_sizer (grid, this, _("Audio Stream"));
37         _audio_stream = new wxChoice (this, wxID_ANY);
38         grid->Add (_audio_stream, 1, wxEXPAND | wxALL, 6);
39         _audio_description = new wxStaticText (this, wxID_ANY, wxT (""));
40         grid->Add (_audio_description, 1, wxALIGN_CENTER_VERTICAL | wxLEFT, 8);
41         
42         add_label_to_sizer (grid, this, _("Subtitle stream"));
43         _subtitle_stream = new wxChoice (this, wxID_ANY);
44         grid->Add (_subtitle_stream, 1, wxEXPAND | wxALL, 6);
45         grid->AddSpacer (0);
46
47         _audio_stream->Clear ();
48         vector<FFmpegAudioStream> a = content->audio_streams ();
49         for (vector<FFmpegAudioStream>::iterator i = a.begin(); i != a.end(); ++i) {
50                 _audio_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (lexical_cast<string> (i->id))));
51         }
52         
53         if (content->audio_stream()) {
54                 checked_set (_audio_stream, lexical_cast<string> (content->audio_stream()->id));
55         }
56
57         _subtitle_stream->Clear ();
58         vector<FFmpegSubtitleStream> s = content->subtitle_streams ();
59         for (vector<FFmpegSubtitleStream>::iterator i = s.begin(); i != s.end(); ++i) {
60                 _subtitle_stream->Append (std_to_wx (i->name), new wxStringClientData (std_to_wx (lexical_cast<string> (i->id))));
61         }
62         
63         if (content->subtitle_stream()) {
64                 checked_set (_subtitle_stream, lexical_cast<string> (content->subtitle_stream()->id));
65         } else {
66                 _subtitle_stream->SetSelection (wxNOT_FOUND);
67         }
68
69         wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL);
70         overall_sizer->Add (grid, 1, wxEXPAND | wxALL, 6);
71
72         wxSizer* buttons = CreateSeparatedButtonSizer (wxOK);
73         if (buttons) {
74                 overall_sizer->Add (buttons, wxSizerFlags().Expand().DoubleBorder());
75         }
76
77         SetSizer (overall_sizer);
78         overall_sizer->Layout ();
79         overall_sizer->SetSizeHints (this);
80
81         _audio_stream->Connect    (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FFmpegContentDialog::audio_stream_changed), 0, this);
82         _subtitle_stream->Connect (wxID_ANY, wxEVT_COMMAND_CHOICE_SELECTED, wxCommandEventHandler (FFmpegContentDialog::subtitle_stream_changed), 0, this);
83 }
84
85 void
86 FFmpegContentDialog::audio_stream_changed (wxCommandEvent &)
87 {
88         shared_ptr<FFmpegContent> c = _content.lock ();
89         if (!c) {
90                 return;
91         }
92         
93         vector<FFmpegAudioStream> a = c->audio_streams ();
94         vector<FFmpegAudioStream>::iterator i = a.begin ();
95         string const s = string_client_data (_audio_stream->GetClientObject (_audio_stream->GetSelection ()));
96         while (i != a.end() && lexical_cast<string> (i->id) != s) {
97                 ++i;
98         }
99
100         if (i != a.end ()) {
101                 c->set_audio_stream (*i);
102         }
103
104         if (!c->audio_stream ()) {
105                 _audio_description->SetLabel (wxT (""));
106         } else {
107                 wxString s;
108                 if (c->audio_channels() == 1) {
109                         s << _("1 channel");
110                 } else {
111                         s << c->audio_channels() << wxT (" ") << _("channels");
112                 }
113                 s << wxT (", ") << c->audio_frame_rate() << _("Hz");
114                 _audio_description->SetLabel (s);
115         }
116 }
117
118
119
120 void
121 FFmpegContentDialog::subtitle_stream_changed (wxCommandEvent &)
122 {
123         shared_ptr<FFmpegContent> c = _content.lock ();
124         if (!c) {
125                 return;
126         }
127         
128         vector<FFmpegSubtitleStream> a = c->subtitle_streams ();
129         vector<FFmpegSubtitleStream>::iterator i = a.begin ();
130         string const s = string_client_data (_subtitle_stream->GetClientObject (_subtitle_stream->GetSelection ()));
131         while (i != a.end() && lexical_cast<string> (i->id) != s) {
132                 ++i;
133         }
134
135         if (i != a.end ()) {
136                 c->set_subtitle_stream (*i);
137         }
138 }