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) 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 "midiremote/imidiremote.h"
26 : #include "async/asyncable.h"
27 :
28 : #include "modularity/ioc.h"
29 : #include "midiremote/imidiremoteconfiguration.h"
30 : #include "io/ifilesystem.h"
31 : #include "multiwindows/imultiwindowsprovider.h"
32 : #include "rcommand/icommanddispatcher.h"
33 :
34 : #include "midiremote/immcdecoderfactory.h"
35 :
36 : namespace muse {
37 : class XmlStreamReader;
38 : class XmlStreamWriter;
39 : }
40 :
41 : namespace muse::midiremote {
42 : class MidiRemote : public IMidiRemote, public Contextable, public async::Asyncable
43 : {
44 : GlobalInject<IMidiRemoteConfiguration> configuration;
45 : GlobalInject<io::IFileSystem> fileSystem;
46 : GlobalInject<mi::IMultiWindowsProvider> multiwindowsProvider;
47 : GlobalInject<IMMCDecoderFactory> mmcDecoderFactory;
48 : ContextInject<rcommand::ICommandDispatcher> commandDispatcher = { this };
49 : public:
50 0 : MidiRemote(const modularity::ContextPtr& iocCtx)
51 0 : : Contextable(iocCtx) {}
52 :
53 : void init();
54 :
55 : const MidiMappingList& midiMappings() const override;
56 : Ret setMidiMappings(const MidiMappingList& midiMappings) override;
57 : void resetMidiMappings() override;
58 : async::Notification midiMappingsChanged() const override;
59 :
60 : // Setting
61 : void setIsSettingMode(bool arg) override;
62 : bool isSettingMode() const override;
63 :
64 : void setCurrentActionEvent(const muse::midi::Event& ev) override;
65 :
66 : // Process
67 : Ret process(const muse::midi::Event& ev) override;
68 :
69 : private:
70 : void readMidiMappings();
71 : MidiControlsMapping readMidiMapping(XmlStreamReader& reader) const;
72 :
73 : bool writeMidiMappings(const MidiMappingList& midiMappings) const;
74 : void writeMidiMapping(XmlStreamWriter& writer, const MidiControlsMapping& midiMapping) const;
75 :
76 : bool needIgnoreEvent(const muse::midi::Event& event) const;
77 :
78 : RemoteEvent remoteEvent(const rcommand::Command& command) const;
79 :
80 : void processMMC(const MMCMessage& msg);
81 :
82 : bool m_isSettingMode = false;
83 :
84 : MidiMappingList m_midiMappings;
85 : async::Notification m_midiMappingsChanged;
86 :
87 : IMMCDecoderPtr m_mmcDecoder;
88 : };
89 : }
|