/[svn]/linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/InstrumentScriptVMFunctions.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2596 - (hide annotations) (download)
Thu Jun 5 19:39:12 2014 UTC (3 years, 5 months ago) by schoenebeck
File size: 2427 byte(s)
* ScriptVM (WIP): Implemented execution of script event
  handlers "note" and "release".
* ScriptVM (WIP): Implemented built-in script function
  "play_note()" (only two of the max. four function
  arguments are currently implemented yet though).
* ScriptVM (WIP): Fixed incorrect handling of
  suspended scripts.
* Bumped version (1.0.0.svn43).

1 schoenebeck 2596 /*
2     * Copyright (c) 2014 Christian Schoenebeck
3     *
4     * http://www.linuxsampler.org
5     *
6     * This file is part of LinuxSampler and released under the same terms.
7     * See README file for details.
8     */
9    
10     #include "InstrumentScriptVMFunctions.h"
11     #include "InstrumentScriptVM.h"
12     #include "../AbstractEngineChannel.h"
13    
14     namespace LinuxSampler {
15    
16     InstrumentScriptVMFunction_play_note::InstrumentScriptVMFunction_play_note(InstrumentScriptVM* parent)
17     : m_vm(parent)
18     {
19     }
20    
21     VMFnResult* InstrumentScriptVMFunction_play_note::exec(VMFnArgs* args) {
22     int note = args->arg(0)->asInt()->evalInt();
23     int velocity = (args->argsCount() >= 2) ? args->arg(1)->asInt()->evalInt() : 127;
24     int sampleoffset = (args->argsCount() >= 3) ? args->arg(2)->asInt()->evalInt() : 0;
25     int duration = (args->argsCount() >= 4) ? args->arg(3)->asInt()->evalInt() : 0; //TODO: once -1 is implemented, it might be a better default value instead of 0
26    
27     if (note < 0 || note > 127) {
28     errMsg("play_note(): argument 1 is an invalid note number");
29     return errorResult();
30     }
31    
32     if (velocity < 0 || velocity > 127) {
33     errMsg("play_note(): argument 2 is an invalid velocity value");
34     return errorResult();
35     }
36    
37     if (sampleoffset < 0) {
38     errMsg("play_note(): argument 3 may not be a negative sample offset");
39     return errorResult();
40     } else if (sampleoffset != 0) {
41     wrnMsg("play_note(): argument 3 does not support a sample offset other than 0 yet");
42     }
43    
44     if (duration < -1) {
45     errMsg("play_note(): argument 4 must be a duration value of at least -1 or higher");
46     return errorResult();
47     } else if (duration == -1) {
48     wrnMsg("play_note(): argument 4 does not support special value -1 as duration yet");
49     } else if (duration != 0) {
50     wrnMsg("play_note(): argument 4 does not support any other value as 0 as duration yet");
51     }
52    
53     AbstractEngineChannel* pEngineChannel =
54     static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
55    
56     Event e = m_vm->m_event->cause;
57     e.Type = Event::type_note_on;
58     e.Param.Note.Key = note;
59     e.Param.Note.Velocity = velocity;
60    
61     pEngineChannel->ScheduleEvent(&e, duration);
62    
63     return successResult();
64     }
65    
66     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC