Advertisement
Guest User

contour.pl

a guest
Dec 7th, 2017
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.19 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use warnings;
  4. use strict;
  5.  
  6. my $parsons = shift;
  7. if (!$parsons || $parsons !~ /^\*/)
  8. {
  9.     print STDERR "Parsons code must start with *\n";
  10.     exit 1;
  11. }
  12. $parsons =~ s/^\*//g;
  13.  
  14. my $output;
  15. my $pitch = 0;
  16. my $index = 1;
  17. $output->{$pitch}->{$index} = "*";
  18.  
  19. foreach my $parson (split //, $parsons)
  20. {
  21.     $parson = lc $parson;
  22.     if ($parson eq "r")
  23.     {
  24.         $output->{$pitch}->{ ++$index } = "-";
  25.         $output->{$pitch}->{ ++$index } = "*";
  26.     }
  27.     elsif ($parson eq "u")
  28.     {
  29.         $output->{ --$pitch }->{ ++$index } .= "/";
  30.         $output->{ --$pitch }->{ ++$index } .= "*";
  31.     }
  32.     elsif ($parson eq "d")
  33.     {
  34.         $output->{ ++$pitch }->{ ++$index } .= "\\";
  35.         $output->{ ++$pitch }->{ ++$index } .= "*";
  36.     }
  37.     else
  38.     {
  39.         print STDERR "Illegal tone '$parson'\n";
  40.         exit 1;
  41.     }
  42. }
  43.  
  44. foreach my $line (sort { $a <=> $b } keys %$output)
  45. {
  46.     $index = 0;
  47.     foreach my $note (sort { $a <=> $b } keys %{ $output->{$line} })
  48.     {
  49.         my $offset = $note - $index;
  50.         print " " x --$offset if $offset > 1;
  51.         print $output->{$line}->{$note};
  52.         $index = $note;
  53.     }
  54.     print "\n";
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement