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_UMPView.h 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. #ifndef DOXYGEN
  18. namespace juce
  19. {
  20. namespace universal_midi_packets
  21. {
  22. /**
  23. Points to a single Universal MIDI Packet.
  24. The packet must be well-formed for member functions to work correctly.
  25. Specifically, the constructor argument must be the beginning of a region of
  26. uint32_t that contains at least `getNumWordsForMessageType(*ddata)` items,
  27. where `data` is the constructor argument.
  28. NOTE: Instances of this class do not own the memory that they point to!
  29. If you need to store a packet pointed-to by a View for later use, copy
  30. the view contents to a Packets collection, or use the Utils::PacketX types.
  31. @tags{Audio}
  32. */
  33. class View
  34. {
  35. public:
  36. /** Create an invalid view. */
  37. View() noexcept = default;
  38. /** Create a view of the packet starting at address `d`. */
  39. explicit View (const uint32_t* data) noexcept : ptr (data) {}
  40. /** Get a pointer to the first word in the Universal MIDI Packet currently
  41. pointed-to by this view.
  42. */
  43. const uint32_t* data() const noexcept { return ptr; }
  44. /** Get the number of 32-words (between 1 and 4 inclusive) in the Universal
  45. MIDI Packet currently pointed-to by this view.
  46. */
  47. uint32_t size() const noexcept;
  48. /** Get a specific word from this packet.
  49. Passing an `index` that is greater than or equal to the result of `size`
  50. will cause undefined behaviour.
  51. */
  52. const uint32_t& operator[] (size_t index) const noexcept { return ptr[index]; }
  53. /** Get an iterator pointing to the first word in the packet. */
  54. const uint32_t* begin() const noexcept { return ptr; }
  55. const uint32_t* cbegin() const noexcept { return ptr; }
  56. /** Get an iterator pointing one-past the last word in the packet. */
  57. const uint32_t* end() const noexcept { return ptr + size(); }
  58. const uint32_t* cend() const noexcept { return ptr + size(); }
  59. /** Return true if this view is pointing to the same address as another view. */
  60. bool operator== (const View& other) const noexcept { return ptr == other.ptr; }
  61. /** Return false if this view is pointing to the same address as another view. */
  62. bool operator!= (const View& other) const noexcept { return ! operator== (other); }
  63. private:
  64. const uint32_t* ptr = nullptr;
  65. };
  66. }
  67. }
  68. #endif