From b525eb7a0e541f7ec66d4f60a076a1ec996e34d1 Mon Sep 17 00:00:00 2001 From: WarmUpTill Date: Sun, 26 Nov 2023 00:18:30 +0100 Subject: [PATCH] Add temp variable support to MIDI condition --- data/locale/en-US.ini | 6 ++++ .../midi/macro-condition-midi.cpp | 33 +++++++++++++++++-- .../midi/macro-condition-midi.hpp | 3 ++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/data/locale/en-US.ini b/data/locale/en-US.ini index 5239f049b..66775f5e8 100644 --- a/data/locale/en-US.ini +++ b/data/locale/en-US.ini @@ -1442,6 +1442,12 @@ AdvSceneSwitcher.tempVar.date.minute="Minute" AdvSceneSwitcher.tempVar.date.second="Second" AdvSceneSwitcher.tempVar.date.dayOfWeek="Day of week" +AdvSceneSwitcher.tempVar.midi.type="Message type" +AdvSceneSwitcher.tempVar.midi.channel="Channel" +AdvSceneSwitcher.tempVar.midi.note="Note" +AdvSceneSwitcher.tempVar.midi.value1="Value 1" +AdvSceneSwitcher.tempVar.midi.value2="Value 2" + AdvSceneSwitcher.selectScene="--select scene--" AdvSceneSwitcher.selectPreviousScene="Previous Scene" AdvSceneSwitcher.selectCurrentScene="Current Scene" diff --git a/src/macro-external/midi/macro-condition-midi.cpp b/src/macro-external/midi/macro-condition-midi.cpp index bcdd2211b..290eddce1 100644 --- a/src/macro-external/midi/macro-condition-midi.cpp +++ b/src/macro-external/midi/macro-condition-midi.cpp @@ -19,8 +19,7 @@ bool MacroConditionMidi::CheckCondition() for (const auto &m : *messages) { if (m.Matches(_message)) { - SetVariableValue(std::to_string(m.Note()) + " " + - std::to_string(m.Value())); + SetVariableValues(m); return true; } } @@ -49,6 +48,36 @@ std::string MacroConditionMidi::GetShortDesc() const return _device.Name(); } +void MacroConditionMidi::SetupTempVars() +{ + MacroCondition::SetupTempVars(); + AddTempvar("type", + obs_module_text("AdvSceneSwitcher.tempVar.midi.type")); + AddTempvar("channel", + obs_module_text("AdvSceneSwitcher.tempVar.midi.channel")); + AddTempvar("note", + obs_module_text("AdvSceneSwitcher.tempVar.midi.note")); + AddTempvar("value1", + obs_module_text("AdvSceneSwitcher.tempVar.midi.value1")); + AddTempvar("value2", + obs_module_text("AdvSceneSwitcher.tempVar.midi.value2")); +} + +void MacroConditionMidi::SetVariableValues(const MidiMessage &m) +{ + SetVariableValue(std::to_string(m.Note()) + " " + + std::to_string(m.Value())); + SetTempVarValue("type", m.MidiTypeToString(m.Type())); + SetTempVarValue("channel", std::to_string(m.Channel())); + try { + SetTempVarValue("note", + GetAllNotes().at(m.Note()).toStdString()); + } catch (...) { + } + SetTempVarValue("value1", std::to_string(m.Note())); + SetTempVarValue("value2", std::to_string(m.Value())); +} + MacroConditionMidiEdit::MacroConditionMidiEdit( QWidget *parent, std::shared_ptr entryData) : QWidget(parent), diff --git a/src/macro-external/midi/macro-condition-midi.hpp b/src/macro-external/midi/macro-condition-midi.hpp index e916b4e84..bfedc3e9b 100644 --- a/src/macro-external/midi/macro-condition-midi.hpp +++ b/src/macro-external/midi/macro-condition-midi.hpp @@ -24,6 +24,9 @@ class MacroConditionMidi : public MacroCondition { MidiMessage _message; private: + void SetupTempVars(); + void SetVariableValues(const MidiMessage &); + static bool _registered; static const std::string id; };