LCOV - code coverage report
Current view: top level - src/engraving - engravingmodule.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 80.6 % 144 116
Test Date: 2026-11-05 04:07:02

            Line data    Source code
       1              : /*
       2              :  * SPDX-License-Identifier: GPL-3.0-only
       3              :  * MuseScore-Studio-CLA-applies
       4              :  *
       5              :  * MuseScore Studio
       6              :  * Music Composition & Notation
       7              :  *
       8              :  * Copyright (C) 2021 MuseScore Limited and others
       9              :  *
      10              :  * This program is free software: you can redistribute it and/or modify
      11              :  * it under the terms of the GNU General Public License version 3 as
      12              :  * published by the Free Software Foundation.
      13              :  *
      14              :  * This program is distributed in the hope that it will be useful,
      15              :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      16              :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17              :  * GNU General Public License for more details.
      18              :  *
      19              :  * You should have received a copy of the GNU General Public License
      20              :  * along with this program.  If not, see <https://www.gnu.org/licenses/>.
      21              :  */
      22              : #include "engravingmodule.h"
      23              : 
      24              : #include "modularity/ioc.h"
      25              : #include "global/allocator.h"
      26              : 
      27              : #include "draw/ifontprovider.h"
      28              : #include "draw/internal/ifontsdatabase.h"
      29              : 
      30              : #include "infrastructure/smufl.h"
      31              : 
      32              : #ifndef ENGRAVING_NO_INTERNAL
      33              : #include "internal/engravingconfiguration.h"
      34              : #include "internal/engravingcontextconfiguration.h"
      35              : #include "internal/engravingfontsprovider.h"
      36              : #include "internal/palettescoreprovider.h"
      37              : #endif
      38              : 
      39              : #include "engraving/style/defaultstyle.h"
      40              : 
      41              : #include "engraving/dom/stafftype.h"
      42              : #include "engraving/dom/mscore.h"
      43              : #include "engraving/dom/masterscore.h"
      44              : #include "engraving/dom/drumset.h"
      45              : #include "engraving/dom/figuredbass.h"
      46              : 
      47              : #include "rendering/score/scorerenderer.h"
      48              : #include "rendering/single/singlerenderer.h"
      49              : #include "rendering/editmode/editmoderenderer.h"
      50              : 
      51              : #ifndef ENGRAVING_NO_API
      52              : #include "global/api/iapiregister.h"
      53              : #include "api/v1/qmlpluginapi.h"
      54              : #include "api/v1/engravingapiv1.h"
      55              : #endif
      56              : 
      57              : #ifdef MUE_BUILD_ENGRAVING_DEVTOOLS
      58              : #include "interactive/iinteractiveuriregister.h"
      59              : #include "devtools/engravingelementsprovider.h"
      60              : #include "devtools/drawdata/diagnosticdrawprovider.h"
      61              : #endif
      62              : 
      63              : #include "muse_framework_config.h"
      64              : 
      65              : #include "log.h"
      66              : 
      67              : using namespace mu::engraving;
      68              : using namespace muse;
      69              : using namespace muse::modularity;
      70              : using namespace muse::draw;
      71              : 
      72              : static const std::string mname("engraving");
      73              : 
      74           16 : static void engraving_init_qrc()
      75              : {
      76              : #ifndef NO_QT_SUPPORT
      77           16 :     Q_INIT_RESOURCE(engraving);
      78              : 
      79           16 :     Q_INIT_RESOURCE(fonts_Leland);
      80           16 :     Q_INIT_RESOURCE(fonts_Bravura);
      81           16 :     Q_INIT_RESOURCE(fonts_Campania);
      82           16 :     Q_INIT_RESOURCE(fonts_Edwin);
      83           16 :     Q_INIT_RESOURCE(fonts_FreeSans);
      84           16 :     Q_INIT_RESOURCE(fonts_FreeSerif);
      85           16 :     Q_INIT_RESOURCE(fonts_Gootville);
      86           16 :     Q_INIT_RESOURCE(fonts_MScore);
      87           16 :     Q_INIT_RESOURCE(fonts_MuseJazz);
      88           16 :     Q_INIT_RESOURCE(fonts_Smufl);
      89           16 :     Q_INIT_RESOURCE(fonts_Petaluma);
      90           16 :     Q_INIT_RESOURCE(fonts_FinaleMaestro);
      91           16 :     Q_INIT_RESOURCE(fonts_FinaleBroadway);
      92           16 :     Q_INIT_RESOURCE(fonts_Tabulature);
      93              : #endif
      94           16 : }
      95              : 
      96            0 : std::string EngravingModule::moduleName() const
      97              : {
      98            0 :     return mname;
      99              : }
     100              : 
     101           16 : void EngravingModule::registerExports()
     102              : {
     103              : #ifndef ENGRAVING_NO_INTERNAL
     104              : 
     105           16 :     m_configuration = std::make_shared<EngravingConfiguration>();
     106           16 :     m_engravingfonts = std::make_shared<EngravingFontsProvider>();
     107              : 
     108           16 :     globalIoc()->registerExport<IEngravingConfiguration>(mname, m_configuration);
     109           16 :     globalIoc()->registerExport<IEngravingFontsProvider>(mname, m_engravingfonts);
     110              : #endif
     111              : 
     112              :     // internal
     113           16 :     globalIoc()->registerExport<rendering::IScoreRenderer>(mname, new rendering::score::ScoreRenderer());
     114           16 :     globalIoc()->registerExport<rendering::ISingleRenderer>(mname, new rendering::single::SingleRenderer());
     115           16 :     globalIoc()->registerExport<rendering::IEditModeRenderer>(mname, new rendering::editmode::EditModeRenderer());
     116              : 
     117              : #ifdef MUE_BUILD_ENGRAVING_DEVTOOLS
     118           16 :     globalIoc()->registerExport<IDiagnosticDrawProvider>(mname, new DiagnosticDrawProvider());
     119              : #endif
     120           16 : }
     121              : 
     122           16 : void EngravingModule::resolveImports()
     123              : {
     124              : #ifdef MUE_BUILD_ENGRAVING_DEVTOOLS
     125           16 :     auto ir = globalIoc()->resolve<muse::interactive::IInteractiveUriRegister>(mname);
     126           16 :     if (ir) {
     127            0 :         ir->registerQmlUri(Uri("musescore://diagnostics/engraving/elements"), "MuseScore.Engraving", "EngravingElementsDialog");
     128            0 :         ir->registerQmlUri(Uri("musescore://diagnostics/engraving/undostack"), "MuseScore.Engraving", "EngravingUndoStackDialog");
     129            0 :         ir->registerQmlUri(Uri("musescore://diagnostics/engraving/style"), "MuseScore.Engraving", "EngravingStyleDialog");
     130              :     }
     131              : #endif
     132           16 : }
     133              : 
     134            0 : void EngravingModule::registerApi()
     135              : {
     136              : #ifndef ENGRAVING_NO_API
     137            0 :     apiv1::PluginAPI::registerQmlTypes();
     138              : 
     139            0 :     auto api = globalIoc()->resolve<muse::api::IApiRegister>(mname);
     140            0 :     if (api) {
     141            0 :         api->regApiCreator(mname, "MuseApi.Engraving", new muse::api::ApiCreator<apiv1::EngravingApiV1>());
     142              : 
     143              :         //! TODO remove me
     144            0 :         const char* uri = "MuseApi.Engraving";
     145            0 :         api->regEnum<apiv1::enums::ElementType>(uri, muse::api::EnumType::String, "Element");
     146            0 :         api->regEnum<apiv1::enums::TextStyleType>(uri);
     147              :     }
     148              : #endif
     149            0 : }
     150              : 
     151           16 : void EngravingModule::registerResources()
     152              : {
     153           16 :     engraving_init_qrc();
     154           16 : }
     155              : 
     156           16 : void EngravingModule::registerUiTypes()
     157              : {
     158           16 :     MScore::registerUiTypes();
     159           16 : }
     160              : 
     161           16 : void EngravingModule::onInit(const IApplication::RunMode&)
     162              : {
     163              : #ifndef ENGRAVING_NO_INTERNAL
     164              :     // Init fonts
     165              :     {
     166              :         using namespace muse::draw;
     167              : 
     168           16 :         std::shared_ptr<IFontsDatabase> fdb = globalIoc()->resolve<IFontsDatabase>(mname);
     169              : 
     170              :         // Text
     171           16 :         fdb->addFont(FontDataKey(u"Edwin", false, false), ":/fonts/edwin/Edwin-Roman.otf");
     172           16 :         fdb->addFont(FontDataKey(u"Edwin", false, true), ":/fonts/edwin/Edwin-Italic.otf");
     173           16 :         fdb->addFont(FontDataKey(u"Edwin", true, false), ":/fonts/edwin/Edwin-Bold.otf");
     174           16 :         fdb->addFont(FontDataKey(u"Edwin", true, true), ":/fonts/edwin/Edwin-BdIta.otf");
     175              : 
     176              :         // MusicSymbol[Text]
     177          128 :         auto addMusicFont = [this, fdb](const std::string& name, const FontDataKey& fontDataKey, const muse::io::path_t& filePath){
     178          128 :             fdb->addFont(FontDataKey(fontDataKey), filePath);
     179          128 :             m_engravingfonts->addInternalFont(name, fontDataKey.family().id().toStdString(), filePath);
     180          144 :         };
     181              : 
     182           48 :         addMusicFont("Bravura", FontDataKey(u"Bravura"), ":/fonts/bravura/Bravura.otf");
     183           16 :         fdb->addFont(FontDataKey(u"Bravura Text"), ":/fonts/bravura/BravuraText.otf");
     184           48 :         addMusicFont("Leland", FontDataKey(u"Leland"), ":/fonts/leland/Leland.otf");
     185           16 :         fdb->addFont(FontDataKey(u"Leland Text"), ":/fonts/leland/LelandText.otf");
     186           48 :         addMusicFont("Emmentaler", FontDataKey(u"MScore"), ":/fonts/mscore/MScore.otf");
     187           16 :         fdb->addFont(FontDataKey(u"MScore Text"), ":/fonts/mscore/MScoreText.otf");
     188           48 :         addMusicFont("Gonville", FontDataKey(u"Gootville"), ":/fonts/gootville/Gootville.otf");
     189           16 :         fdb->addFont(FontDataKey(u"Gootville Text"), ":/fonts/gootville/GootvilleText.otf");
     190           48 :         addMusicFont("MuseJazz", FontDataKey(u"MuseJazz"), ":/fonts/musejazz/MuseJazz.otf");
     191           16 :         fdb->addFont(FontDataKey(u"MuseJazz Text"), ":/fonts/musejazz/MuseJazzText.otf");
     192           48 :         addMusicFont("Petaluma", FontDataKey(u"Petaluma"),    ":/fonts/petaluma/Petaluma.otf");
     193           16 :         fdb->addFont(FontDataKey(u"Petaluma Text"), ":/fonts/petaluma/PetalumaText.otf");
     194           48 :         addMusicFont("Finale Maestro", FontDataKey(u"Finale Maestro"), ":/fonts/finalemaestro/FinaleMaestro.otf");
     195           16 :         fdb->addFont(FontDataKey(u"Finale Maestro Text"), ":/fonts/finalemaestro/FinaleMaestroText.otf");
     196           48 :         addMusicFont("Finale Broadway", FontDataKey(u"Finale Broadway"), ":/fonts/finalebroadway/FinaleBroadway.otf");
     197           16 :         fdb->addFont(FontDataKey(u"Finale Broadway Text"), ":/fonts/finalebroadway/FinaleBroadwayText.otf");
     198              : 
     199              :         // Tabulature
     200           16 :         fdb->addFont(FontDataKey(u"FreeSerif"), ":/fonts/FreeSerif.ttf");
     201           16 :         fdb->addFont(FontDataKey(u"FreeSerif", true, false), ":/fonts/FreeSerifBold.ttf");
     202           16 :         fdb->addFont(FontDataKey(u"FreeSerif", false, true), ":/fonts/FreeSerifItalic.ttf");
     203           16 :         fdb->addFont(FontDataKey(u"FreeSerif", true, true), ":/fonts/FreeSerifBoldItalic.ttf");
     204           16 :         fdb->addFont(FontDataKey(u"FreeSans"), ":/fonts/FreeSans.ttf");
     205           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabRenaiss"), ":/fonts/MuseScoreTabRenaiss.ttf");
     206           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabPhalese"), ":/fonts/MuseScoreTabPhalese.ttf");
     207           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabBonneuilDeVisee"), ":/fonts/MuseScoreTabBonneuilDeVisee.ttf");
     208           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabBonneuilGaultier"), ":/fonts/MuseScoreTabBonneuilGaultier.ttf");
     209           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabDowland"), ":/fonts/MuseScoreTabDowland.ttf");
     210           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabLuteDidactic"), ":/fonts/MuseScoreTabLuteDidactic.ttf");
     211           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabModern"), ":/fonts/MuseScoreTabModern.ttf");
     212           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabItalian"), ":/fonts/MuseScoreTabItalian.ttf");
     213           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabFrench"), ":/fonts/MuseScoreTabFrench.ttf");
     214           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabFrenchBaroqueHeadless"), ":/fonts/MuseScoreTabFrenchBaroqueHeadless.ttf");
     215           16 :         fdb->addFont(FontDataKey(u"MuseScoreTabFrenchBaroque"), ":/fonts/MuseScoreTabFrenchBaroque.ttf");
     216              : 
     217              :         // Figured Bass
     218           16 :         fdb->addFont(FontDataKey(u"MscoreBC"), ":/fonts/mscore-BC.ttf");
     219              : 
     220              :         // Roman Numeral Analysis
     221           16 :         fdb->addFont(FontDataKey(u"Campania"), ":/fonts/campania/Campania.otf");
     222              : 
     223              :         // Defaults
     224           16 :         fdb->setDefaultFont(Font::Type::Unknown, FontDataKey(u"Edwin"));
     225           16 :         fdb->setDefaultFont(Font::Type::Text, FontDataKey(u"Edwin"));
     226           16 :         fdb->setDefaultFont(Font::Type::Tablature, FontDataKey(u"FreeSerif"));
     227           16 :         fdb->setDefaultFont(Font::Type::MusicSymbolText, FontDataKey(u"Bravura Text"));
     228           16 :         fdb->setDefaultFont(Font::Type::MusicSymbol, FontDataKey(u"Bravura"));
     229           32 :         m_engravingfonts->setFallbackFont("Bravura");
     230              : 
     231              :         //! NOTE Used for Qt font provider
     232           16 :         fdb->insertSubstitution(u"Leland Text",    u"Bravura Text");
     233           16 :         fdb->insertSubstitution(u"Bravura Text",   u"Leland Text");
     234           16 :         fdb->insertSubstitution(u"MScore Text",    u"Leland Text");
     235           16 :         fdb->insertSubstitution(u"Gootville Text", u"Leland Text");
     236           16 :         fdb->insertSubstitution(u"MuseJazz Text",  u"Leland Text");
     237           16 :         fdb->insertSubstitution(u"Petaluma Text",  u"MuseJazz Text");
     238           16 :         fdb->insertSubstitution(u"Finale Maestro Text", u"Leland Text");
     239           16 :         fdb->insertSubstitution(u"Finale Broadway Text", u"MuseJazz Text");
     240           16 :         fdb->insertSubstitution(u"ScoreFont",      u"Leland Text");// alias for current Musical Text Font
     241              : 
     242              :         // Symbols
     243           16 :         Smufl::init();
     244              : 
     245              :         //! NOTE It may be necessary to draw something with these fonts without requesting the fonts themselves
     246              :         //! (for example, simply specifying the family name for painter).
     247              :         //! But if they are not loaded, then they are not added to the font database and,
     248              :         //! accordingly, they are drawn incorrectly
     249           16 :         m_engravingfonts->loadAllFonts();
     250           16 :     }
     251              : 
     252           16 :     m_configuration->init();
     253              : 
     254           32 :     DefaultStyle::instance()->init(m_configuration->defaultStyleFilePath(),
     255           32 :                                    m_configuration->partStyleFilePath(),
     256           16 :                                    m_configuration->defaultPageSize());
     257              : 
     258           16 :     StaffType::initStaffTypes(m_configuration->defaultColor());
     259              : #endif // ENGRAVING_NO_INTERNAL
     260              : 
     261              :     // initialize dom
     262              : 
     263           16 :     MScore::warnPitchRange      = true;
     264           16 :     MScore::warnGuitarBends     = true;
     265           16 :     MScore::pedalEventsMinTicks = 1;
     266              : 
     267           16 :     Drumset::initDrumset();
     268           16 :     FiguredBass::readConfigFile(String());
     269              : 
     270           16 :     MScore::setNudgeStep(0.1);     // cursor key (default 0.1)
     271           16 :     MScore::setNudgeStep10(1.0);     // Ctrl + cursor key (default 1.0)
     272           16 :     MScore::setNudgeStep50(0.01);     // Alt  + cursor key (default 0.01)
     273              : 
     274              :     //! NOTE And some initialization in the `Notation::init()`
     275           16 : }
     276              : 
     277           16 : void EngravingModule::onDeinit()
     278              : {
     279              : #ifndef ENGRAVING_NO_INTERNAL
     280           16 :     m_engravingfonts->deinit();
     281              : #endif
     282           16 : }
     283              : 
     284            0 : IContextSetup* EngravingModule::newContext(const muse::modularity::ContextPtr& ctx) const
     285              : {
     286            0 :     return new EngravingContext(ctx);
     287              : }
     288              : 
     289            0 : void EngravingContext::registerExports()
     290              : {
     291              : #ifndef ENGRAVING_NO_INTERNAL
     292            0 :     m_paletteScoreProvider = std::make_shared<PaletteScoreProvider>(iocContext());
     293            0 :     ioc()->registerExport<IPaletteScoreProvider>(mname, m_paletteScoreProvider);
     294            0 :     ioc()->registerExport<IEngravingElementsProvider>(mname, new EngravingElementsProvider());
     295            0 :     ioc()->registerExport<IEngravingContextConfiguration>(mname, new EngravingContextConfiguration(iocContext()));
     296              : #endif
     297            0 : }
     298              : 
     299            0 : void EngravingContext::onInit(const muse::IApplication::RunMode&)
     300              : {
     301              : #ifndef ENGRAVING_NO_INTERNAL
     302            0 :     m_paletteScoreProvider->init();
     303              : #endif
     304            0 : }
     305              : 
     306            0 : void EngravingContext::onDestroy()
     307              : {
     308              : #ifndef ENGRAVING_NO_INTERNAL
     309            0 :     m_paletteScoreProvider->deinit();
     310              : #endif
     311            0 : }
        

Generated by: LCOV version 2.0-1