/* -------------------------------------------------------------------------- */ static void mpd_key_handler(const char *str, void *cookie) { struct lcd_stuff_mpd *mpd = (struct lcd_stuff_mpd *)cookie; if (g_ascii_strcasecmp(str, "Up") == 0) { /* if playing, next song */ if (mpd->current_state == MPD_PLAYER_PLAY) { mpd_player_next(mpd->mpd); } else { mpd_player_stop(mpd->mpd); } } else { if (mpd->current_state == MPD_PLAYER_PLAY) { mpd_player_pause(mpd->mpd); } else { mpd_player_play(mpd->mpd); } } }
bool gimmix_play (MpdObj *mo) { if (mpd_playlist_get_playlist_length (mo)) { int state; state = mpd_player_get_state (mo); if (state == MPD_PLAYER_PAUSE || state == MPD_PLAYER_STOP) { mpd_player_play (mo); return true; } else if (state == MPD_PLAYER_PLAY) { mpd_player_pause (mo); return false; } } return false; }
void *event_key_thread() { struct input_event *event; event=malloc(sizeof(struct input_event)); struct pollfd fds; int retval; while(!leaving) { event->value=0; event->code=0; fds.fd=mmedia_fd; fds.events=POLLIN; if(poll(&fds,1,500)<1) continue; retval=read(mmedia_fd,event,sizeof(struct input_event)); if(event->value==0||current_fg_check==0) continue; int keycode = event->code; int code_audio_play = KEY_PLAYPAUSE; int code_audio_stop = KEY_STOPCD; int code_audio_next = KEY_NEXTSONG; int code_audio_prev = KEY_PREVIOUSSONG; int code_audio_raisevol = KEY_VOLUMEUP; int code_audio_lowervol = KEY_VOLUMEDOWN; int code_audio_mute = KEY_MUTE; /* printf("keycode = %d\n", keycode); */ if(keycode == code_audio_play) { if(playing && !playlist_mode) { if (paused==1) { mpd_player_play(obj); paused = 0; } else { mpd_player_pause(obj); paused = 1; } } else { mpd_player_play(obj); playing = 1; } if(playlist_mode){ mpd_player_play_id(obj, item_selected); } } if(keycode == code_audio_stop) { mpd_player_stop(obj); playing = 0; continue; } if(keycode == code_audio_next) { if(playlist_mode) playlist_selection+=1; else mpd_player_next(obj); continue; } if(keycode == code_audio_prev) { if(playlist_mode) playlist_selection-=1; else mpd_player_prev(obj); continue; } if(keycode == code_audio_raisevol){ if(playlist_mode && quickscroll) playlist_selection+=1; else { pthread_mutex_lock(&daemon_mutex); volume_adjust+=1; pthread_mutex_unlock(&daemon_mutex); continue; } } if(keycode == code_audio_lowervol){ if(playlist_mode && quickscroll) playlist_selection-=1; else { pthread_mutex_lock(&daemon_mutex); volume_adjust-=1; pthread_mutex_unlock(&daemon_mutex); continue; } } if(keycode == code_audio_mute){ pthread_mutex_lock(&daemon_mutex); mute = 1; pthread_mutex_unlock(&daemon_mutex); continue; } /* now the default stuff */ if(own_keyboard) { menulevel=MENU_MODE1; continue; } } free(event); return NULL; }
void *main_mpd_cli(void *data ) { blockQueue char_queue; // kolejka polecen thread_data *my_data; my_data = (thread_data*)data; ////////////////////////////// LCD PART /////////////////////// my_data->mainLCD->set_print_song_state(0); /////////////////////////////////////////////////////////////////// int iport = 6600, button_counter =0; char *hostname = getenv("MPD_HOST"); char *port = getenv("MPD_PORT"); char *password = getenv("MPD_PASSWORD"); MpdObj *obj = NULL; std::cout << " adres hosta to " << hostname << std::endl; if(!hostname) { std::cout << " ip mpd to " << my_data->server_settings->MPD_IP << " ! \n"; hostname = (char*)my_data->server_settings->MPD_IP.c_str(); } if(port){ iport = std::stoi(port); } /* Create mpd object */ obj = mpd_new(hostname, iport,password); /* Connect signals */ mpd_signal_connect_error(obj,(ErrorCallback)error_callback, NULL); mpd_signal_connect_status_changed(obj,(StatusChangedCallback)status_changed , my_data ); /* Set timeout */ mpd_set_connection_timeout(obj, 10); int work; work = mpd_connect(obj); while (work){ log_file_mutex.mutex_lock(); log_file_cout << ERROR << "nie udalo sie polaczyc z MPD "<< std::endl; log_file_mutex.mutex_unlock(); system("service mpd stop"); sleep(1); system("service mpd start"); log_file_mutex.mutex_lock(); log_file_cout << INFO << "restart MPD "<< std::endl; log_file_cout << INFO << "nawiazuje nowe polaczenie z MPD "<< std::endl; log_file_mutex.mutex_unlock(); my_data->myEventHandler.run("mpd")->addEvent("restart MPD"); work = mpd_connect(obj); } std::cout << " stop "<<std::endl; if(!work) { char buffer; do{ if(char_queue._size() > 0) { //digitalWrite(LED7,1); buffer = char_queue._get(); switch(buffer) { case '\n': break; case 'D': mpd_player_next(obj); break; case 'U': mpd_player_prev(obj); break; case 't': mpd_player_play(obj); break; case 'A': mpd_player_pause(obj); break; case 'P': mpd_player_pause(obj); mpd_player_stop(obj); break; case 'q': printf("Quitting....\n"); break; case 'R': mpd_player_set_repeat(obj, !mpd_player_get_repeat(obj)); break; case 's': mpd_player_set_random(obj, !mpd_player_get_random(obj)); break; case 'p': /*if(char_queue._size() > 0) { buffer = char_queue._get(); int id = atoi(buffer); printf(GREEN"Playing:"RESET" %i\n", id); mpd_player_play_id(obj,id); } break;*/ case '+': mpd_status_set_volume(obj, mpd_status_get_volume(obj)+1); break; case '-': mpd_status_set_volume(obj, mpd_status_get_volume(obj)-1); break; case '%': mpd_status_set_volume(obj, my_data->ptr_MPD_info->volume); break; case '2': debug_level = (debug_level > 0)?0:3; printf( "Debug:"" %s\n", (debug_level >0)? "Enabled":"Disabled"); break; case 'I': mpd_player_play_id(obj,my_data->currentSongID); break; case 'h': printf("\th:\t\tHelp\n"\ "\td:\t\tToggle debug on/off\n"\ "\t+:\t\tIncrease volume\n"\ "\t-:\t\tDecrease volume\n"\ "\ta <pass>:\t Authentificate with pass\n"\ "\tp <id>:\t Play song with id\n"\ "\tl:\t\tList the playlist\n"\ "\ts:\t\tToggle shuffle mode\n"\ "\tr:\t\tToggle repeat\n"\ "\tq:\t\tQuit\n"\ "\tv:\t\tStop\n"\ "\tc:\t\tPause\n"\ "\tx:\t\tPlay\n"\ "\tz:\t\tPrevious\n"\ "\tb:\t\tNext\n"); break; default: printf("buffer: %c\n", buffer); } } if (!mpd_check_connected(obj)) { log_file_mutex.mutex_lock(); log_file_cout << WARNING << "utracono polacznie z MPD "<< std::endl; log_file_cout << INFO << "restart MPD" << std::endl; log_file_mutex.mutex_unlock(); system ("service mpd restart"); mpd_connect(obj); } mpd_status_update(obj); my_data->mainLCD->checkState(); if ( digitalRead(BUTTON_PIN) == HIGH ) { std::cout << " wcisnieta pin !" << std::endl; if (check_title_song_to == true && button_counter ==4) { char_queue._add('P'); std::cout << " \n\ngasze !" << std::endl; } else if (check_title_song_to == false && button_counter ==4) { char_queue._add('t'); std::cout << " \n\n\n zapalam !" << std::endl; } else if (check_title_song_to == false && button_counter ==10) { std::cout << " \n\n\n koniec programu z przyciska !" << std::endl; go_while = false; } std::cout << " \n\n\n licznik guzika wskazuje "<< button_counter << std::endl; ++button_counter; } else { button_counter =0; } } while(!usleep(500000) && go_while); mpd_player_stop(obj); sleep (3); } else{ std::cout << " NIE UDALO SIE POłączyć "<<std::endl; } mpd_free(obj); log_file_mutex.mutex_lock(); log_file_cout << INFO << " koniec watku klient MPD "<< std::endl; log_file_mutex.mutex_unlock(); return 0; }