iris-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Iris-devel] Update to pinwheel theme; new pipes theme


From: The Speedster
Subject: [Iris-devel] Update to pinwheel theme; new pipes theme
Date: Thu, 02 May 2002 22:54:24 -0700
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.2.1) Gecko/20010901

My wife kindly added some gtk controls for the pinwheel theme so that a few parameters are adjustable. I also created a new theme called "pipes", which draws a spiral of pipes that each change height. She added a couple of nice controls for that too.

The attached patch is based off version 0.9 again..

Rgds.,
Ron & Stephanie Lockwood-Childs

diff -urN --exclude=RCS iris-0.9/src/Makefile.in iris_new/src/Makefile.in
--- iris-0.9/src/Makefile.in    Mon Mar 25 13:43:59 2002
+++ iris_new/src/Makefile.in    Wed Apr 24 23:00:58 2002
@@ -102,7 +102,7 @@
 
 CFLAGS = -Wall @XMMS_CFLAGS@ @CFLAGS@ -I$(top_builddir) -I$(top_srcdir) 
-D_REENTRANT @GTK_CFLAGS@
 
-libiris_la_SOURCES = iris.c config.c color.c 3Dstuff.c theme.c 
theme_original.c theme_spectrum.c theme_spectrotoy.c theme_squarefield.c 
theme_pyramid.c theme_waves.c iris.h
+libiris_la_SOURCES = iris.c config.c color.c 3Dstuff.c theme.c 
theme_original.c theme_spectrum.c theme_spectrotoy.c theme_squarefield.c 
theme_pyramid.c theme_waves.c theme_pinwheel.c theme_pipes.c iris.h
 mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
 CONFIG_HEADER = ../config.h
 CONFIG_CLEAN_FILES = 
@@ -115,7 +115,8 @@
 libiris_la_LIBADD = 
 libiris_la_OBJECTS =  iris.lo config.lo color.lo 3Dstuff.lo theme.lo \
 theme_original.lo theme_spectrum.lo theme_spectrotoy.lo \
-theme_squarefield.lo theme_pyramid.lo theme_waves.lo
+theme_squarefield.lo theme_pyramid.lo theme_waves.lo theme_pinwheel.lo \
+theme_pipes.lo
 COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) 
$(CFLAGS)
 LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) 
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
 CCLD = $(CC)
@@ -130,7 +131,8 @@
 DEP_FILES =  .deps/3Dstuff.P .deps/color.P .deps/config.P .deps/iris.P \
 .deps/theme.P .deps/theme_original.P .deps/theme_pyramid.P \
 .deps/theme_spectrotoy.P .deps/theme_spectrum.P \
-.deps/theme_squarefield.P .deps/theme_waves.P
+.deps/theme_squarefield.P .deps/theme_waves.P .deps/theme_pinwheel.P \
+.deps/theme_pipes.P
 SOURCES = $(libiris_la_SOURCES)
 OBJECTS = $(libiris_la_OBJECTS)
 
diff -urN --exclude=RCS iris-0.9/src/iris.h iris_new/src/iris.h
--- iris-0.9/src/iris.h Tue Apr  9 09:44:15 2002
+++ iris_new/src/iris.h Wed Apr 24 23:52:24 2002
@@ -145,7 +145,7 @@
 extern void bar_full (GLfloat height, xz * xz1, xz * xz2, xz * xz3, xz * xz4);
 
 /* theme.c */
-#define THEME_NUMBER 6
+#define THEME_NUMBER 8 // Added 1 theme 4/17/02 RC
 extern void theme_register (void);
 extern iris_theme theme[THEME_NUMBER];
 
diff -urN --exclude=RCS iris-0.9/src/theme.c iris_new/src/theme.c
--- iris-0.9/src/theme.c        Tue Apr  9 09:44:47 2002
+++ iris_new/src/theme.c        Wed Apr 24 23:52:27 2002
@@ -25,6 +25,9 @@
 extern iris_theme theme_squarefield;
 extern iris_theme theme_waves;
 extern iris_theme theme_pyramid;
+
+extern iris_theme theme_pinwheel; // added 4/17/02 RC
+extern iris_theme theme_pipes; // added 4/22/02 RC
 iris_theme theme[THEME_NUMBER];
 
 /* this initialize the theme registry */
@@ -37,4 +40,7 @@
   theme[3] = theme_squarefield;
   theme[4] = theme_waves;
   theme[5] = theme_pyramid;
