Musical keyboard component written in React.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MidiGenerator.ts 3.4 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import SoundGenerator from '../SoundGenerator'
  2. type MIDIMessage = [number, number, number?]
  3. interface MIDIOutput {
  4. send(message: MIDIMessage): void
  5. }
  6. export default class MidiGenerator implements SoundGenerator {
  7. constructor(private output: MIDIOutput) {
  8. }
  9. noteOn(channel: number, key: number, velocity: number) {
  10. this.output.send([0b10010000 + channel, key, velocity])
  11. }
  12. noteOff(channel: number, key: number, velocity: number) {
  13. this.output.send([0b10000000 + channel, key, velocity])
  14. }
  15. changeInstrument(channel: number, patch: number) {
  16. this.output.send([0b11000000 + channel, patch])
  17. }
  18. getInstrumentNames(): string[] {
  19. return [
  20. 'Acoustic Grand Piano',
  21. 'Bright Acoustic Piano',
  22. 'Electric Grand Piano',
  23. 'Honky-tonk Piano',
  24. 'Electric Piano 1',
  25. 'Electric Piano 2',
  26. 'Harpsichord',
  27. 'Clavi',
  28. 'Celesta',
  29. 'Glockenspiel',
  30. 'Music Box',
  31. 'Vibraphone',
  32. 'Marimba',
  33. 'Xylophone',
  34. 'Tubular Bells',
  35. 'Dulcimer',
  36. 'Drawbar Organ',
  37. 'Percussive Organ',
  38. 'Rock Organ',
  39. 'Church Organ',
  40. 'Reed Organ',
  41. 'Accordion',
  42. 'Harmonica',
  43. 'Tango Accordion',
  44. 'Acoustic Guitar (nylon)',
  45. 'Acoustic Guitar (steel)',
  46. 'Electric Guitar (jazz)',
  47. 'Electric Guitar (clean)',
  48. 'Electric Guitar (muted)',
  49. 'Overdriven Guitar',
  50. 'Distortion Guitar',
  51. 'Guitar harmonics',
  52. 'Acoustic Bass',
  53. 'Electric Bass (finger)',
  54. 'Electric Bass (pick)',
  55. 'Fretless Bass',
  56. 'Slap Bass 1',
  57. 'Slap Bass 2',
  58. 'Synth Bass 1',
  59. 'Synth Bass 2',
  60. 'Violin',
  61. 'Viola',
  62. 'Cello',
  63. 'Contrabass',
  64. 'Tremolo Strings',
  65. 'Pizzicato Strings',
  66. 'Orchestral Harp',
  67. 'Timpani',
  68. 'String Ensemble 1',
  69. 'String Ensemble 2',
  70. 'SynthStrings 1',
  71. 'SynthStrings 2',
  72. 'Choir Aahs',
  73. 'Voice Oohs',
  74. 'Synth Voice',
  75. 'Orchestra Hit',
  76. 'Trumpet',
  77. 'Trombone',
  78. 'Tuba',
  79. 'Muted Trumpet',
  80. 'French Horn',
  81. 'Brass Section',
  82. 'SynthBrass 1',
  83. 'SynthBrass 2',
  84. 'Soprano Sax',
  85. 'Alto Sax',
  86. 'Tenor Sax',
  87. 'Baritone Sax',
  88. 'Oboe',
  89. 'English Horn',
  90. 'Bassoon',
  91. 'Clarinet',
  92. 'Piccolo',
  93. 'Flute',
  94. 'Recorder',
  95. 'Pan Flute',
  96. 'Blown Bottle',
  97. 'Shakuhachi',
  98. 'Whistle',
  99. 'Ocarina',
  100. 'Lead 1 (square)',
  101. 'Lead 2 (sawtooth)',
  102. 'Lead 3 (calliope)',
  103. 'Lead 4 (chiff)',
  104. 'Lead 5 (charang)',
  105. 'Lead 6 (voice)',
  106. 'Lead 7 (fifths)',
  107. 'Lead 8 (bass + lead)',
  108. 'Pad 1 (new age)',
  109. 'Pad 2 (warm)',
  110. 'Pad 3 (polysynth)',
  111. 'Pad 4 (choir)',
  112. 'Pad 5 (bowed)',
  113. 'Pad 6 (metallic)',
  114. 'Pad 7 (halo)',
  115. 'Pad 8 (sweep)',
  116. 'FX 1 (rain)',
  117. 'FX 2 (soundtrack)',
  118. 'FX 3 (crystal)',
  119. 'FX 4 (atmosphere)',
  120. 'FX 5 (brightness)',
  121. 'FX 6 (goblins)',
  122. 'FX 7 (echoes)',
  123. 'FX 8 (sci-fi)',
  124. 'Sitar',
  125. 'Banjo',
  126. 'Shamisen',
  127. 'Koto',
  128. 'Kalimba',
  129. 'Bag pipe',
  130. 'Fiddle',
  131. 'Shanai',
  132. 'Tinkle Bell',
  133. 'Agogo',
  134. 'Steel Drums',
  135. 'Woodblock',
  136. 'Taiko Drum',
  137. 'Melodic Tom',
  138. 'Synth Drum',
  139. 'Reverse Cymbal',
  140. 'Guitar Fret Noise',
  141. 'Breath Noise',
  142. 'Seashore',
  143. 'Bird Tweet',
  144. 'Telephone Ring',
  145. 'Helicopter',
  146. 'Applause',
  147. 'Gunshot',
  148. ]
  149. }
  150. }