OpenShot Audio Library | OpenShotAudio 0.4.0
 
Loading...
Searching...
No Matches
juce_UMPUtils.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
25namespace juce::universal_midi_packets
26{
27
33struct Utils
34{
36 static constexpr uint32_t bytesToWord (std::byte a, std::byte b, std::byte c, std::byte d)
37 {
38 return uint32_t (a) << 0x18
39 | uint32_t (b) << 0x10
40 | uint32_t (c) << 0x08
41 | uint32_t (d) << 0x00;
42 }
43
50 static uint32_t getNumWordsForMessageType (uint32_t);
51
55 template <size_t Index>
56 struct U4
57 {
58 static constexpr uint32_t shift = (uint32_t) 0x1c - Index * 4;
59
60 static constexpr uint32_t set (uint32_t word, uint8_t value)
61 {
62 return (word & ~((uint32_t) 0xf << shift)) | (uint32_t) ((value & 0xf) << shift);
63 }
64
65 static constexpr uint8_t get (uint32_t word)
66 {
67 return (uint8_t) ((word >> shift) & 0xf);
68 }
69 };
70
74 template <size_t Index>
75 struct U8
76 {
77 static constexpr uint32_t shift = (uint32_t) 0x18 - Index * 8;
78
79 static constexpr uint32_t set (uint32_t word, uint8_t value)
80 {
81 return (word & ~((uint32_t) 0xff << shift)) | (uint32_t) (value << shift);
82 }
83
84 static constexpr uint8_t get (uint32_t word)
85 {
86 return (uint8_t) ((word >> shift) & 0xff);
87 }
88 };
89
93 template <size_t Index>
94 struct U16
95 {
96 static constexpr uint32_t shift = (uint32_t) 0x10 - Index * 16;
97
98 static constexpr uint32_t set (uint32_t word, uint16_t value)
99 {
100 return (word & ~((uint32_t) 0xffff << shift)) | (uint32_t) (value << shift);
101 }
102
103 static constexpr uint16_t get (uint32_t word)
104 {
105 return (uint16_t) ((word >> shift) & 0xffff);
106 }
107 };
108
109 static constexpr uint8_t getMessageType (uint32_t w) noexcept { return U4<0>::get (w); }
110 static constexpr uint8_t getGroup (uint32_t w) noexcept { return U4<1>::get (w); }
111 static constexpr uint8_t getStatus (uint32_t w) noexcept { return U4<2>::get (w); }
112 static constexpr uint8_t getChannel (uint32_t w) noexcept { return U4<3>::get (w); }
113};
114
115} // namespace juce::universal_midi_packets
116
117#endif
static constexpr uint32_t bytesToWord(std::byte a, std::byte b, std::byte c, std::byte d)
static uint32_t getNumWordsForMessageType(uint32_t)