// -*- c-basic-offset: 4 -*- /* Rosegarden A sequencer and musical notation editor. This program is Copyright 2000-2008 Guillaume Laurent , Chris Cannam , Richard Bown The moral right of the authors to claim authorship of this work has been asserted. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the file COPYING included with this distribution for more information. */ #ifndef _DSSIPLUGININSTANCE_H_ #define _DSSIPLUGININSTANCE_H_ #include #include #include #include #include "Instrument.h" #ifdef HAVE_DSSI #include #include "RingBuffer.h" #include "RunnablePluginInstance.h" #include "Scavenger.h" #include namespace Rosegarden { class DSSIPluginInstance : public RunnablePluginInstance { public: virtual ~DSSIPluginInstance(); virtual bool isOK() const { return m_instanceHandle != 0; } InstrumentId getInstrument() const { return m_instrument; } virtual QString getIdentifier() const { return m_identifier; } int getPosition() const { return m_position; } virtual void run(const RealTime &); virtual void setPortValue(unsigned int portNumber, float value); virtual float getPortValue(unsigned int portNumber); virtual QString configure(QString key, QString value); virtual void sendEvent(const RealTime &eventTime, const void *event); virtual size_t getBufferSize() { return m_blockSize; } virtual size_t getAudioInputCount() { return m_audioPortsIn.size(); } virtual size_t getAudioOutputCount() { return m_idealChannelCount; } virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; } virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; } virtual QStringList getPrograms(); virtual QString getCurrentProgram(); virtual QString getProgram(int bank, int program); virtual unsigned long getProgram(QString name); virtual void selectProgram(QString program); virtual bool isBypassed() const { return m_bypassed; } virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; } virtual size_t getLatency(); virtual void silence(); virtual void discardEvents(); virtual void setIdealChannelCount(size_t channels); // may re-instantiate virtual bool isInGroup() const { return m_grouped; } virtual void detachFromGroup(); protected: // To be constructed only by DSSIPluginFactory friend class DSSIPluginFactory; // Constructor that creates the buffers internally // DSSIPluginInstance(PluginFactory *factory, InstrumentId instrument, QString identifier, int position, unsigned long sampleRate, size_t blockSize, int idealChannelCount, const DSSI_Descriptor* descriptor); // Constructor that uses shared buffers // DSSIPluginInstance(PluginFactory *factory, InstrumentId instrument, QString identifier, int position, unsigned long sampleRate, size_t blockSize, sample_t **inputBuffers, sample_t **outputBuffers, const DSSI_Descriptor* descriptor); void init(); void instantiate(unsigned long sampleRate); void cleanup(); void activate(); void deactivate(); void connectPorts(); bool handleController(snd_seq_event_t *ev); void setPortValueFromController(unsigned int portNumber, int controlValue); void selectProgramAux(QString program, bool backupPortValues); void checkProgramCache(); void initialiseGroupMembership(); void runGrouped(const RealTime &); InstrumentId m_instrument; int m_position; LADSPA_Handle m_instanceHandle; const DSSI_Descriptor *m_descriptor; std::vector > m_controlPortsIn; std::vector > m_controlPortsOut; std::vector m_backupControlPortsIn; std::vector m_portChangedSinceProgramChange; std::map m_controllerMap; std::vector m_audioPortsIn; std::vector m_audioPortsOut; struct ProgramControl { int msb; int lsb; int program; }; ProgramControl m_pending; struct ProgramDescriptor { int bank; int program; QString name; }; std::vector m_cachedPrograms; bool m_programCacheValid; RingBuffer m_eventBuffer; size_t m_blockSize; sample_t **m_inputBuffers; sample_t **m_outputBuffers; bool m_ownBuffers; size_t m_idealChannelCount; size_t m_outputBufferCount; size_t m_sampleRate; float *m_latencyPort; bool m_run; bool m_runSinceReset; bool m_bypassed; QString m_program; bool m_grouped; RealTime m_lastRunTime; pthread_mutex_t m_processLock; typedef std::set PluginSet; typedef std::map GroupMap; static GroupMap m_groupMap; static snd_seq_event_t **m_groupLocalEventBuffers; static size_t m_groupLocalEventBufferCount; static Scavenger > m_bufferScavenger; }; }; #endif // HAVE_DSSI #endif // _DSSIPLUGININSTANCE_H_