Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!decwrl!labrea!daemon From: lane@sumex-aim.stanford.edu (Christopher Lane) Newsgroups: comp.sys.next Subject: NeXT Volume Control Message-ID: <23814@labrea.Stanford.EDU> Date: 23 Mar 89 21:47:24 GMT Sender: daemon@labrea.Stanford.EDU Lines: 53 As a companion to the display brightness control routine I posted earlier, here's one (below) that provides similar control of the speaker volume (and also saves on finger strain and accidental pushes of the power key). Like 'bright', the command 'volume' (execute it from the shell/terminal) with no argument prints out the current volume value; 'volume max' & 'volume min' will set the volume to the limits and 'volume def' will set it to the default (predefined below and arbitrary). If a numeric argument is given, the volume is set to that value which should range between 'volume min;volume' and 'volume max;volume'. Unlike the 'bright' command, I was able to build a simple slider and button interface which I've FTP'd to the submissions directory of the cs.orst.edu NeXT archive. It's intentionally sparse. If we can get the brightness slider to work (without crashing the machine after use) and a few other similar controls we may be well on the way to a complete Macintosh control panel... Enjoy, - Christopher PS: Yes I know the values for 'min' and 'max' seem reversed below; I only make the routines run (by guess work) I leave to NeXT to explain them. #include #include #include #define VOLUME_DEF 0x08 main(argc, argv) int argc; char *argv[]; { int c = 0, d; if((d = open("/dev/sound0", O_RDWR, 0)) != -1){ if(argc > 1){ if(strncmp(argv[1], "max", 3) == 0) c = VOLUME_MIN; else if(strncmp(argv[1], "min", 3) == 0) c = VOLUME_MAX; else if(strncmp(argv[1], "def", 3) == 0) c = VOLUME_DEF; else c = atoi(argv[1]) & VOLUME_MASK; c |= VOLUME_LCHAN | VOLUME_RCHAN; if(ioctl(d, SOUNDIOCSVOL, &c) == -1) perror("ioctl"); } else if(ioctl(d, SOUNDIOCGVOL, &c) == -1) perror("ioctl"); else printf("%d\n", c & VOLUME_MASK); if(close(d) == -1) perror("close"); } else perror("open"); }