Beatmup
signal_plot.h
Go to the documentation of this file.
1 /*
2  Beatmup image and signal processing library
3  Copyright (C) 2019, lnstadrum
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18 
19 #pragma once
20 #include "../bitmap/abstract_bitmap.h"
21 #include "../parallelism.h"
22 #include "signal.h"
23 #include <vector>
24 
25 namespace Beatmup {
26 namespace Audio {
27 
28  /**
29  AbstractTask drawing amplitude graph of a given Signal in a bitmap.
30  */
31  class SignalPlot : public AbstractTask, private BitmapContentLock {
32  private:
37  float scale;
38  int channels;
39 
40  std::vector<int> values;
41 
42  struct {
45 
46  /**
47  \internal
48  Computes plot data for a given thread.
49  */
50  void getPlot(TaskThread& thread, std::vector<int>& data, int& left, int& right);
51 
52  protected:
53  virtual bool process(TaskThread& thread);
55  virtual void afterProcessing(ThreadIndex, GraphicPipeline*, bool);
56  virtual TaskDeviceRequirement getUsedDevices() const;
57  virtual ThreadIndex getMaxThreads() const;
58 
59  public:
60  SignalPlot();
61 
62  /**
63  Sets the input signal to plot.
64  */
65  void setSignal(Signal*);
66 
67  /**
68  Sets the output bitmap.
69  */
71 
72  /**
73  Specifies a rectangular area in pixels in the output bitmap where the plot will be drawn.
74  */
76 
77  /**
78  Specifies a time range (X coordinate) and a magnitude range (Y coordinate scaled by `scale`) that will be plotted.
79  \param window a rectangle in time-value plane containing the two ranges
80  \param scale magnitude scaling factor
81  */
82  void setWindow(IntRectangle window, float scale);
83 
84  /**
85  Specifies plot colors.
86  \param bgColor background color
87  \param color1 main plotting color
88  \param color2 second plotting color used when plotting all the channels together (see setChannels())
89  */
91 
92  /**
93  Specifies which channels to plot
94  \param channels a channel number (counted from 0) to plot a single channel; any number out of correct range to plot all channels
95  */
96  void setChannels(int channels);
97 
98  inline AbstractBitmap* getBitmap() const { return bitmap; }
99  inline Signal* getSignal() const { return signal; }
100  };
101 
102 }
103 }
A very basic class for any image.
Task: an operation that can be executed by multiple threads in parallel.
Definition: parallelism.h:90
TaskDeviceRequirement
Specifies which device (CPU and/or GPU) is used to run the task.
Definition: parallelism.h:95
AbstractTask drawing amplitude graph of a given Signal in a bitmap.
Definition: signal_plot.h:31
std::vector< int > values
Definition: signal_plot.h:40
virtual ThreadIndex getMaxThreads() const
Gives the upper limint on the number of threads the task may be performed by.
struct Beatmup::Audio::SignalPlot::@0 palette
AbstractBitmap * getBitmap() const
Definition: signal_plot.h:98
void setSignal(Signal *)
Sets the input signal to plot.
void getPlot(TaskThread &thread, std::vector< int > &data, int &left, int &right)
Signal * getSignal() const
Definition: signal_plot.h:99
void setChannels(int channels)
Specifies which channels to plot.
void setPlotArea(IntRectangle)
Specifies a rectangular area in pixels in the output bitmap where the plot will be drawn.
AbstractBitmap * bitmap
Definition: signal_plot.h:34
void setPalette(color4i bgColor, color4i color1, color4i color2)
Specifies plot colors.
virtual void beforeProcessing(ThreadIndex, ProcessingTarget target, GraphicPipeline *)
Instruction called before the task is executed.
void setWindow(IntRectangle window, float scale)
Specifies a time range (X coordinate) and a magnitude range (Y coordinate scaled by scale) that will ...
virtual void afterProcessing(ThreadIndex, GraphicPipeline *, bool)
Instruction called after the task is executed.
virtual TaskDeviceRequirement getUsedDevices() const
Communicates devices (CPU and/or GPU) the task is run on.
virtual bool process(TaskThread &thread)
Executes the task on CPU within a given thread.
void setBitmap(AbstractBitmap *)
Sets the output bitmap.
An audio signal.
Definition: signal.h:36
Makes sure the bitmap content is accessible within an image processing task.
Definition: content_lock.h:34
Internal low-level GPU control API.
Definition: pipeline.h:33
Thread executing tasks.
Definition: parallelism.h:154
unsigned char ThreadIndex
number of threads / thread index
Definition: parallelism.h:68
ProcessingTarget
Definition: basic_types.h:55
jlong jlong jint jint jint jint jint left