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