VLCTrackSynchronizationWindowController.m 7.67 KB
Newer Older
1
/*****************************************************************************
2
 * VLCTrackSynchronizationWindowController.m: MacOS X interface module
3
 *****************************************************************************
4
 * Copyright (C) 2011-2014 VLC authors and VideoLAN
5
 * Copyright (C) 2011-2015 Felix Paul Kühne
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
 * $Id$
 *
 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

25
#import "CompatibilityFixes.h"
26
#import "VLCMain.h"
27
#import <vlc_common.h>
28
#import "VLCTrackSynchronizationWindowController.h"
29
#import "VLCCoreInteraction.h"
30

31 32 33 34 35 36
#define SUBSDELAY_CFG_MODE                     "subsdelay-mode"
#define SUBSDELAY_CFG_FACTOR                   "subsdelay-factor"
#define SUBSDELAY_MODE_ABSOLUTE                0
#define SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY   1
#define SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT 2

37
@implementation VLCTrackSynchronizationWindowController
38

39
- (id)init
40
{
41
    self = [super initWithWindowNibName:@"SyncTracks"];
42

43
    return self;
44 45
}

46
- (void)windowDidLoad
47
{
48
    [self.window setTitle:_NS("Track Synchronization")];
49 50 51 52 53 54 55 56 57 58 59 60 61
    [_resetButton setTitle:_NS("Reset")];
    [_avLabel setStringValue:_NS("Audio/Video")];
    [_av_advanceLabel setStringValue: _NS("Audio track synchronization:")];
    [[_av_advanceTextField formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("s")]];
    [_av_advanceTextField setToolTip: _NS("A positive value means that the audio is ahead of the video")];
    [_svLabel setStringValue: _NS("Subtitles/Video")];
    [_sv_advanceLabel setStringValue: _NS("Subtitle track synchronization:")];
    [[_sv_advanceTextField formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("s")]];
    [_sv_advanceTextField setToolTip: _NS("A positive value means that the subtitles are ahead of the video")];
    [_sv_speedLabel setStringValue: _NS("Subtitle speed:")];
    [[_sv_speedTextField formatter] setFormat:[NSString stringWithFormat:@"#,##0.000 %@", _NS("fps")]];
    [_sv_durLabel setStringValue: _NS("Subtitle duration factor:")];

62
    int i_mode = var_InheritInteger(getIntf(), SUBSDELAY_CFG_MODE);
63 64
    NSString * o_toolTip, * o_suffix;

65
    switch (i_mode) {
66 67
        default:
        case SUBSDELAY_MODE_ABSOLUTE:
68
            o_toolTip = _NS("Extend subtitle duration by this value.\nSet 0 to disable.");
69 70 71
            o_suffix = @" s";
            break;
        case SUBSDELAY_MODE_RELATIVE_SOURCE_DELAY:
72
            o_toolTip = _NS("Multiply subtitle duration by this value.\nSet 0 to disable.");
73 74 75
            o_suffix = @"";
            break;
        case SUBSDELAY_MODE_RELATIVE_SOURCE_CONTENT:
76
            o_toolTip = _NS("Recalculate subtitle duration according\nto their content and this value.\nSet 0 to disable.");
77 78 79 80
            o_suffix = @"";
            break;
    }

81 82
    [[_sv_durTextField formatter] setFormat:[NSString stringWithFormat:@"#,##0.000%@", o_suffix]];
    [_sv_durTextField setToolTip: o_toolTip];
83

84
    [self.window setCollectionBehavior: NSWindowCollectionBehaviorFullScreenAuxiliary];
85

86 87 88
    [self resetValues:self];
}

89 90
- (void)updateCocoaWindowLevel:(NSInteger)i_level
{
91
    if (self.isWindowLoaded && [self.window isVisible] && [self.window level] != i_level)
92
        [self.window setLevel: i_level];
93 94
}

95 96
- (IBAction)toggleWindow:(id)sender
{
97 98
    if ([self.window isVisible])
        [self.window orderOut:sender];
99
    else {
100 101 102 103
        [self.window setLevel: [[[VLCMain sharedInstance] voutController] currentStatusWindowLevel]];
        [self.window makeKeyAndOrderFront:sender];

        [self updateValues];
104
    }
105 106 107 108
}

- (IBAction)resetValues:(id)sender
{
109 110 111 112 113 114 115 116
    [_av_advanceTextField setFloatValue:0.0];
    [_sv_advanceTextField setFloatValue:0.0];
    [_sv_speedTextField setFloatValue:1.0];
    [_sv_durTextField setFloatValue:0.0];
    [_avStepper setFloatValue:0.0];
    [_sv_advanceStepper setFloatValue:0.0];
    [_sv_speedStepper setFloatValue:1.0];
    [_sv_durStepper setFloatValue:0.0];
117

118
    input_thread_t * p_input = pl_CurrentInput(getIntf());
119

120
    if (p_input) {
121 122
        var_SetInteger(p_input, "audio-delay", 0.0);
        var_SetInteger(p_input, "spu-delay", 0.0);
123
        var_SetFloat(p_input, "sub-fps", 1.0);
124
        [self svDurationValueChanged:nil];
125
        vlc_object_release(p_input);
126 127 128
    }
}

129 130
- (void)updateValues
{
131
    input_thread_t * p_input = pl_CurrentInput(getIntf());
132 133

    if (p_input) {
134 135 136
        [_av_advanceTextField setDoubleValue: var_GetInteger(p_input, "audio-delay") / 1000000.];
        [_sv_advanceTextField setDoubleValue: var_GetInteger(p_input, "spu-delay") / 1000000.];
        [_sv_speedTextField setFloatValue: var_GetFloat(p_input, "sub-fps")];
137
        vlc_object_release(p_input);
138
    }
139 140 141
    [_avStepper setDoubleValue: [_av_advanceTextField doubleValue]];
    [_sv_advanceStepper setDoubleValue: [_sv_advanceTextField doubleValue]];
    [_sv_speedStepper setDoubleValue: [_sv_speedTextField doubleValue]];
142 143
}

144 145
- (IBAction)avValueChanged:(id)sender
{
146 147
    if (sender == _avStepper)
        [_av_advanceTextField setDoubleValue: [_avStepper doubleValue]];
148
    else
149
        [_avStepper setDoubleValue: [_av_advanceTextField doubleValue]];
150

151
    input_thread_t * p_input = pl_CurrentInput(getIntf());
152

153
    if (p_input) {
154
        var_SetInteger(p_input, "audio-delay", [_av_advanceTextField doubleValue] * 1000000.);
155
        vlc_object_release(p_input);
156 157 158 159 160
    }
}

- (IBAction)svAdvanceValueChanged:(id)sender
{
161 162
    if (sender == _sv_advanceStepper)
        [_sv_advanceTextField setDoubleValue: [_sv_advanceStepper doubleValue]];
163
    else
164
        [_sv_advanceStepper setDoubleValue: [_sv_advanceTextField doubleValue]];
165

166
    input_thread_t * p_input = pl_CurrentInput(getIntf());
167

168
    if (p_input) {
169
        var_SetInteger(p_input, "spu-delay", [_sv_advanceTextField doubleValue] * 1000000.);
170
        vlc_object_release(p_input);
171 172 173 174 175
    }
}

- (IBAction)svSpeedValueChanged:(id)sender
{
176 177
    if (sender == _sv_speedStepper)
        [_sv_speedTextField setFloatValue: [_sv_speedStepper floatValue]];
178
    else
179
        [_sv_speedStepper setFloatValue: [_sv_speedTextField floatValue]];
180

181
    input_thread_t * p_input = pl_CurrentInput(getIntf());
182

183
    if (p_input) {
184
        var_SetFloat(p_input, "sub-fps", [_sv_speedTextField floatValue]);
185
        vlc_object_release(p_input);
186 187 188
    }
}

189 190
- (IBAction)svDurationValueChanged:(id)sender
{
191 192
    if (sender == _sv_durStepper)
        [_sv_durTextField setFloatValue: [_sv_durStepper floatValue]];
193
    else
194
        [_sv_durStepper setFloatValue: [_sv_durTextField floatValue]];
195

196
    input_thread_t * p_input = pl_CurrentInput(getIntf());
197

198
    if (p_input) {
199
        float f_factor = [_sv_durTextField floatValue];
200
        NSArray<NSValue *> *vouts = getVouts();
201

202 203 204 205 206 207 208
        if (vouts)
            for (NSValue *ptr in vouts) {
                vout_thread_t *p_vout = [ptr pointerValue];

                var_SetFloat(p_vout, SUBSDELAY_CFG_FACTOR, f_factor);
                vlc_object_release(p_vout);
            }
209
        [[VLCCoreInteraction sharedInstance] setVideoFilter: "subsdelay" on: f_factor > 0];
210

211
        vlc_object_release(p_input);
212 213 214
    }
}

215
@end