473,403 Members | 2,354 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Building musical chords starting from (a lot of) rules

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
7 2000
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Slavik | last post by:
All libraries were installed (precompiled) This is FreeBSD 5.1 installed zlib, installed jpeg and png libraries (in default directories) GD 2.0.11 source is in /usr/gd-2.0.11 (compiled and...
17
by: Mark Tranchant | last post by:
On some of my pages, for example: http://tranchant.plus.com/guitar/chord-tutorial/music-theory ....I refer to musical note names a lot in the text, such as A, F# and Eb. Whilst cycling in to...
2
by: Mark Tranchant | last post by:
Thanks for the input everyone. I've settled (for now) on the following: <abbr title="B flat">Bb</abbr> My magic conversion to pander to IE's non-support of <abbr> has now been turned off as...
2
by: Matthew Crouch | last post by:
Okay, I've come up with hacky workarounds every time I build an app, and now I just need some tips on how to do this correctly and efficiently. I usually have a head.inc and/or a constants.inc...
6
by: Bas Cost Budde | last post by:
I play in a band (contrabass) and store the chords for our songs in an application. Its two main purposes are * to easily transpose a song * to display a set list (enlarged chord symbols) that...
3
by: thomson | last post by:
Hi All, While Iam building my solution, the VS 2003 editor get stucked, for a few minutes and after sometimes it gets recovered, and the solution building done, While building i looked into the...
2
by: Andreas Prilop | last post by:
Is Ruby annotation http://www.w3.org/TR/ruby/ suitable for text with musical score written with symbols from http://www.unicode.org/charts/PDF/U1D100.pdf ? -- All free men, wherever they may...
3
by: clintonG | last post by:
This article has shown me how to playing system sounds and .wav files via a web page. Very nice to know. It got me wondering if we could somehow play one or more tones of a musical scale somehow...
0
by: Dan Upton | last post by:
On Fri, Nov 14, 2008 at 1:00 PM, Mr. SpOOn <mr.spoon21@gmail.comwrote: I don't know if this is any better, but you could represent a chord formula as a 15-tuple consisting of (-, n, b, #) for...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.