Esempio n. 1
0
int playlist_list_get_playlist_position(PlayList_List *pl, int x, int y)
{
	int iy, length;
	
	if (!inside_widget(x, y, pl) || !pl->pl_fheight)
		return -1;

	if ((length = get_playlist_length()) == 0)
		return -1;
	iy = y - pl->pl_widget.y;

	return(MIN((iy / pl->pl_fheight) + pl->pl_first, length - 1));
}
Esempio n. 2
0
gboolean playlist_save(char *filename, gboolean is_pls)
{
    GList *node;
    FILE *file;

    if ((file = fopen(filename, "w")) == NULL)
        return FALSE;

    if (is_pls)
    {
        is_pls = TRUE;
        fprintf(file, "[playlist]\n");
        fprintf(file, "NumberOfEntries=%d\n", get_playlist_length());
    }
    else if (cfg.use_pl_metadata)
        fprintf(file, "#EXTM3U\n");

    PL_LOCK();
    node = playlist;
    while (node)
    {
        PlaylistEntry *entry = node->data;
        if (is_pls)
            fprintf(file, "File%d=%s\n",
                    g_list_position(playlist, node) + 1,
                    entry->filename);
        else
        {
            if (entry->title && cfg.use_pl_metadata)
            {
                int seconds;

                if (entry->length > 0)
                    seconds = (entry->length) / 1000;
                else
                    seconds = -1;

                fprintf(file, "#EXTINF:%d,%s\n",
                        seconds, entry->title);
            }
            fprintf(file, "%s\n", entry->filename);
        }
        node = g_list_next(node);
    }
    PL_UNLOCK();
    return (fclose(file) == 0);
}
Esempio n. 3
0
void playlist_display (int argc, char * * argv)
{
    int entries = get_playlist_length ();

    fauxdtool_report ("%d track%s.", entries, entries != 1 ? "s" : "");

    int total = 0;

    for (int entry = 0; entry < entries; entry ++)
    {
        char * title = get_entry_title (entry);
        int length = get_entry_length (entry) / 1000;

        total += length;

        /* adjust width for multi byte characters */
        int column = 60;

        for (const char * p = title; * p; p = g_utf8_next_char (p))
        {
            int stride = g_utf8_next_char (p) - p;

            if (g_unichar_iswide (g_utf8_get_char (p)) ||
             g_unichar_iswide_cjk (g_utf8_get_char (p)))
                column += (stride - 2);
            else
                column += (stride - 1);
        }

        char * fmt = g_strdup_printf ("%%4d | %%-%ds | %%d:%%.2d", column);
        fauxdtool_report (fmt, entry + 1, title, length / 60, length % 60);

        g_free (fmt);
        g_free (title);
    }

    fauxdtool_report ("Total length: %d:%.2d", total / 60, total % 60);
}
Esempio n. 4
0
void playlist_play(void)
{
    char *filename = NULL;

    if (get_playlist_length() == 0)
        return;

    /* If the user wants a skin randomly selected on play */
    if (cfg.random_skin_on_play)
    {
        /* Get the current skin list */
        scan_skins();
        /* If there are entries */
        if (g_list_length(skinlist)) {
            /* Get a random value to select the skin to use */
            int randval = (gint)(random() / (RAND_MAX + 1.0) * (g_list_length(skinlist) + 1));
            /* If the random value is 0, use the default skin */
            /* Otherwise subtract 1 from the random value and */
            /* select the skin */
            if (randval == 0)
                load_skin(NULL);
            else
            {
                struct SkinNode *skin;
                skin = g_list_nth(skinlist, randval - 1)->data;
                load_skin(skin->path);
            }
        }
        /* Call scan_skins() again to make sure skin selector */
        /* is up to date */
        scan_skins();
    }

    if (get_input_playing())
        input_stop();

    vis_clear_data(mainwin_vis);
    vis_clear_data(playlistwin_vis);
    svis_clear_data(mainwin_svis);
    mainwin_disable_seekbar();

    PL_LOCK();
    if (playlist)
    {
        if (!playlist_position)
        {
            if (cfg.shuffle)
                playlist_position = shuffle_list->data;
            else
                playlist_position = playlist->data;
        }
        filename = playlist_position->filename;
    }
    PL_UNLOCK();

    if (!filename)
        return;

    input_play(filename);

    if (input_get_time() != -1)
    {
        equalizerwin_load_auto_preset(filename);
        input_set_eq(cfg.equalizer_active, cfg.equalizer_preamp,
                     cfg.equalizer_bands);
    }
    playlist_check_pos_current();
}
Esempio n. 5
0
void playlist_list_button_press_cb(GtkWidget * widget, GdkEventButton * event, PlayList_List * pl)
{
	if (event->button == 1 && pl->pl_fheight &&
	    inside_widget(event->x, event->y, &pl->pl_widget))
	{
		int nr, y;

		y = event->y - pl->pl_widget.y;
		nr = (y / pl->pl_fheight) + pl->pl_first;
		if (nr >= get_playlist_length())
			nr = get_playlist_length() - 1;
		if (!(event->state & GDK_CONTROL_MASK))
			playlist_select_all(FALSE);
		
		if (event->state & GDK_SHIFT_MASK && pl->pl_prev_selected != -1)
		{
			playlist_select_range(pl->pl_prev_selected, nr, TRUE);
			pl->pl_prev_min = pl->pl_prev_selected;
			pl->pl_prev_max = nr;
			pl->pl_drag_pos = nr - pl->pl_first;
		}
		else
		{
			if (playlist_select_invert(nr))
			{
				if (event->state & GDK_CONTROL_MASK)
				{
					if (pl->pl_prev_min == -1)
					{
						pl->pl_prev_min =
							pl->pl_prev_selected;
						pl->pl_prev_max =
							pl->pl_prev_selected;
					}
					if (nr < pl->pl_prev_min)
						pl->pl_prev_min = nr;
					else if (nr > pl->pl_prev_max)
						pl->pl_prev_max = nr;
				}
				else
					pl->pl_prev_min = -1;
				pl->pl_prev_selected = nr;
				pl->pl_drag_pos = nr - pl->pl_first;
			}
		}
		if (event->type == GDK_2BUTTON_PRESS)
		{
			/*
			 * Ungrab the pointer to prevent us from
			 * hanging on to it during the sometimes slow
			 * playlist_play().
			 */
			gdk_pointer_ungrab(GDK_CURRENT_TIME);
			gdk_flush();
			playlist_set_position(nr);
			if (!get_input_playing())
				playlist_play();
		}
		pl->pl_dragging = TRUE;
		playlistwin_update_list();
	}
}
Esempio n. 6
0
void playlist_length (int argc, char * * argv)
{
    fauxdtool_report ("%d", get_playlist_length ());
}