annotate audioio/AudioGenerator.h @ 54:a798f5e6fc5e

* Further naming change: Transformer -> ModelTransformer. The Transform class now describes a thing that can be done, and the ModelTransformer does it to a Model.
author Chris Cannam
date Wed, 07 Nov 2007 12:59:01 +0000
parents 3c5756fb6a68
children e25e8f5d785b
rev   line source
Chris@43 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@43 2
Chris@43 3 /*
Chris@43 4 Sonic Visualiser
Chris@43 5 An audio file viewer and annotation editor.
Chris@43 6 Centre for Digital Music, Queen Mary, University of London.
Chris@43 7 This file copyright 2006 Chris Cannam.
Chris@43 8
Chris@43 9 This program is free software; you can redistribute it and/or
Chris@43 10 modify it under the terms of the GNU General Public License as
Chris@43 11 published by the Free Software Foundation; either version 2 of the
Chris@43 12 License, or (at your option) any later version. See the file
Chris@43 13 COPYING included with this distribution for more information.
Chris@43 14 */
Chris@43 15
Chris@43 16 #ifndef _AUDIO_GENERATOR_H_
Chris@43 17 #define _AUDIO_GENERATOR_H_
Chris@43 18
Chris@43 19 class Model;
Chris@43 20 class NoteModel;
Chris@43 21 class DenseTimeValueModel;
Chris@43 22 class SparseOneDimensionalModel;
Chris@43 23 class RealTimePluginInstance;
Chris@43 24
Chris@43 25 #include <QObject>
Chris@43 26 #include <QMutex>
Chris@43 27
Chris@43 28 #include <set>
Chris@43 29 #include <map>
Chris@43 30
Chris@43 31 class AudioGenerator : public QObject
Chris@43 32 {
Chris@43 33 Q_OBJECT
Chris@43 34
Chris@43 35 public:
Chris@43 36 AudioGenerator();
Chris@43 37 virtual ~AudioGenerator();
Chris@43 38
Chris@43 39 /**
Chris@43 40 * Return true if the given model is of a type that we generally
Chris@43 41 * know how to play. This doesn't guarantee that a specific
Chris@43 42 * AudioGenerator will actually produce sounds for it (for
Chris@43 43 * example, it may turn out that a vital plugin is missing).
Chris@43 44 */
Chris@43 45 static bool canPlay(const Model *model);
Chris@43 46
Chris@43 47 static QString getDefaultPlayPluginId(const Model *model);
Chris@43 48 static QString getDefaultPlayPluginConfiguration(const Model *model);
Chris@43 49
Chris@43 50 /**
Chris@43 51 * Add a data model to be played from and initialise any necessary
Chris@43 52 * audio generation code. Returns true if the model will be
Chris@43 53 * played. (The return value test here is stricter than that for
Chris@43 54 * canPlay, above.) The model will be added regardless of the
Chris@43 55 * return value.
Chris@43 56 */
Chris@43 57 virtual bool addModel(Model *model);
Chris@43 58
Chris@43 59 /**
Chris@43 60 * Remove a model.
Chris@43 61 */
Chris@43 62 virtual void removeModel(Model *model);
Chris@43 63
Chris@43 64 /**
Chris@43 65 * Remove all models.
Chris@43 66 */
Chris@43 67 virtual void clearModels();
Chris@43 68
Chris@43 69 /**
Chris@43 70 * Reset playback, clearing plugins and the like.
Chris@43 71 */
Chris@43 72 virtual void reset();
Chris@43 73
Chris@43 74 /**
Chris@43 75 * Set the target channel count. The buffer parameter to mixModel
Chris@43 76 * must always point to at least this number of arrays.
Chris@43 77 */
Chris@43 78 virtual void setTargetChannelCount(size_t channelCount);
Chris@43 79
Chris@43 80 /**
Chris@43 81 * Return the internal processing block size. The frameCount
Chris@43 82 * argument to all mixModel calls must be a multiple of this
Chris@43 83 * value.
Chris@43 84 */
Chris@43 85 virtual size_t getBlockSize() const;
Chris@43 86
Chris@43 87 /**
Chris@43 88 * Mix a single model into an output buffer.
Chris@43 89 */
Chris@43 90 virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount,
Chris@43 91 float **buffer, size_t fadeIn = 0, size_t fadeOut = 0);
Chris@43 92
Chris@43 93 /**
Chris@43 94 * Specify that only the given set of models should be played.
Chris@43 95 */
Chris@43 96 virtual void setSoloModelSet(std::set<Model *>s);
Chris@43 97
Chris@43 98 /**
Chris@43 99 * Specify that all models should be played as normal (if not
Chris@43 100 * muted).
Chris@43 101 */
Chris@43 102 virtual void clearSoloModelSet();
Chris@43 103
Chris@43 104 protected slots:
Chris@43 105 void playPluginIdChanged(const Model *, QString);
Chris@43 106 void playPluginConfigurationChanged(const Model *, QString);
Chris@43 107
Chris@43 108 protected:
Chris@43 109 size_t m_sourceSampleRate;
Chris@43 110 size_t m_targetChannelCount;
Chris@43 111
Chris@43 112 bool m_soloing;
Chris@43 113 std::set<Model *> m_soloModelSet;
Chris@43 114
Chris@43 115 struct NoteOff {
Chris@43 116
Chris@43 117 int pitch;
Chris@43 118 size_t frame;
Chris@43 119
Chris@43 120 struct Comparator {
Chris@43 121 bool operator()(const NoteOff &n1, const NoteOff &n2) const {
Chris@43 122 return n1.frame < n2.frame;
Chris@43 123 }
Chris@43 124 };
Chris@43 125 };
Chris@43 126
Chris@43 127 typedef std::map<const Model *, RealTimePluginInstance *> PluginMap;
Chris@43 128
Chris@43 129 typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet;
Chris@43 130 typedef std::map<const Model *, NoteOffSet> NoteOffMap;
Chris@43 131
Chris@43 132 QMutex m_mutex;
Chris@43 133 PluginMap m_synthMap;
Chris@43 134 NoteOffMap m_noteOffs;
Chris@43 135 static QString m_sampleDir;
Chris@43 136
Chris@43 137 virtual RealTimePluginInstance *loadPluginFor(const Model *model);
Chris@43 138 virtual RealTimePluginInstance *loadPlugin(QString id, QString program);
Chris@43 139 static QString getSampleDir();
Chris@43 140 static void setSampleDir(RealTimePluginInstance *plugin);
Chris@43 141
Chris@43 142 virtual size_t mixDenseTimeValueModel
Chris@43 143 (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
Chris@43 144 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@43 145
Chris@43 146 virtual size_t mixSparseOneDimensionalModel
Chris@43 147 (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount,
Chris@43 148 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@43 149
Chris@43 150 virtual size_t mixNoteModel
Chris@43 151 (NoteModel *model, size_t startFrame, size_t frameCount,
Chris@43 152 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@43 153
Chris@43 154 static const size_t m_pluginBlockSize;
Chris@43 155 };
Chris@43 156
Chris@43 157 #endif
Chris@43 158