Mercurial > hg > svcore
comparison transform/ModelTransformer.h @ 388:370aa9714ef5
* Move plugin/transform to plain transform. This way transform can depend on
model and GUI classes, but plugin doesn't have to.
author | Chris Cannam |
---|---|
date | Wed, 12 Mar 2008 18:02:17 +0000 |
parents | plugin/transform/ModelTransformer.h@399ea254afd6 |
children | 418cd2064769 |
comparison
equal
deleted
inserted
replaced
387:7aa1de571880 | 388:370aa9714ef5 |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 This file copyright 2006 Chris Cannam. | |
8 | |
9 This program is free software; you can redistribute it and/or | |
10 modify it under the terms of the GNU General Public License as | |
11 published by the Free Software Foundation; either version 2 of the | |
12 License, or (at your option) any later version. See the file | |
13 COPYING included with this distribution for more information. | |
14 */ | |
15 | |
16 #ifndef _TRANSFORMER_H_ | |
17 #define _TRANSFORMER_H_ | |
18 | |
19 #include "base/Thread.h" | |
20 | |
21 #include "data/model/Model.h" | |
22 | |
23 #include "Transform.h" | |
24 | |
25 /** | |
26 * A ModelTransformer turns one data model into another. | |
27 * | |
28 * Typically in this application, a ModelTransformer might have a | |
29 * DenseTimeValueModel as its input (e.g. an audio waveform) and a | |
30 * SparseOneDimensionalModel (e.g. detected beats) as its output. | |
31 * | |
32 * The ModelTransformer typically runs in the background, as a | |
33 * separate thread populating the output model. The model is | |
34 * available to the user of the ModelTransformer immediately, but may | |
35 * be initially empty until the background thread has populated it. | |
36 */ | |
37 | |
38 class ModelTransformer : public Thread | |
39 { | |
40 public: | |
41 virtual ~ModelTransformer(); | |
42 | |
43 class Input { | |
44 public: | |
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 */ | |
66 void abandon() { m_abandoned = true; } | |
67 | |
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 */ | |
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 */ | |
90 Model *detachOutputModel() { m_detached = true; return m_output; } | |
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 | |
100 protected: | |
101 ModelTransformer(Input input, const Transform &transform); | |
102 | |
103 Transform m_transform; | |
104 Input m_input; // I don't own the model in this | |
105 Model *m_output; // I own this, unless... | |
106 bool m_detached; // ... this is true. | |
107 bool m_abandoned; | |
108 QString m_message; | |
109 }; | |
110 | |
111 #endif |