comparison audioio/AudioGenerator.h @ 0:cd5d7ff8ef38

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