1 |
/* |
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 |
VMFnResult* InstrumentScriptVMFunction_gig_set_dim_zone::exec(VMFnArgs* args) { |
26 |
int id = args->arg(0)->asInt()->evalInt(); |
27 |
int dim = args->arg(1)->asInt()->evalInt(); |
28 |
int zone = args->arg(2)->asInt()->evalInt(); |
29 |
|
30 |
if (id < 0) { |
31 |
wrnMsg("gig_set_dim_zone(): argument 1 may not be a negative event ID"); |
32 |
return successResult(); |
33 |
} |
34 |
|
35 |
EngineChannel* pEngineChannel = |
36 |
static_cast<EngineChannel*>(m_vm->m_event->cause.pEngineChannel); |
37 |
|
38 |
RTList<Event>::Iterator itEvent = pEngineChannel->pEngine->EventByID(id); |
39 |
if (!itEvent) { |
40 |
dmsg(2,("gig_set_dim_zone(): no active event with ID %d\n", id)); |
41 |
return successResult(); |
42 |
} |
43 |
|
44 |
int note = itEvent->Param.Note.Key; |
45 |
|
46 |
::gig::Region* pRegion = pEngineChannel->pInstrument->GetRegion(note); |
47 |
if (!pRegion) { |
48 |
dmsg(2,("gig_set_dim_zone(): no region for key %d\n", note)); |
49 |
return successResult(); |
50 |
} |
51 |
|
52 |
int idx = -1, baseBits = 0; |
53 |
for (int i = 0; i < pRegion->Dimensions; ++i) { |
54 |
if (pRegion->pDimensionDefinitions[i].dimension == dim) { |
55 |
idx = i; |
56 |
break; |
57 |
} |
58 |
baseBits += pRegion->pDimensionDefinitions[i].bits; |
59 |
} |
60 |
if (idx < 0) { |
61 |
dmsg(2,("gig_set_dim_zone(): no such gig dimension %d\n", dim)); |
62 |
return successResult(); // no such dimension found |
63 |
} |
64 |
|
65 |
int bits = pRegion->pDimensionDefinitions[idx].bits; |
66 |
int mask = 0; |
67 |
for (int i = 0; i < bits; ++i) mask |= (1 << (baseBits + i)); |
68 |
|
69 |
itEvent->Format.Gig.DimMask |= mask; |
70 |
itEvent->Format.Gig.DimBits |= (zone << baseBits) & mask; |
71 |
|
72 |
dmsg(3,("gig_set_dim_zone(): success, mask=%d bits=%d\n", itEvent->Format.Gig.DimMask, itEvent->Format.Gig.DimBits)); |
73 |
|
74 |
return successResult(); |
75 |
} |
76 |
|
77 |
}} // namespace LinuxSampler::gig |