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) 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 "midimodule.h"
24 :
25 : #include "internal/midiconfiguration.h"
26 :
27 : #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
28 : #include "internal/platform/lin/alsamidioutport.h"
29 : #include "internal/platform/lin/alsamidiinport.h"
30 : #elif defined(Q_OS_WIN)
31 : #include "internal/platform/win/winmidioutport.h"
32 : #include "internal/platform/win/winmidiinport.h"
33 : #elif defined(Q_OS_MACOS)
34 : #include "internal/platform/osx/coremidioutport.h"
35 : #include "internal/platform/osx/coremidiinport.h"
36 : #else
37 : #include "internal/dummymidioutport.h"
38 : #include "internal/dummymidiinport.h"
39 : #endif
40 :
41 : using namespace muse::midi;
42 :
43 0 : std::string MidiModule::moduleName() const
44 : {
45 0 : return "midi";
46 : }
47 :
48 0 : void MidiModule::registerExports()
49 : {
50 0 : m_configuration = std::make_shared<MidiConfiguration>();
51 :
52 : #if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
53 0 : m_midiOutPort = std::make_shared<AlsaMidiOutPort>();
54 0 : m_midiInPort = std::make_shared<AlsaMidiInPort>();
55 : #elif defined(Q_OS_WIN)
56 : m_midiOutPort = std::make_shared<WinMidiOutPort>();
57 : m_midiInPort = std::make_shared<WinMidiInPort>();
58 : #elif defined(Q_OS_MACOS)
59 : m_midiOutPort = std::make_shared<CoreMidiOutPort>();
60 : m_midiInPort = std::make_shared<CoreMidiInPort>();
61 : #else
62 : m_midiOutPort = std::make_shared<DummyMidiOutPort>();
63 : m_midiInPort = std::make_shared<DummyMidiInPort>();
64 : #endif
65 :
66 0 : globalIoc()->registerExport<IMidiConfiguration>(moduleName(), m_configuration);
67 0 : globalIoc()->registerExport<IMidiOutPort>(moduleName(), m_midiOutPort);
68 0 : globalIoc()->registerExport<IMidiInPort>(moduleName(), m_midiInPort);
69 0 : }
70 :
71 0 : void MidiModule::onInit(const IApplication::RunMode& mode)
72 : {
73 0 : m_configuration->init();
74 :
75 0 : if (mode == IApplication::RunMode::GuiApp) {
76 0 : m_midiOutPort->init();
77 0 : m_midiInPort->init();
78 : }
79 0 : }
80 :
81 0 : void MidiModule::onDeinit()
82 : {
83 0 : m_midiOutPort->deinit();
84 0 : m_midiInPort->deinit();
85 0 : }
|