The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

90 lines
3.2KB

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