annotate audioio/AudioGenerator.h @ 32:42989c2e621b

* Fix crash in spectrogram layer when replacing model * Change sample player's sample path to a single sample directory. This makes it immune to OS path separator differences, and ensures it can reject configure calls that try to set a nonexistent directory. Reloading play parameters (e.g. sample program) should now work. * some win32 fixes.
author Chris Cannam
date Wed, 26 Apr 2006 16:00:13 +0000
parents f38b8abd3540
children
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@21 4 Sonic Visualiser
Chris@21 5 An audio file viewer and annotation editor.
Chris@21 6 Centre for Digital Music, Queen Mary, University of London.
Chris@21 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@21 9 This program is free software; you can redistribute it and/or
Chris@21 10 modify it under the terms of the GNU General Public License as
Chris@21 11 published by the Free Software Foundation; either version 2 of the
Chris@21 12 License, or (at your option) any later version. See the file
Chris@21 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@11 20 class NoteModel;
Chris@0 21 class DenseTimeValueModel;
Chris@0 22 class SparseOneDimensionalModel;
Chris@0 23 class RealTimePluginInstance;
Chris@0 24
Chris@22 25 #include <QObject>
Chris@8 26 #include <QMutex>
Chris@8 27
Chris@0 28 #include <set>
Chris@0 29 #include <map>
Chris@0 30
Chris@22 31 class AudioGenerator : public QObject
Chris@0 32 {
Chris@22 33 Q_OBJECT
Chris@22 34
Chris@0 35 public:
Chris@30 36 AudioGenerator();
Chris@0 37 virtual ~AudioGenerator();
Chris@0 38
Chris@0 39 /**
Chris@13 40 * Return true if the given model is of a type that we generally
Chris@13 41 * know how to play. This doesn't guarantee that a specific
Chris@13 42 * AudioGenerator will actually produce sounds for it (for
Chris@13 43 * example, it may turn out that a vital plugin is missing).
Chris@13 44 */
Chris@13 45 static bool canPlay(const Model *model);
Chris@13 46
Chris@22 47 static QString getDefaultPlayPluginId(const Model *model);
Chris@22 48 static QString getDefaultPlayPluginConfiguration(const Model *model);
Chris@22 49
Chris@13 50 /**
Chris@13 51 * Add a data model to be played from and initialise any necessary
Chris@13 52 * audio generation code. Returns true if the model will be
Chris@13 53 * played. (The return value test here is stricter than that for
Chris@13 54 * canPlay, above.) The model will be added regardless of the
Chris@13 55 * return value.
Chris@0 56 */
Chris@10 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@4 91 float **buffer, size_t fadeIn = 0, size_t fadeOut = 0);
Chris@0 92
Chris@22 93 protected slots:
Chris@22 94 void playPluginIdChanged(const Model *, QString);
Chris@22 95 void playPluginConfigurationChanged(const Model *, QString);
Chris@22 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@22 113 typedef std::map<const Model *, RealTimePluginInstance *> PluginMap;
Chris@0 114
Chris@0 115 typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet;
Chris@22 116 typedef std::map<const Model *, NoteOffSet> NoteOffMap;
Chris@0 117
Chris@8 118 QMutex m_mutex;
Chris@0 119 PluginMap m_synthMap;
Chris@0 120 NoteOffMap m_noteOffs;
Chris@30 121 static QString m_sampleDir;
Chris@0 122
Chris@22 123 virtual RealTimePluginInstance *loadPluginFor(const Model *model);
Chris@11 124 virtual RealTimePluginInstance *loadPlugin(QString id, QString program);
Chris@30 125 static QString getSampleDir();
Chris@32 126 static void setSampleDir(RealTimePluginInstance *plugin);
Chris@11 127
Chris@0 128 virtual size_t mixDenseTimeValueModel
Chris@0 129 (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
Chris@4 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@4 134 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@0 135
Chris@11 136 virtual size_t mixNoteModel
Chris@11 137 (NoteModel *model, size_t startFrame, size_t frameCount,
Chris@11 138 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@11 139
Chris@0 140 static const size_t m_pluginBlockSize;
Chris@0 141 };
Chris@0 142
Chris@0 143 #endif
Chris@0 144