/[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 3218 by schoenebeck, Thu May 25 16:32:17 2017 UTC revision 3246 by schoenebeck, Sun May 28 22:22:56 2017 UTC
# Line 1071  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 1217  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)

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

  ViewVC Help
Powered by ViewVC