MayaFlux 0.2.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ extract_value()

double MayaFlux::Nodes::Input::MIDINode::extract_value ( const Core::InputValue value)
overrideprotectedvirtual

Extract a scalar value from an InputValue.

Parameters
valueThe input value to extract from
Returns
Scalar value for smoothing/output

Override in derived classes for specific input types. Default handles SCALAR and MIDI CC values.

Reimplemented from MayaFlux::Nodes::Input::InputNode.

Definition at line 10 of file MIDINode.cpp.

11{
12 if (value.type != Core::InputValue::Type::MIDI) {
13 return m_last_output;
14 }
15
16 const auto& midi = value.as_midi();
18
19 if (!matches_filters(value)) {
20 return m_last_output;
21 }
22
23 uint8_t msg_type = midi.type();
24
25 switch (msg_type) {
26 case 0x90:
28 return m_last_output;
29 }
30 // Velocity 0 is actually Note Off
31 if (midi.data2 == 0 && m_config.note_on_only) {
32 return m_last_output;
33 }
34
36 ? m_config.velocity_curve(midi.data2)
37 : static_cast<double>(midi.data2) / 127.0;
38
39 case 0x80: // Note Off
41 return m_last_output;
42 }
43 return 0.0;
44
45 case 0xB0: { // Control Change
46 double value = static_cast<double>(midi.data2) / 127.0;
47 return m_config.invert_cc ? (1.0 - value) : value;
48 }
49
50 case 0xE0: {
51 // Pitch bend is 14-bit: combine data1 and data2
52 int bend_value = (midi.data2 << 7) | midi.data1;
53 return (static_cast<double>(bend_value) - 8192.0) / 8192.0;
54 }
55
56 case 0xD0: // Channel Pressure (Aftertouch)
57 case 0xC0: // Program Change
58 default:
59 return static_cast<double>(midi.data1) / 127.0;
60 }
61}
std::optional< Core::InputValue::MIDIMessage > m_last_midi_message
Definition MIDINode.hpp:184
bool matches_filters(const Core::InputValue &value) const
Definition MIDINode.cpp:63
double m_last_output
The most recent sample value generated by this oscillator.
Definition Node.hpp:377
@ MIDI
Structured MIDI message.
std::function< double(uint8_t)> velocity_curve
Custom velocity mapping.
Definition MIDINode.hpp:19
bool invert_cc
Flip CC 127→0.
Definition MIDINode.hpp:20
bool note_on_only
Only respond to Note On.
Definition MIDINode.hpp:16
bool note_off_only
Only respond to Note Off.
Definition MIDINode.hpp:17

References MayaFlux::Core::InputValue::as_midi(), MayaFlux::Nodes::Input::MIDIConfig::invert_cc, m_config, m_last_midi_message, MayaFlux::Nodes::Node::m_last_output, matches_filters(), MayaFlux::Core::InputValue::MIDI, MayaFlux::Nodes::Input::MIDIConfig::note_off_only, MayaFlux::Nodes::Input::MIDIConfig::note_on_only, MayaFlux::Core::InputValue::MIDIMessage::type(), MayaFlux::Core::InputValue::type, and MayaFlux::Nodes::Input::MIDIConfig::velocity_curve.

+ Here is the call graph for this function: