Audio plugin host https://kx.studio/carla
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.

177 lines
6.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. The code included in this file is provided under the terms of the ISC license
  8. http://www.isc.org/downloads/software-support-policy/isc-license. Permission
  9. To use, copy, modify, and/or distribute this software for any purpose with or
  10. without fee is hereby granted provided that the above copyright notice and
  11. this permission notice appear in all copies.
  12. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  13. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  14. DISCLAIMED.
  15. ==============================================================================
  16. */
  17. namespace juce
  18. {
  19. //==============================================================================
  20. /**
  21. This struct represents a playing MPE note.
  22. A note is identified by a unique ID, or alternatively, by a MIDI channel
  23. and an initial note. It is characterised by five dimensions of continuous
  24. expressive control. Their current values are represented as
  25. MPEValue objects.
  26. @see MPEValue
  27. */
  28. struct JUCE_API MPENote
  29. {
  30. //==============================================================================
  31. enum KeyState
  32. {
  33. off = 0,
  34. keyDown = 1,
  35. sustained = 2,
  36. keyDownAndSustained = 3
  37. };
  38. //==============================================================================
  39. /** Constructor.
  40. @param midiChannel The MIDI channel of the note, between 2 and 16.
  41. (Channel 1 can never be a note channel in MPE).
  42. @param initialNote The MIDI note number, between 0 and 127.
  43. @param velocity The note-on velocity of the note.
  44. @param pitchbend The initial per-note pitchbend of the note.
  45. @param pressure The initial pressure of the note.
  46. @param timbre The timbre value of the note.
  47. @param keyState The key state of the note (whether the key is down
  48. and/or the note is sustained). This value must not
  49. be MPENote::off, since you are triggering a new note.
  50. (If not specified, the default value will be MPENOte::keyDown.)
  51. */
  52. MPENote (int midiChannel,
  53. int initialNote,
  54. MPEValue velocity,
  55. MPEValue pitchbend,
  56. MPEValue pressure,
  57. MPEValue timbre,
  58. KeyState keyState = MPENote::keyDown) noexcept;
  59. /** Default constructor.
  60. Constructs an invalid MPE note (a note with the key state MPENote::off
  61. and an invalid MIDI channel. The only allowed use for such a note is to
  62. call isValid() on it; everything else is undefined behaviour.
  63. */
  64. MPENote() noexcept;
  65. /** Checks whether the MPE note is valid. */
  66. bool isValid() const noexcept;
  67. //==============================================================================
  68. // Invariants that define the note.
  69. /** A unique ID. Useful to distinguish the note from other simultaneously
  70. sounding notes that may use the same note number or MIDI channel.
  71. This should never change during the lifetime of a note object.
  72. */
  73. uint16 noteID;
  74. /** The MIDI channel which this note uses.
  75. This should never change during the lifetime of an MPENote object.
  76. */
  77. uint8 midiChannel;
  78. /** The MIDI note number that was sent when the note was triggered.
  79. This should never change during the lifetime of an MPENote object.
  80. */
  81. uint8 initialNote;
  82. //==============================================================================
  83. // The five dimensions of continuous expressive control
  84. /** The velocity ("strike") of the note-on.
  85. This dimension will stay constant after the note has been turned on.
  86. */
  87. MPEValue noteOnVelocity;
  88. /** Current per-note pitchbend of the note (in units of MIDI pitchwheel
  89. position). This dimension can be modulated while the note sounds.
  90. Note: This value is not aware of the currently used pitchbend range,
  91. or an additional master pitchbend that may be simultaneously applied.
  92. To compute the actual effective pitchbend of an MPENote, you should
  93. probably use the member totalPitchbendInSemitones instead.
  94. @see totalPitchbendInSemitones, getFrequencyInHertz
  95. */
  96. MPEValue pitchbend;
  97. /** Current pressure with which the note is held down.
  98. This dimension can be modulated while the note sounds.
  99. */
  100. MPEValue pressure;
  101. /** Current value of the note's third expressive dimension, tyically
  102. encoding some kind of timbre parameter.
  103. This dimension can be modulated while the note sounds.
  104. */
  105. MPEValue timbre;
  106. /** The release velocity ("lift") of the note after a note-off has been
  107. received.
  108. This dimension will only have a meaningful value after a note-off has
  109. been received for the note (and keyState is set to MPENote::off or
  110. MPENOte::sustained). Initially, the value is undefined.
  111. */
  112. MPEValue noteOffVelocity;
  113. //==============================================================================
  114. /** Current effective pitchbend of the note in units of semitones, relative
  115. to initialNote. You should use this to compute the actual effective pitch
  116. of the note. This value is computed and set by an MPEInstrument to the
  117. sum of the per-note pitchbend value (stored in MPEValue::pitchbend)
  118. and the master pitchbend of the MPE zone, weighted with the per-note
  119. pitchbend range and master pitchbend range of the zone, respectively.
  120. @see getFrequencyInHertz
  121. */
  122. double totalPitchbendInSemitones;
  123. /** Current key state. Indicates whether the note key is currently down (pressed)
  124. and/or the note is sustained (by a sustain or sostenuto pedal).
  125. */
  126. KeyState keyState;
  127. //==============================================================================
  128. /** Returns the current frequency of the note in Hertz. This is the a sum of
  129. the initialNote and the totalPitchbendInSemitones, converted to Hertz.
  130. */
  131. double getFrequencyInHertz (double frequencyOfA = 440.0) const noexcept;
  132. /** Returns true if two notes are the same, determined by their unique ID. */
  133. bool operator== (const MPENote& other) const noexcept;
  134. /** Returns true if two notes are different notes, determined by their unique ID. */
  135. bool operator!= (const MPENote& other) const noexcept;
  136. };
  137. } // namespace juce