saebekassebil / teoria

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

Setting chord duration? #98

Closed hjek closed 7 years ago

hjek commented 8 years ago

If I set a duration in the root note of a chord and also as an argument to the chord constructor, like this:

require('teoria').note('c4',{value:16}).chord('M',{value:8}).notes()

then none of these are used, and instead duration is set to 4:

[ { duration: { value: 4, dots: 0 }, coord: [ 1, -3 ] },
  { duration: { value: 4, dots: 0 }, coord: [ -1, 1 ] },
  { duration: { value: 4, dots: 0 }, coord: [ 1, -2 ] } ]
 [ { duration: { value: 4, dots: 0 }, coord: [ 1, -3 ] },
 { duration: { value: 4, dots: 0 }, coord: [ -1, 1 ] },
 { duration: { value: 4, dots: 0 }, coord: [ 1, -2 ] } ]
[ { duration: { value: 4, dots: 0 }, coord: [ 1, -3 ] },
  { duration: { value: 4, dots: 0 }, coord: [ -1, 1 ] },
  { duration: { value: 4, dots: 0 }, coord: [ 1, -2 ] } ]

Wouldn't it be better to be able to set duration of a chord either in the chord constructor (like note), or just set it to be the duration of the root note?

hjek commented 8 years ago

It can sort of be worked around by taking the duration of the root (or tonica for scales). It would still be slightly more intuitive if either there was a method for setting it or it just left the 4 out.

//Assuming note.play() plays a note

teoria.Chord.prototype.play = function(){
  var that = this
  that.notes().map(
    function(note){
      //set duration to that of the root
      if (that.root){
        note.duration = that.root.duration
      }
      note.play()
    }
  )
}

teoria.Chord.prototype.play = function(){
  var that = this
  that.notes().map(
    function(note){
      //set duration to that of the root
      if (that.root){
        note.duration = that.root.duration
      }
      note.play()
    }
  )
}
saebekassebil commented 8 years ago

Hi Pelle. I personally think that the duration stuff should be removed. This library could focus on the theory, and then another library could extend the theory with features important for playback and sheet music.

Do you use the duration features?

hjek commented 8 years ago

If they work well, I want to use them. The harmonics are really well worked out with loads of scales and chord,s and it works to the point where you can just give the midi pitch to some MIDI API; whereas the time/duration stuff maybe has some way to go before being able to do that, such as for example knowing when a note is being played; maybe both in bar/beat and (milli)seconds.

I'd suggest either cutting it or improving it.

I pushed my tiny >100 line library for rhythm here, because I couldn't find any here. If that kind of stuff is within the scope of teoria, fell free to incorporate it..

saebekassebil commented 7 years ago

Should be fixed by #110