Mercurial > audlegacy
changeset 3020:6065d70cb790 trunk
replace old Vis with UiVis
author | Tomasz Mon <desowin@gmail.com> |
---|---|
date | Tue, 10 Jul 2007 11:32:54 +0200 |
parents | 80cf8f8b0651 |
children | e3d7490ffd15 |
files | src/audacious/Makefile src/audacious/playback.c src/audacious/ui_main.c src/audacious/ui_main.h src/audacious/ui_vis.c src/audacious/ui_vis.h src/audacious/visualization.c src/audacious/widgets/Makefile src/audacious/widgets/skin.c src/audacious/widgets/svis.c src/audacious/widgets/widgetcore.h |
diffstat | 11 files changed, 881 insertions(+), 39 deletions(-) [+] |
line wrap: on
line diff
--- a/src/audacious/Makefile Mon Jul 09 13:05:05 2007 +0200 +++ b/src/audacious/Makefile Tue Jul 10 11:32:54 2007 +0200 @@ -109,6 +109,7 @@ ui_skinned_button.c \ ui_skinned_textbox.c \ ui_skinned_number.c \ + ui_vis.c \ ui_skinselector.c \ ui_urlopener.c \ util.c \
--- a/src/audacious/playback.c Mon Jul 09 13:05:05 2007 +0200 +++ b/src/audacious/playback.c Tue Jul 10 11:32:54 2007 +0200 @@ -82,7 +82,7 @@ if (playback_get_playing()) playback_stop(); - vis_clear_data(mainwin_vis); + ui_vis_clear_data(mainwin_vis); svis_clear_data(mainwin_svis); mainwin_disable_seekbar();
--- a/src/audacious/ui_main.c Mon Jul 09 13:05:05 2007 +0200 +++ b/src/audacious/ui_main.c Tue Jul 10 11:32:54 2007 +0200 @@ -145,7 +145,7 @@ static gboolean setting_volume = FALSE; -Vis *mainwin_vis; +GtkWidget *mainwin_vis; SVis *mainwin_svis; HSlider *mainwin_sposition = NULL; @@ -266,7 +266,7 @@ MAINWIN_SHADED_HEIGHT * (cfg.doublesize + 1)); widget_show(WIDGET(mainwin_svis)); - vis_clear_data(mainwin_vis); + ui_vis_clear_data(mainwin_vis); gtk_widget_show(mainwin_srew); gtk_widget_show(mainwin_splay); @@ -392,11 +392,14 @@ if (mode == VIS_OFF) { if (cfg.player_shaded && cfg.player_visible) svis_clear(mainwin_svis); - else - vis_clear(mainwin_vis); + else { + ui_vis_clear(mainwin_vis); + ui_vis_set_visible(mainwin_vis, FALSE); + } } if (mode == VIS_ANALYZER || mode == VIS_SCOPE || mode == VIS_VOICEPRINT) { - vis_clear_data(mainwin_vis); + ui_vis_clear_data(mainwin_vis); + ui_vis_set_visible(mainwin_vis, TRUE); svis_clear_data(mainwin_svis); } } @@ -473,6 +476,26 @@ exit(EXIT_SUCCESS); } +void +mainwin_vis_cb(void) +{ + cfg.vis_type++; + + if (cfg.vis_type > VIS_OFF) + cfg.vis_type = VIS_ANALYZER; + + mainwin_vis_set_type(cfg.vis_type); +} + +void +mainwin_vis_menu_cb(void) +{ + gint x, y; + gdk_window_get_pointer(NULL, &x, &y, NULL); + ui_manager_popup_menu_show(GTK_MENU(mainwin_visualization_menu), + x, y, 3, GDK_CURRENT_TIME); +} + static void mainwin_destroy(GtkWidget * widget, gpointer data) { @@ -677,12 +700,12 @@ /* positioning and size attributes */ if (bmp_active_skin->properties.mainwin_vis_x && bmp_active_skin->properties.mainwin_vis_y) - widget_move(WIDGET(mainwin_vis), bmp_active_skin->properties.mainwin_vis_x, + gtk_fixed_move(GTK_FIXED(SKINNED_WINDOW(mainwin)->fixed), GTK_WIDGET(mainwin_vis), bmp_active_skin->properties.mainwin_vis_x, bmp_active_skin->properties.mainwin_vis_y); if (bmp_active_skin->properties.mainwin_vis_width) - widget_resize(WIDGET(mainwin_vis), bmp_active_skin->properties.mainwin_vis_width, - mainwin_vis->vs_widget.height); + gtk_widget_set_size_request(mainwin_vis, bmp_active_skin->properties.mainwin_vis_width*(1+cfg.doublesize), + UI_VIS(mainwin_vis)->height*(1+cfg.doublesize)); if (bmp_active_skin->properties.mainwin_text_x && bmp_active_skin->properties.mainwin_text_y) gtk_fixed_move(GTK_FIXED(SKINNED_WINDOW(mainwin)->fixed), GTK_WIDGET(mainwin_info), bmp_active_skin->properties.mainwin_text_x, @@ -794,11 +817,6 @@ else widget_hide(WIDGET(mainwin_menurow)); - if (bmp_active_skin->properties.mainwin_vis_visible) - widget_show(WIDGET(mainwin_vis)); - else - widget_hide(WIDGET(mainwin_vis)); - /* window size, mainwinWidth && mainwinHeight properties */ if (bmp_active_skin->properties.mainwin_height && bmp_active_skin->properties.mainwin_width) { @@ -949,7 +967,7 @@ playlistwin_hide_timer(); draw_main_window(TRUE); - vis_clear(mainwin_vis); + ui_vis_clear(mainwin_vis); } void @@ -1101,20 +1119,12 @@ } if ((event->button == 1) && event->type != GDK_2BUTTON_PRESS && - !cfg.player_shaded ? widget_contains(WIDGET(mainwin_vis), event->x, event->y) : widget_contains(WIDGET(mainwin_svis), event->x, event->y) ) { - - cfg.vis_type++; - - if (cfg.vis_type > VIS_OFF) - cfg.vis_type = VIS_ANALYZER; - - mainwin_vis_set_type(cfg.vis_type); + mainwin_vis_cb(); } if (event->button == 3) { - if (widget_contains(WIDGET(mainwin_vis), event->x, event->y) || - widget_contains(WIDGET(mainwin_svis), event->x, event->y)) { + if (widget_contains(WIDGET(mainwin_svis), event->x, event->y)) { ui_manager_popup_menu_show(GTK_MENU(mainwin_visualization_menu), event->x_root, event->y_root, 3, event->time); grab = FALSE; @@ -1917,7 +1927,7 @@ check_set( toggleaction_group_others , "show player" , TRUE ); if (cfg.player_shaded) - vis_clear_data(mainwin_vis); + ui_vis_clear_data(mainwin_vis); mainwin_set_shape_mask(); @@ -2021,7 +2031,6 @@ } draw_main_window(TRUE); - vis_set_doublesize(mainwin_vis, doublesize); } void @@ -2838,9 +2847,10 @@ g_signal_connect(mainwin_about, "clicked", show_about_window, NULL); g_signal_connect(mainwin_about, "right-clicked", mainwin_about_cb, NULL ); - mainwin_vis = - create_vis(&mainwin_wlist, mainwin_bg, mainwin->window, SKINNED_WINDOW(mainwin)->gc, - 24, 43, 76, cfg.doublesize); + mainwin_vis = ui_vis_new(SKINNED_WINDOW(mainwin)->fixed, 24, 43, 76); + g_signal_connect(mainwin_vis, "clicked", mainwin_vis_cb, NULL); + g_signal_connect(mainwin_vis, "right-clicked", mainwin_vis_menu_cb, NULL); + mainwin_svis = create_svis(&mainwin_wlist, mainwin_bg, SKINNED_WINDOW(mainwin)->gc, 79, 5); mainwin_position = @@ -2882,7 +2892,6 @@ ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_monostereo)); ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_playstatus)); - ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_vis)); ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_svis)); ui_skinned_window_widgetlist_associate(mainwin, WIDGET(mainwin_position)); @@ -2974,7 +2983,10 @@ gtk_widget_hide(mainwin_sec_num); gtk_widget_hide(mainwin_othertext); - vis_set_window(mainwin_vis, mainwin->window); + if (bmp_active_skin->properties.mainwin_vis_visible) + gtk_widget_show(mainwin_vis); + else + gtk_widget_hide(mainwin_vis); } void
--- a/src/audacious/ui_main.h Mon Jul 09 13:05:05 2007 +0200 +++ b/src/audacious/ui_main.h Tue Jul 10 11:32:54 2007 +0200 @@ -24,6 +24,7 @@ #include <gtk/gtk.h> #include "widgets/widgetcore.h" +#include "ui_vis.h" /* yes, main window size is fixed */ #define MAINWIN_WIDTH (gint)275 @@ -103,7 +104,7 @@ extern GtkWidget *mainwin_stime_min, *mainwin_stime_sec; -extern Vis *mainwin_vis; +extern GtkWidget *mainwin_vis; extern SVis *mainwin_svis; extern PlayStatus *mainwin_playstatus;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/ui_vis.c Tue Jul 10 11:32:54 2007 +0200 @@ -0,0 +1,731 @@ +/* + * Audacious - a cross-platform multimedia player + * Copyright (c) 2007 Audacious development team. + * + * Based on: + * BMP - Cross-platform multimedia player + * Copyright (C) 2003-2004 BMP development team. + * XMMS: + * Copyright (C) 1998-2003 XMMS development team. + * + * 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; under version 2 of the License. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#include "widgets/widgetcore.h" +#include "ui_vis.h" +#include "main.h" +#include "util.h" +#include "strings.h" +#include "playback.h" +#include <string.h> +#include <ctype.h> +#include <gtk/gtkmain.h> +#include <gtk/gtkmarshal.h> +#include <gtk/gtkimage.h> + +#define UI_TYPE_VIS (ui_vis_get_type()) + +static const gfloat vis_afalloff_speeds[] = { 0.34, 0.5, 1.0, 1.3, 1.6 }; +static const gfloat vis_pfalloff_speeds[] = { 1.2, 1.3, 1.4, 1.5, 1.6 }; +static const gint vis_redraw_delays[] = { 1, 2, 4, 8 }; +static const guint8 vis_scope_colors[] = + { 21, 21, 20, 20, 19, 19, 18, 19, 19, 20, 20, 21, 21 }; +static guchar voiceprint_data[76*16]; + +enum { + CLICKED, + RIGHT_CLICKED, + DOUBLED, + REDRAW, + LAST_SIGNAL +}; + +static void ui_vis_class_init (UiVisClass *klass); +static void ui_vis_init (UiVis *vis); +static void ui_vis_destroy (GtkObject *object); +static void ui_vis_realize (GtkWidget *widget); +static void ui_vis_unrealize (GtkWidget *widget); +static void ui_vis_size_request (GtkWidget *widget, GtkRequisition *requisition); +static void ui_vis_size_allocate (GtkWidget *widget, GtkAllocation *allocation); +static gboolean ui_vis_expose (GtkWidget *widget, GdkEventExpose *event); +static gboolean ui_vis_button_press (GtkWidget *widget, GdkEventButton *event); +static gboolean ui_vis_button_release (GtkWidget *widget, GdkEventButton *event); +static void ui_vis_toggle_doublesize (UiVis *vis); + +static GtkWidgetClass *parent_class = NULL; +static guint vis_signals[LAST_SIGNAL] = { 0 }; + +GType ui_vis_get_type() { + static GType vis_type = 0; + if (!vis_type) { + static const GTypeInfo vis_info = { + sizeof (UiVisClass), + NULL, + NULL, + (GClassInitFunc) ui_vis_class_init, + NULL, + NULL, + sizeof (UiVis), + 0, + (GInstanceInitFunc) ui_vis_init, + }; + vis_type = g_type_register_static (GTK_TYPE_WIDGET, "UiVis", &vis_info, 0); + } + + return vis_type; +} + +static void ui_vis_class_init(UiVisClass *klass) { + GtkObjectClass *object_class; + GtkWidgetClass *widget_class; + + object_class = (GtkObjectClass*) klass; + widget_class = (GtkWidgetClass*) klass; + parent_class = gtk_type_class (gtk_widget_get_type ()); + + object_class->destroy = ui_vis_destroy; + + widget_class->realize = ui_vis_realize; + widget_class->unrealize = ui_vis_unrealize; + widget_class->expose_event = ui_vis_expose; + widget_class->size_request = ui_vis_size_request; + widget_class->size_allocate = ui_vis_size_allocate; + widget_class->button_press_event = ui_vis_button_press; + widget_class->button_release_event = ui_vis_button_release; + + klass->clicked = NULL; + klass->right_clicked = NULL; + klass->doubled = ui_vis_toggle_doublesize; + + vis_signals[CLICKED] = + g_signal_new ("clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (UiVisClass, clicked), NULL, NULL, + gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + vis_signals[RIGHT_CLICKED] = + g_signal_new ("right-clicked", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (UiVisClass, right_clicked), NULL, NULL, + gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); + + vis_signals[DOUBLED] = + g_signal_new ("toggle-double-size", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION, + G_STRUCT_OFFSET (UiVisClass, doubled), NULL, NULL, + gtk_marshal_VOID__VOID, G_TYPE_NONE, 0); +} + +static void ui_vis_init(UiVis *vis) { + memset(voiceprint_data, 0, 16*76); +} + +GtkWidget* ui_vis_new(GtkWidget *fixed, gint x, gint y, gint width) { + UiVis *vis = g_object_new (ui_vis_get_type (), NULL); + + vis->x = x; + vis->y = y; + + vis->width = width; + vis->height = 16; + + vis->fixed = fixed; + vis->double_size = FALSE; + + vis->visible_window = TRUE; + + gtk_fixed_put(GTK_FIXED(vis->fixed), GTK_WIDGET(vis), vis->x, vis->y); + + return GTK_WIDGET(vis); +} + +static void ui_vis_destroy(GtkObject *object) { + UiVis *vis; + + g_return_if_fail (object != NULL); + g_return_if_fail (UI_IS_VIS (object)); + + vis = UI_VIS (object); + + if (GTK_OBJECT_CLASS (parent_class)->destroy) + (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); +} + +static void ui_vis_realize(GtkWidget *widget) { + UiVis *vis; + GdkWindowAttr attributes; + gint attributes_mask; + + g_return_if_fail (widget != NULL); + g_return_if_fail (UI_IS_VIS(widget)); + + GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED); + vis = UI_VIS(widget); + + attributes.x = widget->allocation.x; + attributes.y = widget->allocation.y; + attributes.width = widget->allocation.width; + attributes.height = widget->allocation.height; + attributes.window_type = GDK_WINDOW_CHILD; + attributes.event_mask = gtk_widget_get_events(widget); + attributes.event_mask |= GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK; + + if (vis->visible_window) + { + attributes.visual = gtk_widget_get_visual(widget); + attributes.colormap = gtk_widget_get_colormap(widget); + attributes.wclass = GDK_INPUT_OUTPUT; + 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); + } + else + { + attributes.wclass = GDK_INPUT_ONLY; + attributes_mask = GDK_WA_X | GDK_WA_Y; + 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); +} + +static void ui_vis_unrealize(GtkWidget *widget) { + UiVis *vis; + vis = UI_VIS(widget); + + if (GTK_WIDGET_CLASS (parent_class)->unrealize) + (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); +} + +static void ui_vis_size_request(GtkWidget *widget, GtkRequisition *requisition) { + UiVis *vis = UI_VIS(widget); + + requisition->width = vis->width*(1+vis->double_size); + requisition->height = vis->height*(1+vis->double_size); +} + +static void ui_vis_size_allocate(GtkWidget *widget, GtkAllocation *allocation) { + UiVis *vis = UI_VIS (widget); + + widget->allocation = *allocation; + widget->allocation.x *= (1+vis->double_size); + widget->allocation.y *= (1+vis->double_size); + if (GTK_WIDGET_REALIZED (widget)) + gdk_window_move_resize(widget->window, widget->allocation.x, widget->allocation.y, allocation->width, allocation->height); + + vis->x = widget->allocation.x/(vis->double_size ? 2 : 1); + vis->y = widget->allocation.y/(vis->double_size ? 2 : 1); +} + +static gboolean ui_vis_expose(GtkWidget *widget, GdkEventExpose *event) { + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (UI_IS_VIS (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + UiVis *vis = UI_VIS (widget); + + gint x, y, n, h = 0, h2; + gfloat delta; + guchar skin_col[2][3]; + guchar vis_color[24][3]; + guchar vis_voice_color[256][3], voice_c[3]; + guchar rgb_data[76 * 16 * 3 * 2 * 2], *ptr, c; + guint32 colors[24]; + GdkColor *fgc, *bgc; + GdkRgbCmap *cmap; + + if (!GTK_WIDGET_VISIBLE(widget)) + return FALSE; + + if (!vis->visible_window) + return FALSE; + + skin_get_viscolor(bmp_active_skin, vis_color); + for (y = 0; y < 24; y++) { + colors[y] = + vis_color[y][0] << 16 | vis_color[y][1] << 8 | vis_color[y][2]; + } + cmap = gdk_rgb_cmap_new(colors, 24); + + if (!vis->double_size) { + if(cfg.vis_type == VIS_VOICEPRINT /*&& cfg.voiceprint_mode != VOICEPRINT_NORMAL*/){ + memset(rgb_data, 0, 76 * 16 * 3); + } + else{ + memset(rgb_data, 0, 76 * 16); + for (y = 1; y < 16; y += 2) { + ptr = rgb_data + (y * 76); + for (x = 0; x < 76; x += 2, ptr += 2) + *ptr = 1; + } + } + } + else{ + if(cfg.vis_type == VIS_VOICEPRINT /*&& cfg.voiceprint_mode != VOICEPRINT_NORMAL*/){ + memset(rgb_data, 0, 3 * 4 * 16 * 76); + } + else{ + memset(rgb_data, 0, 152 * 32); + for (y = 1; y < 16; y += 2) { + ptr = rgb_data + (y * 304); + for (x = 0; x < 76; x += 2, ptr += 4) { + *ptr = 1; + *(ptr + 1) = 1; + *(ptr + 152) = 1; + *(ptr + 153) = 1; + } + } + } + } + if (cfg.vis_type == VIS_ANALYZER) { + for (x = 0; x < 75; x++) { + if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0) + h = vis->data[x >> 2]; + else if (cfg.analyzer_type == ANALYZER_LINES) + h = vis->data[x]; + if (h && (cfg.analyzer_type == ANALYZER_LINES || + (x % 4) != 3)) { + if (!vis->double_size) { + ptr = rgb_data + ((16 - h) * 76) + x; + switch (cfg.analyzer_mode) { + case ANALYZER_NORMAL: + for (y = 0; y < h; y++, ptr += 76) + *ptr = 18 - h + y; + break; + case ANALYZER_FIRE: + for (y = 0; y < h; y++, ptr += 76) + *ptr = y + 2; + break; + case ANALYZER_VLINES: + for (y = 0; y < h; y++, ptr += 76) + *ptr = 18 - h; + break; + } + } + else{ + ptr = rgb_data + ((16 - h) * 304) + (x << 1); + switch (cfg.analyzer_mode) { + case ANALYZER_NORMAL: + for (y = 0; y < h; y++, ptr += 304) { + *ptr = 18 - h + y; + *(ptr + 1) = 18 - h + y; + *(ptr + 152) = 18 - h + y; + *(ptr + 153) = 18 - h + y; + } + break; + case ANALYZER_FIRE: + for (y = 0; y < h; y++, ptr += 304) { + *ptr = y + 2; + *(ptr + 1) = y + 2; + *(ptr + 152) = y + 2; + *(ptr + 153) = y + 2; + } + break; + case ANALYZER_VLINES: + for (y = 0; y < h; y++, ptr += 304) { + *ptr = 18 - h; + *(ptr + 1) = 18 - h; + *(ptr + 152) = 18 - h; + *(ptr + 153) = 18 - h; + } + + break; + } + } + } + } + if (cfg.analyzer_peaks) { + for (x = 0; x < 75; x++) { + if (cfg.analyzer_type == ANALYZER_BARS && (x % 4) == 0) + h = vis->peak[x >> 2]; + else if (cfg.analyzer_type == ANALYZER_LINES) + h = vis->peak[x]; + if (h && (cfg.analyzer_type == ANALYZER_LINES || (x % 4) != 3)){ + + if (!vis->double_size) { + rgb_data[(16 - h) * 76 + x] = 23; + } + else{ + ptr = rgb_data + (16 - h) * 304 + (x << 1); + *ptr = 23; + *(ptr + 1) = 23; + *(ptr + 152) = 23; + *(ptr + 153) = 23; + } + } + } + } + } + else if (cfg.vis_type == VIS_VOICEPRINT) { + if(!playback_get_paused() && playback_get_playing()){/*Don't scroll when it's paused or stopped*/ + for (y = 0; y < 16; y ++) + for (x = 75; x > 0; x--) + voiceprint_data[x + y * 76] = voiceprint_data[x-1+y*76]; + for(y=0;y<16;y++) + voiceprint_data[y * 76] = vis->data[y]; + } + if(playback_get_playing()){ /*Only draw the data if we're playing*/ + if(cfg.voiceprint_mode == VOICEPRINT_NORMAL){ + /* Create color gradient from the skin's background- and foreground color*/ + fgc = skin_get_color(bmp_active_skin, SKIN_TEXTFG); + bgc = skin_get_color(bmp_active_skin, SKIN_TEXTBG); + skin_col[0][0] = fgc->red >> 8; + skin_col[0][1] = fgc->green >> 8; + skin_col[0][2] = fgc->blue >> 8; + skin_col[1][0] = bgc->red >> 8; + skin_col[1][1] = bgc->green >> 8; + skin_col[1][2] = bgc->blue >> 8; + for(n=0;n<3;n++){ + for(x=0;x<256;x++){ + if(skin_col[0][n] > skin_col[1][n]){ + delta = (gfloat)(skin_col[0][n] - skin_col[1][n]) / 256.0; + vis_voice_color[x][n] = skin_col[1][n] + (gfloat)(delta * x); + } + else if(skin_col[0][n] == skin_col[1][n]){ + vis_voice_color[x][n] = skin_col[0][n]; + } + else{ + delta = (gfloat)(skin_col[1][n] - skin_col[0][n]) / 256.0; + vis_voice_color[x][n] = skin_col[1][n] - (gfloat)(delta * x); + } + } + } + } + for (y = 0; y < 16; y ++){ + for (x = 0; x < 76; x++){ + guint8 d = voiceprint_data[x + y*76]; + + if(cfg.voiceprint_mode == VOICEPRINT_NORMAL){ + voice_c[0] = vis_voice_color[d][0]; + voice_c[1] = vis_voice_color[d][1]; + voice_c[2] = vis_voice_color[d][2]; + } + else if(cfg.voiceprint_mode == VOICEPRINT_FIRE){ + voice_c[0] = d < 64 ? (d * 2) : 255; + voice_c[1] = d < 64 ? 0 : (d < 128 ? (d-64) * 2 : 255); + voice_c[2] = d < 128 ? 0 : (d-128) * 2; + /* Test for black->blue->green->red. Isn't pretty, though... + voice_c[0] = d > 192 ? (d - 192) << 2 : 0; + voice_c[1] = d > 64 ? (d < 128 ? (d - 64) << 2 : (d < 192 ? (192 - d) << 2 : 0)) : 0; + voice_c[2] = d < 64 ? d << 2 : (d < 128 ? (128 - d) << 2 : 0); + */ + } + else if(cfg.voiceprint_mode == VOICEPRINT_ICE){ + voice_c[0] = d; + voice_c[1] = d < 128 ? d * 2 : 255; + voice_c[2] = d < 64 ? d * 4 : 255; + } + if(!vis->double_size){ + for(n=0;n<3;n++) + rgb_data[x * 3 + y * 76*3+n] = voice_c[n]; + } + else{ + ptr = rgb_data + x * 3 * 2 + y * 2 * 76 * 3 * 2; + for(n=0;n<3;n++) + { + *(ptr + n) = voice_c[n]; + *(ptr + n + 3) = voice_c[n]; + *(ptr + n + 76 * 2 * 3) = voice_c[n]; + *(ptr + n + 3 + 76 * 2 * 3) = voice_c[n]; + } + } + } + } + } + } + if (cfg.vis_type == VIS_SCOPE) { + for (x = 0; x < 75; x++) { + switch (cfg.scope_mode) { + case SCOPE_DOT: + h = vis->data[x]; + if (!vis->double_size) { + ptr = rgb_data + ((14 - h) * 76) + x; + *ptr = vis_scope_colors[h + 1]; + }else{ + ptr = rgb_data + ((14 - h) * 304) + (x << 1); + *ptr = vis_scope_colors[h + 1]; + *(ptr + 1) = vis_scope_colors[h + 1]; + *(ptr + 152) = vis_scope_colors[h + 1]; + *(ptr + 153) = vis_scope_colors[h + 1]; + } + break; + case SCOPE_LINE: + if (x != 74) { + h = 14 - vis->data[x]; + h2 = 14 - vis->data[x + 1]; + if (h > h2) { + y = h; + h = h2; + h2 = y; + } + if (!vis->double_size) { + ptr = rgb_data + (h * 76) + x; + for (y = h; y <= h2; y++, ptr += 76) + *ptr = vis_scope_colors[y - 2]; + } + else{ + ptr = rgb_data + (h * 304) + (x << 1); + for (y = h; y <= h2; y++, ptr += 304) { + *ptr = vis_scope_colors[y - 2]; + *(ptr + 1) = vis_scope_colors[y - 2]; + *(ptr + 152) = vis_scope_colors[y - 2]; + *(ptr + 153) = vis_scope_colors[y - 2]; + } + } + } + else { + h = 14 - vis->data[x]; + if (!vis->double_size) { + ptr = rgb_data + (h * 76) + x; + *ptr = vis_scope_colors[h + 1]; + }else{ + ptr = rgb_data + (h * 304) + (x << 1); + *ptr = vis_scope_colors[h + 1]; + *(ptr + 1) = vis_scope_colors[h + 1]; + *(ptr + 152) = vis_scope_colors[h + 1]; + *(ptr + 153) = vis_scope_colors[h + 1]; + } + } + break; + case SCOPE_SOLID: + h = 14 - vis->data[x]; + h2 = 8; + c = vis_scope_colors[(gint) vis->data[x]]; + if (h > h2) { + y = h; + h = h2; + h2 = y; + } + if (!vis->double_size) { + ptr = rgb_data + (h * 76) + x; + for (y = h; y <= h2; y++, ptr += 76) + *ptr = c; + }else{ + ptr = rgb_data + (h * 304) + (x << 1); + for (y = h; y <= h2; y++, ptr += 304) { + *ptr = c; + *(ptr + 1) = c; + *(ptr + 152) = c; + *(ptr + 153) = c; + } + } + break; + } + } + } + + GdkPixmap *obj = NULL; + GdkGC *gc; + obj = gdk_pixmap_new(NULL, vis->width*(1+vis->double_size), vis->height*(1+vis->double_size), gdk_rgb_get_visual()->depth); + gc = gdk_gc_new(obj); + + if (!vis->double_size) { + if (cfg.vis_type == VIS_VOICEPRINT) { + gdk_draw_rgb_image(obj, gc, 0, 0, vis->width, vis->height, + GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data, + 76 * 3); + } else { + gdk_draw_indexed_image(obj, gc, 0, 0, vis->width, vis->height, + GDK_RGB_DITHER_NORMAL, (guchar *) rgb_data, + 76 , cmap); + } + } else { + if (cfg.vis_type == VIS_VOICEPRINT) { + gdk_draw_rgb_image(obj, gc, 0 << 1, 0 << 1, + vis->width << 1, vis->height << 1, + GDK_RGB_DITHER_NONE, (guchar *) rgb_data, + 76 * 2 * 3); + } else { + gdk_draw_indexed_image(obj, gc, 0 << 1, 0 << 1, + vis->width << 1, vis->height << 1, + GDK_RGB_DITHER_NONE, (guchar *) rgb_data, + 76 * 2 , cmap); + } + } + + gdk_draw_drawable (widget->window, gc, obj, 0, 0, 0, 0, + vis->width*(1+vis->double_size), vis->height*(1+vis->double_size)); + g_object_unref(obj); + g_object_unref(gc); + gdk_rgb_cmap_free(cmap); + return FALSE; +} + +static gboolean ui_vis_button_press(GtkWidget *widget, GdkEventButton *event) { + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (UI_IS_VIS (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + if (event->type == GDK_BUTTON_PRESS) { + if (event->button == 1) { + g_signal_emit(widget, vis_signals[CLICKED], 0); + } + } + + return TRUE; +} + +static gboolean ui_vis_button_release(GtkWidget *widget, GdkEventButton *event) { + g_return_val_if_fail (widget != NULL, FALSE); + g_return_val_if_fail (UI_IS_VIS (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); + + if (event->button == 3) + g_signal_emit(widget, vis_signals[RIGHT_CLICKED], 0); + + return TRUE; +} + +static void ui_vis_toggle_doublesize(UiVis *vis) { + GtkWidget *widget = GTK_WIDGET (vis); + vis->double_size = !vis->double_size; + + gtk_widget_set_size_request(widget, vis->width*(1+vis->double_size), vis->height*(1+vis->double_size)); + + gtk_widget_queue_draw(GTK_WIDGET(vis)); +} + +void ui_vis_draw_pixel(GtkWidget *widget, guchar* texture, gint x, gint y, guint8 colour) { + UiVis *vis = UI_VIS (widget); + if (vis->double_size){ + texture[y * 76 + x] = colour; + texture[y * 76 + x + 1] = colour; + texture[y * 76 * 4 + x] = colour; + texture[y * 76 * 4 + x + 1] = colour; + } else { + texture[y * 76 + x] = colour; + } +} + +void ui_vis_set_visible(GtkWidget *widget, gboolean window_is_visible) +{ + UiVis *vis; + gboolean widget_is_visible; + + g_return_if_fail(UI_IS_VIS(widget)); + + vis = UI_VIS (widget); + widget_is_visible = GTK_WIDGET_VISIBLE(widget); + + vis->visible_window = window_is_visible; + + if (GTK_WIDGET_REALIZED (widget)) + { + if ( widget_is_visible ) + gtk_widget_hide(widget); + + gtk_widget_unrealize(widget); + gtk_widget_realize(widget); + + if ( widget_is_visible ) + gtk_widget_show(widget); + } + + if (widget_is_visible) + gtk_widget_queue_resize(widget); +} + +void ui_vis_clear(GtkWidget *widget) { + UiVis *vis = UI_VIS (widget); + gdk_window_clear_area(widget->window, 0, + 0, vis->width, + vis->height); +} + +void ui_vis_clear_data(GtkWidget *widget) { + gint i; + UiVis *vis = UI_VIS (widget); + + memset(voiceprint_data, 0, 16*76); + for (i = 0; i < 75; i++) { + vis->data[i] = (cfg.vis_type == VIS_SCOPE) ? 6 : 0; + vis->peak[i] = 0; + } +} + +void ui_vis_timeout_func(GtkWidget *widget, guchar * data) { + UiVis *vis = UI_VIS (widget); + static GTimer *timer = NULL; + gulong micros = 9999999; + gboolean falloff = FALSE; + gint i; + + if (!timer) { + timer = g_timer_new(); + g_timer_start(timer); + } + else { + g_timer_elapsed(timer, µs); + if (micros > 14000) + g_timer_reset(timer); + } + if (cfg.vis_type == VIS_ANALYZER) { + if (micros > 14000) + falloff = TRUE; + if (data || falloff) { + for (i = 0; i < 75; i++) { + if (data && data[i] > vis->data[i]) { + vis->data[i] = data[i]; + if (vis->data[i] > vis->peak[i]) { + vis->peak[i] = vis->data[i]; + vis->peak_speed[i] = 0.01; + + } + else if (vis->peak[i] > 0.0) { + vis->peak[i] -= vis->peak_speed[i]; + vis->peak_speed[i] *= + vis_pfalloff_speeds[cfg.peaks_falloff]; + if (vis->peak[i] < vis->data[i]) + vis->peak[i] = vis->data[i]; + if (vis->peak[i] < 0.0) + vis->peak[i] = 0.0; + } + } + else if (falloff) { + if (vis->data[i] > 0.0) { + vis->data[i] -= + vis_afalloff_speeds[cfg.analyzer_falloff]; + if (vis->data[i] < 0.0) + vis->data[i] = 0.0; + } + if (vis->peak[i] > 0.0) { + vis->peak[i] -= vis->peak_speed[i]; + vis->peak_speed[i] *= + vis_pfalloff_speeds[cfg.peaks_falloff]; + if (vis->peak[i] < vis->data[i]) + vis->peak[i] = vis->data[i]; + if (vis->peak[i] < 0.0) + vis->peak[i] = 0.0; + } + } + } + } + } + else if (cfg.vis_type == VIS_VOICEPRINT && data){ + for(i = 0; i < 16; i++) + { + vis->data[i] = data[15 - i]; + } + } + else if (data) { + for (i = 0; i < 75; i++) + vis->data[i] = data[i]; + } + + if (micros > 14000) { + if (!vis->refresh_delay) { + gtk_widget_queue_draw(widget); + vis->refresh_delay = vis_redraw_delays[cfg.vis_refresh]; + } + vis->refresh_delay--; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/audacious/ui_vis.h Tue Jul 10 11:32:54 2007 +0200 @@ -0,0 +1,100 @@ +/* + * Audacious - a cross-platform multimedia player + * Copyright (c) 2007 Audacious development team. + * + * 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; under version 2 of the License. + * + * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +#ifndef UIVIS_H +#define UIVIS_H + +#include <gdk/gdk.h> +#include <gtk/gtkadjustment.h> +#include <gtk/gtkwidget.h> + +#ifdef __cplusplus +extern "C" { +#endif + +#define UI_VIS(obj) GTK_CHECK_CAST (obj, ui_vis_get_type (), UiVis) +#define UI_VIS_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, ui_vis_get_type (), UiVisClass) +#define UI_IS_VIS(obj) GTK_CHECK_TYPE (obj, ui_vis_get_type ()) + +typedef enum { + VIS_ANALYZER, VIS_SCOPE, VIS_VOICEPRINT, VIS_OFF +} VisType; + +typedef enum { + ANALYZER_NORMAL, ANALYZER_FIRE, ANALYZER_VLINES +} AnalyzerMode; + +typedef enum { + ANALYZER_LINES, ANALYZER_BARS +} AnalyzerType; + +typedef enum { + SCOPE_DOT, SCOPE_LINE, SCOPE_SOLID +} ScopeMode; +typedef enum { + VOICEPRINT_NORMAL, VOICEPRINT_FIRE, VOICEPRINT_ICE +} VoiceprintMode; + + +typedef enum { + VU_NORMAL, VU_SMOOTH +} VUMode; + +typedef enum { + REFRESH_FULL, REFRESH_HALF, REFRESH_QUARTER, REFRESH_EIGTH +} RefreshRate; + +typedef enum { + FALLOFF_SLOWEST, FALLOFF_SLOW, FALLOFF_MEDIUM, FALLOFF_FAST, + FALLOFF_FASTEST +} FalloffSpeed; + +typedef struct _UiVis UiVis; +typedef struct _UiVisClass UiVisClass; + +struct _UiVis { + GtkWidget widget; + + gint x, y, width, height; + gfloat data[75], peak[75], peak_speed[75]; + gint refresh_delay; + gboolean double_size; + GtkWidget *fixed; + gboolean visible_window; +}; + +struct _UiVisClass { + GtkWidgetClass parent_class; + void (* clicked) (UiVis *vis); + void (* right_clicked) (UiVis *vis); + void (* doubled) (UiVis *vis); +}; + +GtkWidget* ui_vis_new (GtkWidget *fixed, gint x, gint y, gint width); +GtkType ui_vis_get_type(void); +void ui_vis_set_vis(GtkWidget *widget, gint num); +void ui_vis_clear_data(GtkWidget *widget); +void ui_vis_clear(GtkWidget *widget); +void ui_vis_timeout_func(GtkWidget *widget, guchar * data); +void ui_vis_set_visible(GtkWidget *widget, gboolean window_is_visible); + +#ifdef __cplusplus +} +#endif + +#endif
--- a/src/audacious/visualization.c Mon Jul 09 13:05:05 2007 +0200 +++ b/src/audacious/visualization.c Tue Jul 10 11:32:54 2007 +0200 @@ -286,7 +286,7 @@ if (cfg.player_shaded && cfg.player_visible) svis_timeout_func(mainwin_svis, NULL); else - vis_timeout_func(mainwin_vis, NULL); + ui_vis_timeout_func(mainwin_vis, NULL); } return; } @@ -466,5 +466,5 @@ if (cfg.player_shaded && cfg.player_visible) svis_timeout_func(mainwin_svis, intern_vis_data); else - vis_timeout_func(mainwin_vis, intern_vis_data); + ui_vis_timeout_func(mainwin_vis, intern_vis_data); }
--- a/src/audacious/widgets/Makefile Mon Jul 09 13:05:05 2007 +0200 +++ b/src/audacious/widgets/Makefile Tue Jul 10 11:32:54 2007 +0200 @@ -23,7 +23,6 @@ hslider.c \ menurow.c \ monostereo.c \ - vis.c \ svis.c \ playstatus.c \ playlist_list.c \
--- a/src/audacious/widgets/skin.c Mon Jul 09 13:05:05 2007 +0200 +++ b/src/audacious/widgets/skin.c Tue Jul 10 11:32:54 2007 +0200 @@ -168,7 +168,6 @@ draw_playlist_window(TRUE); draw_equalizer_window(TRUE); - vis_set_window(mainwin_vis, mainwin->window); playlistwin_update_list(playlist_get_active()); return TRUE;