Esempio n. 1
0
/* Sets new volume, expects new_vol to be within [0,100] range. */
bool set_new_volume(
        struct sound_profile* sp,
        long int new_vol,
        bool relative_inc,
        bool set_default_vol,
        bool toggle_vol,
        bool use_semaphore,
        enum Volume_type volume_type)
{
    /* XXX: Checking new_vol limits */
    if (relative_inc) {
        if (new_vol < 0 || new_vol > 100) {
            fprintf(stderr, "Cannot set volume which is not in range [0,100]: %li\n", new_vol);
            return false;
        }
    } else if ((new_vol < -100 || new_vol > 100) && !set_default_vol && !toggle_vol) {
        fprintf(stderr, "Cannot set volume which is not in range [-100,100]: %li\n", new_vol);
        return false;
    }
    /* **************************** */

    sem_t *sem = NULL; /* Semaphore which is used if USE_SEMAPHORE is true */
    if (use_semaphore && !check_semaphore(&sem)) return false;

    /* Change new volume to native range */
    PD_M("set_new_volume: new vol [-100,100], relative or toggling: %li\n", new_vol);

    if (set_default_vol) {
        // Set default volume
        PD_M("set_new_volume: setting default vol..\n");
        set_vol(sp->volume_cntrl_mixer_element, sp->volume_type, sp->default_volume, 0);
    } else if (toggle_vol) {
        // toggle volume
        PD_M("set_new_volume: toggling..\n");
        toggle_volume(sp, new_vol, volume_type);
    } else {
        /* Change absolute and relative volumes */

        /* First check if relative volume */
        if (relative_inc || new_vol < 0) {
            if (new_vol != 0) {
                PD_M("set_new_volume: Relative vol change...\n");
                long int current_vol = 0;
                // Change volume relative to current volume
                get_vol(sp->volume_cntrl_mixer_element, volume_type, &current_vol);
                // By setting the round direction we always guarantee that
                // some change happens.
                int round_direction = new_vol < 0 ? -1 : 1;
                set_vol(sp->volume_cntrl_mixer_element, volume_type, current_vol + new_vol, round_direction);
            }
        } else {
            // Change absolute volume
            PD_M("set_new_volume: Changing absolute volume: %li\n", new_vol);
            set_vol(sp->volume_cntrl_mixer_element, volume_type, new_vol, 0);
        }
    }

    if (use_semaphore && !check_semaphore(&sem)) return false;
    return true;
}
Esempio n. 2
0
int
main(void)
{
        struct items {
                char *up;
                char *load;
                char *fan;
                char *temp;
                char *mem;
                char *swap;
                char *diskio;
                char *fs_root;
                char *fs_home;
                char *fs_storage;
                char *net_speed;
                char *batt;
                char *vol;
                char *time;
                char *status;
        };

	if (!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmstatus: cannot open display.\n");
		return 1;
    }

        struct items *i = malloc(sizeof(struct items));

	while(1) {
		i->up = get_up();
		i->load = get_load();
		i->fan = get_fan();
		i->temp = get_temp();
		i->mem = get_mem();
		i->swap = get_swap();
		i->diskio = get_diskio("sda");
                i->fs_root = get_space("/");
                i->fs_home = get_space("/home");
                i->net_speed = get_net_speed();
		i->batt = get_batt();
		i->vol = get_vol();
		i->time = mktimes("%m/%d/%Y %a %H:%M", tzkiev);

		i->status = smprintf(
                        "up:%s la:%s fan:%s temp:%s m:%s s:%s io:%s /:%s "
                        "~/:%s net:%s bat:%s vol:%s %s",
                        i->up, i->load, i->fan, i->temp, i->mem, i->swap,
                        i->diskio, i->fs_root, i->fs_home, i->net_speed,
                        i->batt, i->vol, i->time);
		setstatus(i->status);

                sleep(INTERVAL);
    }

        free(i);

	XCloseDisplay(dpy);

	return EXIT_SUCCESS;
}
Esempio n. 3
0
void floodfill()
{
    int i;
    cell_t p, p1;
    grid[0][0][0] = -1;
    p.x = p.y = p.z = 0;
    q.push(p);
    while(!q.empty())
    {
        p = q.front(), q.pop();
        vol += get_vol(p.x, p.y, p.z);
        for(i = 0; i < 6; ++i)
        {
            p1.x = p.x+D[i][0], p1.y = p.y+D[i][1], p1.z = p.z+D[i][2];
            if(p1.x < 0 || p1.x >= mx || p1.y < 0 || p1.y >= my || p1.z < 0 || p1.z >= mz)
                continue;
            if(grid[p1.x][p1.y][p1.z] == 0)
            {
                grid[p1.x][p1.y][p1.z] = -1;
                q.push(p1);
            }
            else if(grid[p1.x][p1.y][p1.z] == 1)
            {
                area += get_area(p1.x, p1.y, p1.z, i);
            }
        }
    }
}
Esempio n. 4
0
/* Volume toggler between 0 <--> element default volume.
 * Now excepts new_vol to be in default hardware range of the sound card in use. */
