GdkFilterReturn filter(GdkXEvent *xevent, GdkEvent *event, gpointer data) { XEvent *e = (XEvent *)xevent; pa_context *c = (pa_context *)data; if (pa_context_get_state(c) != PA_CONTEXT_READY) return GDK_FILTER_CONTINUE; switch (e->type) { case KeyPress: if (e->xkey.keycode == keycodes[RAISE_VOLUME]) change_volume(c, +VOLUME_INCREMENT); else if (e->xkey.keycode == keycodes[LOWER_VOLUME]) change_volume(c, -VOLUME_INCREMENT); else if (e->xkey.keycode == keycodes[MUTE]) toggle_mute(c); else if (e->xkey.keycode == keycodes[MIC_MUTE]) toggle_mic_mute(c); break; default: break; } return GDK_FILTER_CONTINUE; }
int main(int argc, char *argv[]) { unsigned short volume; pid_t pid = create_process(); switch(pid) { case -1: return EXIT_FAILURE; break; case 0: if(argc > 1) { if(sscanf(argv[1], "%d", &volume) != EOF) { if(volume >= 0 && volume <= 100) { change_volume(volume); } } } break; default: if(wait(NULL) == -1) { perror("wait :"); exit(EXIT_FAILURE); } } return 0; }
// Volume and Volume DB change both at once. Only send one event. // Event can be NULL in which case only the variable is changed. static void change_volume_and_notify(struct action_event *event, const char *volume, const char *db_volume) { change_volume(volume, db_volume); if (event) { notify_lastchange(event, strdup(control_values[CONTROL_VAR_LAST_CHANGE])); } }
static void vscroll_volume_value_changed(GtkWidget* widget, gpointer data) { double value = VSCROLL_VOLUME_MAX - gtk_range_get_value(GTK_RANGE(vscroll_volume)); volume = VOLUME_MAX/VSCROLL_VOLUME_MAX*value; //pthread_t thread_change_volume; //pthread_create(&thread_change_volume, NULL, &change_volume, NULL); //with thread there are problems because of too many threads (when scrolling the scrollbar fast) //-> next timer program that the thread will wait or something like that so that the main loop doesn't //has to make the complicated system call with amixer!! //then the call of change_volume has to be changed for threads (void*) function(void*) if(mute==FALSE) { change_volume(volume); } }
// Change volume variables from the given decibel. Quantize value according to // our ranges. static float change_volume_decibel(float raw_decibel) { int volume_level = volume_decibel_to_level(raw_decibel); // Since we quantize it to the level, lets calculate the // actual level. float decibel = volume_level_to_decibel(volume_level); char volume[10]; snprintf(volume, sizeof(volume), "%d", volume_level); char db_volume[10]; snprintf(db_volume, sizeof(db_volume), "%d", (int) (256 * decibel)); Log_info("control", "Setting volume-db to %.2fdb == #%d", decibel, volume_level); change_volume(volume, db_volume); return decibel; }
void handle_ADC(void){ if (!g_timer_ADC && g_timer_ADC_active) { //nastepny pomiar za 100ms g_timer_ADC=10; // wlacz tranzystor CHECK_VOL_START; // wlacz pomiar AD1CON1bits.SAMP = 1; // start sampling, then after 31Tad go to conversion } if ( (AD1CON1bits.DONE == 1)){// && (g_timer_ADC_active == false) ){ // /*TODO pomiar gotowy.*/ AD1CON1bits.DONE=0; //wylacz tranzystor CHECK_VOL_STOP; //zmien gloscnosc change_volume(); } }
static int set_volume(struct action_event *event) { const char *volume = upnp_get_string(event, "DesiredVolume"); service_lock(); int volume_level = atoi(volume); // range 0..100 if (volume_level < volume_range.min) volume_level = volume_range.min; if (volume_level > volume_range.max) volume_level = volume_range.max; const float decibel = volume_level_to_decibel(volume_level); char db_volume[10]; snprintf(db_volume, sizeof(db_volume), "%d", (int) (256 * decibel)); Log_info("control", "Setting %d volume-db to %d" , volume_level,(int)decibel); const double fraction = exp(decibel / 20 * log(10)); change_volume(volume, db_volume); output_set_volume(fraction, volume_level); set_mute_toggle(volume_level == 0); service_unlock(); return 0; }
/* Set the current volume */ void set_volume (U8 level) { silence_volume (); change_volume (level); }
/* Silence the volume control */ void silence_volume (void) { change_volume (-120); }
void main_loop(void) { Doubly_linked_node *iterator; int direction, dx, dy, count; int x, y; uint32_t last_time; uint32_t current_time; uint32_t ellapsed_time; uint32_t start_time; Point *save_eye; float speed; last_time = SDL_GetTicks(); while (!conf->key[SDLK_ESCAPE] && !conf->quit) { start_time = SDL_GetTicks(); save_eye = point_new(conf->eye->x, conf->eye->y, conf->eye->z); speed = (conf->free_fly) ? 5 : 0.5; update_event(); if (!conf->viewMode && conf->key[SDLK_F1]) { conf->key[SDLK_F1] = 0; conf->free_fly = !conf->free_fly; if (!conf->free_fly) { save_eye->x = CELL_SIZE / 2; save_eye->y = CELL_SIZE / 2; save_eye->z = CHARACTER_SIZE; } else { conf->jump_duration = 0; } } if (!conf->viewMode && (conf->key[SDLK_LSHIFT] || conf->key[SDLK_LALT])) { if ( conf->jump_duration == 0 ) { /* j'ai du mal a courir quand je saute */ speed = (conf->free_fly) ? 7.51337 : 0.91337; } } if (!conf->viewMode && conf->key[SDLK_LCTRL]) { speed = (conf->free_fly) ? 0.1 : 0.3; } if (conf->key[SDLK_F2]) { conf->key[SDLK_F2] = 0; conf->time = !conf->time; } if (conf->key[SDLK_F3]) { conf->key[SDLK_F3] = 0; conf->display = !conf->display; } if (!conf->viewMode && conf->key[SDLK_F4]) { conf->key[SDLK_F4] = 0; conf->quadTreeView = !conf->quadTreeView; } if (conf->key[SDLK_F5]) { conf->key[SDLK_F5] = 0; if (!strcmp(conf->music, "music/music2.mp3")) { conf->music = "music/music.mp3"; music_new(); } else if (!strcmp(conf->music, "music/music.mp3")) { conf->music = "music/music2.mp3"; music_new(); } } if (!conf->viewMode && (conf->key[SDLK_UP] || conf->key[SDLK_z])) { forward_move(save_eye, speed); } if (!conf->viewMode && (conf->key[SDLK_DOWN] || conf->key[SDLK_s])) { backward_move(save_eye, speed); } if (!conf->viewMode && (conf->key[SDLK_RIGHT] || conf->key[SDLK_d])) { right_move(save_eye, speed); } if (!conf->viewMode && (conf->key[SDLK_LEFT] || conf->key[SDLK_q])) { left_move(save_eye, speed); } if (!conf->viewMode && conf->key[SDLK_a]) { conf->key[SDLK_a] = 0; conf->theta += 180; } if (!conf->viewMode && conf->key[SDLK_r]) { conf->key[SDLK_r] = 0; conf->life = MAX_HEALTH; save_eye->x = CELL_SIZE / 2; save_eye->y = CELL_SIZE / 2; save_eye->z = CHARACTER_SIZE; portals->bleu->actif = 0; portals->orange->actif = 0; conf->timer = SDL_GetTicks(); } if (conf->key[SDLK_KP2] || (conf->key[SDLK_n])) { if (conf->free_fly) { save_eye->z -= 3; } else if (conf->viewMode) { save_eye->z -= 10; } } if (conf->key[SDLK_KP8] || (conf->key[SDLK_SPACE])) { if (!conf->free_fly && !conf->viewMode) { conf->key[SDLK_KP8] = 0; conf->key[SDLK_SPACE] = 0; if ( !conf->viewMode && conf->jump_duration == 0 ) { conf->jump_duration = 120; } } else if (conf->free_fly){ save_eye->z += 3; } else { save_eye->z += 10; } } conf->eye->z += jump(save_eye); if ( conf->key[SDLK_p] ) { conf->key[SDLK_p] = 0; if(Mix_PausedMusic() == 1) { Mix_ResumeMusic(); } else { Mix_PauseMusic(); } } if ( conf->key[SDLK_PLUS] || conf->key[SDLK_m] || conf->key[SDLK_KP_PLUS] ) { change_volume(CHANG_VOL); } if ( conf->key[SDLK_MINUS] || conf->key[SDLK_l] || conf->key[SDLK_KP_MINUS] ) { change_volume(-CHANG_VOL); } if (!conf->mousebutton[SDL_BUTTON_LEFT] && !conf->mousebutton[SDL_BUTTON_RIGHT]) { conf->shoot = 0; } if (!conf->viewMode && conf->mousebutton[SDL_BUTTON_LEFT]) { conf->mousebutton[SDL_BUTTON_LEFT] = 0; conf->mousebutton[SDL_BUTTON_RIGHT] = 0; conf->shoot = 1; } if (!conf->viewMode && conf->mousebutton[SDL_BUTTON_RIGHT]) { conf->mousebutton[SDL_BUTTON_LEFT] = 0; conf->mousebutton[SDL_BUTTON_RIGHT] = 0; conf->shoot = 2; } if (!conf->viewMode && portals->orange->actif && portals->bleu->actif ) { if ( abs(save_eye->x - portals->bleu->portail->x ) < TRIGGER_DISTANCE && abs(save_eye->y - portals->bleu->portail->y) < TRIGGER_DISTANCE) { save_eye->x = portals->orange->portail->x - (sin(portals->orange->rotation) * PUSH_DISTANCE); save_eye->y = portals->orange->portail->y + (cos(portals->orange->rotation) * PUSH_DISTANCE); conf->theta += 180 + ( portals->orange->rotation - portals->bleu->rotation); } else if ( abs(save_eye->x - portals->orange->portail->x ) < TRIGGER_DISTANCE && abs(save_eye->y - portals->orange->portail->y) < TRIGGER_DISTANCE) { save_eye->x = portals->bleu->portail->x - (sin(portals->bleu->rotation) * PUSH_DISTANCE); save_eye->y = portals->bleu->portail->y + (cos(portals->bleu->rotation) * PUSH_DISTANCE); conf->theta += 180 + ( portals->bleu->rotation - portals->orange->rotation); } } if (COORD((int)(save_eye->x / CELL_SIZE), (int)(save_eye->y / CELL_SIZE)) != COORD((int)((conf->eye)->x / CELL_SIZE), (int)((conf->eye)->y / CELL_SIZE))) { iterator = mwl->last; while (1) { if ((iterator->object)->type == MOVING_WALL) { x = (((int)((iterator->object)->anchor)->x ) / CELL_SIZE); y = (((int)((iterator->object)->anchor)->y ) / CELL_SIZE); count = 0; direction = rand() % 4; while (count < 4) { dx = 0; dy = 0; switch (direction) { case 0: dx = 1; break; case 1: dy = 1; break; case 2: dx = -1; break; default: dy = -1; break; } if(COORD((x+dx),(y+dy)) == COORD(((int)save_eye->x / CELL_SIZE), ((int)save_eye->y / CELL_SIZE)) || !IS_PLAYABLE(COORD((x+dx),(y+dy))) || (dx == 1 && END_RIGHT(COORD(x,y))) || (dy == 1 && END_TOP(COORD(x,y))) || (dx == -1 && END_LEFT(COORD(x,y))) || (dy == -1 && END_BOTTOM(COORD(x,y))) ) { direction = (direction + 1) % 4; ++count; } else { if(laby->matrix[COORD(x,y)] == SPIKES_MW) { laby->matrix[COORD(x,y)] = SPIKES; } else if (laby->matrix[COORD(x,y)] == MOVING_WALL) { laby->matrix[COORD(x,y)] = PASS; } if(laby->matrix[COORD((x+dx),(y+dy))] == PASS) { laby->matrix[COORD((x+dx),(y+dy))] = MOVING_WALL; } else if (laby->matrix[COORD((x+dx),(y+dy))] == SPIKES) { laby->matrix[COORD((x+dx),(y+dy))] = SPIKES_MW; } ((iterator->object)->anchor)->x += (dx * CELL_SIZE); ((iterator->object)->anchor)->y += (dy * CELL_SIZE); count = 4; } } } if (iterator->next != NULL) { iterator = iterator->next; } else { break; } } } /*fprintf(stderr, "%d %d\n", conf->mousex - SCREEN_MID_WIDTH, conf->mousey - SCREEN_MID_HEIGHT);*/ if (!conf->viewMode && (( save_eye->x > 2 && save_eye->y > 2 && save_eye->x < (CELL_SIZE * WIDTH) - 2 && save_eye->y < (CELL_SIZE * HEIGHT) - 2 /*&& save_eye->z <= CHARACTER_SIZE && save_eye->z > CHARACTER_SIZE - 3*/ && IS_PLAYABLE(COORD((int)(save_eye->x / CELL_SIZE),(int)(save_eye->y / CELL_SIZE))) && IS_PLAYABLE(COORD((int)((save_eye->x + 2) / CELL_SIZE),(int)((save_eye->y) / CELL_SIZE))) && IS_PLAYABLE(COORD((int)((save_eye->x) / CELL_SIZE),(int)((save_eye->y + 2) / CELL_SIZE))) && IS_PLAYABLE(COORD((int)((save_eye->x - 2) / CELL_SIZE),(int)((save_eye->y) / CELL_SIZE))) && IS_PLAYABLE(COORD((int)((save_eye->x) / CELL_SIZE),(int)((save_eye->y - 2) / CELL_SIZE))) ) || conf->free_fly == 1 )) { conf->eye->x = save_eye->x; conf->eye->y = save_eye->y; conf->eye->z = save_eye->z; } /* Mouse motion */ if(!conf->viewMode) { conf->theta -= (conf->mousex - SCREEN_MID_WIDTH) * SENSITIVITY; conf->phi -= (conf->mousey - SCREEN_MID_HEIGHT) * SENSITIVITY; SDL_WarpMouse(SCREEN_MID_WIDTH, SCREEN_MID_HEIGHT); modify_direction(); change_center(); } else { conf->eye->x = conf->center->x + CELL_SIZE * WIDTH * cos(conf->theta * M_PI / 180); conf->eye->y = conf->center->y + CELL_SIZE * HEIGHT * sin(conf->theta * M_PI / 180); conf->theta += 0.5; if (conf->theta >= 360) { conf->theta = 0; } } if (conf->life <= 0) { fprintf(stderr," .,---.\n"); fprintf(stderr," ,/XM#MMMX;,\n"); fprintf(stderr," -%%##########M%%,\n"); fprintf(stderr," -@######%% $###@=\n"); fprintf(stderr," .,--, -H#######$ $###M:\n"); fprintf(stderr," ,;$M###MMX; .;##########$;HM###X=\n"); fprintf(stderr," ,/@##########H= ;################+\n"); fprintf(stderr,"-+#############M/, %%##############+\n"); fprintf(stderr,"%%M###############= /##############:\n"); fprintf(stderr,"H################ .M#############;.\n"); fprintf(stderr,"@###############M ,@###########M:.\n"); fprintf(stderr,"X################, -$=X#######@:\n"); fprintf(stderr,"/@##################%%- +######$-\n"); fprintf(stderr,".;##################X .X#####+,\n"); fprintf(stderr," .;H################/ -X####+.\n"); fprintf(stderr," ,;X##############, .MM/\n"); fprintf(stderr," ,:+$H@M#######M#$- .$$=\n"); fprintf(stderr," .,-=;+$@###X: ;/=.\n"); fprintf(stderr," .,/X$; .::,\n"); fprintf(stderr," ., ..\n"); fprintf(stderr,"Haw Haw ! You lose !\n"); conf->quit = 1; } if (IS_EXIT(COORD((int)(conf->eye->x / CELL_SIZE), (int)(conf->eye->y / CELL_SIZE))) && !conf->free_fly) { if (!conf->win) { fprintf(stderr, "\n #,\n"); fprintf(stderr, " ###\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " ####\n"); fprintf(stderr, " |\n"); fprintf(stderr, " #####\n"); fprintf(stderr, " ######\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " ## ##########\n"); fprintf(stderr, " ## #############\n"); fprintf(stderr, " ####### ###############\n"); fprintf(stderr, " #############################\n"); fprintf(stderr, " .###################################\n"); fprintf(stderr, " #####################################;\n"); fprintf(stderr, " ## ##.\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " #####################################\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " ## ###\n"); fprintf(stderr, " ##### #####\n"); fprintf(stderr, " ### ##################################### ###\n"); fprintf(stderr, " ### ## ## ###\n"); fprintf(stderr, " ## ## ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,, ## ##\n"); fprintf(stderr, " ## ##################################### ##\n"); fprintf(stderr, " ## ##\n"); fprintf(stderr, " #### ####\n"); fprintf(stderr, " ###### ######\n"); fprintf(stderr, " ###############################\n"); fprintf(stderr, "The cake was not a lie !\n"); } if (strcmp(conf->music, "music/music3.mp3")) { conf->music = "music/music3.mp3"; music_new(); } conf->win = 1; } /* Display with FPS care */ current_time = SDL_GetTicks(); ellapsed_time = current_time - last_time; last_time = current_time; display(); ellapsed_time = SDL_GetTicks() - start_time; if (ellapsed_time < 25) { SDL_Delay(25 - ellapsed_time); } point_free(save_eye); } }