|
1 | 1 | /* |
2 | 2 | * mTroll MIDI Controller |
3 | | - * Copyright (C) 2007-2015,2018,2020-2023 Sean Echevarria |
| 3 | + * Copyright (C) 2007-2015,2018,2020-2024 Sean Echevarria |
4 | 4 | * |
5 | 5 | * This file is part of mTroll. |
6 | 6 | * |
|
63 | 63 | #include "ControllerInputMonitor.h" |
64 | 64 | #include "RepeatingMomentaryPatch.h" |
65 | 65 | #include "RepeatingTogglePatch.h" |
| 66 | +#include "SleepRandomCommand.h" |
66 | 67 |
|
67 | 68 |
|
68 | 69 | #ifdef _MSC_VER |
|
73 | 74 | static PatchBank::PatchState GetLoadState(const std::string & tmpLoad); |
74 | 75 | static PatchBank::PatchSyncState GetSyncState(const std::string & tmpLoad); |
75 | 76 | static PatchBank::SecondFunctionOperation GetSecondFuncOp(const std::string & tmp); |
| 77 | +static void ReadTwoIntValues(std::string tmp, int & val1, int & val2); |
76 | 78 |
|
77 | 79 | EngineLoader::EngineLoader(ITrollApplication * app, |
78 | 80 | IMidiOutGenerator * midiOutGenerator, |
@@ -896,6 +898,29 @@ EngineLoader::LoadPatches(TiXmlElement * pElem) |
896 | 898 | } |
897 | 899 | continue; |
898 | 900 | } |
| 901 | + else if (patchElement == "SleepRandom") |
| 902 | + { |
| 903 | + std::string sleepAmtStr; |
| 904 | + if (childElem->GetText()) |
| 905 | + sleepAmtStr = childElem->GetText(); |
| 906 | + int sleepMinAmt = 0; |
| 907 | + int sleepMaxAmt = 0; |
| 908 | + ::ReadTwoIntValues(sleepAmtStr, sleepMinAmt, sleepMaxAmt); |
| 909 | + if (0 < sleepMinAmt && 0 < sleepMaxAmt) |
| 910 | + { |
| 911 | + if (group == "B") |
| 912 | + cmds2.push_back(std::make_shared<SleepRandomCommand>(sleepMinAmt, sleepMaxAmt)); |
| 913 | + else |
| 914 | + cmds.push_back(std::make_shared<SleepRandomCommand>(sleepMinAmt, sleepMaxAmt)); |
| 915 | + } |
| 916 | + else if (mTraceDisplay) |
| 917 | + { |
| 918 | + std::strstream traceMsg; |
| 919 | + traceMsg << "Error loading config file: no (or invalid) times specified in SleepRandom in patch " << patchName << '\n' << std::ends; |
| 920 | + mTraceDisplay->Trace(std::string(traceMsg.str())); |
| 921 | + } |
| 922 | + continue; |
| 923 | + } |
899 | 924 | else if (patchElement == "localExpr") |
900 | 925 | continue; |
901 | 926 | else if (patchElement == "globalExpr") |
@@ -3008,3 +3033,23 @@ GetSecondFuncOp(const std::string & secFuncOp) |
3008 | 3033 | else |
3009 | 3034 | return PatchBank::sfoManual; |
3010 | 3035 | } |
| 3036 | + |
| 3037 | +void |
| 3038 | +ReadTwoIntValues(std::string tmp, int & val1, int & val2) |
| 3039 | +{ |
| 3040 | + if (tmp.empty()) |
| 3041 | + return; |
| 3042 | + |
| 3043 | + int tokenPos = tmp.find_first_of(" ,:;"); |
| 3044 | + if (std::string::npos == tokenPos) |
| 3045 | + return; |
| 3046 | + |
| 3047 | + val1 = ::atoi(tmp.c_str()); |
| 3048 | + |
| 3049 | + tmp = tmp.substr(tokenPos + 1); |
| 3050 | + while ((tokenPos = tmp.find_first_of(" ,:;")) != std::string::npos) |
| 3051 | + tmp = tmp.substr(tokenPos + 1); |
| 3052 | + |
| 3053 | + if (!tmp.empty()) |
| 3054 | + val2 = ::atoi(tmp.c_str()); |
| 3055 | +} |
0 commit comments