[comp.sys.next] NeXT Volume Control

lane@sumex-aim.stanford.edu (Christopher Lane) (03/24/89)

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 <sys/file.h>
#include <sys/ioctl.h>
#include <nextdev/soundvar.h>

#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");
}

jasmerb@mist.cs.orst.edu (Bryce Jasmer) (03/24/89)

In article <23814@labrea.Stanford.EDU> lane@sumex-aim.stanford.edu (Christopher Lane) writes:
>....I've FTP'd [volume.tar] to the submissions directory of the cs.orst.edu
>NeXT archive.

In case anyone couldn't find the volume.tar file, that is because files are
initially sent to "pub/next/submissions" and then I check them over and put
them in their appropriate directory (in this case "pub/next/sources"). For
more information on the directories, get the file "pub/next/00DIR.STRUCTURE".

>...we may be well on the way to a complete Macintosh control panel...

I wouldn't recommend putting too much more work into this. Isn't this going
to be the purpose of the Prefs application that should be out in system
release 0.9 due out in two weeks(??) ?

------------------------------------------------------------------------------
Bryce Jasmer             |
c/o Support Staff        | Internet email: jasmerb@cs.orst.edu
Computer Science Dept.   |
Oregon State University  | NeXT voice mail: jasmerb@hobbes.cs.orst.edu
Corvallis, OR  97331     | 
------------------------------------------------------------------------------