Beispiel #1
0
/* This detects changes in the title, and also draws the title when appropriate.
 * It should be called once for each frame.
 */
static guchar *show_info(guchar *img, gint height, gint bpl)
{
	gint pos, length;
	gchar *title;
	time_t now;
	static int prevpos;
	static gchar *prevtitle;
	static char buf[200];
	static time_t start, then;
	static gboolean persistent = FALSE;
	char	showinfo;

	/* Once per second, check for any changes in the title.  Note that we
	 * do this even for the "Never show title" setting, because a change
	 * in the title should trigger "quiet" actions even if the title isn't
	 * shown.
	 */
	time(&now);
	if (now != then)
	{
		then = now;
		pos = cf_position;
		title = (gchar*)cf_title.c_str();
/*		pos = xmms_remote_get_playlist_pos(0);
		title = xmms_remote_get_playlist_title(0, pos);*/
		if (!title) {
			title = "Unknown";
		}
		
		
		if (pos != prevpos || !prevtitle || strcmp(title, prevtitle))
		{
			
			/* Yes, it changed.  Regenerate the info string */
			prevpos = pos;
			if (prevtitle)
				free(prevtitle);
			prevtitle = strdup(title);
			
			sprintf(buf, "{%d} %s", pos + 1, title);
			
			start = now;

			/* Trigger "quiet" acctions. */
			beatquiet = TRUE;
		}
	}

	/* If the user pressed 'i' recently, then show info for 4 seconds */
	showinfo = *config.show_info;
	if (blurskinfo || persistent)
	{
		if (showinfo == 'A')
		{
			config.show_info = config_default_show_info;
			showinfo = 'N';
		}
		else
		{
			showinfo = '4';
			if (blurskinfo)
			{
				start = now;
				persistent = TRUE;
			}
		}
		blurskinfo = FALSE;
	}

	/* If not supposed to show text, then we're done */
	switch (showinfo)
	{
	  case 'N': /* Never show info */
		return img;

	  case '4': /* 4 second info */
		if (now - start > 4)
		{
			persistent = FALSE;
			return img;
		}

	  case 'A': /* Always show info */
		break;
	}

	/* We don't want to draw onto the main image, because then the text
	 * would leave blur trails.  Most combinations of cpu_speed and
	 * overall_effect copy the image data into a temporary buffer, but
	 * the specific combination of cpu_speed=Fast and overall_effect=Normal
	 * (which is very common!) normally leaves the image in the main buffer.
	 * We need to detect this, and copy the image before we draw the text.
	 */
	if (img != img_tmp)
	{
		memcpy(img_tmp, img, img_chunks * 8);
		img = img_tmp;
	}
	
	/* draw the text */
	textdraw(img, height, bpl, "Center", buf);
	return img;
}
Beispiel #2
0
static unsigned char *show_info(unsigned char *img, int height, int bpl)
{
    int pos, length;
    time_t now;
    static int prevpos;
    static char buf[1000];
    static time_t start, then;
    static int persistent = FALSE;
    char showinfo;
    char posstr[32], lenstr[32];

    if(songinfo == NULL || visual_songinfo_get_type(songinfo) == VISUAL_SONGINFO_TYPE_NULL)
        return img;

    time(&now);
    if(now != then)
    {
        then = now;
        pos = visual_songinfo_get_elapsed (songinfo);

        convert_ms_to_timestamp(posstr, pos);
        length = visual_songinfo_get_length(songinfo);
        convert_ms_to_timestamp(lenstr, length);
        if(pos != prevpos)
        {
            prevpos = pos;
            beatquiet = TRUE;
            switch(visual_songinfo_get_type(songinfo))
            {
                case VISUAL_SONGINFO_TYPE_SIMPLE:
                    if(config.show_timestamp)
                    {
                        if(lenstr != NULL)
                            sprintf(buf, "{%s/%s} %s", posstr, lenstr, visual_songinfo_get_simple_name(songinfo));
                        else
                            sprintf(buf, "(%s) %s", posstr, visual_songinfo_get_simple_name(songinfo));
                        break;
                    }
                    else
                    {
                        sprintf(buf, "%s", visual_songinfo_get_simple_name (songinfo));
                    }

                case VISUAL_SONGINFO_TYPE_ADVANCED:
                    if(config.show_timestamp)
                    {
                        if(strcmp(visual_songinfo_get_artist(songinfo), "(null)") == 0)
                        {
                            if(length >= 0)
                                sprintf(buf, "{%s/%s} %s", posstr, lenstr, visual_songinfo_get_song(songinfo));
                            else
                                sprintf(buf, "(%s) %s", posstr, visual_songinfo_get_song(songinfo));
                        }
                        else
                        {
                            if(length >= 0)
                                sprintf(buf, "{%s/%s} %s by %s", posstr, lenstr,
                                    visual_songinfo_get_song(songinfo), visual_songinfo_get_artist(songinfo));
                            else
                                sprintf(buf, "(%s) %s by %s", posstr,
                                    visual_songinfo_get_song(songinfo), visual_songinfo_get_artist(songinfo));
                        }
                    }
                    else
                    {
                        if(strcmp(visual_songinfo_get_artist(songinfo), "(null)") == 0)
                        {
                            if(strcmp(visual_songinfo_get_song(songinfo), "(null)") != 0)
                                sprintf(buf, "%s", visual_songinfo_get_song(songinfo));
                        }
                        else
                        {
                            sprintf(buf, "%s by %s", visual_songinfo_get_song(songinfo), visual_songinfo_get_artist(songinfo));
                        }
                    }
                    break;


                default:
                    break;
            }
        }
    }

    showinfo = *config.show_info;
    if(blurskinfo || persistent)
    {
        if(showinfo == 'N')
            return img;

        if(blurskinfo)
        {
            start = now;
            persistent = TRUE;
        }
        blurskinfo = FALSE;
    }

    /* If not supposed to show text, then we're done */
    switch(showinfo) {
        case 'N': /* Never show info */
            return img;
        case 'T': /* 4 second info */
            if(now - start > config.info_timeout)
            {
                persistent = FALSE;
                return img;
            }
        case 'A': /* Always show info */
            break;
    }

    /* We don't want to draw onto the main image, because then the text
     * would leave blur trails.  Most combinations of cpu_speed and
     * overall_effect copy the image data into a temporary buffer, but
     * the specific combination of cpu_speed=Fast and overall_effect=Normal
     * (which is very common!) normally leaves the image in the main buffer.
     * We need to detect this, and copy the image before we draw the text.
     */
    if (img != img_tmp)
    {
        memcpy(img_tmp, img, img_chunks * 8);
        img = img_tmp;
    }

    /* draw the text */
    textdraw(img, height, bpl, "Center", buf);
    return img;
}