--- linuxsampler/trunk/src/engines/common/InstrumentScriptVMDynVars.cpp 2017/01/04 15:49:52 3072 +++ linuxsampler/trunk/src/engines/common/InstrumentScriptVMDynVars.cpp 2017/01/05 16:04:00 3073 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Christian Schoenebeck + * Copyright (c) 2016 - 2017 Christian Schoenebeck * * http://www.linuxsampler.org * @@ -11,9 +11,12 @@ #include "InstrumentScriptVMDynVars.h" #include "InstrumentScriptVM.h" #include "../AbstractEngineChannel.h" +#include "../EngineBase.h" namespace LinuxSampler { + // built-in variable $ENGINE_UPTIME + int InstrumentScriptVMDynVar_ENGINE_UPTIME::evalInt() { AbstractEngineChannel* pEngineChannel = @@ -27,6 +30,8 @@ double(pEngine->SampleRate) * 1000.0 ); } + // built-in variable $NI_CALLBACK_ID + int InstrumentScriptVMDynVar_NI_CALLBACK_ID::evalInt() { AbstractEngineChannel* pEngineChannel = @@ -35,4 +40,43 @@ return pEngineChannel->GetScriptCallbackID(m_vm->m_event); } + // built-in variable %ALL_EVENTS + + InstrumentScriptVMDynVar_ALL_EVENTS::InstrumentScriptVMDynVar_ALL_EVENTS(InstrumentScriptVM* parent) + : m_vm(parent), m_ids(NULL), m_numIDs(0) + { + m_ids = new note_id_t[GLOBAL_MAX_NOTES]; + memset(&m_ids[0], 0, GLOBAL_MAX_NOTES * sizeof(note_id_t)); + } + + InstrumentScriptVMDynVar_ALL_EVENTS::~InstrumentScriptVMDynVar_ALL_EVENTS() { + if (m_ids) delete[] m_ids; + } + + VMIntArrayExpr* InstrumentScriptVMDynVar_ALL_EVENTS::asIntArray() const { + const_cast(this)->updateNoteIDs(); + return const_cast( dynamic_cast(this) ); + } + + int InstrumentScriptVMDynVar_ALL_EVENTS::arraySize() const { + return m_numIDs; + } + + int InstrumentScriptVMDynVar_ALL_EVENTS::evalIntElement(uint i) { + if (i >= m_numIDs) return 0; + return m_ids[i]; + } + + void InstrumentScriptVMDynVar_ALL_EVENTS::updateNoteIDs() { + + AbstractEngineChannel* pEngineChannel = + static_cast(m_vm->m_event->cause.pEngineChannel); + + m_numIDs = pEngineChannel->AllNoteIDs(&m_ids[0], GLOBAL_MAX_NOTES); + + // translate sampler engine internal note IDs to public script id scope + for (uint i = 0; i < m_numIDs; ++i) + m_ids[i] = ScriptID::fromNoteID(m_ids[i]); + } + } // namespace LinuxSampler