Development code question

• Aug 23, 2017 - 02:07

Is there an appropriate place on the forums where coding questions can be posted instead of questions pertaining to the usage of Musescore or notation? For instance, I gave a quick run-through and didn't find the code that translates a note's duration to a a tick-based or time-based duration, where it occurs, and how that translates into an actual OnNote event. I found some functions that do translate ticks to time and time to ticks, but the actual implementation after a non-thorough quick-perusal wasn't located. Now, I can be lazy and ask where this is, or I can continue perusing. Before continuing perusal, besides the IRC channel, is it possible that programming related topics like this are applicable here in the Generic forum? If so, it would be cool if a new sub-forum for Programming/Development Code was set up and anyone could post inquiries or observations about the code imho. Is that not in the cards? That way if a topic was useful in the IRC chat, it might be logged and benefit someone else who happens to come across the posts.


Comments

To answer the specific question - libmscore/renderMidi.cpp is where most of the work of generating playback events happens. And DurationElement is the parent class of chords (which are the containers for notes) and rests, where the implementation of most functions involving duration would be found.

We don't get many development questions on the forums, as you've no doubt noticed. The develop mailing list or IRC are really the best places. But if you do want to ask something on the forum, I might suggest Technology Preview as the best choice, just because it tends to be of interest mainly to developers and "bleeding edge" users.

In reply to by worldwideweary

QtCreator is definitely great for browsing the code and understanding the data structures. If nothing else, just opening chord.h and looking at the class declaration for Chord will show you that it inherits from ChordRest, then a Ctrl+Click on ChordRest takes you right to the declaration for that, showing you it inherits from DurationElement, etc.

It is important to keep in mind the difference between inheritance and membership. We sometimes loosely use the words "parent" and "child" to describe both types of relationships, but they are entirely different. A Segment is not the ancestor of Chord in the sense of inheritance, but a segment contains Chords in the sense of membership. Similarly, a Chord is not the ancestor of a Note in the sense of inheritance, but a Chord contains Notes in the sense of membership. So no, a Note does not inherit from DurationElement - Chord is the end of the line as far as that goes. But as you'll see in rendermidi.cpp, the code to generate events for notes uses the "parent" (in the sense of membership) Chord to get the default duration. Although Chord does not itself directly define a duration, it does indirectly because it inherits from DurationElement.

For more on the overall structure of a score, see https://musescore.org/en/developers-handbook/references/musescore-inter…

Just a meta-comment: for that kind of getting-into-the-code tasks I'd suggest you have a look at SourceNavigator (http://sourcenav.sourceforge.net/). That's an old (and pretty much dead) tool,
but still very useful to navigate source code. It let's you quickly explore class hierarchies, method
declarations and implementations (right click on a symbol and select 'find declaration' or
'find implementation') and grep through the source code.

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