1

My aim is to hook up a midi device to my computer to create and manipulate shapes in p5.js. I'm still learning code so have a few questions regarding arrays and keys.

Is there a way to say if any of the values in noteC, noteE and noteG are triggered then 'something happens'? But in a sort of combo as that is a chord as a opposed to say noteD and noteE which is not a chord.

Essentially I am trying to manipulate the shapes via chords being played but I am unaware of if "noteC + noteE + noteG" would do anything.

For example:

     var noteC = [24, 36, 48, 60, 72, 84, 96, 108]
     var noteE = [28, 40, 52, 64, 76, 88, 100]
     var noteG = [31, 43, 55, 67, 79, 91, 103]


    function keyPressed();
     if (value ===noteC, noteE, noteG) {
        ellipse(200, 200, 25, 30);
        ellipse(200, 200, 50, 60); 
        ellipse(200, 200, 100, 100);

To do it without chords I imagine it would go something like:

    function keyPressed() {
      if (value ===36) {
        ellipse(200, 200, 25, 30);
      } else if (value === 40) {
        ellipse(200, 200, 50, 60);
  }
}

However manually transforming shapes separately away from any combination of chords feels static and I would like there to be a relationship between the manipulation if a chord is being played.

I would like it so that the scale of the ellipse is determined by the velocity of the keys being played but if it is part of a chord the x and y parameters will be the same.

Not asking for someone to do the code but if anyone could help me understand or point me in the right direction that would be great! Thanks!

2242
  • 21
  • 1
  • Please ignore any syntax errors unless its very very wrong as i wrote this quickly and on my commute so not paying complete attention its more the logic i'm after. Thanks! – 2242 May 08 '19 at 13:33
  • What does this line mean: if (value ===noteC, noteE, noteG) Do you want the condition to be true if value is in all of the arrays? If so is this what you want: if(noteC.includes(value) && noteE.includes(value) && noteG.includes(value)) – Charlie Wallace May 08 '19 at 13:54
  • @CharlieWallace Yeah, so I want to "do something" if values from noteC, noteE and noteG are played in a sequence. Will try your suggestion, thanks! – 2242 May 08 '19 at 14:01
  • Well.. not sure if my suggestion is exactly what you need.. so when you say in a sequence.. do you actually have a list of values? Maybe as simple as if(noteC.includes(value1) && noteE.includes(value2) && noteG.includes(value3) or... does the chord have to be played in that exact order? What about inversions? so say if(noteC.includes(value2) && noteE.includes(value1) && noteG.includes(value3) do you still consider that a C chord? Maybe you could get CEG working and then add inversion capability later? – Charlie Wallace May 08 '19 at 14:39
  • How is `value` calculated? – Kevin Workman May 13 '19 at 10:15

0 Answers0