1 /* 2 * Copyright (C) 2020-2021 Alexandros Theodotou <alex at zrythm dot org> 3 * 4 * This file is part of Zrythm 5 * 6 * Zrythm is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU Affero General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * Zrythm is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU Affero General Public License for more details. 15 * 16 * You should have received a copy of the GNU Affero General Public License 17 * along with Zrythm. If not, see <https://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __UNDO_MIDI_MAPPING_ACTION_H__ 21 #define __UNDO_MIDI_MAPPING_ACTION_H__ 22 23 #include "actions/undoable_action.h" 24 #include "audio/ext_port.h" 25 #include "audio/midi_mapping.h" 26 #include "audio/port_identifier.h" 27 #include "utils/types.h" 28 29 /** 30 * @addtogroup actions 31 * 32 * @{ 33 */ 34 35 typedef enum MidiMappingActionType 36 { 37 MIDI_MAPPING_ACTION_BIND, 38 MIDI_MAPPING_ACTION_UNBIND, 39 MIDI_MAPPING_ACTION_ENABLE, 40 MIDI_MAPPING_ACTION_DISABLE, 41 } MidiMappingActionType; 42 43 static const cyaml_strval_t 44 midi_mapping_action_type_strings[] = 45 { 46 { "Bind", 47 MIDI_MAPPING_ACTION_BIND }, 48 { "Unbind", 49 MIDI_MAPPING_ACTION_UNBIND }, 50 { "Enable", 51 MIDI_MAPPING_ACTION_ENABLE }, 52 { "Disable", 53 MIDI_MAPPING_ACTION_DISABLE }, 54 }; 55 56 /** 57 * MIDI mapping action. 58 */ 59 typedef struct MidiMappingAction 60 { 61 UndoableAction parent_instance; 62 63 /** Index of mapping, if enable/disable. */ 64 int idx; 65 66 /** Action type. */ 67 MidiMappingActionType type; 68 69 PortIdentifier dest_port_id; 70 71 ExtPort * dev_port; 72 73 midi_byte_t buf[3]; 74 75 } MidiMappingAction; 76 77 static const cyaml_schema_field_t 78 midi_mapping_action_fields_schema[] = 79 { 80 YAML_FIELD_MAPPING_EMBEDDED ( 81 MidiMappingAction, parent_instance, 82 undoable_action_fields_schema), 83 YAML_FIELD_INT (MidiMappingAction, idx), 84 YAML_FIELD_MAPPING_EMBEDDED ( 85 MidiMappingAction, dest_port_id, 86 port_identifier_fields_schema), 87 YAML_FIELD_MAPPING_PTR_OPTIONAL ( 88 MidiMappingAction, dev_port, 89 ext_port_fields_schema), 90 YAML_FIELD_FIXED_SIZE_PTR_ARRAY ( 91 MidiMappingAction, buf, 92 uint8_t_schema, 3), 93 94 CYAML_FIELD_END 95 }; 96 97 static const cyaml_schema_value_t 98 midi_mapping_action_schema = 99 { 100 CYAML_VALUE_MAPPING ( 101 CYAML_FLAG_POINTER, MidiMappingAction, 102 midi_mapping_action_fields_schema), 103 }; 104 105 void 106 midi_mapping_action_init_loaded ( 107 MidiMappingAction * self); 108 109 /** 110 * Creates a new action. 111 */ 112 WARN_UNUSED_RESULT 113 UndoableAction * 114 midi_mapping_action_new_enable ( 115 int idx, 116 bool enable, 117 GError ** error); 118 119 /** 120 * Creates a new action. 121 */ 122 WARN_UNUSED_RESULT 123 UndoableAction * 124 midi_mapping_action_new_bind ( 125 midi_byte_t * buf, 126 ExtPort * device_port, 127 Port * dest_port, 128 GError ** error); 129 130 /** 131 * Creates a new action. 132 */ 133 WARN_UNUSED_RESULT 134 UndoableAction * 135 midi_mapping_action_new_unbind ( 136 int idx, 137 GError ** error); 138 139 NONNULL 140 MidiMappingAction * 141 midi_mapping_action_clone ( 142 const MidiMappingAction * src); 143 144 /** 145 * Wrapper of midi_mapping_action_new_enable(). 146 */ 147 bool 148 midi_mapping_action_perform_enable ( 149 int idx, 150 bool enable, 151 GError ** error); 152 153 /** 154 * Wrapper of midi_mapping_action_new_bind(). 155 */ 156 bool 157 midi_mapping_action_perform_bind ( 158 midi_byte_t * buf, 159 ExtPort * device_port, 160 Port * dest_port, 161 GError ** error); 162 163 /** 164 * Wrapper of midi_mapping_action_new_unbind(). 165 */ 166 bool 167 midi_mapping_action_perform_unbind ( 168 int idx, 169 GError ** error); 170 171 int 172 midi_mapping_action_do ( 173 MidiMappingAction * self, 174 GError ** error); 175 176 int 177 midi_mapping_action_undo ( 178 MidiMappingAction * self, 179 GError ** error); 180 181 char * 182 midi_mapping_action_stringize ( 183 MidiMappingAction * self); 184 185 void 186 midi_mapping_action_free ( 187 MidiMappingAction * self); 188 189 /** 190 * @} 191 */ 192 193 #endif 194