Building musical chords starting from (a lot of) rules

M

Mr.SpOOn

Hi,
I'm writing a method to create musical chords.

This method must follow a specific set of syntax rules. At least, this
is my idea, but maybe there's a better way.
Anyway, in the code I have class Chord which is a set.

The costrunction of a chord is based on a root note and a structure,
so by default, giving just a note, it creates a major chord adding the
third and fifth note.

So, in pseudo-code: Chord(C) -> [C, E, G]

And this is the base case. All the other rules must specify what kind
of note to add or which one should be modified.

For example: C min, means to add the third minor note: C Eb G

C 9 is a base chord plus a the ninth note, but this implies the
presence of the seventh too, so it results in: C E G B D

But I can also say: C 9 no7, so it should just be: C E G D, without the seventh.

There are also more complex rules. For the eleventh, for example, it
should add also the ninth and seventh note. In the normal case it adds
their major version, but I can specify to add an augmented nine, so
this modification must have precedence over the base case.

Anyway, I think I can use a chain of if-clauses, one per rule and at
the end remove the notes marked with "no". But this seems to me a very
bad solution, not so pythonic. Before I proceed for this way, do you
have any suggestion? Hope the problem is not too complicated.

Thanks,
Carlo
 
B

bvdp

Mr.SpOOn said:
Hi,
I'm writing a method to create musical chords.

This method must follow a specific set of syntax rules. At least, this
is my idea, but maybe there's a better way.
Anyway, in the code I have class Chord which is a set.

The costrunction of a chord is based on a root note and a structure,
so by default, giving just a note, it creates a major chord adding the
third and fifth note.

So, in pseudo-code: Chord(C) -> [C, E, G]

And this is the base case. All the other rules must specify what kind
of note to add or which one should be modified.

For example: C min, means to add the third minor note: C Eb G

C 9 is a base chord plus a the ninth note, but this implies the
presence of the seventh too, so it results in: C E G B D

But I can also say: C 9 no7, so it should just be: C E G D, without the seventh.

There are also more complex rules. For the eleventh, for example, it
should add also the ninth and seventh note. In the normal case it adds
their major version, but I can specify to add an augmented nine, so
this modification must have precedence over the base case.

Anyway, I think I can use a chain of if-clauses, one per rule and at
the end remove the notes marked with "no". But this seems to me a very
bad solution, not so pythonic. Before I proceed for this way, do you
have any suggestion? Hope the problem is not too complicated.

Thanks,
Carlo

Have a look at my program MMA which does just what I think you want.
Well, probably for different purposes, but same end result with the
chords. All table based, BTW. http://www.mellowood.ca/mma
 
S

Stefaan Himpe

The costrunction of a chord is based on a root note and a structure,
so by default, giving just a note, it creates a major chord adding the
third and fifth note.

Quite some time ago I wrote something to solve the reverse problem:
given a list of note names, find out a chord name.
(http://chordrecognizer.sourceforge.net/ )

I used a look-up table to made a correspondence between the chord-name
and the notes from which the chord is built. The notes are expressed as
a distance from the root note.

E.g. starting from a chromatic scale built on C, the distances would be:
C:0 C#:1 D:2 D#:3 E:4 F:5 F#:6 G:7 G#:8 A:9 A#:10 B:11
(and similar for flats, double sharps and double flats, ...)

Any chord thus can be constructed from a root note + the distance
information.

example distance information:

{ 'm' : [ 0, 3, 7 ], # minor triad
'' : [ 0, 4, 7 ], # major triad
'7' : [ 0, 4, 7, 10] # etc...
....
}

How does one e.g. construct the E7 chord from this information?

1. generate the chromatic scale starting from E, and annotate with note
distance to root note:

E:0 F:1 F#:2 G:3 G#:4 A:5 A#:6 B:7 C:8 C#:9 D:10 D#:11

2. take the recipe for a '7' chord from the distance information:
[0, 4, 7, 10]

3. map the numbers from step 2. to the note names from step 1.: E G# B D

If you care about proper enharmonic spelling of the chord's note names
(i.e. do not confuse F# and Gb), you will need to add some extra
information in the look-up tables or you need to pass extra information
to the chord construction recipe at the moment of creating a chord, but
that is left as an excercise to you - the interested reader ;)

HTH,
Stefaan.
 
L

Lawrence D'Oliveiro

Mr.SpOOn said:
C 9 is a base chord plus a the ninth note, but this implies the
presence of the seventh too, so it results in: C E G B D

I don't recall such meanings in the chord names I came across. If you wanted
both a seventh and ninth, you had to say so: "C7+9" or "Cmaj7+9".
 
M

Mr.SpOOn

I don't recall such meanings in the chord names I came across. If you wanted
both a seventh and ninth, you had to say so: "C7+9" or "Cmaj7+9".

Well, the notation style may vary a lot. In jazz music chords are very
complex and they contain a lot of note so sometimes I think is good to
simplify the notation and write just the exceptions.

So for example in jazz music it is more common the minor seventh than
the major, so writing just G7 you mean the dominant seventh chord
(with minor seventh) and you have to write just the major one with
maj7.

I think I'm going to consider both styles.
 
B

bvdp

Mr.SpOOn said:
So for example in jazz music it is more common the minor seventh than
the major, so writing just G7 you mean the dominant seventh chord
(with minor seventh) and you have to write just the major one with
maj7.

A minor 7th has a flatted 3rd (ie. C, Eb, G, Bb). Don't confuse your
readers and yourself by thinking that "minor" equals "dominant" in this
context. It never does. Spelling is usually Cm7.

A 7th is always a dominant (C, E, G, Bb). The only spelling I've ever
seen for this is C7.

A major 7th is just that (C, E, G, B). Spelling include CM7 (note the
uppercase M) and Cmaj7.

And then there are things like minor major 7th (C, Eb, G, B) ...

and the problem with all this is that the spellings really aren't
standard. It varies with different music book publishers, geographic
locales and time.

There are a number of books around (some out of print) which discuss
this in great detail (insert the word tedious if you want). One good
reference, if you can find it, is: Carl Brandt and Clinton Roemer.
Standardized Chord Symbol Notation. Roerick Music Co. Sherman Oaks, CA.
 
B

bvdp

Mr.SpOOn said:
So for example in jazz music it is more common the minor seventh than
the major, so writing just G7 you mean the dominant seventh chord
(with minor seventh) and you have to write just the major one with
maj7.

A minor 7th has a flatted 3rd (ie. C, Eb, G, Bb). Don't confuse your
readers and yourself by thinking that "minor" equals "dominant" in this
context. It never does. Spelling is usually Cm7.

A 7th is always a dominant (C, E, G, Bb). The only spelling I've ever
seen for this is C7.

A major 7th is just that (C, E, G, B). Spelling include CM7 (note the
uppercase M) and Cmaj7.

And then there are things like minor major 7th (C, Eb, G, B) ...

and the problem with all this is that the spellings really aren't
standard. It varies with different music book publishers, geographic
locales and time.

There are a number of books around (some out of print) which discuss
this in great detail (insert the word tedious if you want). One good
reference, if you can find it, is: Carl Brandt and Clinton Roemer.
Standardized Chord Symbol Notation. Roerick Music Co. Sherman Oaks, CA.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top