tags 348982 +patch
thanks

Hello,

I've had to use beep recently, and found this bug report.
Attached is a patch that allows melodies to be played in three parts:
the first part, the chorus and the finale.

beep -f 880 -n -s -f 440 -n -f 880 -n -s -f 1760
      11111 2222222222222222222222 3333333333333

Part 1 is played initially
Part 2 is played for each line
Part 3 is played at the end.
See also the DEP-3 header in the patch.

This patch is meant to be placed after the catch-sig-term patch in
version 1.3-3.

Good luck,
Roland Clobus
Description: Allow melodies to be played when beep is used with pipes.
 This patch makes beep play multiple notes when it is used with a pipe.
 All beeps that follow will be played for each character/line, until either
 -c or -s is used again. Then the remainder will be played at the end of the
 data in the pipe.

 Example usage: beep -f 880 -n -s -f 440 -n -f 880 -n -s -f 1760
    First a beep of 880Hz is played. Then for each line the sequence 440Hz,
    880Hz is played. At the end of the pipe 1760Hz is played.

Author: Roland Clobus <rclo...@rclobus.nl>
Forwarded: no
Last-Update: 2013-04-25
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/beep.c
+++ b/beep.c
@@ -344,22 +344,42 @@
       while(fgets(sin, 4096, stdin)) {
 	if(parms->stdin_beep==CHAR_STDIN_BEEP) {
 	  for(ptr=sin;*ptr;ptr++) {
+            beep_parms_t *copy = parms;
+
 	    putchar(*ptr);
 	    fflush(stdout);
-	    play_beep(*parms);
+	    copy->stdin_beep = NO_STDIN_BEEP;
+	    while (copy && !copy->stdin_beep) {
+	       play_beep(*copy);
+	       copy = copy->next;
+	    }
 	  }
 	} else {
+          beep_parms_t *copy = parms;
+
 	  fputs(sin, stdout);
-	  play_beep(*parms);
+	  copy->stdin_beep = NO_STDIN_BEEP;
+	  while (copy && !copy->stdin_beep) {
+	     play_beep(*copy);
+	     copy = copy->next;
+	  }
 	}
       }
+      /* At the end of the pipe, remove all related beeps. */
+      while (parms && !parms->stdin_beep) {
+	next = parms->next;
+	free(parms);
+	parms = next;
+      }
+      if (parms) {
+	parms->stdin_beep = NO_STDIN_BEEP;
+      }
     } else {
       play_beep(*parms);
+      /* Junk each parms struct after playing it */
+      free(parms);
+      parms = next;
     }
-
-    /* Junk each parms struct after playing it */
-    free(parms);
-    parms = next;
   }
 
   if(console_device)

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to