[comp.windows.x] SunOS 4.1.x diffs for SPARCstation audio version of `oclock'

earle@POSEUR.JPL.NASA.GOV (Greg Earle - Sun JPL on-site Software Support) (12/13/90)

I pulled the SPARCstation audio-ized version of `oclock' from expo's contrib
directory (much thanks to Mike Wagner - wagner@cadillac.Siemens.COM - for this!)
and built it under SunOS 4.1.1, but found that the code to handle playing the
audio file (from Jef Poskanser's PD SPARCstation audio toolkit) was written for
the original SunOS 4.0.3c audio interface.

A couple of days of whacking and I think I've got it fairly ship-shape.  A
small bit of code was shamelessly pilfered from the 4.1.1 /usr/demo/SOUND/play
program, because of the new 4.1.x audio interface changes.

I took the sample audio files and stored them in /usr/local/lib/X11/oclock;
here are the .Xdefaults/.Xresources resources that I am using (as an example):

Clock*Background:	grey
Clock*BorderColor:	yellow
Clock*hour:		black
Clock*jewel:		coral
Clock*minute:		black
Clock*hourSound:	/usr/local/lib/X11/oclock/BigBen.au
Clock*quarterPastSound:	/usr/local/lib/X11/oclock/GrandfatherClock.au
Clock*halfPastSound:	/usr/local/lib/X11/oclock/GrandfatherClock.au
Clock*quarterOfSound:	/usr/local/lib/X11/oclock/GrandfatherClock.au
Clock*chimeSound:	/usr/local/lib/X11/oclock/TowerClock.au
Clock*volumeSound:	90

Here are the diffs that I've come up with; it changes the Imakefile to define
`SUNOS4_1'.  So, after applying these diffs, if you are running 4.1, leave
everything alone and gen a Makefile with `xmkmf' or `imake' and compile.  If
you're still running 4.0.3c, remove the `-DSUNOS4_1' from the Imakefile before
gen'ing the Makefile.

*** Imakefile.orig	Thu Feb  1 06:55:17 1990
--- Imakefile	Thu Dec 13 00:37:11 1990
***************
*** 3,9 ****
  #endif
  
! DEFINES = ExtensionDefines
! INCLUDES = -I$(TOP) -I$(TOP)/X11
! SYS_LIBRARIES = -lm
  DEPLIBS = $(DEPXTOOLLIB) $(DEPXMULIB) $(DEPEXTENSIONLIB) $(DEPXLIB)
  LOCAL_LIBRARIES = $(XTOOLLIB) $(XMULIB) $(EXTENSIONLIB) $(XLIB)
--- 3,9 ----
  #endif
  
! DEFINES = ExtensionDefines -DSUNOS4_1
! INCLUDES = -I$(TOP) -I$(TOP)/X11 -I/usr/demo/SOUND
! SYS_LIBRARIES = -L/usr/demo/SOUND -laudio -lm
  DEPLIBS = $(DEPXTOOLLIB) $(DEPXMULIB) $(DEPEXTENSIONLIB) $(DEPXLIB)
  LOCAL_LIBRARIES = $(XTOOLLIB) $(XMULIB) $(EXTENSIONLIB) $(XLIB)
*** libsst.h.orig	Thu Feb  1 06:52:25 1990
--- libsst.h	Wed Dec 12 01:35:12 1990
***************
*** 12,16 ****
--- 12,24 ----
  
  #include <sys/ioctl.h>
+ #ifdef SUNOS4_1
+ #define AUDIO_4_0_3_COMPAT
+ #define AUDIO_CHIP
+ #include <sbusdev/audio_79C30.h>
+ #include <multimedia/libaudio.h>
+ #include <multimedia/audio_device.h>
+ #else
  #include <sbusdev/audioreg.h>
+ #endif
  #include <sun/audioio.h>
  
*** play.c.orig	Thu Feb  1 06:52:16 1990
--- play.c	Thu Dec 13 00:24:59 1990
***************
*** 43,46 ****
--- 43,78 ----
  	return( 1 );
      }
+ #ifdef SUNOS4_1
+     {
+     int err;
+     Audio_hdr Dev_hdr;
+     Audio_hdr File_hdr;
+ 
+     err = audio_get_play_config( sst_fd, &Dev_hdr );
+ 
+     if ( err != AUDIO_SUCCESS )
+     {
+ 	perror( "Not a valid audio device" );
+ 	return( 1 );
+     }
+ 
+     err = audio_read_filehdr( file_fd, &File_hdr, (char *) NULL, 0 );
+ 
+     if ( err != AUDIO_SUCCESS )
+     {
+ 	perror( "Not a valid audio file" );
+ 	return( 1 );
+     }
+ 
+     /* Shameless pilfered from /usr/demo/SOUND/play.c */
+     if ( audio_cmp_hdr(&Dev_hdr, &File_hdr) != 0 ) {
+ 	if ( audio_drain( sst_fd, FALSE) != AUDIO_SUCCESS) {
+ 	    perror( "draining audio device" );
+ 	    return( 1 );
+ 	}
+     /* Fancy code to reconfigure audio device for given file header omitted */
+     }
+     }
+ #endif
      
      for ( ; ; )
