saebekassebil / teoria

Javascript taught Music Theory
http://saebekassebil.github.io/teoria
MIT License
1.32k stars 114 forks source link

TeoriaNote#scientific() allowing to exclude octave number from note name #36

Closed Nairam closed 11 years ago

Nairam commented 11 years ago

Modified version of the teoria.note.scientific() method. When used like this: teoria.note.scientific(true), it excludes the octave number from the note name output string.

Using this modified version of the method will greatly simplify use cases in which you need the note name (formatted with scientific pitch notation) as an upper case letter with the corresponding accidental only. Before, this could only be achieved with an hack making note.name upper case and then concatenating note.name and note.accidental together.

It follows the pattern of the note.toString([dontShow]) method and should therefore be convenient to use.

saebekassebil commented 11 years ago

Hm, I just figured that note.toString(true).toUpperCase() doesn't work with double sharps and flats..

I don't think it makes sense to have the opportunity to drop the octave in scientific() because then it'd no longer actually be the scientific notation. If this was to be implemented, I think it should be implemented as a new method with a new name - any suggestions?

Nairam commented 11 years ago

You are probably right about this. What do you think about calling this pitchName() or noteName() and refactor it into a new method?

saebekassebil commented 11 years ago

With more though I think this is taking the library in a wrong direction by adding unnecessary bloat. With the new release of version v0.3 this is somewhat simplified. And all you have to write is:

note.name().toUpperCase() + note.accidental()

If that is too much to write everytime - then just make your own function that does the above

teoria.TeoriaNote.prototype.pitchName = function() {
  return this.name().toUpperCase() + this.accidental();
}

// or this
function pitchName(note) {
  return note.name().toUpperCase() + note.accidental();
}

Anyway I'd like to thank you for taking the time to try to contribute to the project - I'll be glad to receive other PRs if you can think of any betterments or bug fixes!