Having trouble writing a for loop ,any helpful advice much appreciated



  • Hi Folks

    So I have been having a go a drawing an 88 key keyboard to a panel . I originally drew it out with a ton of fillRects Screenshot 2021-03-25 at 01.47.10.png

    I figured there must be a better way to do this so i thought ide have a go at drawing it using a for loop. but the forloop is only drawing one key to the panel. Im quite new to scripting and not sure where im going wrong. Any useful advice would be apprecated Screenshot 2021-03-25 at 22.28.15.png

    Please find a snippet from the project below

    HiseSnippet 1169.3ocsVs0aaaCElJIpnIaAaEcOtGD5SNnmUPRcGYCKK25BZShQbWw.JBJTkosIhLogDcRMFBv9+r+X8sMz+.aGZYWau3VTOfI+hO2H+9N7nOplk5bQUktj3r4KFMPPb9R2ViTldGzKSpHmbHw4qb+4SZcj2wmeg2yO+7lj8GMHqpRzl33r9SsI4r4FjwO+0OteVQlJWLyEg7RsLW7bYeoYl2l68LYQwwYsEuP1etrC16jbs5.cgdHBn0cojAY4Wk0UbVlMs0bIN26n1RitrkIyHpvb1W2dTqd5aT04+RYk7MEBqAizBWnZ2jC5IKZ2bJYqHDmMZNi5qWS8uw8TYa4G7OqE70iC3Mqh46ANqsHj1XAHw9XP5XcQa6B7QfmybvaiZ38.2V4kxAlYQrX6KbOQYDkcxv197vpNWxZ+w5tGnwLTlmzO6JwwknwGpnAiSofWHktytauk8mmGdBTY77t4YhQM0URiTq79AuWEBbeHfAgoPbLjFBLlOv7Y.KHEXQw.KASg5CbNCSME3gnuXLuTevmw.edJ3GDC9QgfeBtVTFtdoPfeLDDFBAwnuTbCnoPHOFBCBgvHeHLwtooPDKFh7CgnPeHJlAQIHRnwPLODhC7g3HFhLzWZLjvBgDeeHIjAIQoPRBBYZHjhbHEIQJxhTKMr7fZIB0xDpkJTKWnIVBR8ubWriLWW4M+qtBK.wKBEas.iywtAEYcDx5.rKPAdPBvih.eJG6.TvOD+eb.3mxg.dBDDDAAIbbUnPHKABCwULlCQzDHhGAQAA3xiaQZBD6G.wgbjkTHgFAI7.jc3+iSfjzHH0miLiBoI39Ss.hx4Wt67GqWmU5MPUfrXecVY6CxTWmUgDY5HRWg4.c+AZEZz3Q2IyGUOlbG+OoRXZhusXtPOzHUhFcFpxs8nFc2Yqeyt8dczkMj3NQ20S588KLd8jBgpqoGF3wOdmwIWWhmWW6BWqGzf91im7rytSi1AkQtPjaZ7pkrduRdINZCd3rfWD8RKzwhtcqaw52dqoHzSqNSaDmqZfHcqM2516DoSmkEx1wJ0EEhxkE0pqU9IJqgZX+2HJA7.oXnXZd3q5KpkbuOOsj75Su4RTqNQIMmOPLwdlZCaIpMjIG+3+9kSNLyjYEfl3CyafnzHsvw4Pw0nZdsbzltGJptxnGLN2IyLDm6aFGc6ohUYJQAQha8CcuyXC4seP6+2uXuQyLFs2Mx1ldDGWmuEc0SH61yXsdJFUZD8mdGwl268u+8TxBd4V2u6c+Is9tl6nihp451CKxLKJwauKaR.7nZAsTqdoBmsFM+ccqftOco59K8j3yDtOvsozj2a43cskfW7D8+a7N4VzscOpSG7cxYfcC2i+0+qWYtBPoV6o6oYlRINX4d1v9svwgbAhDENEVYGfVyNsWaSs11NSKgp8Xi+FelDjYsclDjMMHoeVdo9040uDaum99i8fXRM9ST1z8TqsGiL9E6Zb2G+3gWmmaaDeGh7kWAekqvekqHXkqHbkqHZkqHdkqH4STg8K09ogFc+5WKPGMOZrjliyQpLbpZ7DH4e.bekcqD



  • Did you see my video about making a custom keyboard? (I think it's only visible to patrons at the mo).



  • Oh I can see the problem

    wKeyPosition.length[i]

    .length gives you the number of elements in the array, it is not an array itself.

    You need wKeyPosition[i]

    Also, you don't need to set the colour through every iteration, you can do that outside the loop and condense your code

    pnlKeyBoardCanvas.setPaintRoutine(function(g)
    {
       g.setColour(0xFFFFFFFF);
    
       for(i = 0; i < wKeyPosition.length; i++)
         g.fillRect([wKeyPosition[i], 5, 15, 60]);  
    });
    


  • David you are an absolute legend. Its working now! Thank you so much 🙂

    So just so i am clear for the future. where i went wrong was by using .length again in place of the actual array for the wKeyPosition sending it the number of elements in the array but not the actual data inside the array?. Is that right?
    That would explain why when i was compiling it the white key would be like 50 px further away from where it was meant to be. This is all making sense now.

    now i can build my key board YAY 🙂
    Cheers



  • @d-healey No i didnt know there was a video for it. ile go on patreon now and look for this.



  • @Glyn

    So just so i am clear for the future. where i went wrong was by using .length again in place of the actual array for the wKeyPosition

    Correct. Length is a property of the array. Strings also have a length property which will give you the number of characters in the string.



  • @d-healey Hi David

    I been watching your custom keyboard video. At 32:14 you use the onNoteOn and onNoteOff call backs and have them accessible at the top of the screen. as the image below shows

    Screen Shot 2021-04-06 at 18.14.07.png

    but mine doesnt look the same as mine only has one scriptEditorInterface tab at the top

    Screenshot 2021-04-06 at 18.14.48.png

    Im not sure why that is



  • @Glyn Check out my video about customising your workspace



  • @d-healey Will do, had a feeling you might have a video about it 😉 cheers


Log in to reply
 

16
Online

1.1k
Users

3.8k
Topics

33.4k
Posts