How do I set duration easily ?

• Mar 5, 2023 - 21:21

Hello,

My question is. Is there any other way to set duration of a note besides giving two input argument into cursor.duration ?

I want to store duration of a note in single variable so I can later use it and add it to a score.. but if I want to do that I have to store the numerator and denominator. Is there any way to store in and later use it as one variable and add it to a Score ?

Thank you

import QtQuick 2.0
import MuseScore 3.0

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

  var all = [];
  var cursor = curScore.newCursor(); 
        cursor.rewind(0);



        all.push(cursor.element.duration);


        var a = all[0];
        console.log("a", a.str)

        cursor.setDuration(a)
        cursor.addNote(80)
        Qt.quit()
        }
  }

Comments

My advice : compute all your durations into a common denumerator (I use 64) and store the numerator.

function durationTo64(duration) {
    return 64 * duration.numerator / duration.denominator;
}

onRun: {
        var all = [];
        var cursor = curScore.newCursor(); 
        cursor.rewind(0);

        var dur64=durationTo64(cursor.element.duration);
        all.push(dur64); // store the numerator

        cursor.setDuration(dur64,64); // set the duration in 64th of beats
        cursor.addNote(80)
        }

EDIT: removed the Qt.quit() which is part of the default template, but incorrect.

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