/[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 2871 by schoenebeck, Sun Apr 10 18:22:23 2016 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014 Christian Schoenebeck   * Copyright (c) 2014-2016 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 46  namespace LinuxSampler { Line 46  namespace LinuxSampler {
46              return errorResult(-1);              return errorResult(-1);
47          } else if (duration == -1) {          } else if (duration == -1) {
48              wrnMsg("play_note(): argument 4 does not support special value -1 as duration yet");              wrnMsg("play_note(): argument 4 does not support special value -1 as duration yet");
         } else if (duration != 0) {  
             wrnMsg("play_note(): argument 4 does not support any other value as 0 as duration yet");  
49          }          }
50    
51          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
# Line 57  namespace LinuxSampler { Line 55  namespace LinuxSampler {
55          e.Type = Event::type_note_on;          e.Type = Event::type_note_on;
56          e.Param.Note.Key = note;          e.Param.Note.Key = note;
57          e.Param.Note.Velocity = velocity;          e.Param.Note.Velocity = velocity;
58          memset(&e.Format, 0, sizeof(e.Format)); // init format speific stuff with zero          memset(&e.Format, 0, sizeof(e.Format)); // init format specific stuff with zero
59    
60            int id = pEngineChannel->ScheduleEventMicroSec(&e, 0);
61    
62          int id = pEngineChannel->ScheduleEvent(&e, duration);          // if a duration is supplied, then schedule a subsequent note-ff event
63            if (duration > 0) {
64                e.Type = Event::type_note_off;
65                e.Param.Note.Velocity = 127;
66                pEngineChannel->ScheduleEventMicroSec(&e, duration);
67            }
68    
69          return successResult(id);          return successResult(id);
70      }      }
# Line 93  namespace LinuxSampler { Line 98  namespace LinuxSampler {
98              return errorResult();              return errorResult();
99          }          }
100    
101          int id = pEngineChannel->ScheduleEvent(&e, 0);          int id = pEngineChannel->ScheduleEventMicroSec(&e, 0);
102    
103          return successResult(id);          return successResult(id);
104      }          }    
# Line 103  namespace LinuxSampler { Line 108  namespace LinuxSampler {
108      {      {
109      }      }
110    
111      VMFnResult* InstrumentScriptVMFunction_ignore_event::exec(VMFnArgs* args) {      bool InstrumentScriptVMFunction_ignore_event::acceptsArgType(int iArg, ExprType_t type) const {
112          int id = args->arg(0)->asInt()->evalInt();          return type == INT_EXPR || type == INT_ARR_EXPR;
113          if (id < 0) {      }
             wrnMsg("ignore_event(): argument may not be a negative event ID");  
             return successResult();  
         }  
114    
115        VMFnResult* InstrumentScriptVMFunction_ignore_event::exec(VMFnArgs* args) {
116          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
117              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);                  static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
118    
119          pEngineChannel->IgnoreEvent(id);          if (args->arg(0)->exprType() == INT_EXPR) {
120                int id = args->arg(0)->asInt()->evalInt();
121                if (id < 0) {
122                    wrnMsg("ignore_event(): argument may not be a negative event ID");
123                    return successResult();
124                }
125                pEngineChannel->IgnoreEvent(id);
126            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
127                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
128                for (int i = 0; i < ids->arraySize(); ++i) {
129                    int id = ids->evalIntElement(i);
130                    pEngineChannel->IgnoreEvent(id);
131                }
132            }
133    
134          return successResult();          return successResult();
135      }      }
# Line 143  namespace LinuxSampler { Line 159  namespace LinuxSampler {
159      {      {
160      }      }
161    
162        bool InstrumentScriptVMFunction_note_off::acceptsArgType(int iArg, ExprType_t type) const {
163            return type == INT_EXPR || type == INT_ARR_EXPR;
164        }
165    
166      VMFnResult* InstrumentScriptVMFunction_note_off::exec(VMFnArgs* args) {      VMFnResult* InstrumentScriptVMFunction_note_off::exec(VMFnArgs* args) {
167          int id = args->arg(0)->asInt()->evalInt();          AbstractEngineChannel* pEngineChannel =
168                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
169    
170          int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;          int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;
171            if (velocity < 0 || velocity > 127) {
172                errMsg("note_off(): argument 2 is an invalid velocity value");
173                return errorResult();
174            }
175    
176          if (id < 0) {          if (args->arg(0)->exprType() == INT_EXPR) {
177              wrnMsg("note_off(): argument 1 may not be a negative event ID");              int id = args->arg(0)->asInt()->evalInt();  
178              return successResult();              if (id < 0) {
179                    wrnMsg("note_off(): argument 1 may not be a negative event ID");
180                    return successResult();
181                }
182    
183                RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id);
184                if (!itEvent) return successResult();
185    
186                Event e = *itEvent;
187                e.Type = Event::type_note_off;
188                e.Param.Note.Velocity = velocity;
189                memset(&e.Format, 0, sizeof(e.Format)); // init format speific stuff with zero
190    
191                int releaseEventID = pEngineChannel->ScheduleEventMicroSec(&e, 0);
192            } else if (args->arg(0)->exprType() == INT_ARR_EXPR) {
193                VMIntArrayExpr* ids = args->arg(0)->asIntArray();
194                for (int i = 0; i < ids->arraySize(); ++i) {
195                    int id = ids->evalIntElement(i);
196    
197                    RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id);
198                    if (!itEvent) continue;
199    
200                    Event e = *itEvent;
201                    e.Type = Event::type_note_off;
202                    e.Param.Note.Velocity = velocity;
203                    memset(&e.Format, 0, sizeof(e.Format)); // init format speific stuff with zero
204    
205                    int releaseEventID = pEngineChannel->ScheduleEventMicroSec(&e, 0);
206                }
207          }          }
208    
209          if (velocity < 0 || velocity > 127) {          return successResult();
210              errMsg("note_off(): argument 2 is an invalid velocity value");      }
211    
212        InstrumentScriptVMFunction_set_event_mark::InstrumentScriptVMFunction_set_event_mark(InstrumentScriptVM* parent)
213            : m_vm(parent)
214        {
215        }
216    
217        VMFnResult* InstrumentScriptVMFunction_set_event_mark::exec(VMFnArgs* args) {
218            int eventID = args->arg(0)->asInt()->evalInt();
219            int groupID = args->arg(1)->asInt()->evalInt();
220    
221            if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
222                errMsg("set_event_mark(): argument 2 is an invalid group id");
223              return errorResult();              return errorResult();
224          }          }
225    
226          AbstractEngineChannel* pEngineChannel =          AbstractEngineChannel* pEngineChannel =
227              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);              static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
228    
229          RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id);          RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(eventID);
230          if (!itEvent) return successResult();          if (!itEvent) return successResult();
231    
232          Event e = *itEvent;          pEngineChannel->pScript->eventGroups[groupID].insert(eventID);
         e.Type = Event::type_note_off;  
         e.Param.Note.Velocity = velocity;  
         memset(&e.Format, 0, sizeof(e.Format)); // init format speific stuff with zero  
