File: RealTimePluginFactory.cpp

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 (136 lines) | stat: -rw-r--r-- 4,179 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
// -*- c-basic-offset: 4 indent-tabs-mode: nil -*-

/*
    Rosegarden-4
    A sequencer and musical notation editor.

    This program is Copyright 2000-2006
        Guillaume Laurent   <glaurent@telegraph-road.org>,
        Chris Cannam        <cannam@all-day-breakfast.com>,
        Richard Bown        <bownie@bownie.com>

    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.
*/

#include "RealTimePluginFactory.h"
#include "PluginIdentifier.h"

#include "LADSPAPluginFactory.h"
#include "DSSIPluginFactory.h"

#include "system/System.h"
#include "base/Profiler.h"

#include <iostream>

namespace sv {

sv_samplerate_t RealTimePluginFactory::m_sampleRate = 48000;

static LADSPAPluginFactory *_ladspaInstance = nullptr;
static LADSPAPluginFactory *_dssiInstance = nullptr;

RealTimePluginFactory::~RealTimePluginFactory()
{
}

RealTimePluginFactory *
RealTimePluginFactory::instance(QString pluginType)
{
    if (pluginType == "ladspa") {
        if (!_ladspaInstance) {
//            SVDEBUG << "RealTimePluginFactory::instance(" << pluginType//                      << "): creating new LADSPAPluginFactory" << endl;
            _ladspaInstance = new LADSPAPluginFactory();
            _ladspaInstance->discoverPlugins();
        }
        return _ladspaInstance;
    } else if (pluginType == "dssi") {
        if (!_dssiInstance) {
//            SVDEBUG << "RealTimePluginFactory::instance(" << pluginType//                      << "): creating new DSSIPluginFactory" << endl;
            _dssiInstance = new DSSIPluginFactory();
            _dssiInstance->discoverPlugins();
        }
        return _dssiInstance;
    }
        
    else return nullptr;
}

RealTimePluginFactory *
RealTimePluginFactory::instanceFor(QString identifier)
{
    QString type, soName, label;
    PluginIdentifier::parseIdentifier(identifier, type, soName, label);
    return instance(type);
}

std::vector<QString>
RealTimePluginFactory::getAllPluginIdentifiers()
{
    Profiler profiler("RealTimePluginFactory::getAllPluginIdentifiers");

    RealTimePluginFactory *factory;
    std::vector<QString> rv;
    
    // Query DSSI plugins before LADSPA ones.
    // This is to provide for the interesting possibility of plugins
    // providing either DSSI or LADSPA versions of themselves,
    // returning both versions if the LADSPA identifiers are queried
    // first but only the DSSI version if the DSSI identifiers are
    // queried first.

    factory = instance("dssi");
    if (factory) {
        const std::vector<QString> &tmp = factory->getPluginIdentifiers();
        for (size_t i = 0; i < tmp.size(); ++i) {
            rv.push_back(tmp[i]);
        }
    }

    factory = instance("ladspa");
    if (factory) {
        const std::vector<QString> &tmp = factory->getPluginIdentifiers();
        for (size_t i = 0; i < tmp.size(); ++i) {
            rv.push_back(tmp[i]);
        }
    }

    // Plugins can change the locale, revert it to default.
    RestoreStartupLocale();

    return rv;
}

void
RealTimePluginFactory::enumerateAllPlugins(std::vector<QString> &list)
{
    Profiler profiler("RealTimePluginFactory::enumerateAllPlugins");

    RealTimePluginFactory *factory;

    // Query DSSI plugins before LADSPA ones.
    // This is to provide for the interesting possibility of plugins
    // providing either DSSI or LADSPA versions of themselves,
    // returning both versions if the LADSPA identifiers are queried
    // first but only the DSSI version if the DSSI identifiers are
    // queried first.

    factory = instance("dssi");
    if (factory) factory->enumeratePlugins(list);

    factory = instance("ladspa");
    if (factory) factory->enumeratePlugins(list);
    
    // Plugins can change the locale, revert it to default.
    RestoreStartupLocale();
}

} // end namespace sv