svapp
1.9
|
00001 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ 00002 00003 /* 00004 Sonic Visualiser 00005 An audio file viewer and annotation editor. 00006 Centre for Digital Music, Queen Mary, University of London. 00007 This file copyright 2006 Chris Cannam. 00008 00009 This program is free software; you can redistribute it and/or 00010 modify it under the terms of the GNU General Public License as 00011 published by the Free Software Foundation; either version 2 of the 00012 License, or (at your option) any later version. See the file 00013 COPYING included with this distribution for more information. 00014 */ 00015 00016 #ifndef _AUDIO_GENERATOR_H_ 00017 #define _AUDIO_GENERATOR_H_ 00018 00019 class Model; 00020 class NoteModel; 00021 class FlexiNoteModel; 00022 class DenseTimeValueModel; 00023 class SparseOneDimensionalModel; 00024 class Playable; 00025 class ClipMixer; 00026 class ContinuousSynth; 00027 00028 #include <QObject> 00029 #include <QMutex> 00030 00031 #include <set> 00032 #include <map> 00033 #include <vector> 00034 00035 class AudioGenerator : public QObject 00036 { 00037 Q_OBJECT 00038 00039 public: 00040 AudioGenerator(); 00041 virtual ~AudioGenerator(); 00042 00049 virtual bool addModel(Model *model); 00050 00054 virtual void removeModel(Model *model); 00055 00059 virtual void clearModels(); 00060 00064 virtual void reset(); 00065 00070 virtual void setTargetChannelCount(int channelCount); 00071 00077 virtual int getBlockSize() const; 00078 00082 virtual int mixModel(Model *model, int startFrame, int frameCount, 00083 float **buffer, int fadeIn = 0, int fadeOut = 0); 00084 00088 virtual void setSoloModelSet(std::set<Model *>s); 00089 00094 virtual void clearSoloModelSet(); 00095 00096 protected slots: 00097 void playClipIdChanged(const Playable *, QString); 00098 00099 protected: 00100 int m_sourceSampleRate; 00101 int m_targetChannelCount; 00102 int m_waveType; 00103 00104 bool m_soloing; 00105 std::set<Model *> m_soloModelSet; 00106 00107 struct NoteOff { 00108 00109 NoteOff(float _freq, int _frame) : frequency(_freq), frame(_frame) { } 00110 00111 float frequency; 00112 int frame; 00113 00114 struct Comparator { 00115 bool operator()(const NoteOff &n1, const NoteOff &n2) const { 00116 return n1.frame < n2.frame; 00117 } 00118 }; 00119 }; 00120 00121 00122 typedef std::map<const Model *, ClipMixer *> ClipMixerMap; 00123 00124 typedef std::multiset<NoteOff, NoteOff::Comparator> NoteOffSet; 00125 typedef std::map<const Model *, NoteOffSet> NoteOffMap; 00126 00127 typedef std::map<const Model *, ContinuousSynth *> ContinuousSynthMap; 00128 00129 QMutex m_mutex; 00130 00131 ClipMixerMap m_clipMixerMap; 00132 NoteOffMap m_noteOffs; 00133 static QString m_sampleDir; 00134 00135 ContinuousSynthMap m_continuousSynthMap; 00136 00137 bool usesClipMixer(const Model *); 00138 bool wantsQuieterClips(const Model *); 00139 bool usesContinuousSynth(const Model *); 00140 00141 ClipMixer *makeClipMixerFor(const Model *model); 00142 ContinuousSynth *makeSynthFor(const Model *model); 00143 00144 static void initialiseSampleDir(); 00145 00146 virtual int mixDenseTimeValueModel 00147 (DenseTimeValueModel *model, int startFrame, int frameCount, 00148 float **buffer, float gain, float pan, int fadeIn, int fadeOut); 00149 00150 virtual int mixClipModel 00151 (Model *model, int startFrame, int frameCount, 00152 float **buffer, float gain, float pan); 00153 00154 virtual int mixContinuousSynthModel 00155 (Model *model, int startFrame, int frameCount, 00156 float **buffer, float gain, float pan); 00157 00158 static const int m_processingBlockSize; 00159 00160 float **m_channelBuffer; 00161 int m_channelBufSiz; 00162 int m_channelBufCount; 00163 }; 00164 00165 #endif 00166