lumy / mingus

Automatically exported from code.google.com/p/mingus
GNU General Public License v3.0
0 stars 0 forks source link

more about chords: chord object, transposition of single and multiple chords #16

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I suggest to add a containers.chord object, that would expose all of the nice 
functions of chords, 
but additionally the "base name" ("C" for "Cmaj7") to able able to transpose 
that.

  >>> c = containers.chords('Am')
  >>> c.base_name
  'A'
  >>> c.from_shorthand
  ['A', 'E', 'C']
  >>> d = c.transpose('D')
  >>> d.common_name
  'Dm'
  >>> d.from_shorthand
  ['D', 'F', 'A']

c.transpose could also work with integers as half steps like this:

  >>> d = c.transpose(1)
  >>> d.common_name()
  'Bm'

The method should perhaps also take a second parameter for the scale, like 
other functions.

I guess this is a very simple extension for you, since most of the parts are 
already in place.

That would lead to transposition of whole accompaniment lines like this:

  >>> line = 'C Am / Dm G'
  >>> accompaniments.transpose(line, 'D')
  'D Bm / Em A'
  >>> accompaniments.transpose(line, 3)
  'D# Cm / Fm Bb'

I'd like to use such a function in the Python-based successor of my song 
collection (see 
http://angerweit.tikon.ch/lieder/lied.php?src=folk-nl/naarisland)

Original issue reported on code.google.com by fiee.vis...@gmail.com on 24 Oct 2008 at 5:17

GoogleCodeExporter commented 9 years ago

Original comment by Rhijnauwen@gmail.com on 30 Nov 2008 at 9:36

GoogleCodeExporter commented 9 years ago
All of this is already possible with the normal NoteContainer and chords 
modules:

>>> from mingus.containers import *
>>> from mingus.core import *
>>> nc = NoteContainer()

To set a chord to the NoteContainer do:

>>> nc + chords.from_shorthand("Am")
>>> nc
['A-4', 'C-5', 'E-5']

Now lets transpose a major third using interval shorthand:

>>> nc.transpose("3")
>>> nc
['C#5', 'E-5', 'G#-5']

You can use the standard determine() functions to check what kind of chord you 
ended
up with:

>>> nc.determine()
['C# minor triad', 'E major sixth, second inversion']

Or using shorthand:

>>> n.determine(True)
['C#m', 'EM6']

So here's a simple implementation of your final example which stores all the
notecontainers in a meterless bar.

>>> line = ["C", "Am", "Dm", "G"]
>>> b = Bar('C', (0,0))
>>> map(lambda x: b + chords.from_shorthand(x), line)
[True, True, True, True]
>>> b
[[0.0, 4, ['C-4', 'E-4', 'G-4']], [0.25, 4, ['A-4', 'C-5', 'E-5']], [0.5, 4, 
['D-4',
'F-4', 'A-4']], [0.75, 4, ['G-4', 'B-4', 'D-5']]]
>>> b.transpose("b3")
>>> b
[[0.0, 4, ['Eb-4', 'G-4', 'Bb-4']], [0.25, 4, ['C-5', 'Eb-4', 'G-4']], [0.5, 4,
['F-4', 'Ab-4', 'C-5']], [0.75, 4, ['Bb-4', 'D-5', 'F-4']]]
>>> b.determine_chords(True)
[[0.0, ['EbM']], [0.25, ['Cm', 'EbM6']], [0.5, ['Fm', 'AbM6']], [0.75, ['BbM']]]

I wrote this very quickly. You should probably factor out a couple of simple
functions to use with your site. You should also take a look at the progressions
class, which makes this sort of stuff very easy.

Good luck!

Original comment by onderste...@gmail.com on 30 Nov 2008 at 10:42