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

Contents of /linuxsampler/trunk/src/engines/common/InstrumentScriptVMDynVars.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3293 - (show annotations) (download)
Tue Jun 27 22:19:19 2017 UTC (6 years, 9 months ago) by schoenebeck
File size: 3445 byte(s)
* NKSP: Added built-in script function "fork()".
* NKSP: Added built-in array variable %NKSP_CALLBACK_CHILD_ID[].
* NKSP: Added built-in variable $NKSP_CALLBACK_PARENT_ID.
* NKSP: Fixed potential crash when accessing dynamic built-in
  array variables.
* Bumped version (2.0.0.svn65).

1 /*
2 * Copyright (c) 2016 - 2017 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 "InstrumentScriptVMDynVars.h"
12 #include "InstrumentScriptVM.h"
13 #include "../AbstractEngineChannel.h"
14 #include "../EngineBase.h"
15
16 namespace LinuxSampler {
17
18 // built-in variable $ENGINE_UPTIME
19
20 int InstrumentScriptVMDynVar_ENGINE_UPTIME::evalInt() {
21
22 AbstractEngineChannel* pEngineChannel =
23 static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
24
25 AbstractEngine* pEngine =
26 static_cast<AbstractEngine*>(pEngineChannel->GetEngine());
27
28 // engine's official playback time in milliseconds (offline bounce safe)
29 return int( double(pEngine->FrameTime + m_vm->m_event->cause.FragmentPos()) /
30 double(pEngine->SampleRate) * 1000.0 );
31 }
32
33 // built-in variable $NI_CALLBACK_ID
34
35 int InstrumentScriptVMDynVar_NI_CALLBACK_ID::evalInt() {
36
37 AbstractEngineChannel* pEngineChannel =
38 static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
39
40 return pEngineChannel->GetScriptCallbackID(m_vm->m_event);
41 }
42
43 // built-in array variable %NKSP_CALLBACK_CHILD_ID[]
44
45 InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID::InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID(InstrumentScriptVM* parent)
46 : m_vm(parent)
47 {
48 }
49
50 VMIntArrayExpr* InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID::asIntArray() const {
51 return const_cast<VMIntArrayExpr*>( dynamic_cast<const VMIntArrayExpr*>(this) );
52 }
53
54 int InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID::arraySize() const {
55 return m_vm->m_event->countChildHandlers();
56 }
57
58 int InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID::evalIntElement(uint i) {
59 if (i >= arraySize()) return 0;
60 return m_vm->m_event->childHandlerID[i];
61 }
62
63 // built-in variable %ALL_EVENTS
64
65 InstrumentScriptVMDynVar_ALL_EVENTS::InstrumentScriptVMDynVar_ALL_EVENTS(InstrumentScriptVM* parent)
66 : m_vm(parent), m_ids(NULL), m_numIDs(0)
67 {
68 m_ids = new note_id_t[GLOBAL_MAX_NOTES];
69 memset(&m_ids[0], 0, GLOBAL_MAX_NOTES * sizeof(note_id_t));
70 }
71
72 InstrumentScriptVMDynVar_ALL_EVENTS::~InstrumentScriptVMDynVar_ALL_EVENTS() {
73 if (m_ids) delete[] m_ids;
74 }
75
76 VMIntArrayExpr* InstrumentScriptVMDynVar_ALL_EVENTS::asIntArray() const {
77 const_cast<InstrumentScriptVMDynVar_ALL_EVENTS*>(this)->updateNoteIDs();
78 return const_cast<VMIntArrayExpr*>( dynamic_cast<const VMIntArrayExpr*>(this) );
79 }
80
81 int InstrumentScriptVMDynVar_ALL_EVENTS::arraySize() const {
82 return m_numIDs;
83 }
84
85 int InstrumentScriptVMDynVar_ALL_EVENTS::evalIntElement(uint i) {
86 if (i >= m_numIDs) return 0;
87 return m_ids[i];
88 }
89
90 void InstrumentScriptVMDynVar_ALL_EVENTS::updateNoteIDs() {
91
92 AbstractEngineChannel* pEngineChannel =
93 static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
94
95 m_numIDs = pEngineChannel->AllNoteIDs(&m_ids[0], GLOBAL_MAX_NOTES);
96
97 // translate sampler engine internal note IDs to public script id scope
98 for (uint i = 0; i < m_numIDs; ++i)
99 m_ids[i] = ScriptID::fromNoteID(m_ids[i]);
100 }
101
102 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC