ape  0.5.0
Audio Programming Environment
plot.h
Go to the documentation of this file.
1 #ifndef CPPAPE_PLOT_H
2 #define CPPAPE_PLOT_H
3 
4 #include "baselib.h"
5 #include <string>
6 #include <cmath>
7 #include <vector>
8 
9 namespace ape
10 {
14  template<std::size_t Size>
15  class Plot : public UIObject
16  {
17  public:
18 
22  typedef double value_type;
26  typedef value_type Proxy;
27 
32  Plot(std::string name)
33  : values(Size)
34  {
35  id = getInterface().createPlot(&getInterface(), name.c_str(), values.data(), values.size());
36  }
37 
42  {
43  getInterface().destroyResource(&getInterface(), id, 0);
44  }
45 
49  Proxy& operator [] (std::size_t index)
50  {
51  if (index < Size)
52  return values[index];
53 
54  abort("Index out of range for Plot");
55  }
56 
60  const value_type& operator [] (std::size_t index) const
61  {
62  if (index < Size)
63  return values[index];
64 
65  abort("Index out of range for Plot");
66  }
67 
71  const value_type* data() const noexcept
72  {
73  return values.data();
74  }
75 
79  constexpr std::size_t size() const noexcept
80  {
81  return Size;
82  }
83 
84  private:
85 
86  std::vector<value_type> values;
87  int id;
88  };
89 }
90 #endif
ape::getInterface
APE_SharedInterface & getInterface()
Acquire the low-level C API.
ape::Plot::operator[]
Proxy & operator[](std::size_t index)
Writable access to an element in the plot.
Definition: plot.h:49
ape::Plot
Fixed buffer of Plot::value_type elements that is plotted in the UI.
Definition: plot.h:15
ape::Plot::size
constexpr std::size_t size() const noexcept
Returns the Size
Definition: plot.h:79
ape::UIObject
Base traits class for all classes that are displayed in the GUI.
Definition: baselib.h:62
abort
void abort(const char *reason)
Terminate the script (not the host application!) safely, with a reason. All resources will automatica...
ape::Plot::~Plot
~Plot()
Destroys a plot.
Definition: plot.h:41
ape::Plot::Plot
Plot(std::string name)
Create a plot with a name .
Definition: plot.h:32
ape::Plot::Proxy
value_type Proxy
Assignable value to update the plot
Definition: plot.h:26
ape::Plot::data
const value_type * data() const noexcept
Read-only access to the underlying buffer
Definition: plot.h:71
ape
Definition: audiofile.h:7
baselib.h
ape::Plot::value_type
double value_type
The type of value being plotted
Definition: plot.h:22