annotate plugin/DSSIPluginInstance.h @ 308:14e0f60435b8

* Make it possible to drop audio files, layer files, session files and images onto SV panes. Need to do a bit more work on where we expect the dropped file to go, particularly in the case of audio files -- at the moment they're always opened in new panes, but it may be better to by default replace whatever is in the target pane.
author Chris Cannam
date Wed, 10 Oct 2007 15:18:02 +0000
parents 71f869dac40b
children ca3b91119482
rev   line source
Chris@49 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@52 4 Sonic Visualiser
Chris@52 5 An audio file viewer and annotation editor.
Chris@52 6 Centre for Digital Music, Queen Mary, University of London.
Chris@0 7
Chris@52 8 This program is free software; you can redistribute it and/or
Chris@52 9 modify it under the terms of the GNU General Public License as
Chris@52 10 published by the Free Software Foundation; either version 2 of the
Chris@52 11 License, or (at your option) any later version. See the file
Chris@52 12 COPYING included with this distribution for more information.
Chris@0 13 */
Chris@0 14
Chris@0 15 /*
Chris@0 16 This is a modified version of a source file from the
Chris@0 17 Rosegarden MIDI and audio sequencer and notation editor.
Chris@17 18 This file copyright 2000-2006 Chris Cannam.
Chris@0 19 */
Chris@0 20
Chris@0 21 #ifndef _DSSIPLUGININSTANCE_H_
Chris@0 22 #define _DSSIPLUGININSTANCE_H_
Chris@0 23
Chris@0 24 #define DSSI_API_LEVEL 2
Chris@0 25
Chris@0 26 #include <vector>
Chris@0 27 #include <set>
Chris@0 28 #include <map>
Chris@0 29 #include <QString>
Chris@0 30 #include <QMutex>
Chris@0 31
Chris@0 32 #include "api/dssi.h"
Chris@0 33
Chris@0 34 #include "base/RingBuffer.h"
Chris@109 35 #include "base/Thread.h"
Chris@0 36 #include "RealTimePluginInstance.h"
Chris@0 37 #include "base/Scavenger.h"
Chris@0 38
Chris@0 39 class DSSIPluginInstance : public RealTimePluginInstance
Chris@0 40 {
Chris@0 41 public:
Chris@0 42 virtual ~DSSIPluginInstance();
Chris@0 43
Chris@0 44 virtual bool isOK() const { return m_instanceHandle != 0; }
Chris@0 45
Chris@0 46 int getClientId() const { return m_client; }
Chris@237 47 virtual QString getPluginIdentifier() const { return m_identifier; }
Chris@0 48 int getPosition() const { return m_position; }
Chris@0 49
Chris@239 50 virtual std::string getIdentifier() const;
Chris@51 51 virtual std::string getName() const;
Chris@51 52 virtual std::string getDescription() const;
Chris@51 53 virtual std::string getMaker() const;
Chris@51 54 virtual int getPluginVersion() const;
Chris@51 55 virtual std::string getCopyright() const;
Chris@51 56
Chris@66 57 virtual void run(const Vamp::RealTime &);
Chris@0 58
Chris@0 59 virtual unsigned int getParameterCount() const;
Chris@0 60 virtual void setParameterValue(unsigned int parameter, float value);
Chris@0 61 virtual float getParameterValue(unsigned int parameter) const;
Chris@0 62 virtual float getParameterDefault(unsigned int parameter) const;
Chris@51 63
Chris@51 64 virtual ParameterList getParameterDescriptors() const;
Chris@51 65 virtual float getParameter(std::string) const;
Chris@51 66 virtual void setParameter(std::string, float);
Chris@51 67
Chris@51 68 virtual std::string configure(std::string key, std::string value);
Chris@66 69 virtual void sendEvent(const Vamp::RealTime &eventTime,
Chris@0 70 const void *event);
Chris@10 71 virtual void clearEvents();
Chris@0 72
Chris@0 73 virtual size_t getBufferSize() const { return m_blockSize; }
Chris@0 74 virtual size_t getAudioInputCount() const { return m_audioPortsIn.size(); }
Chris@0 75 virtual size_t getAudioOutputCount() const { return m_idealChannelCount; }
Chris@0 76 virtual sample_t **getAudioInputBuffers() { return m_inputBuffers; }
Chris@0 77 virtual sample_t **getAudioOutputBuffers() { return m_outputBuffers; }
Chris@0 78
Chris@60 79 virtual size_t getControlOutputCount() const { return m_controlPortsOut.size(); }
Chris@60 80 virtual float getControlOutputValue(size_t n) const;
Chris@60 81
Chris@51 82 virtual ProgramList getPrograms() const;
Chris@51 83 virtual std::string getCurrentProgram() const;
Chris@51 84 virtual std::string getProgram(int bank, int program) const;
Chris@51 85 virtual unsigned long getProgram(std::string name) const;
Chris@51 86 virtual void selectProgram(std::string program);
Chris@0 87
Chris@0 88 virtual bool isBypassed() const { return m_bypassed; }
Chris@0 89 virtual void setBypassed(bool bypassed) { m_bypassed = bypassed; }
Chris@0 90
Chris@0 91 virtual size_t getLatency();
Chris@0 92
Chris@0 93 virtual void silence();
Chris@0 94 virtual void discardEvents();
Chris@0 95 virtual void setIdealChannelCount(size_t channels); // may re-instantiate
Chris@0 96
Chris@0 97 virtual bool isInGroup() const { return m_grouped; }
Chris@0 98 virtual void detachFromGroup();
Chris@0 99
Chris@57 100 virtual std::string getType() const { return "DSSI Real-Time Plugin"; }
Chris@57 101
Chris@0 102 protected:
Chris@0 103 // To be constructed only by DSSIPluginFactory
Chris@0 104 friend class DSSIPluginFactory;
Chris@0 105
Chris@0 106 // Constructor that creates the buffers internally
Chris@0 107 //
Chris@0 108 DSSIPluginInstance(RealTimePluginFactory *factory,
Chris@0 109 int client,
Chris@0 110 QString identifier,
Chris@0 111 int position,
Chris@0 112 unsigned long sampleRate,
Chris@0 113 size_t blockSize,
Chris@0 114 int idealChannelCount,
Chris@0 115 const DSSI_Descriptor* descriptor);
Chris@0 116
Chris@0 117 void init();
Chris@0 118 void instantiate(unsigned long sampleRate);
Chris@0 119 void cleanup();
Chris@0 120 void activate();
Chris@0 121 void deactivate();
Chris@0 122 void connectPorts();
Chris@0 123
Chris@0 124 bool handleController(snd_seq_event_t *ev);
Chris@0 125 void setPortValueFromController(unsigned int portNumber, int controlValue);
Chris@51 126 void selectProgramAux(std::string program, bool backupPortValues);
Chris@0 127 void checkProgramCache() const;
Chris@0 128
Chris@0 129 void initialiseGroupMembership();
Chris@66 130 void runGrouped(const Vamp::RealTime &);
Chris@0 131
Chris@0 132 // For use in DSSIPluginFactory (set in the DSSI_Host_Descriptor):
Chris@0 133 static int requestMidiSend(LADSPA_Handle instance,
Chris@0 134 unsigned char ports,
Chris@0 135 unsigned char channels);
Chris@0 136 static void midiSend(LADSPA_Handle instance,
Chris@0 137 snd_seq_event_t *events,
Chris@0 138 unsigned long eventCount);
Chris@0 139 static int requestNonRTThread(LADSPA_Handle instance,
Chris@0 140 void (*runFunction)(LADSPA_Handle));
Chris@0 141
Chris@0 142 int m_client;
Chris@0 143 int m_position;
Chris@0 144 LADSPA_Handle m_instanceHandle;
Chris@0 145 const DSSI_Descriptor *m_descriptor;
Chris@0 146
Chris@0 147 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsIn;
Chris@0 148 std::vector<std::pair<unsigned long, LADSPA_Data*> > m_controlPortsOut;
Chris@0 149
Chris@0 150 std::vector<LADSPA_Data> m_backupControlPortsIn;
Chris@0 151
Chris@0 152 std::map<int, int> m_controllerMap;
Chris@0 153
Chris@0 154 std::vector<int> m_audioPortsIn;
Chris@0 155 std::vector<int> m_audioPortsOut;
Chris@0 156
Chris@0 157 struct ProgramControl {
Chris@0 158 int msb;
Chris@0 159 int lsb;
Chris@0 160 int program;
Chris@0 161 };
Chris@0 162 ProgramControl m_pending;
Chris@0 163
Chris@0 164 struct ProgramDescriptor {
Chris@0 165 int bank;
Chris@0 166 int program;
Chris@51 167 std::string name;
Chris@0 168 };
Chris@0 169 mutable std::vector<ProgramDescriptor> m_cachedPrograms;
Chris@0 170 mutable bool m_programCacheValid;
Chris@0 171
Chris@0 172 RingBuffer<snd_seq_event_t> m_eventBuffer;
Chris@0 173
Chris@0 174 size_t m_blockSize;
Chris@0 175 sample_t **m_inputBuffers;
Chris@0 176 sample_t **m_outputBuffers;
Chris@0 177 bool m_ownBuffers;
Chris@0 178 size_t m_idealChannelCount;
Chris@0 179 size_t m_outputBufferCount;
Chris@0 180 size_t m_sampleRate;
Chris@0 181 float *m_latencyPort;
Chris@0 182 bool m_run;
Chris@0 183
Chris@0 184 bool m_bypassed;
Chris@51 185 std::string m_program;
Chris@0 186 bool m_grouped;
Chris@66 187 Vamp::RealTime m_lastRunTime;
Chris@0 188
Chris@66 189 Vamp::RealTime m_lastEventSendTime;
Chris@10 190 bool m_haveLastEventSendTime;
Chris@10 191
Chris@0 192 QMutex m_processLock;
Chris@0 193
Chris@0 194 typedef std::set<DSSIPluginInstance *> PluginSet;
Chris@0 195 typedef std::map<QString, PluginSet> GroupMap;
Chris@0 196 static GroupMap m_groupMap;
Chris@0 197 static snd_seq_event_t **m_groupLocalEventBuffers;
Chris@0 198 static size_t m_groupLocalEventBufferCount;
Chris@0 199
Chris@0 200 static Scavenger<ScavengerArrayWrapper<snd_seq_event_t *> > m_bufferScavenger;
Chris@0 201
Chris@109 202 class NonRTPluginThread : public Thread
Chris@0 203 {
Chris@0 204 public:
Chris@0 205 NonRTPluginThread(LADSPA_Handle handle,
Chris@0 206 void (*runFunction)(LADSPA_Handle)) :
Chris@0 207 m_handle(handle),
Chris@0 208 m_runFunction(runFunction),
Chris@0 209 m_exiting(false) { }
Chris@0 210
Chris@0 211 virtual void run();
Chris@0 212 void setExiting() { m_exiting = true; }
Chris@0 213
Chris@0 214 protected:
Chris@0 215 LADSPA_Handle m_handle;
Chris@0 216 void (*m_runFunction)(LADSPA_Handle);
Chris@0 217 bool m_exiting;
Chris@0 218 };
Chris@0 219 static std::map<LADSPA_Handle, std::set<NonRTPluginThread *> > m_threads;
Chris@0 220 };
Chris@0 221
Chris@0 222 #endif // _DSSIPLUGININSTANCE_H_
Chris@0 223