Increasing pitch
Hey guys,
I'm trying to increase the pitch of a note by 10 in my code. However, I'm encountering an issue with the following line:
cursor.element.notes[0].pitch = cursor.element.notes[0].pitch + 10;
For instance, if all original notes have a pitch of 65 (which corresponds to F4), adding 10 should result in D#5s. However, instead of getting D#5s, I'm getting F5s.
How can I fix this?
import QtQuick 2.0
import MuseScore 3.0
MuseScore {
menuPath: "Plugins.pluginName"
description: "Description goes here"
version: "1.0"
onRun: {
var els = curScore.selection.elements;
var tracks = [];
for (var i in els) {
if (!tracks.some(function(x) { return x == els[i].track; })) {
tracks.push(els[i].track);
}
}
var cursor = curScore.newCursor();
cursor.rewind(2); // go to the end of the selection
var endTick = cursor.tick;
if (endTick == 0) { // dealing with some bug when selecting to end.
endTick = curScore.lastSegment.tick + 1;
}
var endStaff = cursor.staffIdx + 1;
var endTrack = endStaff * 4;
console.log("endTrack", endTrack)
// Start
cursor.rewind(1); // go to the beginning of the selection
var startSegTick = curScore.selection.startSegment.tick;
var startTick = cursor.tick;
var startStaff = cursor.staffIdx;
var startTrack = startStaff * 4;
cursor.rewind(1); // beginning of selection
console.log("tracks", tracks)
for (var j = 0; j < tracks.length; j++) {
cursor.rewind(1);
cursor.track = tracks[j];
while (cursor.segment != null && cursor.tick < endTick) {
cursor.element.notes[0].pitch = cursor.element.notes[0].pitch + 10;
cursor.next();
}
}
}
}
Comments
You need to change the tpc (tonal pitch class) as well
In reply to You need to change the tpc … by elsewhere
So each note has to have its tpc.
I Just cannot seem to find where the tpc at.
Thank you
In reply to So each note has to have its… by kamilio141414
Google
site:musescore.org tpc
In reply to So each note has to have its… by kamilio141414
https://musescore.org/en/handbook/developers-handbook/plugin-developmen…
In reply to https://musescore.org/en… by Jojo-Schmitz
Is there any explanation of how it works ?
In reply to Is there any explanation of… by kamilio141414
So how would I input the correct note correctly based on previous notes.
Do I use some kind of formula like I used ? This code doesn't work properly
import QtQuick 2.0
import MuseScore 3.0
MuseScore {
menuPath: "Plugins.pluginName"
description: "Description goes here"
version: "1.0"
onRun: {
var els = curScore.selection.elements;
var tracks = [];
}
In reply to So how would I input the… by kamilio141414
You have to do it right.
Pitch 65 = F
Pitch 75 = Eb
tpc Eb = 11
nowhere near 75-46 = 29
In reply to You have to do it right… by elsewhere
I know I have to do it right but how with every note ?
With notes C D and E my method works but not others
In reply to I know I have to do it right… by kamilio141414
In my view this is not a programming tutorial site, so I bow out, but someone else might be willing to help you. Or submit your question (in detail) to e.g StackOverflow.
In reply to I know I have to do it right… by kamilio141414
note.pitch = note.pitch + 10
note.tpc = note.tpc + 10
if you wish sharp
or
note.tpc = note.tpc - 2
if prefer flat
in this case, I think