<commit_before>'use strict';

angular.module('spotmop.player', [
	'spotmop.services.spotify',
	'spotmop.services.mopidy'
])

.controller('PlayerController', function PlayerController( $scope, $rootScope, $timeout, $interval, MopidyService, SpotifyService ){
	
	// setup template containers
	$scope.muted = false;
	$scope.playing = false;
	$scope.isRepeat = false;
	$scope.isRandom = false;
	$scope.isMute = false;
	$scope.volume = 100;
	$scope.playPosition = 0;
	$scope.playPositionPercent = function(){
		if( typeof($scope.currentTlTrack.track) !== 'undefined' )
			return ( $scope.playPosition / $scope.currentTlTrack.track.length * 100 ).toFixed(2);
	};
    
	
	/**
	 * Core player controls
	 **/
	
	$scope.playPause = function(){
        if( $scope.playing )
            MopidyService.pause();
        else
            MopidyService.play();
	}
    $scope.stop = function(){
        MopidyService.stopPlayback();
    },
	$scope.next = function(){
		MopidyService.next();
	}
	$scope.previous = function(){
		MopidyService.previous();
	}
	$scope.seek = function( event ){
		var slider, offset, position, percent, seekTime;
		if( $(event.target).hasClass('slider') )
			slider = $(event.target);
		else
			slider = $(event.target).closest('.slider');
		
		// calculate the actual destination seek time
		offset = slider.offset();
		position = event.pageX - offset.left;
		percent = position / slider.innerWidth();
		seekTime = Math.round(percent * $scope.currentTlTrack.track.length);
		console.log( 'Seeking to '+percent+'% and '+seekTime+'ms' );
		// tell mopidy to make it so
		MopidyService.seek( seekTime );
	}
	$scope.setVolume = function( event ){
		var slider, offset, position, percent;
		if( $(event.target).hasClass('slider') )
			slider = $(event.target);
		else
			slider = $(event.target).closest('.slider');
		
		// calculate the actual destination seek time
		offset = slider.offset();
		position = event.pageX - offset.left;
		percent = position / slider.innerWidth() * 100;
		
		$scope.volume = percent;
		MopidyService.setVolume( percent );
	};
	
	
	/**
	 * Play order toggle switches
	 **/
	
    $scope.toggleRepeat = function(){
        if( $scope.isRepeat )
            MopidyService.setRepeat( false ).then( function(response){ $scope.isRepeat = false; } );
        else
            MopidyService.setRepeat( true ).then( function(response){ $scope.isRepeat = true; } );
    };
    $scope.toggleRandom = function(){
        if( $scope.isRandom )
            MopidyService.setRandom( false ).then( function(response){ $scope.isRandom = false; } );
        else
            MopidyService.setRandom( true ).then( function(response){ $scope.isRandom = true; } );
    };
    $scope.toggleMute = function(){
        if( $scope.isMute )
            MopidyService.setMute( false ).then( function(response){ $scope.isMute = false; } );
        else
            MopidyService.setMute( true ).then( function(response){ $scope.isMute = true; } );
    };
	
	// listen for changes from other clients
	$rootScope.$on('mopidy:event:optionsChanged', function(event, options){
		MopidyService.getRandom().then( function( isRandom ){
			$scope.isRandom = isRandom;
		});
		MopidyService.getMute().then( function( isMute ){
			$scope.isMute = isMute;
		});
	});
	
    
    /**
     * Keyboard shortcuts
     **/
    
	$('body').bind('keyup',function(evt){
        
        // spacebar
        if( evt.which === 32 )
            $scope.playPause();
    });
	
	
	/**
	 * Fullscreen player panel
	 **/<commit_msg>Spacebar now keydown, and prevents scrolling<commit_after>'use strict';

angular.module('spotmop.player', [
	'spotmop.services.spotify',
	'spotmop.services.mopidy'
])

.controller('PlayerController', function PlayerController( $scope, $rootScope, $timeout, $interval, MopidyService, SpotifyService ){
	
	// setup template containers
	$scope.muted = false;
	$scope.playing = false;
	$scope.isRepeat = false;
	$scope.isRandom = false;
	$scope.isMute = false;
	$scope.volume = 100;
	$scope.playPosition = 0;
	$scope.playPositionPercent = function(){
		if( typeof($scope.currentTlTrack.track) !== 'undefined' )
			return ( $scope.playPosition / $scope.currentTlTrack.track.length * 100 ).toFixed(2);
	};
    
	
	/**
	 * Core player controls
	 **/
	
	$scope.playPause = function(){
        if( $scope.playing )
            MopidyService.pause();
        else
            MopidyService.play();
	}
    $scope.stop = function(){
        MopidyService.stopPlayback();
    },
	$scope.next = function(){
		MopidyService.next();
	}
	$scope.previous = function(){
		MopidyService.previous();
	}
	$scope.seek = function( event ){
		var slider, offset, position, percent, seekTime;
		if( $(event.target).hasClass('slider') )
			slider = $(event.target);
		else
			slider = $(event.target).closest('.slider');
		
		// calculate the actual destination seek time
		offset = slider.offset();
		position = event.pageX - offset.left;
		percent = position / slider.innerWidth();
		seekTime = Math.round(percent * $scope.currentTlTrack.track.length);
		console.log( 'Seeking to '+percent+'% and '+seekTime+'ms' );
		// tell mopidy to make it so
		MopidyService.seek( seekTime );
	}
	$scope.setVolume = function( event ){
		var slider, offset, position, percent;
		if( $(event.target).hasClass('slider') )
			slider = $(event.target);
		else
			slider = $(event.target).closest('.slider');
		
		// calculate the actual destination seek time
		offset = slider.offset();
		position = event.pageX - offset.left;
		percent = position / slider.innerWidth() * 100;
		
		$scope.volume = percent;
		MopidyService.setVolume( percent );
	};
	
	
	/**
	 * Play order toggle switches
	 **/
	
    $scope.toggleRepeat = function(){
        if( $scope.isRepeat )
            MopidyService.setRepeat( false ).then( function(response){ $scope.isRepeat = false; } );
        else
            MopidyService.setRepeat( true ).then( function(response){ $scope.isRepeat = true; } );
    };
    $scope.toggleRandom = function(){
        if( $scope.isRandom )
            MopidyService.setRandom( false ).then( function(response){ $scope.isRandom = false; } );
        else
            MopidyService.setRandom( true ).then( function(response){ $scope.isRandom = true; } );
    };
    $scope.toggleMute = function(){
        if( $scope.isMute )
            MopidyService.setMute( false ).then( function(response){ $scope.isMute = false; } );
        else
            MopidyService.setMute( true ).then( function(response){ $scope.isMute = true; } );
    };
	
	// listen for changes from other clients
	$rootScope.$on('mopidy:event:optionsChanged', function(event, options){
		MopidyService.getRandom().then( function( isRandom ){
			$scope.isRandom = isRandom;
		});
		MopidyService.getMute().then( function( isMute ){
			$scope.isMute = isMute;
		});
	});
	
    
    /**
     * Keyboard shortcuts
     **/
    
	$('body').bind('keydown',function(evt){
        
        // spacebar
        if( evt.which === 32 ){
            evt.preventDefault();
			$scope.playPause();
		}
    });
	
	
	/**
	 * Fullscreen player panel
	 **/
{'fraction_non_alphanumeric': 0.1553548751234655, 'fraction_numerical': 0.0036686891491463243, 'mean_word_length': 3.0272727272727273, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '83974', 'n_tokens_mistral': 2424, 'n_tokens_neox': 2233, 'n_words': 458}