/[svn]/linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3587 by schoenebeck, Sat Aug 31 12:08:49 2019 UTC revision 3588 by schoenebeck, Sun Sep 1 16:06:48 2019 UTC
# Line 42  namespace LinuxSampler { Line 42  namespace LinuxSampler {
42              return false;              return false;
43      }      }
44    
45        void InstrumentScriptVMFunction_play_note::checkArgs(VMFnArgs* args,
46                                                             std::function<void(String)> err,
47                                                             std::function<void(String)> wrn)
48        {
49            // super class checks
50            Super::checkArgs(args, err, wrn);
51    
52            // own checks ...
53            if (args->arg(0)->isConstExpr()) {
54                vmint note = args->arg(0)->asNumber()->evalCastInt();
55                if (note < 0 || note > 127) {
56                    err("MIDI note number value for argument 1 must be between 0..127");
57                    return;
58                }
59            }
60            if (args->argsCount() >= 2 && args->arg(1)->isConstExpr()) {
61                vmint velocity = args->arg(1)->asNumber()->evalCastInt();
62                if (velocity < 0 || velocity > 127) {
63                    err("MIDI velocity value for argument 2 must be between 0..127");
64                    return;
65                }
66            }
67            if (args->argsCount() >= 3 && args->arg(2)->isConstExpr()) {
68                VMNumberExpr* argSampleOffset = args->arg(2)->asNumber();
69                vmint sampleoffset =
70                    (argSampleOffset->unitType()) ?
71                        argSampleOffset->evalCastInt(VM_MICRO) :
72                        argSampleOffset->evalCastInt();
73                if (sampleoffset < -1) {
74                    err("Sample offset of argument 3 may not be less than -1");
75                    return;
76                }
77            }
78            if (args->argsCount() >= 4 && args->arg(3)->isConstExpr()) {
79                VMNumberExpr* argDuration = args->arg(3)->asNumber();
80                vmint duration =
81                    (argDuration->unitType()) ?
82                        argDuration->evalCastInt(VM_MICRO) :
83                        argDuration->evalCastInt();
84                if (duration < -2) {
85                    err("Argument 4 must be a duration value of at least -2 or higher");
86                    return;
87                }
88            }
89        }
90    
91      VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) {
92          vmint note = args->arg(0)->asInt()->evalInt();          vmint note = args->arg(0)->asInt()->evalInt();
93          vmint velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;          vmint velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;
# Line 232  namespace LinuxSampler { Line 278  namespace LinuxSampler {
278          return type == INT_EXPR || type == INT_ARR_EXPR;          return type == INT_EXPR || type == INT_ARR_EXPR;
279      }      }
280    
281        void InstrumentScriptVMFunction_note_off::checkArgs(VMFnArgs* args,
282                                                            std::function<void(String)> err,
283                                                            std::function<void(String)> wrn)
284        {
285            // super class checks
286            Super::checkArgs(args, err, wrn);
287    
288            // own checks ...
289            if (args->argsCount() >= 2 && args->arg(1)->isConstExpr() && args->arg(1)->exprType() == INT_EXPR) {
290                vmint velocity = args->arg(1)->asInt()->evalInt();
291                if (velocity < 0 || velocity > 127) {
292                    err("MIDI velocity value for argument 2 must be between 0..127");
293                    return;
294                }
295            }
296        }
297    
298      VMFnResult* InstrumentScriptVMFunction_note_off::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_note_off::exec(VMFnArgs* args) {
299          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
300              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
# Line 296  namespace LinuxSampler { Line 359  namespace LinuxSampler {
359      {      {
360      }      }
361    
362        void InstrumentScriptVMFunction_set_event_mark::checkArgs(VMFnArgs* args,
363                                                                  std::function<void(String)> err,
364                                                                  std::function<void(String)> wrn)
365        {
366            // super class checks
367            Super::checkArgs(args, err, wrn);
368    
369            // own checks ...
370            if (args->argsCount() >= 2 && args->arg(1)->isConstExpr()) {
371                const vmint groupID = args->arg(1)->asInt()->evalInt();
372                if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
373                    err("Argument 2 value is an invalid group id.");
374                    return;
375                }
376            }
377        }
378    
379      VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) {
380          const ScriptID id = args->arg(0)->asInt()->evalInt();          const ScriptID id = args->arg(0)->asInt()->evalInt();
381          const vmint groupID = args->arg(1)->asInt()->evalInt();          const vmint groupID = args->arg(1)->asInt()->evalInt();
# Line 334  namespace LinuxSampler { Line 414  namespace LinuxSampler {
414      {      {
415      }      }
416    
417        void InstrumentScriptVMFunction_delete_event_mark::checkArgs(VMFnArgs* args,
418                                                                     std::function<void(String)> err,
419                                                                     std::function<void(String)> wrn)
420        {
421            // super class checks
422            Super::checkArgs(args, err, wrn);
423    
424            // own checks ...
425            if (args->argsCount() >= 2 && args->arg(1)->isConstExpr()) {
426                const vmint groupID = args->arg(1)->asInt()->evalInt();
427                if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
428                    err("Argument 2 value is an invalid group id.");
429                    return;
430                }
431            }
432        }
433    
434      VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) {
435          const ScriptID id = args->arg(0)->asInt()->evalInt();          const ScriptID id = args->arg(0)->asInt()->evalInt();
436          const vmint groupID = args->arg(1)->asInt()->evalInt();          const vmint groupID = args->arg(1)->asInt()->evalInt();
# Line 378  namespace LinuxSampler { Line 475  namespace LinuxSampler {
475          return &m_result;          return &m_result;
476      }      }
477    
478        void InstrumentScriptVMFunction_by_marks::checkArgs(VMFnArgs* args,
479                                                            std::function<void(String)> err,
480                                                            std::function<void(String)> wrn)
481        {
482            // super class checks
483            Super::checkArgs(args, err, wrn);
484    
485            // own checks ...
486            if (args->arg(0)->isConstExpr()) {
487                const vmint groupID = args->arg(0)->asInt()->evalInt();
488                if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
489                    err("Argument value is an invalid group id.");
490                    return;
491                }
492            }
493        }
494    
495      VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) {
496          vmint groupID = args->arg(0)->asInt()->evalInt();          vmint groupID = args->arg(0)->asInt()->evalInt();
497    
# Line 766  namespace LinuxSampler { Line 880  namespace LinuxSampler {
880          return iArg == 1;          return iArg == 1;
881      }      }
882    
883        void InstrumentScriptVMFunction_change_cutoff::checkArgs(VMFnArgs* args,
884                                                                 std::function<void(String)> err,
885                                                                 std::function<void(String)> wrn)
886        {
887            // super class checks
888            Super::checkArgs(args, err, wrn);
889    
890            // own checks ...
891            if (args->argsCount() >= 2) {
892                VMNumberExpr* argCutoff = args->arg(1)->asNumber();
893                if (argCutoff->unitType() && !argCutoff->isFinal()) {
894                    wrn("Argument 2 implies 'final' value when using Hz as unit for cutoff frequency.");
895                }
896            }
897        }
898    
899      VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) {
900          StdUnit_t unit = args->arg(1)->asNumber()->unitType();          const StdUnit_t unit = args->arg(1)->asNumber()->unitType();
901          vmint cutoff =          vmint cutoff =
902              (unit) ?              (unit) ?
903                  args->arg(1)->asNumber()->evalCastInt(VM_NO_PREFIX) :                  args->arg(1)->asNumber()->evalCastInt(VM_NO_PREFIX) :
904                  args->arg(1)->asNumber()->evalCastInt();                  args->arg(1)->asNumber()->evalCastInt();
905          bool isFinal = args->arg(1)->asNumber()->isFinal();          const bool isFinal =
906                (unit) ?
907                    true : // imply 'final' value if unit type is used
908                    args->arg(1)->asNumber()->isFinal();
909          if (!unit && cutoff > VM_FILTER_PAR_MAX_VALUE) {          if (!unit && cutoff > VM_FILTER_PAR_MAX_VALUE) {
910              wrnMsg("change_cutoff(): argument 2 may not be larger than " strfy(VM_FILTER_PAR_MAX_VALUE));              wrnMsg("change_cutoff(): argument 2 may not be larger than " strfy(VM_FILTER_PAR_MAX_VALUE));
911              cutoff = VM_FILTER_PAR_MAX_VALUE;              cutoff = VM_FILTER_PAR_MAX_VALUE;
# Line 786  namespace LinuxSampler { Line 919  namespace LinuxSampler {
919          const float fCutoff =          const float fCutoff =
920              (unit) ? cutoff : float(cutoff) / float(VM_FILTER_PAR_MAX_VALUE);              (unit) ? cutoff : float(cutoff) / float(VM_FILTER_PAR_MAX_VALUE);
921    
         if (unit && !isFinal) {  
             wrnMsg("change_cutoff(): you must pass argument 2 as 'final' value when using Hz as unit");  
             return successResult();  
         }  
   
922          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
923              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
924    
# Line 982  namespace LinuxSampler { Line 1110  namespace LinuxSampler {
1110          return iArg == 1;          return iArg == 1;
1111      }      }
1112    
1113        void InstrumentScriptVMFunction_change_attack::checkArgs(VMFnArgs* args,
1114                                                                 std::function<void(String)> err,
1115                                                                 std::function<void(String)> wrn)
1116        {
1117            // super class checks
1118            Super::checkArgs(args, err, wrn);
1119    
1120            // own checks ...
1121            if (args->argsCount() >= 2) {
1122                VMNumberExpr* argTime = args->arg(1)->asNumber();
1123                if (argTime->unitType() && !argTime->isFinal()) {
1124                    wrn("Argument 2 implies 'final' value when using seconds as unit for attack time.");
1125                }
1126            }
1127        }
1128    
1129      VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) {
1130          StdUnit_t unit = args->arg(1)->asNumber()->unitType();          const StdUnit_t unit = args->arg(1)->asNumber()->unitType();
1131          vmint attack =          vmint attack =
1132              (unit) ?              (unit) ?
1133                  args->arg(1)->asNumber()->evalCastInt(VM_MICRO) :                  args->arg(1)->asNumber()->evalCastInt(VM_MICRO) :
1134                  args->arg(1)->asNumber()->evalCastInt();                  args->arg(1)->asNumber()->evalCastInt();
1135          bool isFinal = args->arg(1)->asNumber()->isFinal();          const bool isFinal =
1136                (unit) ?
1137                    true : // imply 'final' value if unit type is used
1138                    args->arg(1)->asNumber()->isFinal();
1139          // note: intentionally not checking against a max. value here!          // note: intentionally not checking against a max. value here!
1140          // (to allow i.e. passing 2000000 for doubling the attack time)          // (to allow i.e. passing 2000000 for doubling the attack time)
1141          if (attack < 0) {          if (attack < 0) {
1142              wrnMsg("change_attack(): argument 2 may not be negative");              wrnMsg("change_attack(): argument 2 may not be negative");
1143              attack = 0;              attack = 0;
1144          }          }
1145          const float fAttack = float(attack) / float(VM_EG_PAR_MAX_VALUE);          const float fAttack =
1146                (unit) ? attack : float(attack) / float(VM_EG_PAR_MAX_VALUE);
         if (unit && !isFinal) {  
             wrnMsg("change_attack(): you must pass argument 2 as 'final' value when using seconds as unit");  
             return successResult();  
         }  
1147    
1148          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
1149              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
# Line 1097  namespace LinuxSampler { Line 1240  namespace LinuxSampler {
1240          return iArg == 1;          return iArg == 1;
1241      }      }
1242    
1243        void InstrumentScriptVMFunction_change_decay::checkArgs(VMFnArgs* args,
1244                                                                std::function<void(String)> err,
1245                                                                std::function<void(String)> wrn)
1246        {
1247            // super class checks
1248            Super::checkArgs(args, err, wrn);
1249    
1250            // own checks ...
1251            if (args->argsCount() >= 2) {
1252                VMNumberExpr* argTime = args->arg(1)->asNumber();
1253                if (argTime->unitType() && !argTime->isFinal()) {
1254                    wrn("Argument 2 implies 'final' value when using seconds as unit for decay time.");
1255                }
1256            }
1257        }
1258    
1259      VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) {
1260          StdUnit_t unit = args->arg(1)->asNumber()->unitType();          const StdUnit_t unit = args->arg(1)->asNumber()->unitType();
1261          vmint decay =          vmint decay =
1262              (unit) ?              (unit) ?
1263                  args->arg(1)->asNumber()->evalCastInt(VM_MICRO) :                  args->arg(1)->asNumber()->evalCastInt(VM_MICRO) :
1264                  args->arg(1)->asNumber()->evalCastInt();                  args->arg(1)->asNumber()->evalCastInt();
1265          bool isFinal = args->arg(1)->asNumber()->isFinal();          const bool isFinal =
1266                (unit) ?
1267                    true : // imply 'final' value if unit type is used
1268                    args->arg(1)->asNumber()->isFinal();
1269          // note: intentionally not checking against a max. value here!          // note: intentionally not checking against a max. value here!
1270          // (to allow i.e. passing 2000000 for doubling the decay time)          // (to allow i.e. passing 2000000 for doubling the decay time)
1271          if (decay < 0) {          if (decay < 0) {
1272              wrnMsg("change_decay(): argument 2 may not be negative");              wrnMsg("change_decay(): argument 2 may not be negative");
1273              decay = 0;              decay = 0;
1274          }          }
1275          const float fDecay = float(decay) / float(VM_EG_PAR_MAX_VALUE);          const float fDecay =
1276                (unit) ? decay : float(decay) / float(VM_EG_PAR_MAX_VALUE);
         if (unit && !isFinal) {  
             wrnMsg("change_decay(): you must pass argument 2 as 'final' value when using seconds as unit");  
             return successResult();  
         }  
1277    
1278          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
1279              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
# Line 1212  namespace LinuxSampler { Line 1370  namespace LinuxSampler {
1370          return iArg == 1;          return iArg == 1;
1371      }      }
1372    
1373        void InstrumentScriptVMFunction_change_release::checkArgs(VMFnArgs* args,
1374                                                                  std::function<void(String)> err,
1375                                                                  std::function<void(String)> wrn)
1376        {
1377            // super class checks
1378            Super::checkArgs(args, err, wrn);
1379    
1380            // own checks ...
1381            if (args->argsCount() >= 2) {
1382                VMNumberExpr* argTime = args->arg(1)->asNumber();
1383                if (argTime->unitType() && !argTime->isFinal()) {
1384                    wrn("Argument 2 implies 'final' value when using seconds as unit for release time.");
1385                }
1386            }
1387        }
1388    
1389      VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) {
1390          StdUnit_t unit = args->arg(1)->asNumber()->unitType();          const StdUnit_t unit = args->arg(1)->asNumber()->unitType();
1391          vmint release =          vmint release =
1392              (unit) ?              (unit) ?
1393                  args->arg(1)->asNumber()->evalCastInt(VM_MICRO) :                  args->arg(1)->asNumber()->evalCastInt(VM_MICRO) :
1394                  args->arg(1)->asNumber()->evalCastInt();                  args->arg(1)->asNumber()->evalCastInt();
1395          bool isFinal = args->arg(1)->asNumber()->isFinal();          const bool isFinal =
1396                (unit) ?
1397                    true : // imply 'final' value if unit type is used
1398                    args->arg(1)->asNumber()->isFinal();
1399          // note: intentionally not checking against a max. value here!          // note: intentionally not checking against a max. value here!
1400          // (to allow i.e. passing 2000000 for doubling the release time)          // (to allow i.e. passing 2000000 for doubling the release time)
1401          if (release < 0) {          if (release < 0) {
1402              wrnMsg("change_release(): argument 2 may not be negative");              wrnMsg("change_release(): argument 2 may not be negative");
1403              release = 0;              release = 0;
1404          }          }
1405          const float fRelease = float(release) / float(VM_EG_PAR_MAX_VALUE);          const float fRelease =
1406                (unit) ? release : float(release) / float(VM_EG_PAR_MAX_VALUE);
         if (unit && !isFinal) {  
             wrnMsg("change_release(): you must pass argument 2 as 'final' value when using seconds as unit");  
             return successResult();  
         }  
1407    
1408          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
1409              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
# Line 1343  namespace LinuxSampler { Line 1516  namespace LinuxSampler {
1516          param = value;          param = value;
1517      }      }
1518    
1519        void VMChangeSynthParamFunction::checkArgs(VMFnArgs* args,
1520                                                   std::function<void(String)> err,
1521                                                   std::function<void(String)> wrn)
1522        {
1523            // super class checks
1524            Super::checkArgs(args, err, wrn);
1525    
1526            // own checks ...
1527            if (m_unit && m_unit != VM_BEL && args->argsCount() >= 2) {
1528                VMNumberExpr* arg = args->arg(1)->asNumber();
1529                if (arg && arg->unitType() && !arg->isFinal()) {
1530                    wrn("Argument 2 implies 'final' value when unit type " +
1531                        unitTypeStr(arg->unitType()) + " is used.");
1532                }
1533            }
1534        }
1535    
1536      // Arbitrarily chosen constant value symbolizing "no limit".      // Arbitrarily chosen constant value symbolizing "no limit".
1537      #define NO_LIMIT 1315916909      #define NO_LIMIT 1315916909
1538    
# Line 1354  namespace LinuxSampler { Line 1544  namespace LinuxSampler {
1544      VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName)      VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName)
1545      {      {
1546          const StdUnit_t unit = args->arg(1)->asNumber()->unitType();          const StdUnit_t unit = args->arg(1)->asNumber()->unitType();
1547          const bool isFinal   = args->arg(1)->asNumber()->isFinal();          const bool isFinal =
1548                (m_unit && m_unit != VM_BEL && unit) ?
1549                    true : // imply 'final' value if unit type is used (except of 'Bel' which may be relative)
1550                    args->arg(1)->asNumber()->isFinal();
1551          vmint value =          vmint value =
1552              (m_acceptUnitPrefix && ((m_unit && unit) || (!m_unit && args->arg(1)->asNumber()->hasUnitFactorNow())))              (m_acceptUnitPrefix && ((m_unit && unit) || (!m_unit && args->arg(1)->asNumber()->hasUnitFactorNow())))
1553                  ? args->arg(1)->asNumber()->evalCastInt(T_unitPrefix0, T_unitPrefixN ...)                  ? args->arg(1)->asNumber()->evalCastInt(T_unitPrefix0, T_unitPrefixN ...)
1554                  : args->arg(1)->asNumber()->evalCastInt();                  : args->arg(1)->asNumber()->evalCastInt();
1555    
         if (unit && !isFinal && m_unit != VM_BEL && m_unit) {  
             wrnMsg(String(functionName) + "(): you must pass argument 2 as 'final' value when using a unit");  
             return successResult();  
         }  
   
1556          // check if passed value is in allowed range          // check if passed value is in allowed range
1557          if (unit && m_unit) {          if (unit && m_unit) {
1558              if (T_maxValueUnit != NO_LIMIT && value > T_maxValueUnit) {              if (T_maxValueUnit != NO_LIMIT && value > T_maxValueUnit) {

Legend:
Removed from v.3587  
changed lines
  Added in v.3588

  ViewVC Help
Powered by ViewVC