Exemplo n.º 1
0
bool
Control::pause(bool tryplay)
{
	EXIT_IDLE;

	pms->log(MSG_DEBUG, 0, "Toggling pause, tryplay=%d\n", tryplay);

	switch(st->state)
	{
		case MPD_STATE_PLAY:
			return mpd_run_pause(conn->h(), true);
		case MPD_STATE_PAUSE:
			return mpd_run_pause(conn->h(), false);
		case MPD_STATE_STOP:
		case MPD_STATE_UNKNOWN:
		default:
			return (tryplay && play());
	}
}
Exemplo n.º 2
0
/*
 * pgmpc_pause
 * Pause current song
 */
Datum
pgmpc_pause(PG_FUNCTION_ARGS)
{
	pgmpc_init();
	/*
	 * Enforce pause to be set in all cases. Subsequent calls
	 * to this function result still in a pause state.
	 */
	if (!mpd_run_pause(mpd_conn, true))
		pgmpc_print_error();
	pgmpc_reset();
	PG_RETURN_NULL();
}
Exemplo n.º 3
0
/*
 * pgmpc_play
 * Play a song.
 */
Datum
pgmpc_play(PG_FUNCTION_ARGS)
{
	pgmpc_init();
	/*
	 * Enforce disabling of pause. We could here check for the server
	 * status before doing anything but is it worth the round trip?
	 */
	if (!mpd_run_pause(mpd_conn, false))
		pgmpc_print_error();
	pgmpc_reset();
	PG_RETURN_VOID();
}
Exemplo n.º 4
0
void cmd_pause(irc_session_t* session, const char* cmd, const char* origin, char* args) {
    struct mpd_connection* conn;

    conn = mpd_connection_new(NULL, 0, 30000);

    if(mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
        log_and_print("Impossible de se connecter à MPD");
        mpd_connection_free(conn);
        return;
    }

    mpd_run_pause(conn, 1);
    mpd_connection_free(conn);
}
Exemplo n.º 5
0
/*my_mpd_run_pause*/
void my_mpd_run_pause(void)
{
	struct mpd_status *status = NULL;

	pthread_mutex_lock(&mutex);
	status = mpd_run_status(conn);
	if (!status) 
	{
		printf("nd my_mpd_run_pause mpd_run_status1 %s \n", mpd_connection_get_error_message(conn));
	}
	else
	{
		if (mpd_status_get_state(status) == MPD_STATE_PLAY)
		{
			mpd_run_pause(conn, true);
		}
	
		mpd_status_free(status);
	}
	
	pthread_mutex_unlock(&mutex);
}
Exemplo n.º 6
0
bool
handle_player_command(struct mpdclient *c, command_t cmd)
{
	struct mpd_connection *connection;

	if (!mpdclient_is_connected(c) || c->status == NULL)
		return false;

	cancel_seek_timer();

	switch(cmd) {
		/*
	case CMD_PLAY:
		mpdclient_cmd_play(c, MPD_PLAY_AT_BEGINNING);
		break;
		*/
	case CMD_PAUSE:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_pause(connection,
				   mpd_status_get_state(c->status) != MPD_STATE_PAUSE))
			mpdclient_handle_error(c);
		break;
	case CMD_STOP:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_stop(connection))
			mpdclient_handle_error(c);
		break;
	case CMD_CROP:
		mpdclient_cmd_crop(c);
		break;
	case CMD_SEEK_FORWARD:
		if (!setup_seek(c))
			break;

		seek_target_time += options.seek_time;
		if (seek_target_time > (int)mpd_status_get_total_time(c->status))
			seek_target_time = mpd_status_get_total_time(c->status);
		break;

	case CMD_TRACK_NEXT:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_next(connection))
			mpdclient_handle_error(c);
		break;
	case CMD_SEEK_BACKWARD:
		if (!setup_seek(c))
			break;

		seek_target_time -= options.seek_time;
		if (seek_target_time < 0)
			seek_target_time = 0;
		break;

	case CMD_TRACK_PREVIOUS:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_previous(connection))
			mpdclient_handle_error(c);
		break;
	case CMD_SHUFFLE:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (mpd_run_shuffle(connection))
			screen_status_message(_("Shuffled playlist"));
		else
			mpdclient_handle_error(c);
		break;
	case CMD_CLEAR:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (mpdclient_cmd_clear(c))
			screen_status_message(_("Cleared playlist"));
		break;
	case CMD_REPEAT:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_repeat(connection,
				    !mpd_status_get_repeat(c->status)))
			mpdclient_handle_error(c);
		break;
	case CMD_RANDOM:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_random(connection,
				    !mpd_status_get_random(c->status)))
			mpdclient_handle_error(c);
		break;
	case CMD_SINGLE:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_single(connection,
				    !mpd_status_get_single(c->status)))
			mpdclient_handle_error(c);
		break;
	case CMD_CONSUME:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_consume(connection,
				     !mpd_status_get_consume(c->status)))
			mpdclient_handle_error(c);
		break;
	case CMD_CROSSFADE:
		connection = mpdclient_get_connection(c);
		if (connection == NULL)
			break;

		if (!mpd_run_crossfade(connection,
				       mpd_status_get_crossfade(c->status) > 0
				       ? 0 : options.crossfade_time))
			mpdclient_handle_error(c);
		break;
	case CMD_DB_UPDATE:
		screen_database_update(c, NULL);
		break;
	case CMD_VOLUME_UP:
		mpdclient_cmd_volume_up(c);
		break;
	case CMD_VOLUME_DOWN:
		mpdclient_cmd_volume_down(c);
		break;

	default:
		return false;
	}

	return true;
}
Exemplo n.º 7
0
/*The thread of I2C*/
void * I2CThread(void *arg)
{
        int res = 0;

        while (1)
        {
                res = 0;
                if (i2c_file > 0)
                {
                        if (!bread_register)
                        {
                                res = i2c_smbus_read_word_data(i2c_file, REGISTER3);
                                switch (res)
                                {
                                        case SWITCH_BTN_SHUT_DWON:
                                        {
                                                printf("nd I2CThread SWITCH_BTN_SHUT_DWON: 0x%0*x\n", 2, res);
                                                break;
                                        }
                                        case SHUT_DWON:
                                        {
                                                printf("nd I2CThread BTN3 SHUT_DWON: 0x%0*x\n", 2, res);
                                                break;
                                        }
                                        case AUTO_SLEEP:
                                        {
                                                printf("nd I2CThread AUTO_SLEEP: 0x%0*x\n", 2, res);
                                                break;
                                        }
                                }

                                bread_register = true;
                        }

                        res = i2c_smbus_read_word_data(i2c_file, REGISTER2);
                        //printf("md I2CThread i2c_file res: 0x%0*x\n", 2, res);
                        switch (res)
                        {
                                case BTN1_SHORT_PRESS:
                                {
                                        printf("nd I2CThread BTN1_SHORT_PRESS: 0x%0*x\n", 2, res);
                                        btn1_short_press();
                                        break;
                                }
                                case BTN1_LONG_PRESS:
                                {
                                        printf("nd I2CThread BTN1_LONG_PRESS: 0x%0*x\n", 2, res);
                                        btn1_long_press();
                                        break;
                                }
                                case BTN1_AUDIO_SPPEK_ARECORD:
                                {
					printf("nd BTN1_AUDIO_SPPEK_ARECORD :: 0x%0*x\n", 2, res);
                                        btn1_audio_sppek_arecord(res);
                                        break;
                                }
                                case BTN2_SHORT_PRESS:
                                {
                                        printf("nd I2CThread BTN2_SHORT_PRESS: 0x%0*x\n", 2, res);
                                        btn2_short_press();
                                        break;
                                }
                                case BTN2_LONG_PRESS:
                                {
                                        printf("nd I2CThread BTN2_LONG_PRESS: 0x%0*x\n", 2, res);
                                        btn2_long_press();
                                        break;
                                }
                                case BTN3_SHORT_PRESS:
                                {
                                        printf("nd I2CThread BTN3_SHORT_PRESS: 0x%0*x\n", 2, res);
                                        btn3_short_press();
                                        break;
                                }
                                case BTN3_LONG_PRESS:
                                {
                                        printf("nd I2CThread BTN3_LONG_PRESS: 0x%0*x\n", 2, res);
                                        btn3_long_press();
                                     break;
                                }
                                case BTN4_SHORT_PRESS:
                                {
                                        printf("nd I2CThread BTN4_SHORT_PRESS: 0x%0*x\n", 2, res);
                                        btn4_short_press();
                                        break;
                                }
                                case BTN4_LONG_PRESS:
                                {
                                        printf("nd I2CThread BTN4_LONG_PRESS: 0x%0*x\n", 2, res);
                                        btn4_long_press();
                                        break;
                                }
                                case BTN5_SHORT_PRESS:
                                {
                                        printf("nd I2CThread BTN5_SHORT_PRESS: 0x%0*x\n", 2, res);
                                        btn5_short_press();
                                        break;
                                }
                                case BTN5_LONG_PRESS:
                                {
                                        printf("nd I2CThread BTN5_LONG_PRESS: 0x%0*x\n", 2, res);
                                        btn5_long_press();
                                        break;
                                }
                                case BTN5_QUESTION_ANSWER_ARECORD:
                                {
                                        btn5_question_answer_arecord(res);
                                        break;
                                }

                                case PEN_START:
                                {
#ifdef PEN_SUPPORT                                      
                                        printf("nd I2CThread PEN_START: 0x%0*x\n", 2, res);
                                        int nValue = 0, nValue8 = 0, nValue9 = 0, nValue10 = 0, nValue89 = 0;

                                        nValue10 = i2c_smbus_read_word_data(i2c_file, REGISTER10);
                                        printf("nd I2CThread REGISTER10: 0x%0*x, %d\n", 2, nValue10, nValue10);

                                        nValue9 = i2c_smbus_read_word_data(i2c_file, REGISTER9);
                                        printf("nd I2CThread REGISTER9: 0x%0*x, %d\n", 2, nValue9, nValue9);

                                        nValue8 = i2c_smbus_read_word_data(i2c_file, REGISTER8);
                                        printf("nd I2CThread REGISTER8: 0x%0*x, %d\n", 2, nValue8, nValue8);

                                        nValue89 = nValue8 | ((nValue9 << 8) & 0xff00);
                                        printf("nd I2CThread nValue89: %x, nValue89: %d, \n", nValue89, nValue89);

                                        nValue = nValue8 | ((nValue9 << 8) & 0xff00) | ((nValue10 << 16) & 0xff0000);
                                        printf("nd I2CThread nValue: %x, \n", nValue, nValue);

                                        if (nValue == 0x60fff8)
                                        {
                                                pthread_mutex_lock(&mutex);
                                                mpd_run_pause(conn, true);
                                                mpd_run_clear(conn);
                                                mpd_run_load(conn, "ljyy.lst");
                                                pthread_mutex_unlock(&mutex);
                                        }
                                        else if (nValue == 0x60fff7)
                                        {

                                        }
                                        else if (nValue89 > 52900)
                                        {
                                                int nPos = nValue89 - 52901;
                                                printf("nd I2CThread nPos: %d, \n", nPos);
                                                pthread_mutex_lock(&mutex);
                                                mpd_run_pause(conn, true);
                                                mpd_run_single(conn, true);
                                                mpd_run_play_pos(conn, nPos);
                                                pthread_mutex_unlock(&mutex);
                                        }

                                        res = i2c_smbus_read_word_data(i2c_file, REGISTER2);
                                        printf("nd I2CThread REGISTER2: 0x%0*x\n", 2, res);
#endif

                                        break;
                                }
                                case NOT_BTN_EVENT:
                                {
                                        break;
                                }
                        }
                }
                else
                {
                        printf("nd I2CThread i2c_file: %d\n", i2c_file);
                        InitI2CDev();
                }

                usleep(50*1000);
        }
}
Exemplo n.º 8
0
/*btn3_short_press*/
void btn3_short_press(void)
{
        int res = json_type_null;
        json_object * pjson_obj_read = NULL;
        struct mpd_status *status = NULL;

        ncurrt_time = 0;
        system("killall aplay");
        system("killall xfchat");

        pthread_rwlock_wrlock(&json_rwlock_voice);
        pjson_obj_read = json_object_from_file(PLAY_VOICE_JSON_PATH);
        pthread_rwlock_unlock(&json_rwlock_voice);
        res = json_object_get_type(pjson_obj_read);
        printf("json_type: %u \n", json_object_get_type(pjson_obj_read));
//        printf("json_length: %u \n", json_object_array_length(pjson_obj_read));

        json_object_put(pjson_obj_read);
        if ((json_type_array == res) && (0 < json_object_array_length(pjson_obj_read)) && (!bplay_audio))
        {
                printf("nd btn3_short_press ret: %d, bplay_audio: %d\n", res, bplay_audio);
                my_mpd_run_pause();
                bplay_audio = true;
        }
        else
        {
                int quere_len = 0;
                int online_size = 0;
                bplay_audio = false;

                online_size = get_file_size(ONLINE_LIST_PATH);
                if (online_size > 0)
                {
                        quere_len = get_mpc_quere_len(conn);

                        pthread_mutex_lock(&mutex);
                        if (quere_len > 0)
                        {
                                mpd_run_stop(conn);
                                mpd_run_clear(conn);
                        }

                        bool mpc_load = mpd_run_load(conn, "online.lst");
                        bool mpc_list_clear = mpd_run_playlist_clear(conn, "online.lst");
                        printf("nd btn3_short_press mpc_load: %d, mpc_list_clear: %d\n", mpc_load, mpc_list_clear);
                        pthread_mutex_unlock(&mutex);

                        res = i2c_smbus_write_byte_data(i2c_file, 0x00, BLUE_OFF);
                        if (res < 0)
                        {
                                printf("nd btn3_short_press i2c_smbus_write_byte_data BLUE_OFF failed, ret: %d\n", res);
                        }
                }

                quere_len = get_mpc_quere_len(conn);
                if (quere_len > 0)
                {
                        printf("nd btn3_short_press get_mpc_quere_len quere_len: %d\n", quere_len);
                        pthread_mutex_lock(&mutex);
                        status = mpd_run_status(conn);
                        if (!status)
                        {
                                printf("nd btn3_short_press mpd_run_status2 %s \n", mpd_connection_get_error_message(conn));
                        }
                        else
                        {
                                if (mpd_status_get_state(status) == MPD_STATE_PLAY)
                                {
                                        printf("nd btn3_short_press mpd_status_get_state MPD_STATE_PLAY\n");
                                        mpd_run_pause(conn, true);
                                }
                                else
                                {
                                        printf("nd btn3_short_press mpd_status_get_state other state\n");
                                        mpd_run_play(conn);
                                }

                                mpd_status_free(status);
                        }
                        pthread_mutex_unlock(&mutex);
                }
  }
}
Exemplo n.º 9
0
void Connection::Pause(bool state)
{
	prechecksNoCommandsList();
	mpd_run_pause(m_connection.get(), state);
	checkErrors();
}
Exemplo n.º 10
0
void* threadManager(void *thread_arg){
	int i;
	conn = NULL;

        if (DEBUG)
                fprintf (stderr, "DEBUG: [mgr-thread] -starting\n");

	alsaSetup();

        if (ADC_init() < 0) {
                fprintf(stderr, "FATAL: ADC: Unable to setup ADC interface\n");
		flag_exit++;
		return thread_arg;
        }

	for (i = 0; i < 10 && conn == NULL; i++) {
		if (!mgr_mpd_connect()) {
			fprintf(stderr, "ERROR: MPD: Unable to connect, reconnecting...\n");
			delay(1000);
		}
	}

	if (conn == NULL) {
		fprintf(stderr, "FATAL: MPD: Unable to connect to MPD server, exiting...\n");
		flag_exit++;
		return thread_arg;
	}

	if (!mgr_mpd_fetch_status( conn, 1 )) {
		fprintf(stderr, "ERROR: MPD: Unable to fetch MPD status\n");
		mgr_handle_mpd_error();
	}

	// Read ADC & Update MPD
	volume_update();

	// Set volume to 0 if it does not play
	if (conn != NULL && cur_mpd_player_status != MPD_STATE_PLAY) {

		if (DEBUG)
			fprintf (stderr, "DEBUG: [mgr-thread] mpd: starting playing...\n");

		// set value to 0
		if (!mpd_run_set_volume(conn, 0)) {
			fprintf(stderr, "ERROR: MPD: Unable to set volume\n");
			mgr_handle_mpd_error();
		}

		// start player
		if (!mpd_run_play(conn)) {
			fprintf(stderr, "ERROR: MPD: Unable to start playing\n");
			mgr_handle_mpd_error();
		}
	}

	mgr_unsetWarmingUp();

        if (DEBUG)
                fprintf (stderr, "DEBUG: [mgr-thread] +started\n");

	while (!flag_exit) {

		//////////////////////////////////////////////////////////////////
		// Open MPD Connection
		//////////////////////////////////////////////////////////////////
		if (conn == NULL) {
			if (!mgr_mpd_connect()) {
				delay(5000);
				continue;
			}

		}

		//////////////////////////////////////////////////////////////////
		// WARMING?
		//////////////////////////////////////////////////////////////////
		if (mgr_isWarmingUp()) {
			delay(1000);
			continue;
		}

		//////////////////////////////////////////////////////////////////
		// RECEIVE STATUS
		//////////////////////////////////////////////////////////////////
		if (!mgr_mpd_fetch_status( conn, 0 )) {
			mgr_handle_mpd_error();
			continue;
		}

		//////////////////////////////////////////////////////////////////
		// update volume
		//////////////////////////////////////////////////////////////////
		volume_update();

		//////////////////////////////////////////////////////////////////
		// update playlist if needed
		//////////////////////////////////////////////////////////////////
		if (cur_mpd_stats_number_of_songs != cur_mpd_status_queue_len) {
			if (!mqr_update_playlist()) {
				fprintf(stderr, "ERROR: MPD: Unable to update playlist\n");
				mgr_handle_mpd_error();
				return 0;
			}
		}

		//////////////////////////////////////////////////////////////////
		// check player timeout
		//////////////////////////////////////////////////////////////////
		if (cur_mpd_player_status == MPD_STATE_PLAY) {
			if (ts_started == 0)
				ts_started = time(NULL); 

			int timeout = 3600;
			if (ts_started + timeout < time(NULL)) {
				if (!flag_stop) {
					if (DEBUG)
						fprintf(stderr, "DEBUG: MGR: Timeout reached, stop playing\n");
				}
				flag_stop++;
			}
		} else {
			ts_started = 0;
		}

		//////////////////////////////////////////////////////////////////
		// START
		//////////////////////////////////////////////////////////////////
		if (flag_start) {
			alsaPlaySound(PCM_SOUND_ID_CLICK);

			if (!mpd_run_play(conn)) {
				fprintf(stderr, "ERROR: [mgr-thread] mpd: start command failed\n");
				mgr_handle_mpd_error();
				continue;
			}

			if (DEBUG)
				fprintf(stderr, "DEBUG: [mgr-thread] player started\n");

			cur_mpd_player_status = MPD_STATE_PLAY; // for volume control
			flag_start = 0;
		}

		//////////////////////////////////////////////////////////////////
		// STOP 
		if (flag_stop) {
			// alsaPlaySound(PCM_SOUND_ID_CLICK);
			if (cur_mpd_volume == 0) {

				if (DEBUG)
					fprintf(stderr, "DEBUG: [mgr-thread] player stopped\n");

				if (!mpd_run_pause(conn, true)) {
					fprintf(stderr, "ERROR: [mgr-thread] mpd: stop command failed\n");

					mgr_handle_mpd_error();
					continue;
				}

				cur_mpd_player_status = MPD_STATE_PAUSE; // for volume control
				flag_stop = 0;
			}
		}

		//////////////////////////////////////////////////////////////////
		// RANDOM SWTICH MODE (SKIP2)
		if (flag_skip2) {
			alsaPlaySound(PCM_SOUND_ID_CLICK);

			if (!mpd_run_random(conn, (cur_mpd_random > 0 ? false : true) )) {
				fprintf(stderr, "ERROR: [mgr-thread] mpd: random command failed\n");

				mgr_handle_mpd_error();
				continue;
			}

			cur_mpd_random = cur_mpd_random > 0 ? 0 : 1;
		}

		//////////////////////////////////////////////////////////////////
		// SKIP1 (skip file)
		if (flag_skip1 || flag_skip2) {
			if (flag_skip1) {
				alsaPlaySound(PCM_SOUND_ID_CLICK);
			}

			if (!mpd_run_next(conn)) {
				fprintf(stderr, "ERROR: [mgr-thread] mpd: skip command failed\n");

				mgr_handle_mpd_error();
				continue;
			}
		}

		flag_skip1 = flag_skip2 = 0;

		delay(400); //delay 40 ms

	}//end while

        if (DEBUG)
                fprintf (stderr, "DEBUG: [mgr-thread] thread finished\n");
	
	return thread_arg;
}