Chris@43
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@43
|
2
|
Chris@43
|
3 /*
|
Chris@43
|
4 Sonic Visualiser
|
Chris@43
|
5 An audio file viewer and annotation editor.
|
Chris@43
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@43
|
7 This file copyright 2006 Chris Cannam.
|
Chris@43
|
8
|
Chris@43
|
9 This program is free software; you can redistribute it and/or
|
Chris@43
|
10 modify it under the terms of the GNU General Public License as
|
Chris@43
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@43
|
12 License, or (at your option) any later version. See the file
|
Chris@43
|
13 COPYING included with this distribution for more information.
|
Chris@43
|
14 */
|
Chris@43
|
15
|
Chris@43
|
16 #ifndef _AUDIO_GENERATOR_H_
|
Chris@43
|
17 #define _AUDIO_GENERATOR_H_
|
Chris@43
|
18
|
Chris@43
|
19 class Model;
|
Chris@43
|
20 class NoteModel;
|
matthiasm@281
|
21 class FlexiNoteModel;
|
Chris@43
|
22 class DenseTimeValueModel;
|
Chris@43
|
23 class SparseOneDimensionalModel;
|
Chris@108
|
24 class Playable;
|
Chris@307
|
25 class ClipMixer;
|
Chris@43
|
26
|
Chris@43
|
27 #include <QObject>
|
Chris@43
|
28 #include <QMutex>
|
Chris@43
|
29
|
Chris@43
|
30 #include <set>
|
Chris@43
|
31 #include <map>
|
Chris@275
|
32 #include <vector>
|
Chris@43
|
33
|
Chris@43
|
34 class AudioGenerator : public QObject
|
Chris@43
|
35 {
|
Chris@43
|
36 Q_OBJECT
|
Chris@43
|
37
|
Chris@43
|
38 public:
|
Chris@43
|
39 AudioGenerator();
|
Chris@43
|
40 virtual ~AudioGenerator();
|
Chris@43
|
41
|
Chris@43
|
42 /**
|
Chris@43
|
43 * Add a data model to be played from and initialise any necessary
|
Chris@43
|
44 * audio generation code. Returns true if the model will be
|
Chris@108
|
45 * played. The model will be added regardless of the return
|
Chris@108
|
46 * value.
|
Chris@43
|
47 */
|
Chris@43
|
48 virtual bool addModel(Model *model);
|
Chris@43
|
49
|
Chris@43
|
50 /**
|
Chris@43
|
51 * Remove a model.
|
Chris@43
|
52 */
|
Chris@43
|
53 virtual void removeModel(Model *model);
|
Chris@43
|
54
|
Chris@43
|
55 /**
|
Chris@43
|
56 * Remove all models.
|
Chris@43
|
57 */
|
Chris@43
|
58 virtual void clearModels();
|
Chris@43
|
59
|
Chris@43
|
60 /**
|
Chris@305
|
61 * Reset playback, clearing buffers and the like.
|
Chris@43
|
62 */
|
Chris@43
|
63 virtual void reset();
|
Chris@43
|
64
|
Chris@43
|
65 /**
|
Chris@43
|
66 * Set the target channel count. The buffer parameter to mixModel
|
Chris@43
|
67 * must always point to at least this number of arrays.
|
Chris@43
|
68 */
|
Chris@43
|
69 virtual void setTargetChannelCount(size_t channelCount);
|
Chris@43
|
70
|
Chris@43
|
71 /**
|
Chris@43
|
72 * Return the internal processing block size. The frameCount
|
Chris@43
|
73 * argument to all mixModel calls must be a multiple of this
|
Chris@43
|
74 * value.
|
Chris@43
|
75 */
|
Chris@43
|
76 virtual size_t getBlockSize() const;
|
Chris@43
|
77
|
Chris@43
|
78 /**
|
Chris@43
|
79 * Mix a single model into an output buffer.
|
Chris@43
|
80 */
|
Chris@43
|
81 virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount,
|
Chris@43
|
82 float **buffer, size_t fadeIn = 0, size_t fadeOut = 0);
|
Chris@43
|
83
|
Chris@43
|
84 /**
|
Chris@43
|
85 * Specify that only the given set of models should be played.
|
Chris@43
|
86 */
|
Chris@43
|
87 virtual void setSoloModelSet(std::set<Model *>s);
|
Chris@43
|
88
|
Chris@43
|
89 /**
|
Chris@43
|
90 * Specify that all models should be played as normal (if not
|
Chris@43
|
91 * muted).
|
Chris@43
|
92 */
|
Chris@43
|
93 virtual void clearSoloModelSet();
|
Chris@43
|
94
|
Chris@43
|
95 protected slots:
|
Chris@309
|
96 void playClipIdChanged(const Playable *, QString);
|
Chris@43
|
97
|
Chris@43
|
98 protected:
|
Chris@305
|
99 size_t m_sourceSampleRate;
|
Chris@305
|
100 size_t m_targetChannelCount;
|
Chris@43
|
101
|
Chris@43
|
102 bool m_soloing;
|
Chris@43
|
103 std::set<Model *> m_soloModelSet;
|
Chris@43
|
104
|
Chris@43
|
105 struct NoteOff {
|
Chris@43
|
106
|
Chris@308
|
107 NoteOff(float _freq, size_t _frame) : frequency(_freq), frame(_frame) { }
|
Chris@275
|
108
|
Chris@308
|
109 float frequency;
|
Chris@43
|
110 size_t frame;
|
Chris@43
|
111
|
Chris@43
|
112 struct Comparator {
|
Chris@43
|
113 bool operator()(const NoteOff &n1, const NoteOff &n2) const {
|
Chris@43
|
114 return n1.frame < n2.frame;
|
Chris@43
|
115 }
|
Chris@43
|
116 };
|
Chris@43
|
117 };
|
Chris@43
|
118
|
Chris@307
|
119
|
Chris@307
|
120 typedef std::map<const Model *, ClipMixer *> ClipMixerMap;
|
Chris@43
|
121
|
Chris@178
|
122 typedef std::multiset<NoteOff, NoteOff::Comparator> NoteOffSet;
|
Chris@43
|
123 typedef std::map<const Model *, NoteOffSet> NoteOffMap;
|
Chris@43
|
124
|
Chris@43
|
125 QMutex m_mutex;
|
Chris@307
|
126 ClipMixerMap m_clipMixerMap;
|
Chris@43
|
127 NoteOffMap m_noteOffs;
|
Chris@43
|
128 static QString m_sampleDir;
|
Chris@43
|
129
|
Chris@307
|
130 ClipMixer *makeClipMixerFor(const Model *model);
|
Chris@307
|
131
|
Chris@108
|
132 static void initialiseSampleDir();
|
Chris@43
|
133
|
Chris@43
|
134 virtual size_t mixDenseTimeValueModel
|
Chris@43
|
135 (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
|
Chris@43
|
136 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
|
Chris@43
|
137
|
Chris@275
|
138 virtual size_t mixSyntheticNoteModel
|
Chris@275
|
139 (Model *model, size_t startFrame, size_t frameCount,
|
Chris@43
|
140 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
|
Chris@275
|
141
|
Chris@305
|
142 static const size_t m_processingBlockSize;
|
Chris@43
|
143 };
|
Chris@43
|
144
|
Chris@43
|
145 #endif
|
Chris@43
|
146
|