Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2026 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 :
23 : #include "enginesetup.h"
24 :
25 : #include "internal/audioengineconfiguration.h"
26 : #include "internal/synthesizers/synthresolver.h"
27 : #include "internal/synthesizers/fluidsynth/fluidresolver.h"
28 : #include "internal/synthesizers/soundfontrepository.h"
29 : #include "internal/fx/fxresolver.h"
30 : #include "internal/fx/musefxresolver.h"
31 :
32 : #include "internal/audioengine.h"
33 : #include "internal/audiofactory.h"
34 : #include "internal/transporteventsdispatcher.h"
35 :
36 : using namespace muse::audio::engine;
37 :
38 : static const std::string mname("audio_engine");
39 :
40 : // Global
41 0 : std::string EngineGlobalSetup::moduleName() const
42 : {
43 0 : return mname;
44 : }
45 :
46 0 : void EngineGlobalSetup::registerExports()
47 : {
48 : //! NOTE Services registration
49 : //! At the moment, it is better to create services
50 : //! and register them in the IOC in the main thread,
51 : //! because the IOC thread is not safe.
52 : //! Therefore, we will need to make own IOC instance for the engine.
53 :
54 0 : m_configuration = std::make_shared<AudioEngineConfiguration>();
55 0 : m_synthResolver = std::make_shared<synth::SynthResolver>();
56 0 : m_fxResolver = std::make_shared<fx::FxResolver>();
57 0 : m_soundFontRepository = std::make_shared<synth::SoundFontRepository>();
58 0 : m_audioEngine = std::make_shared<AudioEngine>();
59 0 : m_transportEventsDispatcher = std::make_shared<TransportEventsDispatcher>();
60 :
61 0 : globalIoc()->registerExport<IAudioFactory>(mname, new AudioFactory());
62 0 : globalIoc()->registerExport<IAudioEngineConfiguration>(mname, m_configuration);
63 0 : globalIoc()->registerExport<synth::ISynthResolver>(mname, m_synthResolver);
64 0 : globalIoc()->registerExport<fx::IFxResolver>(mname, m_fxResolver);
65 0 : globalIoc()->registerExport<synth::ISoundFontRepository>(mname, m_soundFontRepository);
66 0 : globalIoc()->registerExport<IAudioEngine>(mname, m_audioEngine);
67 0 : globalIoc()->registerExport<ITransportEventsDispatcher>(mname, m_transportEventsDispatcher);
68 0 : }
69 :
70 0 : void EngineGlobalSetup::resolveImports()
71 : {
72 0 : m_fxResolver->registerResolver(AudioFxType::MuseFx, std::make_shared<fx::MuseFxResolver>());
73 0 : m_synthResolver->registerResolver(AudioSourceType::Fluid, std::make_shared<synth::FluidResolver>());
74 0 : }
75 :
76 0 : void EngineGlobalSetup::onDeinit()
77 : {
78 : //! MAIN THREAD
79 0 : globalIoc()->unregister<IAudioEngineConfiguration>(mname);
80 0 : globalIoc()->unregister<synth::ISynthResolver>(mname);
81 0 : globalIoc()->unregister<synth::ISoundFontRepository>(mname);
82 0 : globalIoc()->unregister<fx::IFxResolver>(mname);
83 0 : globalIoc()->unregister<IAudioEngine>(mname);
84 0 : globalIoc()->unregister<ITransportEventsDispatcher>(mname);
85 0 : globalIoc()->unregister<IAudioFactory>(mname);
86 0 : }
|