Commit ff8183c0 authored by Jan Winter's avatar Jan Winter Committed by Felix Paul Kühne

OS X AppleScript: added new features

Signed-off-by: default avatarFelix Paul Kühne <fkuehne@videolan.org>
parent 0333f05e
...@@ -41,8 +41,22 @@ ...@@ -41,8 +41,22 @@
- (int)playbackRate; - (int)playbackRate;
- (void)next; - (void)next;
- (void)previous; - (void)previous;
- (void)forward; - (BOOL)isPlaying;
- (void)backward; - (int)currentTime;
- (void)setCurrentTime:(int)i_value;
- (int)durationOfCurrentPlaylistItem;
- (NSURL*)URLOfCurrentPlaylistItem;
- (NSString*)nameOfCurrentPlaylistItem;
- (void)forward; //LEGACY SUPPORT
- (void)backward; //LEGACY SUPPORT
- (void)forwardExtraShort;
- (void)backwardExtraShort;
- (void)forwardShort;
- (void)backwardShort;
- (void)forwardMedium;
- (void)backwardMedium;
- (void)forwardLong;
- (void)backwardLong;
- (void)repeatOne; - (void)repeatOne;
- (void)repeatAll; - (void)repeatAll;
...@@ -52,7 +66,9 @@ ...@@ -52,7 +66,9 @@
- (void)volumeUp; - (void)volumeUp;
- (void)volumeDown; - (void)volumeDown;
- (void)mute; - (void)mute;
- (void)setVolume: (int)i_value; - (BOOL)isMuted;
- (int)volume;
- (void)setVolume:(int)i_value;
- (void)setAspectRatioLocked:(BOOL)b_value; - (void)setAspectRatioLocked:(BOOL)b_value;
- (BOOL)aspectRatioIsLocked; - (BOOL)aspectRatioIsLocked;
......
...@@ -29,6 +29,8 @@ ...@@ -29,6 +29,8 @@
#import <vlc_keys.h> #import <vlc_keys.h>
#import <vlc_osd.h> #import <vlc_osd.h>
#import <vlc_aout_intf.h> #import <vlc_aout_intf.h>
#import <vlc/vlc.h>
#import <vlc_strings.h>
@implementation VLCCoreInteraction @implementation VLCCoreInteraction
static VLCCoreInteraction *_o_sharedInstance = nil; static VLCCoreInteraction *_o_sharedInstance = nil;
...@@ -123,7 +125,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -123,7 +125,7 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
- (void)setPlaybackRate:(int)i_value - (void)setPlaybackRate:(int)i_value
{ {
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
double speed = pow( 2, (double)i_value / 17 ); double speed = pow( 2, (double)i_value / 17 );
int rate = INPUT_RATE_DEFAULT / speed; int rate = INPUT_RATE_DEFAULT / speed;
if( i_currentPlaybackRate != rate ) if( i_currentPlaybackRate != rate )
...@@ -134,16 +136,16 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -134,16 +136,16 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
- (int)playbackRate - (int)playbackRate
{ {
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
float rate = var_GetFloat( p_playlist, "rate" ); float rate = var_GetFloat( p_playlist, "rate" );
double value = 17 * log( rate ) / log( 2. ); double value = 17 * log( rate ) / log( 2. );
int returnValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 ); int returnValue = (int) ( ( value > 0 ) ? value + .5 : value - .5 );
if( returnValue < -34 ) if( returnValue < -34 )
returnValue = -34; returnValue = -34;
else if( returnValue > 34 ) else if( returnValue > 34 )
returnValue = 34; returnValue = 34;
i_currentPlaybackRate = returnValue; i_currentPlaybackRate = returnValue;
return returnValue; return returnValue;
} }
...@@ -158,120 +160,277 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -158,120 +160,277 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT ); var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_NEXT );
} }
- (BOOL)isPlaying
{
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if (!p_input) return NO;
input_state_e i_state = ERROR_S;
input_Control( p_input, INPUT_GET_STATE, &i_state);
vlc_object_release( p_input );
return ((i_state == OPENING_S) || (i_state == PLAYING_S));
}
- (int)currentTime
{
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
int64_t i_currentTime = -1;
if (!p_input) return i_currentTime;
input_Control( p_input, INPUT_GET_TIME, &i_currentTime);
vlc_object_release( p_input );
return (int)( i_currentTime / 1000000 );
}
- (void)setCurrentTime:(int)i_value
{
int64_t i64_value = (int64_t)i_value;
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
if (!p_input) return;
input_Control( p_input, INPUT_SET_TIME, (int64_t)(i64_value * 1000000));
vlc_object_release( p_input );
}
- (int)durationOfCurrentPlaylistItem
{
input_thread_t * p_input = pl_CurrentInput( VLCIntf );
int64_t i_duration = -1;
if (!p_input) return i_duration;
input_Control( p_input, INPUT_GET_LENGTH, &i_duration);
vlc_object_release( p_input );
return (int)(i_duration / 1000000);
}
- (NSURL*)URLOfCurrentPlaylistItem
{
input_thread_t *p_input = pl_CurrentInput( VLCIntf );
if (!p_input) return nil;
input_item_t *p_item = input_GetItem( p_input );
if (!p_item) return nil;
char *psz_uri = input_item_GetURI( p_item );
if (!psz_uri) return nil;
NSURL *o_url;
o_url = [NSURL URLWithString:[NSString stringWithUTF8String:psz_uri]];
return o_url;
}
- (NSString*)nameOfCurrentPlaylistItem
{
input_thread_t *p_input = pl_CurrentInput( VLCIntf );
if (!p_input) return nil;
input_item_t *p_item = input_GetItem( p_input );
if (!p_item) return nil;
char *psz_uri = input_item_GetURI( p_item );
if (!psz_uri) return nil;
NSString *o_name;
char *format = var_InheritString( VLCIntf, "input-title-format" );
char *formated = str_format_meta( p_input, format );
free( format );
o_name = [NSString stringWithUTF8String:formated];
free( formated );
NSURL * o_url = [NSURL URLWithString: [NSString stringWithUTF8String: psz_uri]];
free( psz_uri );
if ([o_name isEqualToString:@""])
{
if ([o_url isFileURL])
o_name = [[NSFileManager defaultManager] displayNameAtPath: [o_url path]];
else
o_name = [o_url absoluteString];
}
return o_name;
}
- (void)forward - (void)forward
{ {
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT ); //LEGACY SUPPORT
[self forwardShort];
} }
- (void)backward - (void)backward
{ {
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT ); //LEGACY SUPPORT
[self backwardShort];
} }
- (void)shuffle - (void)forwardExtraShort
{ {
vlc_value_t val; var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_EXTRASHORT );
playlist_t * p_playlist = pl_Get( VLCIntf ); }
vout_thread_t *p_vout = getVout();
var_Get( p_playlist, "random", &val ); - (void)backwardExtraShort
val.b_bool = !val.b_bool; {
var_Set( p_playlist, "random", val ); var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_EXTRASHORT );
if( val.b_bool ) }
{
if (p_vout) - (void)forwardShort
{
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_SHORT );
}
- (void)backwardShort
{
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_SHORT );
}
- (void)forwardMedium
{
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_MEDIUM );
}
- (void)backwardMedium
{
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_MEDIUM );
}
- (void)forwardLong
{
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_FORWARD_LONG );
}
- (void)backwardLong
{
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_JUMP_BACKWARD_LONG );
}
- (void)shuffle
{
vlc_value_t val;
playlist_t * p_playlist = pl_Get( VLCIntf );
vout_thread_t *p_vout = getVout();
var_Get( p_playlist, "random", &val );
val.b_bool = !val.b_bool;
var_Set( p_playlist, "random", val );
if( val.b_bool )
{ {
vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Random On" ) ); if (p_vout)
vlc_object_release( p_vout ); {
vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Random On" ) );
vlc_object_release( p_vout );
}
config_PutInt( p_playlist, "random", 1 );
} }
config_PutInt( p_playlist, "random", 1 ); else
}
else
{
if (p_vout)
{ {
vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Random Off" ) ); if (p_vout)
vlc_object_release( p_vout ); {
vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Random Off" ) );
vlc_object_release( p_vout );
}
config_PutInt( p_playlist, "random", 0 );
} }
config_PutInt( p_playlist, "random", 0 );
}
} }
- (void)repeatAll - (void)repeatAll
{ {
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
var_SetBool( p_playlist, "repeat", NO ); var_SetBool( p_playlist, "repeat", NO );
var_SetBool( p_playlist, "loop", YES ); var_SetBool( p_playlist, "loop", YES );
config_PutInt( p_playlist, "repeat", NO ); config_PutInt( p_playlist, "repeat", NO );
config_PutInt( p_playlist, "loop", YES ); config_PutInt( p_playlist, "loop", YES );
vout_thread_t *p_vout = getVout(); vout_thread_t *p_vout = getVout();
if (p_vout) if (p_vout)
{ {
vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat All" ) ); vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat All" ) );
vlc_object_release( p_vout ); vlc_object_release( p_vout );
} }
} }
- (void)repeatOne - (void)repeatOne
{ {
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
var_SetBool( p_playlist, "repeat", YES ); var_SetBool( p_playlist, "repeat", YES );
var_SetBool( p_playlist, "loop", NO ); var_SetBool( p_playlist, "loop", NO );
config_PutInt( p_playlist, "repeat", YES ); config_PutInt( p_playlist, "repeat", YES );
config_PutInt( p_playlist, "loop", NO ); config_PutInt( p_playlist, "loop", NO );
vout_thread_t *p_vout = getVout(); vout_thread_t *p_vout = getVout();
if (p_vout) if (p_vout)
{ {
vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat One" ) ); vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat One" ) );
vlc_object_release( p_vout ); vlc_object_release( p_vout );
} }
} }
- (void)repeatOff - (void)repeatOff
{ {
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
var_SetBool( p_playlist, "repeat", NO ); var_SetBool( p_playlist, "repeat", NO );
var_SetBool( p_playlist, "loop", NO ); var_SetBool( p_playlist, "loop", NO );
config_PutInt( p_playlist, "repeat", NO ); config_PutInt( p_playlist, "repeat", NO );
config_PutInt( p_playlist, "loop", NO ); config_PutInt( p_playlist, "loop", NO );
vout_thread_t *p_vout = getVout(); vout_thread_t *p_vout = getVout();
if (p_vout) if (p_vout)
{ {
vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat Off" ) ); vout_OSDMessage( p_vout, SPU_DEFAULT_CHANNEL, "%s", _( "Repeat Off" ) );
vlc_object_release( p_vout ); vlc_object_release( p_vout );
} }
} }
- (void)volumeUp - (void)volumeUp
{ {
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_UP ); var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_UP );
} }
- (void)volumeDown - (void)volumeDown
{ {
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_DOWN ); var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_DOWN );
} }
- (void)mute - (void)mute
{ {
var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_MUTE ); var_SetInteger( VLCIntf->p_libvlc, "key-action", ACTIONID_VOL_MUTE );
} }
- (void)setVolume: (int)i_value - (BOOL)isMuted
{
playlist_t * p_playlist = pl_Get( VLCIntf );
BOOL b_is_muted = NO;
b_is_muted = aout_IsMuted( VLC_OBJECT(p_playlist) );
return b_is_muted;
}
- (int)volume
{ {
intf_thread_t * p_intf = VLCIntf; intf_thread_t * p_intf = VLCIntf;
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
audio_volume_t i_volume = (audio_volume_t)i_value; audio_volume_t i_volume = aout_VolumeGet( p_playlist );
int i_volume_step;
return (int)i_volume;
}
i_volume_step = config_GetInt( VLCIntf->p_libvlc, "volume-step" ); - (void)setVolume: (int)i_value
aout_VolumeSet( p_playlist, i_volume * i_volume_step ); {
intf_thread_t * p_intf = VLCIntf;
playlist_t * p_playlist = pl_Get( VLCIntf );
audio_volume_t i_volume = (audio_volume_t)i_value;
int i_volume_step;
i_volume_step = config_GetInt( VLCIntf->p_libvlc, "volume-step" );
aout_VolumeSet( p_playlist, i_volume * i_volume_step );
} }
#pragma mark - #pragma mark -
...@@ -279,17 +438,18 @@ static VLCCoreInteraction *_o_sharedInstance = nil; ...@@ -279,17 +438,18 @@ static VLCCoreInteraction *_o_sharedInstance = nil;
- (void)setAspectRatioLocked:(BOOL)b_value - (void)setAspectRatioLocked:(BOOL)b_value
{ {
b_lockAspectRatio = b_value; b_lockAspectRatio = b_value;
} }
- (BOOL)aspectRatioIsLocked - (BOOL)aspectRatioIsLocked
{ {
return b_lockAspectRatio; return b_lockAspectRatio;
} }
- (void)toggleFullscreen - (void)toggleFullscreen
{ {
playlist_t * p_playlist = pl_Get( VLCIntf ); playlist_t * p_playlist = pl_Get( VLCIntf );
var_ToggleBool( p_playlist, "fullscreen" ); var_ToggleBool( p_playlist, "fullscreen" );
} }
@end @end
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/ *****************************************************************************/
#import <Cocoa/Cocoa.h>
/***************************************************************************** /*****************************************************************************
* VLGetURLScriptCommand interface * VLGetURLScriptCommand interface
*****************************************************************************/ *****************************************************************************/
...@@ -40,4 +42,15 @@ ...@@ -40,4 +42,15 @@
- (BOOL)scriptFullscreenMode; - (BOOL)scriptFullscreenMode;
- (void)setScriptFullscreenMode: (BOOL)mode; - (void)setScriptFullscreenMode: (BOOL)mode;
- (double)audioVolume;
- (void)setAudioVolume: (double)mode;
- (int)currentTime;
- (void)setCurrentTime: (int)mode;
- (int) durationOfCurrentItem;
- (NSString*) pathOfCurrentItem;
- (NSString*) nameOfCurrentItem;
@end @end
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "intf.h" #include "intf.h"
#include "applescript.h" #include "applescript.h"
#include "CoreInteraction.h" #include "CoreInteraction.h"
#include "vlc_aout_intf.h"
/***************************************************************************** /*****************************************************************************
* VLGetURLScriptCommand implementation * VLGetURLScriptCommand implementation
...@@ -85,7 +86,8 @@ ...@@ -85,7 +86,8 @@
- (id)performDefaultImplementation { - (id)performDefaultImplementation {
NSString *o_command = [[self commandDescription] commandName]; NSString *o_command = [[self commandDescription] commandName];
NSString *o_parameter = [self directParameter];
intf_thread_t * p_intf = VLCIntf; intf_thread_t * p_intf = VLCIntf;
playlist_t * p_playlist = pl_Get( p_intf ); playlist_t * p_playlist = pl_Get( p_intf );
if( p_playlist == NULL ) if( p_playlist == NULL )
...@@ -125,7 +127,67 @@ ...@@ -125,7 +127,67 @@
{ {
[[VLCCoreInteraction sharedInstance] volumeDown]; [[VLCCoreInteraction sharedInstance] volumeDown];
} }
return nil; else if ( [o_command isEqualToString:@"stepForward"] )
{
//default: forwardShort
if (o_parameter)
{
int i_parameter = [o_parameter intValue];
switch (i_parameter)
{
case 1:
[[VLCCoreInteraction sharedInstance] forwardExtraShort];
break;
case 2:
[[VLCCoreInteraction sharedInstance] forwardShort];
break;
case 3:
[[VLCCoreInteraction sharedInstance] forwardMedium];
break;
case 4:
[[VLCCoreInteraction sharedInstance] forwardLong];
break;
default:
[[VLCCoreInteraction sharedInstance] forwardShort];
break;
}
}
else
{
[[VLCCoreInteraction sharedInstance] forwardShort];
}
}
else if ( [o_command isEqualToString:@"stepBackward"] )
{
//default: backwardShort
if (o_parameter)
{
int i_parameter = [o_parameter intValue];
switch (i_parameter)
{
case 1:
[[VLCCoreInteraction sharedInstance] backwardExtraShort];
break;
case 2:
[[VLCCoreInteraction sharedInstance] backwardShort];
break;
case 3:
[[VLCCoreInteraction sharedInstance] backwardMedium];
break;
case 4:
[[VLCCoreInteraction sharedInstance] backwardLong];
break;
default:
[[VLCCoreInteraction sharedInstance] backwardShort];
break;
}
}
else
{
[[VLCCoreInteraction sharedInstance] backwardShort];
}
}
return nil;
} }
@end @end
...@@ -156,4 +218,59 @@ ...@@ -156,4 +218,59 @@
[[VLCCoreInteraction sharedInstance] toggleFullscreen]; [[VLCCoreInteraction sharedInstance] toggleFullscreen];
} }
- (BOOL) muted {
return [[VLCCoreInteraction sharedInstance] isMuted];
}
- (BOOL) playing {
return [[VLCCoreInteraction sharedInstance] isPlaying];
}
- (double) audioVolume {
return ( (double)[[VLCCoreInteraction sharedInstance] volume] / (double)AOUT_VOLUME_DEFAULT );
}
- (void) setAudioVolume: (double) d_audioVolume {
//1 = 100%, 4 = 400%; 0 <= d_audioVolume <= 4
//0-1024 (but AOUT_VOLUME_MAX == 512)???
//AOUT_VOLUME_DEFAULT = 256 = 100%
//somehow [[VLCCoreInteraction sharedInstance] setVolume:i_parameter] has 0-32 steps with 32 as stepWidth (0 - 1024)
if (d_audioVolume < 0)
d_audioVolume = 0;
if (d_audioVolume > 4)
d_audioVolume = 4;
intf_thread_t * p_intf = VLCIntf;
playlist_t * p_playlist = pl_Get( VLCIntf );
int i_volume_step = config_GetInt( VLCIntf->p_libvlc, "volume-step" );
int i_parameter = (int) ( d_audioVolume * i_volume_step / 4 );
[[VLCCoreInteraction sharedInstance] setVolume:i_parameter];
}
- (int) currentTime {
return [[VLCCoreInteraction sharedInstance] currentTime];
}
- (void) setCurrentTime: (int) i_currentTime {
if (i_currentTime) {
[[VLCCoreInteraction sharedInstance] setCurrentTime:i_currentTime];
}
}
#pragma mark -
//TODO:whenever VLC should implement NSDocument, the methods below should move or be additionaly implemented in the NSDocument category
- (int) durationOfCurrentItem {
return [[VLCCoreInteraction sharedInstance] durationOfCurrentPlaylistItem];
}
- (NSString*) pathOfCurrentItem {
return [[[VLCCoreInteraction sharedInstance] URLOfCurrentPlaylistItem] path];
}
- (NSString*) nameOfCurrentItem {
return [[VLCCoreInteraction sharedInstance] nameOfCurrentPlaylistItem];
}
@end @end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment