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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_MidiInputDevice.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
17 private juce::Timer,
18 private juce::MidiKeyboardStateListener
19{
20public:
22 ~MidiInputDevice() override;
23
24 virtual juce::String openDevice() = 0;
25 virtual void closeDevice() = 0;
26
27 void setEnabled (bool) override;
28 bool isMidi() const override { return true; }
29
30 MidiChannel getChannelToUse() const noexcept { return channelToUse; }
31 void setChannelToUse (int);
32
33 int getProgramToUse() const noexcept { return programToUse; }
34 void setProgramToUse (int);
35
36 void setBankToUse (int);
37 int getBankToUse() const { return bankToUse; }
38
39 void setChannelAllowed (int midiChannel, bool);
40 bool isChannelAllowed (int midiChannel) const { return ! disallowedChannels[midiChannel - 1]; }
41
43 {
44 int startNote = 0, endNote = 128;
45
46 void set (int start, int end)
47 {
48 startNote = std::min (127, std::max (0, start));
49 endNote = std::min (128, std::max (startNote + 1, end));
50 }
51
52 bool isAllNotes() const { return startNote == 0 && endNote == 128; }
53 };
54
55 void setNoteFilterRange (NoteFilterRange);
56 NoteFilterRange getNoteFilterRange() const { return noteFilterRange; }
57
58 void setOverridingNoteVelocities (bool);
59 bool isOverridingNoteVelocities() const { return overrideNoteVels; }
60
61 void setManualAdjustmentMs (double);
62 double getManualAdjustmentMs() const { return manualAdjustMs; }
63
64 void setMinimumLengthMs (double);
65 double getMinimumLengthMs() const { return minimumLengthMs; }
66
68 bool isMPEDevice() const;
69
70 //==============================================================================
71 void masterTimeUpdate (double time) override;
72 void connectionStateChanged();
73
78
79 //==============================================================================
80 void addInstance (MidiInputDeviceInstanceBase*);
81 void removeInstance (MidiInputDeviceInstanceBase*);
82
83 virtual void loadProps() = 0;
84
85 bool mergeRecordings = true;
86 bool recordingEnabled = true;
87 bool replaceExistingClips = false;
88 bool recordToNoteAutomation = false;
89 QuantisationType quantisation;
90
91 enum class MergeMode { always, never, optional };
92
93 Clip* addMidiAsTransaction (Edit&, EditItemID targetID,
94 Clip* takeClip, juce::MidiMessageSequence,
95 TimeRange markedRange, MergeMode, MidiChannel);
96
97 juce::MidiKeyboardState keyboardState;
98
99 void handleIncomingMidiMessage (juce::MidiInput*, const juce::MidiMessage&) override;
100 virtual void handleIncomingMidiMessage (const juce::MidiMessage&) = 0;
101
102 RetrospectiveMidiBuffer* getRetrospectiveMidiBuffer() const { return retrospectiveBuffer.get(); }
103 void updateRetrospectiveBufferLength (double length) override;
104 double getAdjustSecs() const { return adjustSecs; }
105
106 juce::Array<AudioTrack*> getDestinationTracks();
107
108 MidiChannel getMidiChannelFor (int rawChannelNumber) const;
109 MidiMessageArray::MPESourceID getMPESourceID() const { return midiSourceID; }
110
111 //==============================================================================
114 {
115 struct Listener
116 {
117 virtual ~Listener() {}
118
120 virtual void midiKeyStateChanged (AudioTrack*, const juce::Array<int>& notesOn, const juce::Array<int>& vels, const juce::Array<int>& notesOff) = 0;
121 };
122
124
125 private:
128 };
129
130protected:
131 class MidiEventSnifferNode;
132 class NoteDispatcher;
133
134 std::atomic<double> adjustSecs { 0 };
135 double manualAdjustMs = 0;
136 double minimumLengthMs = 0;
137 bool overrideNoteVels = false, eventReceivedFromDevice = false;
138 juce::BigInteger disallowedChannels;
139 MidiChannel channelToUse;
140 int programToUse = 0;
141 int bankToUse = 0;
142 NoteFilterRange noteFilterRange;
143
144 MidiMessageArray::MPESourceID midiSourceID = MidiMessageArray::createUniqueMPESourceID();
145
146 std::unique_ptr<NoteDispatcher> noteDispatcher;
147 std::vector<double> lastNoteOns;
148
149 juce::CriticalSection noteLock;
150 bool keysDown[128], keysUp[128];
151 uint8_t keyDownVelocities[128];
153
154 juce::CriticalSection instanceLock;
157
158 void handleNoteOn (juce::MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
159 void handleNoteOff (juce::MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity) override;
160
161 void timerCallback() override;
162
163 void sendNoteOnToMidiKeyListeners (juce::MidiMessage&);
164
165 void loadMidiProps (const juce::XmlElement*);
166 void saveMidiProps (juce::XmlElement&);
167
168 void sendMessageToInstances (const juce::MidiMessage&);
169
171};
172
173}} // namespace tracktion { inline namespace engine
The Engine is the central class for all tracktion sessions.
Represents an input device.
void masterTimeUpdate(double time) override
This is a bit of a hack but allows the time for MIDI devices to be set through the base class interfa...
bool handleIncomingMessage(juce::MidiMessage &)
Updates the timestamp of the message and handles sending it out to listeners.
bool isMPEDevice() const
Returns true if the given device is an MPE device and so should always record incoming MIDI to Note E...
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)
T max(T... args)
T min(T... args)
typedef uint8_t
Represents a MIDI channel 1-16, and also contains extra ID bits to encode info about the event's orig...
virtual void midiKeyStateChanged(AudioTrack *, const juce::Array< int > &notesOn, const juce::Array< int > &vels, const juce::Array< int > &notesOff)=0
Callback to indicate notes have been played for the given track.
Gets notified (lazily, not in real-time) when any MidiInputDevice's key's state changes.