1 |
/* |
/* |
2 |
* Copyright (c) 2014 Christian Schoenebeck |
* Copyright (c) 2014-2017 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
22 |
{ |
{ |
23 |
} |
} |
24 |
|
|
25 |
|
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 |
VMFnResult* InstrumentScriptVMFunction_gig_set_dim_zone::exec(VMFnArgs* args) { |
VMFnResult* InstrumentScriptVMFunction_gig_set_dim_zone::exec(VMFnArgs* args) { |
30 |
int id = args->arg(0)->asInt()->evalInt(); |
EngineChannel* pEngineChannel = |
31 |
|
static_cast<EngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
32 |
|
|
33 |
int dim = args->arg(1)->asInt()->evalInt(); |
int dim = args->arg(1)->asInt()->evalInt(); |
34 |
int zone = args->arg(2)->asInt()->evalInt(); |
int zone = args->arg(2)->asInt()->evalInt(); |
35 |
|
|
36 |
if (id < 0) { |
if (args->arg(0)->exprType() == INT_EXPR) { |
37 |
wrnMsg("gig_set_dim_zone(): argument 1 may not be a negative event ID"); |
const ScriptID id = args->arg(0)->asInt()->evalInt(); |
38 |
return successResult(); |
if (!id) { |
39 |
} |
wrnMsg("gig_set_dim_zone(): note ID for argument 1 may not be zero"); |
40 |
|
return successResult(); |
41 |
|
} |
42 |
|
if (!id.isNoteID()) { |
43 |
|
wrnMsg("gig_set_dim_zone(): argument 1 is not a note ID"); |
44 |
|
return successResult(); |
45 |
|
} |
46 |
|
|
47 |
int note = m_vm->m_event->cause.Param.Note.Key; |
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
48 |
|
if (!pNote) { |
49 |
|
dmsg(2,("gig_set_dim_zone(): no active note with ID %d\n", int(id))); |
50 |
|
return successResult(); |
51 |
|
} |
52 |
|
|
53 |
EngineChannel* pEngineChannel = |
int note = pNote->cause.Param.Note.Key; |
|
static_cast<EngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
|
54 |
|
|
55 |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(note); |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(note); |
56 |
if (!pRegion) return successResult(); |
if (!pRegion) { |
57 |
|
dmsg(2,("gig_set_dim_zone(): no region for key %d\n", note)); |
58 |
|
return successResult(); |
59 |
|
} |
60 |
|
|
61 |
int idx = -1, baseBits = 0; |
int idx = -1, baseBits = 0; |
62 |
for (int i = 0; i < pRegion->Dimensions; ++i) { |
for (int i = 0; i < pRegion->Dimensions; ++i) { |
63 |
if (pRegion->pDimensionDefinitions[i].dimension == dim) { |
if (pRegion->pDimensionDefinitions[i].dimension == dim) { |
64 |
idx = i; |
idx = i; |
65 |
break; |
break; |
66 |
|
} |
67 |
|
baseBits += pRegion->pDimensionDefinitions[i].bits; |
68 |
|
} |
69 |
|
if (idx < 0) { |
70 |
|
dmsg(2,("gig_set_dim_zone(): no such gig dimension %d\n", dim)); |
71 |
|
return successResult(); // no such dimension found |
72 |
} |
} |
|
baseBits += pRegion->pDimensionDefinitions[i].bits; |
|
|
} |
|
|
if (idx < 0) return successResult(); // no such dimension found |
|
73 |
|
|
74 |
RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id); |
int bits = pRegion->pDimensionDefinitions[idx].bits; |
75 |
if (!itEvent) return successResult(); |
int mask = 0; |
76 |
|
for (int i = 0; i < bits; ++i) mask |= (1 << (baseBits + i)); |
77 |
|
|
78 |
|
pNote->Format.Gig.DimMask |= mask; |
79 |
|
pNote->Format.Gig.DimBits |= (zone << baseBits) & mask; |
80 |
|
|
81 |
|
dmsg(3,("gig_set_dim_zone(): success, mask=%d bits=%d\n", pNote->Format.Gig.DimMask, pNote->Format.Gig.DimBits)); |
82 |
|
} else if (args->arg(0)->exprType() == INT_ARR_EXPR) { |
83 |
|
VMIntArrayExpr* ids = args->arg(0)->asIntArray(); |
84 |
|
for (int i = 0; i < ids->arraySize(); ++i) { |
85 |
|
const ScriptID id = ids->evalIntElement(i); |
86 |
|
if (!id || !id.isNoteID()) continue; |
87 |
|
|
88 |
|
NoteBase* pNote = pEngineChannel->pEngine->NoteByID( id.noteID() ); |
89 |
|
if (!pNote) continue; |
90 |
|
|
91 |
|
int note = pNote->cause.Param.Note.Key; |
92 |
|
|
93 |
|
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(note); |
94 |
|
if (!pRegion) continue; |
95 |
|
|
96 |
|
int idx = -1, baseBits = 0; |
97 |
|
for (int i = 0; i < pRegion->Dimensions; ++i) { |
98 |
|
if (pRegion->pDimensionDefinitions[i].dimension == dim) { |
99 |
|
idx = i; |
100 |
|
break; |
101 |
|
} |
102 |
|
baseBits += pRegion->pDimensionDefinitions[i].bits; |
103 |
|
} |
104 |
|
if (idx < 0) continue; |
105 |
|
|
106 |
|
int bits = pRegion->pDimensionDefinitions[idx].bits; |
107 |
|
int mask = 0; |
108 |
|
for (int i = 0; i < bits; ++i) mask |= (1 << (baseBits + i)); |
109 |
|
|
110 |
int bits = pRegion->pDimensionDefinitions[idx].bits; |
pNote->Format.Gig.DimMask |= mask; |
111 |
int mask = 0; |
pNote->Format.Gig.DimBits |= (zone << baseBits) & mask; |
|
for (int i = 0; i < bits; ++i) mask |= (1 << (baseBits + i)); |
|
112 |
|
|
113 |
itEvent->Format.Gig.DimMask |= mask; |
dmsg(3,("gig_set_dim_zone(): success, mask=%d bits=%d\n", pNote->Format.Gig.DimMask, pNote->Format.Gig.DimBits)); |
114 |
itEvent->Format.Gig.DimBits |= (zone << baseBits) & mask; |
} |
115 |
|
} |
116 |
|
|
117 |
return successResult(); |
return successResult(); |
118 |
} |
} |
119 |
|
|
120 |
|
///////////////////////////////////////////////////////////////////////// |
121 |
|
// Function: |
122 |
|
// same_region(key1, key2) |
123 |
|
|
124 |
|
InstrumentScriptVMFunction_same_region::InstrumentScriptVMFunction_same_region(InstrumentScriptVM* parent) |
125 |
|
: m_vm(parent) |
126 |
|
{ |
127 |
|
} |
128 |
|
|
129 |
|
VMFnResult* InstrumentScriptVMFunction_same_region::exec(VMFnArgs* args) { |
130 |
|
EngineChannel* pEngineChannel = |
131 |
|
static_cast<EngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
132 |
|
|
133 |
|
int key1 = args->arg(0)->asInt()->evalInt(); |
134 |
|
int key2 = args->arg(1)->asInt()->evalInt(); |
135 |
|
|
136 |
|
if (key1 < 0 || key1 > 127) { |
137 |
|
wrnMsg("same_region(): key number for argument 1 out of range"); |
138 |
|
return successResult(-1); |
139 |
|
} |
140 |
|
if (key2 < 0 || key2 > 127) { |
141 |
|
wrnMsg("same_region(): key number for argument 2 out of range"); |
142 |
|
return successResult(-1); |
143 |
|
} |
144 |
|
|
145 |
|
::gig::Region* pRgn1 = pEngineChannel->pInstrument->GetRegion(key1); |
146 |
|
::gig::Region* pRgn2 = pEngineChannel->pInstrument->GetRegion(key2); |
147 |
|
|
148 |
|
if (!pRgn1 && !pRgn2) |
149 |
|
return successResult(5); |
150 |
|
if (pRgn1 == pRgn2) |
151 |
|
return successResult(1); |
152 |
|
if (pRgn1 && !pRgn2) |
153 |
|
return successResult(3); |
154 |
|
if (!pRgn1 && pRgn2) |
155 |
|
return successResult(4); |
156 |
|
if (pRgn1->KeyRange.overlaps(pRgn2->KeyRange)) |
157 |
|
return successResult(2); |
158 |
|
return successResult(0); |
159 |
|
} |
160 |
|
|
161 |
}} // namespace LinuxSampler::gig |
}} // namespace LinuxSampler::gig |