SubInstrument.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. "use strict";
  2. var ClefInstruction_1 = require("./VoiceData/Instructions/ClefInstruction");
  3. var Logging_1 = require("../Common/Logging");
  4. var SubInstrument = (function () {
  5. function SubInstrument(parentInstrument) {
  6. this.parentInstrument = parentInstrument;
  7. this.fixedKey = -1;
  8. this.name = this.parseMidiInstrument(this.parentInstrument.Name);
  9. this.midiInstrumentID = SubInstrument.midiInstrument[this.name];
  10. this.volume = 1.0;
  11. }
  12. Object.defineProperty(SubInstrument.prototype, "ParentInstrument", {
  13. get: function () {
  14. return this.parentInstrument;
  15. },
  16. enumerable: true,
  17. configurable: true
  18. });
  19. SubInstrument.isPianoInstrument = function (instrument) {
  20. return (instrument === ClefInstruction_1.MidiInstrument.Acoustic_Grand_Piano
  21. || instrument === ClefInstruction_1.MidiInstrument.Bright_Acoustic_Piano
  22. || instrument === ClefInstruction_1.MidiInstrument.Electric_Grand_Piano
  23. || instrument === ClefInstruction_1.MidiInstrument.Electric_Piano_1
  24. || instrument === ClefInstruction_1.MidiInstrument.Electric_Piano_2);
  25. };
  26. SubInstrument.prototype.setMidiInstrument = function (instrumentType) {
  27. this.midiInstrumentID = SubInstrument.midiInstrument[this.parseMidiInstrument(instrumentType)];
  28. };
  29. SubInstrument.prototype.parseMidiInstrument = function (instrumentType) {
  30. // FIXME: test this function
  31. try {
  32. if (instrumentType) {
  33. var tmpName = instrumentType.toLowerCase().trim();
  34. for (var key in SubInstrument.midiInstrument) {
  35. if (tmpName.indexOf(key) !== -1) {
  36. return key;
  37. }
  38. }
  39. }
  40. if (this.parentInstrument.Name) {
  41. var tmpName = this.parentInstrument.Name.toLowerCase().trim();
  42. for (var key in SubInstrument.midiInstrument) {
  43. if (tmpName.indexOf(key) !== -1) {
  44. return key;
  45. }
  46. }
  47. }
  48. }
  49. catch (e) {
  50. Logging_1.Logging.error("Error parsing MIDI Instrument. Default to Grand Piano.");
  51. }
  52. return "unnamed";
  53. };
  54. SubInstrument.midiInstrument = {
  55. "cello": ClefInstruction_1.MidiInstrument.Cello,
  56. "violon-c": ClefInstruction_1.MidiInstrument.Cello,
  57. "contrabass": ClefInstruction_1.MidiInstrument.Contrabass,
  58. "kontrabass": ClefInstruction_1.MidiInstrument.Contrabass,
  59. "clarinet": ClefInstruction_1.MidiInstrument.Clarinet,
  60. "klarinette": ClefInstruction_1.MidiInstrument.Clarinet,
  61. "flute": ClefInstruction_1.MidiInstrument.Flute,
  62. "flöte": ClefInstruction_1.MidiInstrument.Flute,
  63. "frenchhorn": ClefInstruction_1.MidiInstrument.French_Horn,
  64. "guitar": ClefInstruction_1.MidiInstrument.Acoustic_Guitar_nylon,
  65. "gitarre": ClefInstruction_1.MidiInstrument.Acoustic_Guitar_nylon,
  66. "harp": ClefInstruction_1.MidiInstrument.Orchestral_Harp,
  67. "harfe": ClefInstruction_1.MidiInstrument.Orchestral_Harp,
  68. "oboe": ClefInstruction_1.MidiInstrument.Oboe,
  69. "organ": ClefInstruction_1.MidiInstrument.Church_Organ,
  70. "orgue": ClefInstruction_1.MidiInstrument.Church_Organ,
  71. "orgel": ClefInstruction_1.MidiInstrument.Church_Organ,
  72. "piano": ClefInstruction_1.MidiInstrument.Acoustic_Grand_Piano,
  73. "klavier": ClefInstruction_1.MidiInstrument.Acoustic_Grand_Piano,
  74. "piccolo": ClefInstruction_1.MidiInstrument.Piccolo,
  75. "strings": ClefInstruction_1.MidiInstrument.String_Ensemble_1,
  76. "streicher": ClefInstruction_1.MidiInstrument.String_Ensemble_1,
  77. "steeldrum": ClefInstruction_1.MidiInstrument.Steel_Drums,
  78. "trombone": ClefInstruction_1.MidiInstrument.Trombone,
  79. "posaune": ClefInstruction_1.MidiInstrument.Trombone,
  80. "brass": ClefInstruction_1.MidiInstrument.Trombone,
  81. "trumpet": ClefInstruction_1.MidiInstrument.Trumpet,
  82. "trompete": ClefInstruction_1.MidiInstrument.Trumpet,
  83. "tpt": ClefInstruction_1.MidiInstrument.Trumpet,
  84. "tuba": ClefInstruction_1.MidiInstrument.Tuba,
  85. "sax": ClefInstruction_1.MidiInstrument.Tenor_Sax,
  86. "viola": ClefInstruction_1.MidiInstrument.Viola,
  87. "bratsche": ClefInstruction_1.MidiInstrument.Viola,
  88. "violin": ClefInstruction_1.MidiInstrument.Violin,
  89. "violon.": ClefInstruction_1.MidiInstrument.Violin,
  90. "woodblock": ClefInstruction_1.MidiInstrument.Woodblock,
  91. "alt": ClefInstruction_1.MidiInstrument.Synth_Voice,
  92. "alto": ClefInstruction_1.MidiInstrument.Synth_Voice,
  93. "tenor": ClefInstruction_1.MidiInstrument.Synth_Voice,
  94. "bariton": ClefInstruction_1.MidiInstrument.Synth_Voice,
  95. "baritone": ClefInstruction_1.MidiInstrument.Synth_Voice,
  96. "bass": ClefInstruction_1.MidiInstrument.Synth_Voice,
  97. "sopran": ClefInstruction_1.MidiInstrument.Synth_Voice,
  98. "voice": ClefInstruction_1.MidiInstrument.Synth_Voice,
  99. "recorder": ClefInstruction_1.MidiInstrument.Recorder,
  100. "blockflöte": ClefInstruction_1.MidiInstrument.Recorder,
  101. "banjo": ClefInstruction_1.MidiInstrument.Banjo,
  102. "drums": ClefInstruction_1.MidiInstrument.Percussion,
  103. "percussion": ClefInstruction_1.MidiInstrument.Percussion,
  104. "schlagzeug": ClefInstruction_1.MidiInstrument.Percussion,
  105. "schlagwerk": ClefInstruction_1.MidiInstrument.Percussion,
  106. "unnamed": ClefInstruction_1.MidiInstrument.Acoustic_Grand_Piano,
  107. };
  108. return SubInstrument;
  109. }());
  110. exports.SubInstrument = SubInstrument;