By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,034 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,034 IT Pros & Developers. It's quick & easy.

Building musical chords starting from (a lot of) rules

P: n/a
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
Nov 14 '08 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Mr.SpOOn wrote:
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
Nov 14 '08 #2

P: n/a
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.
Nov 15 '08 #3

P: n/a
In message <ma**************************************@python.o rg>, Mr.SpOOn
wrote:
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".
Nov 16 '08 #4

P: n/a
In message <6u******************************@earthlink.com> , Dennis Lee
Bieber wrote:
On Sun, 16 Nov 2008 19:21:49 +1300, Lawrence D'Oliveiro
<ld*@geek-central.gen.new_zealanddeclaimed the following in
comp.lang.python:
>In message <ma**************************************@python.o rg>,
Mr.SpOOn wrote:
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".

My books on harmony and such do indicate that a Cx implies all the
intervening odd values up to x... But they also tend to indicate that
(especially for guitar) the intervening can be left out...
Well, I did pick up chord notation mainly from guitar-playing friends.
Myself I was learning classical piano, where we didn't have much need for
such things. :)
Nov 16 '08 #5

P: n/a
On Sun, Nov 16, 2008 at 7:21 AM, Lawrence D'Oliveiro
<ld*@geek-central.gen.new_zealandwrote:
In message <ma**************************************@python.o rg>, Mr.SpOOn
wrote:
>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".
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.
Nov 16 '08 #6

P: n/a
Mr.SpOOn wrote:
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.
--
**** Listen to my CD at http://www.mellowood.ca/music/cedars ****
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bo*@mellowood.ca
WWW: http://www.mellowood.ca

Nov 16 '08 #7

P: n/a
Mr.SpOOn wrote:
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.
--
**** Listen to my CD at http://www.mellowood.ca/music/cedars ****
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bo*@mellowood.ca
WWW: http://www.mellowood.ca
Nov 16 '08 #8

This discussion thread is closed

Replies have been disabled for this discussion.