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 "audiofactory.h"
24 :
25 : #include "audio/common/audioerrors.h"
26 :
27 : #include "nodes/eventaudionode.h"
28 :
29 : using namespace muse;
30 : using namespace muse::audio;
31 : using namespace muse::audio::engine;
32 :
33 0 : AudioResourceMetaList AudioFactory::availableInputResources() const
34 : {
35 0 : return synthResolver()->resolveAvailableResources();
36 : }
37 :
38 0 : SoundPresetList AudioFactory::availableSoundPresets(const AudioResourceMeta& resourceMeta) const
39 : {
40 0 : return synthResolver()->resolveAvailableSoundPresets(resourceMeta);
41 : }
42 :
43 0 : AudioResourceMetaList AudioFactory::availableOutputResources() const
44 : {
45 0 : return fxResolver()->resolveAvailableResources();
46 : }
47 :
48 0 : RetVal<synth::ISynthesizerPtr> AudioFactory::makeSynth(const TrackId trackId, const AudioInputParams& params,
49 : const PlaybackSetupData& setupData) const
50 : {
51 0 : auto synth = synthResolver()->resolveSynth(trackId, params, audioEngine()->outputSpec(), setupData);
52 0 : if (!synth) {
53 0 : return RetVal<synth::ISynthesizerPtr>::make_ret(Err::InvalidSynth);
54 : }
55 0 : return RetVal<synth::ISynthesizerPtr>::make_ok(synth);
56 0 : }
57 :
58 0 : RetVal<synth::ISynthesizerPtr> AudioFactory::makeDefaultSynth(const TrackId trackId) const
59 : {
60 0 : auto synth = synthResolver()->resolveDefaultSynth(trackId);
61 0 : if (!synth) {
62 0 : return RetVal<synth::ISynthesizerPtr>::make_ret(Err::InvalidSynth);
63 : }
64 0 : return RetVal<synth::ISynthesizerPtr>::make_ok(synth);
65 0 : }
66 :
67 0 : void AudioFactory::clearSynthSources()
68 : {
69 0 : synthResolver()->clearSources();
70 0 : }
71 :
72 0 : RetVal<AudioSourceNodePtr> AudioFactory::makeEventSource(const TrackId trackId, const mpe::PlaybackData& playbackData,
73 : const AudioInputParams& params,
74 : const std::function<void()> onOffStreamReceived) const
75 : {
76 0 : EventAudioNodePtr source = std::make_shared<EventAudioNode>(trackId, playbackData, onOffStreamReceived);
77 0 : source->setOutputSpec(audioEngine()->outputSpec());
78 0 : source->applyInputParams(params);
79 0 : return RetVal<AudioSourceNodePtr>::make_ok(source);
80 0 : }
81 :
82 0 : FxChainPtr AudioFactory::makeMasterFxChain(const AudioFxChain& fxChain) const
83 : {
84 0 : std::vector<IFxProcessorPtr> fxlist = fxResolver()->resolveMasterFxList(fxChain, audioEngine()->outputSpec());
85 :
86 0 : FxChainPtr chain = std::make_shared<FxChain>();
87 0 : chain->setName("FxChain [master]");
88 0 : chain->setFxList(fxlist);
89 0 : chain->setFxChainSpec(fxChain);
90 :
91 0 : return chain;
92 0 : }
93 :
94 0 : FxChainPtr AudioFactory::makeTrackFxChain(const TrackId trackId, const AudioFxChain& fxChain) const
95 : {
96 0 : std::vector<IFxProcessorPtr> fxlist = fxResolver()->resolveFxList(trackId, fxChain, audioEngine()->outputSpec());
97 :
98 0 : FxChainPtr chain = std::make_shared<FxChain>();
99 0 : if (trackId == MASTER_TRACK_ID) {
100 0 : chain->setName("FxChain [master]");
101 : } else {
102 0 : chain->setName("FxChain [track " + std::to_string(trackId) + "]");
103 : }
104 0 : chain->setFxList(fxlist);
105 0 : chain->setFxChainSpec(fxChain);
106 :
107 0 : return chain;
108 0 : }
109 :
110 0 : void AudioFactory::clearAllFx()
111 : {
112 0 : fxResolver()->clearAllFx();
113 0 : }
|