lilypond-user
[Top][All Lists]
Advanced

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

Re: lyrics entry help!!!-was hebrew lily


From: Amelie Zapf
Subject: Re: lyrics entry help!!!-was hebrew lily
Date: Wed, 2 Jul 2003 19:22:12 +0200
User-agent: KMail/1.4.3

Hi Aaron, all,
The following script should do the job:

Cheers, Amy

#!/usr/bin/perl
####################################################
# revertlyrics.pl v0.1
# Script to print right-to-left languages backwards
# in Lilypond
# (c) Amelie Zapf 2003
# Licensed under the GNU GPL v2
####################################################

# Usage: revertlyrics.pl <lilypondfile>
#  1. Name each lyric file <lilypondfile>.lyr.<number>
#  2. Insert "\include "<lilypondfile>.out.<number>";
#     at the appropriate positions in your lilypond file
#  3. Run script

use warnings;
use strict;

# which files to process
my $file=$ARGV[0];
$file=~s/\.ly//;
my @files=glob("$file.lyr.*");

foreach (@files) {
        # read
        open FILE, $_;
        my @content=<FILE>;
        close FILE;

        # process
        for (my $i=0; $i<scalar(@content); $i++) {
                # get rid of spurious blank space
                chomp $content[$i];
                $content[$i]=~s/\s+/ /g;
                #split into syllables
                my @line=split / /, $content[$i];
                for (my $j=0; $j<scalar(@line); $j++) {
                        # get rid of lyric value
                        my $time=$line[$j];
                        $time=~s/^[^\d]+//;
                        $line[$j]=~s/[\d]+\.+$//;
                        # take care that trailing hyphens appear at the end
                        if ($line[$j]=~/\-$/) {
                                $line[$j]=~s/\-$//;
                                $line[$j]="-$line[$j]";
                        }
                        # special treatment of centered hyphens and
                        # syllable extenders, actual substitution
                        if ($line[$j] ne "--" && $line[$j] ne "__") {
                                $line[$j]="\"\\\\R{$line[$j]}\"";
                        }
                        # get value back in
                        $line[$j]="$line[$j]$time";
                }
                # fuse line from syllables
                $content[$i]=join " ", @line;
        }

        # output
        my $newfile=$_;
        $newfile=~s/\.lyr\./.out./;
        open FILE, ">$newfile";
        for (my $i=0; $i<scalar(@content); $i++) {
                print FILE "$content[$i]\n";
        }
        close FILE;
}





reply via email to

[Prev in Thread] Current Thread [Next in Thread]