ARAPitchInterpretation.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //------------------------------------------------------------------------------
  2. //! \file ARAPitchInterpretation.h
  3. //! classes to find proper names for pitches, ARAContentChord and ARAContentKeySignature
  4. //! if not provided by the API partner
  5. //! \project ARA SDK Library
  6. //! \copyright Copyright (c) 2018-2021, Celemony Software GmbH, All Rights Reserved.
  7. //! \license Licensed under the Apache License, Version 2.0 (the "License");
  8. //! you may not use this file except in compliance with the License.
  9. //! You may obtain a copy of the License at
  10. //!
  11. //! http://www.apache.org/licenses/LICENSE-2.0
  12. //!
  13. //! Unless required by applicable law or agreed to in writing, software
  14. //! distributed under the License is distributed on an "AS IS" BASIS,
  15. //! WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. //! See the License for the specific language governing permissions and
  17. //! limitations under the License.
  18. //------------------------------------------------------------------------------
  19. #ifndef ARAPitchInterpretation_h
  20. #define ARAPitchInterpretation_h
  21. #include "ARA_API/ARAInterface.h"
  22. #include <string>
  23. namespace ARA {
  24. //! @addtogroup ARA_Library_Utility_Pitch_Interpretation
  25. //! @{
  26. //! Base class for chord and key signature interpretation, provides basic configuration.
  27. class PitchInterpreter
  28. {
  29. public:
  30. //! Construct to use ASCII symbols and/or German note names.
  31. explicit PitchInterpreter (bool useAsciiSymbols = false, bool useGermanNoteNames = false)
  32. : _asciiSymbols { useAsciiSymbols }, _germanNoteNames { useGermanNoteNames } {}
  33. bool usesASCIISymbols () const noexcept { return _asciiSymbols; } //!< True if the interpreter uses ASCII symbols.
  34. void setUseASCIISymbols (bool use) noexcept { _asciiSymbols = use; } //!< Enable or disable the use of ASCII symbols.
  35. bool usesGermanNoteNames () const noexcept { return _germanNoteNames; } //!< True if the interpreter uses German note names.
  36. void setUseGermanNoteNames (bool use) noexcept { _germanNoteNames = use; } //!< Enable or disable the use of German note names.
  37. //! Get the name of the note at the given ::ARACircleOfFifthsIndex.
  38. //! If usesASCIISymbols() is false, the returned std::string may contain ::ARAUtf8Char (potentially multi-byte) symbols.
  39. std::string getNoteNameForCircleOfFifthIndex (ARACircleOfFifthsIndex index) const;
  40. protected:
  41. ARAUtf8String getFlatSymbol () const noexcept;
  42. ARAUtf8String getSharpSymbol () const noexcept;
  43. private:
  44. bool _asciiSymbols { false };
  45. bool _germanNoteNames { false };
  46. };
  47. //! Provides a user-readable name for an ARAContentChord based on its interval description.
  48. class ChordInterpreter : public PitchInterpreter
  49. {
  50. public:
  51. using PitchInterpreter::PitchInterpreter;
  52. //! Returns true if \p chord is the "no chord".
  53. //! A chord is considered "no chord" if it contains no notes, i.e. all intervals are unused.
  54. static bool isNoChord (const ARAContentChord& chord) noexcept;
  55. //! Get the user-readable name of \p chord.
  56. //! Will always generate a name based on the abstract chord data and ignore ARAContentChord.name.
  57. //! If usesASCIISymbols() is false, the returned std::string may contain ::ARAUtf8Char (potentially multi-byte) symbols.
  58. std::string getNameForChord (const ARAContentChord& chord) const;
  59. };
  60. //! Provides a user-readable name for an ARAContentKeySignature based on its interval description.
  61. class KeySignatureInterpreter : public PitchInterpreter
  62. {
  63. public:
  64. using PitchInterpreter::PitchInterpreter;
  65. //! Scale mode type returned from getScaleMode().
  66. enum ScaleMode
  67. {
  68. kInvalid = 0,
  69. kIonian = 1,
  70. kDorian = 2,
  71. kPhrygian = 3,
  72. kLydian = 4,
  73. kMixolydian = 5,
  74. kAeolian = 6,
  75. kLocrian = 7
  76. };
  77. //! True if scale of \p keySignature contains a major third, false otherwise.
  78. static bool hasMajorThird (const ARAContentKeySignature& keySignature) noexcept { return keySignature.intervals[4] != kARAKeySignatureIntervalUnused; }
  79. //! True if scale of \p keySignature contains a minor third, false otherwise.
  80. static bool hasMinorThird (const ARAContentKeySignature& keySignature) noexcept { return keySignature.intervals[3] != kARAKeySignatureIntervalUnused; }
  81. //! True if scale of \p keySignature contains a major seventh, false otherwise.
  82. static bool hasMajorSeventh (const ARAContentKeySignature& keySignature) noexcept { return keySignature.intervals[11] != kARAKeySignatureIntervalUnused; }
  83. //! True if scale of \p keySignature contains a minor seventh, false otherwise.
  84. static bool hasMinorSeventh (const ARAContentKeySignature& keySignature) noexcept { return keySignature.intervals[10] != kARAKeySignatureIntervalUnused; }
  85. //! Returns the scale mode of \p keySignature.
  86. static ScaleMode getScaleMode (const ARAContentKeySignature& keySignature) noexcept;
  87. //! Get the user-readable name of \p keySignature.
  88. //! Will always try to generate a name based on the abstract key signature data and ignore ARAContentKeySignature.name.
  89. //! Only covers a commonly used subset of the key signatures that the abstract key signature data can describe -
  90. //! will return empty string if no suitable name can be provided.
  91. //! If usesASCIISymbols() is false, the returned std::string may contain ::ARAUtf8Char (potentially multi-byte) symbols.
  92. std::string getNameForKeySignature (const ARAContentKeySignature& keySignature) const;
  93. //! Returns the name of the root note of \p keySignature (useful if getNameForKeySignature() fails).
  94. //! If usesASCIISymbols() is false, the returned std::string may contain ::ARAUtf8Char (potentially multi-byte) symbols.
  95. std::string getRootNoteNameForKeySignature (const ARAContentKeySignature& keySignature) const { return getNoteNameForCircleOfFifthIndex(keySignature.root); }
  96. };
  97. //! @} ARA_Library_Utility_Pitch_Interpretation
  98. } // namespace ARA
  99. #endif // ARAPitchInterpretation_h