/[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 3073 - (show annotations) (download)
Thu Jan 5 16:04:00 2017 UTC (7 years, 2 months ago) by schoenebeck
File size: 2722 byte(s)
* NKSP: Implemented built-in script array variable "%ALL_EVENTS".
* Bumped version (2.0.0.svn35).

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 variable %ALL_EVENTS
44
45 InstrumentScriptVMDynVar_ALL_EVENTS::InstrumentScriptVMDynVar_ALL_EVENTS(InstrumentScriptVM* parent)
46 : m_vm(parent), m_ids(NULL), m_numIDs(0)
47 {
48 m_ids = new note_id_t[GLOBAL_MAX_NOTES];
49 memset(&m_ids[0], 0, GLOBAL_MAX_NOTES * sizeof(note_id_t));
50 }
51
52 InstrumentScriptVMDynVar_ALL_EVENTS::~InstrumentScriptVMDynVar_ALL_EVENTS() {
53 if (m_ids) delete[] m_ids;
54 }
55
56 VMIntArrayExpr* InstrumentScriptVMDynVar_ALL_EVENTS::asIntArray() const {
57 const_cast<InstrumentScriptVMDynVar_ALL_EVENTS*>(this)->updateNoteIDs();
58 return const_cast<VMIntArrayExpr*>( dynamic_cast<const VMIntArrayExpr*>(this) );
59 }
60
61 int InstrumentScriptVMDynVar_ALL_EVENTS::arraySize() const {
62 return m_numIDs;
63 }
64
65 int InstrumentScriptVMDynVar_ALL_EVENTS::evalIntElement(uint i) {
66 if (i >= m_numIDs) return 0;
67 return m_ids[i];
68 }
69
70 void InstrumentScriptVMDynVar_ALL_EVENTS::updateNoteIDs() {
71
72 AbstractEngineChannel* pEngineChannel =
73 static_cast<AbstractEngineChannel*>(m_vm->m_event->cause.pEngineChannel);
74
75 m_numIDs = pEngineChannel->AllNoteIDs(&m_ids[0], GLOBAL_MAX_NOTES);
76
77 // translate sampler engine internal note IDs to public script id scope
78 for (uint i = 0; i < m_numIDs; ++i)
79 m_ids[i] = ScriptID::fromNoteID(m_ids[i]);
80 }
81
82 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC