]> git.sesse.net Git - vlc/blob - modules/gui/macosx/CoreInteraction.m
macosx: fail the video output if Quartz Extreme isn't supported, removed specific...
[vlc] / modules / gui / macosx / CoreInteraction.m
1 /*****************************************************************************
2  * CoreInteraction.m: MacOS X interface module
3  *****************************************************************************
4  * Copyright (C) 2011 Felix Paul Kühne
5  * $Id$
6  *
7  * Authors: Felix Paul Kühne <fkuehne -at- videolan -dot- org>
8  *
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.
13  *
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.
18  *
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  *****************************************************************************/
23
24 #import "CoreInteraction.h"
25 #import "intf.h"
26 #import "open.h"
27 #import <vlc_playlist.h>
28 #import <vlc_input.h>
29 #import <vlc_keys.h>
30 #import <vlc_osd.h>
31 #import <vlc_aout_intf.h>
32
33 @implementation VLCCoreInteraction
34 static VLCCoreInteraction *_o_sharedInstance = nil;
35
36 + (VLCCoreInteraction *)sharedInstance
37 {
38     return _o_sharedInstance ? _o_sharedInstance : [[self alloc] init];
39 }
40
41 #pragma mark -
42 #pragma mark Initialization
43
44 - (id)init
45 {
46     if( _o_sharedInstance)
47     {
48         [self dealloc];
49         return _o_sharedInstance;
50     }
51     else
52     {
53         _o_sharedInstance = [super init];
54         b_lockAspectRatio = YES;
55     }
56     
57     return _o_sharedInstance;
58 }
59
60 - (void)dealloc
61 {
62     [[NSNotificationCenter defaultCenter] removeObserver: self];
63     [super dealloc];
64 }
65
66 - (void)awakeFromNib
67 {
68     [[NSNotificationCenter defaultCenter] addObserver: self 
69                                              selector: @selector(applicationWillFinishLaunching:)
70                                                  name: NSApplicationWillFinishLaunchingNotification
71                                                object: nil];
72 }
73
74 #pragma mark -
75 #pragma mark Playback Controls
76
77 - (void)play
78 {
79     playlist_t * p_playlist = pl_Get( VLCIntf );
80     bool empty;
81     
82     PL_LOCK;
83     empty = playlist_IsEmpty( p_playlist );
84     PL_UNLOCK;
85     
86     if( empty )
87         [[[VLCMain sharedInstance] open] openFileGeneric];
88     
89     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PLAY_PAUSE );
90 }
91
92 - (void)stop
93 {
94     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_STOP );
95 }
96
97 - (void)faster
98 {
99     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_FASTER );
100 }
101
102 - (void)slower
103 {
104     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_SLOWER );
105 }
106
107 - (void)normalSpeed
108 {
109     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_RATE_NORMAL );
110 }
111
112 - (void)setPlaybackRate:(int)i_value
113 {
114     playlist_t * p_playlist = pl_Get( VLCIntf );
115
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;
121 }
122
123 - (int)playbackRate
124 {
125     playlist_t * p_playlist = pl_Get( VLCIntf );
126
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 );
130
131     if( returnValue < -34 )
132         returnValue = -34;
133     else if( returnValue > 34 )
134         returnValue = 34;
135
136     i_currentPlaybackRate = returnValue;
137     return returnValue;
138 }
139
140 - (void)previous
141 {
142     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_PREV );
143 }
144
145 - (void)next
146 {
147     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
148 }
149
150 - (void)forward
151 {
152     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
153 }
154
155 - (void)backward
156 {
157     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
158 }
159
160 - (void)shuffle
161 {
162     vlc_value_t val;
163     playlist_t * p_playlist = pl_Get( VLCIntf );
164     
165     var_Get( p_playlist, "random", &val );
166     val.b_bool = !val.b_bool;
167     var_Set( p_playlist, "random", val );
168     if( val.b_bool )
169     {
170         //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Random On" ) );
171         config_PutInt( p_playlist, "random", 1 );
172     }
173     else
174     {
175         //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Random Off" ) );
176         config_PutInt( p_playlist, "random", 0 );
177     }
178 }
179
180 - (void)repeatAll
181 {
182     playlist_t * p_playlist = pl_Get( VLCIntf );
183
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 );
188
189     //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat All" ) );
190 }
191
192 - (void)repeatOne
193 {
194     playlist_t * p_playlist = pl_Get( VLCIntf );
195
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 );
200
201     //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat One" ) );
202 }
203
204 - (void)repeatOff
205 {
206     playlist_t * p_playlist = pl_Get( VLCIntf );
207
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 );
212
213     //vout_OSDMessage( VLCIntf, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat Off" ) );
214 }
215
216 // CAVE: [o_main manageVolumeSlider]
217
218 - (void)volumeUp
219 {
220     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_UP );
221 }
222
223 - (void)volumeDown
224 {
225     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
226 }
227
228 - (void)mute
229 {
230     var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
231 }
232
233 - (void)setVolume: (int)i_value
234 {
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;
238     int i_volume_step;
239
240     i_volume_step = config_GetInt( VLCIntf->p_libvlc, "volume-step" );
241     aout_VolumeSet( p_playlist, i_volume * i_volume_step );
242 }
243
244 #pragma mark -
245 #pragma mark video output stuff
246
247 - (void)setAspectRatioLocked:(BOOL)b_value
248 {
249     b_lockAspectRatio = b_value;
250 }
251
252 - (BOOL)aspectRatioIsLocked
253 {
254     return b_lockAspectRatio;
255 }
256
257 - (void)toggleFullscreen
258 {
259     input_thread_t * p_input = pl_CurrentInput( VLCIntf );
260
261     if( p_input != NULL )
262     {
263         playlist_t * p_playlist = pl_Get( VLCIntf );
264         var_ToggleBool( p_playlist, "fullscreen" );
265
266         vlc_object_release( p_input );
267     }
268 }
269 @end