annotate plugin/transform/ModelTransformer.h @ 384:6f6ab834449d spectrogram-cache-rejig

* Merge from trunk
author Chris Cannam
date Wed, 27 Feb 2008 11:59:42 +0000
parents f620ce48c950
children
rev   line source
Chris@320 1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
Chris@320 2
Chris@320 3 /*
Chris@320 4 Sonic Visualiser
Chris@320 5 An audio file viewer and annotation editor.
Chris@320 6 Centre for Digital Music, Queen Mary, University of London.
Chris@320 7 This file copyright 2006 Chris Cannam.
Chris@320 8
Chris@320 9 This program is free software; you can redistribute it and/or
Chris@320 10 modify it under the terms of the GNU General Public License as
Chris@320 11 published by the Free Software Foundation; either version 2 of the
Chris@320 12 License, or (at your option) any later version. See the file
Chris@320 13 COPYING included with this distribution for more information.
Chris@320 14 */
Chris@320 15
Chris@329 16 #ifndef _TRANSFORMER_H_
Chris@329 17 #define _TRANSFORMER_H_
Chris@320 18
Chris@320 19 #include "base/Thread.h"
Chris@320 20
Chris@320 21 #include "data/model/Model.h"
Chris@320 22
Chris@384 23 #include "Transform.h"
Chris@384 24
Chris@320 25 /**
Chris@331 26 * A ModelTransformer turns one data model into another.
Chris@320 27 *
Chris@331 28 * Typically in this application, a ModelTransformer might have a
Chris@320 29 * DenseTimeValueModel as its input (e.g. an audio waveform) and a
Chris@320 30 * SparseOneDimensionalModel (e.g. detected beats) as its output.
Chris@320 31 *
Chris@331 32 * The ModelTransformer typically runs in the background, as a
Chris@331 33 * separate thread populating the output model. The model is
Chris@331 34 * available to the user of the ModelTransformer immediately, but may
Chris@331 35 * be initially empty until the background thread has populated it.
Chris@320 36 */
Chris@320 37
Chris@331 38 class ModelTransformer : public Thread
Chris@320 39 {
Chris@320 40 public:
Chris@331 41 virtual ~ModelTransformer();
Chris@320 42
Chris@384 43 class Input {
Chris@384 44 public:
Chris@384 45 Input(Model *m) : m_model(m), m_channel(-1) { }
Chris@384 46 Input(Model *m, int c) : m_model(m), m_channel(c) { }
Chris@384 47
Chris@384 48 Model *getModel() const { return m_model; }
Chris@384 49 void setModel(Model *m) { m_model = m; }
Chris@384 50
Chris@384 51 int getChannel() const { return m_channel; }
Chris@384 52 void setChannel(int c) { m_channel = c; }
Chris@384 53
Chris@384 54 protected:
Chris@384 55 Model *m_model;
Chris@384 56 int m_channel;
Chris@384 57 };
Chris@384 58
Chris@384 59 /**
Chris@384 60 * Hint to the processing thread that it should give up, for
Chris@384 61 * example because the process is going to exit or we want to get
Chris@384 62 * rid of the input model. Caller should still wait() and/or
Chris@384 63 * delete the transform before assuming its input and output
Chris@384 64 * models are no longer required.
Chris@384 65 */
Chris@320 66 void abandon() { m_abandoned = true; }
Chris@320 67
Chris@384 68 /**
Chris@384 69 * Return the input model for the transform.
Chris@384 70 */
Chris@384 71 Model *getInputModel() { return m_input.getModel(); }
Chris@384 72
Chris@384 73 /**
Chris@384 74 * Return the input channel spec for the transform.
Chris@384 75 */
Chris@384 76 int getInputChannel() { return m_input.getChannel(); }
Chris@384 77
Chris@384 78 /**
Chris@384 79 * Return the output model created by the transform. Returns a
Chris@384 80 * null model if the transform could not be initialised; an error
Chris@384 81 * message may be available via getMessage() in this situation.
Chris@384 82 */
Chris@320 83 Model *getOutputModel() { return m_output; }
Chris@384 84
Chris@384 85 /**
Chris@384 86 * Return the output model, also detaching it from the transformer
Chris@384 87 * so that it will not be deleted when the transformer is. The
Chris@384 88 * caller takes ownership of the model.
Chris@384 89 */
Chris@320 90 Model *detachOutputModel() { m_detached = true; return m_output; }
Chris@320 91
Chris@384 92 /**
Chris@384 93 * Return a warning or error message. If getOutputModel returned
Chris@384 94 * a null pointer, this should contain a fatal error message for
Chris@384 95 * the transformer; otherwise it may contain a warning to show to
Chris@384 96 * the user about e.g. suboptimal block size or whatever.
Chris@384 97 */
Chris@384 98 QString getMessage() const { return m_message; }
Chris@384 99
Chris@320 100 protected:
Chris@384 101 ModelTransformer(Input input, const Transform &transform);
Chris@320 102
Chris@384 103 Transform m_transform;
Chris@384 104 Input m_input; // I don't own the model in this
Chris@320 105 Model *m_output; // I own this, unless...
Chris@320 106 bool m_detached; // ... this is true.
Chris@320 107 bool m_abandoned;
Chris@384 108 QString m_message;
Chris@320 109 };
Chris@320 110
Chris@320 111 #endif