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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_TrackMidiInputDeviceNode.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
11
12namespace tracktion { inline namespace engine
13{
14
15TrackMidiInputDeviceNode::TrackMidiInputDeviceNode (MidiInputDevice& owner, std::unique_ptr<Node> inputNode, ProcessState& ps,
16 bool copyInputsToOutputs_)
17 : TracktionEngineNode (ps),
18 midiInputDevice (owner),
19 input (std::move (inputNode)),
20 copyInputsToOutputs (copyInputsToOutputs_)
21{
22 jassert (midiInputDevice.isTrackDevice());
23
24 setOptimisations ({ tracktion::graph::ClearBuffers::yes,
25 copyInputsToOutputs ? tracktion::graph::AllocateAudioBuffer::no
26 : tracktion::graph::AllocateAudioBuffer::yes });
27}
28
29std::vector<tracktion::graph::Node*> TrackMidiInputDeviceNode::getDirectInputNodes()
30{
31 return { input.get() };
32}
33
34tracktion::graph::NodeProperties TrackMidiInputDeviceNode::getNodeProperties()
35{
36 return input->getNodeProperties();
37}
38
39void TrackMidiInputDeviceNode::prepareToPlay (const tracktion::graph::PlaybackInitialisationInfo& info)
40{
41 offsetSeconds = tracktion::graph::sampleToTime (info.blockSize, info.sampleRate);
42}
43
44bool TrackMidiInputDeviceNode::isReadyToProcess()
45{
46 return input->hasProcessed();
47}
48
49void TrackMidiInputDeviceNode::process (ProcessContext& pc)
50{
51 SCOPED_REALTIME_CHECK
52
53 // Pass on input to output
54 auto sourceBuffers = input->getProcessedOutput();
55
56 if (copyInputsToOutputs)
57 {
58 setAudioOutput (input.get(), sourceBuffers.audio);
59 pc.buffers.midi.copyFrom (sourceBuffers.midi);
60 }
61
62 const double midiStreamTime = tracktion::graph::sampleToTime (getReferenceSampleRange().getStart(), getSampleRate())
63 - midiInputDevice.getAdjustSecs();
64
65 // And pass MIDI to device
66 for (auto& m : sourceBuffers.midi)
67 midiInputDevice.handleIncomingMidiMessage (nullptr, juce::MidiMessage (m, midiStreamTime + m.getTimeStamp()));
68}
69
70}} // namespace tracktion { inline namespace engine
Struct to describe a single iteration of a process call.
#define jassert(expression)
T move(T... args)
Holds some really basic properties of a node.
Passed into Nodes when they are being initialised, to give them useful contextual information that th...