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