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.

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