/[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 2629 by schoenebeck, Thu Jun 12 18:25:11 2014 UTC revision 2630 by schoenebeck, Fri Jun 13 15:01:06 2014 UTC
# Line 103  namespace LinuxSampler { Line 103  namespace LinuxSampler {
103      {      {
104      }      }
105    
106      VMFnResult* InstrumentScriptVMFunction_ignore_event::exec(VMFnArgs* args) {      bool InstrumentScriptVMFunction_ignore_event::acceptsArgType(int iArg, ExprType_t type) const {
107          int id = args->arg(0)->asInt()->evalInt();          return type == INT_EXPR || type == INT_ARR_EXPR;
108          if (id < 0) {      }
             wrnMsg("ignore_event(): argument may not be a negative event ID");  
             return successResult();  
         }  
109    
110        VMFnResult* InstrumentScriptVMFunction_ignore_event::exec(VMFnArgs* args) {
111          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
112              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);                  static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
113    
114          pEngineChannel->IgnoreEvent(id);          if (args->arg(0)->exprType() == INT_EXPR) {
115                int id = args->arg(0)->asInt()->evalInt();
116                if (id < 0) {
117                    wrnMsg("ignore_event(): argument may not be a negative event ID");
118                    return successResult();
119                }
120                pEngineChannel->IgnoreEvent(id);
121            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
122                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
123                for (int i = 0; i < ids->arraySize(); ++i) {
124                    int id = ids->evalIntElement(i);
125                    pEngineChannel->IgnoreEvent(id);
126                }
127            }
128    
129          return successResult();          return successResult();
130      }      }
# Line 143  namespace LinuxSampler { Line 154  namespace LinuxSampler {
154      {      {
155      }      }
156    
157        bool InstrumentScriptVMFunction_note_off::acceptsArgType(int iArg, ExprType_t type) const {
158            return type == INT_EXPR || type == INT_ARR_EXPR;
159        }
160    
161      VMFnResult* InstrumentScriptVMFunction_note_off::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_note_off::exec(VMFnArgs* args) {
162          int id = args->arg(0)->asInt()->evalInt();          AbstractEngineChannel* pEngineChannel =
163                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
164    
165          int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;          int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;
166            if (velocity < 0 || velocity > 127) {
167                errMsg("note_off(): argument 2 is an invalid velocity value");
168                return errorResult();
169            }
170    
171          if (id < 0) {          if (args->arg(0)->exprType() == INT_EXPR) {
172              wrnMsg("note_off(): argument 1 may not be a negative event ID");              int id = args->arg(0)->asInt()->evalInt();  
173              return successResult();              if (id < 0) {
174                    wrnMsg("note_off(): argument 1 may not be a negative event ID");
175                    return successResult();
176                }
177    
178                RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id);
179                if (!itEvent) return successResult();
180    
181                Event e = *itEvent;
182                e.Type = Event::type_note_off;
183                e.Param.Note.Velocity = velocity;
184                memset(&e.Format, 0, sizeof(e.Format)); // init format speific stuff with zero
185    
186                int releaseEventID = pEngineChannel->ScheduleEvent(&e, 0);
187            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
188                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
189                for (int i = 0; i < ids->arraySize(); ++i) {
190                    int id = ids->evalIntElement(i);
191    
192                    RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id);
193                    if (!itEvent) continue;
194    
195                    Event e = *itEvent;
196                    e.Type = Event::type_note_off;
197                    e.Param.Note.Velocity = velocity;
198                    memset(&e.Format, 0, sizeof(e.Format)); // init format speific stuff with zero
199    
200                    int releaseEventID = pEngineChannel->ScheduleEvent(&e, 0);
201                }
202          }          }
203    
204          if (velocity < 0 || velocity > 127) {          return successResult();
205              errMsg("note_off(): argument 2 is an invalid velocity value");      }
206    
207        InstrumentScriptVMFunction_set_event_mark::InstrumentScriptVMFunction_set_event_mark(InstrumentScriptVM* parent)
208            : m_vm(parent)
209        {
210        }
211    
212        VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) {
213            int eventID = args->arg(0)->asInt()->evalInt();
214            int groupID = args->arg(1)->asInt()->evalInt();
215    
216            if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
217                errMsg("set_event_mark(): argument 2 is an invalid group id");
218              return errorResult();              return errorResult();
219          }          }
220    
221          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
222              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
223    
224          RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id);          RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(eventID);
225          if (!itEvent) return successResult();          if (!itEvent) return successResult();
226    
227          Event e = *itEvent;          pEngineChannel->pScript->eventGroups[groupID].insert(eventID);
228          e.Type = Event::type_note_off;  
229          e.Param.Note.Velocity = velocity;          return successResult();
230          memset(&e.Format, 0, sizeof(e.Format)); // init format speific stuff with zero      }
231    
232        InstrumentScriptVMFunction_delete_event_mark::InstrumentScriptVMFunction_delete_event_mark(InstrumentScriptVM* parent)
233            : m_vm(parent)
234        {
235        }
236    
237          int releaseEventID = pEngineChannel->ScheduleEvent(&e, 0);      VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) {
238            int eventID = args->arg(0)->asInt()->evalInt();
239            int groupID = args->arg(1)->asInt()->evalInt();
240    
241            if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
242                errMsg("delete_event_mark(): argument 2 is an invalid group id");
243                return errorResult();
244            }
245    
246            AbstractEngineChannel* pEngineChannel =
247                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
248    
249            pEngineChannel->pScript->eventGroups[groupID].erase(eventID);
250    
251          return successResult();          return successResult();
252      }      }
253    
254        InstrumentScriptVMFunction_by_marks::InstrumentScriptVMFunction_by_marks(InstrumentScriptVM* parent)
255            : m_vm(parent)
256        {
257        }
258    
259        int InstrumentScriptVMFunction_by_marks::Result::arraySize() const {
260            return eventGroup->size();
261        }
262    
263        int InstrumentScriptVMFunction_by_marks::Result::evalIntElement(uint i) {
264            return (*eventGroup)[i];
265        }
266    
267        VMFnResult* InstrumentScriptVMFunction_by_marks::errorResult() {
268            m_result.eventGroup = NULL;
269            m_result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
270            return &m_result;
271        }
272    
273        VMFnResult* InstrumentScriptVMFunction_by_marks::successResult(EventGroup* eventGroup) {
274            m_result.eventGroup = eventGroup;
275            m_result.flags = STMT_SUCCESS;
276            return &m_result;
277        }
278    
279        VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) {
280            int groupID = args->arg(0)->asInt()->evalInt();
281    
282            if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
283                errMsg("by_marks(): argument is an invalid group id");
284                return errorResult();
285            }
286    
287            AbstractEngineChannel* pEngineChannel =
288                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
289    
290            return successResult( &pEngineChannel->pScript->eventGroups[groupID] );
291        }
292    
293  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2629  
changed lines
  Added in v.2630

  ViewVC Help
Powered by ViewVC