|
Audio::Beep - a module to use your computer beeper in fancy ways |
Audio::Beep - a module to use your computer beeper in fancy ways
#functional simple way
use Audio::Beep;
beep($freq, $milliseconds);
#OO more musical way
use Audio::Beep;
my $beeper = Audio::Beep->new();
# lilypond subset syntax accepted
# relative notation is the default
# (now correctly implemented)
my $music = "g' f bes' c8 f d4 c8 f d4 bes c g f2";
# Pictures at an Exhibition by Modest Mussorgsky
$beeper->play( $music );
FREQUENCY is in Hz. Defaults to 440.
DURATION is in milliseconds. Defaults to 100.
new([%options])new method
to be passed in hash fashion.
Audio::Beep::Linux::beep).
If you're lazy (as any good programmer should be)
you can pass a string as a player,
like "Audio::Beep::Linux::PP" or even just "Linux::PP": the method
will prepend the Audio::Beep namespace, require the module and call
the new method on it for you.
The new method will try to look up the best player
on your platform if you don't specify one.
So the following is all valid:
use Audio::Beep;
#super lazy (should do the right thing most of the time)
my $beeper = Audio::Beep->new();
#still lazy
my $beeper2 = Audio::Beep->new(player => 'Linux::PP');
#medium lazy
my $beeper3 = Audio::Beep->new(
player => 'Audio::Beep::Win32::API'
);
#not so lazy, but more versatile
require Audio::Beep::Linux::beep;
my $beeper4 = Audio::Beep->new(
player => Audio::Beep::Linux::beep->new(
path => '/home/foo/bin/beep'
)
);
$music.
The accepted format is a subset of http://lilypond.org syntax.
The string is a space separated list of notes to play.
See the NOTATION section below for more info.
new method for more info.
With no parameter it just gives you back the current player.
new method for more info.
With no parameter it gives you back the current rest.
The defaults at start are middle octave C and a quarter length. Standard notation is the relative notation. Here is an explanation from Lilypond documentation:
If no octave changing marks are used, the basic interval between
this and the last note is always taken to be a fourth or less
(This distance is determined without regarding alterations;
a fisis following a ceses will be put above the ceses)
The octave changing marks ' and , can be added to raise or lower
the pitch by an extra octave.
You can switch from relative to non relative notation (in which you specify for
every note the octave) using the \norel and \rel commands (see below)
Every note has the following structure:
[note][flat|sharp][octave][duration][dots]
NB: previous note duration is used if omitted. ``Flatness'', ``Sharpness'' and ``Dottiness'' are reset after each note.
Special commands always begin with a ``\''. They change the behavior of the parser or the music played. Unlike in the Lilypond original syntax, these commands are embedded between notes so they have a slightly different syntax.
\tempo
You can embed comments in your music the Perl way. Everything after a # will be ignored until end of line.
my $scale = <<'EOS';
\rel \bpm144
c d e f g a b c2. r4 # a scale going up
c b a g f e d c1 # and then down
EOS
my $music = <<'EOM'; # a Smashing Pumpkins tune
\bpm90 \norel \transpose''
d8 a, e a, d a, fis16 d a,8
d a, e a, d a, fis16 d a,8
EOM
my $love_will_tear_us_apart = <<'EOLOVE'; # a happier tune
\bpm160
d'8
e1 fis4 g8 fis4 e8 d4
b2.. d8 a2.. d8
e1 fis4 g8 fis4 e8 d4
b2.. d8 a1
EOLOVE
There should be extra examples in the ``music'' directory of this tarball.
#a louder beep perl -MAudio::Beep -ne 'print and beep(550, 1000) if /ERROR/i' logfile
#turn your PC in Hofmann mode (courtesy of Thomas Klausner) perl -MAudio::Beep -e 'beep(21 + rand 1000, rand 300) while 1'
#your new music player perl -mAudio::Beep -0777e 'Audio::Beep->new->play(<>)' musicfile
Requires either the beep program by Johnathan Nightingale
(you should find sources in this tarball) SUID root or you to be root (that's
because we need writing access to the /dev/console device).
If you don't have the beep program this library will also assume some kernel
constants which may vary from kernel to kernel (or not, i'm no kernel expert).
Anyway this was tested on a 2.4.20 kernel compiled for i386 and it worked
with all 2.4 kernel since. It also works with the 2.6 kernel series.
With 2.4 kernels i have problems on my PowerBook G3 (it plays a continous
single beep). See the rest method if you'd like to play something anyway.
Requires Windows NT, 2000 or XP and the Win32::API module. You can find sources on CPAN or you can install it using ActiveState ppm. No support is available for Windows 95, 98 and ME yet: that would require some assembler and an XS module.
IMPORTANT! This IS NOT TESTED ON BSD! It may work, it may not. Try it, let me know what you got. BTW, you need the beep program wrote by Andrew Stevenson. I found it at http://www.freshports.org/audio/beep/ , but you can even find it at http://www.freebsd.org/ports/audio.html
If you are a developer interested in having Audio::Beep working on your platform, you should think about writing a backend module. A backend module for Beep should offer just a couple of methods:
NB: FREQUENCY is in Hertz. DURATION in milliseconds
new([%options])rest(DURATION)
This module works for me, but if someone wants to help here is some cool stuff to do:
- an XS Windoze backend (look at the Prima project for some useful code)
- test this on BSD (cause it's not tested yet!)
Some of course.
Copyright 2003-2004 Giulio Motta giulienk@cpan.org.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
Audio::Beep - a module to use your computer beeper in fancy ways |