/[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 2600 - (hide annotations) (download)
Sat Jun 7 00:16:03 2014 UTC (3 years, 5 months ago) by schoenebeck
File size: 5197 byte(s)
* Implemented built-in instrument script function "set_controller()".
* Fixed built-in script functions "ignore_event()" and
  "ignore_controller()".
* Added extended instrument script VM for the Gigasampler/GigaStudio format
  sampler engine, which extends the general instrument script VM with Giga
  format specific variables and functions.
* Giga format instrument scripts: added built-in script int constant
  variables $GIG_DIM_CHANNEL, $GIG_DIM_LAYER, $GIG_DIM_VELOCITY,
  $GIG_DIM_AFTERTOUCH, $GIG_DIM_RELEASE, $GIG_DIM_KEYBOARD,
  $GIG_DIM_ROUNDROBIN, $GIG_DIM_RANDOM, $GIG_DIM_SMARTMIDI,
  $GIG_DIM_ROUNDROBINKEY, $GIG_DIM_MODWHEEL, $GIG_DIM_BREATH,
  $GIG_DIM_FOOT, $GIG_DIM_PORTAMENTOTIME, $GIG_DIM_EFFECT1,
  $GIG_DIM_EFFECT2, $GIG_DIM_GENPURPOSE1, $GIG_DIM_GENPURPOSE2,
  $GIG_DIM_GENPURPOSE3, $GIG_DIM_GENPURPOSE4, $GIG_DIM_SUSTAIN,
  $GIG_DIM_PORTAMENTO, $GIG_DIM_SOSTENUTO, $GIG_DIM_SOFT,
  $GIG_DIM_GENPURPOSE5, $GIG_DIM_GENPURPOSE6, $GIG_DIM_GENPURPOSE7,
  $GIG_DIM_GENPURPOSE8, $GIG_DIM_EFFECT1DEPTH, $GIG_DIM_EFFECT2DEPTH,
  $GIG_DIM_EFFECT3DEPTH, $GIG_DIM_EFFECT4DEPTH, $GIG_DIM_EFFECT5DEPTH.
* Giga format instrument scripts: Implemented built-in script function
  "gig_set_dim_zone(event_id, dimension, zone)", which allows to override
  dimension zone(s) for new voices.
* Bumped version (1.0.0.svn45).

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 schoenebeck 2598 return errorResult(-1);
30 schoenebeck 2596 }
31    
32     if (velocity < 0 || velocity > 127) {
33     errMsg("play_note(): argument 2 is an invalid velocity value");
34 schoenebeck 2598 return errorResult(-1);
35 schoenebeck 2596 }
36    
37     if (sampleoffset < 0) {
38     errMsg("play_note(): argument 3 may not be a negative sample offset");
39 schoenebeck 2598 return errorResult(-1);
40 schoenebeck 2596 } 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 schoenebeck 2598 return errorResult(-1);
47 schoenebeck 2596 } 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 schoenebeck 2600 e.Format = {}; // init format speific stuff with zero
61 schoenebeck 2596
62 schoenebeck 2598 int id = pEngineChannel->ScheduleEvent(&e, duration);
63 schoenebeck 2596
64 schoenebeck 2598 return successResult(id);
65     }
66    
67 schoenebeck 2600 InstrumentScriptVMFunction_set_controller::InstrumentScriptVMFunction_set_controller(InstrumentScriptVM* parent)
68     : m_vm(parent)
69     {
70     }
71    
72     VMFnResult* InstrumentScriptVMFunction_set_controller::exec(VMFnArgs* args) {
73     int controller = args->arg(0)->asInt()->evalInt();
74     int value = args->arg(1)->asInt()->evalInt();
75    
76     AbstractEngineChannel* pEngineChannel =
77     static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
78    
79     Event e = m_vm->m_event->cause;
80     e.Format = {}; // init format speific stuff with zero
81     if (controller == CTRL_TABLE_IDX_AFTERTOUCH) {
82     e.Type = Event::type_channel_pressure;
83     e.Param.ChannelPressure.Value = value & 127;
84     } else if (controller == CTRL_TABLE_IDX_PITCHBEND) {
85     e.Type = Event::type_pitchbend;
86     e.Param.Pitch.Pitch = value;
87     } else if (controller >= 0 && controller <= 127) {
88     e.Type = Event::type_control_change;
89     e.Param.CC.Controller = controller;
90     e.Param.CC.Value = value;
91     } else {
92     errMsg("set_controller(): argument 1 is an invalid controller");
93     return errorResult();
94     }
95    
96     int id = pEngineChannel->ScheduleEvent(&e, 0);
97    
98     return successResult(id);
99     }
100    
101 schoenebeck 2598 InstrumentScriptVMFunction_ignore_event::InstrumentScriptVMFunction_ignore_event(InstrumentScriptVM* parent)
102     : m_vm(parent)
103     {
104     }
105    
106     VMFnResult* InstrumentScriptVMFunction_ignore_event::exec(VMFnArgs* args) {
107     int id = args->arg(0)->asInt()->evalInt();
108     if (id < 0) {
109     wrnMsg("ignore_event(): argument may not be a negative event ID");
110     return successResult();
111     }
112    
113     AbstractEngineChannel* pEngineChannel =
114     static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
115    
116     pEngineChannel->IgnoreEvent(id);
117    
118 schoenebeck 2596 return successResult();
119     }
120    
121 schoenebeck 2598 InstrumentScriptVMFunction_ignore_controller::InstrumentScriptVMFunction_ignore_controller(InstrumentScriptVM* parent)
122     : m_vm(parent)
123     {
124     }
125    
126     VMFnResult* InstrumentScriptVMFunction_ignore_controller::exec(VMFnArgs* args) {
127     int id = (args->argsCount() >= 1) ? args->arg(0)->asInt()->evalInt() : m_vm->m_event->id;
128     if (id < 0) {
129     wrnMsg("ignore_controller(): argument may not be a negative event ID");
130     return successResult();
131     }
132    
133     AbstractEngineChannel* pEngineChannel =
134     static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
135    
136     pEngineChannel->IgnoreEvent(id);
137    
138     return successResult();
139     }
140    
141 schoenebeck 2596 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC