1 /**
2 Plays back audio non-positionally.
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.audiostreamplayer;
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.node;
25 import godot.audiostream;
26 import godot.audiostreamplayback;
27 /**
28 Plays back audio non-positionally.
29 
30 Plays an audio stream non-positionally.
31 To play audio positionally, use $(D AudioStreamPlayer2D) or $(D AudioStreamPlayer3D) instead of $(D AudioStreamPlayer).
32 */
33 @GodotBaseClass struct AudioStreamPlayer
34 {
35 	package(godot) enum string _GODOT_internal_name = "AudioStreamPlayer";
36 public:
37 @nogc nothrow:
38 	union { /** */ godot_object _godot_object; /** */ Node _GODOT_base; }
39 	alias _GODOT_base this;
40 	alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses);
41 	package(godot) __gshared bool _classBindingInitialized = false;
42 	package(godot) static struct GDNativeClassBinding
43 	{
44 		__gshared:
45 		@GodotName("_bus_layout_changed") GodotMethod!(void) _busLayoutChanged;
46 		@GodotName("_is_active") GodotMethod!(bool) _isActive;
47 		@GodotName("_set_playing") GodotMethod!(void, bool) _setPlaying;
48 		@GodotName("get_bus") GodotMethod!(String) getBus;
49 		@GodotName("get_mix_target") GodotMethod!(AudioStreamPlayer.MixTarget) getMixTarget;
50 		@GodotName("get_pitch_scale") GodotMethod!(double) getPitchScale;
51 		@GodotName("get_playback_position") GodotMethod!(double) getPlaybackPosition;
52 		@GodotName("get_stream") GodotMethod!(AudioStream) getStream;
53 		@GodotName("get_stream_paused") GodotMethod!(bool) getStreamPaused;
54 		@GodotName("get_stream_playback") GodotMethod!(AudioStreamPlayback) getStreamPlayback;
55 		@GodotName("get_volume_db") GodotMethod!(double) getVolumeDb;
56 		@GodotName("is_autoplay_enabled") GodotMethod!(bool) isAutoplayEnabled;
57 		@GodotName("is_playing") GodotMethod!(bool) isPlaying;
58 		@GodotName("play") GodotMethod!(void, double) play;
59 		@GodotName("seek") GodotMethod!(void, double) seek;
60 		@GodotName("set_autoplay") GodotMethod!(void, bool) setAutoplay;
61 		@GodotName("set_bus") GodotMethod!(void, String) setBus;
62 		@GodotName("set_mix_target") GodotMethod!(void, long) setMixTarget;
63 		@GodotName("set_pitch_scale") GodotMethod!(void, double) setPitchScale;
64 		@GodotName("set_stream") GodotMethod!(void, AudioStream) setStream;
65 		@GodotName("set_stream_paused") GodotMethod!(void, bool) setStreamPaused;
66 		@GodotName("set_volume_db") GodotMethod!(void, double) setVolumeDb;
67 		@GodotName("stop") GodotMethod!(void) stop;
68 	}
69 	/// 
70 	pragma(inline, true) bool opEquals(in AudioStreamPlayer other) const
71 	{ return _godot_object.ptr is other._godot_object.ptr; }
72 	/// 
73 	pragma(inline, true) typeof(null) opAssign(typeof(null) n)
74 	{ _godot_object.ptr = n; return null; }
75 	/// 
76 	pragma(inline, true) bool opEquals(typeof(null) n) const
77 	{ return _godot_object.ptr is n; }
78 	/// 
79 	size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; }
80 	mixin baseCasts;
81 	/// Construct a new instance of AudioStreamPlayer.
82 	/// Note: use `memnew!AudioStreamPlayer` instead.
83 	static AudioStreamPlayer _new()
84 	{
85 		static godot_class_constructor constructor;
86 		if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AudioStreamPlayer");
87 		if(constructor is null) return typeof(this).init;
88 		return cast(AudioStreamPlayer)(constructor());
89 	}
90 	@disable new(size_t s);
91 	/// 
92 	enum MixTarget : int
93 	{
94 		/**
95 		The audio will be played only on the first channel.
96 		*/
97 		mixTargetStereo = 0,
98 		/**
99 		The audio will be played on all surround channels.
100 		*/
101 		mixTargetSurround = 1,
102 		/**
103 		The audio will be played on the second channel, which is usually the center.
104 		*/
105 		mixTargetCenter = 2,
106 	}
107 	/// 
108 	enum Constants : int
109 	{
110 		mixTargetStereo = 0,
111 		mixTargetSurround = 1,
112 		mixTargetCenter = 2,
113 	}
114 	/**
115 	
116 	*/
117 	void _busLayoutChanged()
118 	{
119 		Array _GODOT_args = Array.make();
120 		String _GODOT_method_name = String("_bus_layout_changed");
121 		this.callv(_GODOT_method_name, _GODOT_args);
122 	}
123 	/**
124 	
125 	*/
126 	bool _isActive() const
127 	{
128 		Array _GODOT_args = Array.make();
129 		String _GODOT_method_name = String("_is_active");
130 		return this.callv(_GODOT_method_name, _GODOT_args).as!(RefOrT!bool);
131 	}
132 	/**
133 	
134 	*/
135 	void _setPlaying(in bool enable)
136 	{
137 		Array _GODOT_args = Array.make();
138 		_GODOT_args.append(enable);
139 		String _GODOT_method_name = String("_set_playing");
140 		this.callv(_GODOT_method_name, _GODOT_args);
141 	}
142 	/**
143 	
144 	*/
145 	String getBus() const
146 	{
147 		checkClassBinding!(typeof(this))();
148 		return ptrcall!(String)(GDNativeClassBinding.getBus, _godot_object);
149 	}
150 	/**
151 	
152 	*/
153 	AudioStreamPlayer.MixTarget getMixTarget() const
154 	{
155 		checkClassBinding!(typeof(this))();
156 		return ptrcall!(AudioStreamPlayer.MixTarget)(GDNativeClassBinding.getMixTarget, _godot_object);
157 	}
158 	/**
159 	
160 	*/
161 	double getPitchScale() const
162 	{
163 		checkClassBinding!(typeof(this))();
164 		return ptrcall!(double)(GDNativeClassBinding.getPitchScale, _godot_object);
165 	}
166 	/**
167 	Returns the position in the $(D AudioStream) in seconds.
168 	*/
169 	double getPlaybackPosition()
170 	{
171 		checkClassBinding!(typeof(this))();
172 		return ptrcall!(double)(GDNativeClassBinding.getPlaybackPosition, _godot_object);
173 	}
174 	/**
175 	
176 	*/
177 	Ref!AudioStream getStream() const
178 	{
179 		checkClassBinding!(typeof(this))();
180 		return ptrcall!(AudioStream)(GDNativeClassBinding.getStream, _godot_object);
181 	}
182 	/**
183 	
184 	*/
185 	bool getStreamPaused() const
186 	{
187 		checkClassBinding!(typeof(this))();
188 		return ptrcall!(bool)(GDNativeClassBinding.getStreamPaused, _godot_object);
189 	}
190 	/**
191 	Returns the $(D AudioStreamPlayback) object associated with this $(D AudioStreamPlayer).
192 	*/
193 	Ref!AudioStreamPlayback getStreamPlayback()
194 	{
195 		checkClassBinding!(typeof(this))();
196 		return ptrcall!(AudioStreamPlayback)(GDNativeClassBinding.getStreamPlayback, _godot_object);
197 	}
198 	/**
199 	
200 	*/
201 	double getVolumeDb() const
202 	{
203 		checkClassBinding!(typeof(this))();
204 		return ptrcall!(double)(GDNativeClassBinding.getVolumeDb, _godot_object);
205 	}
206 	/**
207 	
208 	*/
209 	bool isAutoplayEnabled()
210 	{
211 		checkClassBinding!(typeof(this))();
212 		return ptrcall!(bool)(GDNativeClassBinding.isAutoplayEnabled, _godot_object);
213 	}
214 	/**
215 	
216 	*/
217 	bool isPlaying() const
218 	{
219 		checkClassBinding!(typeof(this))();
220 		return ptrcall!(bool)(GDNativeClassBinding.isPlaying, _godot_object);
221 	}
222 	/**
223 	Plays the audio from the given `from_position`, in seconds.
224 	*/
225 	void play(in double from_position = 0)
226 	{
227 		checkClassBinding!(typeof(this))();
228 		ptrcall!(void)(GDNativeClassBinding.play, _godot_object, from_position);
229 	}
230 	/**
231 	Sets the position from which audio will be played, in seconds.
232 	*/
233 	void seek(in double to_position)
234 	{
235 		checkClassBinding!(typeof(this))();
236 		ptrcall!(void)(GDNativeClassBinding.seek, _godot_object, to_position);
237 	}
238 	/**
239 	
240 	*/
241 	void setAutoplay(in bool enable)
242 	{
243 		checkClassBinding!(typeof(this))();
244 		ptrcall!(void)(GDNativeClassBinding.setAutoplay, _godot_object, enable);
245 	}
246 	/**
247 	
248 	*/
249 	void setBus(in String bus)
250 	{
251 		checkClassBinding!(typeof(this))();
252 		ptrcall!(void)(GDNativeClassBinding.setBus, _godot_object, bus);
253 	}
254 	/**
255 	
256 	*/
257 	void setMixTarget(in long mix_target)
258 	{
259 		checkClassBinding!(typeof(this))();
260 		ptrcall!(void)(GDNativeClassBinding.setMixTarget, _godot_object, mix_target);
261 	}
262 	/**
263 	
264 	*/
265 	void setPitchScale(in double pitch_scale)
266 	{
267 		checkClassBinding!(typeof(this))();
268 		ptrcall!(void)(GDNativeClassBinding.setPitchScale, _godot_object, pitch_scale);
269 	}
270 	/**
271 	
272 	*/
273 	void setStream(AudioStream stream)
274 	{
275 		checkClassBinding!(typeof(this))();
276 		ptrcall!(void)(GDNativeClassBinding.setStream, _godot_object, stream);
277 	}
278 	/**
279 	
280 	*/
281 	void setStreamPaused(in bool pause)
282 	{
283 		checkClassBinding!(typeof(this))();
284 		ptrcall!(void)(GDNativeClassBinding.setStreamPaused, _godot_object, pause);
285 	}
286 	/**
287 	
288 	*/
289 	void setVolumeDb(in double volume_db)
290 	{
291 		checkClassBinding!(typeof(this))();
292 		ptrcall!(void)(GDNativeClassBinding.setVolumeDb, _godot_object, volume_db);
293 	}
294 	/**
295 	Stops the audio.
296 	*/
297 	void stop()
298 	{
299 		checkClassBinding!(typeof(this))();
300 		ptrcall!(void)(GDNativeClassBinding.stop, _godot_object);
301 	}
302 	/**
303 	If `true`, audio plays when added to scene tree.
304 	*/
305 	@property bool autoplay()
306 	{
307 		return isAutoplayEnabled();
308 	}
309 	/// ditto
310 	@property void autoplay(bool v)
311 	{
312 		setAutoplay(v);
313 	}
314 	/**
315 	Bus on which this audio is playing.
316 	*/
317 	@property String bus()
318 	{
319 		return getBus();
320 	}
321 	/// ditto
322 	@property void bus(String v)
323 	{
324 		setBus(v);
325 	}
326 	/**
327 	If the audio configuration has more than two speakers, this sets the target channels. See $(D mixtarget) constants.
328 	*/
329 	@property AudioStreamPlayer.MixTarget mixTarget()
330 	{
331 		return getMixTarget();
332 	}
333 	/// ditto
334 	@property void mixTarget(long v)
335 	{
336 		setMixTarget(v);
337 	}
338 	/**
339 	The pitch and the tempo of the audio, as a multiplier of the audio sample's sample rate.
340 	*/
341 	@property double pitchScale()
342 	{
343 		return getPitchScale();
344 	}
345 	/// ditto
346 	@property void pitchScale(double v)
347 	{
348 		setPitchScale(v);
349 	}
350 	/**
351 	If `true`, audio is playing.
352 	*/
353 	@property bool playing()
354 	{
355 		return isPlaying();
356 	}
357 	/// ditto
358 	@property void playing(bool v)
359 	{
360 		_setPlaying(v);
361 	}
362 	/**
363 	The $(D AudioStream) object to be played.
364 	*/
365 	@property AudioStream stream()
366 	{
367 		return getStream();
368 	}
369 	/// ditto
370 	@property void stream(AudioStream v)
371 	{
372 		setStream(v);
373 	}
374 	/**
375 	If `true`, the playback is paused. You can resume it by setting `stream_paused` to `false`.
376 	*/
377 	@property bool streamPaused()
378 	{
379 		return getStreamPaused();
380 	}
381 	/// ditto
382 	@property void streamPaused(bool v)
383 	{
384 		setStreamPaused(v);
385 	}
386 	/**
387 	Volume of sound, in dB.
388 	*/
389 	@property double volumeDb()
390 	{
391 		return getVolumeDb();
392 	}
393 	/// ditto
394 	@property void volumeDb(double v)
395 	{
396 		setVolumeDb(v);
397 	}
398 }