Skip to content

Commit

Permalink
Add header for AURenderEvent.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Dec 27, 2021
1 parent 5837e3a commit e4df360
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 14 deletions.
84 changes: 84 additions & 0 deletions AURenderEvent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

typedef uint32_t AUAudioFrameCount;
typedef float AUValue;
typedef uint64_t AUParameterAddress;

// forward declaration
union AURenderEvent;

// =================================================================================================
// Realtime events - parameters and MIDI

/*
/// Describes the type of a render event.
typedef NS_ENUM(uint8_t, AURenderEventType) {
AURenderEventParameter = 1,
AURenderEventParameterRamp = 2,
AURenderEventMIDI = 8,
AURenderEventMIDISysEx = 9,
AURenderEventMIDIEventList = 10
};
*/

typedef uint8_t AURenderEventType;
#define AURenderEventParameter 1
#define AURenderEventParameterRamp 2
#define AURenderEventMIDI 8
#define AURenderEventMIDISysEx 9
#define AURenderEventMIDIEventList 10

#pragma pack(4)
/// Common header for an AURenderEvent.
typedef struct AURenderEventHeader {
union AURenderEvent *__nullable next; //!< The next event in a linked list of events.
AUEventSampleTime eventSampleTime; //!< The sample time at which the event is scheduled to occur.
AURenderEventType eventType; //!< The type of the event.
uint8_t reserved; //!< Must be 0.
} AURenderEventHeader;

/// Describes a scheduled parameter change.
typedef struct AUParameterEvent {
union AURenderEvent *__nullable next; //!< The next event in a linked list of events.
AUEventSampleTime eventSampleTime; //!< The sample time at which the event is scheduled to occur.
AURenderEventType eventType; //!< AURenderEventParameter or AURenderEventParameterRamp.
uint8_t reserved[3]; //!< Must be 0.
AUAudioFrameCount rampDurationSampleFrames;
//!< If greater than 0, the event is a parameter ramp;
/// should be 0 for a non-ramped event.
AUParameterAddress parameterAddress; //!< The parameter to change.
AUValue value; //!< If ramped, the parameter value at the
/// end of the ramp; for a non-ramped event,
/// the new value.
} AUParameterEvent;

/// Describes a single scheduled MIDI event.
typedef struct AUMIDIEvent {
union AURenderEvent *__nullable next; //!< The next event in a linked list of events.
AUEventSampleTime eventSampleTime; //!< The sample time at which the event is scheduled to occur.
AURenderEventType eventType; //!< AURenderEventMIDI or AURenderEventMIDISysEx.
uint8_t reserved; //!< Must be 0.
uint16_t length; //!< The number of valid MIDI bytes in the data field.
/// 1, 2 or 3 for most MIDI events, but can be longer
/// for system-exclusive (sys-ex) events.
uint8_t cable; //!< The virtual cable number.
uint8_t data[3]; //!< The bytes of the MIDI event. Running status will not be used.
} AUMIDIEvent;

/// Describes a single scheduled MIDIEventList.
typedef struct AUMIDIEventList {
union AURenderEvent *__nullable next; //!< The next event in a linked list of events.
AUEventSampleTime eventSampleTime; //!< The sample time at which the event is scheduled to occur.
AURenderEventType eventType; //!< AURenderEventMIDI or AURenderEventMIDISysEx.
uint8_t reserved; //!< Must be 0.
uint8_t cable; //!< The virtual cable number.
MIDIEventList eventList; //!< A structure containing UMP packets.
} AUMIDIEventList;

typedef union AURenderEvent {
AURenderEventHeader head;
AUParameterEvent parameter;
AUMIDIEvent MIDI;
AUMIDIEventList MIDIEventsList;
} AURenderEvent;
#pragma pack()

24 changes: 10 additions & 14 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,44 @@ fn build(sdk_path: Option<&str>, target: &str) {
use std::env;
use std::path::PathBuf;

let mut headers: Vec<&'static str> = vec![];
let mut header = String::new();

#[cfg(feature = "audio_toolbox")]
{
println!("cargo:rustc-link-lib=framework=AudioToolbox");
headers.push("AudioToolbox/AudioToolbox.h");
header.push_str("#include <AudioToolbox/AudioToolbox.h>\n");
header.push_str("#include \"AURenderEvent.h\"\n");
}

#[cfg(feature = "audio_unit")]
{
println!("cargo:rustc-link-lib=framework=AudioToolbox");
headers.push("AudioUnit/AudioUnit.h");
header.push_str("#include <AudioUnit/AudioUnit.h>\n");
}

#[cfg(feature = "core_audio")]
{
println!("cargo:rustc-link-lib=framework=CoreAudio");

if target.contains("apple-ios") {
headers.push("CoreAudio/CoreAudioTypes.h");
header.push_str("#include <CoreAudio/CoreAudioTypes.h>\n");
} else {
headers.push("CoreAudio/CoreAudio.h");
header.push_str("#include <CoreAudio/CoreAudio.h>\n");
}
}

#[cfg(feature = "open_al")]
{
println!("cargo:rustc-link-lib=framework=OpenAL");
headers.push("OpenAL/al.h");
headers.push("OpenAL/alc.h");
header.push_str("#include <OpenAL/al.h>\n");
header.push_str("#include <OpenAL/alc.h>\n");
}

#[cfg(all(feature = "core_midi"))]
{
if target.contains("apple-darwin") {
println!("cargo:rustc-link-lib=framework=CoreMIDI");
headers.push("CoreMIDI/CoreMIDI.h");
header.push_str("#include <CoreMIDI/CoreMIDI.h>");
}
}

Expand Down Expand Up @@ -113,12 +114,7 @@ fn build(sdk_path: Option<&str>, target: &str) {
builder = builder.blacklist_item("objc_object");
}

let meta_header: Vec<_> = headers
.iter()
.map(|h| format!("#include <{}>\n", h))
.collect();

builder = builder.header_contents("coreaudio.h", &meta_header.concat());
builder = builder.header_contents("coreaudio.h", &header);

// Generate the bindings.
builder = builder.trust_clang_mangling(false).derive_default(true);
Expand Down

0 comments on commit e4df360

Please sign in to comment.