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.5KB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2016 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of the ISC license
  6. http://www.isc.org/downloads/software-support-policy/isc-license/
  7. Permission to use, copy, modify, and/or distribute this software for any
  8. purpose with or without fee is hereby granted, provided that the above
  9. copyright notice and this permission notice appear in all copies.
  10. THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD
  11. TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  12. FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
  13. OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  14. USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  15. TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
  16. OF THIS SOFTWARE.
  17. -----------------------------------------------------------------------------
  18. To release a closed-source product which uses other parts of JUCE not
  19. licensed under the ISC terms, commercial licenses are available: visit
  20. www.juce.com for more information.
  21. ==============================================================================
  22. */
  23. #ifndef JUCE_MPENOTE_H_INCLUDED
  24. #define JUCE_MPENOTE_H_INCLUDED
  25. //==============================================================================
  26. /**
  27. This struct represents a playing MPE note.
  28. A note is identified by a unique ID, or alternatively, by a MIDI channel
  29. and an initial note. It is characterised by five dimensions of continuous
  30. expressive control. Their current values are represented as
  31. MPEValue objects.
  32. @see MPEValue
  33. */
  34. struct JUCE_API MPENote
  35. {
  36. //==============================================================================
  37. enum KeyState
  38. {
  39. off = 0,
  40. keyDown = 1,
  41. sustained = 2,
  42. keyDownAndSustained = 3
  43. };
  44. //==============================================================================
  45. /** Constructor.
  46. @param midiChannel The MIDI channel of the note, between 2 and 16.
  47. (Channel 1 can never be a note channel in MPE).
  48. @param initialNote The MIDI note number, between 0 and 127.
  49. @param velocity The note-on velocity of the note.
  50. @param pitchbend The initial per-note pitchbend of the note.
  51. @param pressure The initial pressure of the note.
  52. @param timbre The timbre value of the note.
  53. @param keyState The key state of the note (whether the key is down
  54. and/or the note is sustained). This value must not
  55. be MPENote::off, since you are triggering a new note.
  56. (If not specified, the default value will be MPENOte::keyDown.)
  57. */
  58. MPENote (int midiChannel,
  59. int initialNote,
  60. MPEValue velocity,
  61. MPEValue pitchbend,
  62. MPEValue pressure,
  63. MPEValue timbre,
  64. KeyState keyState = MPENote::keyDown) noexcept;
  65. /** Default constructor.
  66. Constructs an invalid MPE note (a note with the key state MPENote::off
  67. and an invalid MIDI channel. The only allowed use for such a note is to
  68. call isValid() on it; everything else is undefined behaviour.
  69. */
  70. MPENote() noexcept;
  71. /** Checks whether the MPE note is valid. */
  72. bool isValid() const noexcept;
  73. //==============================================================================
  74. // Invariants that define the note.
  75. /** A unique ID. Useful to distinguish the note from other simultaneously
  76. sounding notes that may use the same note number or MIDI channel.
  77. This should never change during the lifetime of a note object.
  78. */
  79. uint16 noteID;
  80. /** The MIDI channel which this note uses.
  81. This should never change during the lifetime of an MPENote object.
  82. */
  83. uint8 midiChannel;
  84. /** The MIDI note number that was sent when the note was triggered.
  85. This should never change during the lifetime of an MPENote object.
  86. */
  87. uint8 initialNote;
  88. //==============================================================================
  89. // The five dimensions of continuous expressive control
  90. /** The velocity ("strike") of the note-on.
  91. This dimension will stay constant after the note has been turned on.
  92. */
  93. MPEValue noteOnVelocity;
  94. /** Current per-note pitchbend of the note (in units of MIDI pitchwheel
  95. position). This dimension can be modulated while the note sounds.
  96. Note: This value is not aware of the currently used pitchbend range,
  97. or an additional master pitchbend that may be simultaneously applied.
  98. To compute the actual effective pitchbend of an MPENote, you should
  99. probably use the member totalPitchbendInSemitones instead.
  100. @see totalPitchbendInSemitones, getFrequencyInHertz
  101. */
  102. MPEValue pitchbend;
  103. /** Current pressure with which the note is held down.
  104. This dimension can be modulated while the note sounds.
  105. */
  106. MPEValue pressure;
  107. /** Current value of the note's third expressive dimension, tyically
  108. encoding some kind of timbre parameter.
  109. This dimension can be modulated while the note sounds.
  110. */
  111. MPEValue timbre;
  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;
  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;
  133. //==============================================================================
  134. /** Returns the current frequency of the note in Hertz. This is the a 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. #endif // JUCE_MPENOTE_H_INCLUDED