1 |
schoenebeck |
2600 |
/* |
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 "EngineChannel.h" |
13 |
|
|
|
14 |
|
|
namespace LinuxSampler { namespace gig { |
15 |
|
|
|
16 |
|
|
///////////////////////////////////////////////////////////////////////// |
17 |
|
|
// Function: |
18 |
|
|
// gig_set_dim_zone(event_id, dimension, zone) |
19 |
|
|
|
20 |
|
|
InstrumentScriptVMFunction_gig_set_dim_zone::InstrumentScriptVMFunction_gig_set_dim_zone(InstrumentScriptVM* parent) |
21 |
|
|
: m_vm(parent) |
22 |
|
|
{ |
23 |
|
|
} |
24 |
|
|
|
25 |
schoenebeck |
2630 |
bool InstrumentScriptVMFunction_gig_set_dim_zone::acceptsArgType(int iArg, ExprType_t type) const { |
26 |
|
|
return type == INT_EXPR || type == INT_ARR_EXPR; |
27 |
|
|
} |
28 |
|
|
|
29 |
schoenebeck |
2600 |
VMFnResult* InstrumentScriptVMFunction_gig_set_dim_zone::exec(VMFnArgs* args) { |
30 |
schoenebeck |
2630 |
EngineChannel* pEngineChannel = |
31 |
|
|
static_cast<EngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
32 |
|
|
|
33 |
schoenebeck |
2600 |
int dim = args->arg(1)->asInt()->evalInt(); |
34 |
|
|
int zone = args->arg(2)->asInt()->evalInt(); |
35 |
|
|
|
36 |
schoenebeck |
2630 |
if (args->arg(0)->exprType() == INT_EXPR) { |
37 |
|
|
int id = args->arg(0)->asInt()->evalInt(); |
38 |
|
|
if (id < 0) { |
39 |
|
|
wrnMsg("gig_set_dim_zone(): argument 1 may not be a negative event ID"); |
40 |
|
|
return successResult(); |
41 |
|
|
} |
42 |
schoenebeck |
2600 |
|
43 |
schoenebeck |
2630 |
RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id); |
44 |
|
|
if (!itEvent) { |
45 |
|
|
dmsg(2,("gig_set_dim_zone(): no active event with ID %d\n", id)); |
46 |
|
|
return successResult(); |
47 |
|
|
} |
48 |
schoenebeck |
2611 |
|
49 |
schoenebeck |
2630 |
int note = itEvent->Param.Note.Key; |
50 |
schoenebeck |
2611 |
|
51 |
schoenebeck |
2630 |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(note); |
52 |
|
|
if (!pRegion) { |
53 |
|
|
dmsg(2,("gig_set_dim_zone(): no region for key %d\n", note)); |
54 |
|
|
return successResult(); |
55 |
|
|
} |
56 |
schoenebeck |
2600 |
|
57 |
schoenebeck |
2630 |
int idx = -1, baseBits = 0; |
58 |
|
|
for (int i = 0; i < pRegion->Dimensions; ++i) { |
59 |
|
|
if (pRegion->pDimensionDefinitions[i].dimension == dim) { |
60 |
|
|
idx = i; |
61 |
|
|
break; |
62 |
|
|
} |
63 |
|
|
baseBits += pRegion->pDimensionDefinitions[i].bits; |
64 |
schoenebeck |
2600 |
} |
65 |
schoenebeck |
2630 |
if (idx < 0) { |
66 |
|
|
dmsg(2,("gig_set_dim_zone(): no such gig dimension %d\n", dim)); |
67 |
|
|
return successResult(); // no such dimension found |
68 |
|
|
} |
69 |
schoenebeck |
2600 |
|
70 |
schoenebeck |
2630 |
int bits = pRegion->pDimensionDefinitions[idx].bits; |
71 |
|
|
int mask = 0; |
72 |
|
|
for (int i = 0; i < bits; ++i) mask |= (1 << (baseBits + i)); |
73 |
schoenebeck |
2600 |
|
74 |
schoenebeck |
2630 |
itEvent->Format.Gig.DimMask |= mask; |
75 |
|
|
itEvent->Format.Gig.DimBits |= (zone << baseBits) & mask; |
76 |
schoenebeck |
2600 |
|
77 |
schoenebeck |
2630 |
dmsg(3,("gig_set_dim_zone(): success, mask=%d bits=%d\n", itEvent->Format.Gig.DimMask, itEvent->Format.Gig.DimBits)); |
78 |
|
|
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
79 |
|
|
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
80 |
|
|
for (int i = 0; i < ids->arraySize(); ++i) { |
81 |
|
|
int id = ids->evalIntElement(i); |
82 |
|
|
if (id < 0) continue; |
83 |
schoenebeck |
2611 |
|
84 |
schoenebeck |
2630 |
RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id); |
85 |
|
|
if (!itEvent) continue; |
86 |
|
|
|
87 |
|
|
int note = itEvent->Param.Note.Key; |
88 |
|
|
|
89 |
|
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(note); |
90 |
|
|
if (!pRegion) continue; |
91 |
|
|
|
92 |
|
|
int idx = -1, baseBits = 0; |
93 |
|
|
for (int i = 0; i < pRegion->Dimensions; ++i) { |
94 |
|
|
if (pRegion->pDimensionDefinitions[i].dimension == dim) { |
95 |
|
|
idx = i; |
96 |
|
|
break; |
97 |
|
|
} |
98 |
|
|
baseBits += pRegion->pDimensionDefinitions[i].bits; |
99 |
|
|
} |
100 |
|
|
if (idx < 0) continue; |
101 |
|
|
|
102 |
|
|
int bits = pRegion->pDimensionDefinitions[idx].bits; |
103 |
|
|
int mask = 0; |
104 |
|
|
for (int i = 0; i < bits; ++i) mask |= (1 << (baseBits + i)); |
105 |
|
|
|
106 |
|
|
itEvent->Format.Gig.DimMask |= mask; |
107 |
|
|
itEvent->Format.Gig.DimBits |= (zone << baseBits) & mask; |
108 |
|
|
|
109 |
|
|
dmsg(3,("gig_set_dim_zone(): success, mask=%d bits=%d\n", itEvent->Format.Gig.DimMask, itEvent->Format.Gig.DimBits)); |
110 |
|
|
} |
111 |
|
|
} |
112 |
|
|
|
113 |
schoenebeck |
2600 |
return successResult(); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
|
}} // namespace LinuxSampler::gig |