#ifndef lint
static	char sccsid[] = "@(#)gaintool.c 1.2 89/12/22 Copyr 1989 Sun Micro";
#endif

/*
 * Copyright (c) 1989 by Sun Microsystems, Inc.
 */

#include <stdio.h>
#include <fcntl.h>
#include <strings.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <stropts.h>

#include <sun/audioio.h>

#include <suntool/sunview.h>
#include <suntool/panel.h>
#include <suntool/canvas.h>
#include <suntool/seln.h>

static	short	icon_image[] = {
#include "gaintool.icon"
};
mpr_static(Icon_pixrect, 64, 64, 1, icon_image);

static	short	on_image[] = {
#include <images/panel_choice_on.pr>
};
mpr_static(On_image, 16, 16, 1, on_image);

static	short	off_image[] = {
#include <images/panel_choice_off.pr>
};
mpr_static(Off_image, 16, 16, 1, off_image);


#ifdef OPENLOOK
/* Special hacks to make SunView/OpenLook compatibility work */
/* XXX - The on/off images in the status panel still don't work in OpenLook */
#define	Pixrect					char
#define	panel_button_image(x, str, y, z)	str
#define	PANEL_LABEL_IMAGE			PANEL_LABEL_STRING
#endif


#define	AUDIO_IODEV	"/dev/audio"
#define	AUDIO_CTLDEV	"/dev/audioctl"

#define	MAX_GAIN	100

#define	FPRINTF (void) fprintf
#define	SPRINTF (void) sprintf
#define	STRCPY  (void) strcpy


Frame		Base_frame;
Panel		Main_panel;
Panel_item	play_volume_item;
Panel_item	record_volume_item;
Panel_item	monitor_volume_item;
Panel_item	speaker_item;
Panel_item	pause_item;
Pixrect		*Pause_button;
Pixrect		*Resume_button;

int		Show_status;
Frame		Status_frame;
Panel_item	play_open_item;
Panel_item	play_active_item;
Panel_item	play_pause_item;
Panel_item	play_error_item;
Panel_item	play_waiting_item;
Panel_item	play_eof_item;
Panel_item	play_samples_item;
Panel_item	play_sample_rate_item;
Panel_item	play_channels_item;
Panel_item	play_precision_item;
Panel_item	play_encoding_item;
Panel_item	record_open_item;
Panel_item	record_active_item;
Panel_item	record_pause_item;
Panel_item	record_error_item;
Panel_item	record_waiting_item;
Panel_item	record_samples_item;
Panel_item	record_sample_rate_item;
Panel_item	record_channels_item;
Panel_item	record_precision_item;
Panel_item	record_encoding_item;


Notify_value	sigpoll_handler();
Notify_value	timer_handler();
void		show_status();

int		Audio_pausefd = -1;
int		Audio_pauseflag = 0;
int		Audio_fd;
audio_info_t	Audio_info;
audio_info_t	Audio_new;

main(argc, argv)
	int	argc;
	char	*argv[];
{
	Icon	icon;

	icon = icon_create(ICON_IMAGE, &Icon_pixrect, 0);

	Base_frame = window_create(NULL, FRAME,
	    FRAME_ARGS,				argc, argv,
	    FRAME_ICON,				icon,
	    FRAME_LABEL,
	    "           AUDIO CONTROL PANEL",
	    FRAME_SUBWINDOWS_ADJUSTABLE,	FALSE,
#ifndef notdef
/* XXX - SunView/OpenLook compatibility doesn't like FRAME_PROPS_ACTION_PROP */
	    FRAME_PROPS_ACTION_PROC,		show_status,
	    FRAME_PROPS_ACTIVE,			TRUE,
#endif
	    0);
	if (Base_frame == (Frame) 0) {
		FPRINTF(stderr, "Can't get base frame\n");
		exit(1);
	}

	/* Set up to catch SIGPOLL */
	(void) notify_set_signal_func(Base_frame,
	    (Notify_func)sigpoll_handler, SIGPOLL, NOTIFY_SYNC);

	audio_open();
	create_main_panel();
	create_status_panel();
	update_panels();

	window_fit(Base_frame);
	window_set(Base_frame, WIN_SHOW, TRUE, 0);
	window_main_loop(Base_frame);
	exit(0);
/*NOTREACHED*/
}


