comparison audioio/AudioGenerator.h @ 43:3c5756fb6a68

* Move some things around to facilitate plundering libraries for other applications without needing to duplicate so much code. sv/osc -> data/osc sv/audioio -> audioio sv/transform -> plugin/transform sv/document -> document (will rename to framework in next commit)
author Chris Cannam
date Wed, 24 Oct 2007 16:34:31 +0000
parents
children e25e8f5d785b
comparison
equal deleted inserted replaced
42:0619006a1ee3 43:3c5756fb6a68
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 /**
94 * Specify that only the given set of models should be played.
95 */
96 virtual void setSoloModelSet(std::set<Model *>s);
97
98 /**
99 * Specify that all models should be played as normal (if not
100 * muted).
101 */
102 virtual void clearSoloModelSet();
103
104 protected slots:
105 void playPluginIdChanged(const Model *, QString);
106 void playPluginConfigurationChanged(const Model *, QString);
107
108 protected:
109 size_t m_sourceSampleRate;
110 size_t m_targetChannelCount;
111
112 bool m_soloing;
113 std::set<Model *> m_soloModelSet;
114
115 struct NoteOff {
116
117 int pitch;
118 size_t frame;
119
120 struct Comparator {
121 bool operator()(const NoteOff &n1, const NoteOff &n2) const {
122 return n1.frame < n2.frame;
123 }
124 };
125 };
126
127 typedef std::map<const Model *, RealTimePluginInstance *> PluginMap;
128
129 typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet;
130 typedef std::map<const Model *, NoteOffSet> NoteOffMap;
131
132 QMutex m_mutex;
133 PluginMap m_synthMap;
134 NoteOffMap m_noteOffs;
135 static QString m_sampleDir;
136
137 virtual RealTimePluginInstance *loadPluginFor(const Model *model);
138 virtual RealTimePluginInstance *loadPlugin(QString id, QString program);
139 static QString getSampleDir();
140 static void setSampleDir(RealTimePluginInstance *plugin);
141
142 virtual size_t mixDenseTimeValueModel
143 (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
144 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
145
146 virtual size_t mixSparseOneDimensionalModel
147 (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount,
148 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
149
150 virtual size_t mixNoteModel
151 (NoteModel *model, size_t startFrame, size_t frameCount,
152 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
153
154 static const size_t m_pluginBlockSize;
155 };
156
157 #endif
158