-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmidi_value.h
46 lines (40 loc) · 1.22 KB
/
midi_value.h
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
#ifndef CSYNTH_MIDI_VALUE_H
#define CSYNTH_MIDI_VALUE_H
#include <float.h>
#include <math.h>
#include "../../core/func.h"
#include "../../core/gen.h"
#include "../../ui/midi_state.h"
/** @see midi_value_create */
typedef struct
{
/** @brief MIDI type to get value for. */
MidiType type;
/** @brief MIDI channel to get value for. */
uint8_t channel;
/** @brief MIDI control number to get value for. */
uint8_t data1;
} MidiValueContext;
static double midi_value_eval(__U size_t count, __U Gen **args, __U Eval *eval, void *context_)
{
MidiValueContext *context = (MidiValueContext *)context_;
return midi_state_get(context->type, context->channel, context->data1);
}
/**
* @brief Create a function that gets a MIDI control value.
*
* @param type MIDI message type.
* @param channel MIDI channel.
* @param control MIDI control number.
* @return Func* Value function.
*/
Func *midi_value_create(MidiType type, int channel, int control)
{
MidiValueContext initial = {
.type = type,
.channel = channel - 1,
.data1 = control,
};
return func_create(NULL, midi_value_eval, NULL, NULL, sizeof(MidiValueContext), &initial, FuncFlagSkipReset);
}
#endif // CSYNTH_MIDI_VALUE_H