/*
 * Entered any time there is a change of state of the audio device.
 * However, the Notifier schedules this routine synchronously, so
 * we don't have to worry about stomping on gloabal data structures.
 */
/*ARGSUSED*/
Notify_value
sigpoll_handler(client, sig, when)
	Notify_client		client;
	int			sig;
	Notify_signal_mode	when;
{
	update_panels();
	return (NOTIFY_DONE);
}

/*
 * Get the latest device state and update the panels appropriately.
 */
update_panels()
{
	char	buf[128];

	/* Only change settings that changed, to avoid flashing */
#define	NEWVAL(X, Y)	{						\
			if (Audio_new.X != Audio_info.X)		\
				(void) panel_set_value(Y, Audio_new.X);	\
			}


#define	NEWSTATE(X, Y)	{						\
			if (Audio_new.X != Audio_info.X)		\
				(void) panel_set(Y,			\
				    PANEL_MARK_IMAGE, 0, (Audio_new.X ?	\
				    &On_image : &Off_image), 0);	\
			}

#define	NEWSTRING(X, Y) {						\
			if (Audio_new.X != Audio_info.X) {		\
				SPRINTF(buf, "%u", Audio_new.X);	\
				(void) panel_set_value(Y, buf);		\
			} }

	/* Get the current device state */
	getinfo(&Audio_new);

	/* Update main panel items */
	NEWVAL(play.gain, play_volume_item);
	NEWVAL(record.gain, record_volume_item);
	NEWVAL(monitor_gain, monitor_volume_item);
	NEWVAL(play.port, speaker_item);

	/*
	 * Pause is tricky, since we may be holding the device open.
	 * If 'resume', then release the device, if held.
	 */
	if (!Audio_new.play.pause && (Audio_pausefd >= 0)) {
		(void) close(Audio_pausefd);
		Audio_pausefd = -1;
	}

	if (Audio_new.play.pause != Audio_info.play.pause) {
		if (Audio_new.play.pause) {
			set_button(pause_item, Resume_button);
		} else {
			set_button(pause_item, Pause_button);
		}
	}


	/* Update status panel, if it is visible */
	if (Show_status) {
		NEWSTATE(play.open, play_open_item);
		NEWSTATE(play.pause, play_pause_item);
		NEWSTATE(play.active, play_active_item);
		NEWSTATE(play.error, play_error_item);
		NEWSTATE(play.waiting, play_waiting_item);
		NEWSTRING(play.eof, play_eof_item);
		NEWSTRING(play.sample_rate, play_sample_rate_item);
		NEWSTRING(play.channels, play_channels_item);
		NEWSTRING(play.precision, play_precision_item);

		/* Handle huge numbers 'gracefully' */
		if (Audio_new.play.samples != Audio_info.play.samples) {
			char	*pre;
			int	i;

			if (Audio_new.play.samples < 1000000) {
				pre = "    ";
				i = -6;		/* left-justified */
			} else {
				pre = "";
				i = 10;		/* right-justified */
			}
			SPRINTF(buf, "%s%*u", pre, i, Audio_new.play.samples);
			(void) panel_set_value(play_samples_item, buf);
		}
		if (Audio_new.play.encoding != Audio_info.play.encoding) {
			encode_string(Audio_new.play.encoding, buf);
			(void) panel_set_value(play_encoding_item, buf);
		}

		NEWSTATE(record.open, record_open_item);
		NEWSTATE(record.active, record_active_item);
		NEWSTATE(record.pause, record_pause_item);
		NEWSTATE(record.error, record_error_item);
		NEWSTATE(record.waiting, record_waiting_item);
		NEWSTRING(record.sample_rate, record_sample_rate_item);
		NEWSTRING(record.channels, record_channels_item);
		NEWSTRING(record.precision, record_precision_item);

		/* Handle huge numbers 'gracefully' */
		if (Audio_new.record.samples != Audio_info.record.samples) {
			char	*pre;
			int	i;

			if (Audio_new.record.samples < 1000000) {
				pre = "    ";
				i = -6;		/* left-justified */
			} else {
				pre = "";
				i = 10;		/* right-justified */
			}
			SPRINTF(buf, "%s%*u", pre, i, Audio_new.record.samples);
			(void) panel_set_value(record_samples_item, buf);
		}
		if (Audio_new.record.encoding != Audio_info.record.encoding) {
			encode_string(Audio_new.record.encoding, buf);
			(void) panel_set_value(record_encoding_item, buf);
		}
	}
	/* Save latest values */
	Audio_info = Audio_new;
}

