File: ProcessingObject_controls_example.cxx

package info (click to toggle)
clam 1.4.0-6
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 17,836 kB
  • ctags: 20,981
  • sloc: cpp: 92,504; python: 9,721; ansic: 1,602; xml: 444; sh: 239; makefile: 153; perl: 54; asm: 15
file content (149 lines) | stat: -rw-r--r-- 4,048 bytes parent folder | download | duplicates (2)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
 * Copyright (c) 2001-2004 MUSIC TECHNOLOGY GROUP (MTG)
 *                         UNIVERSITAT POMPEU FABRA
 *
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */


/**
 * @example  ProcessingObject_controls_example.cxx
 * This example shows several things about using controls
 *  - How to connect controls each other
 *  - How to explicitly propagate a value from an output control using SendControl
 *  - How to explicitly set a value to a input control using DoControl
 *  - How to associate processing callbacks to an input control
 */

///////////////////////////////////////////////////////////////////////////////////
// class MyProcObj
// Just a test class.
//

#include "Processing.hxx"
#include "OutControl.hxx"
#include <string>
#include <stdexcept>

#include <iostream> 

using namespace CLAM;

// Empty configuration for our processing
class MyProcConf : public ProcessingConfig {
public:
	DYNAMIC_TYPE_USING_INTERFACE (MyProcConf, 0,ProcessingConfig);
};


// A processing with some controls
class MyProcObj : public Processing
{
private:
	MyProcConf mConfig;
	FloatInControl mInPitch;
	FloatInControl mInAmplitude;
	
	FloatOutControl mOutNoteOn;
	FloatOutControl mOutNoteOff;
private:
	bool ConcreteConfigure(const ProcessingConfig &c) {return true;}
// Constructor/Destructor
public:
	MyProcObj(const MyProcConf &c) :
		// Asocciating callbacks to the control receiving
		mInPitch("Pitch", this, &MyProcObj::DoInPitchControl),
		mInAmplitude("Amplitude", this, &MyProcObj::DoInAmplitudeControl),

		mOutNoteOn("NoteOn", this),
		mOutNoteOff("NoteOff", this)
	{
		Configure(c);
	}
	virtual ~MyProcObj(){}
	const char * GetClassName() const {return "CLAMTest_MyProcObj";}
	
public:
	// Callbacks to receive controls
	void DoInPitchControl(TControlData val) 
	{ 
		std::cout << GetClassName() << ": DoInPitchControl activated. Value="<< val << std::endl;  
	}
	void DoInAmplitudeControl(TControlData val) 
	{ 
		std::cout << GetClassName() << ": DoInAmplitudeControl activated. Value="<< val << std::endl;  
	}

	// The do
	bool Do() 
	{
		std::cout << GetClassName() << ": doing my Do()... " << std::endl;
		return true;
	}
	const ProcessingConfig &GetConfig() const { return mConfig;};
	virtual bool Start(void) {return true;};
	virtual bool Stop(void) {return true;};
};


int main(void)
{
	try {
		MyProcConf conf1;
		conf1.UpdateData();
		MyProcObj proc1(conf1);
		MyProcObj proc2(conf1);
		MyProcObj proc3(conf1);

		// Connection by number.
		// Its also possible to connect them using control
		// names: "Pitch", "Amplitude", "NoteOn" and "NoteOff"

		CLAM::ConnectControls( proc1, "NoteOn",  proc2, "Amplitude");
		CLAM::ConnectControls( proc1, "NoteOff", proc2, "Pitch");
		CLAM::ConnectControls( proc1, "NoteOn",  proc3, "Amplitude");
		CLAM::ConnectControls( proc1, "NoteOn",  proc3, "Pitch");

		// SendControl propagates the value from an output control
		// to its connected in controls.

		// From proc1:Out[0] to proc2:In[0], proc3:In[0] and proc3:In[1]
		SendFloatToOutControl(proc1,"NoteOn",44);
		// From proc1:Out[1] to proc2:In[1]
		SendFloatToOutControl(proc1,"NoteOff",555);

		// 
		SendFloatToOutControl(proc1,0,222.2f);

		// Useless Do's, they are not necessary for the example
		proc1.Do();
		proc2.Do();


	}catch(std::out_of_range e)
	{
		std::cerr << e.what() << std::endl;
	}
	catch(Err e)
	{
		e.Print();
	}
	
	return 0;

}