-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrtmidi_c.nim
278 lines (237 loc) · 10.6 KB
/
rtmidi_c.nim
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
{.deadCodeElim: on.}
when defined(windows):
const
rtmididll* = "rtmidi.dll"
elif defined(macosx):
const
rtmididll* = "librtmidi.dylib"
else:
const
rtmididll* = "librtmidi.so"
## **********************************************************************
## ! \defgroup C-interface
## @{
##
## \brief C interface to realtime MIDI input/output C++ classes.
##
## RtMidi offers a C-style interface, principally for use in binding
## RtMidi to other programming languages. All structs, enums, and
## functions listed here have direct analogs (and simply call to)
## items in the C++ RtMidi class and its supporting classes and
## types
##
## **********************************************************************
## !
## \file rtmidi_c.h
##
##
## #if defined(RTMIDI_EXPORT)
## #if defined _WIN32 || defined __CYGWIN__
## #define RTMIDIAPI __declspec(dllexport)
## #else
## #define RTMIDIAPI __attribute__((visibility("default")))
## #endif
## #else
## #define RTMIDIAPI //__declspec(dllimport)
## #endif
##
## #ifdef __cplusplus
## extern "C" {
## #endif
##
## ! \brief Wraps an RtMidi object for C function return statuses.
type
RtMidiWrapper* {.bycopy.} = object
`ptr`*: pointer ## ! The wrapped RtMidi object.
data*: pointer ## ! True when the last function call was OK.
ok*: bool ## ! If an error occured (ok != true), set to an error message.
msg*: cstring
## ! \brief Typedef for a generic RtMidi pointer.
type
RtMidiPtr* = ptr RtMidiWrapper
## ! \brief Typedef for a generic RtMidiIn pointer.
type
RtMidiInPtr* = ptr RtMidiWrapper
## ! \brief Typedef for a generic RtMidiOut pointer.
type
RtMidiOutPtr* = ptr RtMidiWrapper
## ! \brief MIDI API specifier arguments. See \ref RtMidi::Api.
type
RtMidiApi* {.size: sizeof(cint).} = enum
RTMIDI_API_UNSPECIFIED, ## !< Search for a working compiled API.
RTMIDI_API_MACOSX_CORE, ## !< Macintosh OS-X CoreMIDI API.
RTMIDI_API_LINUX_ALSA, ## !< The Advanced Linux Sound Architecture API.
RTMIDI_API_UNIX_JACK, ## !< The Jack Low-Latency MIDI Server API.
RTMIDI_API_WINDOWS_MM, ## !< The Microsoft Multimedia MIDI API.
RTMIDI_API_RTMIDI_DUMMY, ## !< A compilable but non-functional API.
RTMIDI_API_NUM ## !< Number of values in this enum.
## ! \brief Defined RtMidiError types. See \ref RtMidiError::Type.
type
RtMidiErrorType* {.size: sizeof(cint).} = enum
RTMIDI_ERROR_WARNING, ## !< A non-critical error.
RTMIDI_ERROR_DEBUG_WARNING, ## !< A non-critical error which might be useful for debugging.
RTMIDI_ERROR_UNSPECIFIED, ## !< The default, unspecified error type.
RTMIDI_ERROR_NO_DEVICES_FOUND, ## !< No devices found on system.
RTMIDI_ERROR_INVALID_DEVICE, ## !< An invalid device ID was specified.
RTMIDI_ERROR_MEMORY_ERROR, ## !< An error occured during memory allocation.
RTMIDI_ERROR_INVALID_PARAMETER, ## !< An invalid parameter was specified to a function.
RTMIDI_ERROR_INVALID_USE, ## !< The function was called incorrectly.
RTMIDI_ERROR_DRIVER_ERROR, ## !< A system driver error occured.
RTMIDI_ERROR_SYSTEM_ERROR, ## !< A system error occured.
RTMIDI_ERROR_THREAD_ERROR ## !< A thread error occured.
## ! \brief The type of a RtMidi callback function.
##
## \param timeStamp The time at which the message has been received.
## \param message The midi message.
## \param userData Additional user data for the callback.
##
## See \ref RtMidiIn::RtMidiCallback.
##
type
RtMidiCCallback* = proc (timeStamp: cdouble; message: ptr cuchar; messageSize: csize;
userData: pointer) {.cdecl.}
## RtMidi API
## ! \brief Determine the available compiled MIDI APIs.
##
## If the given `apis` parameter is null, returns the number of available APIs.
## Otherwise, fill the given apis array with the RtMidi::Api values.
##
## \param apis An array or a null value.
## \param apis_size Number of elements pointed to by apis
## \return number of items needed for apis array if apis==NULL, or
## number of items written to apis array otherwise. A negative
## return value indicates an error.
##
## See \ref RtMidi::getCompiledApi().
##
proc rtmidi_get_compiled_api*(apis: ptr RtMidiApi; apis_size: cuint): cint {.cdecl,
importc: "rtmidi_get_compiled_api", dynlib: rtmididll.}
## ! \brief Return the name of a specified compiled MIDI API.
## ! See \ref RtMidi::getApiName().
proc rtmidi_api_name*(api: RtMidiApi): cstring {.cdecl, importc: "rtmidi_api_name",
dynlib: rtmididll.}
## ! \brief Return the display name of a specified compiled MIDI API.
## ! See \ref RtMidi::getApiDisplayName().
proc rtmidi_api_display_name*(api: RtMidiApi): cstring {.cdecl,
importc: "rtmidi_api_display_name", dynlib: rtmididll.}
## ! \brief Return the compiled MIDI API having the given name.
## ! See \ref RtMidi::getCompiledApiByName().
proc rtmidi_compiled_api_by_name*(name: cstring): RtMidiApi {.cdecl,
importc: "rtmidi_compiled_api_by_name", dynlib: rtmididll.}
## ! \internal Report an error.
proc rtmidi_error*(`type`: RtMidiErrorType; errorString: cstring) {.cdecl,
importc: "rtmidi_error", dynlib: rtmididll.}
## ! \brief Open a MIDI port.
##
## \param port Must be greater than 0
## \param portName Name for the application port.
##
## See RtMidi::openPort().
##
proc rtmidi_open_port*(device: RtMidiPtr; portNumber: cuint; portName: cstring) {.
cdecl, importc: "rtmidi_open_port", dynlib: rtmididll.}
## ! \brief Creates a virtual MIDI port to which other software applications can
## connect.
##
## \param portName Name for the application port.
##
## See RtMidi::openVirtualPort().
##
proc rtmidi_open_virtual_port*(device: RtMidiPtr; portName: cstring) {.cdecl,
importc: "rtmidi_open_virtual_port", dynlib: rtmididll.}
## ! \brief Close a MIDI connection.
## See RtMidi::closePort().
##
proc rtmidi_close_port*(device: RtMidiPtr) {.cdecl, importc: "rtmidi_close_port",
dynlib: rtmididll.}
## ! \brief Return the number of available MIDI ports.
## See RtMidi::getPortCount().
##
proc rtmidi_get_port_count*(device: RtMidiPtr): cuint {.cdecl,
importc: "rtmidi_get_port_count", dynlib: rtmididll.}
## ! \brief Return a string identifier for the specified MIDI input port number.
## See RtMidi::getPortName().
##
proc rtmidi_get_port_name*(device: RtMidiPtr; portNumber: cuint): cstring {.cdecl,
importc: "rtmidi_get_port_name", dynlib: rtmididll.}
## RtMidiIn API
##
## ! \brief Create a default RtMidiInPtr value, with no initialization.
proc rtmidi_in_create_default*(): RtMidiInPtr {.cdecl,
importc: "rtmidi_in_create_default", dynlib: rtmididll.}
## ! \brief Create a RtMidiInPtr value, with given api, clientName and queueSizeLimit.
##
## \param api An optional API id can be specified.
## \param clientName An optional client name can be specified. This
## will be used to group the ports that are created
## by the application.
## \param queueSizeLimit An optional size of the MIDI input queue can be
## specified.
##
## See RtMidiIn::RtMidiIn().
##
proc rtmidi_in_create*(api: RtMidiApi; clientName: cstring; queueSizeLimit: cuint): RtMidiInPtr {.
cdecl, importc: "rtmidi_in_create", dynlib: rtmididll.}
## ! \brief Free the given RtMidiInPtr.
proc rtmidi_in_free*(device: RtMidiInPtr) {.cdecl, importc: "rtmidi_in_free",
dynlib: rtmididll.}
## ! \brief Returns the MIDI API specifier for the given instance of RtMidiIn.
## ! See \ref RtMidiIn::getCurrentApi().
proc rtmidi_in_get_current_api*(device: RtMidiPtr): RtMidiApi {.cdecl,
importc: "rtmidi_in_get_current_api", dynlib: rtmididll.}
## ! \brief Set a callback function to be invoked for incoming MIDI messages.
## ! See \ref RtMidiIn::setCallback().
proc rtmidi_in_set_callback*(device: RtMidiInPtr; callback: RtMidiCCallback;
userData: pointer) {.cdecl,
importc: "rtmidi_in_set_callback", dynlib: rtmididll.}
## ! \brief Cancel use of the current callback function (if one exists).
## ! See \ref RtMidiIn::cancelCallback().
proc rtmidi_in_cancel_callback*(device: RtMidiInPtr) {.cdecl,
importc: "rtmidi_in_cancel_callback", dynlib: rtmididll.}
## ! \brief Specify whether certain MIDI message types should be queued or ignored during input.
## ! See \ref RtMidiIn::ignoreTypes().
proc rtmidi_in_ignore_types*(device: RtMidiInPtr; midiSysex: bool; midiTime: bool;
midiSense: bool) {.cdecl,
importc: "rtmidi_in_ignore_types", dynlib: rtmididll.}
## ! Fill the user-provided array with the data bytes for the next available
## MIDI message in the input queue and return the event delta-time in seconds.
##
## \param message Must point to a char* that is already allocated.
## SYSEX messages maximum size being 1024, a statically
## allocated array could
## be sufficient.
## \param size Is used to return the size of the message obtained.
## Must be set to the size of \ref message when calling.
##
## See RtMidiIn::getMessage().
##
proc rtmidi_in_get_message*(device: RtMidiInPtr; message: ptr cuchar; size: ptr csize): cdouble {.
cdecl, importc: "rtmidi_in_get_message", dynlib: rtmididll.}
## RtMidiOut API
##
## ! \brief Create a default RtMidiInPtr value, with no initialization.
proc rtmidi_out_create_default*(): RtMidiOutPtr {.cdecl,
importc: "rtmidi_out_create_default", dynlib: rtmididll.}
## ! \brief Create a RtMidiOutPtr value, with given and clientName.
##
## \param api An optional API id can be specified.
## \param clientName An optional client name can be specified. This
## will be used to group the ports that are created
## by the application.
##
## See RtMidiOut::RtMidiOut().
##
proc rtmidi_out_create*(api: RtMidiApi; clientName: cstring): RtMidiOutPtr {.cdecl,
importc: "rtmidi_out_create", dynlib: rtmididll.}
## ! \brief Free the given RtMidiOutPtr.
proc rtmidi_out_free*(device: RtMidiOutPtr) {.cdecl, importc: "rtmidi_out_free",
dynlib: rtmididll.}
## ! \brief Returns the MIDI API specifier for the given instance of RtMidiOut.
## ! See \ref RtMidiOut::getCurrentApi().
proc rtmidi_out_get_current_api*(device: RtMidiPtr): RtMidiApi {.cdecl,
importc: "rtmidi_out_get_current_api", dynlib: rtmididll.}
## ! \brief Immediately send a single message out an open MIDI output port.
## ! See \ref RtMidiOut::sendMessage().
proc rtmidi_out_send_message*(device: RtMidiOutPtr; message: ptr cuchar; length: cint): cint {.
cdecl, importc: "rtmidi_out_send_message", dynlib: rtmididll.}
## ! }@