Exploring code and data structures

Updated 3 months ago

How to get started

After you have downloaded a Nightly Build or made you own version, you are ready to explore data structures and code. In a score right click on a note or any other item and select "Object Debugger" from the right-click menu. This will give you an opportunity to explore the data structures. Also, there is "Edit → Debugger", that lets you explore the data in a score. Note: that debugger nowadays is only enabled when running MuseScore in 'experimental' mode, i.e. using the -e option, see also Command line options

Getting started in the source tree

The main part of the code lives in mscore/mscore and mscore/libmscore. A good point to start exploring is mscore/mscore/musescore.cpp. This is also where the main() function is located. In MuseScore::cmd commands are processed. Most commands that modify the score are passed off to ScoreView::cmd in scoreview.cpp. If you put a breakpoint in ScoreView::cmd, you can find and then step into the function that processes a specific command. Commands like cut, copy, paste are posted as a new event right at the start of ScoreView::cmd. These events are then processed in ScoreView::normalCut, ScoreView::normalCopy, ScoreView::normalPaste. The paste execution ends up in mscore/libmscore/cmd.cpp Score::cmdPaste. Note that copy and paste put content onto the clipboard through the interface provided by Qt (in ScoreView::normalCopy()). Quite a few commands, like changing the duration of a note, are handled right at the end of this function where _score->cmd() is called. In mscore/libmscore you find the source for the various classes and the layout algorithm. If you sort the directory by file size, you'll easily spot where most processing is done: measure.cpp, score.cpp, cmd.cpp, undo.cpp., layout.cpp. edit.cpp and chord.cpp.