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 :
23 : #pragma once
24 :
25 : #include "async/asyncable.h"
26 : #include "project/iprojectsession.h"
27 : #include "midi/imidiconfiguration.h"
28 : #include "midi/imidiinport.h"
29 : #include "midi/imidioutport.h"
30 : #include "midiremote/imidiremote.h"
31 : #include "modularity/ioc.h"
32 : #include "notation/inotationconfiguration.h"
33 :
34 : namespace mu::notation {
35 : class MidiInputOutputController : public muse::async::Asyncable, public muse::Contextable
36 : {
37 : muse::GlobalInject<INotationConfiguration> configuration;
38 : muse::GlobalInject<muse::midi::IMidiConfiguration> midiConfiguration;
39 : muse::GlobalInject<muse::midi::IMidiInPort> midiInPort;
40 : muse::GlobalInject<muse::midi::IMidiOutPort> midiOutPort;
41 : muse::ContextInject<muse::midiremote::IMidiRemote> midiRemote = { this };
42 : muse::ContextInject<project::IProjectSession> projectSession = { this };
43 :
44 : public:
45 :
46 0 : MidiInputOutputController(const muse::modularity::ContextPtr& iocCtx)
47 0 : : muse::Contextable(iocCtx)
48 : {
49 0 : }
50 :
51 : void init();
52 :
53 : private:
54 : void checkInputConnection();
55 : void checkOutputConnection();
56 :
57 : void checkConnection(const muse::midi::MidiDeviceID& preferredDeviceId, const muse::midi::MidiDeviceID& currentDeviceId,
58 : const muse::midi::MidiDeviceList& availableDevices, const std::function<muse::Ret(
59 : const muse::midi::MidiDeviceID&)>& connectCallback);
60 :
61 : void onMidiEventReceived(const muse::midi::tick_t tick, const muse::midi::Event& event);
62 :
63 : muse::midi::MidiDeviceID firstAvailableDeviceId(const muse::midi::MidiDeviceList& devices) const;
64 : };
65 : }
|