/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     Internet Radio Automation & Encoding Toolkit
#+
#+     Copyright (C) 2018, 2019, 2020, 2021 by Kevin C. O'Kane
#+
#+     Kevin C. O'Kane
#+     kc.okane@gmail.com
#+     https://www.cs.uni.edu/~okane
#+     https://threadsafebooks.com/
#+
#+ This program is free software; you can redistribute it and/or modify
#+ it under the terms of the GNU General Public License as published by
#+ the Free Software Foundation; either version 2 of the License, or
#+ (at your option) any later version.
#+
#+ This program is distributed in the hope that it will be useful,
#+ but WITHOUT ANY WARRANTY; without even the implied warranty of
#+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#+ GNU General Public License for more details.
#+
#+ You should have received a copy of the GNU General Public License
#+ along with this program; if not, write to the Free Software
#+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	Oct 5, 2021

#include "includes.h"
#include "common-externs.h"

#define SLASH '/'


//-----------------------------------------------------------------------------------------------
//	Linux Audio Notes
//
//	Using pactl via a system() call to control levels

//	Note: pavucontrol settings can cause havoc -
//		so check your inputs, outputs, mutes, sources, etc.

//	pactl list short
//		yields a list of client numbers and names
//	pactl list short clients
//		variant that only lists clients
//	pactl list short sink-inputs
//		yields a list of index numbers by client number

//	pactl list source-outputs
//		OBS input will be found here
//		One OBS entry will be 'Desktop Audio' (or similar) - this is the player volume
//		One OBS entry will be 'Mic/Aux' (or similar) - this is the microphone volume
//		Note the 'Source Output' numbers
//	pactl set-source-output-volume nbr 50%
//		Will set the volume of source 'nbr' to 50% where 'nbr' is the Source Output number.
//		This is a way to remotely set OBS inputs

//	pactl list sink-inputs
//		VLC and other players will be found here
//		VLC will be something like "VLC media player (LibVLC 3.0.4)"
//		Note 'Source Output' number as 'nbr'
//	pactl set-sink-input-volume nbr 50%
//		This is a way to remotely set VLC and other player output levels
//
//	pactl list source-outputs | grep -e "Source Output" -e "application\.name" -e "media\.name"
//-----------------------------------------------------------------------------------------------

void	outVolume(double percent) { // change output volume

//	Set master vlc api volume directly - this is noisy
//
//	if (mediaPlayer) libvlc_audio_set_volume(mediaPlayer, percent);
//	return;

//------------------------------------------------------------------------------
//	The following will locate an external vlc player and change its volume
//	This is experimental code. Not currently in use.
//------------------------------------------------------------------------------
//
//	char line[1024];
//	sprintf(line, "A=`pactl list short clients | grep vlc | cut -f 1` && pactl set-sink-input-volume"
//	" `pactl list short sink-inputs | grep $A | cut -f 1` %d%%", percent);
//	system(line);
//	return;

//-------------------------------------------------
//	Adjustment of volume by means of preamp
//-------------------------------------------------
//
	gdouble x = (int) gtk_adjustment_get_value(adjustment10); // preAmp
	x = (double) percent - 100.0 ;
	if (x > 50.0 ) x = 50.0;
	else if (x < -50.0) x = -50.0;
	gtk_adjustment_set_value (GTK_ADJUSTMENT(adjustment10), x); // preAmp

//---------------------------------------------------------------------
//	Adjust volume by accessing PulseAudio directly - this is noisy
//---------------------------------------------------------------------
//
//	pa_cvolume vol = {2, 65000, 65000};
//	pa_context_success_cb_t cbt;
//	printf("\nsink: %s\nsource: %s\nmonitor: %s\n",default_sink, default_source,default_monitor);
//	pa_cvolume vol = {2, 65000, 65000};
//	if (Mcontext) // wait for Mcontext to become active
//	pa_context_set_source_volume_by_name(Mcontext, default_source, &vol, NULL, NULL);

//---------------------------------------------------------------
//	Adjust volume by changeing OBS volume settings
//	The following will locate obs and change its volume
//---------------------------------------------------------------
//
//	char line[4096],tmp[1024];
//	int pulseNbr;
//
//	obsFactor = percent;
//
//	if (strlen(obsIndex)) { // OBS found
//
//		pulseNbr = ((double) obsFactor/100.0) * 65000;
//		vol.values[0] = pulseNbr;
//		vol.values[1] = pulseNbr;
//		int pindx = atoi(obsIndex);
//
//		// pa_context_set_sink_volume_by_index(context, (uint32_t) 0, &vol, NULL, NULL);
//
//		sprintf(tmp, "pactl set-source-output-volume %s %d%%", obsIndex, obsFactor);
//		system(tmp);
//		return;
//
//------------------------------
//	Old OBS index lookup
//------------------------------
//
//	sprintf(line, "A=`pactl list short clients | grep obs | cut -f 1` && pactl set-source-output-volume"
//		" `pactl list short source-outputs | grep $A | head -1 | cut -f 1` %d%%", obsFactor);
//	system(line);

//	pa_context_set_sink_volume_by_name(context, default_sink, &vol, NULL, NULL); // alt
// 	pa_context_set_source_volume_by_name(context, default_monitor, &vol, NULL, NULL);

	}
