annotate audioio/AudioGenerator.h @ 25:4593a7ebad93

* Ensure plugin parameters for a transform are saved in the .sv file and restored in case the plugin has to be run again * Make plugin dialog offer options for mixdown/single-channel use if the file has more than one channels but the plugin only accepts one * Fix incorrect samplerate playback for second file loaded if its samplerate differed from first * Add Zoom to Fit and Select Visible Range menu options, split out Import Audio into main model and secondary model options * Add stubs for cut, copy and paste operations (not implemented yet)
author Chris Cannam
date Thu, 30 Mar 2006 13:18:11 +0000
parents 7f32bb07629a
children dd2084d32652
rev   line source
Chris@19 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@0 2
Chris@0 3 /*
Chris@21 4 Sonic Visualiser
Chris@21 5 An audio file viewer and annotation editor.
Chris@21 6 Centre for Digital Music, Queen Mary, University of London.
Chris@21 7 This file copyright 2006 Chris Cannam.
Chris@0 8
Chris@21 9 This program is free software; you can redistribute it and/or
Chris@21 10 modify it under the terms of the GNU General Public License as
Chris@21 11 published by the Free Software Foundation; either version 2 of the
Chris@21 12 License, or (at your option) any later version. See the file
Chris@21 13 COPYING included with this distribution for more information.
Chris@0 14 */
Chris@0 15
Chris@0 16 #ifndef _AUDIO_GENERATOR_H_
Chris@0 17 #define _AUDIO_GENERATOR_H_
Chris@0 18
Chris@0 19 class Model;
Chris@0 20 class ViewManager;
Chris@11 21 class NoteModel;
Chris@0 22 class DenseTimeValueModel;
Chris@0 23 class SparseOneDimensionalModel;
Chris@0 24 class RealTimePluginInstance;
Chris@0 25
Chris@22 26 #include <QObject>
Chris@8 27 #include <QMutex>
Chris@8 28
Chris@0 29 #include <set>
Chris@0 30 #include <map>
Chris@0 31
Chris@22 32 class AudioGenerator : public QObject
Chris@0 33 {
Chris@22 34 Q_OBJECT
Chris@22 35
Chris@0 36 public:
Chris@0 37 AudioGenerator(ViewManager *);
Chris@0 38 virtual ~AudioGenerator();
Chris@0 39
Chris@0 40 /**
Chris@13 41 * Return true if the given model is of a type that we generally
Chris@13 42 * know how to play. This doesn't guarantee that a specific
Chris@13 43 * AudioGenerator will actually produce sounds for it (for
Chris@13 44 * example, it may turn out that a vital plugin is missing).
Chris@13 45 */
Chris@13 46 static bool canPlay(const Model *model);
Chris@13 47
Chris@22 48 static QString getDefaultPlayPluginId(const Model *model);
Chris@22 49 static QString getDefaultPlayPluginConfiguration(const Model *model);
Chris@22 50
Chris@13 51 /**
Chris@13 52 * Add a data model to be played from and initialise any necessary
Chris@13 53 * audio generation code. Returns true if the model will be
Chris@13 54 * played. (The return value test here is stricter than that for
Chris@13 55 * canPlay, above.) The model will be added regardless of the
Chris@13 56 * return value.
Chris@0 57 */
Chris@10 58 virtual bool addModel(Model *model);
Chris@0 59
Chris@0 60 /**
Chris@0 61 * Remove a model.
Chris@0 62 */
Chris@0 63 virtual void removeModel(Model *model);
Chris@0 64
Chris@0 65 /**
Chris@0 66 * Remove all models.
Chris@0 67 */
Chris@0 68 virtual void clearModels();
Chris@0 69
Chris@0 70 /**
Chris@0 71 * Reset playback, clearing plugins and the like.
Chris@0 72 */
Chris@0 73 virtual void reset();
Chris@0 74
Chris@0 75 /**
Chris@0 76 * Set the target channel count. The buffer parameter to mixModel
Chris@0 77 * must always point to at least this number of arrays.
Chris@0 78 */
Chris@0 79 virtual void setTargetChannelCount(size_t channelCount);
Chris@0 80
Chris@0 81 /**
Chris@0 82 * Return the internal processing block size. The frameCount
Chris@0 83 * argument to all mixModel calls must be a multiple of this
Chris@0 84 * value.
Chris@0 85 */
Chris@0 86 virtual size_t getBlockSize() const;
Chris@0 87
Chris@0 88 /**
Chris@0 89 * Mix a single model into an output buffer.
Chris@0 90 */
Chris@0 91 virtual size_t mixModel(Model *model, size_t startFrame, size_t frameCount,
Chris@4 92 float **buffer, size_t fadeIn = 0, size_t fadeOut = 0);
Chris@0 93
Chris@22 94 protected slots:
Chris@22 95 void playPluginIdChanged(const Model *, QString);
Chris@22 96 void playPluginConfigurationChanged(const Model *, QString);
Chris@22 97
Chris@0 98 protected:
Chris@0 99 ViewManager *m_viewManager;
Chris@0 100 size_t m_sourceSampleRate;
Chris@0 101 size_t m_targetChannelCount;
Chris@0 102
Chris@0 103 struct NoteOff {
Chris@0 104
Chris@0 105 int pitch;
Chris@0 106 size_t frame;
Chris@0 107
Chris@0 108 struct Comparator {
Chris@0 109 bool operator()(const NoteOff &n1, const NoteOff &n2) const {
Chris@0 110 return n1.frame < n2.frame;
Chris@0 111 }
Chris@0 112 };
Chris@0 113 };
Chris@0 114
Chris@22 115 typedef std::map<const Model *, RealTimePluginInstance *> PluginMap;
Chris@0 116
Chris@0 117 typedef std::set<NoteOff, NoteOff::Comparator> NoteOffSet;
Chris@22 118 typedef std::map<const Model *, NoteOffSet> NoteOffMap;
Chris@0 119
Chris@8 120 QMutex m_mutex;
Chris@0 121 PluginMap m_synthMap;
Chris@0 122 NoteOffMap m_noteOffs;
Chris@0 123
Chris@22 124 virtual RealTimePluginInstance *loadPluginFor(const Model *model);
Chris@11 125 virtual RealTimePluginInstance *loadPlugin(QString id, QString program);
Chris@11 126
Chris@0 127 virtual size_t mixDenseTimeValueModel
Chris@0 128 (DenseTimeValueModel *model, size_t startFrame, size_t frameCount,
Chris@4 129 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@0 130
Chris@0 131 virtual size_t mixSparseOneDimensionalModel
Chris@0 132 (SparseOneDimensionalModel *model, size_t startFrame, size_t frameCount,
Chris@4 133 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@0 134
Chris@11 135 virtual size_t mixNoteModel
Chris@11 136 (NoteModel *model, size_t startFrame, size_t frameCount,
Chris@11 137 float **buffer, float gain, float pan, size_t fadeIn, size_t fadeOut);
Chris@11 138
Chris@0 139 static const size_t m_pluginBlockSize;
Chris@0 140 };
Chris@0 141
Chris@0 142 #endif
Chris@0 143