float mpd_status_set_volume_as_float(MpdObj *mi, float fvol) { int volume = mpd_status_set_volume(mi, (int)(fvol*100.0)); if(volume > -1) { return (float)volume/100.0; } return (float)volume; }
static void cb_volume_scale_changed (GtkWidget *widget, gpointer data) { GtkAdjustment *volume_adj; gint value; volume_adj = gtk_range_get_adjustment (GTK_RANGE(widget)); value = gtk_adjustment_get_value (GTK_ADJUSTMENT(volume_adj)); mpd_status_set_volume (gmo, value); return; }
static void volume_set(gpointer data, const char *param) { int cur_volume = mpd_status_get_volume(connection); /* if volume is disabled (current_volume < 0) ignore this command */ if (strlen(param) > 0 && current_volume >= 0) { int volume = 0; if (param[0] == '-' || param[0] == '+') { volume = cur_volume; } volume += atoi(param); mpd_status_set_volume(connection, volume); } }
void *Lkeys_thread() { int keystate = 0; int volume; struct pollfd fds; char ver[5]; strncpy(ver,G15DAEMON_VERSION,3); float g15v; sscanf(ver,"%f",&g15v); fds.fd = g15screen_fd; fds.events = POLLIN; while(!leaving){ int foo=0; current_fg_check = g15_send_cmd (g15screen_fd, G15DAEMON_IS_FOREGROUND, foo); static int last_fg_check = 0; if(playlist_mode && last_fg_check != current_fg_check){ if(own_keyboard){ if(current_fg_check==0){ own_keyboard=0; } }else if(current_fg_check && !own_keyboard) { own_keyboard=1; } last_fg_check = current_fg_check; } /* g15daemon series 1.2 need key request packets */ pthread_mutex_lock(&daemon_mutex); if((g15v*10)<=18) { keystate = g15_send_cmd (g15screen_fd, G15DAEMON_GET_KEYSTATE, foo); } else { if ((poll(&fds, 1, 5)) > 0) read (g15screen_fd, &keystate, sizeof (keystate)); } pthread_mutex_unlock(&daemon_mutex); if (keystate) { switch (keystate) { case G15_KEY_L1: exit(1); // FIXME quick hack to exit break; case G15_KEY_L2: menulevel++; if(menulevel>=MAX_MENU_MODES) menulevel=0; break; case G15_KEY_L3: if(!own_keyboard){ own_keyboard=playlist_mode=1; mpd_Song *song = mpd_playlist_get_current_song(obj); if(song) if(song->pos) track_info.currentsong=song->pos; }else{ //de-activate own_keyboard=playlist_mode=0; } break; case G15_KEY_L4: if(menulevel==MENU_MODE1){ mpd_player_set_random(obj,mpd_player_get_random(obj)^1); } if(menulevel==MENU_MODE2){ volume=mpd_status_get_volume(obj); if(volume>0) volume-=10; mpd_status_set_volume (obj,volume); } break; case G15_KEY_L5: if(menulevel==MENU_MODE1){ mpd_player_set_repeat(obj, mpd_player_get_repeat(obj)^1); } if(menulevel==MENU_MODE2){ volume=mpd_status_get_volume(obj); if(volume<100) volume+=10; mpd_status_set_volume (obj,volume); } break; default: break; } keystate = 0; } usleep(100*1000); } return NULL; }
int main(int argc, char **argv) { int fdstdin = 0; pthread_t Lkeys; pthread_t g15display; pthread_t EKeys; int volume; int volume_new; char devname[256] = "Unknown"; int iport = 6600; char *hostname = getenv("MPD_HOST"); char *port = getenv("MPD_PORT"); char *password = getenv("MPD_PASSWORD"); int eventdev; char evdev_name[128]; pthread_mutex_init(&lockit,NULL); pthread_mutex_init(&daemon_mutex,NULL); int i; for (i=0;i<argc;i++) { char argument[20]; memset(argument,0,20); strncpy(argument,argv[i],19); if (!strncmp(argument, "-q",2) || !strncmp(argument, "--quickscroll",13)) { quickscroll=1; } if (!strncmp(argument, "-h",2) || !strncmp(argument, "--help",6)) { printf(" %s version %s\n (c)2006-2007 Mike Lampard\n\n",argv[0],VERSION); printf("%s -q or --quickscroll Use volume control to scroll through the playlist\n",argv[0]); printf("%s -v or --version Show program version\n",argv[0]); printf("%s -h or --help This help text\n\n",argv[0]); exit(0); } if (!strncmp(argument, "-v",2) || !strncmp(argument, "--version",9)) { printf("%s version %s\n",argv[0],VERSION); exit(0); } } for(eventdev=0;eventdev<127;eventdev++) { snprintf(evdev_name,127,"/dev/input/event%i",eventdev); if ((mmedia_fd = open(evdev_name, O_NONBLOCK|O_RDONLY)) < 0) { // ignore errors when opening devices //printf("error opening interface %i\n",eventdev); } else { ioctl(mmedia_fd, EVIOCGNAME(sizeof(devname)), devname); printf("Device Name %s on %s\n", devname, evdev_name); if(0==strncmp(devname,"Logitech Logitech Gaming Keyboard",256)){ printf("Found device: \"%s\" on %s ", devname,evdev_name); break; } else if(0==strncmp(devname,"G15 Gaming Keyboard",256)){ printf("Found device: \"%s\" on %s ", devname,evdev_name); break; }else close(mmedia_fd); } } if (mmedia_fd) { // we assume that the next event device is the multimedia keys close(mmedia_fd); snprintf(evdev_name,127,"/dev/input/event%i",++eventdev); printf("and %s\n",evdev_name); if ((mmedia_fd = open(evdev_name, O_NONBLOCK|O_RDONLY)) < 0) { printf("error opening interface %i",eventdev); } }else { printf("Unable to find Keyboard via EVENT interface... is /dev/input/event[0-9] readable??\n"); } /* set correct hostname */ if(!hostname) { hostname = "localhost"; } if(port){ iport = atoi(port); } if((g15screen_fd = new_g15_screen(G15_G15RBUF))<0){ printf("Sorry, cant connect to the G15daemon\n"); return 1; } canvas = (g15canvas *) malloc (sizeof (g15canvas)); if (canvas != NULL) { memset(canvas->buffer, 0, G15_BUFFER_LEN); canvas->mode_cache = 0; canvas->mode_reverse = 0; canvas->mode_xor = 0; } /* 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, NULL); /* Set timeout */ mpd_set_connection_timeout(obj, 10); if(0==mpd_connect(obj)) { char buffer[20]; pthread_attr_t attr; mpd_send_password(obj); memset(buffer, '\0', 20); pthread_attr_init(&attr); pthread_attr_setstacksize(&attr,32*1024); /* set stack to 64k - dont need 8Mb !! */ pthread_create(&Lkeys, &attr, Lkeys_thread, NULL); pthread_create(&EKeys, &attr,event_key_thread, NULL); pthread_create(&g15display, &attr, g15display_thread, NULL); do{ pthread_mutex_lock(&daemon_mutex); if(voltimeout) --voltimeout; if(mute){ volume_adjust = 0; mute = 0; if (muted_volume == 0) { //printf("mute\n"); muted_volume = mpd_status_get_volume(obj); mpd_status_set_volume (obj,0); } else { //printf("unmute\n"); if (mpd_status_get_volume(obj) == 0) { /* if no other client has set volume up */ mpd_status_set_volume (obj,muted_volume); } muted_volume = 0; } } if(volume_adjust != 0){ if (muted_volume != 0) { volume=muted_volume; } else { volume=mpd_status_get_volume(obj); } volume_new = volume + volume_adjust; volume_adjust = 0; if(volume_new < 0) volume_new = 0; if(volume_new > 100) volume_new = 100; if(volume != volume_new || muted_volume){ //printf("volume %d -> %d\n", volume, volume_new); mpd_status_set_volume (obj,volume_new); } voltimeout=100; muted_volume=0; } mpd_status_update(obj); pthread_mutex_unlock(&daemon_mutex); }while(!usleep(5000) && !leaving); leaving = 1; pthread_join(Lkeys,NULL); pthread_join(g15display,NULL); }else printf("Unable to connect to MPD server. Exiting\n"); if(obj) mpd_free(obj); close(fdstdin); if(canvas!=NULL) free(canvas); close(g15screen_fd); close(mmedia_fd); pthread_mutex_destroy(&lockit); return 1; }
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; }
void gimmix_set_volume (MpdObj *mo, int vol) { mpd_status_set_volume(mo, vol); }