AudioGenerator.h

Go to the documentation of this file.
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 DenseTimeValueModel;
00022 class SparseOneDimensionalModel;
00023 class RealTimePluginInstance;
00024 
00025 #include <QObject>
00026 #include <QMutex>
00027 
00028 #include <set>
00029 #include <map>
00030 
00031 class AudioGenerator : public QObject
00032 {
00033     Q_OBJECT
00034 
00035 public:
00036     AudioGenerator();
00037     virtual ~AudioGenerator();
00038 
00045     static bool canPlay(const Model *model);
00046 
00047     static QString getDefaultPlayPluginId(const Model *model);
00048     static QString getDefaultPlayPluginConfiguration(const Model *model);
00049 
00057     virtual bool addModel(Model *model);
00058 
00062     virtual void removeModel(Model *model);
00063 
00067     virtual void clearModels();
00068 
00072     virtual void reset();
00073 
00078     virtual void setTargetChannelCount(size_t channelCount);
00079 
00085     virtual size_t getBlockSize() const;
00086 
00090     virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount,
00091                             float **buffer, size_t fadeIn = 0, size_t fadeOut = 0);
00092 
00096     virtual void setSoloModelSet(std::set<Model *>s);
00097 
00102     virtual void clearSoloModelSet();
00103 
00104 protected slots:
00105     void playPluginIdChanged(const Model *, QString);
00106     void playPluginConfigurationChanged(const Model *, QString);
00107 
00108 protected:
00109     size_t       m_sourceSampleRate;
00110     size_t       m_targetChannelCount;
00111 
00112     bool m_soloing;
00113     std::set<Model *> m_soloModelSet;
00114 
00115     struct NoteOff {
00116 
00117         int pitch;
00118         size_t frame;
00119 
00120         struct Comparator {
00121             bool operator()(const NoteOff &n1, const NoteOff &n2) const {
00122                 return n1.frame < n2.frame;
00123             }
00124         };
00125     };
00126 
00127     typedef std::map<const Model *, RealTimePluginInstance *> PluginMap;
00128 
00129     typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet;
00130     typedef std::map<const Model *, NoteOffSet> NoteOffMap;
00131 
00132     QMutex m_mutex;
00133     PluginMap m_synthMap;
00134     NoteOffMap m_noteOffs;
00135     static QString m_sampleDir;
00136 
00137     virtual RealTimePluginInstance *loadPluginFor(const Model *model);
00138     virtual RealTimePluginInstance *loadPlugin(QString id, QString program);
00139     static QString getSampleDir();
00140     static void setSampleDir(RealTimePluginInstance *plugin);
00141 
00142     virtual size_t mixDenseTimeValueModel
00143     (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
00144      float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
00145 
00146     virtual size_t mixSparseOneDimensionalModel
00147     (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount,
00148      float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
00149 
00150     virtual size_t mixNoteModel
00151     (NoteModel *model, size_t startFrame, size_t frameCount,
00152      float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
00153 
00154     static const size_t m_pluginBlockSize;
00155 };
00156 
00157 #endif
00158 

Generated on Wed Feb 20 15:45:24 2008 for SonicVisualiser by  doxygen 1.5.1