]> git.sesse.net Git - vlc/blob - modules/gui/macosx/TrackSynchronization.m
macosx: remove debug
[vlc] / modules / gui / macosx / TrackSynchronization.m
1 /*****************************************************************************
2  * TrackSynchronization.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011-2012 VLC authors and VideoLAN
5  * Copyright (C) 2011-2012 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
30 @implementation VLCTrackSynchronization
31 static VLCTrackSynchronization *_o_sharedInstance = nil;
32
33 + (VLCTrackSynchronization *)sharedInstance
34 {
35     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
36 }
37
38 - (id)init
39 {
40     if (_o_sharedInstance) {
41         [self dealloc];
42     } else {
43         p_intf = VLCIntf;
44         _o_sharedInstance = [super init];
45     }
46
47     return _o_sharedInstance;
48 }
49
50 - (void)awakeFromNib
51 {
52     [o_window setTitle:_NS("Track Synchronization")];
53     [o_reset_btn setTitle:_NS("Reset")];
54     [o_av_lbl setStringValue:_NS("Audio/Video")];
55     [o_av_advance_lbl setStringValue: _NS("Advance of audio over video:")];
56     [[o_av_value_fld formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("s")]];
57     [o_av_value_fld setToolTip: _NS("A positive value means that the audio is ahead of the video")];
58     [o_sv_lbl setStringValue: _NS("Subtitles/Video")];
59     [o_sv_advance_lbl setStringValue: _NS("Advance of subtitles over video:")];
60     [[o_sv_advance_value_fld formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("s")]];
61     [o_sv_advance_value_fld setToolTip: _NS("A positive value means that the subtitles are ahead of the video" )];
62     [o_sv_speed_lbl setStringValue: _NS("Speed of the subtitles:")];
63     [[o_sv_speed_value_fld formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("fps")]];
64
65     if (OSX_LION)
66         [o_window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
67
68     [self resetValues:self];
69 }
70
71 - (IBAction)toggleWindow:(id)sender
72 {
73     if( [o_window isVisible] )
74         [o_window orderOut:sender];
75     else
76         [o_window makeKeyAndOrderFront:sender];
77 }
78
79 - (IBAction)resetValues:(id)sender
80 {
81     [o_av_value_fld setFloatValue:0.0];
82     [o_sv_advance_value_fld setFloatValue:0.0];
83     [o_sv_speed_value_fld setFloatValue:1.0];
84     [o_av_stp setFloatValue:0.0];
85     [o_sv_advance_stp setFloatValue:0.0];
86     [o_sv_speed_stp setFloatValue:1.0];
87
88     input_thread_t * p_input = pl_CurrentInput( p_intf );
89
90     if( p_input )
91     {
92         var_SetTime( p_input, "audio-delay", 0.0 );
93         var_SetTime( p_input, "spu-delay", 0.0 );
94         var_SetFloat( p_input, "sub-fps", 1.0 );
95         vlc_object_release( p_input );
96     }
97 }
98
99 - (void)updateValues
100 {
101     input_thread_t * p_input = pl_CurrentInput( p_intf );
102
103     if( p_input )
104     {
105         [o_av_value_fld setDoubleValue: var_GetTime( p_input, "audio-delay" ) / 1000000.];
106         [o_sv_advance_value_fld setDoubleValue: var_GetTime( p_input, "spu-delay" ) / 1000000.];
107         [o_sv_speed_value_fld setFloatValue: var_GetFloat( p_input, "sub-fps" )];
108         vlc_object_release( p_input );
109     }
110     [o_av_stp setDoubleValue: [o_av_value_fld doubleValue]];
111     [o_sv_advance_stp setDoubleValue: [o_sv_advance_value_fld doubleValue]];
112     [o_sv_speed_stp setDoubleValue: [o_sv_speed_value_fld doubleValue]];
113 }
114
115 - (IBAction)avValueChanged:(id)sender
116 {
117     if( sender == o_av_minus_btn )
118         [o_av_value_fld setDoubleValue: [o_av_value_fld doubleValue] - 0.5];
119
120     if( sender == o_av_plus_btn )
121         [o_av_value_fld setDoubleValue: [o_av_value_fld doubleValue] + 0.5];
122
123     if( sender == o_av_stp )
124         [o_av_value_fld setDoubleValue: [o_av_stp doubleValue]];
125     else
126         [o_av_stp setDoubleValue: [o_av_value_fld doubleValue]];
127
128     input_thread_t * p_input = pl_CurrentInput( p_intf );
129
130     if( p_input )
131     {
132         var_SetTime( p_input, "audio-delay", [o_av_value_fld doubleValue] * 1000000. );
133
134         vlc_object_release( p_input );
135     }
136 }
137
138 - (IBAction)svAdvanceValueChanged:(id)sender
139 {
140     if( sender == o_sv_advance_minus_btn )
141         [o_sv_advance_value_fld setDoubleValue: [o_sv_advance_value_fld doubleValue] - 0.5];
142
143     if( sender == o_sv_advance_plus_btn )
144         [o_sv_advance_value_fld setDoubleValue: [o_sv_advance_value_fld doubleValue] + 0.5];
145
146     if( sender == o_sv_advance_stp )
147         [o_sv_advance_value_fld setDoubleValue: [o_sv_advance_stp doubleValue]];
148     else
149         [o_sv_advance_stp setDoubleValue: [o_sv_advance_value_fld doubleValue]];
150
151     input_thread_t * p_input = pl_CurrentInput( p_intf );
152
153     if( p_input )
154     {
155         var_SetTime( p_input, "spu-delay", [o_sv_advance_value_fld doubleValue] * 1000000. );
156
157         vlc_object_release( p_input );
158     }
159 }
160
161 - (IBAction)svSpeedValueChanged:(id)sender
162 {
163     if( sender == o_sv_speed_minus_btn )
164         [o_sv_speed_value_fld setFloatValue: [o_sv_speed_value_fld floatValue] - 0.5];
165
166     if( sender == o_sv_speed_plus_btn )
167         [o_sv_speed_value_fld setFloatValue: [o_sv_speed_value_fld floatValue] + 0.5];
168
169     if( sender == o_sv_speed_stp )
170         [o_sv_speed_value_fld setFloatValue: [o_sv_speed_stp floatValue]];
171     else
172         [o_sv_speed_stp setFloatValue: [o_sv_speed_value_fld floatValue]];
173
174     input_thread_t * p_input = pl_CurrentInput( p_intf );
175
176     if( p_input )
177     {
178         var_SetFloat( p_input, "sub-fps", [o_sv_speed_value_fld floatValue] );
179
180         vlc_object_release( p_input );
181     }
182 }
183
184 @end