lilypond-user
[Top][All Lists]
Advanced

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

Re: scheme - notes as variables


From: Rob Canning
Subject: Re: scheme - notes as variables
Date: Mon, 02 Feb 2009 14:43:06 +0000
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

Andrew Wilson wrote:
2009/1/31 Rob Canning <address@hidden>:
#!/usr/bin/perl

sub InsertNotes {
  my ($num, $form, @notes) = @_;

  my ($output, @temp);
  while (@notes) {
    (@temp[0..$num-1], @notes) = @notes;
    $output .= sprintf $form, (@temp);
  }
  return $output;
}
  my @list = qw"a b c d a b c d a f cis d aes b c d g b c d a bes c dis c c c d a e 
c d a b c d";

my $format = "%s''4\\pp r16 %s'4\\accent %s''1 %s'''4 r8 %s''4\\mf \\accent %s8 
\\staccato\n";

print InsertNotes(6, $format, @list);


what i would like would be numbered variables (%s[1-n]) so i can
repeat/recall certain elements within the script like this:

like this (quasi-code):
my $format = "%s1''8 r16 %s1'4 %s2''1 %s3'''4 r8 %s3''4 %s4''8";

The code is using the sprintf function, you can see how this works
with the command perldoc -f sprintf.  What printf needs is a format
string and a list of variables to substitute into the string.  Your
quasi-code is close to being correct, you can follow any of the
format strings (in out case %s) with a format parameter index.
The format parameter index is 1$, 2$, etc.  i.e. %s1$, %s2$

my $format = "%s1$''8 r16 %s1$'4 %s2$''1 %s3$'''4 r8 %s3$''4 %s4$''8";

If you're going to do that then you'll need to alter the number that
you pass to the InsertNotes function or you'll be throwing
entries from the note array.

also would it be possible to incorperate a second variable reading from a
second list? %B

my $format = "%sA1''%sB1 r16 %sA1'%sB2 %sA2''%sB1 %sA3'''%sB3 r8 %sA3'' %sB2
%sA4''"%sB4;

No, not directly.  you would have to interleave the values from the
separate arrays yourself before you called the sprintf function.

I've attached a file with some ides rob3.pl

also
to read from a list
my @list = qw"a b c d a"

is something like this possible?
my @list = qw"mynotelist.txt"

see rob4.pl

HTH

If you want to learn perl, I recommend learning perl by O'Reilly.

andrew

wow! that is so fantastic - what a great help you are!
i read the perlintro and the perldoc -f sprintf docs last night and now have a much clearer idea of what is going on - i also just ordered learning perl (got a copy for 0.69p!) the more i see of this perl the more i think this is definitly the way to go - i dont really know anything apart from a bit of basic shell - this looks like the next step for sure.

i will study what you have sent me in detail and report back when i am clear about it all.

many many thanks

rob






reply via email to

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