Groups | Search | Server Info | Login | Register
Groups > comp.lang.perl.misc > #4820
| Newsgroups | comp.lang.perl.misc, comp.music.misc |
|---|---|
| Subject | Re: Increment with '#' and decrement with 'b' |
| References | <Au6dnWYprLy6Uv7SnZ2dnUVZ8g-dnZ2d@giganews.com> <98KdnZ0g9-yI4PnSnZ2dnUVZ8nKdnZ2d@giganews.com> <86fwd63p0p.fsf@gray.siamics.net> <R5GdnfSAN9kNjvvSnZ2dnUVZ8gCdnZ2d@giganews.com> |
| From | Ben Morrow <ben@morrow.me.uk> |
| Date | 2012-03-20 15:12 +0000 |
| Message-ID | <ibjm39-eoe1.ln1@anubis.morrow.me.uk> (permalink) |
Cross-posted to 2 groups.
Quoth Henry Law <news@lawshouse.org>:
>
[ representing musical notes as A=>0, A#=>1, Bb=>1, B=>2, &c.]
>
> Actually in this project I'm using a notation that already exists, for
> better or worse; it's the one in the vast number of chord charts that I
> have which need transposing for different singers! I need to be able to
> transpose C Am7 Dm7 G7#5b9 to, say, Eb Cm7 Fm7 Bb7#5b9 (and without it
> coming out as A#7#5b9 either). And so on.
I don't think you can do that with this representation. Consider
transposing
C F G C => 3 8 10 3
into B major
2 7 9 2 => B E F# B
and Db major
4 9 11 4 => Db Gb Ab Db
The enharmonic information you need to distinguish between F# and Gb is
exactly what you've just thrown away.
I would do a transposing job like this with a circle-of-fifths
representation, perhaps something like
my %sharps = qw( F 0 C 1 G 2 D 3 A 4 E 5 B 6 );
my %acc = qw( # +7 b -7 x +14 ## +14 bb -14 );
my ($accs) = map qr/$_/, join "|", keys %acc;
$acc{""} = 0;
my ($note, $acc, $mods) = /([A-G])($accs)(.*)/i
or die "not a valid chord symbol: '$_'\n";
my $chord = $sharps{uc $note} + $acc{lc $acc};
# transpose $chord
my %base = reverse %sharps;
my %offset = reverse %acc;
$offset{14} = "x"; # or ## if you prefer
my $base = $chord % 7;
my $offset = $chord - $base;
$offset > 14 and die "triple-sharp required\n";
$offset < -14 and die "triple-flat required\n";
my $symbol = "$base{$base}$offset{$offset}$mods";
I don't really like starting with F, but it seems to be the easiest way
to make it work: otherwise you end up with code like
my $base = $chord % 7;
$base == 6 and $base = -1;
which is just ugly when it can easily be avoided.
Ben
Back to comp.lang.perl.misc | Previous | Next — Previous in thread | Next in thread | Find similar
Increment with '#' and decrement with 'b' Henry Law <news@lawshouse.org> - 2012-03-16 23:39 +0000
Re: Increment with '#' and decrement with 'b' Ben Morrow <ben@morrow.me.uk> - 2012-03-17 00:54 +0000
Re: Increment with '#' and decrement with 'b' Henry Law <news@lawshouse.org> - 2012-03-17 12:01 +0000
Re: Increment with '#' and decrement with 'b' Ivan Shmakov <oneingray@gmail.com> - 2012-03-18 22:30 +0700
Re: Increment with '#' and decrement with 'b' Henry Law <news@lawshouse.org> - 2012-03-18 16:55 +0000
Re: Increment with '#' and decrement with 'b' Ben Morrow <ben@morrow.me.uk> - 2012-03-20 15:12 +0000
Re: Increment with '#' and decrement with 'b' Rainer Weikusat <rweikusat@mssgmbh.com> - 2012-03-17 17:05 +0000
csiph-web