Nsound  0.9.4
Plotter.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 //
3 // $Id: Plotter.h 912 2015-07-26 00:50:29Z weegreenblobbie $
4 //
5 // Nsound is a C++ library and Python module for audio synthesis featuring
6 // dynamic digital filters. Nsound lets you easily shape waveforms and write
7 // to disk or plot them. Nsound aims to be as powerful as Csound but easy to
8 // use.
9 //
10 // Copyright (c) 2005-Present Nick Hilton
11 //
12 // weegreenblobbie_yahoo_com (replace '_' with '@' and '.')
13 //
14 //-----------------------------------------------------------------------------
15 
16 //-----------------------------------------------------------------------------
17 //
18 // This program is free software; you can redistribute it and/or modify
19 // it under the terms of the GNU General Public License as published by
20 // the Free Software Foundation; either version 2 of the License, or
21 // (at your option) any later version.
22 //
23 // This program is distributed in the hope that it will be useful,
24 // but WITHOUT ANY WARRANTY; without even the implied warranty of
25 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 // GNU Library General Public License for more details.
27 //
28 // You should have received a copy of the GNU General Public License
29 // along with this program; if not, write to the Free Software
30 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 //
32 //-----------------------------------------------------------------------------
33 #ifndef _NSOUND_PLOTTER_H_
34 #define _NSOUND_PLOTTER_H_
35 
36 #include <Nsound/Nsound.h>
37 
38 #include <map>
39 #include <string>
40 
41 
42 namespace Nsound
43 {
44 
45 class AudioStream;
46 class Buffer;
47 
48 #if ! ( defined(NSOUND_C_PYLAB) || defined(NSOUND_IN_PYTHON_MODULE) )
49  typedef void PyObject;
50 #endif
51 
52 //-----------------------------------------------------------------------------
54 class Axes
55 {
56  public:
57 
58  Axes(PyObject * axes_ptr);
59  Axes(const Axes & copy);
60  ~Axes();
61  Axes & operator=(const Axes & rhs);
62  PyObject * get_axes(){return axes_ptr_;};
63 
64  private:
65 
67 };
68 
69 //-----------------------------------------------------------------------------
70 // DOXME
71 class Plotter
72 {
73  public:
74 
76  Plotter();
77 
79  virtual ~Plotter();
80 
82  void
83  axhline(
84  const float64 & y_pos = 0.0,
85  const std::string & kwargs = "");
86 
88  void
89  axvline(
90  const float64 & x_pos = 0.0,
91  const std::string & kwargs = "");
92 
94  void xlim(const float64 & xmin, const float64 & xmax);
95  void ylim(const float64 & ymin, const float64 & ymax);
96 
98  void figure(const std::string & kwargs="") const;
99 
101  void grid(boolean flag);
102 
104  void hide();
105 
107  void hold(boolean flag);
108 
110  void imagesc(
111  const AudioStream & Z,
112  const std::string & kwargs="");
113 
115  void imagesc(
116  const Buffer & x_axis,
117  const Buffer & y_axis,
118  const AudioStream & Z,
119  const std::string & kwargs="");
120 
122  void legend(const std::string & kwargs="");
123 
125  void plot(
126  const Buffer & y,
127  const std::string & fmt = "",
128  const std::string & kwargs = "");
129 
131  void plot(
132  const Buffer & x,
133  const Buffer & y,
134  const std::string & fmt = "",
135  const std::string & kwargs = "");
136 
138  void plot(
139  const float64 & x,
140  const float64 & y,
141  const std::string & fmt = "",
142  const std::string & kwargs = "");
143 
145  void run_string(const std::string & command) const;
146 
148  void
149  savefig(const std::string & filename, const std::string & kwargs = "");
150 
152  void
153  set_xscale(const std::string & s);
154 
156  void
157  set_yscale(const std::string & s);
158 
160  //
167  Axes
168  subplot(
169  const uint32 n_rows,
170  const uint32 n_cols,
171  const uint32 n,
172  const std::string & kwargs = "",
173  Axes * sharex = NULL,
174  Axes * sharey = NULL);
175 
177  void text(
178  const float64 & x,
179  const float64 & y,
180  const std::string & text,
181  const std::string & kwargs = "");
182 
184  void title(const std::string & title, const std::string & kwargs="");
185 
187  void xlabel(const std::string & label, const std::string & kwargs="");
188 
190  void ylabel(const std::string & label, const std::string & kwargs="");
191 
193  static
194  void
195  show();
196 
198  void _swig_shadow(){};
199 
200  protected:
201 
202  typedef std::pair < std::string, PyObject * > StringPyObjectPair;
203  typedef std::map < std::string, PyObject * > PylabTable;
204 
205  PyObject * _make_kwargs(const std::string & kwargs) const;
206 
207  static int32 count_;
208 
210 
212  {
216  };
217 
219 
220  static boolean grid_is_on_;
221  static boolean hold_is_on_;
222 
223  static float64 xmin_;
224  static float64 xmax_;
225  static float64 ymin_;
226  static float64 ymax_;
227 
228  // disable these
229  private:
230 
232  Plotter(const Plotter & rhs);
233 
235  Plotter & operator=(const Plotter & rhs);
236 
238  PyObject * makePyListFromBuffer(const Buffer & buffer) const;
239 
241  PyObject * makePyIntFromUint32(const uint32 & i) const;
242 
243 };
244 
245 } // namespace
246 
247 // :mode=c++: jEdit modeline
248 
249 #endif
PyObject * makePyIntFromUint32(const uint32 &i) const
Create a PyInt.
unsigned int uint32
Definition: Nsound.h:153
void xlabel(const std::string &label, const std::string &kwargs="")
Add a label x axis.
Definition: Plotter.cc:1154
void grid(boolean flag)
Sets the grid state.
Definition: Plotter.cc:496
PyObject * get_axes()
Definition: Plotter.h:62
PyObject * _make_kwargs(const std::string &kwargs) const
Definition: Plotter.cc:292
static void show()
Acutally draw the plots to the screen.
Definition: Plotter.cc:252
static PylabTable table_
Definition: Plotter.h:209
void savefig(const std::string &filename, const std::string &kwargs="")
Saves the last figure drawn to filename.
Definition: Plotter.cc:951
static boolean grid_is_on_
Definition: Plotter.h:220
void plot(const Buffer &y, const std::string &fmt="", const std::string &kwargs="")
Plots the Buffer on the current figure.
Definition: Plotter.cc:765
static float64 xmin_
Definition: Plotter.h:223
void axvline(const float64 &x_pos=0.0, const std::string &kwargs="")
Draws a vertical line at x and spans ymin to ymax (ralitive).
Definition: Plotter.cc:358
void hide()
Hides all plots, prevents any plot window being rendered to the screen. Usefull if only saveing plots...
Definition: Plotter.cc:525
void figure(const std::string &kwargs="") const
Creates a new figure window to plot in.
Definition: Plotter.cc:455
void _swig_shadow()
SWIG helper function function to shadow.
Definition: Plotter.h:198
A wrapper around a Matplotlib Axes object.
Definition: Plotter.h:54
void title(const std::string &title, const std::string &kwargs="")
Add a title to the plot at the top and centered.
Definition: Plotter.cc:1127
std::pair< std::string, PyObject * > StringPyObjectPair
Definition: Plotter.h:198
void legend(const std::string &kwargs="")
Shows the legend on the current axes.
Definition: Plotter.cc:745
static float64 ymin_
Definition: Plotter.h:225
void xlim(const float64 &xmin, const float64 &xmax)
Sets the limit for the x & y axis.
Definition: Plotter.cc:389
PyObject * makePyListFromBuffer(const Buffer &buffer) const
Create a PyList object from a buffer!
static boolean hold_is_on_
Definition: Plotter.h:221
double float64
Definition: Nsound.h:146
void set_yscale(const std::string &s)
Sets the y axis scaling: log or linear.
Definition: Plotter.cc:1013
void set_xscale(const std::string &s)
Sets the x axis scaling: log or linear.
Definition: Plotter.cc:995
Plotter()
Construct the Plotter.
Definition: Plotter.cc:114
Axes subplot(const uint32 n_rows, const uint32 n_cols, const uint32 n, const std::string &kwargs="", Axes *sharex=NULL, Axes *sharey=NULL)
Creates a figure in a subplot, subplot(A, B, C, **kwargs)
Definition: Plotter.cc:1031
void ylim(const float64 &ymin, const float64 &ymax)
Definition: Plotter.cc:422
void PyObject
Definition: Plotter.h:46
PyObject * axes_ptr_
Definition: Plotter.h:62
void imagesc(const AudioStream &Z, const std::string &kwargs="")
Plots the AudioStream like a 2D matrix.
Definition: Plotter.cc:593
void text(const float64 &x, const float64 &y, const std::string &text, const std::string &kwargs="")
Adds text at the x, y data point.
Definition: Plotter.cc:1092
Plotter & operator=(const Plotter &rhs)
Asignment disabled.
void hold(boolean flag)
Sets the hold state.
Definition: Plotter.cc:554
Axes & operator=(const Axes &rhs)
Definition: Plotter.cc:91
static float64 xmax_
Definition: Plotter.h:224
Axes(PyObject *axes_ptr)
Definition: Plotter.cc:73
static PlotterState state_
Definition: Plotter.h:218
void ylabel(const std::string &label, const std::string &kwargs="")
Add a label y axis.
Definition: Plotter.cc:1180
A Buffer for storing audio samples.
Definition: Buffer.h:60
signed int int32
Definition: Nsound.h:142
void axhline(const float64 &y_pos=0.0, const std::string &kwargs="")
Draws a horizontal line at y and spans xmin to xmax (ralitive).
Definition: Plotter.cc:327
std::map< std::string, PyObject * > PylabTable
Definition: Plotter.h:203
static int32 count_
Definition: Plotter.h:207
void run_string(const std::string &command) const
executes the python string
Definition: Plotter.cc:933
static float64 ymax_
Definition: Plotter.h:226
virtual ~Plotter()
Deconstruct the Plotter.
Definition: Plotter.cc:230