/[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 3557 - (show annotations) (download)
Sun Aug 18 00:06:04 2019 UTC (4 years, 8 months ago) by schoenebeck
File size: 3467 byte(s)
* NKSP: Introducing 64 bit support for NKSP integer scripts
  variables (declare $foo).
* Require C++11 compiler support.
* Autoconf: Added m4/ax_cxx_compile_stdcxx.m4 macro which is used
  for checking in configure for C++11 support (as mandatory
  requirement) and automatically adds compiler argument if required
  (e.g. -std=C++11).
* Bumped version (2.1.1.svn3).

1 /*
2 * Copyright (c) 2016 - 2019 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 vmint 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 vmint( 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 vmint 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 vmint InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID::arraySize() const {
55 return m_vm->m_event->countChildHandlers();
56 }
57
58 vmint InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID::evalIntElement(vmuint 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 vmint InstrumentScriptVMDynVar_ALL_EVENTS::arraySize() const {
82 return m_numIDs;
83 }
84
85 vmint InstrumentScriptVMDynVar_ALL_EVENTS::evalIntElement(vmuint 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 (vmuint 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