void playlist_manager::playlist_activate_delta(int p_delta) {
	const t_size total = get_playlist_count();
	if (total > 0) {
		t_size active = get_active_playlist();
		
		//clip p_delta to -(total-1)...(total-1) range
		if (p_delta < 0) {
			p_delta = - ( (-p_delta) % (t_ssize)total );
		} else {
			p_delta = p_delta % total;
		}
		if (p_delta != 0) {
			if (active == pfc_infinite) {
				//special case when no playlist is active
				if (p_delta > 0) {
					active = (t_size)(p_delta - 1);
				} else {
					active = (total + p_delta);//p_delta is negative
				}
			} else {
				active = (t_size) (active + total + p_delta) % total;
			}
			set_active_playlist(active % total);
		}
	}
}
Exemple #2
0
bool playlist_switcher::find_or_create_playlist_activate(const char * name)
{
	bool rv = false;
	unsigned idx = find_or_create_playlist(name);
	if (idx != (unsigned)(-1))
		rv = set_active_playlist(idx);
	return rv;
}
bool playlist_manager::highlight_playing_item()
{
	t_size playlist,item;
	if (!get_playing_item_location(&playlist,&item)) return false;
	set_active_playlist(playlist);
	playlist_set_focus_item(playlist,item);
	playlist_set_selection(playlist,bit_array_true(),bit_array_one(item));
	playlist_ensure_visible(playlist,item);
	return true;
}
Exemple #4
0
/**
 * parse a 'play playlist' or like command.
 * Will first search for the palylist by name,
 * if this fails, search for it by index instead,
 * for a number has been parsed
 */
sp_playlist* parse_play_command(sp_session* session, char *buffer,
                                struct play_queue* node)
{
    sp_playlist *playlist = NULL;

    /* split on ' ', leaving just the name or id of the playlist */
    char *tok;
    tok = strchr(buffer, ' ');

    /* If plain play command */
    if(tok == NULL) {
        playlist = playlist_find_by_num(session, pc);
        if(playlist != NULL) {
            set_active_playlist(session, playlist, node);
            return playlist;
        }
        return NULL;
    } else tok = (tok +1);

    /* Check playlist name first */
    playlist = playlist_find_by_name(pc, tok);
    if(playlist != NULL) {
        printf("Loading playlist %s\n", tok);
        set_active_playlist(session, playlist, node);
        return playlist;
    }

    /* Playlist name not found. Fallback on index */
    int playlist_id;
    if(sscanf( tok, "%d", &playlist_id ) == 1) {
        printf("Match index!\n");
        playlist = playlist_play_by_index(session, pc, playlist_id);
        if(playlist != NULL) {
            set_active_playlist(session, playlist, node);
            return playlist;
        } else {
            printf("Playlist nr.'%d' is not ready!\n", playlist_id );
            return NULL;
        }
    }
    printf("Could not find a playlist with name '%s'\n", buffer + strlen("play ") );
    return NULL;
}
void playlist_manager::active_playlist_fix()
{
	t_size playlist = get_active_playlist();
	if (playlist == pfc_infinite)
	{
		t_size max = get_playlist_count();
		if (max == 0)
		{
			create_playlist_autoname();
		}
		set_active_playlist(0);
	}
}
Exemple #6
0
bool playlist_switcher::delete_playlist_autoswitch(unsigned idx)
{
	unsigned num,active;
	num = get_num_playlists();
	active = get_active_playlist();
	if (idx>=num || num<=1) return false;
	if (idx==active)
	{
		if (idx+1>=num) active = idx-1;
		else active = idx+1;
		set_active_playlist(active);
	}
	return delete_playlist(idx);
}
bool playlist_manager::remove_playlist_switch(t_size idx)
{
	bool need_switch = get_active_playlist() == idx;
	if (remove_playlist(idx))
	{
		if (need_switch)
		{
			t_size total = get_playlist_count();
			if (total > 0)
			{
				if (idx >= total) idx = total-1;
				set_active_playlist(idx);
			}
		}
		return true;
	}
	else return false;
}