annotate plugin/RealTimePluginFactory.cpp @ 303:15b47d30c085

* Ensure locale from environment is retained after plugin load, not just C locale
author Chris Cannam
date Fri, 05 Oct 2007 13:26:47 +0000
parents dc46851837d6
children 115f60df1e4d
rev   line source
Chris@49 1 // -*- c-basic-offset: 4 indent-tabs-mode: nil -*-
Chris@0 2
Chris@0 3 /*
Chris@0 4 Rosegarden-4
Chris@0 5 A sequencer and musical notation editor.
Chris@0 6
Chris@17 7 This program is Copyright 2000-2006
Chris@0 8 Guillaume Laurent <glaurent@telegraph-road.org>,
Chris@0 9 Chris Cannam <cannam@all-day-breakfast.com>,
Chris@0 10 Richard Bown <bownie@bownie.com>
Chris@0 11
Chris@0 12 The moral right of the authors to claim authorship of this work
Chris@0 13 has been asserted.
Chris@0 14
Chris@0 15 This program is free software; you can redistribute it and/or
Chris@0 16 modify it under the terms of the GNU General Public License as
Chris@0 17 published by the Free Software Foundation; either version 2 of the
Chris@0 18 License, or (at your option) any later version. See the file
Chris@0 19 COPYING included with this distribution for more information.
Chris@0 20 */
Chris@0 21
Chris@0 22 #include "RealTimePluginFactory.h"
Chris@0 23 #include "PluginIdentifier.h"
Chris@0 24
Chris@0 25 #include "LADSPAPluginFactory.h"
Chris@0 26 #include "DSSIPluginFactory.h"
Chris@0 27
Chris@303 28 #include "system/System.h"
Chris@303 29
Chris@0 30 #include <iostream>
Chris@0 31
Chris@0 32 int RealTimePluginFactory::m_sampleRate = 48000;
Chris@0 33
Chris@0 34 static LADSPAPluginFactory *_ladspaInstance = 0;
Chris@0 35 static LADSPAPluginFactory *_dssiInstance = 0;
Chris@0 36
Chris@259 37 RealTimePluginFactory::~RealTimePluginFactory()
Chris@259 38 {
Chris@259 39 }
Chris@259 40
Chris@0 41 RealTimePluginFactory *
Chris@0 42 RealTimePluginFactory::instance(QString pluginType)
Chris@0 43 {
Chris@0 44 if (pluginType == "ladspa") {
Chris@0 45 if (!_ladspaInstance) {
Chris@117 46 // std::cerr << "RealTimePluginFactory::instance(" << pluginType.toStdString()
Chris@117 47 // << "): creating new LADSPAPluginFactory" << std::endl;
Chris@0 48 _ladspaInstance = new LADSPAPluginFactory();
Chris@0 49 _ladspaInstance->discoverPlugins();
Chris@0 50 }
Chris@0 51 return _ladspaInstance;
Chris@0 52 } else if (pluginType == "dssi") {
Chris@0 53 if (!_dssiInstance) {
Chris@117 54 // std::cerr << "RealTimePluginFactory::instance(" << pluginType.toStdString()
Chris@117 55 // << "): creating new DSSIPluginFactory" << std::endl;
Chris@0 56 _dssiInstance = new DSSIPluginFactory();
Chris@0 57 _dssiInstance->discoverPlugins();
Chris@0 58 }
Chris@0 59 return _dssiInstance;
Chris@0 60 }
Chris@0 61
Chris@0 62 else return 0;
Chris@0 63 }
Chris@0 64
Chris@0 65 RealTimePluginFactory *
Chris@0 66 RealTimePluginFactory::instanceFor(QString identifier)
Chris@0 67 {
Chris@0 68 QString type, soName, label;
Chris@0 69 PluginIdentifier::parseIdentifier(identifier, type, soName, label);
Chris@0 70 return instance(type);
Chris@0 71 }
Chris@0 72
Chris@0 73 std::vector<QString>
Chris@0 74 RealTimePluginFactory::getAllPluginIdentifiers()
Chris@0 75 {
Chris@0 76 RealTimePluginFactory *factory;
Chris@0 77 std::vector<QString> rv;
Chris@0 78
Chris@0 79 // Query DSSI plugins before LADSPA ones.
Chris@0 80 // This is to provide for the interesting possibility of plugins
Chris@0 81 // providing either DSSI or LADSPA versions of themselves,
Chris@0 82 // returning both versions if the LADSPA identifiers are queried
Chris@0 83 // first but only the DSSI version if the DSSI identifiers are
Chris@0 84 // queried first.
Chris@0 85
Chris@0 86 factory = instance("dssi");
Chris@0 87 if (factory) {
Chris@0 88 const std::vector<QString> &tmp = factory->getPluginIdentifiers();
Chris@0 89 for (size_t i = 0; i < tmp.size(); ++i) {
Chris@0 90 rv.push_back(tmp[i]);
Chris@0 91 }
Chris@0 92 }
Chris@0 93
Chris@0 94 factory = instance("ladspa");
Chris@0 95 if (factory) {
Chris@0 96 const std::vector<QString> &tmp = factory->getPluginIdentifiers();
Chris@0 97 for (size_t i = 0; i < tmp.size(); ++i) {
Chris@0 98 rv.push_back(tmp[i]);
Chris@0 99 }
Chris@0 100 }
Chris@0 101
Chris@0 102 // Plugins can change the locale, revert it to default.
Chris@303 103 RestoreStartupLocale();
Chris@303 104
Chris@0 105 return rv;
Chris@0 106 }
Chris@0 107
Chris@0 108 void
Chris@0 109 RealTimePluginFactory::enumerateAllPlugins(std::vector<QString> &list)
Chris@0 110 {
Chris@0 111 RealTimePluginFactory *factory;
Chris@0 112
Chris@0 113 // Query DSSI plugins before LADSPA ones.
Chris@0 114 // This is to provide for the interesting possibility of plugins
Chris@0 115 // providing either DSSI or LADSPA versions of themselves,
Chris@0 116 // returning both versions if the LADSPA identifiers are queried
Chris@0 117 // first but only the DSSI version if the DSSI identifiers are
Chris@0 118 // queried first.
Chris@0 119
Chris@0 120 factory = instance("dssi");
Chris@0 121 if (factory) factory->enumeratePlugins(list);
Chris@0 122
Chris@0 123 factory = instance("ladspa");
Chris@0 124 if (factory) factory->enumeratePlugins(list);
Chris@0 125
Chris@0 126 // Plugins can change the locale, revert it to default.
Chris@0 127 setlocale(LC_ALL, "C");
Chris@0 128 }
Chris@0 129