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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_VirtualMidiInputDevice.cpp
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
25
26//==============================================================================
27VirtualMidiInputDevice::VirtualMidiInputDevice (Engine& e, juce::String deviceName, DeviceType devType,
28 juce::String deviceIDToUse, bool isAllMIDIIns)
29 : MidiInputDevice (e, devType == trackMidiDevice ? TRANS("Track MIDI Input")
30 : TRANS("Virtual MIDI Input"),
31 deviceName, deviceIDToUse),
32 useAllInputs (isAllMIDIIns),
33 deviceType (devType)
34{
35 if (isAllMIDIIns)
36 defaultMonitorMode = MonitorMode::on;
37
38 loadProps();
39}
40
41VirtualMidiInputDevice::~VirtualMidiInputDevice()
42{
43 notifyListenersOfDeletion();
44 closeDevice();
45}
46
48{
49 if (! isTrackDevice() && retrospectiveBuffer == nullptr)
50 retrospectiveBuffer = std::make_unique<RetrospectiveMidiBuffer> (c.edit.engine);
51
52 return new VirtualMidiInputDeviceInstance (*this, c);
53}
54
55juce::String VirtualMidiInputDevice::openDevice() { return {}; }
56void VirtualMidiInputDevice::closeDevice() {}
57
58void VirtualMidiInputDevice::setEnabled (bool b)
59{
60 if (b && isTrackDevice())
61 loadProps();
62
63 MidiInputDevice::setEnabled (b);
64}
65
66void VirtualMidiInputDevice::setMIDIInputSourceDevices (const juce::StringArray deviceIDs)
67{
68 if (deviceIDs != inputDeviceIDs)
69 {
70 inputDeviceIDs = deviceIDs;
71 changed();
72 saveProps();
73 }
74}
75
76void VirtualMidiInputDevice::toggleMIDIInputSourceDevice (const juce::String& deviceIDToToggle)
77{
78 auto devices = inputDeviceIDs;
79
80 if (devices.contains (deviceIDToToggle))
81 devices.removeString (deviceIDToToggle);
82 else
83 devices.add (deviceIDToToggle);
84
85 setMIDIInputSourceDevices (devices);
86}
87
88void VirtualMidiInputDevice::loadProps()
89{
90 juce::String propName = isTrackDevice() ? "TRACKTION_TRACK_DEVICE" : getName();
91
92 auto n = engine.getPropertyStorage().getXmlPropertyItem (SettingID::virtualmidiin, propName);
93
94 if (! isTrackDevice() && n != nullptr)
95 {
96 inputDeviceIDs.addTokens (n->getStringAttribute ("inputDevices"), ";", {});
97 useAllInputs = n->getBoolAttribute ("useAllInputs", false);
98 }
99
100 MidiInputDevice::loadMidiProps (n.get());
101}
102
103void VirtualMidiInputDevice::saveProps()
104{
105 juce::XmlElement n ("SETTINGS");
106
107 n.setAttribute ("inputDevices", inputDeviceIDs.joinIntoString (";"));
108 n.setAttribute ("useAllInputs", useAllInputs);
109 MidiInputDevice::saveMidiProps (n);
110
111 juce::String propName = isTrackDevice() ? "TRACKTION_TRACK_DEVICE" : getName();
112
113 engine.getPropertyStorage().setXmlPropertyItem (SettingID::virtualmidiin, propName, n);
114}
115
116void VirtualMidiInputDevice::handleIncomingMidiMessage (const juce::MidiMessage& m)
117{
118 auto message = m;
119
120 if (handleIncomingMessage (message))
121 sendMessageToInstances (message);
122}
123
124void VirtualMidiInputDevice::handleMessageFromPhysicalDevice (MidiInputDevice& dev, const juce::MidiMessage& m)
125{
126 if (useAllInputs || inputDeviceIDs.contains (dev.getDeviceID()))
127 handleIncomingMidiMessage (m);
128}
129
131{
132 if (getDeviceType() == trackMidiDevice)
133 return getAlias() + " (" + getType() + ")";
134
136}
137
138}} // namespace tracktion { inline namespace engine
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
bool contains(StringRef stringToLookFor, bool ignoreCase=false) const
void removeString(StringRef stringToRemove, bool ignoreCase=false)
int addTokens(StringRef stringToTokenise, bool preserveQuotedStrings)
The Engine is the central class for all tracktion sessions.
PropertyStorage & getPropertyStorage() const
Returns the PropertyStorage user settings customisable XML file.
An instance of an InputDevice that's available to an Edit.
InputDevice & owner
The state of this instance.
juce::String getAlias() const
the alias is the name shown in the draggable input device components
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
bool handleIncomingMessage(juce::MidiMessage &)
Updates the timestamp of the message and handles sending it out to listeners.
virtual void changed()
This should be called to send a change notification to any SelectableListeners that are registered wi...
InputDeviceInstance * createInstance(EditPlaybackContext &) override
Creates an instance to use for a given playback context.
juce::String getSelectableDescription() override
Subclasses must return a description of what they are.
T is_pointer_v
#define TRANS(stringLiteral)
#define JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(className)