Chris@0: /* -*- c-basic-offset: 4 -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@0: A waveform viewer and audio annotation editor. Chris@2: Chris Cannam, Queen Mary University of London, 2005-2006 Chris@0: Chris@0: This is experimental software. Not for distribution. Chris@0: */ Chris@0: Chris@0: #ifndef _AUDIO_GENERATOR_H_ Chris@0: #define _AUDIO_GENERATOR_H_ Chris@0: Chris@0: class Model; Chris@0: class ViewManager; Chris@0: class DenseTimeValueModel; Chris@0: class SparseOneDimensionalModel; Chris@0: class RealTimePluginInstance; Chris@0: Chris@0: #include Chris@0: #include Chris@0: Chris@0: class AudioGenerator Chris@0: { Chris@0: public: Chris@0: AudioGenerator(ViewManager *); Chris@0: virtual ~AudioGenerator(); Chris@0: Chris@0: /** Chris@0: * Add a data model to be played from and initialise any Chris@0: * necessary audio generation code. Chris@0: */ Chris@0: virtual void addModel(Model *model); Chris@0: Chris@0: /** Chris@0: * Remove a model. Chris@0: */ Chris@0: virtual void removeModel(Model *model); Chris@0: Chris@0: /** Chris@0: * Remove all models. Chris@0: */ Chris@0: virtual void clearModels(); Chris@0: Chris@0: /** Chris@0: * Reset playback, clearing plugins and the like. Chris@0: */ Chris@0: virtual void reset(); Chris@0: Chris@0: /** Chris@0: * Set the target channel count. The buffer parameter to mixModel Chris@0: * must always point to at least this number of arrays. Chris@0: */ Chris@0: virtual void setTargetChannelCount(size_t channelCount); Chris@0: Chris@0: /** Chris@0: * Return the internal processing block size. The frameCount Chris@0: * argument to all mixModel calls must be a multiple of this Chris@0: * value. Chris@0: */ Chris@0: virtual size_t getBlockSize() const; Chris@0: Chris@0: /** Chris@0: * Mix a single model into an output buffer. Chris@0: */ Chris@0: virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount, Chris@0: float **buffer); Chris@0: Chris@0: protected: Chris@0: ViewManager *m_viewManager; Chris@0: size_t m_sourceSampleRate; Chris@0: size_t m_targetChannelCount; Chris@0: Chris@0: struct NoteOff { Chris@0: Chris@0: int pitch; Chris@0: size_t frame; Chris@0: Chris@0: struct Comparator { Chris@0: bool operator()(const NoteOff &n1, const NoteOff &n2) const { Chris@0: return n1.frame < n2.frame; Chris@0: } Chris@0: }; Chris@0: }; Chris@0: Chris@0: typedef std::map PluginMap; Chris@0: Chris@0: typedef std::set NoteOffSet; Chris@0: typedef std::map NoteOffMap; Chris@0: Chris@0: PluginMap m_synthMap; Chris@0: NoteOffMap m_noteOffs; Chris@0: Chris@0: virtual size_t mixDenseTimeValueModel Chris@0: (DenseTimeValueModel *model, size_t startFrame, size_t frameCount, Chris@0: float **buffer, float gain, float pan); Chris@0: Chris@0: virtual size_t mixSparseOneDimensionalModel Chris@0: (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount, Chris@0: float **buffer, float gain, float pan); Chris@0: Chris@0: static const size_t m_pluginBlockSize; Chris@0: }; Chris@0: Chris@0: #endif Chris@0: