1 /**
2 Plays positional sound in 2D space.
3 
4 Copyright:
5 Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur.  
6 Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md)  
7 Copyright (c) 2017-2018 Godot-D contributors  
8 
9 License: $(LINK2 https://opensource.org/licenses/MIT, MIT License)
10 
11 
12 */
13 module godot.audiostreamplayer2d;
14 import std.meta : AliasSeq, staticIndexOf;
15 import std.traits : Unqual;
16 import godot.d.traits;
17 import godot.core;
18 import godot.c;
19 import godot.d.bind;
20 import godot.d.reference;
21 import godot.globalenums;
22 import godot.object;
23 import godot.classdb;
24 import godot.node2d;
25 import godot.audiostream;
26 import godot.audiostreamplayback;
27 /**
28 Plays positional sound in 2D space.
29 
30 Plays audio that dampens with distance from screen center.
31 See also $(D AudioStreamPlayer) to play a sound non-positionally.
32 $(B Note:) Hiding an $(D AudioStreamPlayer2D) node does not disable its audio output. To temporarily disable an $(D AudioStreamPlayer2D)'s audio output, set $(D volumeDb) to a very low value like `-100` (which isn't audible to human hearing).
33 */
34 @GodotBaseClass struct AudioStreamPlayer2D
35 {
36 	package(godot) enum string _GODOT_internal_name = "AudioStreamPlayer2D";
37 public:
38 @nogc nothrow:
39 	union { /** */ godot_object _godot_object; /** */ Node2D _GODOT_base; }
40 	alias _GODOT_base this;
41 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
42 	package(godot) __gshared bool _classBindingInitialized = false;
43 	package(godot) static struct GDNativeClassBinding
44 	{
45 		__gshared:
46 		@GodotName("_bus_layout_changed") GodotMethod!(void) _busLayoutChanged;
47 		@GodotName("_is_active") GodotMethod!(bool) _isActive;
48 		@GodotName("_set_playing") GodotMethod!(void, bool) _setPlaying;
49 		@GodotName("get_area_mask") GodotMethod!(long) getAreaMask;
50 		@GodotName("get_attenuation") GodotMethod!(double) getAttenuation;
51 		@GodotName("get_bus") GodotMethod!(String) getBus;
52 		@GodotName("get_max_distance") GodotMethod!(double) getMaxDistance;
53 		@GodotName("get_pitch_scale") GodotMethod!(double) getPitchScale;
54 		@GodotName("get_playback_position") GodotMethod!(double) getPlaybackPosition;
55 		@GodotName("get_stream") GodotMethod!(AudioStream) getStream;
56 		@GodotName("get_stream_paused") GodotMethod!(bool) getStreamPaused;
57 		@GodotName("get_stream_playback") GodotMethod!(AudioStreamPlayback) getStreamPlayback;
58 		@GodotName("get_volume_db") GodotMethod!(double) getVolumeDb;
59 		@GodotName("is_autoplay_enabled") GodotMethod!(bool) isAutoplayEnabled;
60 		@GodotName("is_playing") GodotMethod!(bool) isPlaying;
61 		@GodotName("play") GodotMethod!(void, double) play;
62 		@GodotName("seek") GodotMethod!(void, double) seek;
63 		@GodotName("set_area_mask") GodotMethod!(void, long) setAreaMask;
64 		@GodotName("set_attenuation") GodotMethod!(void, double) setAttenuation;
65 		@GodotName("set_autoplay") GodotMethod!(void, bool) setAutoplay;
66 		@GodotName("set_bus") GodotMethod!(void, String) setBus;
67 		@GodotName("set_max_distance") GodotMethod!(void, double) setMaxDistance;
68 		@GodotName("set_pitch_scale") GodotMethod!(void, double) setPitchScale;
69 		@GodotName("set_stream") GodotMethod!(void, AudioStream) setStream;
70 		@GodotName("set_stream_paused") GodotMethod!(void, bool) setStreamPaused;
71 		@GodotName("set_volume_db") GodotMethod!(void, double) setVolumeDb;
72 		@GodotName("stop") GodotMethod!(void) stop;
73 	}
74 	/// 
75 	pragma(inline, true) bool opEquals(in AudioStreamPlayer2D other) const
76 	{ return _godot_object.ptr is other._godot_object.ptr; }
77 	/// 
78 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
79 	{ _godot_object.ptr = n; return null; }
80 	/// 
81 	pragma(inline, true) bool opEquals(typeof(null) n) const
82 	{ return _godot_object.ptr is n; }
83 	/// 
84 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
85 	mixin baseCasts;
86 	/// Construct a new instance of AudioStreamPlayer2D.
87 	/// Note: use `memnew!AudioStreamPlayer2D` instead.
88 	static AudioStreamPlayer2D _new()
89 	{
90 		static godot_class_constructor constructor;
91 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AudioStreamPlayer2D");
92 		if(constructor is null) return typeof(this).init;
93 		return cast(AudioStreamPlayer2D)(constructor());
94 	}
95 	@disable new(size_t s);
96 	/**
97 	
98 	*/
99 	void _busLayoutChanged()
100 	{
101 		Array _GODOT_args = Array.make();
102 		String _GODOT_method_name = String("_bus_layout_changed");
103 		this.callv(_GODOT_method_name, _GODOT_args);
104 	}
105 	/**
106 	
107 	*/
108 	bool _isActive() const
109 	{
110 		Array _GODOT_args = Array.make();
111 		String _GODOT_method_name = String("_is_active");
112 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
113 	}
114 	/**
115 	
116 	*/
117 	void _setPlaying(in bool enable)
118 	{
119 		Array _GODOT_args = Array.make();
120 		_GODOT_args.append(enable);
121 		String _GODOT_method_name = String("_set_playing");
122 		this.callv(_GODOT_method_name, _GODOT_args);
123 	}
124 	/**
125 	
126 	*/
127 	long getAreaMask() const
128 	{
129 		checkClassBinding!(typeof(this))();
130 		return ptrcall!(long)(GDNativeClassBinding.getAreaMask, _godot_object);
131 	}
132 	/**
133 	
134 	*/
135 	double getAttenuation() const
136 	{
137 		checkClassBinding!(typeof(this))();
138 		return ptrcall!(double)(GDNativeClassBinding.getAttenuation, _godot_object);
139 	}
140 	/**
141 	
142 	*/
143 	String getBus() const
144 	{
145 		checkClassBinding!(typeof(this))();
146 		return ptrcall!(String)(GDNativeClassBinding.getBus, _godot_object);
147 	}
148 	/**
149 	
150 	*/
151 	double getMaxDistance() const
152 	{
153 		checkClassBinding!(typeof(this))();
154 		return ptrcall!(double)(GDNativeClassBinding.getMaxDistance, _godot_object);
155 	}
156 	/**
157 	
158 	*/
159 	double getPitchScale() const
160 	{
161 		checkClassBinding!(typeof(this))();
162 		return ptrcall!(double)(GDNativeClassBinding.getPitchScale, _godot_object);
163 	}
164 	/**
165 	Returns the position in the $(D AudioStream).
166 	*/
167 	double getPlaybackPosition()
168 	{
169 		checkClassBinding!(typeof(this))();
170 		return ptrcall!(double)(GDNativeClassBinding.getPlaybackPosition, _godot_object);
171 	}
172 	/**
173 	
174 	*/
175 	Ref!AudioStream getStream() const
176 	{
177 		checkClassBinding!(typeof(this))();
178 		return ptrcall!(AudioStream)(GDNativeClassBinding.getStream, _godot_object);
179 	}
180 	/**
181 	
182 	*/
183 	bool getStreamPaused() const
184 	{
185 		checkClassBinding!(typeof(this))();
186 		return ptrcall!(bool)(GDNativeClassBinding.getStreamPaused, _godot_object);
187 	}
188 	/**
189 	Returns the $(D AudioStreamPlayback) object associated with this $(D AudioStreamPlayer2D).
190 	*/
191 	Ref!AudioStreamPlayback getStreamPlayback()
192 	{
193 		checkClassBinding!(typeof(this))();
194 		return ptrcall!(AudioStreamPlayback)(GDNativeClassBinding.getStreamPlayback, _godot_object);
195 	}
196 	/**
197 	
198 	*/
199 	double getVolumeDb() const
200 	{
201 		checkClassBinding!(typeof(this))();
202 		return ptrcall!(double)(GDNativeClassBinding.getVolumeDb, _godot_object);
203 	}
204 	/**
205 	
206 	*/
207 	bool isAutoplayEnabled()
208 	{
209 		checkClassBinding!(typeof(this))();
210 		return ptrcall!(bool)(GDNativeClassBinding.isAutoplayEnabled, _godot_object);
211 	}
212 	/**
213 	
214 	*/
215 	bool isPlaying() const
216 	{
217 		checkClassBinding!(typeof(this))();
218 		return ptrcall!(bool)(GDNativeClassBinding.isPlaying, _godot_object);
219 	}
220 	/**
221 	Plays the audio from the given position `from_position`, in seconds.
222 	*/
223 	void play(in double from_position = 0)
224 	{
225 		checkClassBinding!(typeof(this))();
226 		ptrcall!(void)(GDNativeClassBinding.play, _godot_object, from_position);
227 	}
228 	/**
229 	Sets the position from which audio will be played, in seconds.
230 	*/
231 	void seek(in double to_position)
232 	{
233 		checkClassBinding!(typeof(this))();
234 		ptrcall!(void)(GDNativeClassBinding.seek, _godot_object, to_position);
235 	}
236 	/**
237 	
238 	*/
239 	void setAreaMask(in long mask)
240 	{
241 		checkClassBinding!(typeof(this))();
242 		ptrcall!(void)(GDNativeClassBinding.setAreaMask, _godot_object, mask);
243 	}
244 	/**
245 	
246 	*/
247 	void setAttenuation(in double curve)
248 	{
249 		checkClassBinding!(typeof(this))();
250 		ptrcall!(void)(GDNativeClassBinding.setAttenuation, _godot_object, curve);
251 	}
252 	/**
253 	
254 	*/
255 	void setAutoplay(in bool enable)
256 	{
257 		checkClassBinding!(typeof(this))();
258 		ptrcall!(void)(GDNativeClassBinding.setAutoplay, _godot_object, enable);
259 	}
260 	/**
261 	
262 	*/
263 	void setBus(in String bus)
264 	{
265 		checkClassBinding!(typeof(this))();
266 		ptrcall!(void)(GDNativeClassBinding.setBus, _godot_object, bus);
267 	}
268 	/**
269 	
270 	*/
271 	void setMaxDistance(in double pixels)
272 	{
273 		checkClassBinding!(typeof(this))();
274 		ptrcall!(void)(GDNativeClassBinding.setMaxDistance, _godot_object, pixels);
275 	}
276 	/**
277 	
278 	*/
279 	void setPitchScale(in double pitch_scale)
280 	{
281 		checkClassBinding!(typeof(this))();
282 		ptrcall!(void)(GDNativeClassBinding.setPitchScale, _godot_object, pitch_scale);
283 	}
284 	/**
285 	
286 	*/
287 	void setStream(AudioStream stream)
288 	{
289 		checkClassBinding!(typeof(this))();
290 		ptrcall!(void)(GDNativeClassBinding.setStream, _godot_object, stream);
291 	}
292 	/**
293 	
294 	*/
295 	void setStreamPaused(in bool pause)
296 	{
297 		checkClassBinding!(typeof(this))();
298 		ptrcall!(void)(GDNativeClassBinding.setStreamPaused, _godot_object, pause);
299 	}
300 	/**
301 	
302 	*/
303 	void setVolumeDb(in double volume_db)
304 	{
305 		checkClassBinding!(typeof(this))();
306 		ptrcall!(void)(GDNativeClassBinding.setVolumeDb, _godot_object, volume_db);
307 	}
308 	/**
309 	Stops the audio.
310 	*/
311 	void stop()
312 	{
313 		checkClassBinding!(typeof(this))();
314 		ptrcall!(void)(GDNativeClassBinding.stop, _godot_object);
315 	}
316 	/**
317 	Areas in which this sound plays.
318 	*/
319 	@property long areaMask()
320 	{
321 		return getAreaMask();
322 	}
323 	/// ditto
324 	@property void areaMask(long v)
325 	{
326 		setAreaMask(v);
327 	}
328 	/**
329 	Dampens audio over distance with this as an exponent.
330 	*/
331 	@property double attenuation()
332 	{
333 		return getAttenuation();
334 	}
335 	/// ditto
336 	@property void attenuation(double v)
337 	{
338 		setAttenuation(v);
339 	}
340 	/**
341 	If `true`, audio plays when added to scene tree.
342 	*/
343 	@property bool autoplay()
344 	{
345 		return isAutoplayEnabled();
346 	}
347 	/// ditto
348 	@property void autoplay(bool v)
349 	{
350 		setAutoplay(v);
351 	}
352 	/**
353 	Bus on which this audio is playing.
354 	*/
355 	@property String bus()
356 	{
357 		return getBus();
358 	}
359 	/// ditto
360 	@property void bus(String v)
361 	{
362 		setBus(v);
363 	}
364 	/**
365 	Maximum distance from which audio is still hearable.
366 	*/
367 	@property double maxDistance()
368 	{
369 		return getMaxDistance();
370 	}
371 	/// ditto
372 	@property void maxDistance(double v)
373 	{
374 		setMaxDistance(v);
375 	}
376 	/**
377 	The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
378 	*/
379 	@property double pitchScale()
380 	{
381 		return getPitchScale();
382 	}
383 	/// ditto
384 	@property void pitchScale(double v)
385 	{
386 		setPitchScale(v);
387 	}
388 	/**
389 	If `true`, audio is playing.
390 	*/
391 	@property bool playing()
392 	{
393 		return isPlaying();
394 	}
395 	/// ditto
396 	@property void playing(bool v)
397 	{
398 		_setPlaying(v);
399 	}
400 	/**
401 	The $(D AudioStream) object to be played.
402 	*/
403 	@property AudioStream stream()
404 	{
405 		return getStream();
406 	}
407 	/// ditto
408 	@property void stream(AudioStream v)
409 	{
410 		setStream(v);
411 	}
412 	/**
413 	If `true`, the playback is paused. You can resume it by setting `stream_paused` to `false`.
414 	*/
415 	@property bool streamPaused()
416 	{
417 		return getStreamPaused();
418 	}
419 	/// ditto
420 	@property void streamPaused(bool v)
421 	{
422 		setStreamPaused(v);
423 	}
424 	/**
425 	Base volume without dampening.
426 	*/
427 	@property double volumeDb()
428 	{
429 		return getVolumeDb();
430 	}
431 	/// ditto
432 	@property void volumeDb(double v)
433 	{
434 		setVolumeDb(v);
435 	}
436 }