Chris@0: /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: A waveform viewer and audio annotation editor. Chris@2: Chris Cannam, Queen Mary University of London, 2005-2006 Chris@0: Chris@0: This is experimental software. Not for distribution. Chris@0: */ Chris@0: Chris@0: /* Chris@0: This is a modified version of a source file from the Chris@0: Rosegarden MIDI and audio sequencer and notation editor. Chris@0: This file copyright 2000-2005 Chris Cannam. Chris@0: */ Chris@0: Chris@0: #ifndef _DSSIPLUGININSTANCE_H_ Chris@0: #define _DSSIPLUGININSTANCE_H_ Chris@0: Chris@0: #define DSSI_API_LEVEL 2 Chris@0: Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: #include Chris@0: Chris@0: #include "api/dssi.h" Chris@0: Chris@0: #include "base/RingBuffer.h" Chris@0: #include "RealTimePluginInstance.h" Chris@0: #include "base/Scavenger.h" Chris@0: Chris@0: class DSSIPluginInstance : public RealTimePluginInstance Chris@0: { Chris@0: public: Chris@0: virtual ~DSSIPluginInstance(); Chris@0: Chris@0: virtual bool isOK() const { return m_instanceHandle != 0; } Chris@0: Chris@0: int getClientId() const { return m_client; } Chris@0: virtual QString getIdentifier() const { return m_identifier; } Chris@0: int getPosition() const { return m_position; } Chris@0: Chris@0: virtual void run(const RealTime &); Chris@0: Chris@0: virtual unsigned int getParameterCount() const; Chris@0: virtual void setParameterValue(unsigned int parameter, float value); Chris@0: virtual float getParameterValue(unsigned int parameter) const; Chris@0: virtual float getParameterDefault(unsigned int parameter) const; Chris@0: virtual QString configure(QString key, QString value); Chris@0: virtual void sendEvent(const RealTime &eventTime, Chris@0: const void *event); Chris@10: virtual void clearEvents(); Chris@0: Chris@0: virtual size_t getBufferSize() const { return m_blockSize; } Chris@0: virtual size_t getAudioInputCount() const { return m_audioPortsIn.size(); } Chris@0: virtual size_t getAudioOutputCount() const { return m_idealChannelCount; } Chris@0: virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; } Chris@0: virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; } Chris@0: Chris@0: virtual QStringList getPrograms() const; Chris@0: virtual QString getCurrentProgram() const; Chris@0: virtual QString getProgram(int bank, int program) const; Chris@0: virtual unsigned long getProgram(QString name) const; Chris@0: virtual void selectProgram(QString program); Chris@0: Chris@0: virtual bool isBypassed() const { return m_bypassed; } Chris@0: virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; } Chris@0: Chris@0: virtual size_t getLatency(); Chris@0: Chris@0: virtual void silence(); Chris@0: virtual void discardEvents(); Chris@0: virtual void setIdealChannelCount(size_t channels); // may re-instantiate Chris@0: Chris@0: virtual bool isInGroup() const { return m_grouped; } Chris@0: virtual void detachFromGroup(); Chris@0: Chris@0: protected: Chris@0: // To be constructed only by DSSIPluginFactory Chris@0: friend class DSSIPluginFactory; Chris@0: Chris@0: // Constructor that creates the buffers internally Chris@0: // Chris@0: DSSIPluginInstance(RealTimePluginFactory *factory, Chris@0: int client, Chris@0: QString identifier, Chris@0: int position, Chris@0: unsigned long sampleRate, Chris@0: size_t blockSize, Chris@0: int idealChannelCount, Chris@0: const DSSI_Descriptor* descriptor); Chris@0: Chris@0: // Constructor that uses shared buffers Chris@0: // Chris@0: DSSIPluginInstance(RealTimePluginFactory *factory, Chris@0: int client, Chris@0: QString identifier, Chris@0: int position, Chris@0: unsigned long sampleRate, Chris@0: size_t blockSize, Chris@0: sample_t **inputBuffers, Chris@0: sample_t **outputBuffers, Chris@0: const DSSI_Descriptor* descriptor); Chris@0: Chris@0: void init(); Chris@0: void instantiate(unsigned long sampleRate); Chris@0: void cleanup(); Chris@0: void activate(); Chris@0: void deactivate(); Chris@0: void connectPorts(); Chris@0: Chris@0: bool handleController(snd_seq_event_t *ev); Chris@0: void setPortValueFromController(unsigned int portNumber, int controlValue); Chris@0: void selectProgramAux(QString program, bool backupPortValues); Chris@0: void checkProgramCache() const; Chris@0: Chris@0: void initialiseGroupMembership(); Chris@0: void runGrouped(const RealTime &); Chris@0: Chris@0: // For use in DSSIPluginFactory (set in the DSSI_Host_Descriptor): Chris@0: static int requestMidiSend(LADSPA_Handle instance, Chris@0: unsigned char ports, Chris@0: unsigned char channels); Chris@0: static void midiSend(LADSPA_Handle instance, Chris@0: snd_seq_event_t *events, Chris@0: unsigned long eventCount); Chris@0: static int requestNonRTThread(LADSPA_Handle instance, Chris@0: void (*runFunction)(LADSPA_Handle)); Chris@0: Chris@0: int m_client; Chris@0: int m_position; Chris@0: LADSPA_Handle m_instanceHandle; Chris@0: const DSSI_Descriptor *m_descriptor; Chris@0: Chris@0: std::vector > m_controlPortsIn; Chris@0: std::vector > m_controlPortsOut; Chris@0: Chris@0: std::vector m_backupControlPortsIn; Chris@0: Chris@0: std::map m_controllerMap; Chris@0: Chris@0: std::vector m_audioPortsIn; Chris@0: std::vector m_audioPortsOut; Chris@0: Chris@0: struct ProgramControl { Chris@0: int msb; Chris@0: int lsb; Chris@0: int program; Chris@0: }; Chris@0: ProgramControl m_pending; Chris@0: Chris@0: struct ProgramDescriptor { Chris@0: int bank; Chris@0: int program; Chris@0: QString name; Chris@0: }; Chris@0: mutable std::vector m_cachedPrograms; Chris@0: mutable bool m_programCacheValid; Chris@0: Chris@0: RingBuffer m_eventBuffer; Chris@0: Chris@0: size_t m_blockSize; Chris@0: sample_t **m_inputBuffers; Chris@0: sample_t **m_outputBuffers; Chris@0: bool m_ownBuffers; Chris@0: size_t m_idealChannelCount; Chris@0: size_t m_outputBufferCount; Chris@0: size_t m_sampleRate; Chris@0: float *m_latencyPort; Chris@0: bool m_run; Chris@0: Chris@0: bool m_bypassed; Chris@0: QString m_program; Chris@0: bool m_grouped; Chris@0: RealTime m_lastRunTime; Chris@0: Chris@10: RealTime m_lastEventSendTime; Chris@10: bool m_haveLastEventSendTime; Chris@10: Chris@0: QMutex m_processLock; Chris@0: Chris@0: typedef std::set PluginSet; Chris@0: typedef std::map GroupMap; Chris@0: static GroupMap m_groupMap; Chris@0: static snd_seq_event_t **m_groupLocalEventBuffers; Chris@0: static size_t m_groupLocalEventBufferCount; Chris@0: Chris@0: static Scavenger > m_bufferScavenger; Chris@0: Chris@0: class NonRTPluginThread : public QThread Chris@0: { Chris@0: public: Chris@0: NonRTPluginThread(LADSPA_Handle handle, Chris@0: void (*runFunction)(LADSPA_Handle)) : Chris@0: m_handle(handle), Chris@0: m_runFunction(runFunction), Chris@0: m_exiting(false) { } Chris@0: Chris@0: virtual void run(); Chris@0: void setExiting() { m_exiting = true; } Chris@0: Chris@0: protected: Chris@0: LADSPA_Handle m_handle; Chris@0: void (*m_runFunction)(LADSPA_Handle); Chris@0: bool m_exiting; Chris@0: }; Chris@0: static std::map > m_threads; Chris@0: }; Chris@0: Chris@0: #endif // _DSSIPLUGININSTANCE_H_ Chris@0: