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.

juce_MPENote.h 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  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. @tags{Audio}
  28. */
  29. struct JUCE_API MPENote
  30. {
  31. //==============================================================================
  32. /** Possible values for the note key state. */
  33. enum KeyState
  34. {
  35. off = 0, /**< The key is up (off). */
  36. keyDown = 1, /**< The note key is currently down (pressed). */
  37. sustained = 2, /**< The note is sustained (by a sustain or sostenuto pedal). */
  38. keyDownAndSustained = 3 /**< The note key is down and sustained (by a sustain or sostenuto pedal). */
  39. };
  40. //==============================================================================
  41. /** Constructor.
  42. @param midiChannel The MIDI channel of the note, between 2 and 15.
  43. (Channel 1 and channel 16 can never be note channels in MPE).
  44. @param initialNote The MIDI note number, between 0 and 127.
  45. @param velocity The note-on velocity of the note.
  46. @param pitchbend The initial per-note pitchbend of the note.
  47. @param pressure The initial pressure of the note.
  48. @param timbre The timbre value of the note.
  49. @param keyState The key state of the note (whether the key is down
  50. and/or the note is sustained). This value must not
  51. be MPENote::off, since you are triggering a new note.
  52. (If not specified, the default value will be MPENote::keyDown.)
  53. */
  54. MPENote (int midiChannel,
  55. int initialNote,
  56. MPEValue velocity,
  57. MPEValue pitchbend,
  58. MPEValue pressure,
  59. MPEValue timbre,
  60. KeyState keyState = MPENote::keyDown) noexcept;
  61. /** Default constructor.
  62. Constructs an invalid MPE note (a note with the key state MPENote::off
  63. and an invalid MIDI channel. The only allowed use for such a note is to
  64. call isValid() on it; everything else is undefined behaviour.
  65. */
  66. MPENote() noexcept;
  67. /** Checks whether the MPE note is valid. */
  68. bool isValid() const noexcept;
  69. //==============================================================================
  70. // Invariants that define the note.
  71. /** A unique ID. Useful to distinguish the note from other simultaneously
  72. sounding notes that may use the same note number or MIDI channel.
  73. This should never change during the lifetime of a note object.
  74. */
  75. uint16 noteID = 0;
  76. /** The MIDI channel which this note uses.
  77. This should never change during the lifetime of an MPENote object.
  78. */
  79. uint8 midiChannel = 0;
  80. /** The MIDI note number that was sent when the note was triggered.
  81. This should never change during the lifetime of an MPENote object.
  82. */
  83. uint8 initialNote = 0;
  84. //==============================================================================
  85. // The five dimensions of continuous expressive control
  86. /** The velocity ("strike") of the note-on.
  87. This dimension will stay constant after the note has been turned on.
  88. */
  89. MPEValue noteOnVelocity { MPEValue::minValue() };
  90. /** Current per-note pitchbend of the note (in units of MIDI pitchwheel
  91. position). This dimension can be modulated while the note sounds.
  92. Note: This value is not aware of the currently used pitchbend range,
  93. or an additional master pitchbend that may be simultaneously applied.
  94. To compute the actual effective pitchbend of an MPENote, you should
  95. probably use the member totalPitchbendInSemitones instead.
  96. @see totalPitchbendInSemitones, getFrequencyInHertz
  97. */
  98. MPEValue pitchbend { MPEValue::centreValue() };
  99. /** Current pressure with which the note is held down.
  100. This dimension can be modulated while the note sounds.
  101. */
  102. MPEValue pressure { MPEValue::centreValue() };
  103. /** Initial value of timbre when the note was triggered.
  104. This should never change during the lifetime of an MPENote object.
  105. */
  106. MPEValue initialTimbre { MPEValue::centreValue() };
  107. /** Current value of the note's third expressive dimension, typically
  108. encoding some kind of timbre parameter.
  109. This dimension can be modulated while the note sounds.
  110. */
  111. MPEValue timbre { MPEValue::centreValue() };
  112. /** The release velocity ("lift") of the note after a note-off has been
  113. received.
  114. This dimension will only have a meaningful value after a note-off has
  115. been received for the note (and keyState is set to MPENote::off or
  116. MPENote::sustained). Initially, the value is undefined.
  117. */
  118. MPEValue noteOffVelocity { MPEValue::minValue() };
  119. //==============================================================================
  120. /** Current effective pitchbend of the note in units of semitones, relative
  121. to initialNote. You should use this to compute the actual effective pitch
  122. of the note. This value is computed and set by an MPEInstrument to the
  123. sum of the per-note pitchbend value (stored in MPEValue::pitchbend)
  124. and the master pitchbend of the MPE zone, weighted with the per-note
  125. pitchbend range and master pitchbend range of the zone, respectively.
  126. @see getFrequencyInHertz
  127. */
  128. double totalPitchbendInSemitones;
  129. /** Current key state. Indicates whether the note key is currently down (pressed)
  130. and/or the note is sustained (by a sustain or sostenuto pedal).
  131. */
  132. KeyState keyState { MPENote::off };
  133. //==============================================================================
  134. /** Returns the current frequency of the note in Hertz. This is the sum of
  135. the initialNote and the totalPitchbendInSemitones, converted to Hertz.
  136. */
  137. double getFrequencyInHertz (double frequencyOfA = 440.0) const noexcept;
  138. /** Returns true if two notes are the same, determined by their unique ID. */
  139. bool operator== (const MPENote& other) const noexcept;
  140. /** Returns true if two notes are different notes, determined by their unique ID. */
  141. bool operator!= (const MPENote& other) const noexcept;
  142. };
  143. } // namespace juce