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

Diff of /linuxsampler/trunk/src/engines/AbstractEngineChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2593 by schoenebeck, Sun May 18 17:38:25 2014 UTC revision 2594 by schoenebeck, Thu Jun 5 00:16:25 2014 UTC
# Line 46  namespace LinuxSampler { Line 46  namespace LinuxSampler {
46          ResetControllers();          ResetControllers();
47          PortamentoMode = false;          PortamentoMode = false;
48          PortamentoTime = CONFIG_PORTAMENTO_TIME_DEFAULT;          PortamentoTime = CONFIG_PORTAMENTO_TIME_DEFAULT;
49            pScriptEvents = NULL;
50      }      }
51    
52      AbstractEngineChannel::~AbstractEngineChannel() {      AbstractEngineChannel::~AbstractEngineChannel() {
53            unloadCurrentInstrumentScript();
54            if (pScriptEvents) delete pScriptEvents;
55          delete pEventQueue;          delete pEventQueue;
56          DeleteGroupEventLists();          DeleteGroupEventLists();
57          RemoveAllFxSends();          RemoveAllFxSends();
# Line 142  namespace LinuxSampler { Line 145  namespace LinuxSampler {
145      }      }
146    
147      /**      /**
148         * Loads the real-time instrument script given by @a text on this engine
149         * channel. A resource manager is used to allocate and share equivalent
150         * scripts on multiple engine channels.
151         *
152         * @param text - source code of script
153         */
154        void AbstractEngineChannel::loadInstrumentScript(const String& text) {
155            dmsg(1,("Loading real-time instrument script ... "));
156    
157            // hand back old script reference and VM execution contexts
158            // (if not done already)
159            unloadCurrentInstrumentScript();
160    
161            // get new script reference
162            script.parserContext = pEngine->scripts.Borrow(text, this);
163            if (!script.parserContext->errors().empty()) {
164                std::vector<ParserIssue> errors = script.parserContext->errors();
165                std::cerr << "[ScriptVM] Could not load instrument script, there were "
166                          << errors.size() << " parser errors:\n";
167                for (int i = 0; i < errors.size(); ++i)
168                    errors[i].dump();
169                return; // stop here if there were any parser errors
170            }
171    
172            script.handlerInit = script.parserContext->eventHandlerByName("init");
173            script.handlerNote = script.parserContext->eventHandlerByName("note");
174            script.handlerController = script.parserContext->eventHandlerByName("controller");
175            script.bHasValidScript =
176                script.handlerInit || script.handlerNote || script.handlerController;
177    
178            // amount of script handlers each script event has to execute
179            int handlerExecCount = 0;
180            if (script.handlerInit) handlerExecCount++;
181            if (script.handlerNote || script.handlerController) handlerExecCount++;
182    
183            // create script event pool (if it doesn't exist already)
184            if (!pScriptEvents)
185                pScriptEvents = new Pool<ScriptEvent>(CONFIG_MAX_EVENTS_PER_FRAGMENT);
186    
187            // create new VM execution contexts for new script
188            while (!pScriptEvents->poolIsEmpty()) {
189                RTList<ScriptEvent>::Iterator it = pScriptEvents->allocAppend();
190                it->execCtx = pEngine->pScriptVM->createExecContext(
191                    script.parserContext
192                );
193                it->handlers = new VMEventHandler*[handlerExecCount+1];
194            }
195            pScriptEvents->clear();
196    
197            dmsg(1,("Done\n"));
198        }
199    
200        /**
201         * Unloads the currently used real-time instrument script on this sampler
202         * channel. A resource manager is used to share equivalent scripts among
203         * multiple sampler channels, and to deallocate the parsed script once not
204         * used on any engine channel anymore.
205         */
206        void AbstractEngineChannel::unloadCurrentInstrumentScript() {
207            if (script.parserContext)
208                dmsg(1,("Unloading current instrument script."));
209    
210            // free allocated VM execution contexts
211            if (pScriptEvents) {
212                pScriptEvents->clear();
213                while (!pScriptEvents->poolIsEmpty()) {
214                    RTList<ScriptEvent>::Iterator it = pScriptEvents->allocAppend();
215                    if (it->execCtx) {
216                        // free VM execution context object
217                        delete it->execCtx;
218                        it->execCtx = NULL;
219                        // free C array of handler pointers
220                        delete [] it->handlers;
221                    }
222                }
223                pScriptEvents->clear();
224            }
225            // hand back VM representation of script
226            if (script.parserContext) {
227                pEngine->scripts.HandBack(script.parserContext, this);
228                script.parserContext = NULL;
229                script.handlerInit = NULL;
230                script.handlerNote = NULL;
231                script.handlerController = NULL;
232            }
233            script.bHasValidScript = false;
234        }
235    
236        /**
237       * Implementation of virtual method from abstract EngineChannel interface.       * Implementation of virtual method from abstract EngineChannel interface.
238       * This method will periodically be polled (e.g. by the LSCP server) to       * This method will periodically be polled (e.g. by the LSCP server) to
239       * check if some engine channel parameter has changed since the last       * check if some engine channel parameter has changed since the last

Legend:
Removed from v.2593  
changed lines
  Added in v.2594

  ViewVC Help
Powered by ViewVC