tonaljs / tonal

A functional music theory library for Javascript
https://tonaljs.github.io/tonal/docs
3.78k stars 218 forks source link

Proposal: modes #27

Closed edellaq closed 6 years ago

edellaq commented 7 years ago

Hi, are modes implemented (o can they) in any way? From a computing point it could simply be a circular shift of a scale notes array, possibly having a name (but not necessarily, for the library purpose, could be up to the programmer to associate e.g. "Aeolian" name - also in different languages - to the Scale.mode(6).

This could be applied to any scale (programmer has to be aware of what he's doing)... so that if a C major scale is [C, D, E, F, G, A, B] with two circular shift we could obtain a Phrygian scale like: C_major_scale.mode(3) = [E, F, G, A, B, C, D]

this could be used mainly for the common scales (major, melodic minor, harmonic minor, harmonic major) but since it'd be a generic mechanism, it could be applied to any scale, so that Any_Major_scale.mode(6) = Aeolian array scale (natural minor) Any_Aeolian_scale.mode(2) = Ionian array scale (major scale) Any_Melodic_minor_scale.mode(4) = Lydian augmented array scale .. etc etc...

Moreover, comes in mind a scale transformation function, to obtain parallel modes by dropping the right degrees, so that, e.g. you can obtain a melodic minor scale by flatting the 3rd degree of any major scale object...

I'll take some time to browse through the code, although I think my JS skills still are still lacking a bit...

danigb commented 7 years ago

Hi @edellaq

Sorry for the delay. Circular shift of pitch class sets are implemented in pcset package:

tonal.pcset.modes('c d e f g a b');

However, sometimes it has problems properly naming the notes. Take a look to https://github.com/danigb/tonal/blob/c7bf9572e5ce42511a6a64ff830fd23e2f96c92b/packages/core/pcset/test/pcset.test.js#L25

Also, you can get the name of the modes using the key module:

tonal.key.names();

See https://github.com/danigb/tonal/blob/c7bf9572e5ce42511a6a64ff830fd23e2f96c92b/packages/extensions/key/test/key.test.js#L34

I'm curious about the scale transformation and parallel modes. Can you write a little bit more about it?

I hope it helps.

edellaq commented 7 years ago

Hi @danigb, my concept is: having a major scale note array, simply returning the array starting form the n-th note, by shifting it circularly, returns the new modals scale... So that e.g. a c major scale [c,d,e,f,g,a,b], shifted by 3 steps gives a F lydian scale [f,g,a,b,c,d,e] without altering any note. A bit more complicated is when you want a parallel mode, having the same root note. starting from a C major scale [c,d,e,f,g,a,b], if you want a C lydian [c,d,e,f#,g,a,b] you'll have to raise only the 4th grade (f to f#) So I was thinking to a function using circular shifting to obtain new a modal scale starting from any current one, and another function using some kind of "transformation matrix" for scales, that alters only the degrees needed to obtain the new parallel mode (= having the same root) Each returned object would be a regular "scale" object, to be used seamlessly in any computation...

So for example you can have by shifting: Gmixolydian=Cmajor.mode(5) and then by 'parallelizing': Gdorian=Gmixolydian('toDorian') that simply flattens the 3rd degree of the mixolydian scale... etc..

danigb commented 6 years ago

I think this is implemented in tonal-key. Please feel free to reopen if not.