Plugin question

• Nov 26, 2022 - 17:02

Hi guys Iam doing plugin which takes for notes or rest or mix of these a then it prints these elements randomly to next 15 measures.

It works pretty well but it doesnt print these notes/rest after one another but at the start of every new measure.
Can you please help me to fix it.

import QtQuick 2.0
import MuseScore 3.0

MuseScore {
menuPath: "Plugins.pluginName"
description: "Description goes here"
version: "1.0"
onRun: {

  function get_rand_num(min, max){

                          return Math.random() *  (max-min) + min;
                          }



  var all_notes = [];
          var cursor = curScore.newCursor();

       cursor.rewind(1);
      var first  =     cursor.element.clone();
      console.log("first",first.duration.str );
      cursor.next();

      var second  =     cursor.element.clone();
      console.log("second",second.duration.str );
      cursor.next();

      var third  =     cursor.element.clone();
      console.log("third",third.duration.str );
      cursor.next();

      var fourth  =     cursor.element.clone();
      console.log("fourth",fourth.duration.str );
      cursor.next();

     all_notes.push(first,second,third,fourth);

     console.log("all", all_notes[0].duration.str);
      console.log("placement", cursor.tick)

 var  rand_num = Math.floor(get_rand_num(0,4))
   console.log("rand_num",rand_num)
    cursor.add(all_notes[rand_num]);

       console.log("placement1", cursor.tick)


    console.log("placement2", cursor.tick)
   // while (cursor.prev() && (cursor.segment.type != 90)) {
                     // Nothing to do here, just continue rewinding
     //               }
     var  rand_num_1 = Math.floor(get_rand_num(0,4))
     cursor.next();
   console.log("rand_num",rand_num)
    cursor.add(all_notes[rand_num_1]);
    console.log("placement3", cursor.tick)

    console.log("placement4", cursor.tick)

        console.log("hello world")
        Qt.quit()
        }
  }
Attachment Size
Screen Shot 2022-11-26 at 18.01.47.png 69.18 KB

Comments

Do you still have an unanswered question? Please log in first to post your question.