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.

97 lines
3.4KB

  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. Holds a collection of Universal MIDI Packets.
  24. Unlike MidiBuffer, this collection does not store any additional information
  25. (e.g. timestamps) alongside the raw messages.
  26. If timestamps are required, these can be added to the container in UMP format,
  27. as Jitter Reduction Utility messages.
  28. @tags{Audio}
  29. */
  30. class Packets
  31. {
  32. public:
  33. /** Adds a single packet to the collection.
  34. The View must be valid for this to work. If the view
  35. points to a malformed message, or if the view points to a region
  36. too short for the contained message, this call will result in
  37. undefined behaviour.
  38. */
  39. void add (const View& v) { storage.insert (storage.end(), v.cbegin(), v.cend()); }
  40. void add (const PacketX1& p) { addImpl (p); }
  41. void add (const PacketX2& p) { addImpl (p); }
  42. void add (const PacketX3& p) { addImpl (p); }
  43. void add (const PacketX4& p) { addImpl (p); }
  44. /** Pre-allocates space for at least `numWords` 32-bit words in this collection. */
  45. void reserve (size_t numWords) { storage.reserve (numWords); }
  46. /** Removes all previously-added packets from this collection. */
  47. void clear() { storage.clear(); }
  48. /** Gets an iterator pointing to the first packet in this collection. */
  49. Iterator cbegin() const noexcept { return Iterator (data(), size()); }
  50. Iterator begin() const noexcept { return cbegin(); }
  51. /** Gets an iterator pointing one-past the last packet in this collection. */
  52. Iterator cend() const noexcept { return Iterator (data() + size(), 0); }
  53. Iterator end() const noexcept { return cend(); }
  54. /** Gets a pointer to the contents of the collection as a range of raw 32-bit words. */
  55. const uint32_t* data() const noexcept { return storage.data(); }
  56. /** Returns the number of uint32_t words in storage.
  57. Note that this is likely to be larger than the number of packets
  58. currently being stored, as some packets span multiple words.
  59. */
  60. size_t size() const noexcept { return storage.size(); }
  61. private:
  62. template <size_t numWords>
  63. void addImpl (const Packet<numWords>& p)
  64. {
  65. jassert (Utils::getNumWordsForMessageType (p[0]) == numWords);
  66. add (View (p.data()));
  67. }
  68. std::vector<uint32_t> storage;
  69. };
  70. }
  71. }
  72. #endif