1 /* 2 * Copyright (C) 2019-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 /** 21 * \file 22 * 23 * Velocities for MidiNote's. 24 */ 25 26 #ifndef __AUDIO_VELOCITY_H__ 27 #define __AUDIO_VELOCITY_H__ 28 29 #include <stdint.h> 30 31 #include "audio/region_identifier.h" 32 #include "gui/backend/arranger_object.h" 33 34 #include <cyaml/cyaml.h> 35 36 typedef struct MidiNote MidiNote; 37 typedef struct _VelocityWidget VelocityWidget; 38 39 /** 40 * @addtogroup audio 41 * 42 * @{ 43 */ 44 45 #define VELOCITY_SCHEMA_VERSION 1 46 47 #define velocity_is_selected(r) \ 48 arranger_object_is_selected ( \ 49 (ArrangerObject *) r) 50 51 /** 52 * Default velocity. 53 */ 54 #define VELOCITY_DEFAULT 90 55 56 /** 57 * The MidiNote velocity. 58 */ 59 typedef struct Velocity 60 { 61 /** Base struct. */ 62 ArrangerObject base; 63 64 int schema_version; 65 66 /** Velocity value (0-127). */ 67 uint8_t vel; 68 69 /** Velocity at drag begin - used for ramp 70 * actions only. */ 71 uint8_t vel_at_start; 72 73 /** Pointer back to the MIDI note. */ 74 MidiNote * midi_note; 75 } Velocity; 76 77 static const cyaml_schema_field_t 78 velocity_fields_schema[] = 79 { 80 YAML_FIELD_MAPPING_EMBEDDED ( 81 Velocity, base, 82 arranger_object_fields_schema), 83 YAML_FIELD_INT (Velocity, schema_version), 84 YAML_FIELD_UINT (Velocity, vel), 85 CYAML_FIELD_END 86 }; 87 88 static const cyaml_schema_value_t 89 velocity_schema = 90 { 91 YAML_VALUE_PTR ( 92 Velocity, 93 velocity_fields_schema), 94 }; 95 96 /** 97 * Creates a new Velocity with the given value. 98 */ 99 Velocity * 100 velocity_new ( 101 MidiNote * midi_note, 102 const uint8_t vel); 103 104 /** 105 * Sets the MidiNote the Velocity belongs to. 106 */ 107 void 108 velocity_set_midi_note ( 109 Velocity * velocity, 110 MidiNote * midi_note); 111 112 /** 113 * Returns 1 if the Velocity's match, 0 if not. 114 */ 115 int 116 velocity_is_equal ( 117 Velocity * src, 118 Velocity * dest); 119 120 /** 121 * Changes the Velocity by the given amount of 122 * values (delta). 123 */ 124 void 125 velocity_shift ( 126 Velocity * self, 127 const int delta); 128 129 /** 130 * Sets the velocity to the given value. 131 * 132 * The given value may exceed the bounds 0-127, 133 * and will be clamped. 134 */ 135 void 136 velocity_set_val ( 137 Velocity * self, 138 const int val); 139 140 /** 141 * Returns the owner MidiNote. 142 */ 143 MidiNote * 144 velocity_get_midi_note ( 145 const Velocity * const self); 146 147 /** 148 * @} 149 */ 150 151 #endif 152