/[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 3214 by schoenebeck, Thu May 25 14:46:47 2017 UTC revision 3246 by schoenebeck, Sun May 28 22:22:56 2017 UTC
# Line 385  namespace LinuxSampler { Line 385  namespace LinuxSampler {
385              if (!pNote) return successResult();              if (!pNote) return successResult();
386    
387              // if change_vol() was called immediately after note was triggered              // if change_vol() was called immediately after note was triggered
388              // then immediately apply the volume to note object              // then immediately apply the volume to note object, but only if
389              if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {              // change_vol_time() has not been called before
390                if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime &&
391                    pNote->Override.VolumeTime <= DEFAULT_NOTE_VOLUME_TIME_S)
392                {
393                  if (relative)                  if (relative)
394                      pNote->Override.Volume *= fVolumeLin;                      pNote->Override.Volume *= fVolumeLin;
395                  else                  else
# Line 412  namespace LinuxSampler { Line 415  namespace LinuxSampler {
415                  if (!pNote) continue;                  if (!pNote) continue;
416    
417                  // if change_vol() was called immediately after note was triggered                  // if change_vol() was called immediately after note was triggered
418                  // then immediately apply the volume to Note object                  // then immediately apply the volume to Note object, but only if
419                  if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {                  // change_vol_time() has not been called before
420                    if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime &&
421                        pNote->Override.VolumeTime <= DEFAULT_NOTE_VOLUME_TIME_S)
422                    {
423                      if (relative)                      if (relative)
424                          pNote->Override.Volume *= fVolumeLin;                          pNote->Override.Volume *= fVolumeLin;
425                      else                      else
# Line 472  namespace LinuxSampler { Line 478  namespace LinuxSampler {
478              if (!pNote) return successResult();              if (!pNote) return successResult();
479    
480              // if change_tune() was called immediately after note was triggered              // if change_tune() was called immediately after note was triggered
481              // then immediately apply the tuning to Note object              // then immediately apply the tuning to Note object, but only if
482              if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {              // change_tune_time() has not been called before
483                if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime &&
484                    pNote->Override.PitchTime <= DEFAULT_NOTE_PITCH_TIME_S)
485                {
486                  if (relative)                  if (relative)
487                      pNote->Override.Pitch *= fFreqRatio;                      pNote->Override.Pitch *= fFreqRatio;
488                  else                  else
# Line 499  namespace LinuxSampler { Line 508  namespace LinuxSampler {
508                  if (!pNote) continue;                  if (!pNote) continue;
509    
510                  // if change_tune() was called immediately after note was triggered                  // if change_tune() was called immediately after note was triggered
511                  // then immediately apply the tuning to Note object                  // then immediately apply the tuning to Note object, but only if
512                  if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {                  // change_tune_time() has not been called before
513                    if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime &&
514                        pNote->Override.PitchTime <= DEFAULT_NOTE_PITCH_TIME_S)
515                    {
516                      if (relative)                      if (relative)
517                          pNote->Override.Pitch *= fFreqRatio;                          pNote->Override.Pitch *= fFreqRatio;
518                      else                      else
# Line 1059  namespace LinuxSampler { Line 1071  namespace LinuxSampler {
1071          return successResult();          return successResult();
1072      }      }
1073    
1074        // template for change_*() functions
1075    
1076      bool VMChangeSynthParamFunction::acceptsArgType(int iArg, ExprType_t type) const {      bool VMChangeSynthParamFunction::acceptsArgType(int iArg, ExprType_t type) const {
1077          if (iArg == 0)          if (iArg == 0)
1078              return type == INT_EXPR || type == INT_ARR_EXPR;              return type == INT_EXPR || type == INT_ARR_EXPR;
# Line 1205  namespace LinuxSampler { Line 1219  namespace LinuxSampler {
1219                      false, NO_LIMIT, 0>( args, "change_tune_time" );                      false, NO_LIMIT, 0>( args, "change_tune_time" );
1220      }      }
1221    
1222        // template for change_*_curve() functions
1223    
1224        bool VMChangeFadeCurveFunction::acceptsArgType(int iArg, ExprType_t type) const {
1225            if (iArg == 0)
1226                return type == INT_EXPR || type == INT_ARR_EXPR;
1227            else
1228                return type == INT_EXPR;
1229        }
1230    
1231        template<fade_curve_t NoteBase::_Override::*T_noteParam, int T_synthParam>
1232        VMFnResult* VMChangeFadeCurveFunction::execTemplate(VMFnArgs* args, const char* functionName) {
1233            int value = args->arg(1)->asInt()->evalInt();
1234            switch (value) {
1235                case FADE_CURVE_LINEAR:
1236                case FADE_CURVE_EASE_IN_EASE_OUT:
1237                    break;
1238                default:
1239                    wrnMsg(String(functionName) + "(): invalid curve type passed as argument 2");
1240                    return successResult();
1241            }
1242    
1243            AbstractEngineChannel* pEngineChannel =
1244                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1245    
1246            if (args->arg(0)->exprType() == INT_EXPR) {
1247                const ScriptID id = args->arg(0)->asInt()->evalInt();
1248                if (!id) {
1249                    wrnMsg(String(functionName) + "(): note ID for argument 1 may not be zero");
1250                    return successResult();
1251                }
1252                if (!id.isNoteID()) {
1253                    wrnMsg(String(functionName) + "(): argument 1 is not a note ID");
1254                    return successResult();
1255                }
1256    
1257                NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1258                if (!pNote) return successResult();
1259    
1260                // if this change_*_curve() script function was called immediately after
1261                // note was triggered then immediately apply the synth parameter
1262                // change to Note object
1263                if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {
1264                    pNote->Override.*T_noteParam = (fade_curve_t) value;
1265                } else { // otherwise schedule this synth parameter change ...
1266                    Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
1267                    e.Init(); // clear IDs
1268                    e.Type = Event::type_note_synth_param;
1269                    e.Param.NoteSynthParam.NoteID   = id.noteID();
1270                    e.Param.NoteSynthParam.Type     = (Event::synth_param_t) T_synthParam;
1271                    e.Param.NoteSynthParam.Delta    = value;
1272                    e.Param.NoteSynthParam.Relative = false;
1273    
1274                    pEngineChannel->ScheduleEventMicroSec(&e, 0);
1275                }
1276            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
1277                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
1278                for (int i = 0; i < ids->arraySize(); ++i) {
1279                    const ScriptID id = ids->evalIntElement(i);
1280                    if (!id || !id.isNoteID()) continue;
1281    
1282                    NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1283                    if (!pNote) continue;
1284    
1285                    // if this change_*_curve() script function was called immediately after
1286                    // note was triggered then immediately apply the synth parameter
1287                    // change to Note object
1288                    if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {
1289                        pNote->Override.*T_noteParam = (fade_curve_t) value;
1290                    } else { // otherwise schedule this synth parameter change ...
1291                        Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
1292                        e.Init(); // clear IDs
1293                        e.Type = Event::type_note_synth_param;
1294                        e.Param.NoteSynthParam.NoteID   = id.noteID();
1295                        e.Param.NoteSynthParam.Type     = (Event::synth_param_t) T_synthParam;
1296                        e.Param.NoteSynthParam.Delta    = value;
1297                        e.Param.NoteSynthParam.Relative = false;
1298    
1299                        pEngineChannel->ScheduleEventMicroSec(&e, 0);
1300                    }
1301                }
1302            }
1303    
1304            return successResult();
1305        }
1306    
1307        // change_vol_curve() function
1308    
1309        VMFnResult* InstrumentScriptVMFunction_change_vol_curve::exec(VMFnArgs* args) {
1310            return VMChangeFadeCurveFunction::execTemplate<
1311                        &NoteBase::_Override::VolumeCurve,
1312                        Event::synth_param_volume_curve>( args, "change_vol_curve" );
1313        }
1314    
1315        // change_tune_curve() function
1316    
1317        VMFnResult* InstrumentScriptVMFunction_change_tune_curve::exec(VMFnArgs* args) {
1318            return VMChangeFadeCurveFunction::execTemplate<
1319                        &NoteBase::_Override::PitchCurve,
1320                        Event::synth_param_pitch_curve>( args, "change_tune_curve" );
1321        }
1322    
1323      // fade_in() function      // fade_in() function
1324    
1325      InstrumentScriptVMFunction_fade_in::InstrumentScriptVMFunction_fade_in(InstrumentScriptVM* parent)      InstrumentScriptVMFunction_fade_in::InstrumentScriptVMFunction_fade_in(InstrumentScriptVM* parent)
# Line 1631  namespace LinuxSampler { Line 1746  namespace LinuxSampler {
1746          if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {          if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {
1747              pNote->cause.Param.Note.Key = value;              pNote->cause.Param.Note.Key = value;
1748              m_vm->m_event->cause.Param.Note.Key = value;              m_vm->m_event->cause.Param.Note.Key = value;
1749          } else {          } else {
1750              wrnMsg("change_note(): note number can only be changed when note is new");              wrnMsg("change_note(): note number can only be changed when note is new");
1751          }          }
1752    
# Line 1671  namespace LinuxSampler { Line 1786  namespace LinuxSampler {
1786          if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {          if (m_vm->m_event->scheduleTime == pNote->triggerSchedTime) {
1787              pNote->cause.Param.Note.Velocity = value;              pNote->cause.Param.Note.Velocity = value;
1788              m_vm->m_event->cause.Param.Note.Velocity = value;              m_vm->m_event->cause.Param.Note.Velocity = value;
1789          } else {          } else {
1790              wrnMsg("change_velo(): velocity can only be changed when note is new");              wrnMsg("change_velo(): velocity can only be changed when note is new");
1791          }          }
1792    

Legend:
Removed from v.3214  
changed lines
  Added in v.3246

  ViewVC Help
Powered by ViewVC