Mercurial > hg > svcore
comparison plugin/transform/ModelTransformer.h @ 383:94fc0591ea43 1.2-stable
* merge from trunk (1.2 ended up being tracked from trunk, but we may want
  this branch for fixes later)
| author | Chris Cannam | 
|---|---|
| date | Wed, 27 Feb 2008 10:32:45 +0000 | 
| parents | f620ce48c950 | 
| children | 
   comparison
  equal
  deleted
  inserted
  replaced
| 349:f39d33b0b265 | 383:94fc0591ea43 | 
|---|---|
| 18 | 18 | 
| 19 #include "base/Thread.h" | 19 #include "base/Thread.h" | 
| 20 | 20 | 
| 21 #include "data/model/Model.h" | 21 #include "data/model/Model.h" | 
| 22 | 22 | 
| 23 #include "Transform.h" | |
| 24 | |
| 23 /** | 25 /** | 
| 24 * A ModelTransformer turns one data model into another. | 26 * A ModelTransformer turns one data model into another. | 
| 25 * | 27 * | 
| 26 * Typically in this application, a ModelTransformer might have a | 28 * Typically in this application, a ModelTransformer might have a | 
| 27 * DenseTimeValueModel as its input (e.g. an audio waveform) and a | 29 * DenseTimeValueModel as its input (e.g. an audio waveform) and a | 
| 36 class ModelTransformer : public Thread | 38 class ModelTransformer : public Thread | 
| 37 { | 39 { | 
| 38 public: | 40 public: | 
| 39 virtual ~ModelTransformer(); | 41 virtual ~ModelTransformer(); | 
| 40 | 42 | 
| 41 // Just a hint to the processing thread that it should give up. | 43 class Input { | 
| 42 // Caller should still wait() and/or delete the transform before | 44 public: | 
| 43 // assuming its input and output models are no longer required. | 45 Input(Model *m) : m_model(m), m_channel(-1) { } | 
| 46 Input(Model *m, int c) : m_model(m), m_channel(c) { } | |
| 47 | |
| 48 Model *getModel() const { return m_model; } | |
| 49 void setModel(Model *m) { m_model = m; } | |
| 50 | |
| 51 int getChannel() const { return m_channel; } | |
| 52 void setChannel(int c) { m_channel = c; } | |
| 53 | |
| 54 protected: | |
| 55 Model *m_model; | |
| 56 int m_channel; | |
| 57 }; | |
| 58 | |
| 59 /** | |
| 60 * Hint to the processing thread that it should give up, for | |
| 61 * example because the process is going to exit or we want to get | |
| 62 * rid of the input model. Caller should still wait() and/or | |
| 63 * delete the transform before assuming its input and output | |
| 64 * models are no longer required. | |
| 65 */ | |
| 44 void abandon() { m_abandoned = true; } | 66 void abandon() { m_abandoned = true; } | 
| 45 | 67 | 
| 46 Model *getInputModel() { return m_input; } | 68 /** | 
| 69 * Return the input model for the transform. | |
| 70 */ | |
| 71 Model *getInputModel() { return m_input.getModel(); } | |
| 72 | |
| 73 /** | |
| 74 * Return the input channel spec for the transform. | |
| 75 */ | |
| 76 int getInputChannel() { return m_input.getChannel(); } | |
| 77 | |
| 78 /** | |
| 79 * Return the output model created by the transform. Returns a | |
| 80 * null model if the transform could not be initialised; an error | |
| 81 * message may be available via getMessage() in this situation. | |
| 82 */ | |
| 47 Model *getOutputModel() { return m_output; } | 83 Model *getOutputModel() { return m_output; } | 
| 84 | |
| 85 /** | |
| 86 * Return the output model, also detaching it from the transformer | |
| 87 * so that it will not be deleted when the transformer is. The | |
| 88 * caller takes ownership of the model. | |
| 89 */ | |
| 48 Model *detachOutputModel() { m_detached = true; return m_output; } | 90 Model *detachOutputModel() { m_detached = true; return m_output; } | 
| 49 | 91 | 
| 92 /** | |
| 93 * Return a warning or error message. If getOutputModel returned | |
| 94 * a null pointer, this should contain a fatal error message for | |
| 95 * the transformer; otherwise it may contain a warning to show to | |
| 96 * the user about e.g. suboptimal block size or whatever. | |
| 97 */ | |
| 98 QString getMessage() const { return m_message; } | |
| 99 | |
| 50 protected: | 100 protected: | 
| 51 ModelTransformer(Model *m); | 101 ModelTransformer(Input input, const Transform &transform); | 
| 52 | 102 | 
| 53 Model *m_input; // I don't own this | 103 Transform m_transform; | 
| 104 Input m_input; // I don't own the model in this | |
| 54 Model *m_output; // I own this, unless... | 105 Model *m_output; // I own this, unless... | 
| 55 bool m_detached; // ... this is true. | 106 bool m_detached; // ... this is true. | 
| 56 bool m_abandoned; | 107 bool m_abandoned; | 
| 108 QString m_message; | |
| 57 }; | 109 }; | 
| 58 | 110 | 
| 59 #endif | 111 #endif | 
