Chris@19: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@0: Chris@0: /* Chris@21: Sonic Visualiser Chris@21: An audio file viewer and annotation editor. Chris@21: Centre for Digital Music, Queen Mary, University of London. Chris@21: This file copyright 2006 Chris Cannam. Chris@0: Chris@21: This program is free software; you can redistribute it and/or Chris@21: modify it under the terms of the GNU General Public License as Chris@21: published by the Free Software Foundation; either version 2 of the Chris@21: License, or (at your option) any later version. See the file Chris@21: COPYING included with this distribution for more information. 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@11: class NoteModel; Chris@0: class DenseTimeValueModel; Chris@0: class SparseOneDimensionalModel; Chris@0: class RealTimePluginInstance; Chris@0: Chris@22: #include Chris@8: #include Chris@8: Chris@0: #include Chris@0: #include Chris@0: Chris@22: class AudioGenerator : public QObject Chris@0: { Chris@22: Q_OBJECT Chris@22: Chris@0: public: Chris@0: AudioGenerator(ViewManager *); Chris@0: virtual ~AudioGenerator(); Chris@0: Chris@0: /** Chris@13: * Return true if the given model is of a type that we generally Chris@13: * know how to play. This doesn't guarantee that a specific Chris@13: * AudioGenerator will actually produce sounds for it (for Chris@13: * example, it may turn out that a vital plugin is missing). Chris@13: */ Chris@13: static bool canPlay(const Model *model); Chris@13: Chris@22: static QString getDefaultPlayPluginId(const Model *model); Chris@22: static QString getDefaultPlayPluginConfiguration(const Model *model); Chris@22: Chris@13: /** Chris@13: * Add a data model to be played from and initialise any necessary Chris@13: * audio generation code. Returns true if the model will be Chris@13: * played. (The return value test here is stricter than that for Chris@13: * canPlay, above.) The model will be added regardless of the Chris@13: * return value. Chris@0: */ Chris@10: virtual bool 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@4: float **buffer, size_t fadeIn = 0, size_t fadeOut = 0); Chris@0: Chris@22: protected slots: Chris@22: void playPluginIdChanged(const Model *, QString); Chris@22: void playPluginConfigurationChanged(const Model *, QString); Chris@22: 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@22: typedef std::map PluginMap; Chris@0: Chris@0: typedef std::set NoteOffSet; Chris@22: typedef std::map NoteOffMap; Chris@0: Chris@8: QMutex m_mutex; Chris@0: PluginMap m_synthMap; Chris@0: NoteOffMap m_noteOffs; Chris@0: Chris@22: virtual RealTimePluginInstance *loadPluginFor(const Model *model); Chris@11: virtual RealTimePluginInstance *loadPlugin(QString id, QString program); Chris@11: Chris@0: virtual size_t mixDenseTimeValueModel Chris@0: (DenseTimeValueModel *model, size_t startFrame, size_t frameCount, Chris@4: float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut); Chris@0: Chris@0: virtual size_t mixSparseOneDimensionalModel Chris@0: (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount, Chris@4: float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut); Chris@0: Chris@11: virtual size_t mixNoteModel Chris@11: (NoteModel *model, size_t startFrame, size_t frameCount, Chris@11: float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut); Chris@11: Chris@0: static const size_t m_pluginBlockSize; Chris@0: }; Chris@0: Chris@0: #endif Chris@0: