]> git.sesse.net Git - vlc/blob - modules/gui/macosx/TrackSynchronization.m
macosx: slightly de-uglify the VLC description in the about dialog by rendering it...
[vlc] / modules / gui / macosx / TrackSynchronization.m
1 /*****************************************************************************
2  * TrackSynchronization.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011-2014 VLC authors and VideoLAN
5  * Copyright (C) 2011-2014 Felix Paul Kühne
6  * $Id$
7  *
8  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #import "CompatibilityFixes.h"
26 #import "intf.h"
27 #import <vlc_common.h>
28 #import "TrackSynchronization.h"
29 #import "CoreInteraction.h"
30
31 #define SUBSDELAY_CFG_MODE                     "subsdelay-mode"
32 #define SUBSDELAY_CFG_FACTOR                   "subsdelay-factor"
33 #define SUBSDELAY_MODE_ABSOLUTE                0
34 #define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY   1
35 #define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2
36
37 @implementation VLCTrackSynchronization
38 static VLCTrackSynchronization *_o_sharedInstance = nil;
39
40 + (VLCTrackSynchronization *)sharedInstance
41 {
42     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
43 }
44
45 - (id)init
46 {
47     if (_o_sharedInstance)
48         [self dealloc];
49     else {
50         p_intf = VLCIntf;
51         _o_sharedInstance = [super init];
52     }
53
54     return _o_sharedInstance;
55 }
56
57 - (void)awakeFromNib
58 {
59     [o_window setTitle:_NS("Track Synchronization")];
60     [o_reset_btn setTitle:_NS("Reset")];
61     [o_av_lbl setStringValue:_NS("Audio/Video")];
62     [o_av_advance_lbl setStringValue: _NS("Audio track synchronization:")];
63     [[o_av_value_fld formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("s")]];
64     [o_av_value_fld setToolTip: _NS("A positive value means that the audio is ahead of the video")];
65     [o_sv_lbl setStringValue: _NS("Subtitles/Video")];
66     [o_sv_advance_lbl setStringValue: _NS("Subtitle track synchronization:")];
67     [[o_sv_advance_value_fld formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("s")]];
68     [o_sv_advance_value_fld setToolTip: _NS("A positive value means that the subtitles are ahead of the video")];
69     [o_sv_speed_lbl setStringValue: _NS("Subtitle speed:")];
70     [[o_sv_speed_value_fld formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("fps")]];
71     [o_sv_dur_lbl setStringValue: _NS("Subtitle duration factor:")];
72
73     int i_mode = var_InheritInteger(p_intf, SUBSDELAY_CFG_MODE);
74     NSString * o_toolTip, * o_suffix;
75
76     switch (i_mode) {
77         default:
78         case SUBSDELAY_MODE_ABSOLUTE:
79             o_toolTip = _NS("Extend subtitle duration by this value.\nSet 0 to disable.");
80             o_suffix = @" s";
81             break;
82         case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
83             o_toolTip = _NS("Multiply subtitle duration by this value.\nSet 0 to disable.");
84             o_suffix = @"";
85             break;
86         case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
87             o_toolTip = _NS("Recalculate subtitle duration according\nto their content and this value.\nSet 0 to disable.");
88             o_suffix = @"";
89             break;
90     }
91
92     [[o_sv_dur_value_fld formatter] setFormat:[NSString stringWithFormat:@"#,##0.000%@", o_suffix]];
93     [o_sv_dur_value_fld setToolTip: o_toolTip];
94
95     if (!OSX_SNOW_LEOPARD)
96         [o_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
97
98     [self resetValues:self];
99 }
100
101 - (void)updateCocoaWindowLevel:(NSInteger)i_level
102 {
103     if (o_window && [o_window isVisible] && [o_window level] != i_level)
104         [o_window setLevel: i_level];
105 }
106
107 - (IBAction)toggleWindow:(id)sender
108 {
109     if ([o_window isVisible])
110         [o_window orderOut:sender];
111     else {
112         [o_window setLevel: [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel]];
113         [o_window makeKeyAndOrderFront:sender];
114     }
115 }
116
117 - (IBAction)resetValues:(id)sender
118 {
119     [o_av_value_fld setFloatValue:0.0];
120     [o_sv_advance_value_fld setFloatValue:0.0];
121     [o_sv_speed_value_fld setFloatValue:1.0];
122     [o_sv_dur_value_fld setFloatValue:0.0];
123     [o_av_stp setFloatValue:0.0];
124     [o_sv_advance_stp setFloatValue:0.0];
125     [o_sv_speed_stp setFloatValue:1.0];
126     [o_sv_dur_stp setFloatValue:0.0];
127
128     input_thread_t * p_input = pl_CurrentInput(p_intf);
129
130     if (p_input) {
131         var_SetTime(p_input, "audio-delay", 0.0);
132         var_SetTime(p_input, "spu-delay", 0.0);
133         var_SetFloat(p_input, "sub-fps", 1.0);
134         [self svDurationValueChanged:nil];
135         vlc_object_release(p_input);
136     }
137 }
138
139 - (void)updateValues
140 {
141     input_thread_t * p_input = pl_CurrentInput(p_intf);
142
143     if (p_input) {
144         [o_av_value_fld setDoubleValue: var_GetTime(p_input, "audio-delay") / 1000000.];
145         [o_sv_advance_value_fld setDoubleValue: var_GetTime(p_input, "spu-delay") / 1000000.];
146         [o_sv_speed_value_fld setFloatValue: var_GetFloat(p_input, "sub-fps")];
147         vlc_object_release(p_input);
148     }
149     [o_av_stp setDoubleValue: [o_av_value_fld doubleValue]];
150     [o_sv_advance_stp setDoubleValue: [o_sv_advance_value_fld doubleValue]];
151     [o_sv_speed_stp setDoubleValue: [o_sv_speed_value_fld doubleValue]];
152 }
153
154 - (IBAction)avValueChanged:(id)sender
155 {
156     if (sender == o_av_stp)
157         [o_av_value_fld setDoubleValue: [o_av_stp doubleValue]];
158     else
159         [o_av_stp setDoubleValue: [o_av_value_fld doubleValue]];
160
161     input_thread_t * p_input = pl_CurrentInput(p_intf);
162
163     if (p_input) {
164         var_SetTime(p_input, "audio-delay", [o_av_value_fld doubleValue] * 1000000.);
165
166         vlc_object_release(p_input);
167     }
168 }
169
170 - (IBAction)svAdvanceValueChanged:(id)sender
171 {
172     if (sender == o_sv_advance_stp)
173         [o_sv_advance_value_fld setDoubleValue: [o_sv_advance_stp doubleValue]];
174     else
175         [o_sv_advance_stp setDoubleValue: [o_sv_advance_value_fld doubleValue]];
176
177     input_thread_t * p_input = pl_CurrentInput(p_intf);
178
179     if (p_input) {
180         var_SetTime(p_input, "spu-delay", [o_sv_advance_value_fld doubleValue] * 1000000.);
181
182         vlc_object_release(p_input);
183     }
184 }
185
186 - (IBAction)svSpeedValueChanged:(id)sender
187 {
188     if (sender == o_sv_speed_stp)
189         [o_sv_speed_value_fld setFloatValue: [o_sv_speed_stp floatValue]];
190     else
191         [o_sv_speed_stp setFloatValue: [o_sv_speed_value_fld floatValue]];
192
193     input_thread_t * p_input = pl_CurrentInput(p_intf);
194
195     if (p_input) {
196         var_SetFloat(p_input, "sub-fps", [o_sv_speed_value_fld floatValue]);
197
198         vlc_object_release(p_input);
199     }
200 }
201
202 - (IBAction)svDurationValueChanged:(id)sender
203 {
204     if (sender == o_sv_dur_stp)
205         [o_sv_dur_value_fld setFloatValue: [o_sv_dur_stp floatValue]];
206     else
207         [o_sv_dur_stp setFloatValue: [o_sv_dur_value_fld floatValue]];
208
209     input_thread_t * p_input = pl_CurrentInput(p_intf);
210
211     if (p_input) {
212         float f_factor = [o_sv_dur_value_fld floatValue];
213         config_PutFloat(p_intf, SUBSDELAY_CFG_FACTOR, f_factor);
214
215         /* Try to find an instance of subsdelay, and set its factor */
216         vlc_object_t *p_obj = (vlc_object_t *) vlc_object_find_name(p_intf->p_libvlc, "subsdelay");
217         if (p_obj) {
218             var_SetFloat(p_obj, SUBSDELAY_CFG_FACTOR, f_factor);
219             vlc_object_release(p_obj);
220         }
221         [[VLCCoreInteraction sharedInstance] setVideoFilter: "subsdelay" on: f_factor > 0];
222
223         vlc_object_release(p_input);
224     }
225 }
226
227 @end