svcore  1.9
ModelTransformer.h
Go to the documentation of this file.
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 
38 class ModelTransformer : public Thread
39 {
40 public:
41  virtual ~ModelTransformer();
42 
43  typedef std::vector<Model *> Models;
44 
45  class Input {
46  public:
47  Input(Model *m) : m_model(m), m_channel(-1) { }
48  Input(Model *m, int c) : m_model(m), m_channel(c) { }
49 
50  Model *getModel() const { return m_model; }
51  void setModel(Model *m) { m_model = m; }
52 
53  int getChannel() const { return m_channel; }
54  void setChannel(int c) { m_channel = c; }
55 
56  protected:
58  int m_channel;
59  };
60 
68  void abandon() { m_abandoned = true; }
69 
74 
78  int getInputChannel() { return m_input.getChannel(); }
79 
87 
94  m_detached = true;
95  return getOutputModels();
96  }
97 
105  virtual Models getAdditionalOutputModels() { return Models(); }
106 
112  virtual bool willHaveAdditionalOutputModels() { return false; }
113 
119  m_detachedAdd = true;
120  return getAdditionalOutputModels();
121  }
122 
129  QString getMessage() const { return m_message; }
130 
131 protected:
132  ModelTransformer(Input input, const Transform &transform);
133  ModelTransformer(Input input, const Transforms &transforms);
134 
136  Input m_input; // I don't own the model in this
137  Models m_outputs; // I own this, unless...
138  bool m_detached; // ... this is true.
141  QString m_message;
142 };
143 
144 #endif
void abandon()
Hint to the processing thread that it should give up, for example because the process is going to exi...
int getInputChannel()
Return the input channel spec for the transform.
Model * getModel() const
ModelTransformer(Input input, const Transform &transform)
static const int Input
std::vector< Transform > Transforms
Definition: Transform.h:200
QString getMessage() const
Return a warning or error message.
Models detachOutputModels()
Return the set of output models, also detaching them from the transformer so that they will not be de...
Input(Model *m, int c)
std::vector< Model * > Models
virtual Models detachAdditionalOutputModels()
Return the set of additional models, also detaching them from the transformer.
Transforms m_transforms
Model is the base class for all data models that represent any sort of data on a time scale based on ...
Definition: Model.h:35
virtual Models getAdditionalOutputModels()
Return any additional models that were created during processing.
virtual bool willHaveAdditionalOutputModels()
Return true if the current transform is one that may produce additional models (to be retrieved throu...
Models getOutputModels()
Return the set of output models created by the transform or transforms.
Definition: Thread.h:24
A ModelTransformer turns one data model into another.
Model * getInputModel()
Return the input model for the transform.
virtual ~ModelTransformer()