Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Define a macro for CStr literals #27

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/ext/audio_ports.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use crate::{host::*, id::*, plugin::*, string_sizes::*};
use crate::{cstr, host::*, id::*, plugin::*, string_sizes::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_AUDIO_PORTS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.audio-ports\0") };
pub const CLAP_EXT_AUDIO_PORTS: &CStr = cstr!("clap.audio-ports");

pub const CLAP_PORT_MONO: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"mono\0") };
pub const CLAP_PORT_STEREO: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"stereo\0") };
pub const CLAP_PORT_MONO: &CStr = cstr!("mono");
pub const CLAP_PORT_STEREO: &CStr = cstr!("stereo");

pub const CLAP_AUDIO_PORT_IS_MAIN: u32 = 1 << 0;
pub const CLAP_AUDIO_PORT_SUPPORTS_64BITS: u32 = 1 << 1;
Expand Down
8 changes: 3 additions & 5 deletions src/ext/audio_ports_config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::ext::audio_ports::*;
use crate::{host::*, id::*, plugin::*, string_sizes::*};
use crate::{cstr, host::*, id::*, plugin::*, string_sizes::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_AUDIO_PORTS_CONFIG: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.audio-ports-config\0") };
pub const CLAP_EXT_AUDIO_PORTS_CONFIG_INFO: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.audio-ports-config-info/draft-0\0") };
pub const CLAP_EXT_AUDIO_PORTS_CONFIG: &CStr = cstr!("clap.audio-ports-config");
pub const CLAP_EXT_AUDIO_PORTS_CONFIG_INFO: &CStr = cstr!("clap.audio-ports-config-info/draft-0");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
8 changes: 3 additions & 5 deletions src/ext/draft/ambisonic.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_AMBISONIC: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.ambisonic.draft/2\0") };
pub const CLAP_EXT_AMBISONIC: &CStr = cstr!("clap.ambisonic.draft/2");

pub const CLAP_PORT_AMBISONIC: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"ambisonic\0") };
pub const CLAP_PORT_AMBISONIC: &CStr = cstr!("ambisonic");

pub const CLAP_AMBISONIC_FUMA: u32 = 0;
pub const CLAP_AMBISONIC_ACN: u32 = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/audio_ports_activation.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::plugin::*;
use crate::{cstr, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_AUDIO_PORTS_ACTIVATION: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.audio-ports-activation/draft-1\0") };
pub const CLAP_EXT_AUDIO_PORTS_ACTIVATION: &CStr = cstr!("clap.audio-ports-activation/draft-1");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/check_for_update.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_CHECK_FOR_UPDATE: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.check_for_update.draft/0\0") };
pub const CLAP_EXT_CHECK_FOR_UPDATE: &CStr = cstr!("clap.check_for_update.draft/0");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/configurable_audio_ports.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::plugin::*;
use crate::{cstr, plugin::*};

use std::ffi::{c_char, CStr};

pub const CLAP_EXT_CONFIGURABLE_AUDIO_PORTS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.configurable-audio-ports.draft0\0") };
pub const CLAP_EXT_CONFIGURABLE_AUDIO_PORTS: &CStr = cstr!("clap.configurable-audio-ports.draft0");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/context_menu.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{host::*, id::*, plugin::*};
use crate::{cstr, host::*, id::*, plugin::*};

use std::ffi::{c_void, CStr};
use std::os::raw::c_char;

pub const CLAP_EXT_CONTEXT_MENU: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.context-menu.draft/0\0") };
pub const CLAP_EXT_CONTEXT_MENU: &CStr = cstr!("clap.context-menu.draft/0");

pub const CLAP_CONTEXT_MENU_TARGET_KIND_GLOBAL: u32 = 0;
pub const CLAP_CONTEXT_MENU_TARGET_KIND_PARAM: u32 = 1;
Expand Down
6 changes: 3 additions & 3 deletions src/ext/draft/cv.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_CV: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.cv.draft/0\0") };
pub const CLAP_EXT_CV: &CStr = cstr!("clap.cv.draft/0");

pub const CLAP_PORT_CV: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"cv\0") };
pub const CLAP_PORT_CV: &CStr = cstr!("cv");

pub const CLAP_CV_VALUE: u32 = 0;
pub const CLAP_CV_GATE: u32 = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/extensible_audio_ports.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::plugin::*;
use crate::{cstr, plugin::*};

use std::ffi::{c_char, c_void, CStr};

