tracktion-engine 3.0-10-g034fdde4aa5
Tracktion Engine — High level data model for audio applications

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_MidiOutputDevice.h
Go to the documentation of this file.
1 /*
2 ,--. ,--. ,--. ,--.
3 ,-' '-.,--.--.,--,--.,---.| |,-.,-' '-.`--' ,---. ,--,--, Copyright 2024
4 '-. .-'| .--' ,-. | .--'| /'-. .-',--.| .-. || \ Tracktion Software
5 | | | | \ '-' \ `--.| \ \ | | | |' '-' '| || | Corporation
6 `---' `--' `--`--'`---'`--'`--' `---' `--' `---' `--''--' www.tracktion.com
7
8 Tracktion Engine uses a GPL/commercial licence - see LICENCE.md for details.
9*/
10
11namespace tracktion { inline namespace engine
12{
13
16{
17public:
19 ~MidiOutputDevice() override;
20
21 juce::String openDevice() override;
22 void closeDevice() override;
23
24 void setEnabled (bool) override;
25 bool isMidi() const override { return true; }
26
27 virtual MidiOutputDeviceInstance* createInstance (EditPlaybackContext&);
28
29 //==============================================================================
30 juce::String prepareToPlay (Edit*, TimePosition);
31 bool start();
32 void stop();
33
34 static void setControllerOffMessagesSent (Engine&, bool);
35 static bool getControllerOffMessagesSent (Engine&);
36
37 juce::String getNameForMidiNoteNumber (int note, int midiChannel, bool useSharp = true) const;
38
39 bool isConnectedToExternalController() const { return externalController != nullptr; }
40
43 void removeExternalController (ExternalController*);
44
45 //==============================================================================
46 void updateMidiTC (Edit*);
47
48 void setSendingMMC (bool);
49 bool isSendingMMC() const noexcept { return sendingMMC; }
50 bool isSendingClock() const noexcept { return sendMidiClock; }
51 void setSendingClock (bool);
52
53 bool isSendingTimecode() const noexcept { return sendTimecode; }
54 void flipSendingTimecode();
55
56 void setSendControllerMidiClock (bool b) noexcept { sendControllerMidiClock = b; }
57 bool isSendingControllerMidiClock() const noexcept { return sendControllerMidiClock; }
58
59 //==============================================================================
60 void fireMessage (const juce::MidiMessage&);
61 void sendNoteOffMessages();
62
63 TimeDuration getDeviceDelay() const noexcept;
64
65 int getPreDelayMs() const noexcept { return preDelayMillisecs; }
66 void setPreDelayMs (int);
67
68 //==============================================================================
69 juce::StringArray getProgramSets() const;
70 int getCurrentSetIndex() const;
71 void setCurrentProgramSet (const juce::String&);
72 juce::String getCurrentProgramSet() const { return programNameSet; }
73 juce::String getProgramName (int programNumber, int bank);
74 bool canEditProgramSet (int index) const;
75 bool canDeleteProgramSet (int index) const;
76
77 juce::String getBankName (int bank);
78 int getBankID (int bank);
79 bool areMidiPatchesZeroBased();
80
81 MidiProgramManager& getMidiProgramManager() const { return engine.getMidiProgramManager(); }
82
83protected:
84 //==============================================================================
85 friend class MidiOutputDeviceInstance;
86
87 virtual void sendMessageNow (const juce::MidiMessage& message);
88
89 void loadProps();
90 void saveProps();
91
92 juce::MidiDeviceInfo deviceInfo;
93 int preDelayMillisecs = 0, audioAdjustmentDelay = 0;
95 std::unique_ptr<MidiClockGenerator> midiClockGenerator;
96 bool sendTimecode = false, sendMidiClock = false;
97 bool playing = false;
98 juce::String programNameSet;
99
100 double sampleRate = 0;
101
103 bool sendingMMC = false;
104 bool sendControllerMidiClock = false;
105 bool softDevice = false;
106 ExternalController* externalController = nullptr;
107
108 juce::BigInteger midiNotesOn, channelsUsed;
109 int sustain = 0;
110
111 MidiMessageArray midiMessages;
112
113 juce::CriticalSection noteOnLock;
114};
115
116//==============================================================================
119{
120public:
121 SoftwareMidiOutputDevice (Engine& e, const juce::String& deviceName)
122 : MidiOutputDevice (e, { deviceName, juce::String() })
123 {
124 softDevice = true;
125 }
126};
127
128//==============================================================================
131{
132public:
135
136 juce::String prepareToPlay (TimePosition start, bool shouldSendMidiTC);
137 bool start();
138 void stop();
139
140 MidiOutputDevice& getMidiOutput() const noexcept { return static_cast<MidiOutputDevice&> (owner); }
141
142 void mergeInMidiMessages (const MidiMessageArray&, TimePosition editTime);
143 void addMidiClockMessagesToCurrentBlock (bool isPlaying, bool isDragging, TimeRange streamTime);
144 MidiMessageArray& getPendingMessages() { return midiMessages; }
145
146 // For MidiOutputDevices that aren't connected to a physical piece of hardware,
147 // they should handle sending midi messages to their logical device now
148 // and clear the input buffer
149 virtual bool sendMessages (MidiMessageArray&, TimePosition /*editTime*/) { return false; }
150
151private:
153 std::unique_ptr<MidiClockGenerator> midiClockGenerator;
154
155 double sampleRate = 0, audioAdjustmentDelay = 0;
156 bool playing = false, shouldSendMidiTimecode = false;
157
158 MidiMessageArray midiMessages;
159
161};
162
163}} // namespace tracktion { inline namespace engine
The Tracktion Edit class!
The Engine is the central class for all tracktion sessions.
MidiProgramManager & getMidiProgramManager() const
Returns the MidiProgramManager instance that handles MIDI banks, programs, sets or presets.
Acts as a holder for a ControlSurface object.
void setExternalController(ExternalController *)
sets the external controller messages are coming from
Base class for audio or midi output devices, to which a track's output can be sent.
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
Represents a duration in real-life time.
Represents a position in real-life time.