233    
234          int releaseEventID = pEngineChannel->ScheduleEvent(&e, 0);          return successResult();
235        }
236    
237        InstrumentScriptVMFunction_delete_event_mark::InstrumentScriptVMFunction_delete_event_mark(InstrumentScriptVM* parent)
238            : m_vm(parent)
239        {
240        }
241    
242        VMFnResult* InstrumentScriptVMFunction_delete_event_mark::exec(VMFnArgs* args) {
243            int eventID = args->arg(0)->asInt()->evalInt();
244            int groupID = args->arg(1)->asInt()->evalInt();
245    
246            if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
247                errMsg("delete_event_mark(): argument 2 is an invalid group id");
248                return errorResult();
249            }
250    
251            AbstractEngineChannel* pEngineChannel =
252                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
253    
254            pEngineChannel->pScript->eventGroups[groupID].erase(eventID);
255    
256          return successResult();          return successResult();
257      }      }
258    
259        InstrumentScriptVMFunction_by_marks::InstrumentScriptVMFunction_by_marks(InstrumentScriptVM* parent)
260            : m_vm(parent)
261        {
262        }
263    
264        int InstrumentScriptVMFunction_by_marks::Result::arraySize() const {
265            return eventGroup->size();
266        }
267    
268        int InstrumentScriptVMFunction_by_marks::Result::evalIntElement(uint i) {
269            return (*eventGroup)[i];
270        }
271    
272        VMFnResult* InstrumentScriptVMFunction_by_marks::errorResult() {
273            m_result.eventGroup = NULL;
274            m_result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
275            return &m_result;
276        }
277    
278        VMFnResult* InstrumentScriptVMFunction_by_marks::successResult(EventGroup* eventGroup) {
279            m_result.eventGroup = eventGroup;
280            m_result.flags = STMT_SUCCESS;
281            return &m_result;
282        }
283    
284        VMFnResult* InstrumentScriptVMFunction_by_marks::exec(VMFnArgs* args) {
285            int groupID = args->arg(0)->asInt()->evalInt();
286    
287            if (groupID < 0 || groupID >= INSTR_SCRIPT_EVENT_GROUPS) {
288                errMsg("by_marks(): argument is an invalid group id");
289                return errorResult();
290            }
291    
292            AbstractEngineChannel* pEngineChannel =
293                static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
294    
295            return successResult( &pEngineChannel->pScript->eventGroups[groupID] );
296        }
297    
298  } // namespace LinuxSampler  } // namespace LinuxSampler

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

  ViewVC Help
Powered by ViewVC