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

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

#define SLASH '/'

void	level_bars(cairo_t *cr, double Xx, double rms, int bar) {

#define HOR_ORIGIN 30.0
#define VER_ORIGIN 10.0
#define BAR_WIDTH  3.25

	double Lx, Rx;

	Lx = Rx = Xx;

	cairo_set_font_size(cr,8.0);

//---------------------
//	level bars
//---------------------

	double left_bar;
	left_bar = BAR_WIDTH * Lx;	// bar length
	double right_bar;
	right_bar = BAR_WIDTH * Rx;	// bar length

//	cairo_set_line_cap  (cr, CAIRO_LINE_CAP_ROUND);
	cairo_set_line_cap  (cr, CAIRO_LINE_CAP_SQUARE);

	if (bar == LEFT) {

		cairo_move_to(cr, 1.0, VER_ORIGIN + 3.0 );
		cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // highlight band
		cairo_show_text(cr, "RMS");

		cairo_move_to(cr, HOR_ORIGIN, VER_ORIGIN);

		cairo_set_source_rgb(cr, 0.7, 0.7, 0.0); // highlight band
		cairo_set_line_width(cr, 8.0);

		cairo_line_to (cr, HOR_ORIGIN + BAR_WIDTH * rms, VER_ORIGIN );
		cairo_stroke (cr);

		cairo_move_to(cr, 1.0, VER_ORIGIN + 12.0 );
		cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // highlight band
		cairo_show_text(cr, "PEAK");

		cairo_set_line_width(cr, 8.0);
		cairo_set_source_rgb(cr, 1.0, 1.0, 0.0); // highlight band

		cairo_move_to(cr, HOR_ORIGIN, VER_ORIGIN + 8.0);
		cairo_line_to (cr, HOR_ORIGIN + left_bar, VER_ORIGIN + 8.0 );
		cairo_stroke (cr);

		return;
		}

	if (bar == RIGHT) {

		cairo_move_to(cr, 1.0, VER_ORIGIN + 27.0 );
		cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // highlight band
		cairo_show_text(cr, "RMS");

		cairo_set_source_rgb(cr, 0.7, 0.0, 0.0); // highlight band
		cairo_set_line_width(cr, 8.0);

		cairo_move_to(cr, HOR_ORIGIN, VER_ORIGIN + 24.0 );
		cairo_line_to (cr, HOR_ORIGIN + BAR_WIDTH * rms, VER_ORIGIN + 24.0 );
		cairo_stroke (cr);

		cairo_move_to(cr, 1.0, VER_ORIGIN + 34.0 );
		cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // highlight band
		cairo_show_text(cr, "PEAK");

		cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); // highlight band

		cairo_move_to(cr, HOR_ORIGIN, VER_ORIGIN + 32.0);
		cairo_line_to (cr, right_bar + HOR_ORIGIN, VER_ORIGIN + 32.0 );
		cairo_stroke (cr);
		return;
		}

	if (bar == MIC) {

//---------------------
// 	Microphone bar
//---------------------

#define MIC_BAR_OFFSET 48.0

		static double mic_bar;
		mic_bar =  BAR_WIDTH * ML;

		cairo_move_to(cr, 1.0, VER_ORIGIN + MIC_BAR_OFFSET + 3.0 );
		cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // highlight band
		cairo_show_text(cr, "RMS");

		cairo_set_line_width(cr, 8.0);

		cairo_set_source_rgb(cr, 0.5, 0.7, 0.5); // green

		cairo_move_to(cr, HOR_ORIGIN, VER_ORIGIN + MIC_BAR_OFFSET );
		cairo_line_to (cr, HOR_ORIGIN + BAR_WIDTH * rms, VER_ORIGIN + MIC_BAR_OFFSET );
		cairo_stroke (cr);

		cairo_move_to(cr, 1.0, VER_ORIGIN + MIC_BAR_OFFSET + 12.0 );
		cairo_set_source_rgb(cr, 1.0, 1.0, 1.0); // highlight band
		cairo_show_text(cr, "PEAK");

		cairo_set_source_rgb(cr, 0.5, 1.0, 0.5); // green
		MR = ML = 0.0;
		cairo_move_to(cr, HOR_ORIGIN, VER_ORIGIN + MIC_BAR_OFFSET + 8.0 );
		cairo_line_to (cr, mic_bar + HOR_ORIGIN, VER_ORIGIN + MIC_BAR_OFFSET + 8.0 );
		cairo_stroke (cr);

		MRx = MLx = 0.0;  // done with sample

		return;
		}
	}
