Chris@43: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@43: Chris@43: /* Chris@43: Sonic Visualiser Chris@43: An audio file viewer and annotation editor. Chris@43: Centre for Digital Music, Queen Mary, University of London. Chris@43: This file copyright 2006 Chris Cannam. Chris@43: Chris@43: This program is free software; you can redistribute it and/or Chris@43: modify it under the terms of the GNU General Public License as Chris@43: published by the Free Software Foundation; either version 2 of the Chris@43: License, or (at your option) any later version. See the file Chris@43: COPYING included with this distribution for more information. Chris@43: */ Chris@43: Chris@43: #ifndef _AUDIO_GENERATOR_H_ Chris@43: #define _AUDIO_GENERATOR_H_ Chris@43: Chris@43: class Model; Chris@43: class NoteModel; Chris@43: class DenseTimeValueModel; Chris@43: class SparseOneDimensionalModel; Chris@43: class RealTimePluginInstance; Chris@108: class Playable; Chris@43: Chris@43: #include Chris@43: #include Chris@43: Chris@43: #include Chris@43: #include Chris@43: Chris@43: class AudioGenerator : public QObject Chris@43: { Chris@43: Q_OBJECT Chris@43: Chris@43: public: Chris@43: AudioGenerator(); Chris@43: virtual ~AudioGenerator(); Chris@43: Chris@43: /** Chris@43: * Add a data model to be played from and initialise any necessary Chris@43: * audio generation code. Returns true if the model will be Chris@108: * played. The model will be added regardless of the return Chris@108: * value. Chris@43: */ Chris@43: virtual bool addModel(Model *model); Chris@43: Chris@43: /** Chris@43: * Remove a model. Chris@43: */ Chris@43: virtual void removeModel(Model *model); Chris@43: Chris@43: /** Chris@43: * Remove all models. Chris@43: */ Chris@43: virtual void clearModels(); Chris@43: Chris@43: /** Chris@43: * Reset playback, clearing plugins and the like. Chris@43: */ Chris@43: virtual void reset(); Chris@43: Chris@43: /** Chris@43: * Set the target channel count. The buffer parameter to mixModel Chris@43: * must always point to at least this number of arrays. Chris@43: */ Chris@43: virtual void setTargetChannelCount(size_t channelCount); Chris@43: Chris@43: /** Chris@43: * Return the internal processing block size. The frameCount Chris@43: * argument to all mixModel calls must be a multiple of this Chris@43: * value. Chris@43: */ Chris@43: virtual size_t getBlockSize() const; Chris@43: Chris@43: /** Chris@43: * Mix a single model into an output buffer. Chris@43: */ Chris@43: virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount, Chris@43: float **buffer, size_t fadeIn = 0, size_t fadeOut = 0); Chris@43: Chris@43: /** Chris@43: * Specify that only the given set of models should be played. Chris@43: */ Chris@43: virtual void setSoloModelSet(std::sets); Chris@43: Chris@43: /** Chris@43: * Specify that all models should be played as normal (if not Chris@43: * muted). Chris@43: */ Chris@43: virtual void clearSoloModelSet(); Chris@43: Chris@43: protected slots: Chris@108: void playPluginIdChanged(const Playable *, QString); Chris@108: void playPluginConfigurationChanged(const Playable *, QString); Chris@43: Chris@43: protected: Chris@43: size_t m_sourceSampleRate; Chris@43: size_t m_targetChannelCount; Chris@43: Chris@43: bool m_soloing; Chris@43: std::set m_soloModelSet; Chris@43: Chris@43: struct NoteOff { Chris@43: Chris@43: int pitch; Chris@43: size_t frame; Chris@43: Chris@43: struct Comparator { Chris@43: bool operator()(const NoteOff &n1, const NoteOff &n2) const { Chris@43: return n1.frame < n2.frame; Chris@43: } Chris@43: }; Chris@43: }; Chris@43: Chris@43: typedef std::map PluginMap; Chris@43: Chris@178: typedef std::multiset NoteOffSet; Chris@43: typedef std::map NoteOffMap; Chris@43: Chris@43: QMutex m_mutex; Chris@43: PluginMap m_synthMap; Chris@43: NoteOffMap m_noteOffs; Chris@43: static QString m_sampleDir; Chris@43: Chris@43: virtual RealTimePluginInstance *loadPluginFor(const Model *model); Chris@43: virtual RealTimePluginInstance *loadPlugin(QString id, QString program); Chris@108: static void initialiseSampleDir(); Chris@43: static void setSampleDir(RealTimePluginInstance *plugin); Chris@43: Chris@43: virtual size_t mixDenseTimeValueModel Chris@43: (DenseTimeValueModel *model, size_t startFrame, size_t frameCount, Chris@43: float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut); Chris@43: Chris@43: virtual size_t mixSparseOneDimensionalModel Chris@43: (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount, Chris@43: float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut); Chris@43: Chris@43: virtual size_t mixNoteModel Chris@43: (NoteModel *model, size_t startFrame, size_t frameCount, Chris@43: float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut); Chris@43: Chris@43: static const size_t m_pluginBlockSize; Chris@43: }; Chris@43: Chris@43: #endif Chris@43: