(→Links) |
(→Links) |
||
Line 272:
[http://s23.org/w/images/f/f9/Blinken_xmms.c.txt download source]
[[Category:Blinkenlights]]
|
Revision as of 23:39, 15 May 2007
blinken_xmms
Das blinken_xmms ist ein Spectrum-Analyser-Plugin für den Multimedia Player Xmms. Es sendet UDP-Pakete an 127.0.0.1:2323 im EBLP - extended Blinkenlights protocol mit 8x18 Pixeln. Die Ausgabe kann z.B. mit lldrv auf ein BlinkenLEDsPro umgeleitet werden.
Blinkt zu D&B Musik; erstellt mit blm2gif
(Graustufen werden leider nicht konvertiert)
Quellcode
Den Quellcode für das XMMS-Plugin habe ich mit Hilfe von Workshop: Vis-Plugins in XMMS und XMMS Plugin tutorial at nobugs.org erstellen können. Desweiteren waren Informationen zum EBLP - extended Blinkenlights protocol sehr nützlich. Der "Rechen-Kern" für die Visualisierung entspricht dem des spectrum Plugins.
Jetzt mit Graustufen!
blinken_xmms.c ! Beim Speichern --> Dateiname: blinken_xmms.c !
<highlightSyntax language="c">
/* BLINKEN_XMMS : for XMMS - Cross-platform multimedia player * * 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 forore details. * * You should have received a copy of the GNU General Public License * along with XMMS. */
/* Compile: * gcc -Wall --shared `xmms-config --cflags` -o blinken_xmms.so blinken_xmms.c * Install: * install blinken_plugin.so `xmms-config --visualization-plugin-dir` */
#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <math.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <xmms/plugin.h>
#define NUM_BANDS 18 #define WIDTH 18 #define HEIGHT 8
#define MSG {0xFE,0xED,0xBE,0xEF,0x00,0x00,0x00,0x00,0x00,0x012,0x00,0x08,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00,\ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}
static int sock; static unsigned char msg[156]=MSG; static unsigned char scalmsg[10] = {0x11, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0xAA, 0xCC, 0x00};
static gdouble scale; static gint16 bar_heights[NUM_BANDS];
void our_init(); void our_cleanup(); void our_playback_start(); void our_playback_stop(); void our_render_freq(gint16 data[1][256]);
VisPlugin g_our_plugin = { NULL, /* handle */ NULL, /* filename */ 0, /* session id */ "blinken_xmms", /* description */ 0, /* PCM Channels */ 1, /* Freq. Channels */ /* Callbacks ... */ our_init, /* init */ our_cleanup, /* cleanup */ NULL, /* about-dialog */ NULL, /* configure-dialog */ NULL, /* disable-plugin */ our_playback_start, /* playback-start */ our_playback_stop, /* playback-top */ NULL, /* render-pcm */ our_render_freq /* render-freq */ };
VisPlugin *get_vplugin_info(void) { return( & g_our_plugin); }
void our_init() { if ((sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { printf("couldn't create socket"); our_cleanup(); // programm mit fehlercode 1 beenden exit(1); }
// Struktur anlegen, mit Nullen initialisieren und füllen struct sockaddr_in dest_addr; memset(&dest_addr, 0, sizeof(dest_addr)); // alles mit Nullen fuellen dest_addr.sin_family = AF_INET; // muss hier nochmal stehen dest_addr.sin_port = htons(2323); // auf dem Port sollte UDP laufen dest_addr.sin_addr.s_addr = inet_addr("127.0.0.1"); // IP Adresse von 'localhost'
if (connect(sock, (struct sockaddr*) &dest_addr, sizeof(dest_addr)) == -1) { printf("couldn't connect to 127.0.0.1:2323"); our_cleanup(); exit(2); // mit fehlercode aussteigen }
send(sock, msg, 156, 0); // senden scale = (HEIGHT + 1)/ log(256); }
void our_cleanup() { close(sock); // wir schliessen den descriptor wieder }
void our_playback_start() { /*printf( "playback_start\n");*/ }
void our_playback_stop() { unsigned char msg[156]=MSG; send(sock, msg, 156, 0); }
void our_render_freq( gint16 data[1][256]) { int result,zeile,spalte; int i,j,c; gint y; gint xscale[NUM_BANDS] = {0, 1, 2, 3, 5, 7, 10, 14, 20, 28, 40, 54, 74, 85, 101, 137, 140, 150};
for(i = 0; i < NUM_BANDS; i++) { for(c = xscale[i], y = 0; c < xscale[i + 1]; c++) { if(data[0][c] > y) { y = data[0][c]; }
}
y >>= 7; if(y != 0) { y = (gint)(log(y) * scale); if(y > HEIGHT+1) { y = HEIGHT+1; }
}
bar_heights[i] = -y+9;
}
spalte = 0; zeile = 0; for(i=12;i<=155;i++) { j = i-12; zeile = j/18; spalte = j%18;
if((bar_heights[spalte])==zeile+1) { msg[i]=0xFF; } else if((bar_heights[spalte])<zeile+1) { msg[i]=scalmsg[bar_heights[spalte]]; } else { msg[i]=0x00; }
}
result = send(sock, msg, 156, 0); return; }
</highlightSyntax>
Installation
gcc -Wall --shared `xmms-config --cflags` -o blinken_xmms.so blinken_xmms.c
install blinken_plugin.so `xmms-config --visualization-plugin-dir`
Evtl. ist das dev. Paket von xmms erforderlich.
Nun kann man mit einem Rechtsklick auf das XMMS-Fenster im Menü: Visualisierung-->Visualisierungs-Plugins
blinken-xmms
auswählen. Um den UDP-Stream umzuleiten kann z.B
./BlinkenOutput -l 2323 -d /dev/lldrv
benutzt werden.
Test
<highlightSyntax remoteFile="http://www.s23.org/w/images/f/f9/Blinken_xmms.c.txt" language="c"></highlightSyntax>
<tasks> [3] Fix "highlightSyntax remoteFile" (mutante) </tasks>
The relevant code snippet
Here is the relevant code snippet from syntaxHighlightExtension.php. Do you see a problem?
<highlightSyntax language="php3">
/** * If its a remote file, open it up and parse the returned contents. */ } else if($argv["remoteFile"]){ $openFileName = $argv["remoteFile"]; $fp = fopen($openFileName, "r"); if(!$fp){ $output = "Error: Syntax Highlighter could not open the file ".$openFileName."
"; } else { $fileContents = fread($fp, 8096); fclose($fp);
$output .= "
Code from <a href=\"".$argv["remoteFile"]."\">".$argv["remoteFile"]."</a>
\n"; $output .= $highlighter->highlight_text($fileContents); $output .= "
";
} return $output; /** * Else we just want to highlight the code within the syntaxHighlight tags. */ } else {
</highlightSyntax>
Links
Blinken_xmms has been viewed <counter>page=Blinken_xmms&namespace=0</counter> times.