annotate audioio/AudioGenerator.h @ 19:c606d3ffa397

* Set indent-tabs-mode to nil in Emacs mode direction
author Chris Cannam
date Mon, 20 Mar 2006 11:40:39 +0000
parents 89bb89894ad6
children ebe07d3560e6
rev   line source
Chris@19 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@0 4 A waveform viewer and audio annotation editor.
Chris@2 5 Chris Cannam, Queen Mary University of London, 2005-2006
Chris@0 6
Chris@0 7 This is experimental software. Not for distribution.
Chris@0 8 */
Chris@0 9
Chris@0 10 #ifndef _AUDIO_GENERATOR_H_
Chris@0 11 #define _AUDIO_GENERATOR_H_
Chris@0 12
Chris@0 13 class Model;
Chris@0 14 class ViewManager;
Chris@11 15 class NoteModel;
Chris@0 16 class DenseTimeValueModel;
Chris@0 17 class SparseOneDimensionalModel;
Chris@0 18 class RealTimePluginInstance;
Chris@0 19
Chris@8 20 #include <QMutex>
Chris@8 21
Chris@0 22 #include <set>
Chris@0 23 #include <map>
Chris@0 24
Chris@0 25 class AudioGenerator
Chris@0 26 {
Chris@0 27 public:
Chris@0 28 AudioGenerator(ViewManager *);
Chris@0 29 virtual ~AudioGenerator();
Chris@0 30
Chris@0 31 /**
Chris@13 32 * Return true if the given model is of a type that we generally
Chris@13 33 * know how to play. This doesn't guarantee that a specific
Chris@13 34 * AudioGenerator will actually produce sounds for it (for
Chris@13 35 * example, it may turn out that a vital plugin is missing).
Chris@13 36 */
Chris@13 37 static bool canPlay(const Model *model);
Chris@13 38
Chris@13 39 /**
Chris@13 40 * Add a data model to be played from and initialise any necessary
Chris@13 41 * audio generation code. Returns true if the model will be
Chris@13 42 * played. (The return value test here is stricter than that for
Chris@13 43 * canPlay, above.) The model will be added regardless of the
Chris@13 44 * return value.
Chris@0 45 */
Chris@10 46 virtual bool addModel(Model *model);
Chris@0 47
Chris@0 48 /**
Chris@0 49 * Remove a model.
Chris@0 50 */
Chris@0 51 virtual void removeModel(Model *model);
Chris@0 52
Chris@0 53 /**
Chris@0 54 * Remove all models.
Chris@0 55 */
Chris@0 56 virtual void clearModels();
Chris@0 57
Chris@0 58 /**
Chris@0 59 * Reset playback, clearing plugins and the like.
Chris@0 60 */
Chris@0 61 virtual void reset();
Chris@0 62
Chris@0 63 /**
Chris@0 64 * Set the target channel count. The buffer parameter to mixModel
Chris@0 65 * must always point to at least this number of arrays.
Chris@0 66 */
Chris@0 67 virtual void setTargetChannelCount(size_t channelCount);
Chris@0 68
Chris@0 69 /**
Chris@0 70 * Return the internal processing block size. The frameCount
Chris@0 71 * argument to all mixModel calls must be a multiple of this
Chris@0 72 * value.
Chris@0 73 */
Chris@0 74 virtual size_t getBlockSize() const;
Chris@0 75
Chris@0 76 /**
Chris@0 77 * Mix a single model into an output buffer.
Chris@0 78 */
Chris@0 79 virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount,
Chris@4 80 float **buffer, size_t fadeIn = 0, size_t fadeOut = 0);
Chris@0 81
Chris@0 82 protected:
Chris@0 83 ViewManager *m_viewManager;
Chris@0 84 size_t m_sourceSampleRate;
Chris@0 85 size_t m_targetChannelCount;
Chris@0 86
Chris@0 87 struct NoteOff {
Chris@0 88
Chris@0 89 int pitch;
Chris@0 90 size_t frame;
Chris@0 91
Chris@0 92 struct Comparator {
Chris@0 93 bool operator()(const NoteOff &n1, const NoteOff &n2) const {
Chris@0 94 return n1.frame < n2.frame;
Chris@0 95 }
Chris@0 96 };
Chris@0 97 };
Chris@0 98
Chris@11 99 typedef std::map<Model *, RealTimePluginInstance *> PluginMap;
Chris@0 100
Chris@0 101 typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet;
Chris@11 102 typedef std::map<Model *, NoteOffSet> NoteOffMap;
Chris@0 103
Chris@8 104 QMutex m_mutex;
Chris@0 105 PluginMap m_synthMap;
Chris@0 106 NoteOffMap m_noteOffs;
Chris@0 107
Chris@11 108 virtual RealTimePluginInstance *loadPlugin(QString id, QString program);
Chris@11 109
Chris@0 110 virtual size_t mixDenseTimeValueModel
Chris@0 111 (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
Chris@4 112 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@0 113
Chris@0 114 virtual size_t mixSparseOneDimensionalModel
Chris@0 115 (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount,
Chris@4 116 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@0 117
Chris@11 118 virtual size_t mixNoteModel
Chris@11 119 (NoteModel *model, size_t startFrame, size_t frameCount,
Chris@11 120 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@11 121
Chris@0 122 static const size_t m_pluginBlockSize;
Chris@0 123 };
Chris@0 124
Chris@0 125 #endif
Chris@0 126