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

« « « Anklang Documentation
Loading...
Searching...
No Matches
tracktion_MidiOutputDeviceInstanceInjectingNode.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
14//==============================================================================
15//==============================================================================
16MidiOutputDeviceInstanceInjectingNode::MidiOutputDeviceInstanceInjectingNode (MidiOutputDeviceInstance& instance,
18 tracktion::graph::PlayHead& playHeadToUse)
19 : deviceInstance (instance), input (std::move (inputNode)), playHead (playHeadToUse)
20{
21}
22
23//==============================================================================
24tracktion::graph::NodeProperties MidiOutputDeviceInstanceInjectingNode::getNodeProperties()
25{
26 auto props = input->getNodeProperties();
27 props.numberOfChannels = 0;
28 props.nodeID = 0;
29
30 return props;
31}
32
33std::vector<tracktion::graph::Node*> MidiOutputDeviceInstanceInjectingNode::getDirectInputNodes()
34{
35 return { input.get() };
36}
37
38void MidiOutputDeviceInstanceInjectingNode::prepareToPlay (const tracktion::graph::PlaybackInitialisationInfo& info)
39{
40 sampleRate = info.sampleRate;
41}
42
43bool MidiOutputDeviceInstanceInjectingNode::isReadyToProcess()
44{
45 return input->hasProcessed();
46}
47
48void MidiOutputDeviceInstanceInjectingNode::process (ProcessContext& pc)
49{
50 auto sourceBuffers = input->getProcessedOutput();
51
52 // Block the audio input from reaching the output by not copying
53 pc.buffers.midi.copyFrom (sourceBuffers.midi);
54
55 const auto timelineSampleRange = referenceSampleRangeToSplitTimelineRange (playHead, pc.referenceSampleRange);
56 assert (! timelineSampleRange.isSplit);
57 const auto editTimeRange = tracktion::timeRangeFromSamples (timelineSampleRange.timelineRange1, sampleRate);
58
59 // Add MIDI clock for the current time to the device to be dispatched
60 deviceInstance.addMidiClockMessagesToCurrentBlock (playHead.isPlaying(), playHead.isUserDragging(), editTimeRange);
61
62 if (sourceBuffers.midi.isEmpty() && ! sourceBuffers.midi.isAllNotesOff)
63 return;
64
65 // Merge in the MIDI from the current block to the device to be dispatched
66 deviceInstance.mergeInMidiMessages (sourceBuffers.midi, editTimeRange.getStart());
67}
68
69}} // namespace tracktion { inline namespace engine
assert
Struct to describe a single iteration of a process call.
Converts a monotonically increasing reference range in to a timeline range.
T move(T... args)
SplitTimelineRange referenceSampleRangeToSplitTimelineRange(const PlayHead &playHead, juce::Range< int64_t > referenceSampleRange)
Converts a reference sample range to a TimelinePositionWindow which could have two time ranges if the...
Holds some really basic properties of a node.
Passed into Nodes when they are being initialised, to give them useful contextual information that th...