commit 4711bddac6ee6ca048067a66a7cad50bf9691b01
parent 5bf4674420ce4d736ccf364806f2b80e85d8f45e
Author: Alexandre BIQUE <bique.alexandre@gmail.com>
Date: Tue, 21 Dec 2021 07:59:44 +0100
Initial work on alignment
Diffstat:
9 files changed, 112 insertions(+), 89 deletions(-)
diff --git a/include/clap/all.h b/include/clap/all.h
@@ -1,37 +0,0 @@
-#pragma once
-
-#include "clap.h"
-
-#include "entry.h"
-#include "plugin-factory.h"
-#include "plugin-invalidation.h"
-
-#include "ext/audio-ports.h"
-#include "ext/audio-ports-config.h"
-#include "ext/gui.h"
-#include "ext/gui-x11.h"
-#include "ext/gui-win32.h"
-#include "ext/gui-cocoa.h"
-#include "ext/gui-free-standing.h"
-#include "ext/log.h"
-#include "ext/params.h"
-#include "ext/render.h"
-#include "ext/state.h"
-#include "ext/latency.h"
-#include "ext/thread-check.h"
-#include "ext/timer-support.h"
-#include "ext/fd-support.h"
-#include "ext/note-name.h"
-#include "ext/note-ports.h"
-#include "ext/event-filter.h"
-#include "ext/thread-pool.h"
-
-#include "ext/draft/preset-load.h"
-#include "ext/draft/quick-controls.h"
-#include "ext/draft/track-info.h"
-#include "ext/draft/tuning.h"
-#include "ext/draft/file-reference.h"
-#include "ext/draft/midi-mappings.h"
-
-#include "converters/vst2-converter.h"
-#include "converters/vst3-converter.h"
diff --git a/include/clap/audio-buffer.h b/include/clap/audio-buffer.h
@@ -2,6 +2,8 @@
#include <stdint.h>
+#include "private/align_push.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -10,11 +12,13 @@ typedef struct clap_audio_buffer {
// Either data32 or data64 pointer will be set.
float ** data32;
double **data64;
- uint32_t channel_count;
- uint32_t latency; // latency from/to the audio interface
+ alignas(4) uint32_t channel_count;
+ alignas(4) uint32_t latency; // latency from/to the audio interface
uint64_t constant_mask; // mask & (1 << N) to test if channel N is constant
} clap_audio_buffer_t;
#ifdef __cplusplus
}
-#endif
-\ No newline at end of file
+#endif
+
+#include "private/align_pop.h"
+\ No newline at end of file
diff --git a/include/clap/clap.h b/include/clap/clap.h
@@ -25,5 +25,39 @@
#pragma once
+#include "entry.h"
+#include "plugin-factory.h"
+#include "plugin-invalidation.h"
+
#include "plugin.h"
#include "host.h"
+
+#include "ext/audio-ports.h"
+#include "ext/audio-ports-config.h"
+#include "ext/gui.h"
+#include "ext/gui-x11.h"
+#include "ext/gui-win32.h"
+#include "ext/gui-cocoa.h"
+#include "ext/gui-free-standing.h"
+#include "ext/log.h"
+#include "ext/params.h"
+#include "ext/render.h"
+#include "ext/state.h"
+#include "ext/latency.h"
+#include "ext/thread-check.h"
+#include "ext/timer-support.h"
+#include "ext/fd-support.h"
+#include "ext/note-name.h"
+#include "ext/note-ports.h"
+#include "ext/event-filter.h"
+#include "ext/thread-pool.h"
+
+#include "ext/draft/preset-load.h"
+#include "ext/draft/quick-controls.h"
+#include "ext/draft/track-info.h"
+#include "ext/draft/tuning.h"
+#include "ext/draft/file-reference.h"
+#include "ext/draft/midi-mappings.h"
+
+#include "converters/vst2-converter.h"
+#include "converters/vst3-converter.h"
diff --git a/include/clap/color.h b/include/clap/color.h
@@ -6,6 +6,8 @@
extern "C" {
#endif
+#pragma pack(push, 1)
+
typedef struct clap_color {
uint8_t red;
uint8_t green;
@@ -13,6 +15,8 @@ typedef struct clap_color {
uint8_t alpha;
} clap_color_t;
+#pragma pack(pop)
+
#ifdef __cplusplus
}
#endif
\ No newline at end of file
diff --git a/include/clap/entry.h b/include/clap/entry.h
@@ -3,6 +3,8 @@
#include "version.h"
#include "private/macros.h"
+#include "private/align_push.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -42,3 +44,5 @@ CLAP_EXPORT extern const clap_plugin_entry_t clap_entry;
#ifdef __cplusplus
}
#endif
+
+#include "private/align_pop.h"
+\ No newline at end of file
diff --git a/include/clap/events.h b/include/clap/events.h
@@ -6,6 +6,8 @@
#include "fixedpoint.h"
#include "id.h"
+#include "private/align_push.h"
+
#ifdef __cplusplus
extern "C" {
#endif
@@ -60,14 +62,14 @@ enum {
typedef int32_t clap_note_expression;
typedef struct clap_event_note_expression {
- clap_note_expression expression_id;
+ alignas(4) clap_note_expression expression_id;
// target a specific port, key and channel, -1 for global
- int32_t port_index;
- int32_t key;
- int32_t channel;
+ alignas(4) int32_t port_index;
+ alignas(4) int32_t key;
+ alignas(4) int32_t channel;
- double value; // see expression for the range
+ alignas(8) double value; // see expression for the range
} clap_event_note_expression_t;
enum {
@@ -84,30 +86,30 @@ typedef int32_t clap_event_param_flags;
typedef struct clap_event_param_value {
// target parameter
- void *cookie; // @ref clap_param_info.cookie
- clap_id param_id; // @ref clap_param_info.id
+ void *cookie; // @ref clap_param_info.cookie
+ alignas(4) clap_id param_id; // @ref clap_param_info.id
// target a specific port, key and channel, -1 for global
- int32_t port_index;
- int32_t key;
- int32_t channel;
+ alignas(4) int32_t port_index;
+ alignas(4) int32_t key;
+ alignas(4) int32_t channel;
- clap_event_param_flags flags;
+ alignas(4) clap_event_param_flags flags;
- double value;
+ alignas(8) double value;
} clap_event_param_value_t;
typedef struct clap_event_param_mod {
// target parameter
- void *cookie; // @ref clap_param_info.cookie
- clap_id param_id; // @ref clap_param_info.id
+ void *cookie; // @ref clap_param_info.cookie
+ alignas(4) clap_id param_id; // @ref clap_param_info.id
// target a specific port, key and channel, -1 for global
- int32_t port_index;
- int32_t key;
- int32_t channel;
+ alignas(4) int32_t port_index;
+ alignas(4) int32_t key;
+ alignas(4) int32_t channel;
- double amount; // modulation amount
+ alignas(8) double amount; // modulation amount
} clap_event_param_mod_t;
enum {
@@ -123,29 +125,29 @@ enum {
typedef uint32_t clap_transport_flags;
typedef struct clap_event_transport {
- clap_transport_flags flags;
+ alignas(4) clap_transport_flags flags;
- clap_beattime song_pos_beats; // position in beats
- clap_sectime song_pos_seconds; // position in seconds
+ alignas(8) clap_beattime song_pos_beats; // position in beats
+ alignas(8) clap_sectime song_pos_seconds; // position in seconds
- double tempo; // in bpm
- double tempo_inc; // tempo increment for each samples and until the next
- // time info event
+ alignas(8) double tempo; // in bpm
+ alignas(8) double tempo_inc; // tempo increment for each samples and until the next
+ // time info event
- clap_beattime bar_start; // start pos of the current bar
- int32_t bar_number; // bar at song pos 0 has the number 0
+ alignas(8) clap_beattime bar_start; // start pos of the current bar
+ alignas(4) int32_t bar_number; // bar at song pos 0 has the number 0
- clap_beattime loop_start_beats;
- clap_beattime loop_end_beats;
- clap_sectime loop_start_seconds;
- clap_sectime loop_end_seconds;
+ alignas(8) clap_beattime loop_start_beats;
+ alignas(8) clap_beattime loop_end_beats;
+ alignas(8) clap_sectime loop_start_seconds;
+ alignas(8) clap_sectime loop_end_seconds;
- int16_t tsig_num; // time signature numerator
- int16_t tsig_denom; // time signature denominator
+ alignas(2) int16_t tsig_num; // time signature numerator
+ alignas(2) int16_t tsig_denom; // time signature denominator
} clap_event_transport_t;
typedef struct clap_event_note_mask {
- int32_t port_index;
+ uint32_t port_index;
// bitset of active keys:
// - 11 bits
@@ -154,26 +156,26 @@ typedef struct clap_event_note_mask {
// 000 0100 0100 -> minor chord
// 000 0100 1000 -> major chord
// 010 1011 0101 -> locrian scale
- uint16_t note_mask;
- uint8_t root_note; // 0..11, 0 for C
+ alignas(2) uint16_t note_mask;
+ alignas(1) uint8_t root_note; // 0..11, 0 for C
} clap_event_note_mask_t;
typedef struct clap_event_midi {
- int32_t port_index;
- uint8_t data[3];
+ alignas(4) uint32_t port_index;
+ alignas(1) uint8_t data[3];
} clap_event_midi_t;
typedef struct clap_event_midi_sysex {
- int32_t port_index;
+ alignas(4) uint32_t port_index;
const uint8_t *buffer; // midi buffer
- uint32_t size;
+ alignas(4) uint32_t size;
} clap_event_midi_sysex_t;
typedef struct clap_event {
- clap_event_type type;
- uint32_t time; // offset from the first sample in the process block
+ alignas(4) clap_event_type type;
+ alignas(4) uint32_t time; // offset from the first sample in the process block
- union {
+ alignas(8) union {
clap_event_note_t note;
clap_event_note_expression_t note_expression;
clap_event_param_value_t param_value;
@@ -199,4 +201,6 @@ typedef struct clap_event_list {
#ifdef __cplusplus
}
-#endif
-\ No newline at end of file
+#endif
+
+#include "private/align_pop.h"
+\ No newline at end of file
diff --git a/include/clap/private/align_push.h b/include/clap/private/align_push.h
@@ -1 +1,10 @@
-#pragma pack(push, sizeof(void*))
-\ No newline at end of file
+#include <stdint.h>
+#include <stdalign.h>
+
+#if UINTPTR_MAX == UINT64_MAX
+# pragma pack(push, 8)
+#elif UINTPTR_MAX == UINT32_MAX
+# pragma pack(push, 4)
+#elif UINTPTR_MAX == UINT16_MAX
+# pragma pack(push, 2)
+#endif
+\ No newline at end of file
diff --git a/src/main.c b/src/main.c
@@ -1,4 +1,4 @@
-#include <clap/all.h>
+#include <clap/clap.h>
// The purpose of this file is to check that all headers compile
diff --git a/src/main.cc b/src/main.cc
@@ -1,4 +1,4 @@
-#include <clap/all.h>
+#include <clap/clap.h>
// The purpose of this file is to check that all headers compile