From 792fd531f67a9490f16eb594b4b3eb646128275e Mon Sep 17 00:00:00 2001
From: Ludovic Pouzenc <ludovic@pouzenc.fr>
Date: Fri, 22 Jun 2012 22:58:30 +0000
Subject: "Backport de l'IHM de test7 dans le projet principal. Application
 licence GPL v3.0 Renommage appli Music2Light (homonymes existants) ->
 Instru2Light

git-svn-id: file:///var/svn/2012-violon-leds/trunk@30 6be1fa4d-33ac-4c33-becc-79fcb3794bb6
---
 src/instru2light.c | 102 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)
 create mode 100644 src/instru2light.c

(limited to 'src/instru2light.c')

diff --git a/src/instru2light.c b/src/instru2light.c
new file mode 100644
index 0000000..33892b5
--- /dev/null
+++ b/src/instru2light.c
@@ -0,0 +1,102 @@
+/*
+    Instru2Light - Illumine un instrument de musique en temps réel
+    Copyright (C) 2012 Ludovic Pouzenc <lpouzenc@gmail.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 3 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, see <http://www.gnu.org/licenses/>.
+*/
+#include <gtk/gtk.h>
+#include <stdlib.h>
+#include <pthread.h>
+#include "gtkvumeter.h"
+#include "win_main.h"
+#include "compute.h"
+#include "capture.h"
+#include "hsv2rgb.h"
+#include "illuminate.h"
+
+gint *audio_vumeter_val, *light_h, *light_s, *light_v, *light_r, *light_g, *light_b; 
+void my_process(float *data, size_t nsamples, size_t nchan);
+
+int main (int argc, char **argv) {
+	GtkWidget *mainwin;
+	gint vals_for_vumeters[7]={0,0,0,0,0,0,0}; //sound,h,s,v,r,g,b
+	//Some handy references to the previous array items to make things clear whenever possible
+	audio_vumeter_val=vals_for_vumeters+0;
+	light_h=vals_for_vumeters+1;
+	light_s=vals_for_vumeters+2;
+	light_v=vals_for_vumeters+3;
+	light_r=vals_for_vumeters+4;
+	light_g=vals_for_vumeters+5;
+	light_b=vals_for_vumeters+6;
+
+	pthread_t audio_analyzer;
+
+	g_thread_init(NULL);
+	gdk_threads_init();
+	gdk_threads_enter();
+	gtk_init (&argc, &argv);
+
+	mainwin=win_main_build();
+	gtk_widget_show_all (mainwin);
+
+	dmx_init();
+
+	printf("debug : main my_process==%p\n", my_process);
+	printf("debug : main (void *)my_process==%p\n", (void *)my_process);
+	pthread_create (&audio_analyzer, (void *)NULL, (void *)audio_thread, (void *)my_process);
+	g_timeout_add (25, win_main_update_vumeters, (gpointer)vals_for_vumeters);
+
+	gtk_main ();
+
+	gdk_threads_leave();
+	dmx_deinit();
+
+	return 0;
+}
+
+void my_process(float *data, size_t nsamples, size_t nchan) {
+
+	float sound_level;
+	struct hsv_colour hsv;
+	struct rgb_colour rgb;
+
+	//FIXME : rate should came from PulseAudio
+	sound_level=compute_level(data, nsamples, 44100);
+
+//	printf("sound_level==%+8f nsamples==%8i\n", sound_level, nsamples);
+
+	// Update sound vumeter value (refreshed asynchronously)
+	*audio_vumeter_val=(int)sound_level;
+
+	// Transfert Function
+	audio2hsv_1(sound_level,&(hsv.h),&(hsv.s),&(hsv.v));
+	
+	// Conversion
+	hsv2rgb(&hsv, &rgb);
+//	printf("hsv %+.3f %+.3f %+.3f\n", hsv.h, hsv.s, hsv.v);
+//	printf("rgb %+.3f %+.3f %+.3f\n", rgb.r, rgb.g, rgb.b);
+
+	//Update vu-meters
+	*light_h=hsv.h*255;
+	*light_s=hsv.s*255;
+	*light_v=hsv.v*255;
+
+	*light_r=rgb.r*255;
+	*light_g=rgb.g*255;
+	*light_b=rgb.b*255;
+	
+	// Send to DMX
+	dmx_write_rgb(*light_r, *light_g, *light_b);
+}
+
-- 
cgit v1.2.3