***************
*** 75,78 ****
--- 107,116 ----
      
      close(file_fd);
+ #ifdef SUNOS4_1
+     if ( audio_drain( sst_fd, FALSE) != AUDIO_SUCCESS) {
+ 	perror( "draining audio device" );
+ 	return( 1 );
+     }
+ #endif
      sst_close( sst_fd );
      (void) signal( SIGHUP, sighup_handler );

earle@POSEUR.JPL.NASA.GOV (Greg Earle - Sun JPL on-site Software Support) (12/14/90)

Someone has pointed out to me that my diffs involve adding dependancies on
include files and an audio library that come from the depths of /usr/demo/SOUND
under 4.1.x (namely, libaudio.a and multimedia/*.h).  In case it is not
obvious, one must load the `Demo' software category from the O/S tapes to get
these files.  If the oclock does not compile, this is the most likely reason.

Also, the diff file I placed on `expo' has this additional diff for oclock.c,
shamelessly pilferred from xclock's xclock.c, that makes the program go away
if sent a WM_DELETE from a window manager (e.g., the `f.delete' function of
`twm').  I have a titlebar button to invoke f.delete, and noticed that `xclock'
would politely close up shop but the new `oclock' would not.  Hack, hack, hack.

	- Greg Earle
	  Sun Microsystems
	  earle@poseur.JPL.NASA.GOV
	  earle@Sun.COM

------------------------------------------------------------------------------
*** oclock.c.orig	Thu Apr 12 09:50:03 1990
--- oclock.c	Thu Dec 13 01:38:09 1990
***************
*** 14,17 ****
--- 14,18 ----
  
  extern void exit();
+ static void quit();
  
  /* Command line options table.  Only resources are entered here...there is a
***************
*** 20,23 ****
--- 21,30 ----
  /* Exit with message describing command line format */
  
+ static XtActionsRec xclock_actions[] = {
+     { "quit",   quit },
+ };
+ 
+ static Atom wm_delete_window;
+ 
  void usage()
  {
***************
*** 74,77 ****
--- 81,93 ----
      if (argc != 1) usage();
  
+     XtAddActions (xclock_actions, XtNumber(xclock_actions));
+ 
+     /*
+      * This is a hack so that f.delete will do something useful in this
+      * single-window application.
+      */
+     XtOverrideTranslations(toplevel,
+                     XtParseTranslationTable ("<Message>WM_PROTOCOLS: quit()"));
+ 
      i = 0;
      XtSetArg (arg[i], XtNiconPixmap, 
***************
*** 89,92 ****
--- 105,128 ----
      clock = XtCreateManagedWidget ("clock", clockWidgetClass, toplevel, NULL, 0);
      XtRealizeWidget (toplevel);
+     wm_delete_window = XInternAtom (XtDisplay(toplevel), "WM_DELETE_WINDOW",
+                                     False);
+     (void) XSetWMProtocols (XtDisplay(toplevel), XtWindow(toplevel),
+                             &wm_delete_window, 1);
      XtMainLoop();
  }
+ 
+ static void quit (w, event, params, num_params)
+     Widget w;
+     XEvent *event;
+     String *params;
+     Cardinal *num_params;
+ {
+     if (event->type == ClientMessage &&
+         event->xclient.data.l[0] != wm_delete_window) {
+         XBell (XtDisplay(w), 0);
+         return;
+     }
+     XCloseDisplay (XtDisplay(w));
+     exit (0);
+ }
+ 

stolcke@ICSI.Berkeley.EDU (Andreas Stolcke) (12/14/90)

In article <9012130847.AA21499@poseur.JPL.NASA.GOV>, earle@POSEUR.JPL.NASA.GOV (Greg Earle - Sun JPL on-site Software Support) writes:
|> I took the sample audio files and stored them in /usr/local/lib/X11/oclock;
|> here are the .Xdefaults/.Xresources resources that I am using (as an example):

It should probably be mentioned that the audio files that came with the
original audio-oclock won't work with the fixed one.  One has to run
raw2audio (to be found in /usr/demo/SOUND) on them to convert 
to the new format.

Otherwise, I'm grateful for the patch, I was starting to miss the cockoo
after our recent upgrade to SunOS 4.1 -:)

-- 
Andreas Stolcke
International Computer Science Institute	stolcke@icsi.Berkeley.EDU
1957 Center St., Suite 600, Berkeley, CA 94704	(415) 642-4274 ext. 126