home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / utils / sound / players / unix / olvm / olvwmtls.c < prev    next >
Encoding:
Text File  |  1993-02-10  |  6.7 KB  |  366 lines

  1. *
  2.  * olvwmtool_stubs.c - Notify and event callback function stubs.
  3.  * This file was generated by `gxv' from `olvwmtool.G'.
  4.  */
  5.  
  6. include <stdio.h>
  7. include <sys/param.h>
  8. include <sys/types.h>
  9. include <xview/xview.h>
  10. include <xview/panel.h>
  11. include <xview/textsw.h>
  12. include <xview/xv_xrect.h>
  13. include <rplay.h>
  14. include <string.h>
  15. include "olvwmtool_ui.h"
  16.  
  17.  
  18. *
  19.  * Global object definitions.
  20.  */
  21. lvwmtool_main_objects    *Olvwmtool_main;
  22.  
  23. har    *eventNames[] =
  24.  
  25.     "<EventZero>",
  26.     "<EventOne>",
  27.     "KeyPress",
  28.     "KeyRelease",
  29.     "ButtonPress",
  30.     "ButtonRelease",
  31.     "MotionNotify",
  32.     "EnterNotify",
  33.     "LeaveNotify",
  34.     "FocusIn",
  35.     "FocusOut",
  36.     "KeymapNotify",
  37.     "Expose",
  38.     "GraphicsExpose",
  39.     "NoExpose",
  40.     "VisibilityNotify",
  41.     "CreateNotify",
  42.     "DestroyNotify",
  43.     "UnmapNotify",
  44.     "MapNotify",
  45.     "MapRequest",
  46.     "ReparentNotify",
  47.     "ConfigureNotify",
  48.     "ConfigureRequest",
  49.     "GravityNotify",
  50.     "ResizeRequest",
  51.     "CirculateNotify",
  52.     "CirculateRequest",
  53.     "PropertyNotify",
  54.     "SelectionClear",
  55.     "SelectionRequest",
  56.     "SelectionNotify",
  57.     "ColormapNotify",
  58.     "ClientMessage",
  59.     "MappingNotify",
  60.     "Startup",
  61.     "Shutdown",
  62. ;
  63.  
  64. define    NEVENTS        (sizeof(eventNames) / sizeof(char *))
  65. define    MAX_SOUNDS    2048
  66.  
  67. har    *map[NEVENTS];
  68. har    *sounds[MAX_SOUNDS];
  69. nt    nsounds;
  70. nt    current_event = -1;
  71. nt    current_sound = -1;
  72.  
  73.  
  74. ifdef MAIN
  75.  
  76. *
  77.  * Instance XV_KEY_DATA key.  An instance is a set of related
  78.  * user interface objects.  A pointer to an object's instance
  79.  * is stored under this key in every object.  This must be a
  80.  * global variable.
  81.  */
  82. ttr_attribute    INSTANCE;
  83.  
  84. ain(int argc, char **argv)
  85.  
  86.     /*
  87.      * Initialize XView.
  88.      */
  89.     xv_init(XV_INIT_ARGC_PTR_ARGV, &argc, argv, NULL);
  90.     INSTANCE = xv_unique_key();
  91.     
  92.     /*
  93.      * Initialize user interface components.
  94.      * Do NOT edit the object initializations by hand.
  95.      */
  96.     Olvwmtool_main = olvwmtool_main_objects_initialize(NULL, NULL);
  97.     
  98.     /*
  99.      * Read in the sounds into the sounds list
  100.      */
  101.     read_sounds();
  102.  
  103.     /*
  104.      * Read in the current mapping from events to sounds
  105.      */
  106.     read_mapping();
  107.     
  108.     /*
  109.      * Turn control over to XView.
  110.      */
  111.     xv_main_loop(Olvwmtool_main->main);
  112.     exit(0);
  113.  
  114.  
  115. endif
  116.  
  117.  
  118. ompar(char **a1, char **a2)
  119.  
  120.     return strcasecmp(*a1, *a2);
  121.  
  122.  
  123.  
  124. *
  125.  * Read the sounds from the rplay config file and put them into the sounds list
  126.  */
  127. ead_sounds()
  128.  
  129.     FILE    *fl = fopen("/usr/local/etc/rplay.conf", "r");
  130.     char    buffer[200];
  131.     char    *p;
  132.     int    i, n;
  133.  
  134.     if (fl == NULL)
  135.     {
  136.         perror("fopen");
  137.         exit(1);
  138.     }
  139.  
  140.     n = 0;
  141.     while (fgets(buffer, 200, fl) != NULL)
  142.     {
  143.         p = strrchr(buffer, '/');
  144.         p[strlen(p) - 1] = '\0';
  145.         sounds[n++] = strdup(p + 1);
  146.     }
  147.     qsort(sounds, n, sizeof(char *), compar);
  148.  
  149.     xv_set(Olvwmtool_main->sounds,
  150.         XV_SHOW,        FALSE,
  151.         NULL);
  152.  
  153.     for (i = 0; i < n; i++)
  154.     {
  155.         xv_set(Olvwmtool_main->sounds,
  156.             PANEL_LIST_INSERT,    i,
  157.             PANEL_LIST_STRING,    i, sounds[i],
  158.             NULL);
  159.     }
  160.     fclose(fl);
  161.  
  162.     xv_set(Olvwmtool_main->sounds,
  163.         XV_SHOW,        TRUE,
  164.         NULL);
  165.     nsounds = n;
  166.  
  167.  
  168.  
  169. *
  170.  * Read the current mapping of events to sounds into the map array.
  171.  */
  172. ead_mapping()
  173.  
  174.     FILE    *fl = fopen(".olvwm-sounds", "r");
  175.     char    buffer[200];
  176.     char    *token;
  177.     int    i;
  178.  
  179.     if (fl == NULL)
  180.         return;
  181.     while (fgets(buffer, 200, fl) != NULL)
  182.     {
  183.         token = strtok(buffer, " \t:\r\n");
  184.         if (token == NULL)
  185.             continue;
  186.         for (i = 0; i < NEVENTS; i++)
  187.         {
  188.             if (strcmp(token, eventNames[i]) == 0)
  189.             {
  190.                 token = strtok(NULL, " \t\r\n");
  191.                 if (token == NULL)
  192.                     continue;
  193.                 map[i] = strdup(token);
  194.                 sprintf(buffer, "%s:    %s", eventNames[i], map[i]);
  195.                 xv_set(Olvwmtool_main->events,
  196.                     PANEL_LIST_STRING,    i, buffer,
  197.                     NULL);
  198.             }
  199.         }
  200.     }
  201.     fclose(fl);
  202.  
  203.  
  204.  
  205. *
  206.  * Notify callback function for `events'.
  207.  */
  208. nt
  209. vent_func(Panel_item item, char *string, Xv_opaque client_data, Panel_list_op op, Event *event, int row)
  210.  
  211.     olvwmtool_main_objects *ip = (olvwmtool_main_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  212.     int        i, j;
  213.  
  214.     switch (op)
  215.     {
  216.         case PANEL_LIST_OP_DESELECT:
  217.             current_event = -1;
  218.             break;
  219.         case PANEL_LIST_OP_SELECT:
  220.             current_event = row;
  221.             if (current_sound != -1)
  222.             {
  223.                 xv_set(ip->sounds,
  224.                     PANEL_LIST_SELECT,    current_sound, FALSE,
  225.                     NULL);
  226.                 xv_set(ip->play, PANEL_INACTIVE, TRUE, NULL);
  227.                 xv_set(ip->stop, PANEL_INACTIVE, TRUE, NULL);
  228.                 current_sound = -1;
  229.             }
  230.             break;
  231.     }
  232.  
  233.     /* gxv_start_connections DO NOT EDIT THIS SECTION */
  234.  
  235.     /* gxv_end_connections */
  236.  
  237.     return XV_OK;
  238.  
  239.  
  240. *
  241.  * Notify callback function for `sounds'.
  242.  */
  243. nt
  244. ounds_func(Panel_item item, char *string, Xv_opaque client_data, Panel_list_op op, Event *event, int row)
  245.  
  246.     olvwmtool_main_objects *ip = (olvwmtool_main_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  247.     char        buffer[100];
  248.  
  249.     switch (op)
  250.     {
  251.         case PANEL_LIST_OP_DESELECT:
  252.             xv_set(ip->play, PANEL_INACTIVE, TRUE, NULL);
  253.             xv_set(ip->stop, PANEL_INACTIVE, TRUE, NULL);
  254.             current_sound = -1;
  255.             if (current_event != -1)
  256.             {
  257.                 map[current_event] = NULL;
  258.                 xv_set(ip->events,
  259.                     PANEL_LIST_STRING,    current_event, eventNames[current_event],
  260.                     NULL);
  261.             }
  262.             break;
  263.         case PANEL_LIST_OP_SELECT:
  264.             current_sound = row;
  265.             xv_set(ip->play, PANEL_INACTIVE, FALSE, NULL);
  266.             xv_set(ip->stop, PANEL_INACTIVE, FALSE, NULL);
  267.             if (current_event != -1)
  268.             {
  269.                 map[current_event] = string;
  270.                 sprintf(buffer, "%s:   %s", eventNames[current_event], string);
  271.                 xv_set(ip->events,
  272.                     PANEL_LIST_STRING,    current_event, buffer,
  273.                     NULL);
  274.             }
  275.             break;
  276.     }
  277.  
  278.     /* gxv_start_connections DO NOT EDIT THIS SECTION */
  279.  
  280.     /* gxv_end_connections */
  281.  
  282.     return XV_OK;
  283.  
  284.  
  285.  
  286. *
  287.  * Notify callback function for `apply'.
  288.  */
  289. oid
  290. pply(Panel_item item, Event *event)
  291.  
  292.     olvwmtool_main_objects *ip = (olvwmtool_main_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  293.     FILE        *fl = fopen(".olvwm-sounds", "w");
  294.     int        i;
  295.  
  296.     for (i = 0; i < NEVENTS; i++)
  297.     {
  298.         if (map[i] != NULL)
  299.         {
  300.             fprintf(fl, "%s:\t%s\n", eventNames[i], map[i]);
  301.         }
  302.     }
  303.     fclose(fl);
  304.  
  305.     /* gxv_start_connections DO NOT EDIT THIS SECTION */
  306.  
  307.     /* gxv_end_connections */
  308.  
  309.  
  310.  
  311. tatic int    rplay_fd;
  312. tatic int    had_init = FALSE;
  313.  
  314. *
  315.  * Notify callback function for `play'.
  316.  */
  317. oid
  318. lay(Panel_item item, Event *event)
  319.  
  320.     olvwmtool_main_objects *ip = (olvwmtool_main_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  321.     RPLAY        *rp;
  322.  
  323.     if (!had_init)
  324.     {
  325.         rplay_fd = rplay_open("localhost");
  326.         had_init = TRUE;
  327.     }
  328.  
  329.     rp = rplay_create();
  330.     rplay_set(rp,
  331.         RPLAY_PLAY,    (char *) xv_get(ip->sounds, PANEL_LIST_STRING, current_sound),
  332.         NULL);
  333.  
  334.     rplay(rplay_fd, rp);
  335.     rplay_destroy(rp);
  336.  
  337.     /* gxv_start_connections DO NOT EDIT THIS SECTION */
  338.  
  339.     /* gxv_end_connections */
  340.  
  341.  
  342. *
  343.  * Notify callback function for `stop'.
  344.  */
  345. oid
  346. top(Panel_item item, Event *event)
  347.  
  348.     olvwmtool_main_objects *ip = (olvwmtool_main_objects *) xv_get(item, XV_KEY_DATA, INSTANCE);
  349.     RPLAY        *rp;
  350.  
  351.     if (!had_init)
  352.         return;
  353.  
  354.     rp = rplay_create();
  355.     rplay_set(rp,
  356.         RPLAY_STOP,    (char *) xv_get(ip->sounds, PANEL_LIST_STRING, current_sound),
  357.         NULL);
  358.  
  359.     rplay(rplay_fd, rp);
  360.     rplay_destroy(rp);
  361.  
  362.     /* gxv_start_connections DO NOT EDIT THIS SECTION */
  363.  
  364.     /* gxv_end_connections */
  365.  
  366.