home *** CD-ROM | disk | FTP | other *** search
/ ftp.madoka.org / 2014.12.ftp.madoka.org.tar / ftp.madoka.org / pub / irchat-pj / 2.5 / irchat-pj-2.5.6p.tar.gz / irchat-pj-2.5.6p.tar / irchat-pj-2.5.6p / irchat-pj-sound.el < prev    next >
Lisp/Scheme  |  2001-06-04  |  7KB  |  233 lines

  1. ;;; irchat-pj-sound.el -- irchat-pj sound extension
  2.  
  3. ;; Copyright (C) 1998,1999 TAKAHASHI Kaoru
  4.  
  5. ;; Author: TAKAHASHI "beatmaria" Kaoru <kaoru@kaisei.org>
  6. ;; Created: 25 Dec 1998
  7. ;; Keywords: IRC, sound, irchat
  8.  
  9. ;; $Id: irchat-pj-sound.el,v 1.5 2001/06/04 17:38:17 simm Exp $
  10.  
  11. ;; CTCP-related modification: by simm@irc.fan.gr.jp, Sat, 18 Dec 1999 00:53:21 +0900
  12.  
  13. ;; This file is part of irchat-pj
  14.  
  15. ;;; Commentary:
  16.  
  17. ;;; Code:
  18. (require 'pure-generic)
  19.  
  20. (provide 'irchat-pj-sound)
  21.  
  22. ;; flags
  23. (defvar irchat-pj-sound-words-list nil
  24.   "*Beep list for irchat-pj.
  25. Set a list of regular expression, and you get sound if match.")
  26.  
  27. (defvar irchat-pj-sound-when-bell t
  28.   "*Output sound when bell(\\a) received.")
  29.  
  30. (defvar irchat-pj-sound-when-invited nil
  31.   "*Output sound when invited.")
  32.  
  33. (defvar irchat-pj-sound-when-private nil
  34.   "*Output sound when received private message.")
  35.  
  36. (defvar irchat-pj-sound-when-join nil
  37.   "*Output sound when anyone join to your joined channel.")
  38.  
  39. (defvar irchat-pj-sound-when-part nil
  40.   "*Output sound when anyone part from your joined channel.")
  41.  
  42. (defvar irchat-pj-sound-when-ctcp nil
  43.   "*Output sound when anyone sends you or your joined channel CTCP message.")
  44.  
  45. (defvar irchat-pj-sound-when-error t
  46.   "*Output sound when server sends you ERROR message.")
  47.  
  48. ;; process
  49. (defvar irchat-pj-sound-wav-player "play"
  50.   "Executable program for playing WAV files.")
  51.  
  52. (defvar irchat-pj-sound-au-player "showaudio"
  53.   "Executable program for playing sun AU format sound files.")
  54.  
  55. (defvar irchat-pj-sound-player-alist
  56.   '(("\\.wav$" . irchat-pj-sound-wav-player)
  57.     ("\\.au$"  . irchat-pj-sound-au-player))
  58.   "Filetype and player variables alist.")
  59.  
  60. ;; sound file directory
  61. (defvar irchat-pj-sound-directory nil
  62.   "*Default soundfile directory.
  63. `expand-file-name' argument.")
  64.  
  65. ;; sound file
  66. (defvar irchat-pj-sound-words-file 'ding
  67.   "*Default output sound file for keyword notify.
  68. `ding' means beep.  `ignore' means mute.")
  69.  
  70. (defvar irchat-pj-sound-bell-file 'ding
  71.   "*Output sound file when bell(\\a) recieved.
  72. `ding' means beep.  `ignore' means mute.")
  73.  
  74. (defvar irchat-pj-sound-invited-file 'ding
  75.   "*Output sound file when invited.
  76. `ding' means beep.  `ignore' means mute.")
  77.  
  78. (defvar irchat-pj-sound-private-file 'ding
  79.   "*Output sound file when receive private massage.
  80. `ding' means beep.  `ignore' means mute.")
  81.  
  82. (defvar irchat-pj-sound-join-file 'ding
  83.   "*Default play sound file when anyone join channel.
  84. `ding' means beep.  `ignore' means mute.")
  85.  
  86. (defvar irchat-pj-sound-part-file 'ding
  87.   "*Default play sound file when anyone part channel.
  88. `ding' means beep.  `ignore' means mute.")
  89.  
  90. (defvar irchat-pj-sound-ctcp-file 'ding
  91.   "*Default play sound file when anyone send CTCP messge.
  92. `ding' means beep.  `ignore' means mute.")
  93.  
  94. (defvar irchat-pj-sound-error-file 'ding
  95.   "*Default play sound file when got ERROR messge.
  96. `ding' means beep.  `ignore' means mute.")
  97.  
  98.  
  99. ;; default function
  100. (defvar irchat-pj-sound-words-function 'irchat-pj-sound-play-words
  101.   "Call function when anyone called.")
  102.  
  103. (defvar irchat-pj-sound-bell-function 'irchat-pj-sound-play-bell
  104.   "Call function when bell(\\a) received.")
  105.  
  106. (defvar irchat-pj-sound-invited-function 'irchat-pj-sound-play-invited
  107.   "Call function when invited.")
  108.  
  109. (defvar irchat-pj-sound-private-function 'irchat-pj-sound-play-private
  110.   "Call function when received private message.")
  111.  
  112. (defvar irchat-pj-sound-join-function 'irchat-pj-sound-play-join
  113.   "Call function when anyone join to your joined channel.")
  114.  
  115. (defvar irchat-pj-sound-part-function 'irchat-pj-sound-play-part
  116.   "Call function when anyone part from your joined channel.")
  117.  
  118. (defvar irchat-pj-sound-ctcp-function 'irchat-pj-sound-play-ctcp
  119.   "Call function when anyone send you or your joined channel CTCP message.")
  120.  
  121. (defvar irchat-pj-sound-error-function 'irchat-pj-sound-play-error
  122.   "Call function when server send you ERROR message.")
  123.  
  124.  
  125. (defun irchat-pj-sound-play (sound)
  126.   "If SOUND is string, play SOUND file sound.
  127. If SOUND is symbol, funcall SOUND."
  128.   (cond
  129.    ;; function
  130.    ((symbolp sound)
  131.     (if (fboundp sound)
  132.         (funcall sound)))
  133.    ;; filename
  134.    ((stringp sound)
  135.     (irchat-pj-sound-play-file
  136.      (expand-file-name sound irchat-pj-sound-directory)))))
  137.  
  138. (defun irchat-pj-sound-play-file (file)
  139.   "If readble FILE, play FILE."
  140.   (interactive "fSound file: ")         ; for test
  141.   (if (file-readable-p file)
  142.       (let ((player (symbol-value (cdr (assoc-regexp file irchat-pj-sound-player-alist)))))
  143.         (cond
  144.          ;; e.g. '("cp" file "/dev/audio")
  145.          ((consp player)      
  146.           (apply 'call-process
  147.                  (car player)
  148.                  nil 0 t
  149.                  (mapcar 'eval (cdr player))))
  150.          ;; e.g. "xplay"
  151.          ((stringp player)
  152.           (call-process player nil 0 t file))))))
  153.  
  154. ;; default functions
  155. (defun irchat-pj-sound-play-words (&optional nick)
  156.   "Keyword notify."
  157.   (irchat-pj-sound-play irchat-pj-sound-words-file))
  158.  
  159. (defun irchat-pj-sound-play-bell ()
  160.   "Ring bell."
  161.   (irchat-pj-sound-play irchat-pj-sound-bell-file))
  162.  
  163. (defun irchat-pj-sound-play-invited (&optional nick)
  164.   "Invite notify."
  165.   (irchat-pj-sound-play irchat-pj-sound-invited-file))
  166.  
  167. (defun irchat-pj-sound-play-private ()
  168.   "Priv notify."
  169.   (irchat-pj-sound-play irchat-pj-sound-private-file))
  170.  
  171. (defun irchat-pj-sound-play-join (&optional nick userhost)
  172.   "Join notify."
  173.   (or (irchat-match-me nick) ; join myself
  174.       (irchat-pj-sound-play irchat-pj-sound-join-file)))
  175.  
  176. (defun irchat-pj-sound-play-part (&optional nick userhost)
  177.   "Part notify."
  178.   (or (irchat-match-me nick) ; part myself
  179.       (irchat-pj-sound-play irchat-pj-sound-part-file)))
  180.  
  181. (defun irchat-pj-sound-play-ctcp (&optional nick)
  182.   "CTCP notify."
  183.   (irchat-pj-sound-play irchat-pj-sound-ctcp-file))
  184.  
  185. (defun irchat-pj-sound-play-error ()
  186.   "ERROR notify."
  187.   (irchat-pj-sound-play irchat-pj-sound-error-file))
  188.  
  189.  
  190. ;; another function (undocumented)
  191. (defvar irchat-pj-sound-words-regexp-alist ()
  192.   "Alist of keyword(regexp) and soundfile pair.")
  193.  
  194. (defvar irchat-pj-sound-words-channel-alist ()
  195.   "Alist of channel and soundfile pair for keyword notify.")
  196.  
  197. (defvar irchat-pj-sound-join-nick-alist ()
  198.   "Alist of nick(regexp) and soundfile pair for join notify.")
  199.  
  200. (defvar irchat-pj-sound-join-channel-alist ()
  201.   "Alist of channel and soundfile pair for join notify.")
  202.  
  203. (defvar irchat-pj-sound-part-nick-alist ()
  204.   "Alist of nick(regexp) and soundfile pair for part notify.")
  205.  
  206. (defvar irchat-pj-sound-part-channel-alist ()
  207.   "Alist of channel and soundfile pair for part notify.")
  208.  
  209. (defun irchat-pj-sound-play-words-another (&optional nick)
  210.   "Keyword notify."
  211.   (irchat-pj-sound-play
  212.    (or (cdr (assoc-regexp temp irchat-pj-sound-words-regexp-alist))
  213.        (cdr (assoc chan irchat-pj-sound-words-channel-alist))
  214.        irchat-pj-sound-words-file)))
  215.  
  216. (defun irchat-pj-sound-play-join-another (&optional nick userhost)
  217.   "Join notify."
  218.   (or (irchat-match-me nick) ; join myself
  219.       (irchat-pj-sound-play
  220.        (or (cdr (assoc-regexp nick irchat-pj-sound-join-nick-alist))
  221.        (cdr (assoc chan irchat-pj-sound-join-channel-alist))
  222.        irchat-pj-sound-join-file))))
  223.  
  224. (defun irchat-pj-sound-play-part-another (&optional nick userhost)
  225.   "Part notify."
  226.   (or (irchat-match-me nick) ; part myself
  227.       (irchat-pj-sound-play
  228.        (or (cdr (assoc-regexp nick irchat-pj-sound-part-nick-alist))
  229.        (cdr (assoc chan irchat-pj-sound-part-channel-alist))
  230.        irchat-pj-sound-part-file))))
  231.  
  232. ;;; irchat-pj-sound.el ends here
  233.