/[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 3117 by schoenebeck, Sun Jul 17 17:54:04 2016 UTC revision 3118 by schoenebeck, Fri Apr 21 13:33:03 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2016 Christian Schoenebeck   * Copyright (c) 2014-2017 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 1059  namespace LinuxSampler { Line 1059  namespace LinuxSampler {
1059          return successResult();          return successResult();
1060      }      }
1061    
1062        #define VM_GENERAL_CHANGE_SYNTH_PAR_MAX_VALUE 1000000
1063    
1064        bool VMChangeSynthParamFunction::acceptsArgType(int iArg, ExprType_t type) const {
1065            if (iArg == 0)
1066                return type == INT_EXPR || type == INT_ARR_EXPR;
1067            else
1068                return INT_EXPR;
1069        }
1070    
1071        template<float NoteBase::_Override::*T_noteParam, int T_synthParam>
1072        VMFnResult* VMChangeSynthParamFunction::execTemplate(VMFnArgs* args, const char* functionName) {
1073            int value = args->arg(1)->asInt()->evalInt();
1074            if (value > VM_GENERAL_CHANGE_SYNTH_PAR_MAX_VALUE) {
1075                wrnMsg(String(functionName) + "(): argument 2 may not be larger than 1000000");
1076                value = VM_GENERAL_CHANGE_SYNTH_PAR_MAX_VALUE;
1077            } else if (value < 0) {
1078                wrnMsg(String(functionName) + "(): argument 2 may not be negative");
1079                value = 0;
1080            }
1081            const float fValue = float(value) / float(VM_GENERAL_CHANGE_SYNTH_PAR_MAX_VALUE);
1082    
1083            AbstractEngineChannel* pEngineChannel =
1084                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
1085    
1086            if (args->arg(0)->exprType() == INT_EXPR) {
1087                const ScriptID id = args->arg(0)->asInt()->evalInt();
1088                if (!id) {
1089                    wrnMsg(String(functionName) + "(): note ID for argument 1 may not be zero");
1090                    return successResult();
1091                }
1092                if (!id.isNoteID()) {
1093                    wrnMsg(String(functionName) + "(): argument 1 is not a note ID");
1094                    return successResult();
1095                }
1096    
1097                NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1098                if (!pNote) return successResult();
1099    
1100                // if this change_*() script function was called immediately after
1101                // note was triggered then immediately apply the synth parameter
1102                // change to Note object
1103                if (m_vm->m_event->cause.SchedTime() == pNote->triggerSchedTime) {
1104                    pNote->Override.*T_noteParam = fValue;
1105                } else { // otherwise schedule this synth parameter change ...
1106                    Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
1107                    e.Init(); // clear IDs
1108                    e.Type = Event::type_note_synth_param;
1109                    e.Param.NoteSynthParam.NoteID   = id.noteID();
1110                    e.Param.NoteSynthParam.Type     = (Event::synth_param_t) T_synthParam;
1111                    e.Param.NoteSynthParam.Delta    = fValue;
1112                    e.Param.NoteSynthParam.Relative = false;
1113    
1114                    pEngineChannel->ScheduleEventMicroSec(&e, 0);
1115                }
1116            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
1117                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
1118                for (int i = 0; i < ids->arraySize(); ++i) {
1119                    const ScriptID id = ids->evalIntElement(i);
1120                    if (!id || !id.isNoteID()) continue;
1121    
1122                    NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() );
1123                    if (!pNote) continue;
1124    
1125                    // if this change_*() script function was called immediately after
1126                    // note was triggered then immediately apply the synth parameter
1127                    // change to Note object
1128                    if (m_vm->m_event->cause.SchedTime() == pNote->triggerSchedTime) {
1129                        pNote->Override.*T_noteParam = fValue;
1130                    } else { // otherwise schedule this synth parameter change ...
1131                        Event e = m_vm->m_event->cause; // copy to get fragment time for "now"
1132                        e.Init(); // clear IDs
1133                        e.Type = Event::type_note_synth_param;
1134                        e.Param.NoteSynthParam.NoteID   = id.noteID();
1135                        e.Param.NoteSynthParam.Type     = (Event::synth_param_t) T_synthParam;
1136                        e.Param.NoteSynthParam.Delta    = fValue;
1137                        e.Param.NoteSynthParam.Relative = false;
1138    
1139                        pEngineChannel->ScheduleEventMicroSec(&e, 0);
1140                    }
1141                }
1142            }
1143    
1144            return successResult();
1145        }
1146    
1147        // change_amp_lfo_depth() function
1148    
1149        VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_depth::exec(VMFnArgs* args) {
1150            return VMChangeSynthParamFunction::execTemplate< &NoteBase::_Override::AmpLFODepth, Event::synth_param_amp_lfo_depth >(args, "change_amp_lfo_depth");
1151        }
1152    
1153        // change_amp_lfo_freq() function
1154    
1155        VMFnResult* InstrumentScriptVMFunction_change_amp_lfo_freq::exec(VMFnArgs* args) {
1156            return VMChangeSynthParamFunction::execTemplate< &NoteBase::_Override::AmpLFOFreq, Event::synth_param_amp_lfo_freq >(args, "change_amp_lfo_freq");
1157        }
1158    
1159        // change_pitch_lfo_depth() function
1160    
1161        VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_depth::exec(VMFnArgs* args) {
1162            return VMChangeSynthParamFunction::execTemplate< &NoteBase::_Override::PitchLFODepth, Event::synth_param_pitch_lfo_depth >(args, "change_pitch_lfo_depth");
1163        }
1164    
1165        // change_pitch_lfo_freq() function
1166    
1167        VMFnResult* InstrumentScriptVMFunction_change_pitch_lfo_freq::exec(VMFnArgs* args) {
1168            return VMChangeSynthParamFunction::execTemplate< &NoteBase::_Override::PitchLFOFreq, Event::synth_param_pitch_lfo_freq >(args, "change_pitch_lfo_freq");
1169        }
1170    
1171      // event_status() function      // event_status() function
1172    
1173      InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent)      InstrumentScriptVMFunction_event_status::InstrumentScriptVMFunction_event_status(InstrumentScriptVM* parent)

Legend:
Removed from v.3117  
changed lines
  Added in v.3118

  ViewVC Help
Powered by ViewVC