MCPcopy Create free account
hub / github.com/VCVRack/Rack / onMessage

Method onMessage

src/midi.cpp:52–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50}
51
52void InputDevice::onMessage(const Message& message) {
53 for (Input* input : subscribed) {
54 // Filter channel if message is not a system MIDI message
55 if (message.getStatus() != 0xf && input->channel >= 0 && message.getChannel() != input->channel)
56 continue;
57
58 // We're probably in the MIDI driver's thread, so set the Rack context.
59 contextSet(input->context);
60
61 // Set timestamp to now if unset
62 if (message.getFrame() < 0) {
63 Message msg = message;
64 double deltaTime = system::getTime() - APP->engine->getBlockTime();
65 int64_t deltaFrames = std::floor(deltaTime * APP->engine->getSampleRate());
66 // Delay message by current Engine block size
67 deltaFrames += APP->engine->getBlockFrames();
68 msg.setFrame(APP->engine->getBlockFrame() + deltaFrames);
69 // Pass message to Input port
70 input->onMessage(msg);
71 }
72 else {
73 // Pass message to Input port
74 input->onMessage(message);
75 }
76 }
77}
78
79void OutputDevice::subscribe(Output* output) {
80 subscribed.insert(output);

Callers 1

midiInputCallbackMethod · 0.45

Calls 13

contextSetFunction · 0.85
getTimeFunction · 0.85
floorFunction · 0.85
getStatusMethod · 0.80
getBlockTimeMethod · 0.80
getBlockFramesMethod · 0.80
getBlockFrameMethod · 0.80
getChannelMethod · 0.45
getFrameMethod · 0.45
getSampleRateMethod · 0.45
setFrameMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected