ChordSymbolContainer.ts 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import {Pitch} from "../../Common/DataObjects/pitch";
  2. import {KeyInstruction} from "./Instructions/KeyInstruction";
  3. import {MusicSheetCalculator} from "../Graphical/MusicSheetCalculator";
  4. import {AccidentalEnum} from "../../Common/DataObjects/pitch";
  5. export class ChordSymbolContainer {
  6. private rootPitch: Pitch;
  7. private chordKind: ChordSymbolEnum;
  8. private bassPitch: Pitch;
  9. private degree: Degree;
  10. private keyInstruction: KeyInstruction;
  11. constructor(rootPitch: Pitch, chordKind: ChordSymbolEnum, bassPitch: Pitch, chordDegree: Degree, keyInstruction: KeyInstruction) {
  12. this.rootPitch = rootPitch;
  13. this.chordKind = chordKind;
  14. this.keyInstruction = keyInstruction;
  15. this.bassPitch = bassPitch;
  16. this.degree = chordDegree;
  17. }
  18. public get RootPitch(): Pitch {
  19. return this.rootPitch;
  20. }
  21. public get ChordKind(): ChordSymbolEnum {
  22. return this.chordKind;
  23. }
  24. public get BassPitch(): Pitch {
  25. return this.bassPitch;
  26. }
  27. public get ChordDegree(): Degree {
  28. return this.degree;
  29. }
  30. public get KeyInstruction(): KeyInstruction {
  31. return this.keyInstruction;
  32. }
  33. public static calculateChordText(chordSymbol: ChordSymbolContainer, transposeHalftones: number): string {
  34. let transposedRootPitch: Pitch = chordSymbol.RootPitch;
  35. if (MusicSheetCalculator.transposeCalculator !== undefined) {
  36. transposedRootPitch = MusicSheetCalculator.transposeCalculator.TransposePitch(
  37. chordSymbol.RootPitch,
  38. chordSymbol.KeyInstruction,
  39. transposeHalftones
  40. );
  41. }
  42. let text: string = transposedRootPitch.FundamentalNote.ToString();
  43. if (transposedRootPitch.Accidental !== AccidentalEnum.NONE) {
  44. text += this.getTextForAccidental(transposedRootPitch.Accidental);
  45. }
  46. text += ChordSymbolContainer.getTextFromChordKindEnum(chordSymbol.ChordKind);
  47. if (chordSymbol.BassPitch !== undefined) {
  48. let transposedBassPitch: Pitch = chordSymbol.BassPitch;
  49. if (MusicSheetCalculator.transposeCalculator !== undefined) {
  50. transposedBassPitch = MusicSheetCalculator.transposeCalculator.TransposePitch(
  51. chordSymbol.BassPitch,
  52. chordSymbol.KeyInstruction,
  53. transposeHalftones
  54. );
  55. }
  56. text += "/";
  57. text += transposedBassPitch.FundamentalNote.ToString();
  58. text += this.getTextForAccidental(transposedBassPitch.Accidental);
  59. }
  60. if (chordSymbol.ChordDegree !== undefined) {
  61. switch (chordSymbol.ChordDegree.text) {
  62. case ChordDegreeText.add:
  63. text += "add";
  64. break;
  65. case ChordDegreeText.alter:
  66. text += "alt";
  67. break;
  68. case ChordDegreeText.subtract:
  69. text += "sub";
  70. break;
  71. default:
  72. }
  73. text += chordSymbol.ChordDegree.value;
  74. if (chordSymbol.ChordDegree.alteration !== AccidentalEnum.NONE) {
  75. text += ChordSymbolContainer.getTextForAccidental(chordSymbol.ChordDegree.alteration);
  76. }
  77. }
  78. return text;
  79. }
  80. private static getTextForAccidental(alteration: AccidentalEnum): string {
  81. let text: string = "";
  82. switch (alteration) {
  83. case AccidentalEnum.DOUBLEFLAT:
  84. text += "bb";
  85. break;
  86. case AccidentalEnum.FLAT:
  87. text += "b";
  88. break;
  89. case AccidentalEnum.SHARP:
  90. text += "#";
  91. break;
  92. case AccidentalEnum.DOUBLESHARP:
  93. text += "x";
  94. break;
  95. default:
  96. }
  97. return text;
  98. }
  99. private static getTextFromChordKindEnum(kind: ChordSymbolEnum): string {
  100. let text: string = "";
  101. switch (kind) {
  102. case ChordSymbolEnum.major:
  103. break;
  104. case ChordSymbolEnum.minor:
  105. text += "m";
  106. break;
  107. case ChordSymbolEnum.augmented:
  108. text += "aug";
  109. break;
  110. case ChordSymbolEnum.diminished:
  111. text += "dim";
  112. break;
  113. case ChordSymbolEnum.dominant:
  114. text += "7";
  115. break;
  116. case ChordSymbolEnum.majorseventh:
  117. text += "maj7";
  118. break;
  119. case ChordSymbolEnum.minorseventh:
  120. text += "m7";
  121. break;
  122. case ChordSymbolEnum.diminishedseventh:
  123. text += "dim7";
  124. break;
  125. case ChordSymbolEnum.augmentedseventh:
  126. text += "aug7";
  127. break;
  128. case ChordSymbolEnum.halfdiminished:
  129. text += "m7b5";
  130. break;
  131. case ChordSymbolEnum.majorminor:
  132. text += "";
  133. break;
  134. case ChordSymbolEnum.majorsixth:
  135. text += "maj6";
  136. break;
  137. case ChordSymbolEnum.minorsixth:
  138. text += "m6";
  139. break;
  140. case ChordSymbolEnum.dominantninth:
  141. text += "9";
  142. break;
  143. case ChordSymbolEnum.majorninth:
  144. text += "maj9";
  145. break;
  146. case ChordSymbolEnum.minorninth:
  147. text += "m9";
  148. break;
  149. case ChordSymbolEnum.dominant11th:
  150. text += "11";
  151. break;
  152. case ChordSymbolEnum.major11th:
  153. text += "maj11";
  154. break;
  155. case ChordSymbolEnum.minor11th:
  156. text += "m11";
  157. break;
  158. case ChordSymbolEnum.dominant13th:
  159. text += "13";
  160. break;
  161. case ChordSymbolEnum.major13th:
  162. text += "maj13";
  163. break;
  164. case ChordSymbolEnum.minor13th:
  165. text += "m13";
  166. break;
  167. case ChordSymbolEnum.suspendedsecond:
  168. text += "sus2";
  169. break;
  170. case ChordSymbolEnum.suspendedfourth:
  171. text += "sus4";
  172. break;
  173. case ChordSymbolEnum.Neapolitan:
  174. case ChordSymbolEnum.Italian:
  175. case ChordSymbolEnum.French:
  176. case ChordSymbolEnum.German:
  177. case ChordSymbolEnum.pedal:
  178. case ChordSymbolEnum.power:
  179. case ChordSymbolEnum.Tristan:
  180. break;
  181. default
  182. }
  183. return text;
  184. }
  185. }
  186. export class Degree {
  187. constructor(value: number, alteration: AccidentalEnum, text: ChordDegreeText) {
  188. this.value = value;
  189. this.alteration = alteration;
  190. this.text = text;
  191. }
  192. public value: number;
  193. public alteration: AccidentalEnum;
  194. public text: ChordDegreeText;
  195. }
  196. export enum ChordDegreeText {
  197. add,
  198. alter,
  199. subtract
  200. }
  201. export enum ChordSymbolEnum {
  202. major,
  203. minor,
  204. augmented,
  205. diminished,
  206. dominant,
  207. majorseventh,
  208. minorseventh,
  209. diminishedseventh,
  210. augmentedseventh,
  211. halfdiminished,
  212. majorminor,
  213. majorsixth,
  214. minorsixth,
  215. dominantninth,
  216. majorninth,
  217. minorninth,
  218. dominant11th,
  219. major11th,
  220. minor11th,
  221. dominant13th,
  222. major13th,
  223. minor13th,
  224. suspendedsecond,
  225. suspendedfourth,
  226. Neapolitan,
  227. Italian,
  228. French,
  229. German,
  230. pedal,
  231. power,
  232. Tristan
  233. }