Skip to content

Commit

Permalink
Add temp variable support to MIDI condition
Browse files Browse the repository at this point in the history
  • Loading branch information
WarmUpTill committed Nov 26, 2023
1 parent 3805aae commit b525eb7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 2 deletions.
6 changes: 6 additions & 0 deletions data/locale/en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
33 changes: 31 additions & 2 deletions src/macro-external/midi/macro-condition-midi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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<MacroConditionMidi> entryData)
: QWidget(parent),
Expand Down
3 changes: 3 additions & 0 deletions src/macro-external/midi/macro-condition-midi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
Expand Down

0 comments on commit b525eb7

Please sign in to comment.