-
Notifications
You must be signed in to change notification settings - Fork 9
/
global.c
128 lines (106 loc) · 3.93 KB
/
global.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/* ----
* ---- file : global.c
* ---- author : alisomay
* ---- legal : Distributed under terms of the MIT LICENSE (MIT).
* ----
* ---- Permission is hereby granted, free of charge, to any person obtaining a copy
* ---- of this software and associated documentation files (the "Software"), to deal
* ---- in the Software without restriction, including without limitation the rights
* ---- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* ---- copies of the Software, and to permit persons to whom the Software is
* ---- furnished to do so, subject to the following conditions:
* ----
* ---- The above copyright notice and this permission notice shall be included in
* ---- all copies or substantial portions of the Software.
* ----
* ---- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* ---- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* ---- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* ---- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* ---- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* ---- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* ---- THE SOFTWARE.
* ----
* ---- info : This is part of the "libanalogrytm" package.
* ----
* ---- created: 28Nov2023
* ---- changed: N/A
* ----
* ----
*/
// #define AR_DEBUG defined
#include "types.h"
#include "debug.h"
#include "error.h"
#include "sysex.h"
#include "global.h"
/* ---------------------------------------------------------------------------- ar_global_request */
ar_error_t ar_global_request(sU8 *_dstBuf, sU8 _devId, sU8 _globalSlot) {
ar_sysex_meta_t meta;
ar_error_t ret;
AR_SYSEX_META_INIT(meta, _devId, AR_TYPE_GLOBAL, _globalSlot);
ret = ar_sysex_request(_dstBuf, &meta);
return ret;
}
/* ---------------------------------------------------------------------------- ar_global_request_x */
ar_error_t ar_global_request_x(sU8 *_dstBuf, sU8 _devId, sU8 _globalSlot) {
ar_sysex_meta_t meta;
ar_error_t ret;
AR_SYSEX_META_INIT(meta, _devId, AR_TYPE_GLOBAL, (128u + (_globalSlot & 127u)));
ret = ar_sysex_request(_dstBuf, &meta);
return ret;
}
/* ---------------------------------------------------------------------------- ar_global_syx_to_raw */
ar_error_t ar_global_syx_to_raw(sU8 *_rawBuf,
const sU8 *_syxBuf,
sU32 _syxBufSize,
sU32 *_retRawBufSize,
ar_sysex_meta_t *_meta) {
ar_error_t ret;
sU32 datSz;
ar_sysex_meta_t meta;
ret = ar_sysex_to_raw(_rawBuf, &_syxBuf, &_syxBufSize, &datSz, &meta);
Dprintf("xxx ar_global_syx_to_raw: syxSz=%u rawSz=%u sizeof(global)=%lu\n", _syxBufSize, datSz, sizeof(ar_global_t));
if(AR_ERR_OK == ret)
{
if(NULL != _retRawBufSize)
{
*_retRawBufSize = datSz;
}
if(NULL != _meta)
{
*_meta = meta;
}
if(AR_TYPE_GLOBAL == meta.obj_type)
{
/* Succeeded */
}
else
{
ret = AR_ERR_NOT_A_GLOBAL;
}
}
return ret;
}
/* ---------------------------------------------------------------------------- ar_global_raw_to_syx */
ar_error_t ar_global_raw_to_syx(sU8 *_syxBuf,
const sU8 *_rawBuf,
sU32 _rawBufSize,
sU32 *_retSyxBufSize,
const ar_sysex_meta_t *_meta) {
ar_error_t ret;
if(NULL != _meta)
{
sU32 syxSz;
ret = ar_raw_to_sysex(_syxBuf, _rawBuf, _rawBufSize, &syxSz, _meta);
if(NULL != _retSyxBufSize)
{
*_retSyxBufSize = syxSz;
}
}
else
{
ret = AR_ERR_NULLPTR;
}
return ret;
}