1 (edited by eviljay 2008-03-05 19:55:41)

Topic: perl script to reformat chordie format

When i play live, i like to have the entire song (lyrics and chords) on one sheet of paper with a minimum of 12 pt font.  I find the chordie format (with the chords on top) does not suit this very well.  I created this hack of a perl script to reformat chordie songs the way i like to see them, so i thought i would share with those who might like to use it - you have to have perl installed of course - yes its a hack.  Maybe chordie might see fit to incorporate this format one day?  pretty please.

the format btw look like this....    I am [A] a song [E] these are my [D] lryics

#!/usr/bin/perl

# do a view source on your chordie song and paste the contents
# into a file name song.txt
$inFile = 'D:\chordie\song.txt';

# rename this output file to whatever you want
# this is where the formatted song will be output
$outFile = 'D:\chordie\formattedsong.txt';



open (INFILE, "$inFile")||die $!;
open (OUTFILE, ">$outFile")||die $!;




my $title = '';
my $artist = '';
my @chords = ();
my @lyrics = ();

while (<INFILE>){
   
    if ($_ =~ /finaltitle/i){
        ($x,$y,$title) = split/>/,$_;
        $title =~ s/<\/h1//gi;
        $title =~ s/^\s//;
    }
   
    if ($_ =~ /finalartist/i){
        ($x,$y,$artist) = split/>/,$_;
        $artist =~ s/<\/h2//gi;
        $artist =~ s/^\s//;
        chomp $artist;
        print OUTFILE "$artist - $title\n\n";
    }
   
        if ($_ =~ /<tr class="cl">/){
        $_ =~ s/<td>&nbsp;<\/td>//gi;
        $_ =~ s/<tr class="cl">//gi;
        $_ =~ s/<\/td>//gi;
        $_ =~ s/<\/tr>//gi;
        $_ =~ s/\n//gi;
        @chords = split(/<td class="c">/,$_);
    }
   
       
   
    if ($_ =~ /<tr class="tl">/){
    $_ =~ s/<td>&nbsp;<\/td>//gi;
        $_ =~ s/<tr class="tl">//gi;
        $_ =~ s/<\/td>//gi;
        $_ =~ s/<\/tr>//gi;
        @lyrics = split(/<td>/,$_);
        my $i=0;
        foreach $l (@lyrics){
            $l =~ s/\n//gi;
            $l =~ s/&nbsp;//gi;
            chomp $l;
            $l =~ s/^\s//gi;
            print OUTFILE "$l";
            if ($chords[$i] =~ /\w/){
                if ($l !~ /\w/){
                    print OUTFILE "[" . $chords[$i] . "] ";
                }else{
                    print OUTFILE " [" . $chords[$i] . "] ";
                }
            }
            $i++;
        }
        print OUTFILE "\n";
       
        @chords =();
        @lyrics = ();
       
       
    }
   
   
   
}

print "Done. Press any key to exit.";
$in = <STDIN>;

Re: perl script to reformat chordie format

I'ma gonna work on dis tonite. It seems simple enough.

Nela

Re: perl script to reformat chordie format

i have a tough time with the laundry machines I thought html was wierd good luck mabey someday i'll understand all of what you put down tonight im gonna watch a dvd "I robot"

"Growing old is not for sissies"

Re: perl script to reformat chordie format

I havent tried your script. Could you provide me with a preview of the output? Is it very different from what you get when you click chopro?

Re: perl script to reformat chordie format

I have no idea what chopro is so i couldn't tell you.  Maybe this feature exists already and i just don't know about it??  I gave a small example in my original post but here is another - basically i want the chords inline with the song and wrapped with brackets - this way it fits more easily on a single page.

I've got [C] sunshine [F] on a cloudy [C] day [F]
And when it's [C] cold outside
[F] I've got the month of [C] May [F]
[C] I [Dm] guess [F] you [G] say
[C] What can [Dm] make me [F] feel this [G] way

Re: perl script to reformat chordie format

ahh!!!!!!!   chopro  - so sorry - never saw that before!  Great!!  That is exactly what i am looking for!

Re: perl script to reformat chordie format

is that like viagra?

"Growing old is not for sissies"

Re: perl script to reformat chordie format

Yeah Russell, it's hard.

Nela

Re: perl script to reformat chordie format

LOL great follow up

NELA wrote:

Yeah Russell, it's hard.

Nela

"Growing old is not for sissies"

Re: perl script to reformat chordie format

Eviljay

You can already get the text like this by going to edit song, there you see the song laid out like the way you like to see it. It is chordpro that throws those lovely chords above the words.

I like and prefer the way the songs are laid out, but thats me. Maybe some other would just like the way you are showing?

If I wanted a song like that I would go into edit and copy and paste into word, but then thats not handy for your chordie songbooks.
This is why we have a scroll option as well in chordie. So if you cannot see all the song on the screen and wish to play along you can use the scroll option. I use this a lot too


Ken

ye get some that are cut out for the job and others just get by from pretending