#include <jezabeltool.h>
Inheritance diagram for JezabelTool::
Public Types | |
enum | JezabelPortType { portInput, portOutput } |
enum | JezabelProperty { Property_RealTime = 0x01 } |
Public Methods | |
JezabelTool () | |
virtual void | activate () |
virtual void | run (int samples)=0 |
virtual void | seek (JezabelPosition position) |
virtual JezabelPosition | length () |
virtual void | deactivate () |
virtual int | blockSize () |
int | numPorts () |
JezabelPortType | portType (int port) |
virtual void | setBuffer (int port, JezabelData *buffer) |
virtual const char* | strerror () |
Protected Methods | |
void | makePort (JezabelPortType) |
JezabelData* | portBuffer (int n) |
Generally speaking, a JezabelTool is used in the following way:
1) An instance is created using its constructor, like this:
ToolClass(...parameters...)
For example, the parameters of a band-pass filter might be gain, center frequency and bandwidth.
Tools that can be controlled by the user in real time will typically have as a parameter a pointer to an object the contains the control values. Since the tool runs in a different thread from the UI, it must assume that these values can change asynchronously.
2) The user queries the tool to determine the number and types of its ports by calling numPorts and portType. A port is either of type portInput or portOutput. Each port represents a conceptually unbounded stream of values of type JezabelData (i.e., single precision IEEE floats).
3) The user assigns data buffers to the ports by calling setBuffer. The same buffer can be used as both input and output of a tool. The result is that the data in the buffer are modified in place.
4) The user calls "activate", to warn that the tool is about to be run. This usually does nothing, but can be used, for example, to open files or devices, or in general to allocate resources that should be held only when the tool is running. The method returns "false" if for some reason the tool can't be activated (for example because resources aren't available).
5) The user repeatedly calls "run", causing the tool to process a given number of samples in its buffers. This returns "false" in case of a run-time error that should halt operation of the tool.
6) The user calls "deactivate". This usually does nothing, but can be used, for example, to close files or devices, or to free any resources allocate by "activate". The process can now be restarted at "activate", or the tool can be destructed. The method returns "false" in case of an error.
Between "activate" and "deactivate", it is also possible to call "seek" to cause the tool to move to a given sample position in the stream, or "length", to determine the length of the stream, in case this is meaningful. In most cases, "seek" does nothing, and "length" returns JezabelLengthMax, indicating an infinite stream.
Finally, the method "strerror" should return a string indicating the the error in the most recent operation, or NULL if no error.
Generally, the constructor of the tool stores the parameter values somewhere, and creates the ports, like this:
BandPassFilter::BandPassFilter(float _freq, float _bandwidth) { freq = _freq; bandwidth = _bandwidth; makePort(portInput); makePort(portOutput); }
At a minimum, the tool must also override the "run" method. The "run" method looks like this:
BandPassFilter::run(int samples){ // get pointers to the input and output bufers JezabelData *inp = portBuffer(0); JezabelData *out = portBuffer(1); // process some samples for(i = 0; i < samples; i++, inp++, out++){ ... compute something ... } }
|
Port types |
|
Poperties |
|
Default constructor |
|
Warns tool we are about to call "run" Reimplemented in JezabelPatchTool. |
|
Return the maximum number of samples that this tool can handle with a call to run(), or zero if there is no maximum. Reimplemented in JezabelPatchTool. |
|
Indicate we are done calling run, and will not call run again until activate is called. Reimplemented in JezabelPatchTool. |
|
Return the length of the stream for this tool. This only makes sense for some tools, and will return JezabelLengthMax if the is no upper bound on the length. Reimplemented in JezabelPatchTool. |
|
create a port |
|
Returns the number of ports for this tool |
|
get pointer to the buffer for port "n" |
|
Returns the type of port "port" |
|
Run the tool on "samples" samples, which must be less than or equal to "max_request". Reimplemented in JezabelPatchTool. |
|
Seek to a given position. This only makes sense for some tools, and is ignored by others. Reimplemented in JezabelPatchTool. |
|
Assign buffer "buffer" to port "port*. Must be called for all ports before calling "activate" Reimplemented in JezabelPatchTool. |
|
Returns string describing error in most recent operation, or null is no error Reimplemented in JezabelPatchTool. |