Zrythm
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
midi_mapping.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: © 2019-2022 Alexandros Theodotou <alex@zrythm.org>
2// SPDX-License-Identifier: LicenseRef-ZrythmLicense
3
10#ifndef __AUDIO_MIDI_MAPPING_H__
11#define __AUDIO_MIDI_MAPPING_H__
12
13#include "dsp/ext_port.h"
14#include "dsp/port.h"
15#include "utils/midi.h"
16
17typedef struct _WrappedObjectWithChangeSignal
19
26#define MIDI_MAPPING_SCHEMA_VERSION 1
27#define MIDI_MAPPINGS_SCHEMA_VERSION 1
28
29#define MIDI_MAPPINGS (PROJECT->midi_mappings)
30
34typedef struct MidiMapping
35{
36 int schema_version;
37
40
44
47
55
57 volatile int enabled;
58
62
63static const cyaml_schema_field_t midi_mapping_fields_schema[] = {
64 YAML_FIELD_INT (MidiMapping, schema_version),
67 key,
68 uint8_t_schema,
69 3),
72 device_port,
73 ext_port_fields_schema),
76 dest_id,
77 port_identifier_fields_schema),
78 YAML_FIELD_INT (MidiMapping, enabled),
79
80 CYAML_FIELD_END
81};
82
83static const cyaml_schema_value_t midi_mapping_schema = {
84 YAML_VALUE_PTR (MidiMapping, midi_mapping_fields_schema),
85};
86
87#if 0
88static const cyaml_schema_value_t
89 midi_mapping_schema_default =
90{
92 MidiMapping, midi_mapping_fields_schema),
93};
94#endif
95
99typedef struct MidiMappings
100{
101 int schema_version;
102
103 MidiMapping ** mappings;
104 size_t mappings_size;
105 int num_mappings;
107
108static const cyaml_schema_field_t midi_mappings_fields_schema[] = {
109 YAML_FIELD_INT (MidiMappings, schema_version),
112 mappings,
113 midi_mapping_schema),
114
115 CYAML_FIELD_END
116};
117
118static const cyaml_schema_value_t midi_mappings_schema = {
119 YAML_VALUE_PTR (MidiMappings, midi_mappings_fields_schema),
120};
121
126void
128
134
135#define midi_mappings_bind_device( \
136 self, buf, dev_port, dest_port, fire_events) \
137 midi_mappings_bind_at ( \
138 self, buf, dev_port, dest_port, (self)->num_mappings, \
139 fire_events)
140
141#define midi_mappings_bind_track( \
142 self, buf, dest_port, fire_events) \
143 midi_mappings_bind_at ( \
144 self, buf, NULL, dest_port, (self)->num_mappings, \
145 fire_events)
146
156void
158 MidiMappings * self,
159 midi_byte_t * buf,
160 ExtPort * device_port,
161 Port * dest_port,
162 int idx,
163 bool fire_events);
164
171void
173 MidiMappings * self,
174 int idx,
175 bool fire_events);
176
178midi_mapping_new (void);
179
180void
181midi_mapping_set_enabled (MidiMapping * self, bool enabled);
182
183int
184midi_mapping_get_index (
185 MidiMappings * self,
186 MidiMapping * mapping);
187
188NONNULL MidiMapping *
189midi_mapping_clone (const MidiMapping * src);
190
191void
192midi_mapping_free (MidiMapping * self);
193
202void
204 MidiMappings * self,
205 MidiEvents * events,
206 bool queued);
207
211void
213
221int
223 MidiMappings * self,
224 Port * dest_port,
225 GPtrArray * arr);
226
228midi_mappings_clone (const MidiMappings * src);
229
230void
231midi_mappings_free (MidiMappings * self);
232
237#endif
External ports.
void midi_mappings_apply_from_cc_events(MidiMappings *self, MidiEvents *events, bool queued)
Applies the events to the appropriate mapping.
void midi_mappings_bind_at(MidiMappings *self, midi_byte_t *buf, ExtPort *device_port, Port *dest_port, int idx, bool fire_events)
Binds the CC represented by the given raw buffer (must be size 3) to the given Port.
void midi_mappings_init_loaded(MidiMappings *self)
Initializes the MidiMappings after a Project is loaded.
int midi_mappings_get_for_port(MidiMappings *self, Port *dest_port, GPtrArray *arr)
Get MIDI mappings for the given port.
void midi_mappings_apply(MidiMappings *self, midi_byte_t *buf)
Applies the given buffer to the matching ports.
MidiMappings * midi_mappings_new(void)
Returns a newly allocated MidiMappings.
void midi_mappings_unbind(MidiMappings *self, int idx, bool fire_events)
Unbinds the given binding.
#define YAML_FIELD_MAPPING_EMBEDDED(owner, member, schema)
Mapping embedded inside the struct.
Definition yaml.h:32
#define YAML_VALUE_DEFAULT(cc, fields_schema)
Schema to be used for arrays of structs directly (not as pointers).
Definition yaml.h:238
#define YAML_FIELD_FIXED_SIZE_PTR_ARRAY(owner, member, schema, size)
Fixed-width array of pointers with fixed count.
Definition yaml.h:73
uint8_t midi_byte_t
MIDI byte.
Definition types.h:31
#define YAML_VALUE_PTR(cc, fields_schema)
Schema to be used as a pointer.
Definition yaml.h:221
#define YAML_FIELD_DYN_PTR_ARRAY_VAR_COUNT_OPT(owner, member, schema)
Dynamic-width (reallocated) array of pointers with variable count, nullable.
Definition yaml.h:138
#define YAML_FIELD_MAPPING_PTR_OPTIONAL(owner, member, schema)
Mapping pointer to a struct.
Definition yaml.h:46
MIDI utils.
Ports that transfer audio/midi/other signals to one another.
External port.
Definition ext_port.h:78
Container for passing midi events through ports.
Definition midi_event.h:68
A mapping from a MIDI value to a destination.
midi_byte_t key[3]
Raw MIDI signal.
ExtPort * device_port
The device that this connection will be mapped for.
volatile int enabled
Whether this binding is enabled.
WrappedObjectWithChangeSignal * gobj
Used in Gtk.
Port * dest
Destination pointer, for convenience.
PortIdentifier dest_id
Destination.
All MIDI mappings in Zrythm.
Struct used to identify Ports in the project.
Must ONLY be created via port_new()
Definition port.h:150
A GObject-ified normal C object with a signal that interested parties can listen to for changes.