annotate transform/TransformFactory.h @ 115:90ade4fa63be

* Fix serious failure to reload "imported" (i.e. all non-derived non-main) models from .sv file * Give a short playback duration to notes with formal duration of 0 or 1 * Show crosshairs on spectrogram even when there is another layer on top (if it isn't opaque) * Always paste to the same time in the layer as the cut/copy was from, rather than to the playback pointer -- less flexible, but more predictable and less annoying. We probably need a way to get the old behaviour if pasting from somewhere else in the future (e.g. from a text file), but we can't do that yet anyway * Use a compound operation for dragging and resizing selections, so as to ensure a single undo operation works * Use a note model as the target for feature extraction plugins that output variable samplerate data with more than one value per feature * Avoid possible crashes in cut/paste if a layer proves to have no model
author Chris Cannam
date Thu, 11 May 2006 11:35:46 +0000
parents 9e027aa5b5c3
children 82f529a08cf3
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@52 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@52 9 This program is free software; you can redistribute it and/or
Chris@52 10 modify it under the terms of the GNU General Public License as
Chris@52 11 published by the Free Software Foundation; either version 2 of the
Chris@52 12 License, or (at your option) any later version. See the file
Chris@52 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _TRANSFORM_FACTORY_H_
Chris@0 17 #define _TRANSFORM_FACTORY_H_
Chris@0 18
Chris@0 19 #include "Transform.h"
Chris@0 20
Chris@16 21 #include <map>
Chris@16 22
Chris@79 23 namespace Vamp { class PluginBase; }
Chris@79 24
Chris@0 25 class TransformFactory : public QObject
Chris@0 26 {
Chris@0 27 Q_OBJECT
Chris@0 28
Chris@0 29 public:
Chris@0 30 virtual ~TransformFactory();
Chris@0 31
Chris@0 32 static TransformFactory *instance();
Chris@0 33
Chris@56 34 // The name is intended to be computer-referenceable, and unique
Chris@47 35 // within the application. The description is intended to be
Chris@47 36 // human readable. In principle it doesn't have to be unique, but
Chris@47 37 // the factory will add suffixes to ensure that it is, all the
Chris@60 38 // same (just to avoid user confusion). The friendly name is a
Chris@63 39 // shorter version of the description. The type is also intended
Chris@63 40 // to be user-readable, for use in menus.
Chris@0 41
Chris@0 42 struct TransformDesc {
Chris@56 43 TransformDesc() { }
Chris@63 44 TransformDesc(QString _type, TransformName _name, QString _description,
Chris@60 45 QString _friendlyName, QString _maker,
Chris@63 46 QString _units, bool _configurable) :
Chris@63 47 type(_type), name(_name), description(_description),
Chris@63 48 friendlyName(_friendlyName),
Chris@63 49 maker(_maker), units(_units), configurable(_configurable) { }
Chris@63 50 QString type;
Chris@0 51 TransformName name;
Chris@0 52 QString description;
Chris@60 53 QString friendlyName;
Chris@60 54 QString maker;
Chris@63 55 QString units;
Chris@56 56 bool configurable;
Chris@0 57 };
Chris@0 58 typedef std::vector<TransformDesc> TransformList;
Chris@0 59
Chris@0 60 TransformList getAllTransforms();
Chris@0 61
Chris@63 62 std::vector<QString> getAllTransformTypes();
Chris@63 63
Chris@0 64 /**
Chris@56 65 * Get a configuration XML string for the given transform (by
Chris@56 66 * asking the user, most likely). Returns true if the transform
Chris@56 67 * is acceptable, false if the operation should be cancelled.
Chris@56 68 */
Chris@56 69 bool getConfigurationForTransform(TransformName name, Model *inputModel,
Chris@64 70 int &channel,
Chris@56 71 QString &configurationXml);
Chris@56 72
Chris@56 73 /**
Chris@0 74 * Return the output model resulting from applying the named
Chris@0 75 * transform to the given input model. The transform may still be
Chris@0 76 * working in the background when the model is returned; check the
Chris@0 77 * output model's isReady completion status for more details.
Chris@0 78 *
Chris@0 79 * If the transform is unknown or the input model is not an
Chris@0 80 * appropriate type for the given transform, or if some other
Chris@0 81 * problem occurs, return 0.
Chris@0 82 *
Chris@0 83 * The returned model is owned by the caller and must be deleted
Chris@0 84 * when no longer needed.
Chris@0 85 */
Chris@56 86 Model *transform(TransformName name, Model *inputModel,
Chris@64 87 int channel, QString configurationXml = "");
Chris@0 88
Chris@18 89 /**
Chris@18 90 * Full description of a transform, suitable for putting on a menu.
Chris@18 91 */
Chris@16 92 QString getTransformDescription(TransformName name);
Chris@16 93
Chris@18 94 /**
Chris@18 95 * Brief but friendly description of a transform, suitable for use
Chris@18 96 * as the name of the output layer.
Chris@18 97 */
Chris@18 98 QString getTransformFriendlyName(TransformName name);
Chris@18 99
Chris@63 100 QString getTransformUnits(TransformName name);
Chris@63 101
Chris@57 102 /**
Chris@57 103 * Return true if the transform has any configurable parameters,
Chris@57 104 * i.e. if getConfigurationForTransform can ever return a non-trivial
Chris@57 105 * (not equivalent to empty) configuration string.
Chris@57 106 */
Chris@57 107 bool isTransformConfigurable(TransformName name);
Chris@57 108
Chris@64 109 /**
Chris@64 110 * If the transform has a prescribed number or range of channel
Chris@64 111 * inputs, return true and set minChannels and maxChannels to the
Chris@64 112 * minimum and maximum number of channel inputs the transform can
Chris@64 113 * accept.
Chris@64 114 */
Chris@64 115 bool getTransformChannelRange(TransformName name,
Chris@64 116 int &minChannels, int &maxChannels);
Chris@64 117
Chris@0 118 //!!! Need some way to indicate that the input model has changed /
Chris@0 119 //been deleted so as not to blow up backgrounded transform! -- Or
Chris@0 120 //indeed, if the output model has been deleted -- could equally
Chris@0 121 //well happen!
Chris@0 122
Chris@0 123 //!!! Need transform category!
Chris@0 124
Chris@0 125 protected slots:
Chris@0 126 void transformFinished();
Chris@0 127
Chris@0 128 protected:
Chris@0 129 Transform *createTransform(TransformName name, Model *inputModel,
Chris@64 130 int channel, QString configurationXml, bool start);
Chris@0 131
Chris@56 132 struct TransformIdent
Chris@56 133 {
Chris@56 134 TransformName name;
Chris@56 135 QString configurationXml;
Chris@56 136 };
Chris@56 137
Chris@56 138 typedef std::map<TransformName, QString> TransformConfigurationMap;
Chris@56 139 TransformConfigurationMap m_lastConfigurations;
Chris@56 140
Chris@56 141 typedef std::map<TransformName, TransformDesc> TransformDescriptionMap;
Chris@56 142 TransformDescriptionMap m_transforms;
Chris@56 143
Chris@16 144 void populateTransforms();
Chris@60 145 void populateFeatureExtractionPlugins(TransformDescriptionMap &);
Chris@60 146 void populateRealTimePlugins(TransformDescriptionMap &);
Chris@16 147
Chris@79 148 bool getChannelRange(TransformName name,
Chris@79 149 Vamp::PluginBase *plugin, int &min, int &max);
Chris@79 150
Chris@0 151 static TransformFactory *m_instance;
Chris@0 152 };
Chris@0 153
Chris@0 154
Chris@0 155 #endif