tonaljs / tonal

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

Chord substitutions #115

Open martijnmichel opened 4 years ago

martijnmichel commented 4 years ago

It seems tonaljs is missing a feature to output chord subs (or i just missed it being there ;))

For instance: Cmaj7 can be subbed with Em or Cmaj79 with Em9 G7(9) -> Bm7b5 G7(9) -> Dm6 etc..

Actually I would be fine with helping out on inserting it in tonal if it is missing and if needed... ive finished conservatory jazz guitar so have all the knowledge to make it work.

danigb commented 4 years ago

An implementation of this would be great! 👍

Do you have any ideas about how to implement it? Perhaps we can discuss them in this issue :-)

martijnmichel commented 4 years ago

ill make a fork of tonal and see how the internals work, maybe itll give me an idea..

martijnmichel commented 4 years ago

If im gonna be helping you with this it seems ill need to start learning typescript first...

danigb commented 4 years ago

Okey, no worries. We can discuss what you need first...

martijnmichel commented 4 years ago

Im not sure I understand the setup of tonal yet also... for example, how would I test new functionality? import it into another project with HMR ? I'd be happy to help though, just gonna need a bit of a learning curve first.

martijnmichel commented 4 years ago

Well i'm deep into typescript atm ;) Can you explain to me how i can setup a test env for a new module?

danigb commented 4 years ago

I've updated CONTRIBUTING.md

Hope it helps

martijnmichel commented 4 years ago

it did but it doesnt describe how to setup a test environment, does it? I cant believe id have to run yarn test:ci everything i change something in my code and wait over a minute for the tests to complete?

danigb commented 4 years ago

You can run npx jest module-name in root folder to run the test of one module. For example npx jest chord-detect

martijnmichel commented 4 years ago

okay, thatll work.. though it still seems a bit slow to hit the terminal everytime i change a bit of code. But, we can talk about the actual implementation ;)

martijnmichel commented 4 years ago

Ive been trying to come up with a solution.. we need a way to:

export function sub(chordName: string): string[] | undefined {
  const [tonic, type] = tokenize(chordName);
  if (tonic) {
    let c = Chord.get(`${tonic}${type}`);
    let scales = Chord.chordScales(`${tonic}${type}`);
    return detect(c.notes);
  }
}

There are so many scales listed, many of which are very unknown to me that I find it hard to do the above. Do you have any ideas?

danigb commented 4 years ago

Can you explain me how the algorithm works? For example, to go from "Cmaj7" to "Em" you need to remove the tonic. For example: