/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#+
#+     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
#+
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

//	Nov 4, 2022

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

#define SLASH '/'

void	leftFlgSubText(cairo_t *cr) {

	cairo_select_font_face (cr, "Sans", CAIRO_FONT_SLANT_ITALIC,
	                        CAIRO_FONT_WEIGHT_BOLD); // NORMAL ITALIC OBLIQUE

	cairo_set_font_size(cr,12.0);
	cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // white
	cairo_move_to (cr, G_OFF_FREQ + 10.0, SPECTRUM_FREQ_VERTICAL );
	cairo_show_text(cr, "Linear Output Line Level");
	cairo_stroke (cr);
	}


void	on_video_panel_toggled(GtkWidget *w) {

	return;

	if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(video_panel))) {
		gtk_widget_hide(movie);
		vlc_stop();
		}

	else { // not toggled
		gtk_widget_show(movie);
		gtk_widget_hide(d1mask);
		gtk_widget_hide(drawV);
		vlc_stop();
		}

	}


//--------------------------------
//      Select color for bars
//--------------------------------

void    color_bars(cairo_t *cr, int i, int noLine, int color) {

	double red, green, blue;

	if (!rand_colors ) {
		if (!noLine && srchan[i] > UPPER_MAX_MAX) UPPER_MAX_MAX_COLOR
			else if (!noLine && srchan[i] > UPPER_MAX) UPPER_MAX_COLOR
				else if (color == RED) cairo_set_source_rgb(cr, 1.0, 0.1, 0.1); // red
				else if (color == YELLOW) cairo_set_source_rgb(cr, 1.0, 1.0, 0.3); // yellow
				else if (color == WHITE) cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // white
				else cairo_set_source_rgb(cr, 0.2, 0.2, 1.0); // blue
		}

//--------------------------------------------------------------
//      create a color from deep red up to violet depending on i
//--------------------------------------------------------------

	else  {
		color_generator(cr, i, &red, &green, &blue);
		}
	}


void	color_generator(cairo_t *cr, int i, double *r, double *g, double *b) {

//--------------------------------------------------------------
//	generate colors based on frequency from 1 to 100 (i)
//--------------------------------------------------------------

//--------------------------------------------------------------
//	red starts high (PI/2) and goes to zero (PI)
//--------------------------------------------------------------

	*r = sin(M_PI_2 + (i / 100.) * M_PI_2);  // PI/2 to PI
	if (*r < 0.0) *r = 0.0;

//--------------------------------------------------------------
//	blue starts low (0) and becomes high (PI/2)
//--------------------------------------------------------------

	*b = sin( (i / 100.) * M_PI_2);          // 0 to PI/2

	if (i > 80) { // brighten and make more purple high freqs
		*r = 0.7 * sin( (i / 100.) * M_PI_2);          // 0 to PI/2
		*g = 0.5 * sin( (i / 100.) * M_PI_2);          // 0 to PI/2
		}

//--------------------------------------------------------------
//	green starts low(0) and ends low (PI)
//--------------------------------------------------------------

	*g = sin( (i / 100.) * M_PI);            // 0 to PI

	cairo_set_source_rgb(cr, *r, *g, *b);
	}

void	rand_color_generator(cairo_t *cr, int i, double *r, double *g, double *b) {

	*r = (rand() % 1000) /1000.0;
	*g = (rand() % 1000) /1000.0;
	*b = (rand() % 1000) /1000.0;
	return;
	}

void	on_sprinkle_count_value_changed( GtkSpinButton *s, GtkScrollType scr) {
	sprinkleCount = gtk_spin_button_get_value(s);
	}

