<commit_before>var MPlayer = exports;

var child = require('child_process');
var path = require('path');
var log = require('./log');

var events = require('events');
var eventEmitter = new events.EventEmitter();

var mplayer;
var paused = false;

var forcefullyStopped = false;


MPlayer.play = function(song) {
	if(song == undefined) return;
	// Tidy the song up
	song = song.replace(/(^')|('$)/g, "");
	song = song + "";
	if(mplayer == undefined) {
		// mplayer = child.spawn('mplayer', ['-slave', '-quiet', song.replace(/(^')|('$)/g, "")]);
		log.info('Spawning new MPlayer process to play ' + song);
		mplayer = child.spawn("mplayer", ["-slave", song]);
		paused = false;
		forcefullyStopped = false;
		setupEmitters(mplayer);
	} else {
		log.info('Telling current MPlayer process to play ' + song);
		MPlayer.pause();
		mplayer.stdin.write("loadfile \"" + song + "\"\n");
		paused = false;
	}
}

MPlayer.pause = function() {
	if(mplayer != undefined && !paused) {
		mplayer.stdin.write('pause\n');
		paused = true;
	}
}

MPlayer.unpause = function() {
	if(mplayer != undefined && paused) {
		mplayer.stdin.write('pause\n');
		paused = false;
	}
}

MPlayer.stop = function() {
	if(mplayer != undefined) {
		forcefullyStopped = true;
		mplayer.kill();
		mplayer = undefined;
	}
}

MPlayer.isRunning = function() {
	return mplayer != undefined 
}

MPlayer.isPaused = function() {
	return paused;
}

MPlayer.getVolume = function() {
	if(mplayer != undefined) {
		mplayer.stdin.write("get_property volume");
	}
}

MPlayer.incVolume = function() {
	if(mplayer != undefined) {
		mplayer.stdin.write("volume 1");
	}
}

MPlayer.decVolume = function() {
	if(mplayer != undefined) {
		mplayer.stdin.write("volume -1");
	}
}

MPlayer.getEventEmitter = function(callback){
  callback(eventEmitter);
};

function  setupEmitters(proc) {
	// Event Emitters

	proc.stdout.on('data', function (data) {
	  log.print('MPlayer: ' + data);
	});

	proc.stderr.on('data', function (data) {<commit_msg>Add new line after mplayer volume commands<commit_after>var MPlayer = exports;

var child = require('child_process');
var path = require('path');
var log = require('./log');

var events = require('events');
var eventEmitter = new events.EventEmitter();

var mplayer;
var paused = false;

var forcefullyStopped = false;


MPlayer.play = function(song) {
	if(song == undefined) return;
	// Tidy the song up
	song = song.replace(/(^')|('$)/g, "");
	song = song + "";
	if(mplayer == undefined) {
		// mplayer = child.spawn('mplayer', ['-slave', '-quiet', song.replace(/(^')|('$)/g, "")]);
		log.info('Spawning new MPlayer process to play ' + song);
		mplayer = child.spawn("mplayer", ["-slave", song]);
		paused = false;
		forcefullyStopped = false;
		setupEmitters(mplayer);
	} else {
		log.info('Telling current MPlayer process to play ' + song);
		MPlayer.pause();
		mplayer.stdin.write("loadfile \"" + song + "\"\n");
		paused = false;
	}
}

MPlayer.pause = function() {
	if(mplayer != undefined && !paused) {
		mplayer.stdin.write('pause\n');
		paused = true;
	}
}

MPlayer.unpause = function() {
	if(mplayer != undefined && paused) {
		mplayer.stdin.write('pause\n');
		paused = false;
	}
}

MPlayer.stop = function() {
	if(mplayer != undefined) {
		forcefullyStopped = true;
		mplayer.kill();
		mplayer = undefined;
	}
}

MPlayer.isRunning = function() {
	return mplayer != undefined 
}

MPlayer.isPaused = function() {
	return paused;
}

MPlayer.getVolume = function() {
	if(mplayer != undefined) {
		mplayer.stdin.write("get_property volume\n");
	}
}

MPlayer.incVolume = function() {
	if(mplayer != undefined) {
		mplayer.stdin.write("volume 1\n");
	}
}

MPlayer.decVolume = function() {
	if(mplayer != undefined) {
		mplayer.stdin.write("volume -1\n");
	}
}

MPlayer.getEventEmitter = function(callback){
  callback(eventEmitter);
};

function  setupEmitters(proc) {
	// Event Emitters

	proc.stdout.on('data', function (data) {
	  log.print('MPlayer: ' + data);
	});

	proc.stderr.on('data', function (data) {
{'fraction_non_alphanumeric': 0.1837959489872468, 'fraction_numerical': 0.001000250062515629, 'mean_word_length': 4.128205128205129, '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': '185451', 'n_tokens_mistral': 1494, 'n_tokens_neox': 1431, 'n_words': 294}