encode_string(enc, bp)
	unsigned	enc;
	char		*bp;
{
	switch (enc) {
	case AUDIO_ENCODING_ULAW:
		STRCPY(bp, "u-law"); break;
	case AUDIO_ENCODING_ALAW:
		STRCPY(bp, "A-law"); break;
	default:
		SPRINTF(bp, "[%d]", enc); break;
	}
}

set_button(item, pr)
	Panel_item	item;
	Pixrect		*pr;
{
	(void) panel_set(item, PANEL_LABEL_IMAGE, pr, 0);
}

/* Display the status panel when the PROPS key is hit */
/*ARGSUSED*/
void
show_status(win, event, arg)
	Window	win;
	Event	*event;
	caddr_t	arg;
{
	if (!Show_status) {
		Rect	*r;
		int	sb, fp,	fhw, phw;
		int	x, y;

		/* Put status under tool, unless tool is near screen bottom */
		r = (Rect *) window_get(Base_frame, WIN_SCREEN_RECT);
		sb = r->r_height;
		fp = (int) window_get(Base_frame, WIN_Y);
		fhw = (int) window_get(Base_frame, WIN_HEIGHT);
		phw = (int) window_get(Status_frame, WIN_HEIGHT);
		if ((fp + fhw + phw) > sb)
			y = -(phw + 6);		/* leave room for shadow */
		else
			y = fhw;

		/* Center status under tool, unless off-screen */
		fp = (int) window_get(Base_frame, WIN_X);
		fhw = (int) window_get(Base_frame, WIN_WIDTH);
		phw = (int) window_get(Status_frame, WIN_WIDTH);
		x = (fhw - phw) / 2;
		if ((fp + x) < 0)
			x = 0;
		else if ((fp + x + phw) > r->r_width)
			x = r->r_width - fp - phw;

		(void) window_set(Status_frame,
		    WIN_X,		x,
		    WIN_Y,		y,
		    0);
	}

	/* Init info so that update_panels() resets everything */
	AUDIO_INITINFO(&Audio_info);
	Show_status = TRUE;
	update_panels();

	/* bring status panel to top of display */
	(void) window_set(Status_frame, WIN_SHOW, FALSE, 0);
	(void) window_set(Status_frame, WIN_SHOW, TRUE, 0);
}


/* Timer handler...entered periodically when the mouse is in the status panel */
/*ARGSUSED*/
Notify_value
timer_handler(client, which)
	Notify_client	client;
	int		which;
{
	update_panels();
	return (NOTIFY_DONE);
}

/* When the mouse enters the status panel, set a periodic timer */
/*ARGSUSED*/
void
status_loc(win, event, arg)
	Window			win;
	Event			*event;
	caddr_t			arg;
{
	struct itimerval	timer;

	switch (event_action(event)) {
	case LOC_WINENTER:
		/* Set up to catch interval timer */
		timer.it_value.tv_usec = 1000000 / 4;		/* 1/4 second */
		timer.it_value.tv_sec = 0;
		timer.it_interval.tv_usec = 1000000 / 4;	/* 1/4 second */
		timer.it_interval.tv_sec = 0;

		(void) notify_set_itimer_func(Base_frame,
		    (Notify_func)timer_handler, ITIMER_REAL,
		    &timer, (struct itimerval *)0);
		break;

	case LOC_WINEXIT:
		/* Cancel timer */
		(void) notify_set_itimer_func(Base_frame,
		    (Notify_func)timer_handler, ITIMER_REAL,
		    (struct itimerval *)0, (struct itimerval *)0);
		break;
	}
}


/*ARGSUSED*/
done_status(frame)
	Frame	frame;
{
	if (Show_status) {
		Show_status = FALSE;
		(void) window_set(Status_frame, WIN_SHOW, FALSE, 0);
	}
}


