question about segments

• Feb 19, 2024 - 20:34

Hello all
just trying to write a plugin that compares notes that are on different staves.
now suppose that on one staff you have in the same measure a half-note (note A) and on the other staff two quarter-notes (notes B1 and B2)
in the first segment I can compare notes A and B1
but in the second segment I can't compare A and B2
how to write a very general code that enables me to compare notes that may share some moment in time but are with differrent duration? (I don't understand the 'tick' story)
thanks
(ps: sorry but I am not a native speaker so my question may not be clear enough)


Comments

In reply to by elsewhere

thanks
finding duration.ticks is not obvious (even when reading the docs 😇)
bug I have not found a segment duration (do I have to compare with the tick property of the next segment?)
then I suppose I have to do this:
if a note in a segment has a duration that is longer than the current segment then consider that its remaining duration should be considered in next segment (and so on since this could span multiple segments)
waw! anything simpler?!

In reply to by elsewhere

ok
so I need to investigate the next segment to know its position (and apply what I tried to describe in previous post)
this said I am not familiar with QT and struggle to try to make something that looks like a struct or class
such as ->
struct ElemTicks {
DurationElement elem ;
int currentTickNumber ; // changed after being considered in next segment
} ;
// apparently this is not correct so what can I do?

In reply to by sittingBugle

Qt is like javascript, which is c-like: plenty of javascript tutorials on the net.
The best source for learning are the existing plugins Go to:
https://musescore.org/en/plugins
Select API compatibility: Any and press the Apply button
Download any and all plugins that look interesting, run them, experiment with them and try to understand them. After a while you will be able to write your own plugins.

In reply to by elsewhere

thanks ! (I confess I am not familiar with QT or Javascript)
BTW plenty of QT tutorials on the web but "struct" and "class" examples simply do not fit here! (why?)
read also some javascript tutorials but creating a class like this:
class ElemTicks {
// constructor (elem) {
// this.elem = elem ;
// this.nbTicks = elem.duration.ticks ;
// }

    }

simply is not correct -says the debugger- !!!! (why?)

read a lot of examples in plugins repository (not all for sure) but I am too old to guess things just out of superb examples ... syntax specs somewhere for this specific QT?

In reply to by elsewhere

> ... (why?) ... syntax specs somewhere for this specific ...

Musescore = C++, Qt framework = need compilation !== QML
Plugin scripting = QML, javascript !== C++

"... The desktop program MuseScore is mostly written in C++ utilizing Qt framework 5.9.9, developers expose a minimal collection of frequently used functions and data as API to allow plugin development beyond MuseScore's built-in features... ...Plugins use the QML language of Qt framework, which is a declarative language that provide visual user interfaces, along with the Qt JavaScript host environment it allows interaction programming with a restricted version of javascript ..." https://musescore.org/en/handbook/developers-handbook/plugins-3x

Improving Musescore main involves C++ compilation, and is relevant to "QT tutorials", "class oriented programming"

Writing a plugin script is relevant to "QML tutorials", "javascript tutorials", "QML type", stress, desperation and eventually rage.

Javascript uses "object oriented programming", "prototype", "Object.assign", "IFFE" etc but not "struct", recent version supports "class, constructor" . However, due to decision by the Qt company, QML functions use a restricted version of javascript, the object inheritance feature is currently poorly supported https://musescore.org/en/handbook/developers-handbook/plugins-3x#Class_… ,

In reply to by msfp

Thanks all for your patience!!!! THANKS!
In fact I was mislead because I read documentation of QT and javascript that were not adapted to the version of Qt used in MuseScore (and grepped qml scripts for things that were simply not there!)
All's well that ends well: I finished a script that marks notes that are potential "neighbors" (most of the time these marks just point to something that is ok but sometimes that is not the case). the sources are here : https://github.com/GRU-framework/musescoreSimpleParallel
here is part of a test:

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