[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

[MacPerl] All signing, all dancing MacPerl



Here's a few minimalist modifications to the singing MacPerl script.  
This version works well as a runtime application. Coming soon: Christmas 
Carols!

#!perl
# Author: David Seay <http://www.mastercall.com/g-s>
# Modifed by Charles Albrecht to add accidentals & sing "Daisy Bell"
# Further modified by Jim Miner <jfm@winternet.com> to normalize tempo
# Still Further Modifications by Brian McNett <brianmc@telebyte.net>
# (removed messy string concatenation, added quit-if-runtime)
#
# Daisy Bell (A Bicycle Built for Two), Henry Darce, 1892

use Mac::Speech;

$noteNames =    "c  d  e  f  g  a  b  C  D  E  F  G  A  B  C1";
$scalePitches = "48,50,52,53,55,57,59,60,62,64,65,67,69,71,72";
@noteNames = split("  ",$noteNames);
@scalePitches = split(",",$scalePitches);
$pitches = @scalePitches;
for ($p = 0; $p < $pitches; $p++) {
	$pitch{$noteNames[$p]} = $scalePitches[$p];
}

$tempo = 240; # quarter notes per minute, approx.
$tempo_factor = 60 / $tempo; # seconds per quarter note

# NOTE DURATIONS
$dur{e}   = .5;   # eighth note
$dur{de}  = .75;  # dotted eighth note
$dur{q}   = 1;    # quarter note
$dur{dq}  = 1.5;  # dotted quarter note
$dur{h}   = 2;    # half note
$dur{he}  = 2.5;  # half note + an eighth
$dur{dh}  = 3;    # dotted half note
$dur{dhe} = 3.5;  # dotted half note + an eighth
$dur{w}   = 4;    # whole note

# ACCIDENTALS
$acc{s} = 1;      # sharp
$acc{n} = 0;      # natural
$acc{f} = -1;     # flat

# FORMAT FOR '$song' = syllable pitch accidental duration
$song = <<SONG;
. c n h, daay A s dh, zeee G n dh, daay D s dh, zeee a s dh,
give c n q, me d n q, your d s q, aaan c n h, sir d s q, doooo a s w,
I'm F n dh, halff A s dh, craay G n dh, zeee D s dh,
alll c n q, for d n q, the d s q, love f n h, of g n q, you f n w,
it g n q, won't g s q, be g n q, uh f n q, sty a s h, lish g n q,
mare f n q, ridge d s w, 
I f n q, can't g n h, uh d s q, ford c n h,
uh d s q, care c n q, ridge a s w,
but a s q, you'll d s h, look g n q, sweet f n q, . c n h,
upon d s h, the g n q, seat f n q, of g n e, uh g s e,
buyy a s q, sick g n q, ul d s q, built f n h, for a s q, two d s w
SONG

@song = split(",",$song);
$songNotes = @song;

$count = CountVoices();
for ($i = 0; $i++ < $count; ) {
 	$voice = GetIndVoice($i);
 	$desc  = ${GetVoiceDescription($voice)};
 	# some voices won't change pitch
 	# try 'Zarvox' or 'Pipe Organ' or 'Cellos' or 'Bad News'
	if ($desc =~ /Zarvox/) {
		$channel = NewSpeechChannel($voice)         or die $^E;

		for ($n = 0; $n < $songNotes; $n++) {
			($word,$note,$sharp,$dur) = split(" ",$song[$n]);

			SetSpeechPitch $channel, $pitch{$note}+$acc{$sharp};
			SpeakText $channel, $word               or die $^E;
			select(undef, undef, undef, $tempo_factor * $dur{$dur});
			StopSpeech $channel 	or die $^E;
		}
		DisposeSpeechChannel $channel;
	}
}

MacPerl::Quit(1)

__END__


# Fungal Parataxonomy                   Mycology Information (Mycoinfo)
# Webmaster, Staff Writer      **The World's First Mycology E-Journal**   
# <mailto:webmaster@mycoinfo.com>            <http://www.mycoinfo.com/> 
# "A couple of guys trying to do something great..."



***** Want to unsubscribe from this list?
***** Send mail with body "unsubscribe" to mac-perl-request@iis.ee.ethz.ch