audio_open()
{
	if ((Audio_fd = open(AUDIO_CTLDEV, O_RDWR)) < 0) {
		perror(AUDIO_CTLDEV);
		exit(1);
	}

	/*
	 * Set the notify flag so that this program (and all others
	 * with this stream open) will be sent a SIGPOLL if changes
	 * are made to the parameters of audio device.
	 */
	if (ioctl(Audio_fd, I_SETSIG, S_MSG) < 0) {
		perror("I_SETSIG");
		exit(1);
	}

	/* Init the state structure so update_panels() will set everything */
	AUDIO_INITINFO(&Audio_info);
}

/* Convert local gain into device parameters */
unsigned
scale_gain(g)
	unsigned	g;
{
	return (AUDIO_MIN_GAIN + (unsigned)
	    irint(((double) (AUDIO_MAX_GAIN - AUDIO_MIN_GAIN)) *
	    ((double)g / (double)MAX_GAIN)));
}

/* Convert device gain into the local scaling factor */
unsigned
unscale_gain(g)
	unsigned	g;
{
	return ((unsigned) irint((double)MAX_GAIN *
	    (((double)(g - AUDIO_MIN_GAIN)) /
	    (double)(AUDIO_MAX_GAIN - AUDIO_MIN_GAIN))));
}


/* Get current audio state */
getinfo(ap)
	audio_info_t	*ap;
{
	if (ioctl(Audio_fd, AUDIO_GETINFO, ap) < 0) {
		perror("AUDIO_GETINFO");
	}

	/* Set the output port to a value we understand */
	ap->play.port = (ap->play.port == AUDIO_SPEAKER ? 0 : 1);

	ap->play.gain = unscale_gain(ap->play.gain);
	ap->record.gain = unscale_gain(ap->record.gain);
	ap->monitor_gain = unscale_gain(ap->monitor_gain);
}


/*
 * The following notify procedures only have to set the appropriate state.
 * Once set, a signal will be generated and the SIGPOLL handler will take
 * care of updating the panels.
 */

/* Internal speaker or external jack */
/*ARGSUSED*/
control_output_proc(item, value, event)
	Panel_item	item;
	int	value;
	Event	*event;
{
	AUDIO_INITINFO(&Audio_new);
	Audio_new.play.port = (value == 0 ? AUDIO_SPEAKER : AUDIO_HEADPHONE);
	if (ioctl(Audio_fd, AUDIO_SETINFO, &Audio_new) < 0) {
		perror("Set output port");
	}
}

/*ARGSUSED*/
play_volume_proc(item, value, event)
	Panel_item	item;
	int	value;
	Event	*event;
{
	AUDIO_INITINFO(&Audio_new);
	Audio_new.play.gain = scale_gain(value);
	if (ioctl(Audio_fd, AUDIO_SETINFO, &Audio_new) < 0) {
		perror("Set play volume");
	}
	/* Since the return value is quantized, always update the display */
	Audio_info.play.gain = ~0;
}

/*ARGSUSED*/
record_volume_proc(item, value, event)
	Panel_item	item;
	int	value;
	Event	*event;
{
	AUDIO_INITINFO(&Audio_new);
	Audio_new.record.gain = scale_gain(value);
	if (ioctl(Audio_fd, AUDIO_SETINFO, &Audio_new) < 0) {
		perror("Set record volume");
	}
	/* Since the return value is quantized, always update the display */
	Audio_info.record.gain = ~0;
}

/*ARGSUSED*/
monitor_volume_proc(item, value, event)
	Panel_item	item;
	int	value;
	Event	*event;
{
	AUDIO_INITINFO(&Audio_new);
	Audio_new.monitor_gain = scale_gain(value);
	if (ioctl(Audio_fd, AUDIO_SETINFO, &Audio_new) < 0) {
		perror("Set monitor volume");
	}
	/* Since the return value is quantized, always update the display */
	Audio_info.monitor_gain = ~0;
}


/*
 * The Pause button only affects output.
 * When pushed, it changes to a Resume button.
 *
 * Setting the pause bit on a device that is not open has no effect.
 * If the button is pressed when the play stream of /dev/audio is closed,
 * we open the device here in order to make sure no output occurs.
 *
 * If the resume button is pressed or any other process sets 'play.resume',
 * we let go of the device in update_panels().
 *
 * Since device open/close signals a state change, update_panels()
 * will take care of switching the button image.
 */
