/[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 3381 by schoenebeck, Tue Nov 28 15:54:49 2017 UTC revision 3557 by schoenebeck, Sun Aug 18 00:06:04 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2017 Christian Schoenebeck   * Copyright (c) 2014-2019 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 21  namespace LinuxSampler { Line 21  namespace LinuxSampler {
21      }      }
22    
23      VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) {
24          int note = args->arg(0)->asInt()->evalInt();          vmint note = args->arg(0)->asInt()->evalInt();
25          int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;          vmint velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;
26          int duration = (args->argsCount() >= 4) ? args->arg(3)->asInt()->evalInt() : 0; //TODO: -1 might be a better default value instead of 0          vmint duration = (args->argsCount() >= 4) ? args->arg(3)->asInt()->evalInt() : 0; //TODO: -1 might be a better default value instead of 0
27    
28          if (note < 0 || note > 127) {          if (note < 0 || note > 127) {
29              errMsg("play_note(): argument 1 is an invalid note number");              errMsg("play_note(): argument 1 is an invalid note number");
# Line 68  namespace LinuxSampler { Line 68  namespace LinuxSampler {
68          // if a sample offset is supplied, assign the offset as override          // if a sample offset is supplied, assign the offset as override
69          // to the previously created Note object          // to the previously created Note object
70          if (args->argsCount() >= 3) {          if (args->argsCount() >= 3) {
71              int sampleoffset = args->arg(2)->asInt()->evalInt();              vmint sampleoffset = args->arg(2)->asInt()->evalInt();
72              if (sampleoffset >= 0) {              if (sampleoffset >= 0) {
73                  NoteBase* pNote = pEngineChannel->pEngine->NoteByID(id);                  NoteBase* pNote = pEngineChannel->pEngine->NoteByID(id);
74                  if (pNote) {                  if (pNote) {
75                      pNote->Override.SampleOffset = sampleoffset;                      pNote->Override.SampleOffset =
76                            (decltype(pNote->Override.SampleOffset)) sampleoffset;
77                  }                  }
78              } else if (sampleoffset < -1) {              } else if (sampleoffset < -1) {
79                  errMsg("play_note(): sample offset of argument 3 may not be less than -1");                  errMsg("play_note(): sample offset of argument 3 may not be less than -1");
# Line 102  namespace LinuxSampler { Line 103  namespace LinuxSampler {
103      }      }
104    
105      VMFnResult* InstrumentScriptVMFunction_set_controller::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_set_controller::exec(VMFnArgs* args) {
106          int controller = args->arg(0)->asInt()->evalInt();          vmint controller = args->arg(0)->asInt()->evalInt();
107          int value      = args->arg(1)->asInt()->evalInt();          vmint value      = args->arg(1)->asInt()->evalInt();
108    
109          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
110              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
# Line 140  namespace LinuxSampler { Line 141  namespace LinuxSampler {
141      {      {
142      }      }
143    
144      bool InstrumentScriptVMFunction_ignore_event::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_ignore_event::acceptsArgType(vmint iArg, ExprType_t type) const {
145          return type == INT_EXPR || type == INT_ARR_EXPR;          return type == INT_EXPR || type == INT_ARR_EXPR;
146      }      }
147    
# Line 196  namespace LinuxSampler { Line 197  namespace LinuxSampler {
197      {      {
198      }      }
199    
200      bool InstrumentScriptVMFunction_note_off::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_note_off::acceptsArgType(vmint iArg, ExprType_t type) const {
201          return type == INT_EXPR || type == INT_ARR_EXPR;          return type == INT_EXPR || type == INT_ARR_EXPR;
202      }      }
203    
# Line 204  namespace LinuxSampler { Line 205  namespace LinuxSampler {
205          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
206              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
207    
208          int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;          vmint velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;
209          if (velocity < 0 || velocity > 127) {          if (velocity < 0 || velocity > 127) {
210              errMsg("note_off(): argument 2 is an invalid velocity value");              errMsg("note_off(): argument 2 is an invalid velocity value");
211              return errorResult();              return errorResult();
# Line 235  namespace LinuxSampler { Line 236  namespace LinuxSampler {
236              pEngineChannel->ScheduleEventMicroSec(&e, 0);              pEngineChannel->ScheduleEventMicroSec(&e, 0);
237          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
238              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
239              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
240                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
241                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
242    
# Line 266  namespace LinuxSampler { Line 267  namespace LinuxSampler {
267    
268      VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) {
269          const ScriptID id = args->arg(0)->asInt()->evalInt();          const ScriptID id = args->arg(0)->asInt()->evalInt();
270          const int groupID = args->arg(1)->asInt()->evalInt();          const vmint groupID = args->arg(1)->asInt()->evalInt();
271    
272          if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {          if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
273              errMsg("set_event_mark(): argument 2 is an invalid group id");              errMsg("set_event_mark(): argument 2 is an invalid group id");
# Line 304  namespace LinuxSampler { Line 305  namespace LinuxSampler {
305    
306      VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) {
307          const ScriptID id = args->arg(0)->asInt()->evalInt();          const ScriptID id = args->arg(0)->asInt()->evalInt();
308          const int groupID = args->arg(1)->asInt()->evalInt();          const vmint groupID = args->arg(1)->asInt()->evalInt();
309    
310          if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {          if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
311              errMsg("delete_event_mark(): argument 2 is an invalid group id");              errMsg("delete_event_mark(): argument 2 is an invalid group id");
# Line 326  namespace LinuxSampler { Line 327  namespace LinuxSampler {
327      {      {
328      }      }
329    
330      int InstrumentScriptVMFunction_by_marks::Result::arraySize() const {      vmint InstrumentScriptVMFunction_by_marks::Result::arraySize() const {
331          return eventGroup->size();          return eventGroup->size();
332      }      }
333    
334      int InstrumentScriptVMFunction_by_marks::Result::evalIntElement(uint i) {      vmint InstrumentScriptVMFunction_by_marks::Result::evalIntElement(vmuint i) {
335          return (*eventGroup)[i];          return (*eventGroup)[i];
336      }      }
337    
# Line 347  namespace LinuxSampler { Line 348  namespace LinuxSampler {
348      }      }
349    
350      VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) {
351          int groupID = args->arg(0)->asInt()->evalInt();          vmint groupID = args->arg(0)->asInt()->evalInt();
352    
353          if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {          if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
354              errMsg("by_marks(): argument is an invalid group id");              errMsg("by_marks(): argument is an invalid group id");
# Line 367  namespace LinuxSampler { Line 368  namespace LinuxSampler {
368      {      {
369      }      }
370    
371      bool InstrumentScriptVMFunction_change_vol::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_vol::acceptsArgType(vmint iArg, ExprType_t type) const {
372          if (iArg == 0)          if (iArg == 0)
373              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
374          else          else
# Line 375  namespace LinuxSampler { Line 376  namespace LinuxSampler {
376      }      }
377    
378      VMFnResult* InstrumentScriptVMFunction_change_vol::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_vol::exec(VMFnArgs* args) {
379          int volume = args->arg(1)->asInt()->evalInt(); // volume change in milli dB          vmint volume = args->arg(1)->asInt()->evalInt(); // volume change in milli dB
380          bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false;          bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false;
381          const float fVolumeLin = RTMath::DecibelToLinRatio(float(volume) / 1000.f);          const float fVolumeLin = RTMath::DecibelToLinRatio(float(volume) / 1000.f);
382    
# Line 419  namespace LinuxSampler { Line 420  namespace LinuxSampler {
420              }              }
421          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
422              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
423              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
424                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
425                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
426    
# Line 460  namespace LinuxSampler { Line 461  namespace LinuxSampler {
461      {      {
462      }      }
463    
464      bool InstrumentScriptVMFunction_change_tune::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_tune::acceptsArgType(vmint iArg, ExprType_t type) const {
465          if (iArg == 0)          if (iArg == 0)
466              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
467          else          else
# Line 468  namespace LinuxSampler { Line 469  namespace LinuxSampler {
469      }      }
470    
471      VMFnResult* InstrumentScriptVMFunction_change_tune::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_tune::exec(VMFnArgs* args) {
472          int tune = args->arg(1)->asInt()->evalInt(); // tuning change in milli cents          vmint tune = args->arg(1)->asInt()->evalInt(); // tuning change in milli cents
473          bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false;          bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false;
474          const float fFreqRatio = RTMath::CentsToFreqRatioUnlimited(float(tune) / 1000.f);          const float fFreqRatio = RTMath::CentsToFreqRatioUnlimited(float(tune) / 1000.f);
475    
# Line 512  namespace LinuxSampler { Line 513  namespace LinuxSampler {
513              }              }
514          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
515              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
516              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
517                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
518                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
519    
# Line 553  namespace LinuxSampler { Line 554  namespace LinuxSampler {
554      {      {
555      }      }
556    
557      bool InstrumentScriptVMFunction_change_pan::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_pan::acceptsArgType(vmint iArg, ExprType_t type) const {
558          if (iArg == 0)          if (iArg == 0)
559              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
560          else          else
# Line 561  namespace LinuxSampler { Line 562  namespace LinuxSampler {
562      }      }
563    
564      VMFnResult* InstrumentScriptVMFunction_change_pan::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_pan::exec(VMFnArgs* args) {
565          int pan = args->arg(1)->asInt()->evalInt();          vmint pan = args->arg(1)->asInt()->evalInt();
566          bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false;          bool relative = (args->argsCount() >= 3) ? (args->arg(2)->asInt()->evalInt() & 1) : false;
567    
568          if (pan > 1000) {          if (pan > 1000) {
# Line 612  namespace LinuxSampler { Line 613  namespace LinuxSampler {
613              }              }
614          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
615              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
616              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
617                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
618                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
619    
# Line 655  namespace LinuxSampler { Line 656  namespace LinuxSampler {
656      {      {
657      }      }
658    
659      bool InstrumentScriptVMFunction_change_cutoff::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_cutoff::acceptsArgType(vmint iArg, ExprType_t type) const {
660          if (iArg == 0)          if (iArg == 0)
661              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
662          else          else
# Line 663  namespace LinuxSampler { Line 664  namespace LinuxSampler {
664      }      }
665    
666      VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_cutoff::exec(VMFnArgs* args) {
667          int cutoff = args->arg(1)->asInt()->evalInt();          vmint cutoff = args->arg(1)->asInt()->evalInt();
668          if (cutoff > VM_FILTER_PAR_MAX_VALUE) {          if (cutoff > VM_FILTER_PAR_MAX_VALUE) {
669              wrnMsg("change_cutoff(): argument 2 may not be larger than 1000000");              wrnMsg("change_cutoff(): argument 2 may not be larger than 1000000");
670              cutoff = VM_FILTER_PAR_MAX_VALUE;              cutoff = VM_FILTER_PAR_MAX_VALUE;
# Line 707  namespace LinuxSampler { Line 708  namespace LinuxSampler {
708              }              }
709          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
710              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
711              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
712                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
713                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
714    
# Line 742  namespace LinuxSampler { Line 743  namespace LinuxSampler {
743      {      {
744      }      }
745    
746      bool InstrumentScriptVMFunction_change_reso::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_reso::acceptsArgType(vmint iArg, ExprType_t type) const {
747          if (iArg == 0)          if (iArg == 0)
748              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
749          else          else
# Line 750  namespace LinuxSampler { Line 751  namespace LinuxSampler {
751      }      }
752    
753      VMFnResult* InstrumentScriptVMFunction_change_reso::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_reso::exec(VMFnArgs* args) {
754          int resonance = args->arg(1)->asInt()->evalInt();          vmint resonance = args->arg(1)->asInt()->evalInt();
755          if (resonance > VM_FILTER_PAR_MAX_VALUE) {          if (resonance > VM_FILTER_PAR_MAX_VALUE) {
756              wrnMsg("change_reso(): argument 2 may not be larger than 1000000");              wrnMsg("change_reso(): argument 2 may not be larger than 1000000");
757              resonance = VM_FILTER_PAR_MAX_VALUE;              resonance = VM_FILTER_PAR_MAX_VALUE;
# Line 794  namespace LinuxSampler { Line 795  namespace LinuxSampler {
795              }              }
796          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
797              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
798              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
799                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
800                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
801    
# Line 829  namespace LinuxSampler { Line 830  namespace LinuxSampler {
830      {      {
831      }      }
832    
833      bool InstrumentScriptVMFunction_change_attack::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_attack::acceptsArgType(vmint iArg, ExprType_t type) const {
834          if (iArg == 0)          if (iArg == 0)
835              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
836          else          else
# Line 837  namespace LinuxSampler { Line 838  namespace LinuxSampler {
838      }      }
839    
840      VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_attack::exec(VMFnArgs* args) {
841          int attack = args->arg(1)->asInt()->evalInt();          vmint attack = args->arg(1)->asInt()->evalInt();
842          // note: intentionally not checking against a max. value here!          // note: intentionally not checking against a max. value here!
843          // (to allow i.e. passing 2000000 for doubling the attack time)          // (to allow i.e. passing 2000000 for doubling the attack time)
844          if (attack < 0) {          if (attack < 0) {
# Line 880  namespace LinuxSampler { Line 881  namespace LinuxSampler {
881              }              }
882          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
883              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
884              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
885                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
886                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
887    
# Line 915  namespace LinuxSampler { Line 916  namespace LinuxSampler {
916      {      {
917      }      }
918    
919      bool InstrumentScriptVMFunction_change_decay::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_decay::acceptsArgType(vmint iArg, ExprType_t type) const {
920          if (iArg == 0)          if (iArg == 0)
921              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
922          else          else
# Line 923  namespace LinuxSampler { Line 924  namespace LinuxSampler {
924      }      }
925    
926      VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_decay::exec(VMFnArgs* args) {
927          int decay = args->arg(1)->asInt()->evalInt();          vmint decay = args->arg(1)->asInt()->evalInt();
928          // note: intentionally not checking against a max. value here!          // note: intentionally not checking against a max. value here!
929          // (to allow i.e. passing 2000000 for doubling the decay time)          // (to allow i.e. passing 2000000 for doubling the decay time)
930          if (decay < 0) {          if (decay < 0) {
# Line 966  namespace LinuxSampler { Line 967  namespace LinuxSampler {
967              }              }
968          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
969              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
970              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
971                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
972                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
973    
# Line 1001  namespace LinuxSampler { Line 1002  namespace LinuxSampler {
1002      {      {
1003      }      }
1004    
1005      bool InstrumentScriptVMFunction_change_release::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_change_release::acceptsArgType(vmint iArg, ExprType_t type) const {
1006          if (iArg == 0)          if (iArg == 0)
1007              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
1008          else          else
# Line 1009  namespace LinuxSampler { Line 1010  namespace LinuxSampler {
1010      }      }
1011    
1012      VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_change_release::exec(VMFnArgs* args) {
1013          int release = args->arg(1)->asInt()->evalInt();          vmint release = args->arg(1)->asInt()->evalInt();
1014          // note: intentionally not checking against a max. value here!          // note: intentionally not checking against a max. value here!
1015          // (to allow i.e. passing 2000000 for doubling the release time)          // (to allow i.e. passing 2000000 for doubling the release time)
1016          if (release < 0) {          if (release < 0) {
# Line 1052  namespace LinuxSampler { Line 1053  namespace LinuxSampler {
1053              }              }
1054          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
1055              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
1056              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
1057                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
1058                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
1059    
# Line 1082  namespace LinuxSampler { Line 1083  namespace LinuxSampler {
1083    
1084      // template for change_*() functions      // template for change_*() functions
1085    
1086      bool VMChangeSynthParamFunction::acceptsArgType(int iArg, ExprType_t type) const {      bool VMChangeSynthParamFunction::acceptsArgType(vmint iArg, ExprType_t type) const {
1087          if (iArg == 0)          if (iArg == 0)
1088              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
1089          else          else
# Line 1092  namespace LinuxSampler { Line 1093  namespace LinuxSampler {
1093      // Arbitrarily chosen constant value symbolizing "no limit".      // Arbitrarily chosen constant value symbolizing "no limit".
1094      #define NO_LIMIT 1315916909      #define NO_LIMIT 1315916909
1095    
1096      template<float NoteBase::_Override::*T_noteParam, int T_synthParam,      template<float NoteBase::_Override::*T_noteParam, vmint T_synthParam,
1097               bool T_isNormalizedParam, int T_maxValue, int T_minValue>               bool T_isNormalizedParam, vmint T_maxValue, vmint T_minValue>
1098      VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName) {      VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName) {
1099          int value = args->arg(1)->asInt()->evalInt();          vmint value = args->arg(1)->asInt()->evalInt();
1100          if (T_maxValue != NO_LIMIT && value > T_maxValue) {          if (T_maxValue != NO_LIMIT && value > T_maxValue) {
1101              wrnMsg(String(functionName) + "(): argument 2 may not be larger than " + ToString(T_maxValue));              wrnMsg(String(functionName) + "(): argument 2 may not be larger than " + ToString(T_maxValue));
1102              value = T_maxValue;              value = T_maxValue;
# Line 1145  namespace LinuxSampler { Line 1146  namespace LinuxSampler {
1146              }              }
1147          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
1148              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
1149              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
1150                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
1151                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
1152    
# Line 1302  namespace LinuxSampler { Line 1303  namespace LinuxSampler {
1303    
1304      // template for change_*_curve() functions      // template for change_*_curve() functions
1305    
1306      bool VMChangeFadeCurveFunction::acceptsArgType(int iArg, ExprType_t type) const {      bool VMChangeFadeCurveFunction::acceptsArgType(vmint iArg, ExprType_t type) const {
1307          if (iArg == 0)          if (iArg == 0)
1308              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
1309          else          else
1310              return type == INT_EXPR;              return type == INT_EXPR;
1311      }      }
1312    
1313      template<fade_curve_t NoteBase::_Override::*T_noteParam, int T_synthParam>      template<fade_curve_t NoteBase::_Override::*T_noteParam, vmint T_synthParam>
1314      VMFnResult* VMChangeFadeCurveFunction::execTemplate(VMFnArgs* args, const char* functionName) {      VMFnResult* VMChangeFadeCurveFunction::execTemplate(VMFnArgs* args, const char* functionName) {
1315          int value = args->arg(1)->asInt()->evalInt();          vmint value = args->arg(1)->asInt()->evalInt();
1316          switch (value) {          switch (value) {
1317              case FADE_CURVE_LINEAR:              case FADE_CURVE_LINEAR:
1318              case FADE_CURVE_EASE_IN_EASE_OUT:              case FADE_CURVE_EASE_IN_EASE_OUT:
# Line 1356  namespace LinuxSampler { Line 1357  namespace LinuxSampler {
1357              }              }
1358          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
1359              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
1360              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
1361                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
1362                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
1363    
# Line 1416  namespace LinuxSampler { Line 1417  namespace LinuxSampler {
1417      {      {
1418      }      }
1419    
1420      bool InstrumentScriptVMFunction_fade_in::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_fade_in::acceptsArgType(vmint iArg, ExprType_t type) const {
1421          if (iArg == 0)          if (iArg == 0)
1422              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
1423          else          else
# Line 1424  namespace LinuxSampler { Line 1425  namespace LinuxSampler {
1425      }      }
1426    
1427      VMFnResult* InstrumentScriptVMFunction_fade_in::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_fade_in::exec(VMFnArgs* args) {
1428          int duration = args->arg(1)->asInt()->evalInt();          vmint duration = args->arg(1)->asInt()->evalInt();
1429          if (duration < 0) {          if (duration < 0) {
1430              wrnMsg("fade_in(): argument 2 may not be negative");              wrnMsg("fade_in(): argument 2 may not be negative");
1431              duration = 0;              duration = 0;
# Line 1483  namespace LinuxSampler { Line 1484  namespace LinuxSampler {
1484              }              }
1485          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
1486              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
1487              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
1488                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
1489                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
1490    
# Line 1536  namespace LinuxSampler { Line 1537  namespace LinuxSampler {
1537      {      {
1538      }      }
1539    
1540      bool InstrumentScriptVMFunction_fade_out::acceptsArgType(int iArg, ExprType_t type) const {      bool InstrumentScriptVMFunction_fade_out::acceptsArgType(vmint iArg, ExprType_t type) const {
1541          if (iArg == 0)          if (iArg == 0)
1542              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
1543          else          else
# Line 1544  namespace LinuxSampler { Line 1545  namespace LinuxSampler {
1545      }      }
1546    
1547      VMFnResult* InstrumentScriptVMFunction_fade_out::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_fade_out::exec(VMFnArgs* args) {
1548          int duration = args->arg(1)->asInt()->evalInt();          vmint duration = args->arg(1)->asInt()->evalInt();
1549          if (duration < 0) {          if (duration < 0) {
1550              wrnMsg("fade_out(): argument 2 may not be negative");              wrnMsg("fade_out(): argument 2 may not be negative");
1551              duration = 0;              duration = 0;
# Line 1615  namespace LinuxSampler { Line 1616  namespace LinuxSampler {
1616              }              }
1617          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {          } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
1618              VMIntArrayExpr* ids = args->arg(0)->asIntArray();              VMIntArrayExpr* ids = args->arg(0)->asIntArray();
1619              for (int i = 0; i < ids->arraySize(); ++i) {              for (vmint i = 0; i < ids->arraySize(); ++i) {
1620                  const ScriptID id = ids->evalIntElement(i);                  const ScriptID id = ids->evalIntElement(i);
1621                  if (!id || !id.isNoteID()) continue;                  if (!id || !id.isNoteID()) continue;
1622    
# Line 1698  namespace LinuxSampler { Line 1699  namespace LinuxSampler {
1699              return successResult(0);              return successResult(0);
1700          }          }
1701    
1702          const int parameter = args->arg(1)->asInt()->evalInt();          const vmint parameter = args->arg(1)->asInt()->evalInt();
1703          switch (parameter) {          switch (parameter) {
1704              case EVENT_PAR_NOTE:              case EVENT_PAR_NOTE:
1705                  return successResult(pNote->cause.Param.Note.Key);                  return successResult(pNote->cause.Param.Note.Key);
# Line 1750  namespace LinuxSampler { Line 1751  namespace LinuxSampler {
1751          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1752          if (!pNote) return successResult();          if (!pNote) return successResult();
1753    
1754          const int parameter = args->arg(1)->asInt()->evalInt();          const vmint parameter = args->arg(1)->asInt()->evalInt();
1755          const int value     = args->arg(2)->asInt()->evalInt();          const vmint value     = args->arg(2)->asInt()->evalInt();
1756    
1757          switch (parameter) {          switch (parameter) {
1758              case EVENT_PAR_NOTE:              case EVENT_PAR_NOTE:
# Line 1826  namespace LinuxSampler { Line 1827  namespace LinuxSampler {
1827          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1828          if (!pNote) return successResult();          if (!pNote) return successResult();
1829    
1830          const int value = args->arg(1)->asInt()->evalInt();          const vmint value = args->arg(1)->asInt()->evalInt();
1831          if (value < 0 || value > 127) {          if (value < 0 || value > 127) {
1832              wrnMsg("change_note(): note number of argument 2 is out of range");              wrnMsg("change_note(): note number of argument 2 is out of range");
1833              return successResult();              return successResult();
# Line 1866  namespace LinuxSampler { Line 1867  namespace LinuxSampler {
1867          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1868          if (!pNote) return successResult();          if (!pNote) return successResult();
1869    
1870          const int value = args->arg(1)->asInt()->evalInt();          const vmint value = args->arg(1)->asInt()->evalInt();
1871          if (value < 0 || value > 127) {          if (value < 0 || value > 127) {
1872              wrnMsg("change_velo(): velocity of argument 2 is out of range");              wrnMsg("change_velo(): velocity of argument 2 is out of range");
1873              return successResult();              return successResult();
# Line 1900  namespace LinuxSampler { Line 1901  namespace LinuxSampler {
1901              return successResult();              return successResult();
1902          }          }
1903    
1904          const int pos = args->arg(1)->asInt()->evalInt();          const vmint pos = args->arg(1)->asInt()->evalInt();
1905          if (pos < 0) {          if (pos < 0) {
1906              wrnMsg("change_play_pos(): playback position of argument 2 may not be negative");              wrnMsg("change_play_pos(): playback position of argument 2 may not be negative");
1907              return successResult();              return successResult();
# Line 1912  namespace LinuxSampler { Line 1913  namespace LinuxSampler {
1913          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );          NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1914          if (!pNote) return successResult();          if (!pNote) return successResult();
1915    
1916          pNote->Override.SampleOffset = pos;          pNote->Override.SampleOffset =
1917                (decltype(pNote->Override.SampleOffset)) pos;
1918    
1919          return successResult();          return successResult();
1920      }      }
# Line 2059  namespace LinuxSampler { Line 2061  namespace LinuxSampler {
2061    
2062          // if we are here, then this is the parent, so we must fork this parent          // if we are here, then this is the parent, so we must fork this parent
2063    
2064          const int n =          const vmint n =
2065              (args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : 1;              (args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : 1;
2066          const bool bAutoAbort =          const bool bAutoAbort =
2067              (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : true;              (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : true;
# Line 2085  namespace LinuxSampler { Line 2087  namespace LinuxSampler {
2087                  return errorResult(-1); // terminate script                  return errorResult(-1); // terminate script
2088              }              }
2089              // since both parent, as well all child script execution instances              // since both parent, as well all child script execution instances
2090              // all land in this exect() method, the following is (more or less)              // all land in this exec() method, the following is (more or less)
2091              // the only feature that lets us distinguish the parent and              // the only feature that lets us distinguish the parent and
2092              // respective children from each other in this exect() method              // respective children from each other in this exec() method
2093              itChild->forkIndex = iChild + 1;              itChild->forkIndex = iChild + 1;
2094          }          }
2095    

Legend:
Removed from v.3381  
changed lines
  Added in v.3557

  ViewVC Help
Powered by ViewVC