1 /*****************************************************************************
2 * CoreInteraction.m: MacOS X interface module
3 *****************************************************************************
4 * Copyright (C) 2011 Felix Paul Kühne
7 * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 #import "CoreInteraction.h"
27 #import <vlc_playlist.h>
31 #import <vlc_aout_intf.h>
33 @implementation VLCCoreInteraction
34 static VLCCoreInteraction *_o_sharedInstance = nil;
36 + (VLCCoreInteraction *)sharedInstance
38 return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
42 #pragma mark Initialization
46 if( _o_sharedInstance)
49 return _o_sharedInstance;
53 _o_sharedInstance = [super init];
54 b_lockAspectRatio = YES;
57 return _o_sharedInstance;
62 [[NSNotificationCenter defaultCenter] removeObserver: self];
68 [[NSNotificationCenter defaultCenter] addObserver: self
69 selector: @selector(applicationWillFinishLaunching:)
70 name: NSApplicationWillFinishLaunchingNotification
75 #pragma mark Playback Controls
79 playlist_t * p_playlist = pl_Get( VLCIntf );
83 empty = playlist_IsEmpty( p_playlist );
87 [[[VLCMain sharedInstance] open] openFileGeneric];
89 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
94 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_STOP );
99 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_FASTER );
104 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_SLOWER );
109 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_RATE_NORMAL );
112 - (void)setPlaybackRate:(int)i_value
114 playlist_t * p_playlist = pl_Get( VLCIntf );
116 double speed = pow( 2, (double)i_value / 17 );
117 int rate = INPUT_RATE_DEFAULT / speed;
118 if( i_currentPlaybackRate != rate )
119 var_SetFloat( p_playlist, "rate", (float)INPUT_RATE_DEFAULT / (float)rate );
120 i_currentPlaybackRate = rate;
125 playlist_t * p_playlist = pl_Get( VLCIntf );
127 float rate = var_GetFloat( p_playlist, "rate" );
128 double value = 17 * log( rate ) / log( 2. );
129 int returnValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
131 if( returnValue < -34 )
133 else if( returnValue > 34 )
136 i_currentPlaybackRate = returnValue;
142 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
147 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
152 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
157 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
163 playlist_t * p_playlist = pl_Get( VLCIntf );
165 var_Get( p_playlist, "random", &val );
166 val.b_bool = !val.b_bool;
167 var_Set( p_playlist, "random", val );
170 //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Random On" ) );
171 config_PutInt( p_playlist, "random", 1 );
175 //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Random Off" ) );
176 config_PutInt( p_playlist, "random", 0 );
182 playlist_t * p_playlist = pl_Get( VLCIntf );
184 var_SetBool( p_playlist, "repeat", NO );
185 var_SetBool( p_playlist, "loop", YES );
186 config_PutInt( p_playlist, "repeat", NO );
187 config_PutInt( p_playlist, "loop", YES );
189 //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat All" ) );
194 playlist_t * p_playlist = pl_Get( VLCIntf );
196 var_SetBool( p_playlist, "repeat", YES );
197 var_SetBool( p_playlist, "loop", NO );
198 config_PutInt( p_playlist, "repeat", YES );
199 config_PutInt( p_playlist, "loop", NO );
201 //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat One" ) );
206 playlist_t * p_playlist = pl_Get( VLCIntf );
208 var_SetBool( p_playlist, "repeat", NO );
209 var_SetBool( p_playlist, "loop", NO );
210 config_PutInt( p_playlist, "repeat", NO );
211 config_PutInt( p_playlist, "loop", NO );
213 //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat Off" ) );
216 // CAVE: [o_main manageVolumeSlider]
220 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_UP );
225 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
230 var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
233 - (void)setVolume: (int)i_value
235 intf_thread_t * p_intf = VLCIntf;
236 playlist_t * p_playlist = pl_Get( VLCIntf );
237 audio_volume_t i_volume = (audio_volume_t)i_value;
240 i_volume_step = config_GetInt( VLCIntf->p_libvlc, "volume-step" );
241 aout_VolumeSet( p_playlist, i_volume * i_volume_step );
245 #pragma mark video output stuff
247 - (void)setAspectRatioLocked:(BOOL)b_value
249 b_lockAspectRatio = b_value;
252 - (BOOL)aspectRatioIsLocked
254 return b_lockAspectRatio;
257 - (void)toggleFullscreen
259 input_thread_t * p_input = pl_CurrentInput( VLCIntf );
261 if( p_input != NULL )
263 playlist_t * p_playlist = pl_Get( VLCIntf );
264 var_ToggleBool( p_playlist, "fullscreen" );
266 vlc_object_release( p_input );