/*ARGSUSED*/
pause_proc(item, value, event)
	Panel_item	item;
	int	value;
	Event	*event;
{
	/* If trying to pause, try to open /dev/audio first */
	if (!Audio_info.play.pause && (Audio_pausefd < 0)) {
		Audio_pausefd = open(AUDIO_IODEV, O_WRONLY | O_NDELAY);
	}

	/* Set up to set the pause bit */
	AUDIO_INITINFO(&Audio_new);
	Audio_new.play.pause = !Audio_info.play.pause;
	if (ioctl(Audio_fd, AUDIO_SETINFO, &Audio_new) < 0) {
		perror("pause/resume");
	}
}

Notify_value
main_event_proc(window, event, arg, type)
	Window			window;
	Event			*event;
	Notify_arg		arg;
	Notify_event_type	type;
{
	if ((event_action(event) == ACTION_PROPS) && event_is_up(event)) {
		show_status(window, event, arg);
		return (NOTIFY_DONE);
	}
	return (notify_next_event_func(window, event, arg, type));
}

create_main_panel()
{
	Main_panel = window_create(Base_frame, PANEL,
	    WIN_LEFT_MARGIN,	10,
	    WIN_WIDTH,		ATTR_COL(40),
	    0);

	notify_interpose_event_func(Main_panel, main_event_proc, NOTIFY_SAFE);

	play_volume_item = panel_create_item(Main_panel, PANEL_SLIDER,
	    PANEL_ITEM_X,	ATTR_COL(0),
	    PANEL_ITEM_Y,	ATTR_ROW(0),
	    PANEL_LABEL_STRING, "Play volume    ",
	    PANEL_VALUE_X,	ATTR_COL(16),
	    PANEL_MIN_VALUE,	0,
	    PANEL_MAX_VALUE,	MAX_GAIN,
	    PANEL_SLIDER_WIDTH,	MAX_GAIN+1,
	    PANEL_NOTIFY_PROC,	play_volume_proc,
	    PANEL_NOTIFY_LEVEL,	PANEL_ALL,
	    PANEL_SHOW_RANGE,	FALSE,
	    PANEL_SHOW_VALUE,	TRUE,
	    0);

	record_volume_item = panel_create_item(Main_panel, PANEL_SLIDER,
	    PANEL_ITEM_X,	ATTR_COL(0),
	    PANEL_ITEM_Y,	ATTR_ROW(1),
	    PANEL_LABEL_STRING, "Record volume  ",
	    PANEL_VALUE_X,	ATTR_COL(16),
	    PANEL_MIN_VALUE,	0,
	    PANEL_MAX_VALUE,	MAX_GAIN,
	    PANEL_SLIDER_WIDTH,	MAX_GAIN+1,
	    PANEL_NOTIFY_PROC,	record_volume_proc,
	    PANEL_NOTIFY_LEVEL,	PANEL_ALL,
	    PANEL_SHOW_RANGE,	FALSE,
	    PANEL_SHOW_VALUE,	TRUE,
	    0);

	monitor_volume_item = panel_create_item(Main_panel, PANEL_SLIDER,
	    PANEL_ITEM_X,	ATTR_COL(0),
	    PANEL_ITEM_Y,	ATTR_ROW(2),
	    PANEL_LABEL_STRING, "Monitor volume ",
	    PANEL_VALUE_X,	ATTR_COL(16),
	    PANEL_MIN_VALUE,	0,
	    PANEL_MAX_VALUE,	MAX_GAIN,
	    PANEL_SLIDER_WIDTH,	MAX_GAIN+1,
	    PANEL_NOTIFY_PROC,	monitor_volume_proc,
	    PANEL_NOTIFY_LEVEL,	PANEL_ALL,
	    PANEL_SHOW_RANGE,	FALSE,
	    PANEL_SHOW_VALUE,	TRUE,
	    0);

	speaker_item = panel_create_item(Main_panel, PANEL_CHOICE,
	    PANEL_ITEM_X,	ATTR_COL(0),
	    PANEL_ITEM_Y,	ATTR_ROW(3),
	    PANEL_LABEL_STRING,	"Output:",
	    PANEL_CHOICE_STRINGS,	"Spkr",
					"Jack",
					0,
	    PANEL_NOTIFY_PROC,	control_output_proc,
	    0);

	Pause_button = panel_button_image(Main_panel, "Pause Play",
	    10, (Pixfont *) 0);
	Resume_button = panel_button_image(Main_panel, "Resume",
	    10, (Pixfont *) 0);

	pause_item = panel_create_item(Main_panel, PANEL_BUTTON,
	    PANEL_ITEM_X,	ATTR_COL(27),
	    PANEL_ITEM_Y,	ATTR_ROW(3),
	    PANEL_NOTIFY_PROC,	pause_proc,
	    0);

	window_fit_height(Main_panel);
}


