Re: Building musical chords starting from (a lot of) rules

2008-11-19 Thread Mr . SpOOn
I think I've found a nice way to represent and build chords. At least,
at the moment it satisfy me, maybe later I'll understand how it sucks.

I'm using two separate classes: one represent a chord and is
implemented as a set of Notes; the other represents the structure
(type) of the chord and is a set of Intervals.

I can build a chord in different ways, but the general idea is that I
need a root note and a structure.

The structure isn't bound to any particular chord, because it doesn't
contain notes, but just intervals. So I can have the structure of
minor chord, of a major chord and apply them to two different notes
and build my chords.

So what is important is just the parsing of the structure. The
structure will be a string: at the moment I'm considering it space
separated, so kind of: 'min 9 no5'

I split it in a list and start from the third. I check if there's a
no3, then if there's 'min' and I put a minor third. I do the same for
the fifth. Then the first element will be the main chord structure,
because it could be a 7, a 9, a 11, a 13 and so on. I have a
dictionary with this structures, in this way:

chord_structs = {'9': ['b7', '9'], '11': ., '13': .}

So if the element is in the dictionary, I add the intervals listed,
else I just add the element. That's the case of the 7, or 6 etc. Then
I'll add the rest of the structure.

This is not complete or perfect, neither explained so well, but that's
the main idea.

Thanks for the help :D
bye
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-16 Thread Mr . SpOOn
On Sun, Nov 16, 2008 at 7:21 AM, Lawrence D'Oliveiro
[EMAIL PROTECTED] wrote:
 In message [EMAIL PROTECTED], 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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-16 Thread bvdp

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: [EMAIL PROTECTED]
WWW:   http://www.mellowood.ca

--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-15 Thread 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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-15 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], 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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-15 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], Dennis Lee
Bieber wrote:

 On Sun, 16 Nov 2008 19:21:49 +1300, Lawrence D'Oliveiro
 [EMAIL PROTECTED] declaimed the following in
 comp.lang.python:
 
 In message [EMAIL PROTECTED],
 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. :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-14 Thread Dan Upton
On Fri, Nov 14, 2008 at 1:00 PM, Mr. SpOOn [EMAIL PROTECTED] 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

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 instance, so

maj = (n, -, n, -, n, -, -, -, -, -, -, -, -, -, -)
min = (n, -, b, -, n, -, -, -, -, -, -, -, -, -, -)
#9 = (n, -, n, -, n, -, n, -, #, -, -, -, -, -, -)

and just have a lookup table.  (Or a 7-tuple and do mod arithmetic to
get the extensions)  Then you could remove (well, I suppose with a
tuple it would be build a new one, or you could use a list?) anything
with no.

Just a thought...I don't ever do anything very complicated in Python
though so I don't know if that's Pythonic either ;)

-dan
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-14 Thread Paul McNett

Mr.SpOOn wrote:

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.


I say, start with what you can think of (the chain of if clauses). Get it working. 
Then, you'll likely find ways to refactor if needed.


Get it working first.
Make it right iteratively over time.

At least that's what I do. And it works for me.

Paul
--
http://mail.python.org/mailman/listinfo/python-list


Re: Building musical chords starting from (a lot of) rules

2008-11-14 Thread bvdp

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

--
http://mail.python.org/mailman/listinfo/python-list