CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

BinaryOp.h
Go to the documentation of this file.
1 ///
2 /// BinaryOp.h -- The specification file for simple arithmetic operations on UnitGenerators.
3 /// See the copyright notice and acknowledgment of authors in the file COPYRIGHT
4 ///
5 /// What's here:
6 ///
7 /// BinaryOp -- an abstract class that specific binary operators (add, mul, etc.) inherit from)
8 /// AddOp -- Adds two UnitGenerators (or a UnitGenerator and a scalar) together
9 /// MulOp -- Multiplies two UnitGenerators (or a UnitGenerator and a scalar) together
10 ///
11
12 #ifndef CSL_BINARYOP_H
13 #define CSL_BINARYOP_H
14
15 #include "CSL_Core.h"
16
17 namespace csl {
18
19 ///
20 /// BinaryOp -- An Effect that takes two input sources (UnitGenerators or scalars) and
21 /// gives a single UnitGenerator as its output. BinaryOp is an abstract class who's nextBuffer
22 /// method is to be implemented by subclasses
23 ///
24
25 class BinaryOp : public Effect {
26
27 public: /// The constructor for dual-UnitGenerator operation
28 BinaryOp(UnitGenerator & op1, UnitGenerator & op2);
29 /// Constructuctor for operating a UnitGenerator and a fixed float
30 BinaryOp(UnitGenerator & op1, float op2);
31 /// The same constructor, but with UGen and float inputs
32 BinaryOp(float op1, UnitGenerator & op2);
33 virtual ~BinaryOp(); ///< The destructor
34
35 void dump(); ///< Prints instance info
36 void setOperand(float op); ///< Set the operand from a fixed float
37
38 protected:
39 /// Abstract function that will do the processing for each buffer
40 virtual void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw(CException) = 0;
41 /// Is the input fixed or a dynamic UnitGenerator?
42 inline bool isFixed();
43 inline bool inputIsFixed();
44 /// Is the operand fixed or a dynamic UnitGenerator?
45 inline bool operandIsFixed();
46 /// Convert the dynamic operand to a fixed sample (if operand is fixed)
47 inline sample operandFixedValue(Buffer & outputBuffer);
48
49 };
50
51 inline bool BinaryOp::inputIsFixed() {
52 return (Effect::inPort())->isFixed();
53 }
54
55 inline bool BinaryOp::operandIsFixed() {
56 return mInputs[CSL_OPERAND]->isFixed();
57 }
58
59 /// Declare the operand port (accessing the mInputs map) and current value.
60
61 #define DECLARE_OPERAND_CONTROLS \
62 Port * opPort = mInputs[CSL_OPERAND]; \
63 SampleBuffer inValue; \
64 sample opValue
65
66 /// Load the op-related values at the start of the callback; if the operand is a dynamic UGen input,
67 /// then pull its value, get the pointer to its buffer, and set the first value, otherwise store the constant value
68
69 #define LOAD_OPERAND_CONTROLS \
70 Controllable::pullInput(opPort, numFrames); \
71 Effect::pullInput(numFrames); \
72 inValue = mInputPtr; \
73 opValue = opPort->nextValue()
74
75 /// Update the op-related value in the loop
76
77 #define UPDATE_OPERAND_CONTROLS \
78 opValue = opPort->nextValue() ; \
79 inValue++
80
81 ///
82 /// AddOp -- A BinaryOp that adds two UnitGenerators or fixed constants together.
83 ///
84
85 class AddOp : public BinaryOp {
86
87 public: /// The constructor for dual-UnitGenerator operation
88 AddOp(UnitGenerator & op1, UnitGenerator & op2);
89 /// Constructuctor for operating a UnitGenerator and a fixed float
90 AddOp(UnitGenerator & op1, float op2);
91 /// Returns the next individual frame (for fixed values)
92 AddOp(float op1, UnitGenerator & op2);
93
94 // float nextValue() throw (CException);
95
96 protected: /// Function that implements the adding routine
97 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) ;
98 };
99
100 ///
101 /// MulOp -- A BinaryOp that multiplies two UnitGenerators or fixed constants together, sample-by-sample.
102 ///
103
104 class MulOp : public BinaryOp {
105
106 public: /// The constructor for dual-UnitGenerator operation
107 MulOp(UnitGenerator & op1, UnitGenerator & op2);
108 /// Constructuctor for operating a UnitGenerator and a fixed float
109 MulOp(UnitGenerator & op1, float op2);
110
111 MulOp(float op2, UnitGenerator & op1);
112 /// Returns the next individual frame (for fixed values)
113 // float nextValue() throw (CException);
114
115 protected: /// Function that implements the multiplying routine
116 void nextBuffer(Buffer & outputBuffer, unsigned outBufNum) throw (CException) ;
117
118 };
119
120 }
121
122 #endif // CSL_BINARYOP_H
123