OpenShot Audio Library | OpenShotAudio  0.6.0
juce_UMPackets.h
1 /*
2  ==============================================================================
3 
4  This file is part of the JUCE library.
5  Copyright (c) 2022 - Raw Material Software Limited
6 
7  JUCE is an open source library subject to commercial or open-source
8  licensing.
9 
10  The code included in this file is provided under the terms of the ISC license
11  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
12  To use, copy, modify, and/or distribute this software for any purpose with or
13  without fee is hereby granted provided that the above copyright notice and
14  this permission notice appear in all copies.
15 
16  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
17  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
18  DISCLAIMED.
19 
20  ==============================================================================
21 */
22 
23 #ifndef DOXYGEN
24 
25 namespace juce::universal_midi_packets
26 {
27 
39 class Packets
40 {
41 public:
49  void add (const View& v) { storage.insert (storage.end(), v.cbegin(), v.cend()); }
50 
51  void add (const PacketX1& p) { addImpl (p); }
52  void add (const PacketX2& p) { addImpl (p); }
53  void add (const PacketX3& p) { addImpl (p); }
54  void add (const PacketX4& p) { addImpl (p); }
55 
57  void reserve (size_t numWords) { storage.reserve (numWords); }
58 
60  void clear() { storage.clear(); }
61 
63  Iterator cbegin() const noexcept { return Iterator (data(), size()); }
64  Iterator begin() const noexcept { return cbegin(); }
65 
67  Iterator cend() const noexcept { return Iterator (data() + size(), 0); }
68  Iterator end() const noexcept { return cend(); }
69 
71  const uint32_t* data() const noexcept { return storage.data(); }
72 
78  size_t size() const noexcept { return storage.size(); }
79 
80 private:
81  template <size_t numWords>
82  void addImpl (const Packet<numWords>& p)
83  {
84  jassert (Utils::getNumWordsForMessageType (p[0]) == numWords);
85  add (View (p.data()));
86  }
87 
88  std::vector<uint32_t> storage;
89 };
90 
91 } // namespace juce::universal_midi_packets
92 
93 #endif
Iterator cbegin() const noexcept
const uint32_t * data() const noexcept
Iterator cend() const noexcept
static uint32_t getNumWordsForMessageType(uint32_t)