1/*
2 * Copyright 2009, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 */
5#ifndef _CONTROLLABLE_H
6#define _CONTROLLABLE_H
7
8
9#include <MediaNode.h>
10
11
12class BParameterWeb;
13
14
15class BControllable : public virtual BMediaNode {
16protected:
17	virtual						~BControllable();
18
19public:
20
21	// Control change requests and notifications typically come in/go out in
22	// B_MEDIA_PARAMETERS type buffers (and a BControllable thus also needs
23	// to be a BBufferConsumer and/or a BBufferProducer).
24	// The format of these buffers is:
25	// 		media_node(node),
26	//		int32(count)
27	// 		repeat(count) {
28	//			int64(when),
29	//			int32(control_id),
30	//			int32(value_size),
31	//			<value>
32	//		}
33
34			BParameterWeb*		Web();
35			bool				LockParameterWeb();
36			void				UnlockParameterWeb();
37
38protected:
39
40								BControllable();
41
42	// NOTE: Call SetParameterWeb() from your constructor!
43			status_t			SetParameterWeb(BParameterWeb* web);
44
45	virtual	status_t			HandleMessage(int32 message, const void* data,
46									size_t size);
47
48	// Call when the actual control changes, NOT when the value changes.
49	// A typical case would be a CD with a Selector for Track when a new
50	// CD is inserted.
51			status_t			BroadcastChangedParameter(int32 id);
52
53	// Call this function when a value change takes effect, and
54	// you want people who are interested to stay in sync with you.
55	// Don't call this too densely, though, or you will flood the system
56	// with messages.
57			status_t			BroadcastNewParameterValue(
58									bigtime_t performanceTime,
59									int32 parameterID, void* newValue,
60									size_t valueSize);
61
62	// These are alternate methods of accomplishing the same thing as
63	// connecting to control information source/destinations would.
64	virtual	status_t			GetParameterValue(int32 id,
65									bigtime_t* lastChange,
66									void* value, size_t* ioSize) = 0;
67
68	virtual	void				SetParameterValue(int32 id, bigtime_t when,
69									const void* value, size_t size) = 0;
70
71	// The default implementation of StartControlPanel launches the add-on
72	// as an application (if the Node lives in an add-on). Thus, you can
73	// write your control panel as a "main()" in your add-on, and it'll
74	// automagically work! Your add-on needs to have multi-launch app flags
75	// for this to work right. The first argv argument to main() will be a
76	// string of the format "node=%d" with the node ID in question as "%d".
77	virtual	status_t			StartControlPanel(BMessenger* _messenger);
78
79	// Call this from your BufferReceived() for control information buffers
80	// if you implement BBufferConsumer for that format (recommended!)
81			status_t			ApplyParameterData(const void* value,
82									size_t size);
83	// If you want to generate control information for a set of controls, you
84	// can use this utility function.
85			status_t			MakeParameterData(const int32* controls,
86									int32 count, void* buffer, size_t* ioSize);
87
88	// TODO: Needs a Perform() virtual method!
89
90private:
91	// FBC padding and forbidden methods
92								BControllable(const BControllable& other);
93			BControllable&		operator=(const BControllable& other);
94
95	virtual	status_t				_Reserved_Controllable_0(void*);
96	virtual	status_t				_Reserved_Controllable_1(void*);
97	virtual	status_t				_Reserved_Controllable_2(void*);
98	virtual	status_t				_Reserved_Controllable_3(void*);
99	virtual	status_t				_Reserved_Controllable_4(void*);
100	virtual	status_t				_Reserved_Controllable_5(void*);
101	virtual	status_t				_Reserved_Controllable_6(void*);
102	virtual	status_t				_Reserved_Controllable_7(void*);
103	virtual	status_t				_Reserved_Controllable_8(void*);
104	virtual	status_t				_Reserved_Controllable_9(void*);
105	virtual	status_t				_Reserved_Controllable_10(void*);
106	virtual	status_t				_Reserved_Controllable_11(void*);
107	virtual	status_t				_Reserved_Controllable_12(void*);
108	virtual	status_t				_Reserved_Controllable_13(void*);
109	virtual	status_t				_Reserved_Controllable_14(void*);
110	virtual	status_t				_Reserved_Controllable_15(void*);
111
112private:
113			friend class BMediaNode;
114
115			BParameterWeb*		fWeb;
116			sem_id				fSem;
117			int32				fBen;
118
119			uint32				_reserved_controllable_[14];
120};
121
122
123#endif // _CONTROLLABLE_H
124
125