Plugin.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /*
  2. * Plugin.h - class plugin, the base-class and generic interface for all plugins
  3. *
  4. * Copyright (c) 2005-2014 Tobias Doerffel <tobydox/at/users.sourceforge.net>
  5. *
  6. * This file is part of LMMS - https://lmms.io
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public
  10. * License as published by the Free Software Foundation; either
  11. * version 2 of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public
  19. * License along with this program (see COPYING); if not, write to the
  20. * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  21. * Boston, MA 02110-1301 USA.
  22. *
  23. */
  24. #ifndef PLUGIN_H
  25. #define PLUGIN_H
  26. #include <QtCore/QStringList>
  27. #include <QtCore/QMap>
  28. #include <QtXml/QDomDocument>
  29. #include "JournallingObject.h"
  30. #include "Model.h"
  31. #include "MemoryManager.h"
  32. class QWidget;
  33. class PixmapLoader;
  34. class PluginView;
  35. class AutomatableModel;
  36. class EXPORT Plugin : public Model, public JournallingObject
  37. {
  38. MM_OPERATORS
  39. Q_OBJECT
  40. public:
  41. enum PluginTypes
  42. {
  43. Instrument, // instrument being used in channel-track
  44. Effect, // effect-plugin for effect-board
  45. ImportFilter, // filter for importing a file
  46. ExportFilter, // filter for exporting a file
  47. Tool, // additional tool (level-meter etc)
  48. Library, // simple library holding a code-base for
  49. // several other plugins (e.g. VST-support)
  50. Other,
  51. Undefined = 255
  52. } ;
  53. // descriptor holds information about a plugin - every external plugin
  54. // has to instantiate such a descriptor in an extern "C"-section so that
  55. // the plugin-loader is able to access information about the plugin
  56. struct Descriptor
  57. {
  58. const char * name;
  59. const char * displayName;
  60. const char * description;
  61. const char * author;
  62. int version;
  63. PluginTypes type;
  64. const PixmapLoader * logo;
  65. const char * supportedFileTypes;
  66. inline bool supportsFileType( const QString& extension ) const
  67. {
  68. return QString( supportedFileTypes ).split( QChar( ',' ) ).contains( extension );
  69. }
  70. class EXPORT SubPluginFeatures
  71. {
  72. public:
  73. struct Key
  74. {
  75. typedef QMap<QString, QString> AttributeMap;
  76. inline Key( const Plugin::Descriptor * desc = NULL,
  77. const QString & name = QString(),
  78. const AttributeMap & am = AttributeMap() )
  79. :
  80. desc( desc ),
  81. name( name ),
  82. attributes( am )
  83. {
  84. }
  85. Key( const QDomElement & key );
  86. QDomElement saveXML( QDomDocument & doc ) const;
  87. inline bool isValid() const
  88. {
  89. return desc != NULL && name.isNull() == false;
  90. }
  91. const Plugin::Descriptor* desc;
  92. QString name;
  93. AttributeMap attributes;
  94. } ;
  95. typedef QList<Key> KeyList;
  96. SubPluginFeatures( Plugin::PluginTypes type ) :
  97. m_type( type )
  98. {
  99. }
  100. virtual ~SubPluginFeatures()
  101. {
  102. }
  103. virtual void fillDescriptionWidget( QWidget *, const Key * ) const
  104. {
  105. }
  106. virtual void listSubPluginKeys( const Plugin::Descriptor *, KeyList & ) const
  107. {
  108. }
  109. protected:
  110. const Plugin::PluginTypes m_type;
  111. } ;
  112. SubPluginFeatures * subPluginFeatures;
  113. } ;
  114. // typedef a list so we can easily work with list of plugin descriptors
  115. typedef QList<Descriptor*> DescriptorList;
  116. // contructor of a plugin
  117. Plugin( const Descriptor * descriptor, Model * parent );
  118. virtual ~Plugin();
  119. // returns display-name out of descriptor
  120. virtual QString displayName() const
  121. {
  122. return Model::displayName().isEmpty()
  123. ? m_descriptor->displayName
  124. : Model::displayName();
  125. }
  126. // return plugin-type
  127. inline PluginTypes type( void ) const
  128. {
  129. return m_descriptor->type;
  130. }
  131. // return plugin-descriptor for further information
  132. inline const Descriptor * descriptor() const
  133. {
  134. return m_descriptor;
  135. }
  136. // can be called if a file matching supportedFileTypes should be
  137. // loaded/processed with the help of this plugin
  138. virtual void loadFile( const QString & file );
  139. // Called if external source needs to change something but we cannot
  140. // reference the class header. Should return null if not key not found.
  141. virtual AutomatableModel* childModel( const QString & modelName );
  142. // returns an instance of a plugin whose name matches to given one
  143. // if specified plugin couldn't be loaded, it creates a dummy-plugin
  144. static Plugin * instantiate( const QString& pluginName, Model * parent, void * data );
  145. // create a view for the model
  146. PluginView * createView( QWidget * parent );
  147. protected:
  148. // create a view for the model
  149. virtual PluginView* instantiateView( QWidget * ) = 0;
  150. void collectErrorForUI( QString errMsg );
  151. private:
  152. const Descriptor * m_descriptor;
  153. // pointer to instantiation-function in plugin
  154. typedef Plugin * ( * InstantiationHook )( Model * , void * );
  155. } ;
  156. #endif