LCOV - code coverage report
Current view: top level - src/engraving - engravingmodule.cpp Coverage Total Hit
Test: filtered_coverage.info Lines: 80.4 % 143 115
Test Date: 2026-11-19 04:14:36

            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           18 : static void engraving_init_qrc()
      75              : {
      76              : #ifndef NO_QT_SUPPORT
      77           18 :     Q_INIT_RESOURCE(engraving);
      78              : 
      79           18 :     Q_INIT_RESOURCE(fonts_Leland);
      80           18 :     Q_INIT_RESOURCE(fonts_Bravura);
      81           18 :     Q_INIT_RESOURCE(fonts_Campania);
      82           18 :     Q_INIT_RESOURCE(fonts_Edwin);
      83           18 :     Q_INIT_RESOURCE(fonts_FreeSans);
      84           18 :     Q_INIT_RESOURCE(fonts_FreeSerif);
      85           18 :     Q_INIT_RESOURCE(fonts_Gootville);
      86           18 :     Q_INIT_RESOURCE(fonts_MScore);
      87           18 :     Q_INIT_RESOURCE(fonts_MuseJazz);
      88           18 :     Q_INIT_RESOURCE(fonts_Smufl);
      89           18 :     Q_INIT_RESOURCE(fonts_Petaluma);
      90           18 :     Q_INIT_RESOURCE(fonts_FinaleMaestro);
      91           18 :     Q_INIT_RESOURCE(fonts_FinaleBroadway);
      92           18 :     Q_INIT_RESOURCE(fonts_Tabulature);
      93              : #endif
      94           18 : }
      95              : 
      96            0 : std::string EngravingModule::moduleName() const
      97              : {
      98            0 :     return mname;
      99              : }
     100              : 
     101           18 : void EngravingModule::registerExports()
     102              : {
     103              : #ifndef ENGRAVING_NO_INTERNAL
     104              : 
     105           18 :     m_configuration = std::make_shared<EngravingConfiguration>();
     106           18 :     m_engravingfonts = std::make_shared<EngravingFontsProvider>();
     107              : 
     108           18 :     globalIoc()->registerExport<IEngravingConfiguration>(mname, m_configuration);
     109           18 :     globalIoc()->registerExport<IEngravingFontsProvider>(mname, m_engravingfonts);
     110              : #endif
     111              : 
     112              :     // internal
     113           18 :     globalIoc()->registerExport<rendering::IScoreRenderer>(mname, new rendering::score::ScoreRenderer());
     114           18 :     globalIoc()->registerExport<rendering::ISingleRenderer>(mname, new rendering::single::SingleRenderer());
     115           18 :     globalIoc()->registerExport<rendering::IEditModeRenderer>(mname, new rendering::editmode::EditModeRenderer());
     116              : 
     117              : #ifdef MUE_BUILD_ENGRAVING_DEVTOOLS
     118           18 :     globalIoc()->registerExport<IDiagnosticDrawProvider>(mname, new DiagnosticDrawProvider());
     119              : #endif
     120           18 : }
     121              : 
     122           18 : void EngravingModule::resolveImports()
     123              : {
     124              : #ifdef MUE_BUILD_ENGRAVING_DEVTOOLS
     125           18 :     auto ir = globalIoc()->resolve<muse::interactive::IInteractiveUriRegister>(mname);
     126           18 :     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           18 : }
     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           18 : void EngravingModule::registerResources()
     152              : {
     153           18 :     engraving_init_qrc();
     154           18 : }
     155              : 
     156           18 : void EngravingModule::registerUiTypes()
     157              : {
     158           18 :     MScore::registerUiTypes();
     159           18 : }
     160              : 
     161           18 : void EngravingModule::onInit(const IApplication::RunMode&)
     162              : {
     163              : #ifndef ENGRAVING_NO_INTERNAL
     164              :     // Init fonts
     165              :     {
     166              :         using namespace muse::draw;
     167              : 
     168           18 :         std::shared_ptr<IFontsDatabase> fdb = globalIoc()->resolve<IFontsDatabase>(mname);
     169              : 
     170              :         // Text
     171           18 :         fdb->addFont(FontDataKey(u"Edwin", false, false), ":/fonts/edwin/Edwin-Roman.otf");
     172           18 :         fdb->addFont(FontDataKey(u"Edwin", false, true), ":/fonts/edwin/Edwin-Italic.otf");
     173           18 :         fdb->addFont(FontDataKey(u"Edwin", true, false), ":/fonts/edwin/Edwin-Bold.otf");
     174           18 :         fdb->addFont(FontDataKey(u"Edwin", true, true), ":/fonts/edwin/Edwin-BdIta.otf");
     175              : 
     176              :         // MusicSymbol[Text]
     177          144 :         auto addMusicFont = [this, fdb](const std::string& name, const FontDataKey& fontDataKey, const muse::io::path_t& filePath){
     178          144 :             fdb->addFont(FontDataKey(fontDataKey), filePath);
     179          144 :             m_engravingfonts->addInternalFont(name, fontDataKey.family().id().toStdString(), filePath);
     180          162 :         };
     181              : 
     182           54 :         addMusicFont("Bravura", FontDataKey(u"Bravura"), ":/fonts/bravura/Bravura.otf");
     183           18 :         fdb->addFont(FontDataKey(u"Bravura Text"), ":/fonts/bravura/BravuraText.otf");
     184           54 :         addMusicFont("Leland", FontDataKey(u"Leland"), ":/fonts/leland/Leland.otf");
     185           18 :         fdb->addFont(FontDataKey(u"Leland Text"), ":/fonts/leland/LelandText.otf");
     186           54 :         addMusicFont("Emmentaler", FontDataKey(u"MScore"), ":/fonts/mscore/MScore.otf");
     187           18 :         fdb->addFont(FontDataKey(u"MScore Text"), ":/fonts/mscore/MScoreText.otf");
     188           54 :         addMusicFont("Gonville", FontDataKey(u"Gootville"), ":/fonts/gootville/Gootville.otf");
     189           18 :         fdb->addFont(FontDataKey(u"Gootville Text"), ":/fonts/gootville/GootvilleText.otf");
     190           54 :         addMusicFont("MuseJazz", FontDataKey(u"MuseJazz"), ":/fonts/musejazz/MuseJazz.otf");
     191           18 :         fdb->addFont(FontDataKey(u"MuseJazz Text"), ":/fonts/musejazz/MuseJazzText.otf");
     192           54 :         addMusicFont("Petaluma", FontDataKey(u"Petaluma"),    ":/fonts/petaluma/Petaluma.otf");
     193           18 :         fdb->addFont(FontDataKey(u"Petaluma Text"), ":/fonts/petaluma/PetalumaText.otf");
     194           54 :         addMusicFont("Finale Maestro", FontDataKey(u"Finale Maestro"), ":/fonts/finalemaestro/FinaleMaestro.otf");
     195           18 :         fdb->addFont(FontDataKey(u"Finale Maestro Text"), ":/fonts/finalemaestro/FinaleMaestroText.otf");
     196           54 :         addMusicFont("Finale Broadway", FontDataKey(u"Finale Broadway"), ":/fonts/finalebroadway/FinaleBroadway.otf");
     197           18 :         fdb->addFont(FontDataKey(u"Finale Broadway Text"), ":/fonts/finalebroadway/FinaleBroadwayText.otf");
     198              : 
     199              :         // Tabulature
     200           18 :         fdb->addFont(FontDataKey(u"FreeSerif"), ":/fonts/FreeSerif.ttf");
     201           18 :         fdb->addFont(FontDataKey(u"FreeSerif", true, false), ":/fonts/FreeSerifBold.ttf");
     202           18 :         fdb->addFont(FontDataKey(u"FreeSerif", false, true), ":/fonts/FreeSerifItalic.ttf");
     203           18 :         fdb->addFont(FontDataKey(u"FreeSerif", true, true), ":/fonts/FreeSerifBoldItalic.ttf");
     204           18 :         fdb->addFont(FontDataKey(u"FreeSans"), ":/fonts/FreeSans.ttf");
     205           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabRenaiss"), ":/fonts/MuseScoreTabRenaiss.ttf");
     206           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabPhalese"), ":/fonts/MuseScoreTabPhalese.ttf");
     207           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabBonneuilDeVisee"), ":/fonts/MuseScoreTabBonneuilDeVisee.ttf");
     208           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabBonneuilGaultier"), ":/fonts/MuseScoreTabBonneuilGaultier.ttf");
     209           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabDowland"), ":/fonts/MuseScoreTabDowland.ttf");
     210           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabLuteDidactic"), ":/fonts/MuseScoreTabLuteDidactic.ttf");
     211           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabModern"), ":/fonts/MuseScoreTabModern.ttf");
     212           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabItalian"), ":/fonts/MuseScoreTabItalian.ttf");
     213           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabFrench"), ":/fonts/MuseScoreTabFrench.ttf");
     214           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabFrenchBaroqueHeadless"), ":/fonts/MuseScoreTabFrenchBaroqueHeadless.ttf");
     215           18 :         fdb->addFont(FontDataKey(u"MuseScoreTabFrenchBaroque"), ":/fonts/MuseScoreTabFrenchBaroque.ttf");
     216              : 
     217              :         // Figured Bass
     218           18 :         fdb->addFont(FontDataKey(u"MscoreBC"), ":/fonts/mscore-BC.ttf");
     219              : 
     220              :         // Roman Numeral Analysis
     221           18 :         fdb->addFont(FontDataKey(u"Campania"), ":/fonts/campania/Campania.otf");
     222              : 
     223              :         // Defaults
     224           18 :         fdb->setDefaultFont(Font::Type::Unknown, FontDataKey(u"Edwin"));
     225           18 :         fdb->setDefaultFont(Font::Type::Text, FontDataKey(u"Edwin"));
     226           18 :         fdb->setDefaultFont(Font::Type::Tablature, FontDataKey(u"FreeSerif"));
     227           18 :         fdb->setDefaultFont(Font::Type::MusicSymbolText, FontDataKey(u"Bravura Text"));
     228           18 :         fdb->setDefaultFont(Font::Type::MusicSymbol, FontDataKey(u"Bravura"));
     229           36 :         m_engravingfonts->setFallbackFont("Bravura");
     230              : 
     231              :         //! NOTE Used for Qt font provider
     232           18 :         fdb->insertSubstitution(u"Leland Text",    u"Bravura Text");
     233           18 :         fdb->insertSubstitution(u"Bravura Text",   u"Leland Text");
     234           18 :         fdb->insertSubstitution(u"MScore Text",    u"Leland Text");
     235           18 :         fdb->insertSubstitution(u"Gootville Text", u"Leland Text");
     236           18 :         fdb->insertSubstitution(u"MuseJazz Text",  u"Leland Text");
     237           18 :         fdb->insertSubstitution(u"Petaluma Text",  u"MuseJazz Text");
     238           18 :         fdb->insertSubstitution(u"Finale Maestro Text", u"Leland Text");
     239           18 :         fdb->insertSubstitution(u"Finale Broadway Text", u"MuseJazz Text");
     240           18 :         fdb->insertSubstitution(u"ScoreFont",      u"Leland Text");// alias for current Musical Text Font
     241              : 
     242              :         // Symbols
     243           18 :         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           18 :         m_engravingfonts->loadAllFonts();
     250           18 :     }
     251              : 
     252           18 :     m_configuration->init();
     253              : 
     254           36 :     DefaultStyle::instance()->init(m_configuration->defaultStyleFilePath(),
     255           36 :                                    m_configuration->partStyleFilePath(),
     256           18 :                                    m_configuration->defaultPageSize());
     257              : 
     258           18 :     StaffType::initStaffTypes(m_configuration->defaultColor());
     259              : #endif // ENGRAVING_NO_INTERNAL
     260              : 
     261              :     // initialize dom
     262              : 
     263           18 :     MScore::warnPitchRange      = true;
     264           18 :     MScore::warnGuitarBends     = true;
     265           18 :     MScore::pedalEventsMinTicks = 1;
     266              : 
     267           18 :     Drumset::initDrumset();
     268           18 :     FiguredBass::readConfigFile(String());
     269              : 
     270           18 :     MScore::setNudgeStep(0.1);     // cursor key (default 0.1)
     271           18 :     MScore::setNudgeStep10(1.0);     // Ctrl + cursor key (default 1.0)
     272              : 
     273              :     //! NOTE And some initialization in the `Notation::init()`
     274           18 : }
     275              : 
     276           18 : void EngravingModule::onDeinit()
     277              : {
     278              : #ifndef ENGRAVING_NO_INTERNAL
     279           18 :     m_engravingfonts->deinit();
     280              : #endif
     281           18 : }
     282              : 
     283            0 : IContextSetup* EngravingModule::newContext(const muse::modularity::ContextPtr& ctx) const
     284              : {
     285            0 :     return new EngravingContext(ctx);
     286              : }
     287              : 
     288            0 : void EngravingContext::registerExports()
     289              : {
     290              : #ifndef ENGRAVING_NO_INTERNAL
     291            0 :     m_paletteScoreProvider = std::make_shared<PaletteScoreProvider>(iocContext());
     292            0 :     ioc()->registerExport<IPaletteScoreProvider>(mname, m_paletteScoreProvider);
     293            0 :     ioc()->registerExport<IEngravingElementsProvider>(mname, new EngravingElementsProvider());
     294            0 :     ioc()->registerExport<IEngravingContextConfiguration>(mname, new EngravingContextConfiguration(iocContext()));
     295              : #endif
     296            0 : }
     297              : 
     298            0 : void EngravingContext::onInit(const muse::IApplication::RunMode&)
     299              : {
     300              : #ifndef ENGRAVING_NO_INTERNAL
     301            0 :     m_paletteScoreProvider->init();
     302              : #endif
     303            0 : }
     304              : 
     305            0 : void EngravingContext::onDestroy()
     306              : {
     307              : #ifndef ENGRAVING_NO_INTERNAL
     308            0 :     m_paletteScoreProvider->deinit();
     309              : #endif
     310            0 : }
        

Generated by: LCOV version 2.0-1