annotate audioio/AudioGenerator.h @ 111:7783bbb99887

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