xref: /haiku/src/add-ons/media/media-add-ons/vst_host/VSTNode.h (revision 820dca4df6c7bf955c46e8f6521b9408f50b2900)
1 /*
2  * Copyright 2012, Gerasim Troeglazov (3dEyes**), 3dEyes@gmail.com.
3  * All rights reserved.
4  * Distributed under the terms of the MIT License.
5  */
6 
7 #ifndef __VST_NODE_H__
8 #define __VST_NODE_H__
9 
10 #include <Controllable.h>
11 #include <BufferProducer.h>
12 #include <BufferConsumer.h>
13 #include <MediaEventLooper.h>
14 
15 #include "VSTHost.h"
16 
17 class BMediaAddOn;
18 class BBufferGroup;
19 
20 #define BUFF_SIZE 0x2000
21 
22 #define ID_AUDIO_INPUT	1
23 #define	ID_AUDIO_OUTPUT 2
24 
25 //parameter IDs
26 enum param_id_t {
27 	P_MUTE		= 50,
28 	P_BYPASS,
29 
30 	P_PARAM		= 5000,
31 	P_ABOUT		= 6000,
32 	P_LABEL		= 7000,
33 	P_LABEL2	= 8000,
34 	P_LABEL3	= 9000,
35 };
36 
37 
38 class VSTNode : public	BBufferConsumer,
39 				public	BBufferProducer,
40 				public	BControllable,
41 				public	BMediaEventLooper {
42 public:
43 	virtual 				~VSTNode();
44 							VSTNode(BMediaAddOn *addon, const char *name,
45 								const char* path);
46 	//BMediaNode
47 public:
48 	virtual		BMediaAddOn *AddOn(int32 *id) const;
49 	virtual		status_t 	HandleMessage(int32 code, const void *data,	size_t size);
50 protected:
51 	virtual 	void 		NodeRegistered();
52 	//BControllable
53 public:
54 	virtual 	status_t 	GetParameterValue(int32 id,	bigtime_t *lastChangeTime,
55 									void *value, size_t *size);
56 	virtual 	void 		SetParameterValue(int32 id,	bigtime_t changeTime,
57 									const void *value, size_t size);
58 	//BBufferConsumer
59 public:
60 	virtual 	void 		BufferReceived(BBuffer *buffer);
61 	virtual 	status_t 	AcceptFormat(const media_destination &dst,
62 							media_format *format);
63 	virtual 	status_t 	GetNextInput(int32 *cookie,	media_input *input);
64 	virtual 	void 		DisposeInputCookie(int32 cookie);
65 	virtual 	status_t 	FormatChanged(const media_source &src,
66 									const media_destination &dst,
67 							int32 change_tag, const media_format &format);
68 	virtual 	void 		ProducerDataStatus(const media_destination &dst,
69 									int32 status,
70 									bigtime_t when);
71 	virtual 	status_t 	GetLatencyFor(const media_destination &dst,
72 							bigtime_t *latency,
73 							media_node_id *time_src);
74 	virtual 	status_t 	Connected(const media_source &src,
75 									const media_destination &dst,
76 									const media_format &format,
77 									media_input *input);
78 	virtual 	void 		Disconnected(const media_source &src,
79 									const media_destination &dst);
80 	//BBufferProducer
81 public:
82 	virtual 	status_t 	FormatSuggestionRequested(media_type type,
83 									int32 quality, media_format *format);
84 	virtual 	status_t 	FormatProposal(const media_source &src,
85 									media_format *format);
86 	virtual 	status_t 	FormatChangeRequested(const media_source &src,
87 									const media_destination &dst,
88 									media_format *format,
89 									int32* _deprecated_);
90 	virtual 	void 		LateNoticeReceived(const media_source &src,
91 									bigtime_t late,	bigtime_t when);
92 	virtual 	status_t	GetNextOutput(int32 *cookie, media_output *output);
93 	virtual 	status_t 	DisposeOutputCookie(int32 cookie);
94 	virtual 	status_t	SetBufferGroup(const media_source &src,
95 									BBufferGroup *group);
96 	virtual 	status_t 	PrepareToConnect(const media_source &src,
97 									const media_destination &dst,
98 									media_format *format, media_source *out_source,
99 									char *name);
100 	virtual 	void 		Connect(status_t status,
101 									const media_source &src,
102 									const media_destination &dst,
103 									const media_format &format,
104 									char* name);
105 	virtual		void 		Disconnect(const media_source &src,
106 									const media_destination &dst);
107 	virtual 	void 		EnableOutput(const media_source &src,
108 									bool enabled, int32* _deprecated_);
109 	virtual 	status_t 	GetLatency(bigtime_t *outLatency);
110 	virtual 	void 		LatencyChanged(	const media_source &src,
111 									const media_destination &dst,
112 									bigtime_t latency, uint32 flags);
113 	//BMediaEventLooper
114 protected:
115 	virtual 	bigtime_t 	OfflineTime();
116 	//VSTNode
117 protected:
118 	virtual 	void 		HandleEvent(const media_timed_event *event,
119 									bigtime_t late,
120 									bool realTimeEvent=false);
121 				void 		ParameterEventProcessing(const media_timed_event *event);
122 				status_t 	ValidateFormat(const media_format& preferredFormat,
123 									media_format &proposedFormat);
124 				void 		SetOutputFormat(media_format& ioFormat);
125 	virtual 	void 		InitParameterValues();
126 	virtual 	void 		InitParameterWeb();
127 	virtual 	void 		InitFilter();
128 	virtual 	bigtime_t 	GetFilterLatency();
129 	virtual 	void 		FilterBuffer(BBuffer* pBuffer);
130 
131 private:
132 	BMediaAddOn				*fAddOn;
133 	VSTPlugin				*fPlugin;
134 	BParameterWeb			*fWeb;
135 
136 	media_format			fPreferredFormat;
137 	media_format			fFormat;
138 	media_input				fInputMedia;
139 	media_output			fOutputMedia;
140 	bool					fOutputMediaEnabled;
141 	bigtime_t				fDownstreamLatency;
142 	bigtime_t				fProcessLatency;
143 
144 	int32					fBlockSize;
145 	int32					fMute;
146 	int32					fByPass;
147 	bigtime_t				fMuteLastChanged;
148 	bigtime_t				fByPassLastChanged;
149 };
150 
151 #endif //__VST_NODE_H__
152