pub const CLAP_EXT_EXTENSIBLE_AUDIO_PORTS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.extensible-audio-ports.draft0\0") };
pub const CLAP_EXT_EXTENSIBLE_AUDIO_PORTS: &CStr = cstr!("clap.extensible-audio-ports.draft0");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/midi_mappings.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{host::*, id::*, plugin::*};
use crate::{cstr, host::*, id::*, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_MIDI_MAPPINGS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.midi-mappings.draft/0\0") };
pub const CLAP_EXT_MIDI_MAPPINGS: &CStr = cstr!("clap.midi-mappings.draft/0");

pub const CLAP_MIDI_MAPPING_CC7: clap_midi_mapping_type = 0;
pub const CLAP_MIDI_MAPPING_CC14: clap_midi_mapping_type = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/param_indication.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{color::*, id::*, plugin::*};
use crate::{color::*, cstr, id::*, plugin::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_PARAM_INDICATION: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.param-indication.draft/4\0") };
pub const CLAP_EXT_PARAM_INDICATION: &CStr = cstr!("clap.param-indication.draft/4");

pub const CLAP_PARAM_INDICATION_AUTOMATION_NONE: u32 = 0;
pub const CLAP_PARAM_INDICATION_AUTOMATION_PRESENT: u32 = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/preset_load.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::factory::draft::preset_discovery::*;
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_PRESET_LOAD: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.preset-load.draft/2\0") };
pub const CLAP_EXT_PRESET_LOAD: &CStr = cstr!("clap.preset-load.draft/2");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/remote_controls.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{host::*, id::*, plugin::*, string_sizes::*};
use crate::{cstr, host::*, id::*, plugin::*, string_sizes::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_REMOTE_CONTROLS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.remote-controls.draft/2\0") };
pub const CLAP_EXT_REMOTE_CONTROLS: &CStr = cstr!("clap.remote-controls.draft/2");

pub const CLAP_REMOTE_CONTROLS_COUNT: usize = 8;

Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/resource_directory.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_RESOURCE_DIRECTORY: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.resource-directory.draft/0\0") };
pub const CLAP_EXT_RESOURCE_DIRECTORY: &CStr = cstr!("clap.resource-directory.draft/0");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/state_context.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{plugin::*, stream::*};
use crate::{cstr, plugin::*, stream::*};

use std::ffi::CStr;

pub const CLAP_EXT_STATE_CONTEXT: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.state-context.draft/1\0") };
pub const CLAP_EXT_STATE_CONTEXT: &CStr = cstr!("clap.state-context.draft/1");

pub const CLAP_STATE_CONTEXT_FOR_DUPLICATE: clap_plugin_state_context_type = 1;
pub const CLAP_STATE_CONTEXT_FOR_PRESET: clap_plugin_state_context_type = 2;
Expand Down
7 changes: 3 additions & 4 deletions src/ext/draft/surround.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_SURROUND: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.surround.draft/3\0") };
pub const CLAP_EXT_SURROUND: &CStr = cstr!("clap.surround.draft/3");

pub const CLAP_PORT_SURROUND: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"surround\0") };
pub const CLAP_PORT_SURROUND: &CStr = cstr!("surround");

pub const CLAP_SURROUND_FL: u32 = 0;
pub const CLAP_SURROUND_FR: u32 = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/track_info.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{color::*, host::*, plugin::*, string_sizes::*};
use crate::{color::*, cstr, host::*, plugin::*, string_sizes::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_TRACK_INFO: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.track-info.draft/1\0") };
pub const CLAP_EXT_TRACK_INFO: &CStr = cstr!("clap.track-info.draft/1");

pub const CLAP_TRACK_INFO_HAS_TRACK_NAME: u64 = 1 << 0;
pub const CLAP_TRACK_INFO_HAS_TRACK_COLOR: u64 = 1 << 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/transport_control.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{fixedpoint::*, host::*};
use crate::{cstr, fixedpoint::*, host::*};

use std::ffi::CStr;

pub const CLAP_EXT_TRANSPORT_CONTROL: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.transport-control.draft/0\0") };
pub const CLAP_EXT_TRANSPORT_CONTROL: &CStr = cstr!("clap.transport-control.draft/0");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/triggers.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use crate::{events::*, host::*, id::*, plugin::*, string_sizes::*};
use crate::{cstr, events::*, host::*, id::*, plugin::*, string_sizes::*};

use std::ffi::c_void;
use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_TRIGGERS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.triggers.draft/0\0") };
pub const CLAP_EXT_TRIGGERS: &CStr = cstr!("clap.triggers.draft/0");

pub const CLAP_TRIGGER_IS_AUTOMATABLE_PER_NOTE_ID: clap_trigger_info_flags = 1 << 0;
pub const CLAP_TRIGGER_IS_AUTOMATABLE_PER_KEY: clap_trigger_info_flags = 1 << 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/draft/tuning.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{events::*, host::*, id::*, plugin::*, string_sizes::*};
use crate::{cstr, events::*, host::*, id::*, plugin::*, string_sizes::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_TUNING: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.tuning.draft/2\0") };
pub const CLAP_EXT_TUNING: &CStr = cstr!("clap.tuning.draft/2");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/event_registry.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::host::*;
use crate::{cstr, host::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_EVENT_REGISTRY: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.event-registry\0") };
pub const CLAP_EXT_EVENT_REGISTRY: &CStr = cstr!("clap.event-registry");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
13 changes: 6 additions & 7 deletions src/ext/gui.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::{c_void, CStr};
use std::fmt::Debug;
use std::os::raw::{c_char, c_ulong};

pub const CLAP_EXT_GUI: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.gui\0") };
pub const CLAP_EXT_GUI: &CStr = cstr!("clap.gui");

pub const CLAP_WINDOW_API_WIN32: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"win32\0") };
pub const CLAP_WINDOW_API_COCOA: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"cocoa\0") };
pub const CLAP_WINDOW_API_X11: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"x11\0") };
pub const CLAP_WINDOW_API_WAYLAND: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"wayland\0") };
pub const CLAP_WINDOW_API_WIN32: &CStr = cstr!("win32");
pub const CLAP_WINDOW_API_COCOA: &CStr = cstr!("cocoa");
pub const CLAP_WINDOW_API_X11: &CStr = cstr!("x11");
pub const CLAP_WINDOW_API_WAYLAND: &CStr = cstr!("wayland");

