File: LADSPAPluginInstance.h

package info (click to toggle)
sonic-visualiser 5.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,744 kB
  • sloc: cpp: 158,888; ansic: 11,920; sh: 1,785; makefile: 517; xml: 64; perl: 31
file content (138 lines) | stat: -rw-r--r-- 4,893 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*-  vi:set ts=8 sts=4 sw=4: */

/*
    Sonic Visualiser
    An audio file viewer and annotation editor.
    Centre for Digital Music, Queen Mary, University of London.
    
    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.
*/

/*
   This is a modified version of a source file from the 
   Rosegarden MIDI and audio sequencer and notation editor.
   This file copyright 2000-2006 Chris Cannam and Richard Bown.
*/

#ifndef SV_LADSPAPLUGININSTANCE_H
#define SV_LADSPAPLUGININSTANCE_H

#include <vector>
#include <set>
#include <QString>

#include "api/ladspa.h"
#include "RealTimePluginInstance.h"
#include "base/BaseTypes.h"

// LADSPA plugin instance.  LADSPA is a variable block size API, but
// for one reason and another it's more convenient to use a fixed
// block size in this wrapper.
//
namespace sv {

class LADSPAPluginInstance : public RealTimePluginInstance
{
public:
    virtual ~LADSPAPluginInstance();

    bool isOK() const override { return m_instanceHandles.size() != 0; }

    int getClientId() const { return m_client; }
    QString getPluginIdentifier() const override { return m_identifier; }
    int getPosition() const { return m_position; }

    std::string getIdentifier() const override;
    std::string getName() const override;
    std::string getDescription() const override;
    std::string getMaker() const override;
    int getPluginVersion() const override;
    std::string getCopyright() const override;

    void run(const RealTime &rt, int count = 0) override;

    int getParameterCount() const override;
    void setParameterValue(int parameter, float value) override;
    float getParameterValue(int parameter) const override;
    float getParameterDefault(int parameter) const override;
    int getParameterDisplayHint(int parameter) const override;
    
    ParameterList getParameterDescriptors() const override;
    float getParameter(std::string) const override;
    void setParameter(std::string, float) override;

    int getBufferSize() const override { return m_blockSize; }
    int getAudioInputCount() const override { return int(m_instanceCount * m_audioPortsIn.size()); }
    int getAudioOutputCount() const override { return int(m_instanceCount * m_audioPortsOut.size()); }
    sample_t **getAudioInputBuffers() override { return m_inputBuffers; }
    sample_t **getAudioOutputBuffers() override { return m_outputBuffers; }

    int getControlOutputCount() const override { return int(m_controlPortsOut.size()); }
    float getControlOutputValue(int n) const override;

    bool isBypassed() const override { return m_bypassed; }
    void setBypassed(bool bypassed) override { m_bypassed = bypassed; }

    sv_frame_t getLatency() override;

    void silence() override;
    void setIdealChannelCount(int channels) override; // may re-instantiate

    std::string getType() const override { return "LADSPA Real-Time Plugin"; }

protected:
    // To be constructed only by LADSPAPluginFactory
    friend class LADSPAPluginFactory;

    // Constructor that creates the buffers internally
    // 
    LADSPAPluginInstance(RealTimePluginFactory *factory,
                         int client,
                         QString identifier,
                         int position,
                         sv_samplerate_t sampleRate,
                         int blockSize,
                         int idealChannelCount,
                         const LADSPA_Descriptor* descriptor);

    void init(int idealChannelCount = 0);
    void instantiate(sv_samplerate_t sampleRate);
    void cleanup();
    void activate();
    void deactivate();

    // Connection of data (and behind the scenes control) ports
    //
    void connectPorts();
    
    int                        m_client;
    int                        m_position;
    std::vector<LADSPA_Handle> m_instanceHandles;
    int                        m_instanceCount;
    const LADSPA_Descriptor   *m_descriptor;

    std::vector<std::pair<int, LADSPA_Data*> > m_controlPortsIn;
    std::vector<std::pair<int, LADSPA_Data*> > m_controlPortsOut;

    std::vector<int>          m_audioPortsIn;
    std::vector<int>          m_audioPortsOut;

    int                       m_blockSize;
    sample_t                **m_inputBuffers;
    sample_t                **m_outputBuffers;
    bool                      m_ownBuffers;
    sv_samplerate_t           m_sampleRate;
    float                    *m_latencyPort;
    bool                      m_run;
    
    bool                      m_bypassed;
};

} // end namespace sv

#endif // _LADSPAPLUGININSTANCE_H_