create_status_panel()
{
	Panel	Status_panel;

	Status_frame = window_create(Base_frame, FRAME,
	    FRAME_LABEL,	"             Audio Device Status",
	    FRAME_SHOW_LABEL,			TRUE,
	    FRAME_DONE_PROC,			done_status,
	    FRAME_SUBWINDOWS_ADJUSTABLE,	FALSE,
	    WIN_CONSUME_PICK_EVENTS,		LOC_WINENTER, LOC_WINEXIT, 0,
	    WIN_EVENT_PROC,			status_loc,
	    0);

	/* Record status panel */
	Status_panel = window_create(Status_frame, PANEL,
	    PANEL_EVENT_PROC,			status_loc,
	    PANEL_BACKGROUND_PROC,		status_loc,
	    0);

	(void) panel_create_item(Status_panel, PANEL_BUTTON,
	    PANEL_LABEL_STRING,		"PLAY STATUS",
	    PANEL_LABEL_BOLD,		TRUE,
	    PANEL_ITEM_X,		ATTR_COL(5),
	    PANEL_ITEM_Y,		ATTR_ROW(0),
	    0);
	play_open_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Open:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(2),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	play_pause_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Paused:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(3),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	play_active_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Active:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(5),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	play_error_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Underflow:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(6),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	play_waiting_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Open-Waiting:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(7),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	play_eof_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"EOF count:   ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(9),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);
	play_samples_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Samples: ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(10),
	    PANEL_VALUE_X,		ATTR_COL(10),
	    PANEL_VALUE_DISPLAY_LENGTH,	10,
	    0);
	play_sample_rate_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Sample Rate: ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(12),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);
	play_channels_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Channels:    ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(13),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);
	play_precision_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Precision:   ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(14),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);
	play_encoding_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Encoding:    ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(15),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);

	/* Make the caret invisible */
	window_set(Status_panel, PANEL_CARET_ITEM, (Panel)0, 0);
	window_fit(Status_panel);

	/* Record status panel */
	Status_panel = window_create(Status_frame, PANEL,
	    PANEL_EVENT_PROC,			status_loc,
	    PANEL_BACKGROUND_PROC,		status_loc,
	    0);

	(void) panel_create_item(Status_panel, PANEL_BUTTON,
	    PANEL_LABEL_STRING,		"RECORD STATUS",
	    PANEL_LABEL_BOLD,		TRUE,
	    PANEL_ITEM_X,		ATTR_COL(4),
	    PANEL_ITEM_Y,		ATTR_ROW(0),
	    0);
	record_open_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Open:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(2),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	record_pause_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Paused:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(3),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	record_active_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Active:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(5),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	record_error_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Overflow: ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(6),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	record_waiting_item = panel_create_item(Status_panel, PANEL_CHOICE,
	    PANEL_LABEL_STRING,		"Open-Waiting:",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(7),
	    PANEL_MARK_X,		0, ATTR_COL(14),
	    0);
	record_samples_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Samples: ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(10),
	    PANEL_VALUE_X,		ATTR_COL(10),
	    PANEL_VALUE_DISPLAY_LENGTH,	10,
	    0);
	record_sample_rate_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Sample Rate: ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(12),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);
	record_channels_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Channels:    ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(13),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);
	record_precision_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Precision:   ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(14),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);
	record_encoding_item = panel_create_item(Status_panel, PANEL_TEXT,
	    PANEL_LABEL_STRING,		"Encoding:    ",
	    PANEL_ITEM_X,		ATTR_COL(0),
	    PANEL_ITEM_Y,		ATTR_ROW(15),
	    PANEL_VALUE_X,		ATTR_COL(14),
	    PANEL_VALUE_DISPLAY_LENGTH,	7,
	    0);

	/* Make the caret invisible */
	window_set(Status_panel, PANEL_CARET_ITEM, (Panel)0, 0);
	window_fit(Status_panel);

	window_fit(Status_frame);
}
