webaudio.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. const {
  6. Arg,
  7. Option,
  8. RetVal,
  9. generateActorSpec,
  10. types,
  11. } = require("devtools/shared/protocol");
  12. exports.NODE_CREATION_METHODS = [
  13. "createBufferSource", "createMediaElementSource", "createMediaStreamSource",
  14. "createMediaStreamDestination", "createScriptProcessor", "createAnalyser",
  15. "createGain", "createDelay", "createBiquadFilter", "createWaveShaper",
  16. "createPanner", "createConvolver", "createChannelSplitter", "createChannelMerger",
  17. "createDynamicsCompressor", "createOscillator", "createStereoPanner"
  18. ];
  19. exports.AUTOMATION_METHODS = [
  20. "setValueAtTime", "linearRampToValueAtTime", "exponentialRampToValueAtTime",
  21. "setTargetAtTime", "setValueCurveAtTime", "cancelScheduledValues"
  22. ];
  23. exports.NODE_ROUTING_METHODS = [
  24. "connect", "disconnect"
  25. ];
  26. types.addActorType("audionode");
  27. const audionodeSpec = generateActorSpec({
  28. typeName: "audionode",
  29. methods: {
  30. getType: { response: { type: RetVal("string") }},
  31. isBypassed: {
  32. response: { bypassed: RetVal("boolean") }
  33. },
  34. bypass: {
  35. request: { enable: Arg(0, "boolean") },
  36. response: { bypassed: RetVal("boolean") }
  37. },
  38. setParam: {
  39. request: {
  40. param: Arg(0, "string"),
  41. value: Arg(1, "nullable:primitive")
  42. },
  43. response: { error: RetVal("nullable:json") }
  44. },
  45. getParam: {
  46. request: {
  47. param: Arg(0, "string")
  48. },
  49. response: { text: RetVal("nullable:primitive") }
  50. },
  51. getParamFlags: {
  52. request: { param: Arg(0, "string") },
  53. response: { flags: RetVal("nullable:primitive") }
  54. },
  55. getParams: {
  56. response: { params: RetVal("json") }
  57. },
  58. connectParam: {
  59. request: {
  60. destActor: Arg(0, "audionode"),
  61. paramName: Arg(1, "string"),
  62. output: Arg(2, "nullable:number")
  63. },
  64. response: { error: RetVal("nullable:json") }
  65. },
  66. connectNode: {
  67. request: {
  68. destActor: Arg(0, "audionode"),
  69. output: Arg(1, "nullable:number"),
  70. input: Arg(2, "nullable:number")
  71. },
  72. response: { error: RetVal("nullable:json") }
  73. },
  74. disconnect: {
  75. request: { output: Arg(0, "nullable:number") },
  76. response: { error: RetVal("nullable:json") }
  77. },
  78. getAutomationData: {
  79. request: { paramName: Arg(0, "string") },
  80. response: { values: RetVal("nullable:json") }
  81. },
  82. addAutomationEvent: {
  83. request: {
  84. paramName: Arg(0, "string"),
  85. eventName: Arg(1, "string"),
  86. args: Arg(2, "nullable:json")
  87. },
  88. response: { error: RetVal("nullable:json") }
  89. },
  90. }
  91. });
  92. exports.audionodeSpec = audionodeSpec;
  93. const webAudioSpec = generateActorSpec({
  94. typeName: "webaudio",
  95. /**
  96. * Events emitted by this actor.
  97. */
  98. events: {
  99. "start-context": {
  100. type: "startContext"
  101. },
  102. "connect-node": {
  103. type: "connectNode",
  104. source: Option(0, "audionode"),
  105. dest: Option(0, "audionode")
  106. },
  107. "disconnect-node": {
  108. type: "disconnectNode",
  109. source: Arg(0, "audionode")
  110. },
  111. "connect-param": {
  112. type: "connectParam",
  113. source: Option(0, "audionode"),
  114. dest: Option(0, "audionode"),
  115. param: Option(0, "string")
  116. },
  117. "change-param": {
  118. type: "changeParam",
  119. source: Option(0, "audionode"),
  120. param: Option(0, "string"),
  121. value: Option(0, "string")
  122. },
  123. "create-node": {
  124. type: "createNode",
  125. source: Arg(0, "audionode")
  126. },
  127. "destroy-node": {
  128. type: "destroyNode",
  129. source: Arg(0, "audionode")
  130. },
  131. "automation-event": {
  132. type: "automationEvent",
  133. node: Option(0, "audionode"),
  134. paramName: Option(0, "string"),
  135. eventName: Option(0, "string"),
  136. args: Option(0, "json")
  137. }
  138. },
  139. methods: {
  140. getDefinition: {
  141. response: { definition: RetVal("json") }
  142. },
  143. setup: {
  144. request: { reload: Option(0, "boolean") },
  145. oneway: true
  146. },
  147. finalize: {
  148. oneway: true
  149. }
  150. }
  151. });
  152. exports.webAudioSpec = webAudioSpec;