pub type clap_hwnd = *mut c_void;
pub type clap_nsview = *mut c_void;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/latency.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_LATENCY: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.latency\0") };
pub const CLAP_EXT_LATENCY: &CStr = cstr!("clap.latency");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
4 changes: 2 additions & 2 deletions src/ext/log.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::host::*;
use crate::{cstr, host::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_LOG: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.log\0") };
pub const CLAP_EXT_LOG: &CStr = cstr!("clap.log");

pub const CLAP_LOG_DEBUG: clap_log_severity = 0;
pub const CLAP_LOG_INFO: clap_log_severity = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/note_name.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{host::*, plugin::*, string_sizes::*};
use crate::{cstr, host::*, plugin::*, string_sizes::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_NOTE_NAME: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.note-name\0") };
pub const CLAP_EXT_NOTE_NAME: &CStr = cstr!("clap.note-name");

#[repr(C)]
#[derive(Debug, Copy, Clone)]
Expand Down
5 changes: 2 additions & 3 deletions src/ext/note_ports.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{host::*, id::*, plugin::*, string_sizes::*};
use crate::{cstr, host::*, id::*, plugin::*, string_sizes::*};

use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_NOTE_PORTS: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.note-ports\0") };
pub const CLAP_EXT_NOTE_PORTS: &CStr = cstr!("clap.note-ports");

pub const CLAP_NOTE_DIALECT_CLAP: clap_note_dialect = 1 << 0;
pub const CLAP_NOTE_DIALECT_MIDI: clap_note_dialect = 1 << 1;
Expand Down
4 changes: 2 additions & 2 deletions src/ext/params.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use crate::{events::*, host::*, id::*, plugin::*, string_sizes::*};
use crate::{cstr, events::*, host::*, id::*, plugin::*, string_sizes::*};

use std::ffi::c_void;
use std::ffi::CStr;
use std::os::raw::c_char;

pub const CLAP_EXT_PARAMS: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.params\0") };
pub const CLAP_EXT_PARAMS: &CStr = cstr!("clap.params");

pub const CLAP_PARAM_IS_STEPPED: clap_param_info_flags = 1 << 0;
pub const CLAP_PARAM_IS_PERIODIC: clap_param_info_flags = 1 << 1;
Expand Down
5 changes: 2 additions & 3 deletions src/ext/posix_fd_support.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{host::*, plugin::*};
use crate::{cstr, host::*, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_POSIX_FD_SUPPORT: &CStr =
unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.posix-fd-support\0") };
pub const CLAP_EXT_POSIX_FD_SUPPORT: &CStr = cstr!("clap.posix-fd-support");

pub const CLAP_POSIX_FD_READ: clap_posix_fd_flags = 1 << 0;
pub const CLAP_POSIX_FD_WRITE: clap_posix_fd_flags = 1 << 1;
Expand Down
4 changes: 2 additions & 2 deletions src/ext/render.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::plugin::*;
use crate::{cstr, plugin::*};

use std::ffi::CStr;

pub const CLAP_EXT_RENDER: &CStr = unsafe { CStr::from_bytes_with_nul_unchecked(b"clap.render\0") };
pub const CLAP_EXT_RENDER: &CStr = cstr!("clap.render");

pub const CLAP_RENDER_REALTIME: clap_plugin_render_mode = 0;
pub const CLAP_RENDER_OFFLINE: clap_plugin_render_mode = 1;
Expand Down
Loading