Exemplo n.º 1
0
int
cmd_outputs(mpd_unused int argc, mpd_unused char **argv, mpd_Connection *conn)
{
	mpd_OutputEntity * output;

	mpd_sendOutputsCommand( conn );
	while(( output = mpd_getNextOutput( conn ))) {
		/* We increment by 1 to make it natural to the user  */
		output->id++;

		/* If it's a negative number a password is needed  */
		if( output->id > 0 )
		{
			if( output->enabled ) {
				printf( "Output %i (%s) is enabled\n", output->id, output->name );
			} else {
				printf( "Output %i (%s) is disabled\n", output->id, output->name );
			}
		}
		else
		{
			DIE( "cannot receive the current outputs\n" );
		}
		mpd_freeOutputElement( output );
	}
	mpd_finishCommand( conn );
	return( 0 );
}
Exemplo n.º 2
0
MpdData * mpd_server_get_output_devices(MpdObj *mi)
{
    mpd_OutputEntity *output = NULL;
    MpdData *data = NULL;
    if(!mpd_check_connected(mi))
    {
        debug_printf(DEBUG_WARNING,"not connected\n");
        return NULL;
    }
    /* TODO: Check version */
    if(mpd_lock_conn(mi))
    {
        debug_printf(DEBUG_ERROR,"lock failed\n");
        return NULL;
    }

    mpd_sendOutputsCommand(mi->connection);
    while (( output = mpd_getNextOutput(mi->connection)) != NULL)
    {	
        data = mpd_new_data_struct_append(data);
        data->type = MPD_DATA_TYPE_OUTPUT_DEV; 
        data->output_dev = output;
    }
    mpd_finishCommand(mi->connection);

    /* unlock */
    mpd_unlock_conn(mi);
    if(data == NULL) 
    {
        return NULL;
    }
    return mpd_data_get_first(data);
}
Exemplo n.º 3
0
QList<MPDOutput> MPDConnection::outputs() {
	QList<MPDOutput> outputs;
	if (!isConnected() || version() < 12)
		return outputs;

	Q_ASSERT(d->connection);
	mpd_call(MPDConnection::outputs, Outputs);
	for (mpd_OutputEntity *output; (output = mpd_getNextOutput(d->connection)) != NULL; ) {
		outputs << MPDOutput(output);
		mpd_freeOutputElement(output);
	}
	if (!finishCommand())
		outputs.clear();

	return outputs;
}
Exemplo n.º 4
0
int mpd_status_update(MpdObj *mi)
{
	ChangedStatusType what_changed=0;
	if(!mpd_check_connected(mi))
	{
		debug_printf(DEBUG_INFO,"not connected\n");
		return MPD_NOT_CONNECTED;
	}
	if(mpd_lock_conn(mi))
	{
		debug_printf(DEBUG_ERROR,"lock failed\n");
		return MPD_LOCK_FAILED;
	}



	if(mi->status != NULL)
	{
		mpd_freeStatus(mi->status);
		mi->status = NULL;
	}
	mpd_sendStatusCommand(mi->connection);
	mi->status = mpd_getStatus(mi->connection);
	if(mi->status == NULL)
	{
		debug_printf(DEBUG_ERROR,"Failed to grab status from mpd\n");
		mpd_unlock_conn(mi);
		return MPD_STATUS_FAILED;
	}
	if(mpd_unlock_conn(mi))
	{
		debug_printf(DEBUG_ERROR, "Failed to unlock");
		return MPD_LOCK_FAILED;
	}
	/*
	 * check for changes 
	 */
	/* first save the old status */
	memcpy(&(mi->OldState), &(mi->CurrentState), sizeof(MpdServerState));

	/* playlist change */
	if(mi->CurrentState.playlistid != mi->status->playlist)
	{
		/* print debug message */
		debug_printf(DEBUG_INFO, "Playlist has changed!");

		/* We can't trust the current song anymore. so we remove it */
		/* tags might have been updated */
		if(mi->CurrentSong != NULL)
		{
			mpd_freeSong(mi->CurrentSong);
			mi->CurrentSong = NULL;
		}

		/* set MPD_CST_PLAYLIST to be changed */
		what_changed |= MPD_CST_PLAYLIST;

        if(mi->CurrentState.playlistLength == mi->status->playlistLength)
        {
//            what_changed |= MPD_CST_SONGID; 
        }
		/* save new id */
		mi->CurrentState.playlistid = mi->status->playlist;
	}
	
	if(mi->CurrentState.storedplaylistid != mi->status->storedplaylist)
	{
		/* set MPD_CST_QUEUE to be changed */
		what_changed |= MPD_CST_STORED_PLAYLIST;


		/* save new id */
		mi->CurrentState.storedplaylistid = mi->status->storedplaylist;
	}


	/* state change */
	if(mi->CurrentState.state != mi->status->state)
	{
		what_changed |= MPD_CST_STATE;
		mi->CurrentState.state = mi->status->state;
	}

	if(mi->CurrentState.songid != mi->status->songid)
	{
		/* print debug message */
		debug_printf(DEBUG_INFO, "Songid has changed %i %i!", mi->OldState.songid, mi->status->songid);

		what_changed |= MPD_CST_SONGID;
		/* save new songid */
		mi->CurrentState.songid = mi->status->songid;

	}
	if(mi->CurrentState.songpos != mi->status->song)
	{
		/* print debug message */
		debug_printf(DEBUG_INFO, "Songpos has changed %i %i!", mi->OldState.songpos, mi->status->song);

		what_changed |= MPD_CST_SONGPOS;
		/* save new songid */
		mi->CurrentState.songpos = mi->status->song;

	}
    if(mi->CurrentState.nextsongid != mi->status->nextsongid || mi->CurrentState.nextsongpos != mi->status->nextsong)
    {
		what_changed |= MPD_CST_NEXTSONG;
		/* save new songid */
		mi->CurrentState.nextsongpos = mi->status->nextsong;
        mi->CurrentState.nextsongid = mi->status->nextsongid;
    }
	
	if(mi->CurrentState.single != mi->status->single)
	{
		what_changed |= MPD_CST_SINGLE_MODE;
		mi->CurrentState.single = mi->status->single;
	}
	if(mi->CurrentState.consume != mi->status->consume)
	{
		what_changed |= MPD_CST_CONSUME_MODE;
		mi->CurrentState.consume = mi->status->consume;
	}
	if(mi->CurrentState.repeat != mi->status->repeat)
	{
		what_changed |= MPD_CST_REPEAT;
		mi->CurrentState.repeat = mi->status->repeat;
	}
	if(mi->CurrentState.random != mi->status->random)
	{
		what_changed |= MPD_CST_RANDOM;
		mi->CurrentState.random = mi->status->random;
	}
	if(mi->CurrentState.volume != mi->status->volume)
	{
		what_changed |= MPD_CST_VOLUME;
		mi->CurrentState.volume = mi->status->volume;
	}
	if(mi->CurrentState.xfade != mi->status->crossfade)
	{
		what_changed |= MPD_CST_CROSSFADE;
		mi->CurrentState.xfade = mi->status->crossfade;
	}
	if(mi->CurrentState.totaltime != mi->status->totalTime)
	{
		what_changed |= MPD_CST_TOTAL_TIME;
		mi->CurrentState.totaltime = mi->status->totalTime;
	}
	if(mi->CurrentState.elapsedtime != mi->status->elapsedTime)
	{
		what_changed |= MPD_CST_ELAPSED_TIME;
		mi->CurrentState.elapsedtime = mi->status->elapsedTime;
	}

	/* Check if bitrate changed, happens with vbr encodings. */
	if(mi->CurrentState.bitrate != mi->status->bitRate)
	{
		what_changed |= MPD_CST_BITRATE;
		mi->CurrentState.bitrate = mi->status->bitRate;
	}

	/* The following 3 probly only happen on a song change, or is it possible in one song/stream? */
	/* Check if the sample rate changed */
	if(mi->CurrentState.samplerate != mi->status->sampleRate)
	{
		what_changed |= MPD_CST_AUDIOFORMAT;
		mi->CurrentState.samplerate = mi->status->sampleRate;
	}
	
	/* check if the sampling depth changed */
	if(mi->CurrentState.bits != mi->status->bits)
	{
		what_changed |= MPD_CST_AUDIOFORMAT;
		mi->CurrentState.bits = mi->status->bits;
	}
	
	/* Check if the amount of audio channels changed */
	if(mi->CurrentState.channels != mi->status->channels)
	{
		what_changed |= MPD_CST_AUDIOFORMAT;
		mi->CurrentState.channels = mi->status->channels;
	}

    if(mi->status->error)
    {
        what_changed |= MPD_CST_SERVER_ERROR;
        strcpy(mi->CurrentState.error,mi->status->error);
        mpd_sendClearErrorCommand(mi->connection);
        mpd_finishCommand(mi->connection);
    }
    else
    {
        mi->CurrentState.error[0] ='\0';
    }

	/* Check if the updating changed,
	 * If it stopped, also update the stats for the new db-time.
	 */
	if(mi->CurrentState.updatingDb != mi->status->updatingDb )
	{
		what_changed |= MPD_CST_UPDATING;
		if(!mi->status->updatingDb)
		{
			mpd_stats_update_real(mi, &what_changed);
		}
		mi->CurrentState.updatingDb = mi->status->updatingDb;
	}


    mi->CurrentState.playlistLength = mi->status->playlistLength;


    /* Detect changed outputs */
    if(!mi->has_idle)
    {
        if(mi->num_outputs >0 )
        {
            mpd_OutputEntity *output = NULL;
            mpd_sendOutputsCommand(mi->connection);
            while (( output = mpd_getNextOutput(mi->connection)) != NULL)
            {   
                if(mi->num_outputs < output->id)
                {
                    mi->num_outputs++;
                    mi->output_states = realloc(mi->output_states,mi->num_outputs*sizeof(int));
                    mi->output_states[mi->num_outputs] = output->enabled;
                    what_changed |= MPD_CST_OUTPUT;
                }
                if(mi->output_states[output->id] != output->enabled)
                {
                    mi->output_states[output->id] = output->enabled;
                    what_changed |= MPD_CST_OUTPUT;
                }
                mpd_freeOutputElement(output);
            }
            mpd_finishCommand(mi->connection);
        }
        else
        {
            /* if no outputs, lets fetch them */
            mpd_server_update_outputs(mi);
            if(mi->num_outputs == 0)
            {
                assert("No outputs defined? that cannot be\n");
            }
            what_changed |= MPD_CST_OUTPUT;
        }
    }else {
        char *name;
        int update_stats = 0;
        mpd_sendGetEventsCommand(mi->connection);    
        while((name = mpd_getNextEvent(mi->connection))){
            if(strcmp(name, "output") == 0){
                what_changed |= MPD_CST_OUTPUT;
            }else if (strcmp(name, "database") == 0) {
                if((what_changed&MPD_CST_DATABASE) == 0)
                {
                    update_stats = 1;
                }
                what_changed |= MPD_CST_DATABASE;
            }else if (strcmp(name, "stored_playlist")==0) {
                what_changed |= MPD_CST_STORED_PLAYLIST;
            }else if (strcmp(name, "tag") == 0) {
                what_changed |= MPD_CST_PLAYLIST;
            }else if (strcmp (name, "sticker") == 0) {
                what_changed |= MPD_CST_STICKER;
            }
            free(name);
       }
       mpd_finishCommand(mi->connection);
       if(update_stats) {
           mpd_stats_update_real(mi, &what_changed);
       }
    }

  
	/* Run the callback */
	if((mi->the_status_changed_callback != NULL) && what_changed)
	{
		mi->the_status_changed_callback( mi, what_changed, mi->the_status_changed_signal_userdata );
	}

        /* We could have lost connection again during signal handling... so before we return check again if we are connected */
	if(!mpd_check_connected(mi))
	{
		return MPD_NOT_CONNECTED;
	}
	return MPD_OK;
}