Chris@49: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@52: Sonic Visualiser Chris@52: An audio file viewer and annotation editor. Chris@52: Centre for Digital Music, Queen Mary, University of London. Chris@0: Chris@52: This program is free software; you can redistribute it and/or Chris@52: modify it under the terms of the GNU General Public License as Chris@52: published by the Free Software Foundation; either version 2 of the Chris@52: License, or (at your option) any later version. See the file Chris@52: COPYING included with this distribution for more information. 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@17: This file copyright 2000-2006 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: Chris@0: #include "api/dssi.h" Chris@0: Chris@0: #include "base/RingBuffer.h" Chris@109: #include "base/Thread.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@237: virtual QString getPluginIdentifier() const { return m_identifier; } Chris@0: int getPosition() const { return m_position; } Chris@0: Chris@239: virtual std::string getIdentifier() const; Chris@51: virtual std::string getName() const; Chris@51: virtual std::string getDescription() const; Chris@51: virtual std::string getMaker() const; Chris@51: virtual int getPluginVersion() const; Chris@51: virtual std::string getCopyright() const; Chris@51: Chris@66: virtual void run(const Vamp::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@383: virtual int getParameterDisplayHint(unsigned int parameter) const; Chris@51: Chris@51: virtual ParameterList getParameterDescriptors() const; Chris@51: virtual float getParameter(std::string) const; Chris@51: virtual void setParameter(std::string, float); Chris@51: Chris@51: virtual std::string configure(std::string key, std::string value); Chris@66: virtual void sendEvent(const Vamp::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@60: virtual size_t getControlOutputCount() const { return m_controlPortsOut.size(); } Chris@60: virtual float getControlOutputValue(size_t n) const; Chris@60: Chris@51: virtual ProgramList getPrograms() const; Chris@51: virtual std::string getCurrentProgram() const; Chris@51: virtual std::string getProgram(int bank, int program) const; Chris@51: virtual unsigned long getProgram(std::string name) const; Chris@51: virtual void selectProgram(std::string 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@57: virtual std::string getType() const { return "DSSI Real-Time Plugin"; } Chris@57: 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: 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@51: void selectProgramAux(std::string program, bool backupPortValues); Chris@0: void checkProgramCache() const; Chris@0: Chris@0: void initialiseGroupMembership(); Chris@66: void runGrouped(const Vamp::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@51: std::string 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@51: std::string m_program; Chris@0: bool m_grouped; Chris@66: Vamp::RealTime m_lastRunTime; Chris@0: Chris@66: Vamp::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@109: class NonRTPluginThread : public Thread 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: