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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_HostedMidiInputDeviceNode.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
14HostedMidiInputDeviceNode::HostedMidiInputDeviceNode (InputDeviceInstance& idi, MidiInputDevice&, MidiMessageArray::MPESourceID msi,
16 : TracktionEngineNode (ps),
17 instance (idi),
18 midiSourceID (msi)
19{
20}
21
22HostedMidiInputDeviceNode::~HostedMidiInputDeviceNode()
23{
24 instance.removeConsumer (this);
25}
26
27tracktion::graph::NodeProperties HostedMidiInputDeviceNode::getNodeProperties()
28{
30 props.hasMidi = true;
31 return props;
32}
33
34void HostedMidiInputDeviceNode::prepareToPlay (const tracktion::graph::PlaybackInitialisationInfo& info)
35{
36 sampleRate = info.sampleRate;
37
38 instance.addConsumer (this);
39}
40
41bool HostedMidiInputDeviceNode::isReadyToProcess()
42{
43 return true;
44}
45
46void HostedMidiInputDeviceNode::process (ProcessContext& pc)
47{
48 SCOPED_REALTIME_CHECK
49
50 const auto localTimeRange = tracktion::graph::sampleToTime (pc.referenceSampleRange, sampleRate).withStart (0.0);
51 auto& destMidi = pc.buffers.midi;
52
54
55 for (auto m : incomingMessages)
56 if (localTimeRange.contains (m.getTimeStamp()))
57 destMidi.add (m);
58
59 // Subtract time from messages and trim any negative
60 incomingMessages.addToTimestamps (-localTimeRange.getLength());
61
62 for (int i = incomingMessages.size(); --i >= 0;)
63 if (incomingMessages[i].getTimeStamp() < 0.0)
64 incomingMessages.remove (i);
65}
66
67void HostedMidiInputDeviceNode::handleIncomingMidiMessage (const juce::MidiMessage& message)
68{
69 const auto globalStreamTime = instance.edit.engine.getDeviceManager().getCurrentStreamTime();
70
71 // Timestamps will have global stream times so convert these to buffer offsets
73 incomingMessages.addMidiMessage (message, message.getTimeStamp() - globalStreamTime, midiSourceID);
74}
75
76}} // namespace tracktion { inline namespace engine
double getTimeStamp() const noexcept
Struct to describe a single iteration of a process call.
Determines how this block releates to other previous render blocks and if the play head has jumped in...
Holds the state of a process call.
Holds some really basic properties of a node.
Passed into Nodes when they are being initialised, to give them useful contextual information that th...