void toggle_volume(
        struct sound_profile* sp,
        long int const new_vol, // If INT_MAX or negative then toggle to sound
                                // profiles default volume
        enum Volume_type volume_type)
{
    // TODO: USE "avolt" SEMAPHORE

    long int current_vol;
    get_vol(sp->volume_cntrl_mixer_element, hardware, &current_vol);
    long int min, _;
    snd_mixer_selem_get_playback_volume_range(sp->volume_cntrl_mixer_element, &min, &_);

    // If current volume is lowest possible
    if (current_vol == min) {
        if (new_vol > 0 && new_vol != INT_MAX)
            set_vol(sp->volume_cntrl_mixer_element, volume_type, new_vol, 0);
        else
            set_vol(sp->volume_cntrl_mixer_element, sp->volume_type, sp->default_volume, 0);
    }
    else {
        // Else zero current volume
        set_vol(sp->volume_cntrl_mixer_element, hardware_percentage, 0, 0);
    }
    return;
}
Esempio n. 5
0
void pool_forward(pool_layer_t* l, vol_t** in, vol_t** out, int start, int end) {
  for (int i = start; i <= end; i++) {
    vol_t* V = in[i];
    vol_t* A = out[i];
        
    int n=0;
    for(int d=0;d<l->out_depth;d++) {
      int x = -l->pad;
      int y = -l->pad;
      for(int ax=0; ax<l->out_sx; x+=l->stride,ax++) {
        y = -l->pad;
        for(int ay=0; ay<l->out_sy; y+=l->stride,ay++) {
  
          double a = -99999;
          for(int fx=0;fx<l->sx;fx++) {
            for(int fy=0;fy<l->sy;fy++) {
              int oy = y+fy;
              int ox = x+fx;
              if(oy>=0 && oy<V->sy && ox>=0 && ox<V->sx) {
                double v = get_vol(V, ox, oy, d);
                if(v > a) { a = v; }
              }
            }
          }
          n++;
          set_vol(A, ax, ay, d, a);
        }
      }
    }
  }
}
Esempio n. 6
0
// Function to dump the content of a volume for comparison.
void dump_vol(vol_t* v) {
  printf("%ld,%ld,%ld", v->sx, v->sy, v->depth);
  for (int x = 0; x < v->sx; x++)
    for (int y = 0; y < v->sy; y++)
      for (int z = 0; z < v->depth; z++) {
        printf(",%.20lf", get_vol(v, x, y, z));
      }
  printf("\n");
}
Esempio n. 7
0
void sound_byte(ubyte iobyte) {      // if a noise program byte, return
    if ((iobyte & 0xE0) == 0xE0) return;

    if ((iobyte & 0x90) == 0x90) get_vol(iobyte);  // if a volume byte
    if ((iobyte & 0x90) == 0x80) get_freq(iobyte); // if a frequency byte
    if (!(iobyte & 0x80)) get_freq(iobyte);      // if a frequency byte
    if (soundyesno) update_sound();            // update sound

}
Esempio n. 8
0
int
main(void) {
	Display *dpy;
	struct iwreq wreq;
	snd_mixer_t *handle;
	snd_mixer_elem_t *elem;
	snd_mixer_selem_id_t *vol_info;
	int sockfd, loops = 60;
	char *status, *mpd, *net, *vol, *bat, *clk;

	if(!(dpy = XOpenDisplay(NULL))) {
		fprintf(stderr, "dwmst: cannot open display.\n");
		exit(EXIT_FAILURE);
	}

	memset(&wreq, 0, sizeof(struct iwreq));
	snprintf(wreq.ifr_name, sizeof(WIRELESS_DEVICE), WIRELESS_DEVICE);
	sockfd = socket(AF_INET, SOCK_DGRAM, 0);

	snd_mixer_open(&handle, 0);
	snd_mixer_attach(handle, "default");
	snd_mixer_selem_register(handle, NULL, NULL);
	snd_mixer_load(handle);
	snd_mixer_selem_id_malloc(&vol_info);
	snd_mixer_selem_id_set_name(vol_info, VOL_CH);
	elem = snd_mixer_find_selem(handle, vol_info);
	if(elem == NULL) {
		fprintf(stderr, "dwmst: can not open device.\n");
		cleanup(dpy, sockfd, handle, vol_info);
		exit(EXIT_FAILURE);
	}

	for(;;sleep(INTERVAL)) {
		if(++loops > 60) {
			loops = 0;
			mpd = get_mpd();
			net = get_net(wreq, sockfd);
			bat = get_bat();
			clk = get_time();
		}
		vol = get_vol(handle, elem);
		status = smprintf("%s  %s  %s  %s  %s", mpd, net, vol, bat, clk);
		setstatus(dpy, status);
		free(vol);
		free(status);
	}

	free(mpd);
	free(net);
	free(bat);
	free(clk);
	cleanup(dpy, sockfd, handle, vol_info);
	exit(EXIT_SUCCESS);
}
Esempio n. 9
0
void bar_upd(int sig) {
    static char barstr[750];
    snprintf(barstr, 750, "%%{l}%s %s %s%%{c}%s%%{r}%s %s %s %s\n",
            get_win((sig == -2 ? false : true)),
            get_hname(),
            get_xtitle((sig == -1 ? false : true)),
            get_mpd(),
            get_vol(),
            get_load(),
            get_uname(),
            get_time());
    fputs(barstr, barfp);
    fflush(barfp);
}
Esempio n. 10
0
int main(void) {
	Display *dpy;
	Window root;
	char status[201], net[30], vol[14], cpu[14], mem[14], bat[48];
	int netloops = 60;

	dpy = XOpenDisplay(NULL);
	if(dpy == NULL) {
		fprintf(stderr, "ERROR: could not open display\n");
		return 1;
	}
	root = XRootWindow(dpy, DefaultScreen(dpy));
	winfo = malloc(sizeof(struct wireless_info));
	memset(winfo, 0, sizeof(struct wireless_info));

	skfd = iw_sockets_open();

	infile = fopen(CPU_F, "r");
	fscanf(infile, "cpu %ld %ld %ld %ld", &jif1, &jif2, &jif3, &jif4); fclose(infile);

	while(1) {
		if(++netloops > 60) {
			netloops = 0;
			get_wifi(net);
		}
		get_vol(vol);
		get_cpu(cpu);
		get_mem(mem);
		get_bat(bat);

		sprintf(status, "%s %s %s %s %s", net, vol, cpu, mem, bat);

		XStoreName(dpy, root, status);
		XFlush(dpy);
		sleep(INTERVAL);
	}
	/* NEXT LINES SHOULD NEVER EXECUTE! */
	XCloseDisplay(dpy);
	iw_sockets_close(skfd);
	return 0;
}
Esempio n. 11
0
void pool_forward(pool_layer_t* l, vol_t** in, vol_t** out, int start, int end) {
  uint64_t tempTime = timestamp_us();
  for (int i = start; i <= end; i++) {
    vol_t* V = in[i];
    vol_t* A = out[i];
        
    int n=0;
    for(int d=0;d<l->out_depth;d++) {
      int y = 0;
      int x = 0;

      int lsx = l->out_sx;
      int lsy = l->out_sy;
      int lusx = l->sx;

      for(int ax=0; ax<lsx; x+=2, ax++) {
        y = 0;
        for(int ay=0; ay<lsy; y+=2,ay++) {
          double a = -99999;
          for(int fx=0;fx<lusx;fx++) {
            for(int fy=0;fy<2;fy++) {
              int oy = y+fy;
              int ox = x+fx;
              if(oy>=0 && oy<32 && ox>=0 && ox<32) {
                double v = get_vol(V, ox, oy, d);
                if(v > a) { a = v; }
              }
            }
          }
          n++;
          set_vol(A, ax, ay, d, a);
        }
      }
    }
  }
  l->myTime += timestamp_us() - tempTime;
}
Esempio n. 12
0
static vol_t* copy_vol(vol_t* dest, vol_t* src) {
  for (int x = 0; x < dest->sx; x++)
    for (int y = 0; y < dest->sy; y++)
      for (int z = 0; z < dest->depth; z++)
        set_vol(dest, x, y, z, get_vol(src, x, y, z));
}
Esempio n. 13
0
static vol_t* copy_vol(vol_t* dest, vol_t* src) {
  for (int x = 0; x < 32; x++)
    for (int y = 0; y < 32; y++)
      for (int z = 0; z < 3; z++)
        set_vol(dest, x, y, z, get_vol(src, x, y, z));
}