summaryrefslogtreecommitdiffstats
path: root/arts/modules/mixers/monosimplemixerchannel_impl.cc
blob: 04bad0cecd6de49e8cbbe5f792d9004cf6102d39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "artsmodulesmixers.h"
#include "flowsystem.h"
#include "stdsynthmodule.h"
#include "connect.h"

namespace Arts {
class MonoSimpleMixerChannel_impl : virtual public MonoSimpleMixerChannel_skel,
                                    virtual public StdSynthModule
{
protected:
	Synth_STD_EQUALIZER _equalizer;
	StereoEffectStack _insertEffects;
	Synth_MUL mulGain;
	Synth_MUL mulVolumeLeft, mulVolumeRight;
	float _gain, _pan, _volume, pLeft, pRight;
	std::string _name;
public:
	MonoSimpleMixerChannel_impl()
		: _gain(1.0), _pan(0), _volume(1.0), pLeft(1), pRight(1)
	{
		setValue(mulVolumeLeft,"invalue2",_volume*pLeft);
		setValue(mulVolumeRight,"invalue2",_volume*pRight);
		setValue(mulGain,"invalue2",_gain);
	}

	Synth_STD_EQUALIZER equalizer() { return _equalizer; }
	StereoEffectStack insertEffects() { return _insertEffects; }

	float gain() { return _gain; }
	void gain(float g)
	{
		if(g != _gain) {
			_gain = g;
			setValue(mulGain,"invalue2",g);
			gain_changed(g);
		}
	}

	float volume() { return _volume; }
	void volume(float v)
	{
		if(v != _volume) {
			_volume = v;
			setValue(mulVolumeLeft,"invalue2",v*pLeft);
			setValue(mulVolumeRight,"invalue2",v*pRight);
			volume_changed(v);
		}
	}

	float pan() { return _pan; }
	void pan(float p)
	{
		if(p != _pan)
		{
			_pan = p;
			pLeft = 1.0;
			pRight = 1.0;
			if(p > 0)
				pLeft = 1-p;
			else
				pRight = 1+p;
			setValue(mulVolumeLeft,"invalue2",_volume*pLeft);
			setValue(mulVolumeRight,"invalue2",_volume*pRight);
			pan_changed(p);
		}
	}

	std::string name() { return _name; }
	void name(const std::string& newName)
	{
		if(_name != newName) {
			_name = newName;
			name_changed(newName);
		}
	}

	void streamInit()
	{
		_equalizer.start();
		mulVolumeLeft.start();
		mulVolumeRight.start();
		mulGain.start();
		//_insertEffects.start();

		_node()->virtualize("inleft",mulGain._node(),"invalue1");
		connect(mulGain,"outvalue",_equalizer,"invalue");
		//connect(_equalizer,"outvalue",_insertEffects,"inleft");
		//connect(_insertEffects,"outleft",mulVolume,"invalue1");
		connect(_equalizer,"outvalue",mulVolumeLeft,"invalue1");
		connect(_equalizer,"outvalue",mulVolumeRight,"invalue1");
		_node()->virtualize("outleft",mulVolumeLeft._node(),"outvalue");
		_node()->virtualize("outright",mulVolumeRight._node(),"outvalue");

	}
	void streamEnd()
	{
		_equalizer.stop();
		//_insertEffects.stop();
		mulVolumeLeft.stop();
		mulVolumeRight.stop();
		mulGain.stop();
	}
};
REGISTER_IMPLEMENTATION(MonoSimpleMixerChannel_impl);
}