+
+  theme[6] = theme_pinwheel;
+  theme[7] = theme_pipes;
 }
diff -urN --exclude=RCS iris-0.9/src/theme_pinwheel.c 
iris_new/src/theme_pinwheel.c
--- iris-0.9/src/theme_pinwheel.c       Wed Dec 31 16:00:00 1969
+++ iris_new/src/theme_pinwheel.c       Thu May  2 22:36:00 2002
@@ -0,0 +1,480 @@
+/*  Iris - visualization plugin for XMMS
+ *  Copyright (C) 2000-2002 Cédric DELFOSSE (address@hidden)
+ *
+ *  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.
+ */
+
+/* New Theme created by Ron Lockwood-Childs
+ * Looks best when alpha blending is on
+ */
+
+/* $Id: theme_pinwheel.c,v 1.2 2002/05/03 05:13:15 sjl Exp $ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <math.h>
+#include <time.h>
+#include <GL/gl.h>
+#include <xmms/configfile.h>
+#include "iris.h"
+
+#define NUM_BANDS 16
+
+#define NUM_PER_RING 8
+#define GAP (M_PI_4)
+
+#define RANDOM_HEIGHT_COUNTDOWN 60
+
+static char *modes_name[] = { "Normal" };
+
+static char pinwheel_priority[] = "pinwheel_priority";
+static char pinwheel_blend[] = "pinwheel_blend";
+static char pinwheel_numsec[] = "pinwheel_numsec";
+static char pinwheel_hrandom[] = "pinwheel_hrandom";
+static char pinwheel_hset[] = "pinwheel_hset";
+
+static time_t time_random = 0;   // timer for random height mode
+
+static void init_draw_mode (void);
+static GLfloat get_x_angle (void);
+static gfloat get_priority (void);
+static void set_new_priority (gfloat);
+static void draw_one_frame (gboolean);
+static void config_read (ConfigFile *, char *);
+static void config_write (ConfigFile *, char *);
+static void config_default (void);
+static void config_create (GtkWidget *);
+static void config_apply (void);
+static void set_height (void);
+
+
+iris_theme theme_pinwheel = {
+  "PinWheel",
+  1,
+  modes_name,
+  init_draw_mode,
+  get_x_angle,
+  get_priority,
+  set_new_priority,
+  draw_one_frame,
+  config_read,
+  config_write,
+  config_default,
+  config_create,
+  config_apply
+};
+
+struct
+{
+  gfloat priority;
+  gboolean blend;
+  gboolean height_random;
+  gfloat height_set;
+  gfloat height;
+  gfloat num_sections;
+}
+config_pinwheel, new_config_pinwheel;
+
+extern GLfloat data1[16];
+GLfloat data2[NUM_BANDS];  // previous freq band data
+GLfloat angle[NUM_BANDS];  // previous angle data
+GLfloat radii[NUM_BANDS+2] = { 0.0f, 0.5f, 1.0f, 1.5f, 2.0f, 2.5f, 3.0f, 3.5f,
+                               4.0f, 4.5f, 5.0f, 5.5f, 6.0f, 6.5f, 7.0f, 7.5f,
+                               8.0f };
+
+static void
+init_draw_mode ()
+{
+  if (config_pinwheel.blend)
+    {
+      if (!glIsEnabled (GL_BLEND))
+       {
+         glBlendFunc (GL_SRC_ALPHA, GL_ONE);
+         glEnable (GL_BLEND);
+         glDisable (GL_DEPTH_TEST);
+       }
+    }
+  else
+    {
+      if (glIsEnabled (GL_BLEND))
+       {
+         glDisable (GL_BLEND);
+         glEnable (GL_DEPTH_TEST);
+       }
+    }
+}
+
+
+static GLfloat
+get_x_angle ()
+{
+  return (10.0 + (int) (80.0 * rand () / (RAND_MAX + 1.0)));
+}
+
+
+static gfloat
+get_priority ()
+{
+  return (config_pinwheel.priority);
+}
+
+
+static void
+set_new_priority (gfloat f)
+{
+  new_config_pinwheel.priority = f;
+}
+
+
+static void
+draw_one_frame (gboolean beat)
+{
+  int t1, t2;                        // loop vars
+  GLfloat red, green, blue;
+  GLfloat z = 0.0;
+  GLfloat scaler = 2.0f;      // scales the whole field - lower is bigger
+  GLfloat scaleh;             // height of the bar - lower is smaller
+  GLfloat xin_up, zin_up, xin_dn, zin_dn, xot_up, zot_up, xot_dn, zot_dn;
+  GLfloat rin, rot;           // radius of inner and outer edges of p-gram
+  GLfloat angle_up, angle_dn; // angles of top and bottom of p-gram
+  GLfloat differ;             // holds the angle increment
+  GLfloat maxdropoff = 0.05;  // smooth changes in heights
+  GLfloat angle_step;
+
+  /* update bar height (could be changing randomly over time) */
+  set_height();
+  scaleh = config_pinwheel.height;
+
+  /* internal routine to shift all data when a new datarow arrives */
+  for (t1 = 0; t1 < 16; t1++)
+    {
+        differ = data2[t1] - data1[t1];
+        // Rotate counter c.w. if differ positive, c.w. if negative
+        angle[t1] += (differ * M_PI_4 / 3.0f); // max angle change = +/- PI/12
+        if (angle[t1] > (2.0f * M_PI))
+        { // cap angle at 360
+            angle[t1] -= (2.0f * M_PI);
+        }
+        else if (angle[t1] < 0)
+        { // keep angle positive
+            angle[t1] += (2.0f * M_PI);
+        }
+
+        // smooth bar height changes
+        if (data1[t1] > data2[t1])
+        {
+            if ((data1[t1] - data2[t1]) > maxdropoff)
+                data2[t1] += maxdropoff;
+            else
+                data2[t1] += data1[t1];
+        }
+        else if (data1[t1] < data2[t1])
+        {
+            if ((data2[t1] - data1[t1]) > maxdropoff)
+                data2[t1] -= maxdropoff;
+            else
+                data2[t1] -= data1[t1];
+        }
+    }
+
+  glBegin (GL_QUADS);
+
+  for (t1 = 0; t1 < 16; t1++)
+    { // iterate thru rings
+
+        // calculate inner and outer radius for this ring of p-grams
+        rin = (radii[t1+1] - ((radii[1] - radii[0]) / 2.0f)) / scaler;
+        rot = (radii[t1+1] + ((radii[1] - radii[0]) / 2.0f)) / scaler;
+        for (t2 = 0; t2 < config_pinwheel.num_sections; t2++)
+        { // iterate thru bars in a single ring
+
+            angle_step = angle[t1] + (t2 * 
2*M_PI/config_pinwheel.num_sections);
+            if (angle_step > (M_PI * 2))
+                angle_step -= (M_PI * 2);
+            else if (angle_step < 0)
+                angle_step += (M_PI * 2);
+            // calculate upper and lower angles for this p-gram
+            angle_up = angle_step + (M_PI_2 / 9.0f);
+            angle_dn = angle_step - (M_PI_2 / 9.0f);
+            // now figure out all the p-gram vertices
+            xin_dn = cos( angle_dn ) * rin;
+            zin_dn = sin( angle_dn ) * rin;
+            xin_up = cos( angle_up ) * rin;
+            zin_up = sin( angle_up ) * rin;
+            xot_dn = cos( angle_dn ) * rot;
+            zot_dn = sin( angle_dn ) * rot;
+            xot_up = cos( angle_up ) * rot;
+            zot_up = sin( angle_up ) * rot;
+
+            // now start drawin'
+            // start with the front, then left, back, right, finally the top
+
+            // "front"
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xot_dn, data2[t1] * scaleh, zot_dn ); // "top-right"
+
+            get_color( &red, &green, &blue, &z ); // bottom color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xot_dn, z, zot_dn ); // "bottom-right"
+            glVertex3f( xin_dn, z, zin_dn ); // "bottom-left"
+
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xin_dn, data2[t1] * scaleh, zin_dn ); // "top-left"
+
+            // "left"
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xin_dn, data2[t1] * scaleh, zin_dn ); // "top-out"
+
+            get_color( &red, &green, &blue, &z ); // bottom color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xin_dn, z, zin_dn ); // "bottom-out"
+            glVertex3f( xin_up, z, zin_up ); // "bottom-in"
+
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xin_up, data2[t1] * scaleh, zin_up ); // "top-in"
+
+            // "back"
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xin_up, data2[t1] * scaleh, zin_up ); // "top-left"
+
+            get_color( &red, &green, &blue, &z ); // bottom color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xin_up, z, zin_up ); // "bottom-left"
+            glVertex3f( xot_up, z, zot_up ); // "bottom-right"
+
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xot_up, data2[t1] * scaleh, zot_up ); // "top-right"
+
+            // "right"
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xot_up, data2[t1] * scaleh, zot_up ); // "top-in"
+
+            get_color( &red, &green, &blue, &z ); // bottom color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xot_up, z, zot_up ); // "bottom-in"
+            glVertex3f( xot_dn, z, zot_dn ); // "bottom-out"
+
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xot_dn, data2[t1] * scaleh, zot_dn ); // "top-out"
+
+            // "top"
+            get_color( &red, &green, &blue, &data2[t1] ); // top color
+            glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+            glVertex3f( xot_dn, data2[t1] * scaleh, zot_dn ); // "out-right"
+            glVertex3f( xin_dn, data2[t1] * scaleh, zin_dn ); // "out-left"
+            glVertex3f( xin_up, data2[t1] * scaleh, zin_up ); // "in-left"
+            glVertex3f( xot_up, data2[t1] * scaleh, zot_up ); // "in-right"
+
+        }
+    }
+
+  glEnd ();
+
+}
+
+
+static void
+config_read (ConfigFile * f, char *section_name)
+{
+  xmms_cfg_read_float (f, section_name, pinwheel_priority,
+                      &config_pinwheel.priority);
+  xmms_cfg_read_boolean (f, section_name, pinwheel_blend,
+                        &config_pinwheel.blend);
+  xmms_cfg_read_float (f, section_name, pinwheel_numsec,
+                      &config_pinwheel.num_sections);
+  xmms_cfg_read_boolean (f, section_name, pinwheel_hrandom,
+                      &config_pinwheel.height_random);
+  xmms_cfg_read_float (f, section_name, pinwheel_hset,
+                      &config_pinwheel.height_set);
+}
+
+
+static void
+config_write (ConfigFile * f, char *section_name)
+{
+  xmms_cfg_write_float (f, section_name, pinwheel_priority,
+                       config_pinwheel.priority);
+  xmms_cfg_write_boolean (f, section_name, pinwheel_blend,
+                         config_pinwheel.blend);
+  xmms_cfg_write_float (f, section_name, pinwheel_numsec,
+                         config_pinwheel.num_sections);
+  xmms_cfg_write_boolean (f, section_name, pinwheel_hrandom,
+                         config_pinwheel.height_random);
+  xmms_cfg_write_float (f, section_name, pinwheel_hset,
+                         config_pinwheel.height_set);
+}
+
+
+static void
+config_default ()
+{
+  config_pinwheel.priority = 1.0;
+  config_pinwheel.blend = TRUE;
+  config_pinwheel.num_sections = 8.0;
+  config_pinwheel.height_random = FALSE;
+  config_pinwheel.height_set = 2.0;
+  config_pinwheel.height = 2.0;
+}
+
+
+static void
+blending_toggled (GtkWidget * widget, gpointer data)
+{
+  new_config_pinwheel.blend = !new_config_pinwheel.blend;
+}
+
+
+static void
+sections_changed (GtkAdjustment * adj)
+{
+  new_config_pinwheel.num_sections = (int) adj->value;
+}
+
+
+static void
+height_changed (GtkAdjustment * adj)
+{
+  new_config_pinwheel.height_set = (int) adj->value;
+}
+
+
+static void
+height_toggled (GtkWidget * widget, GtkScale * height_scale)
+{
+  new_config_pinwheel.height_random = !new_config_pinwheel.height_random;
+  gtk_widget_set_sensitive (GTK_WIDGET (height_scale), 
!new_config_pinwheel.height_random);
+}
+
+
+static void
+set_height (void)
+{
+  time_t cur_time = time(NULL); // current time
+
+  if (config_pinwheel.height_random) 
+  {
+    /* we are in random height mode, see if it time to change height */
+    if (cur_time - time_random > RANDOM_HEIGHT_COUNTDOWN)
+    {
+      /* generate float  1 <= x <= 3 */
+      config_pinwheel.height = ( (gfloat)rand() * 2.0 / RAND_MAX) + 1.0;
+  
+      /* reset timer for when to generate new random height */
+      time_random = time(NULL);
+    }
+  }
+  else
+  {
+    config_pinwheel.height = config_pinwheel.height_set;
+  }
+}
+
+
+static void
+config_create (GtkWidget * vbox)
+{
+  GtkWidget *hbox;
+  GtkWidget *button;
+  GtkWidget *label;
+  GtkObject *adjustment;
+  GtkWidget *hscale;
+
+  memcpy (&new_config_pinwheel, &config_pinwheel,
+         sizeof (new_config_pinwheel));
+
+  /* blend mode */
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_widget_show (hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
+
+  button = gtk_check_button_new_with_label ("Alpha blending");
+  gtk_widget_show (button);
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                               new_config_pinwheel.blend);
+  gtk_signal_connect (GTK_OBJECT (button), "toggled",
+                     GTK_SIGNAL_FUNC (blending_toggled), NULL);
+
+  /* number sections per ring */
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_widget_show (hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
+
+  label = gtk_label_new ("Number sections per ring");
+  gtk_widget_show (label);
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
+
+  adjustment =
+    gtk_adjustment_new (new_config_pinwheel.num_sections, 4, 20, 1, 5, 0);
+  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
+  gtk_scale_set_digits (GTK_SCALE (hscale), 0);
+  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 25);
+  gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE, 4);
+  gtk_widget_show (hscale);
+  gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
+                     GTK_SIGNAL_FUNC (sections_changed), NULL);
+
+  /* random max height */
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_widget_show (hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
+
+  button = gtk_check_button_new_with_label ("Random height");
+  gtk_widget_show (button);
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                               new_config_pinwheel.height_random);
+
+  /* explicitly set max height */
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_widget_show (hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
+
+  label = gtk_label_new ("Maximum height");
+  gtk_widget_show (label);
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
+
+  adjustment =
+    gtk_adjustment_new (new_config_pinwheel.height_set, 1, 3, 0.1, 1, 0);
+  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
+  gtk_scale_set_digits (GTK_SCALE (hscale), 1);
+  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 25);
+  gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE, 4);
+  gtk_widget_set_sensitive (GTK_WIDGET (hscale), 
!new_config_pinwheel.height_random);
+  gtk_widget_show (hscale);
+  gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
+                     GTK_SIGNAL_FUNC (height_changed), NULL);
+
+  /* slider gets enabled/disabled according to random setting */
+  gtk_signal_connect (GTK_OBJECT (button), "toggled",
+                     GTK_SIGNAL_FUNC (height_toggled), GTK_SCALE(hscale));
+}
+
+
+static void
+config_apply (void)
+{
+  memcpy (&config_pinwheel, &new_config_pinwheel,
+         sizeof (config_pinwheel));
+}
diff -urN --exclude=RCS iris-0.9/src/theme_pipes.c iris_new/src/theme_pipes.c
--- iris-0.9/src/theme_pipes.c  Wed Dec 31 16:00:00 1969
+++ iris_new/src/theme_pipes.c  Thu May  2 22:39:07 2002
@@ -0,0 +1,450 @@
+/*  Iris - visualization plugin for XMMS
+ *  Copyright (C) 2000-2002 Cédric DELFOSSE (address@hidden)
+ *
+ *  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.
+ */
+
+/* New Theme created by Ron Lockwood-Childs
+ * Looks best when alpha blending is on
+ */
+
+/* $Id: theme_pipes.c,v 1.6 2002/05/03 05:33:21 speedy1 Exp speedy1 $ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <GL/gl.h>
+#include <xmms/configfile.h>
+#include <stdio.h>
+#include "iris.h"
+
+#define NUM_BANDS 16
+#define REPEAT 5
+#define CIRCLE_POINTS 12
+#define PIPE_DIAMETER 0.25f
+#define PIPE_THICKNESS 0.10f
+#define PIPE_ANGLE (45.0f / (float)NUM_BANDS)
+#define PIPE_RING_ANGLE (300.0f / (float)NUM_BANDS)
+#define PIPE_RING_RADIUS(side) (side / (2.0f * sin( PIPE_RING_ANGLE / 2.0f )))
+
+static char *modes_name[] = { "Normal" };
+
+static char pipes_priority[] = "pipes_priority";
+static char pipes_blend[] = "pipes_blend";
+static char pipes_slope[] = "pipes_slope";
+static char pipes_length[] = "pipes_length";
+
+static void init_draw_mode (void);
+static GLfloat get_x_angle (void);
+static gfloat get_priority (void);
+static void set_new_priority (gfloat);
+static void draw_one_frame (gboolean);
+static void config_read (ConfigFile *, char *);
+static void config_write (ConfigFile *, char *);
+static void config_default (void);
+static void config_create (GtkWidget *);
+static void config_apply (void);
+
+
+iris_theme theme_pipes = {
+  "Pipes",
+  1,
+  modes_name,
+  init_draw_mode,
+  get_x_angle,
+  get_priority,
+  set_new_priority,
+  draw_one_frame,
+  config_read,
+  config_write,
+  config_default,
+  config_create,
+  config_apply
+};
+
+struct
+{
+  gfloat priority;
+  gboolean blend;
+  gfloat slope;
+  gfloat length;
+}
+config_pipes, new_config_pipes;
+
+typedef struct
+{
+    GLfloat x_n;
+    GLfloat z_n;
+} rectangular;
+
+
+extern GLfloat data1[16];
+GLfloat data2[NUM_BANDS];  // previous freq band data
+
+static void
+init_draw_mode ()
+{
+  if (config_pipes.blend)
+    {
+      if (!glIsEnabled (GL_BLEND))
+       {
+         glBlendFunc (GL_SRC_ALPHA, GL_ONE);
+         glEnable (GL_BLEND);
+         glDisable (GL_DEPTH_TEST);
+       }
+    }
+  else
+    {
+      if (glIsEnabled (GL_BLEND))
+       {
+         glDisable (GL_BLEND);
+         glEnable (GL_DEPTH_TEST);
+       }
+    }
+}
+
+
+static GLfloat
+get_x_angle ()
+{
+  return (10.0 + (int) (80.0 * rand () / (RAND_MAX + 1.0)));
+}
+
+
+static gfloat
+get_priority ()
+{
+  return (config_pipes.priority);
+}
+
+
+static void
+set_new_priority (gfloat f)
+{
+  new_config_pipes.priority = f;
+}
+
+static void
+draw_one_frame (gboolean beat)
+{
+  int t1, t2, t3;                    // loop vars
+  GLfloat red, green, blue;
+  GLfloat y = 0.0;
+  GLfloat circumference;      // loop var around cylinder
+  // store each set of points around the center of the cylinder
+  rectangular outer_cylinder[CIRCLE_POINTS]; // each y, z around outer circle
+  rectangular inner_cylinder[CIRCLE_POINTS]; // each y, z around inner circle
+  rectangular ring_of_pipes[NUM_BANDS];  // for wrapping pipes in a circle
+  GLfloat differ;             // holds the angle increment
+  GLfloat maxdropoff = 0.05;  // smooth changes in heights
+  GLfloat angle_step;
+  GLfloat adj_x;              // bar height adjustment
+  GLfloat repeat_index_adj;   // adj for repeating NUM_BANDS bars around spiral
+  int next_point;
+  static int first_time = 0;
+
+  for (t1 = 0, angle_step = 0;
+       t1 < CIRCLE_POINTS;
+       t1++, angle_step += ((M_PI * 2) / (float)CIRCLE_POINTS) )
+  { // get each point of each "circle" (more like a polygon)
+      outer_cylinder[t1].x_n = cos( angle_step ) *
+                               (PIPE_DIAMETER / 2.0f);
+      outer_cylinder[t1].z_n = sin( angle_step ) *
+                               (PIPE_DIAMETER / 2.0f);
+      inner_cylinder[t1].x_n = cos( angle_step ) *
+                               ((PIPE_DIAMETER - PIPE_THICKNESS) / 2.0f);
+      inner_cylinder[t1].z_n = sin( angle_step ) *
+                               ((PIPE_DIAMETER - PIPE_THICKNESS) / 2.0f);
+  }
+  for (t1 = 0; t1 < NUM_BANDS; t1++)
+  {
+      // smooth out the pipe length changes
+      differ = data1[t1] - data2[t1]; // calculate change in amplitude
+      if (fabs(differ) > maxdropoff)
+      {
+          if (differ > 0)
+              data2[t1] += maxdropoff;
+          else if (differ < 0)
+              data2[t1] -= maxdropoff;
+      }
+      else
+      {
+          data2[t1] += differ;
+      }
+      // work out the pipe placement
+      ring_of_pipes[t1].x_n = cos( t1 * PIPE_RING_ANGLE ) * 2;
+      ring_of_pipes[t1].z_n = sin( t1 * PIPE_RING_ANGLE ) * 2;
+  }
+
+  for (t3 = 0; t3 < REPEAT; t3++)
+  {
+      for (t1 = 0; t1 < NUM_BANDS; t1++)
+      { // iterate thru each pipe
+
+          glPushMatrix();
+          repeat_index_adj = t1 + (t3 * NUM_BANDS);
+          // now alter the model view matrix to put the pipe in the right 
position
+          glRotatef( PIPE_RING_ANGLE * repeat_index_adj, 0.0f, 0.5f, 0.0f );
+          glTranslatef( 0.5f + (0.05f * repeat_index_adj),
+                        (config_pipes.slope * repeat_index_adj), 0 );
+          glRotatef( -1 * PIPE_ANGLE * repeat_index_adj, 0.0f, 0.0f, 1.0f );
+
+          glBegin (GL_QUADS);
+          // draw each cylinder segment, from one end of the pipe to the other
+          for (t2 = 0; t2 < CIRCLE_POINTS; t2++)
+          {
+              if (t2 >= (CIRCLE_POINTS - 1))
+                  next_point = 0;
+              else
+                  next_point = t2 + 1;
+              // current angle to angle + PI / # of points
+              // can draw both inner and outer cylinder segments per angle
+              // also: split pipe height so we can do 
+              // color 2 -> color 1 -> color 2 along its height
+            
+              // top half of outer pipe segment
+              get_color( &red, &green, &blue, &data2[t1] ); // top color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "top-left"
+              glVertex3f( outer_cylinder[t2].x_n,
+                          data2[t1] * config_pipes.length,
+                          outer_cylinder[t2].z_n );
+
+              get_color( &red, &green, &blue, &y ); // bottom color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "middle-left"
+              glVertex3f( outer_cylinder[t2].x_n,
+                          0.0f,
+                          outer_cylinder[t2].z_n );
+              // "middle-right"
+              glVertex3f( outer_cylinder[next_point].x_n,
+                          0.0f, 
+                          outer_cylinder[next_point].z_n );
+
+              get_color( &red, &green, &blue, &data2[t1] ); // top color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "top-right"
+              glVertex3f( outer_cylinder[next_point].x_n,
+                          data2[t1] * config_pipes.length,
+                          outer_cylinder[next_point].z_n );
+
+              // top half of inner pipe segment
+              get_color( &red, &green, &blue, &data2[t1] ); // top color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "top-left"
+              glVertex3f( inner_cylinder[t2].x_n,
+                          data2[t1] * config_pipes.length,
+                          inner_cylinder[t2].z_n );
+
+              get_color( &red, &green, &blue, &y ); // bottom color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "middle-left"
+              glVertex3f( inner_cylinder[t2].x_n,
+                          0.0f,
+                          inner_cylinder[t2].z_n );
+              // "middle-right"
+              glVertex3f( inner_cylinder[next_point].x_n,
+                          0.0f, 
+                          inner_cylinder[next_point].z_n );
+
+              get_color( &red, &green, &blue, &data2[t1] ); // top color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "top-right"
+              glVertex3f( inner_cylinder[next_point].x_n,
+                          data2[t1] * config_pipes.length,
+                          inner_cylinder[next_point].z_n );
+
+              // now "cap" the ends of the pipe
+    
+              // cap "top" of pipe
+              get_color( &red, &green, &blue, &data2[t1] ); // top color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "outer-bottom"
+              glVertex3f( outer_cylinder[t2].x_n,
+                          data2[t1] * config_pipes.length,
+                          outer_cylinder[t2].z_n );
+              // "inner-bottom"
+              glVertex3f( inner_cylinder[t2].x_n,
+                          data2[t1] * config_pipes.length,
+                          inner_cylinder[t2].z_n );
+              // "inner-top"
+              glVertex3f( inner_cylinder[next_point].x_n,
+                          data2[t1] * config_pipes.length,
+                          inner_cylinder[next_point].z_n );
+              // "outer-top"
+              glVertex3f( outer_cylinder[next_point].x_n,
+                          data2[t1] * config_pipes.length,
+                          outer_cylinder[next_point].z_n );
+
+              // cap "bottom" of pipe
+              get_color( &red, &green, &blue, &y ); // bottom color
+              glColor4f( red / 2.0f, green / 2.0f, blue / 2.0f, 0.5f );
+              // "outer-bottom"
+              glVertex3f( outer_cylinder[t2].x_n,
+                          0.0f,
+                          outer_cylinder[t2].z_n );
+              // "inner-bottom"
+              glVertex3f( inner_cylinder[t2].x_n,
+                          0.0f,
+                          inner_cylinder[t2].z_n );
+              // "inner-top"
+              glVertex3f( inner_cylinder[next_point].x_n,
+                          0.0f,
+                          inner_cylinder[next_point].z_n );
+              // "outer-top"
+              glVertex3f( outer_cylinder[next_point].x_n,
+                          0.0f,
+                          outer_cylinder[next_point].z_n );
+          }
+          glEnd (); // specify each pipe separately
+          glPopMatrix();
+      }
+  }
+
+
+  first_time++;
+}
+
+
+static void
+config_read (ConfigFile * f, char *section_name)
+{
+  xmms_cfg_read_float (f, section_name, pipes_priority,
+                      &config_pipes.priority);
+  xmms_cfg_read_boolean (f, section_name, pipes_blend,
+                        &config_pipes.blend);
+  xmms_cfg_read_float (f, section_name, pipes_slope,
+                         &config_pipes.slope);
+  xmms_cfg_read_float (f, section_name, pipes_length,
+                         &config_pipes.length);
+}
+
+
+static void
+config_write (ConfigFile * f, char *section_name)
+{
+  xmms_cfg_write_float (f, section_name, pipes_priority,
+                       config_pipes.priority);
+  xmms_cfg_write_boolean (f, section_name, pipes_blend,
+                         config_pipes.blend);
+  xmms_cfg_write_float (f, section_name, pipes_slope,
+                         config_pipes.slope);
+  xmms_cfg_write_float (f, section_name, pipes_length,
+                         config_pipes.length);
+}
+
+
+static void
+config_default ()
+{
+  config_pipes.priority = 1.0;
+  config_pipes.blend = TRUE;
+  config_pipes.slope = -0.05;
+  config_pipes.length = 0.5;
+}
+
+
+static void
+blending_toggled (GtkWidget * widget, gpointer data)
+{
+  new_config_pipes.blend = !new_config_pipes.blend;
+}
+
+
+static void
+slope_changed (GtkAdjustment * adj)
+{
+  new_config_pipes.slope = (float)adj->value;
+}
+
+
+static void
+length_changed (GtkAdjustment * adj)
+{
+  new_config_pipes.length = (float)adj->value;
+}
+
+
+static void
+config_create (GtkWidget * vbox)
+{
+  GtkWidget *hbox;
+  GtkWidget *button;
+  GtkWidget *label;
+  GtkObject *adjustment;
+  GtkWidget *hscale;
+
+  memcpy (&new_config_pipes, &config_pipes,
+         sizeof (new_config_pipes));
+
+  /* blend mode */
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_widget_show (hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
+
+  button = gtk_check_button_new_with_label ("Alpha blending");
+  gtk_widget_show (button);
+  gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4);
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
+                               new_config_pipes.blend);
+  gtk_signal_connect (GTK_OBJECT (button), "toggled",
+                     GTK_SIGNAL_FUNC (blending_toggled), NULL);
+
+  /* slope in vertical direction */
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_widget_show (hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
+
+  label = gtk_label_new ("Rate of descent/ascent (vertical slope)");
+  gtk_widget_show (label);
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
+
+  adjustment =
+    gtk_adjustment_new (new_config_pipes.slope, -0.05, 0.05, 0.001, 0.01, 0);
+  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
+  gtk_scale_set_digits (GTK_SCALE (hscale), 2);
+  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 25);
+  gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE, 4);
+  gtk_widget_show (hscale);
+  gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
+                     GTK_SIGNAL_FUNC (slope_changed), NULL);
+
+  /* length of each pipe */
+  hbox = gtk_hbox_new (FALSE, 2);
+  gtk_widget_show (hbox);
+  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 4);
+
+  label = gtk_label_new ("Pipe length");
+  gtk_widget_show (label);
+  gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
+
+  adjustment =
+    gtk_adjustment_new (new_config_pipes.length, 0.5, 3.5, 0.1, 0.5, 0);
+  hscale = gtk_hscale_new (GTK_ADJUSTMENT (adjustment));
+  gtk_scale_set_digits (GTK_SCALE (hscale), 1);
+  gtk_widget_set_usize (GTK_WIDGET (hscale), 200, 25);
+  gtk_box_pack_start (GTK_BOX (hbox), hscale, FALSE, FALSE, 4);
+  gtk_widget_show (hscale);
+  gtk_signal_connect (GTK_OBJECT (adjustment), "value_changed",
+                     GTK_SIGNAL_FUNC (length_changed), NULL);
+}
+
+
+static void
+config_apply (void)
+{
+  memcpy (&config_pipes, &new_config_pipes,
+         sizeof (config_pipes));
+}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]