1 /** 2 Server interface for low-level audio access. 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.audioserver; 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.audioeffect; 24 import godot.audiobuslayout; 25 import godot.audioeffectinstance; 26 /** 27 Server interface for low-level audio access. 28 29 $(D AudioServer) is a low-level server interface for audio access. It is in charge of creating sample data (playable audio) as well as its playback via a voice interface. 30 */ 31 @GodotBaseClass struct AudioServerSingleton 32 { 33 package(godot) enum string _GODOT_internal_name = "AudioServer"; 34 public: 35 @nogc nothrow: 36 union { /** */ godot_object _godot_object; /** */ GodotObject _GODOT_base; } 37 alias _GODOT_base this; 38 alias BaseClasses = AliasSeq!(typeof(_GODOT_base), typeof(_GODOT_base).BaseClasses); 39 package(godot) __gshared bool _classBindingInitialized = false; 40 package(godot) static struct GDNativeClassBinding 41 { 42 __gshared: 43 godot_object _singleton; 44 immutable char* _singletonName = "AudioServer"; 45 @GodotName("add_bus") GodotMethod!(void, long) addBus; 46 @GodotName("add_bus_effect") GodotMethod!(void, long, AudioEffect, long) addBusEffect; 47 @GodotName("capture_get_device") GodotMethod!(String) captureGetDevice; 48 @GodotName("capture_get_device_list") GodotMethod!(Array) captureGetDeviceList; 49 @GodotName("capture_set_device") GodotMethod!(void, String) captureSetDevice; 50 @GodotName("generate_bus_layout") GodotMethod!(AudioBusLayout) generateBusLayout; 51 @GodotName("get_bus_channels") GodotMethod!(long, long) getBusChannels; 52 @GodotName("get_bus_count") GodotMethod!(long) getBusCount; 53 @GodotName("get_bus_effect") GodotMethod!(AudioEffect, long, long) getBusEffect; 54 @GodotName("get_bus_effect_count") GodotMethod!(long, long) getBusEffectCount; 55 @GodotName("get_bus_effect_instance") GodotMethod!(AudioEffectInstance, long, long, long) getBusEffectInstance; 56 @GodotName("get_bus_index") GodotMethod!(long, String) getBusIndex; 57 @GodotName("get_bus_name") GodotMethod!(String, long) getBusName; 58 @GodotName("get_bus_peak_volume_left_db") GodotMethod!(double, long, long) getBusPeakVolumeLeftDb; 59 @GodotName("get_bus_peak_volume_right_db") GodotMethod!(double, long, long) getBusPeakVolumeRightDb; 60 @GodotName("get_bus_send") GodotMethod!(String, long) getBusSend; 61 @GodotName("get_bus_volume_db") GodotMethod!(double, long) getBusVolumeDb; 62 @GodotName("get_device") GodotMethod!(String) getDevice; 63 @GodotName("get_device_list") GodotMethod!(Array) getDeviceList; 64 @GodotName("get_global_rate_scale") GodotMethod!(double) getGlobalRateScale; 65 @GodotName("get_mix_rate") GodotMethod!(double) getMixRate; 66 @GodotName("get_output_latency") GodotMethod!(double) getOutputLatency; 67 @GodotName("get_speaker_mode") GodotMethod!(AudioServer.SpeakerMode) getSpeakerMode; 68 @GodotName("get_time_since_last_mix") GodotMethod!(double) getTimeSinceLastMix; 69 @GodotName("get_time_to_next_mix") GodotMethod!(double) getTimeToNextMix; 70 @GodotName("is_bus_bypassing_effects") GodotMethod!(bool, long) isBusBypassingEffects; 71 @GodotName("is_bus_effect_enabled") GodotMethod!(bool, long, long) isBusEffectEnabled; 72 @GodotName("is_bus_mute") GodotMethod!(bool, long) isBusMute; 73 @GodotName("is_bus_solo") GodotMethod!(bool, long) isBusSolo; 74 @GodotName("lock") GodotMethod!(void) lock; 75 @GodotName("move_bus") GodotMethod!(void, long, long) moveBus; 76 @GodotName("remove_bus") GodotMethod!(void, long) removeBus; 77 @GodotName("remove_bus_effect") GodotMethod!(void, long, long) removeBusEffect; 78 @GodotName("set_bus_bypass_effects") GodotMethod!(void, long, bool) setBusBypassEffects; 79 @GodotName("set_bus_count") GodotMethod!(void, long) setBusCount; 80 @GodotName("set_bus_effect_enabled") GodotMethod!(void, long, long, bool) setBusEffectEnabled; 81 @GodotName("set_bus_layout") GodotMethod!(void, AudioBusLayout) setBusLayout; 82 @GodotName("set_bus_mute") GodotMethod!(void, long, bool) setBusMute; 83 @GodotName("set_bus_name") GodotMethod!(void, long, String) setBusName; 84 @GodotName("set_bus_send") GodotMethod!(void, long, String) setBusSend; 85 @GodotName("set_bus_solo") GodotMethod!(void, long, bool) setBusSolo; 86 @GodotName("set_bus_volume_db") GodotMethod!(void, long, double) setBusVolumeDb; 87 @GodotName("set_device") GodotMethod!(void, String) setDevice; 88 @GodotName("set_global_rate_scale") GodotMethod!(void, double) setGlobalRateScale; 89 @GodotName("swap_bus_effects") GodotMethod!(void, long, long, long) swapBusEffects; 90 @GodotName("unlock") GodotMethod!(void) unlock; 91 } 92 /// 93 pragma(inline, true) bool opEquals(in AudioServerSingleton other) const 94 { return _godot_object.ptr is other._godot_object.ptr; } 95 /// 96 pragma(inline, true) typeof(null) opAssign(typeof(null) n) 97 { _godot_object.ptr = n; return null; } 98 /// 99 pragma(inline, true) bool opEquals(typeof(null) n) const 100 { return _godot_object.ptr is n; } 101 /// 102 size_t toHash() const @trusted { return cast(size_t)_godot_object.ptr; } 103 mixin baseCasts; 104 /// Construct a new instance of AudioServerSingleton. 105 /// Note: use `memnew!AudioServerSingleton` instead. 106 static AudioServerSingleton _new() 107 { 108 static godot_class_constructor constructor; 109 if(constructor is null) constructor = _godot_api.godot_get_class_constructor("AudioServer"); 110 if(constructor is null) return typeof(this).init; 111 return cast(AudioServerSingleton)(constructor()); 112 } 113 @disable new(size_t s); 114 /// 115 enum SpeakerMode : int 116 { 117 /** 118 Two or fewer speakers were detected. 119 */ 120 speakerModeStereo = 0, 121 /** 122 A 3.1 channel surround setup was detected. 123 */ 124 speakerSurround31 = 1, 125 /** 126 A 5.1 channel surround setup was detected. 127 */ 128 speakerSurround51 = 2, 129 /** 130 A 7.1 channel surround setup was detected. 131 */ 132 speakerSurround71 = 3, 133 } 134 /// 135 enum Constants : int 136 { 137 speakerModeStereo = 0, 138 speakerSurround31 = 1, 139 speakerSurround51 = 2, 140 speakerSurround71 = 3, 141 } 142 /** 143 Adds a bus at `at_position`. 144 */ 145 void addBus(in long at_position = -1) 146 { 147 checkClassBinding!(typeof(this))(); 148 ptrcall!(void)(GDNativeClassBinding.addBus, _godot_object, at_position); 149 } 150 /** 151 Adds an $(D AudioEffect) effect to the bus `bus_idx` at `at_position`. 152 */ 153 void addBusEffect(in long bus_idx, AudioEffect effect, in long at_position = -1) 154 { 155 checkClassBinding!(typeof(this))(); 156 ptrcall!(void)(GDNativeClassBinding.addBusEffect, _godot_object, bus_idx, effect, at_position); 157 } 158 /** 159 Name of the current device for audio input (see $(D captureGetDeviceList)). 160 */ 161 String captureGetDevice() 162 { 163 checkClassBinding!(typeof(this))(); 164 return ptrcall!(String)(GDNativeClassBinding.captureGetDevice, _godot_object); 165 } 166 /** 167 Returns the names of all audio input devices detected on the system. 168 */ 169 Array captureGetDeviceList() 170 { 171 checkClassBinding!(typeof(this))(); 172 return ptrcall!(Array)(GDNativeClassBinding.captureGetDeviceList, _godot_object); 173 } 174 /** 175 Sets which audio input device is used for audio capture. 176 */ 177 void captureSetDevice(in String name) 178 { 179 checkClassBinding!(typeof(this))(); 180 ptrcall!(void)(GDNativeClassBinding.captureSetDevice, _godot_object, name); 181 } 182 /** 183 Generates an $(D AudioBusLayout) using the available buses and effects. 184 */ 185 Ref!AudioBusLayout generateBusLayout() const 186 { 187 checkClassBinding!(typeof(this))(); 188 return ptrcall!(AudioBusLayout)(GDNativeClassBinding.generateBusLayout, _godot_object); 189 } 190 /** 191 Returns the amount of channels of the bus at index `bus_idx`. 192 */ 193 long getBusChannels(in long bus_idx) const 194 { 195 checkClassBinding!(typeof(this))(); 196 return ptrcall!(long)(GDNativeClassBinding.getBusChannels, _godot_object, bus_idx); 197 } 198 /** 199 200 */ 201 long getBusCount() const 202 { 203 checkClassBinding!(typeof(this))(); 204 return ptrcall!(long)(GDNativeClassBinding.getBusCount, _godot_object); 205 } 206 /** 207 Returns the $(D AudioEffect) at position `effect_idx` in bus `bus_idx`. 208 */ 209 Ref!AudioEffect getBusEffect(in long bus_idx, in long effect_idx) 210 { 211 checkClassBinding!(typeof(this))(); 212 return ptrcall!(AudioEffect)(GDNativeClassBinding.getBusEffect, _godot_object, bus_idx, effect_idx); 213 } 214 /** 215 Returns the number of effects on the bus at `bus_idx`. 216 */ 217 long getBusEffectCount(in long bus_idx) 218 { 219 checkClassBinding!(typeof(this))(); 220 return ptrcall!(long)(GDNativeClassBinding.getBusEffectCount, _godot_object, bus_idx); 221 } 222 /** 223 Returns the $(D AudioEffectInstance) assigned to the given bus and effect indices (and optionally channel). 224 */ 225 Ref!AudioEffectInstance getBusEffectInstance(in long bus_idx, in long effect_idx, in long channel = 0) 226 { 227 checkClassBinding!(typeof(this))(); 228 return ptrcall!(AudioEffectInstance)(GDNativeClassBinding.getBusEffectInstance, _godot_object, bus_idx, effect_idx, channel); 229 } 230 /** 231 Returns the index of the bus with the name `bus_name`. 232 */ 233 long getBusIndex(in String bus_name) const 234 { 235 checkClassBinding!(typeof(this))(); 236 return ptrcall!(long)(GDNativeClassBinding.getBusIndex, _godot_object, bus_name); 237 } 238 /** 239 Returns the name of the bus with the index `bus_idx`. 240 */ 241 String getBusName(in long bus_idx) const 242 { 243 checkClassBinding!(typeof(this))(); 244 return ptrcall!(String)(GDNativeClassBinding.getBusName, _godot_object, bus_idx); 245 } 246 /** 247 Returns the peak volume of the left speaker at bus index `bus_idx` and channel index `channel`. 248 */ 249 double getBusPeakVolumeLeftDb(in long bus_idx, in long channel) const 250 { 251 checkClassBinding!(typeof(this))(); 252 return ptrcall!(double)(GDNativeClassBinding.getBusPeakVolumeLeftDb, _godot_object, bus_idx, channel); 253 } 254 /** 255 Returns the peak volume of the right speaker at bus index `bus_idx` and channel index `channel`. 256 */ 257 double getBusPeakVolumeRightDb(in long bus_idx, in long channel) const 258 { 259 checkClassBinding!(typeof(this))(); 260 return ptrcall!(double)(GDNativeClassBinding.getBusPeakVolumeRightDb, _godot_object, bus_idx, channel); 261 } 262 /** 263 Returns the name of the bus that the bus at index `bus_idx` sends to. 264 */ 265 String getBusSend(in long bus_idx) const 266 { 267 checkClassBinding!(typeof(this))(); 268 return ptrcall!(String)(GDNativeClassBinding.getBusSend, _godot_object, bus_idx); 269 } 270 /** 271 Returns the volume of the bus at index `bus_idx` in dB. 272 */ 273 double getBusVolumeDb(in long bus_idx) const 274 { 275 checkClassBinding!(typeof(this))(); 276 return ptrcall!(double)(GDNativeClassBinding.getBusVolumeDb, _godot_object, bus_idx); 277 } 278 /** 279 280 */ 281 String getDevice() 282 { 283 checkClassBinding!(typeof(this))(); 284 return ptrcall!(String)(GDNativeClassBinding.getDevice, _godot_object); 285 } 286 /** 287 Returns the names of all audio devices detected on the system. 288 */ 289 Array getDeviceList() 290 { 291 checkClassBinding!(typeof(this))(); 292 return ptrcall!(Array)(GDNativeClassBinding.getDeviceList, _godot_object); 293 } 294 /** 295 296 */ 297 double getGlobalRateScale() const 298 { 299 checkClassBinding!(typeof(this))(); 300 return ptrcall!(double)(GDNativeClassBinding.getGlobalRateScale, _godot_object); 301 } 302 /** 303 Returns the sample rate at the output of the $(D AudioServer). 304 */ 305 double getMixRate() const 306 { 307 checkClassBinding!(typeof(this))(); 308 return ptrcall!(double)(GDNativeClassBinding.getMixRate, _godot_object); 309 } 310 /** 311 Returns the audio driver's output latency. 312 */ 313 double getOutputLatency() const 314 { 315 checkClassBinding!(typeof(this))(); 316 return ptrcall!(double)(GDNativeClassBinding.getOutputLatency, _godot_object); 317 } 318 /** 319 Returns the speaker configuration. 320 */ 321 AudioServer.SpeakerMode getSpeakerMode() const 322 { 323 checkClassBinding!(typeof(this))(); 324 return ptrcall!(AudioServer.SpeakerMode)(GDNativeClassBinding.getSpeakerMode, _godot_object); 325 } 326 /** 327 Returns the relative time since the last mix occurred. 328 */ 329 double getTimeSinceLastMix() const 330 { 331 checkClassBinding!(typeof(this))(); 332 return ptrcall!(double)(GDNativeClassBinding.getTimeSinceLastMix, _godot_object); 333 } 334 /** 335 Returns the relative time until the next mix occurs. 336 */ 337 double getTimeToNextMix() const 338 { 339 checkClassBinding!(typeof(this))(); 340 return ptrcall!(double)(GDNativeClassBinding.getTimeToNextMix, _godot_object); 341 } 342 /** 343 If `true`, the bus at index `bus_idx` is bypassing effects. 344 */ 345 bool isBusBypassingEffects(in long bus_idx) const 346 { 347 checkClassBinding!(typeof(this))(); 348 return ptrcall!(bool)(GDNativeClassBinding.isBusBypassingEffects, _godot_object, bus_idx); 349 } 350 /** 351 If `true`, the effect at index `effect_idx` on the bus at index `bus_idx` is enabled. 352 */ 353 bool isBusEffectEnabled(in long bus_idx, in long effect_idx) const 354 { 355 checkClassBinding!(typeof(this))(); 356 return ptrcall!(bool)(GDNativeClassBinding.isBusEffectEnabled, _godot_object, bus_idx, effect_idx); 357 } 358 /** 359 If `true`, the bus at index `bus_idx` is muted. 360 */ 361 bool isBusMute(in long bus_idx) const 362 { 363 checkClassBinding!(typeof(this))(); 364 return ptrcall!(bool)(GDNativeClassBinding.isBusMute, _godot_object, bus_idx); 365 } 366 /** 367 If `true`, the bus at index `bus_idx` is in solo mode. 368 */ 369 bool isBusSolo(in long bus_idx) const 370 { 371 checkClassBinding!(typeof(this))(); 372 return ptrcall!(bool)(GDNativeClassBinding.isBusSolo, _godot_object, bus_idx); 373 } 374 /** 375 Locks the audio driver's main loop. 376 $(B Note:) Remember to unlock it afterwards. 377 */ 378 void lock() 379 { 380 checkClassBinding!(typeof(this))(); 381 ptrcall!(void)(GDNativeClassBinding.lock, _godot_object); 382 } 383 /** 384 Moves the bus from index `index` to index `to_index`. 385 */ 386 void moveBus(in long index, in long to_index) 387 { 388 checkClassBinding!(typeof(this))(); 389 ptrcall!(void)(GDNativeClassBinding.moveBus, _godot_object, index, to_index); 390 } 391 /** 392 Removes the bus at index `index`. 393 */ 394 void removeBus(in long index) 395 { 396 checkClassBinding!(typeof(this))(); 397 ptrcall!(void)(GDNativeClassBinding.removeBus, _godot_object, index); 398 } 399 /** 400 Removes the effect at index `effect_idx` from the bus at index `bus_idx`. 401 */ 402 void removeBusEffect(in long bus_idx, in long effect_idx) 403 { 404 checkClassBinding!(typeof(this))(); 405 ptrcall!(void)(GDNativeClassBinding.removeBusEffect, _godot_object, bus_idx, effect_idx); 406 } 407 /** 408 If `true`, the bus at index `bus_idx` is bypassing effects. 409 */ 410 void setBusBypassEffects(in long bus_idx, in bool enable) 411 { 412 checkClassBinding!(typeof(this))(); 413 ptrcall!(void)(GDNativeClassBinding.setBusBypassEffects, _godot_object, bus_idx, enable); 414 } 415 /** 416 417 */ 418 void setBusCount(in long amount) 419 { 420 checkClassBinding!(typeof(this))(); 421 ptrcall!(void)(GDNativeClassBinding.setBusCount, _godot_object, amount); 422 } 423 /** 424 If `true`, the effect at index `effect_idx` on the bus at index `bus_idx` is enabled. 425 */ 426 void setBusEffectEnabled(in long bus_idx, in long effect_idx, in bool enabled) 427 { 428 checkClassBinding!(typeof(this))(); 429 ptrcall!(void)(GDNativeClassBinding.setBusEffectEnabled, _godot_object, bus_idx, effect_idx, enabled); 430 } 431 /** 432 Overwrites the currently used $(D AudioBusLayout). 433 */ 434 void setBusLayout(AudioBusLayout bus_layout) 435 { 436 checkClassBinding!(typeof(this))(); 437 ptrcall!(void)(GDNativeClassBinding.setBusLayout, _godot_object, bus_layout); 438 } 439 /** 440 If `true`, the bus at index `bus_idx` is muted. 441 */ 442 void setBusMute(in long bus_idx, in bool enable) 443 { 444 checkClassBinding!(typeof(this))(); 445 ptrcall!(void)(GDNativeClassBinding.setBusMute, _godot_object, bus_idx, enable); 446 } 447 /** 448 Sets the name of the bus at index `bus_idx` to `name`. 449 */ 450 void setBusName(in long bus_idx, in String name) 451 { 452 checkClassBinding!(typeof(this))(); 453 ptrcall!(void)(GDNativeClassBinding.setBusName, _godot_object, bus_idx, name); 454 } 455 /** 456 Connects the output of the bus at `bus_idx` to the bus named `send`. 457 */ 458 void setBusSend(in long bus_idx, in String send) 459 { 460 checkClassBinding!(typeof(this))(); 461 ptrcall!(void)(GDNativeClassBinding.setBusSend, _godot_object, bus_idx, send); 462 } 463 /** 464 If `true`, the bus at index `bus_idx` is in solo mode. 465 */ 466 void setBusSolo(in long bus_idx, in bool enable) 467 { 468 checkClassBinding!(typeof(this))(); 469 ptrcall!(void)(GDNativeClassBinding.setBusSolo, _godot_object, bus_idx, enable); 470 } 471 /** 472 Sets the volume of the bus at index `bus_idx` to `volume_db`. 473 */ 474 void setBusVolumeDb(in long bus_idx, in double volume_db) 475 { 476 checkClassBinding!(typeof(this))(); 477 ptrcall!(void)(GDNativeClassBinding.setBusVolumeDb, _godot_object, bus_idx, volume_db); 478 } 479 /** 480 481 */ 482 void setDevice(in String device) 483 { 484 checkClassBinding!(typeof(this))(); 485 ptrcall!(void)(GDNativeClassBinding.setDevice, _godot_object, device); 486 } 487 /** 488 489 */ 490 void setGlobalRateScale(in double scale) 491 { 492 checkClassBinding!(typeof(this))(); 493 ptrcall!(void)(GDNativeClassBinding.setGlobalRateScale, _godot_object, scale); 494 } 495 /** 496 Swaps the position of two effects in bus `bus_idx`. 497 */ 498 void swapBusEffects(in long bus_idx, in long effect_idx, in long by_effect_idx) 499 { 500 checkClassBinding!(typeof(this))(); 501 ptrcall!(void)(GDNativeClassBinding.swapBusEffects, _godot_object, bus_idx, effect_idx, by_effect_idx); 502 } 503 /** 504 Unlocks the audio driver's main loop. (After locking it, you should always unlock it.) 505 */ 506 void unlock() 507 { 508 checkClassBinding!(typeof(this))(); 509 ptrcall!(void)(GDNativeClassBinding.unlock, _godot_object); 510 } 511 /** 512 Number of available audio buses. 513 */ 514 @property long busCount() 515 { 516 return getBusCount(); 517 } 518 /// ditto 519 @property void busCount(long v) 520 { 521 setBusCount(v); 522 } 523 /** 524 Name of the current device for audio output (see $(D getDeviceList)). 525 */ 526 @property String device() 527 { 528 return getDevice(); 529 } 530 /// ditto 531 @property void device(String v) 532 { 533 setDevice(v); 534 } 535 /** 536 Scales the rate at which audio is played (i.e. setting it to `0.5` will make the audio be played twice as fast). 537 */ 538 @property double globalRateScale() 539 { 540 return getGlobalRateScale(); 541 } 542 /// ditto 543 @property void globalRateScale(double v) 544 { 545 setGlobalRateScale(v); 546 } 547 } 548 /// Returns: the AudioServerSingleton 549 @property @nogc nothrow pragma(inline, true) 550 AudioServerSingleton AudioServer() 551 { 552 checkClassBinding!AudioServerSingleton(); 553 return AudioServerSingleton(AudioServerSingleton.GDNativeClassBinding._singleton); 554 }