marlin r1282 - in trunk: marlin src src/other
- From: iain svn gnome org
- To: svn-commits-list gnome org
- Subject: marlin r1282 - in trunk: marlin src src/other
- Date: Tue, 30 Sep 2008 22:52:00 +0000 (UTC)
Author: iain
Date: Tue Sep 30 22:52:00 2008
New Revision: 1282
URL: http://svn.gnome.org/viewvc/marlin?rev=1282&view=rev
Log:
Make the levels calculations work
Make the levels bounce up and down correctly
Modified:
trunk/marlin/ChangeLog
trunk/marlin/marlin-jack-play.c
trunk/marlin/marlin-jack.c
trunk/marlin/marlin-jack.h
trunk/src/ChangeLog
trunk/src/marlin-window.c
trunk/src/other/gtkvumeter.c
Modified: trunk/marlin/marlin-jack-play.c
==============================================================================
--- trunk/marlin/marlin-jack-play.c (original)
+++ trunk/marlin/marlin-jack-play.c Tue Sep 30 22:52:00 2008
@@ -435,7 +435,7 @@
{
MarlinJackPlay *jack = data;
MarlinJackPlayPrivate *priv = jack->priv;
- long generated;
+ long generated = 0;
float *tmp_frames[2];
int i;
@@ -459,12 +459,7 @@
guint frames_needed;
bytes_free = jack_ringbuffer_write_space (pd->rb);
-#if 0
- /* Only fill it up when its half empty */
- if (bytes_free < (DEFAULT_RB_SIZE * frame_size) / 2) {
- continue;
- }
-#endif
+
frames_needed = bytes_free / frame_size;
if (frames_needed == 0) {
continue;
@@ -481,7 +476,11 @@
generated * frame_size);
}
- marlin_jack_emit_levels ((MarlinJack *) jack, tmp_frames, generated);
+ if (generated > 0) {
+ marlin_jack_emit_levels ((MarlinJack *) jack,
+ (float **) tmp_frames, generated);
+ }
+
priv->mode = MARLIN_JACK_PLAY_MODE_PLAYING;
return TRUE;
@@ -527,6 +526,7 @@
priv = GET_PRIVATE (jack);
if (priv->sample == NULL) {
+ g_warning ("No sample to play");
return FALSE;
}
@@ -747,7 +747,14 @@
&status, server_name);
if (priv->client == NULL) {
/* Make error */
- g_warning ("No jacky client\n");
+ if (*error != NULL) {
+ *error = g_error_new (MARLIN_JACK_ERROR,
+ MARLIN_JACK_ERROR_NO_SERVER,
+ "Unable to run JACK server - JACK status was %d", status);
+ } else {
+ g_warning ("Unable to run JACK server - JACK status was %d");
+ }
+
g_object_unref (jack);
return NULL;
}
Modified: trunk/marlin/marlin-jack.c
==============================================================================
--- trunk/marlin/marlin-jack.c (original)
+++ trunk/marlin/marlin-jack.c Tue Sep 30 22:52:00 2008
@@ -2,7 +2,7 @@
/*
* Authors: Iain Holmes <iain gnome org>
*
- * Copyright 2002 - 2007 Iain Holmes
+ * Copyright 2002 - 2008 Iain Holmes
*
* This file is free software; you can redistribute it and/or
* modify it under the terms of version 2 of the GNU General Public
@@ -269,17 +269,16 @@
}
void
-calculate_peak_and_rms (double *data,
+calculate_peak_and_rms (float *data,
int n_frames,
double *peak,
double *rms)
{
int i;
double p = 0.0, total = 0.0;
-
+
for (i = 0; i < n_frames; i++) {
- double squared = pow (data[i], 2);
- double o = p;
+ double squared = pow ((double) (data[i]), 2);
p = MAX (p, squared);
total += squared;
@@ -287,15 +286,15 @@
*peak = sqrt (p);
*rms = sqrt (total / (double) n_frames);
-
}
void
marlin_jack_emit_levels (MarlinJack *jack,
- double **data,
+ float **data,
int n_frames)
{
MarlinJackPrivate *priv = GET_PRIVATE (jack);
+ double p, r;
double peak[2] = { 0.0, 0.0 };
double rms[2] = { 0.0, 0.0 };
@@ -303,14 +302,20 @@
return;
}
-#if 0
- calculate_peak_and_rms (data[0], n_frames, &(peak[0]), &(rms[0]));
- if (priv->channels > 1) {
- calculate_peak_and_rms (data[1], n_frames, &peak[1], &rms[1]);
+ if (n_frames == 0) {
+ return;
}
+ calculate_peak_and_rms (data[0], n_frames, &p, &r);
+ peak[0] = p;
+ rms[0] = r;
- g_signal_emit (jack, signals[LEVEL_CHANGED], 0,
+ if (priv->channels > 1) {
+ calculate_peak_and_rms (data[1], n_frames, &p, &r);
+ peak[1] = p;
+ rms[1] = r;
+ }
+
+ g_signal_emit (jack, signals[LEVEL_CHANGED], 0,
priv->channels, peak, rms);
-#endif
}
Modified: trunk/marlin/marlin-jack.h
==============================================================================
--- trunk/marlin/marlin-jack.h (original)
+++ trunk/marlin/marlin-jack.h Tue Sep 30 22:52:00 2008
@@ -78,7 +78,7 @@
void marlin_jack_continue (MarlinJack *jack);
void marlin_jack_emit_levels (MarlinJack *jack,
- double **data,
+ float **data,
int n_frames);
G_END_DECLS
Modified: trunk/src/marlin-window.c
==============================================================================
--- trunk/src/marlin-window.c (original)
+++ trunk/src/marlin-window.c Tue Sep 30 22:52:00 2008
@@ -2,10 +2,10 @@
/*
* Authors: Iain Holmes <iain gnome org>
*
- * Copyright 2002-2006 Iain Holmes
+ * Copyright 2002-2008 Iain Holmes
*
* This program is free software; you can redistribute it and/or modify
- * it under the terms of version 2 of the GNU General Public
+ * it under the terms of version 2 of the GNU General Public
* License as published by the Free Foundation.
*
* This program is distributed in the hope that it will be useful,
@@ -1389,7 +1389,7 @@
GtkWidget *vumeter;
MarlinWindowPrivate *priv;
int i;
-
+
priv = window->priv;
for (i = 0; i < channels; i++) {
@@ -1405,7 +1405,7 @@
if (window_icon == NULL) {
char *filename;
filename = marlin_file ("marlin/marlin-icon.png");
-
+
window_icon = gdk_pixbuf_new_from_file (filename, NULL);
g_free (filename);
}
Modified: trunk/src/other/gtkvumeter.c
==============================================================================
--- trunk/src/other/gtkvumeter.c (original)
+++ trunk/src/other/gtkvumeter.c Tue Sep 30 22:52:00 2008
@@ -5,7 +5,7 @@
* Fri Jan 10 20:06:23 2003
* Copyright 2003 Todd Goyen
* wettoad knighthoodofbuh org
- * Modified by Iain Holmes - Copyright (C) 2004-2006
+ * Modified by Iain Holmes - Copyright (C) 2004-2008
****************************************************************************/
#include <math.h>
@@ -40,11 +40,11 @@
PROP_SCALE
};
-GType
+GType
gtk_vumeter_get_type (void)
{
static GType vumeter_type = 0;
-
+
if (!vumeter_type) {
static const GTypeInfo vumeter_info = {
sizeof (GtkVUMeterClass),
@@ -54,16 +54,16 @@
(GInstanceInitFunc) gtk_vumeter_init,
};
- vumeter_type = g_type_register_static (GTK_TYPE_WIDGET,
- "GtkVUMeter",
+ vumeter_type = g_type_register_static (GTK_TYPE_WIDGET,
+ "GtkVUMeter",
&vumeter_info, 0);
}
-
+
return vumeter_type;
}
/* Orientation should be a property */
-GtkWidget*
+GtkWidget*
gtk_vumeter_new (GtkVUMeterOrientation orientation)
{
GtkVUMeter *vumeter;
@@ -73,7 +73,7 @@
return GTK_WIDGET (vumeter);
}
-static void
+static void
gtk_vumeter_init (GtkVUMeter *vumeter)
{
vumeter->peaks_falloff = GTK_VUMETER_PEAKS_FALLOFF_MEDIUM;
@@ -129,25 +129,25 @@
{
}
-static void
+static void
gtk_vumeter_class_init (GtkVUMeterClass *class)
{
GObjectClass *object_class;
GtkWidgetClass *widget_class;
-
+
object_class = (GObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
parent_class = gtk_type_class(gtk_widget_get_type());
-
+
object_class->finalize = gtk_vumeter_finalize;
object_class->set_property = set_property;
object_class->get_property = get_property;
-
+
widget_class->realize = gtk_vumeter_realize;
widget_class->unrealize = gtk_vumeter_unrealize;
widget_class->expose_event = gtk_vumeter_expose;
widget_class->size_request = gtk_vumeter_size_request;
- widget_class->size_allocate = gtk_vumeter_size_allocate;
+ widget_class->size_allocate = gtk_vumeter_size_allocate;
g_object_class_install_property (object_class,
PROP_SCALE,
@@ -158,22 +158,22 @@
G_PARAM_READWRITE));
}
-static void
+static void
gtk_vumeter_finalize (GObject *object)
{
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-static void
+static void
gtk_vumeter_realize (GtkWidget *widget)
{
GtkVUMeter *vumeter;
GdkWindowAttr attributes;
int attributes_mask;
-
+
GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED);
vumeter = GTK_VUMETER (widget);
-
+
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
@@ -185,12 +185,12 @@
attributes.colormap = gtk_widget_get_colormap (widget);
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (widget->parent->window, &attributes, attributes_mask);
-
+
widget->style = gtk_style_attach (widget->style, widget->window);
-
+
gdk_window_set_user_data (widget->window, widget);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
-
+
/* colors */
vumeter->colormap = gdk_colormap_get_system ();
gtk_vumeter_setup_colors (vumeter);
@@ -216,17 +216,17 @@
GTK_WIDGET_CLASS (parent_class)->unrealize (widget);
}
-static void
-gtk_vumeter_size_request (GtkWidget *widget,
+static void
+gtk_vumeter_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkVUMeter *vumeter;
-
+
g_return_if_fail (GTK_IS_VUMETER (widget));
g_return_if_fail (requisition != NULL);
-
+
vumeter = GTK_VUMETER (widget);
-
+
switch (vumeter->orientation) {
case GTK_VUMETER_VERTICAL:
requisition->width = VERTICAL_VUMETER_WIDTH;
@@ -240,41 +240,41 @@
}
}
-static void
+static void
gtk_vumeter_size_allocate (GtkWidget *widget,
GtkAllocation *allocation)
{
GtkVUMeter *vumeter;
-
+
widget->allocation = *allocation;
vumeter = GTK_VUMETER (widget);
-
+
if (GTK_WIDGET_REALIZED (widget) == FALSE) {
return;
}
switch (vumeter->orientation) {
case GTK_VUMETER_VERTICAL:
- gdk_window_move_resize (widget->window,
+ gdk_window_move_resize (widget->window,
allocation->x, allocation->y,
VERTICAL_VUMETER_WIDTH, allocation->height);
break;
-
+
case GTK_VUMETER_HORIZONTAL:
- gdk_window_move_resize (widget->window,
+ gdk_window_move_resize (widget->window,
allocation->x, allocation->y,
allocation->width, HORIZONTAL_VUMETER_HEIGHT);
break;
-
+
default:
break;
}
-
+
gtk_vumeter_setup_colors (vumeter);
}
-static gint
-gtk_vumeter_expose (GtkWidget *widget,
+static gint
+gtk_vumeter_expose (GtkWidget *widget,
GdkEventExpose *event)
{
GtkVUMeter *vumeter;
@@ -284,36 +284,36 @@
if (event->count > 0) {
return FALSE;
}
-
+
vumeter = GTK_VUMETER (widget);
- rms_level = gtk_vumeter_sound_level_to_draw_level (vumeter,
+ rms_level = gtk_vumeter_sound_level_to_draw_level (vumeter,
vumeter->rms_level);
- peak_level = gtk_vumeter_sound_level_to_draw_level (vumeter,
+ peak_level = gtk_vumeter_sound_level_to_draw_level (vumeter,
vumeter->peak_level);
switch (vumeter->orientation) {
case GTK_VUMETER_VERTICAL:
width = widget->allocation.width - 2;
height = widget->allocation.height;
-
+
/* draw border */
- gtk_paint_box (widget->style, widget->window,
- GTK_STATE_NORMAL, GTK_SHADOW_IN,
- NULL, widget, "", 0, 0,
+ gtk_paint_box (widget->style, widget->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_IN,
+ NULL, widget, "", 0, 0,
widget->allocation.width, height);
-
+
for (index = peak_level; index < rms_level; index++) {
- gdk_gc_set_foreground (vumeter->bg_gc,
+ gdk_gc_set_foreground (vumeter->bg_gc,
&vumeter->b_colors[index]);
- gdk_draw_line (widget->window, vumeter->bg_gc,
- 1, index + 1,
- width, index + 1);
+ gdk_draw_line (widget->window, vumeter->bg_gc,
+ 1, index + 1,
+ width, index + 1);
}
-
+
for (index = widget->allocation.height - 3; index > rms_level; index--) {
- gdk_gc_set_foreground (vumeter->fg_gc,
+ gdk_gc_set_foreground (vumeter->fg_gc,
&vumeter->f_colors[index]);
- gdk_draw_line (widget->window, vumeter->fg_gc,
- 1, index + 1,
+ gdk_draw_line (widget->window, vumeter->fg_gc,
+ 1, index + 1,
width, index + 1);
}
@@ -322,29 +322,29 @@
case GTK_VUMETER_HORIZONTAL:
width = widget->allocation.width;
height = widget->allocation.height - 2;
-
+
/* draw border */
/* FIXME: Tell Thomas there's a bug in Clearlooks
that means I can't use trough as the detail here */
- gtk_paint_box (widget->style, widget->window,
- GTK_STATE_NORMAL, GTK_SHADOW_IN,
- NULL, widget, "", 0, 0,
+ gtk_paint_box (widget->style, widget->window,
+ GTK_STATE_NORMAL, GTK_SHADOW_IN,
+ NULL, widget, "", 0, 0,
width, widget->allocation.height);
for (index = rms_level; index < peak_level; index++) {
- gdk_gc_set_foreground (vumeter->bg_gc,
+ gdk_gc_set_foreground (vumeter->bg_gc,
&vumeter->b_colors[index]);
- gdk_draw_line (widget->window, vumeter->bg_gc,
- width - index - 1, 1,
- width - index - 1, height);
+ gdk_draw_line (widget->window, vumeter->bg_gc,
+ width - index - 1, 1,
+ width - index - 1, height);
}
for (index = peak_level; index < width - 2; index++) {
gdk_gc_set_foreground (vumeter->fg_gc,
&vumeter->f_colors[index]);
gdk_draw_line (widget->window, vumeter->bg_gc,
- width - index - 1, 1,
- width - index - 1, height);
+ width - index - 1, 1,
+ width - index - 1, height);
}
break;
@@ -352,11 +352,11 @@
default:
break;
}
-
+
return FALSE;
}
-static void
+static void
gtk_vumeter_free_colors (GtkVUMeter *vumeter)
{
if (vumeter->f_colors) {
@@ -374,38 +374,38 @@
}
}
-static void
+static void
gtk_vumeter_setup_colors (GtkVUMeter *vumeter)
{
int index, colours;
int f_step, b_step;
int first, second;
int log_max = 0;
-
+
g_return_if_fail (vumeter->colormap != NULL);
-
+
if (vumeter->orientation == GTK_VUMETER_VERTICAL) {
colours = MAX (GTK_WIDGET (vumeter)->allocation.height - 2, 0);
} else {
colours = MAX (GTK_WIDGET (vumeter)->allocation.width - 2, 0);
}
-
+
if (colours == vumeter->colors) {
return;
}
-
+
gtk_vumeter_free_colors (vumeter);
-
+
vumeter->colors = colours;
if (vumeter->colors == 0)
return;
vumeter->f_colors = g_malloc (vumeter->colors * sizeof (GdkColor));
- vumeter->b_colors = g_malloc (vumeter->colors * sizeof (GdkColor));
-
+ vumeter->b_colors = g_malloc (vumeter->colors * sizeof (GdkColor));
+
if (vumeter->scale == MARLIN_SCALE_LINEAR) {
first = vumeter->colors / 2;
- second = vumeter->colors;
+ second = vumeter->colors;
} else {
log_max = -20 * log10 (1.0 / 20.0);
@@ -416,11 +416,11 @@
vumeter->f_colors[0].red = 65535;
vumeter->f_colors[0].green = 0;
vumeter->f_colors[0].blue = 0;
-
+
vumeter->b_colors[0].red = 49151;
vumeter->b_colors[0].green = 0;
vumeter->b_colors[0].blue = 0;
-
+
/* Allocate from Red to Yellow */
f_step = 65535 / (first - 1);
b_step = 49151 / (first - 1);
@@ -435,9 +435,9 @@
vumeter->b_colors[index].blue = 0;
}
- /* Allocate from Yellow to Green */
+ /* Allocate from Yellow to Green */
f_step = 65535 / (second - first);
- b_step = 49151 / (second - first);
+ b_step = 49151 / (second - first);
for (index = first; index < second; index++) {
vumeter->f_colors[index].red = vumeter->f_colors[index - 1].red - f_step;
@@ -446,13 +446,13 @@
vumeter->b_colors[index].red = vumeter->b_colors[index - 1].red - b_step;
vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green;
- vumeter->b_colors[index].blue = 0;
+ vumeter->b_colors[index].blue = 0;
}
if (vumeter->scale == MARLIN_SCALE_LOG) {
/* Allocate from Green to Dark Green */
f_step = 32767 / (vumeter->colors - second);
- b_step = 32767 / (vumeter->colors - second);
+ b_step = 32767 / (vumeter->colors - second);
for (index = second; index < vumeter->colors; index++) {
vumeter->f_colors[index].red = 0;
@@ -461,58 +461,58 @@
vumeter->b_colors[index].red = 0;
vumeter->b_colors[index].green = vumeter->b_colors[index - 1].green - b_step;
- vumeter->b_colors[index].blue = 0;
+ vumeter->b_colors[index].blue = 0;
}
}
for (index = 0; index < vumeter->colors; index++) {
- gdk_colormap_alloc_color (vumeter->colormap,
- &vumeter->f_colors[index],
+ gdk_colormap_alloc_color (vumeter->colormap,
+ &vumeter->f_colors[index],
FALSE, TRUE);
- gdk_colormap_alloc_color (vumeter->colormap,
- &vumeter->b_colors[index],
+ gdk_colormap_alloc_color (vumeter->colormap,
+ &vumeter->b_colors[index],
FALSE, TRUE);
}
}
-static int
-gtk_vumeter_sound_level_to_draw_level (GtkVUMeter *vumeter,
+static int
+gtk_vumeter_sound_level_to_draw_level (GtkVUMeter *vumeter,
double level)
{
double draw_level;
double height;
double log_level;
-
+
height = GTK_WIDGET (vumeter)->allocation.height - 2;
-
+
if (vumeter->scale == MARLIN_SCALE_LINEAR) {
draw_level = 0;
} else {
log_level = level / MARLIN_MIN_DB;
draw_level = log_level * height;
}
-
+
return (int) draw_level;
}
-void
-gtk_vumeter_set_levels (GtkVUMeter *vumeter,
- double rms,
+void
+gtk_vumeter_set_levels (GtkVUMeter *vumeter,
+ double rms,
double peak)
{
g_return_if_fail (vumeter != NULL);
g_return_if_fail (GTK_IS_VUMETER (vumeter));
- vumeter->rms_level = CLAMP (rms, MARLIN_MIN_DB, MARLIN_MAX_DB);
- vumeter->peak_level = CLAMP (peak, MARLIN_MIN_DB, MARLIN_MAX_DB);
+ vumeter->rms_level = MARLIN_MIN_DB - (rms * MARLIN_MIN_DB);
+ vumeter->peak_level = MARLIN_MIN_DB - (peak * MARLIN_MIN_DB);
- gtk_widget_queue_draw (GTK_WIDGET (vumeter));
+ gtk_widget_queue_draw (GTK_WIDGET (vumeter));
}
/* Should be set as a property */
-void
-gtk_vumeter_set_peaks_falloff (GtkVUMeter *vumeter,
+void
+gtk_vumeter_set_peaks_falloff (GtkVUMeter *vumeter,
GtkVUMeterFallOff falloff)
{
g_return_if_fail (GTK_IS_VUMETER (vumeter));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]