Skip to content

Commit c05bdd3

Browse files
authored
Update bitflags. (#193)
1 parent fa23019 commit c05bdd3

File tree

8 files changed

+79
-81
lines changed

8 files changed

+79
-81
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "portaudio"
3-
version = "0.7.1"
3+
version = "0.8.0"
44
authors = ["Jeremy Letang <[email protected]>",
55
"Mitchell Nordine <[email protected]>"]
66
description = "PortAudio bindings for Rust."
@@ -9,7 +9,7 @@ homepage = "https://github.com/RustAudio/rust-portaudio"
99
repository = "https://github.com/RustAudio/rust-portaudio.git"
1010

1111
[dependencies]
12-
bitflags = "0.8.2"
12+
bitflags = "2"
1313
libc = "0.2.51"
1414
num = { version = "0.2.0", default-features = false }
1515
portaudio-sys2 = { path = "./rust-portaudio-sys", version = "0.1.0" }

examples/blocking.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn run() -> Result<(), pa::Error> {
6868
where
6969
F: Fn() -> Result<pa::StreamAvailable, pa::error::Error>,
7070
{
71-
'waiting_for_stream: loop {
71+
loop {
7272
match f() {
7373
Ok(available) => match available {
7474
pa::StreamAvailable::Frames(frames) => return frames as u32,
@@ -83,11 +83,11 @@ fn run() -> Result<(), pa::Error> {
8383
),
8484
}
8585
}
86-
};
86+
}
8787

8888
// Now start the main read/write loop! In this example, we pass the input buffer directly to
8989
// the output buffer, so watch out for feedback.
90-
'stream: loop {
90+
loop {
9191
// How many frames are available on the input stream?
9292
let in_frames = wait_for_stream(|| stream.read_available(), "Read");
9393

examples/saw.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ fn run() -> Result<(), pa::Error> {
3535
let mut settings =
3636
pa.default_output_stream_settings(CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFER)?;
3737
// we won't output out of range samples so don't bother clipping them.
38-
settings.flags = pa::stream_flags::CLIP_OFF;
38+
settings.flags = pa::StreamFlags::CLIP_OFF;
3939

4040
// This routine will be called by the PortAudio engine when audio is needed. It may called at
4141
// interrupt level on some machines so don't do anything that could mess up the system like

examples/sine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn run() -> Result<(), pa::Error> {
4242
let mut settings =
4343
pa.default_output_stream_settings(CHANNELS, SAMPLE_RATE, FRAMES_PER_BUFFER)?;
4444
// we won't output out of range samples so don't bother clipping them.
45-
settings.flags = pa::stream_flags::CLIP_OFF;
45+
settings.flags = pa::StreamFlags::CLIP_OFF;
4646

4747
// This routine will be called by the PortAudio engine when audio is needed. It may called at
4848
// interrupt level on some machines so don't do anything that could mess up the system like

rust-portaudio-sys/src/lib.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,51 +5,51 @@
55
--blacklist-type PaStreamCallbackResult
66
*/
77

8-
#[cfg(any(target_os="macos", target_os="linux", target_os="win32", target_os="windows"))]
8+
#[cfg(any(target_os = "macos", target_os = "linux", target_os = "windows"))]
99
mod c_library {
1010
#[link(name = "portaudio")]
11-
extern {}
11+
extern "C" {}
1212
}
1313

1414
mod portaudio;
1515

1616
pub use portaudio::*;
1717

18-
pub const PA_NO_DEVICE : PaDeviceIndex = -1;
18+
pub const PA_NO_DEVICE: PaDeviceIndex = -1;
1919

2020
// Sample format
2121
pub type SampleFormat = ::std::os::raw::c_ulong;
22-
pub const PA_FLOAT_32 : SampleFormat = 0x00000001;
23-
pub const PA_INT_32 : SampleFormat = 0x00000002;
24-
pub const PA_INT_24 : SampleFormat = 0x00000004;
25-
pub const PA_INT_16 : SampleFormat = 0x00000008;
26-
pub const PA_INT_8 : SampleFormat = 0x00000010;
27-
pub const PA_UINT_8 : SampleFormat = 0x00000020;
28-
pub const PA_CUSTOM_FORMAT : SampleFormat = 0x00010000;
29-
pub const PA_NON_INTERLEAVED : SampleFormat = 0x80000000;
22+
pub const PA_FLOAT_32: SampleFormat = 0x00000001;
23+
pub const PA_INT_32: SampleFormat = 0x00000002;
24+
pub const PA_INT_24: SampleFormat = 0x00000004;
25+
pub const PA_INT_16: SampleFormat = 0x00000008;
26+
pub const PA_INT_8: SampleFormat = 0x00000010;
27+
pub const PA_UINT_8: SampleFormat = 0x00000020;
28+
pub const PA_CUSTOM_FORMAT: SampleFormat = 0x00010000;
29+
pub const PA_NON_INTERLEAVED: SampleFormat = 0x80000000;
3030

3131
// Stream flags
3232
pub type StreamFlags = ::std::os::raw::c_ulong;
33-
pub const PA_NO_FLAG : StreamFlags = 0;
34-
pub const PA_CLIP_OFF : StreamFlags = 0x00000001;
35-
pub const PA_DITHER_OFF : StreamFlags = 0x00000002;
36-
pub const PA_NEVER_DROP_INPUT : StreamFlags = 0x00000004;
37-
pub const PA_PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK : StreamFlags = 0x00000008;
38-
pub const PA_PLATFORM_SPECIFIC_FLAGS : StreamFlags = 0xFFFF0000;
33+
pub const PA_NO_FLAG: StreamFlags = 0;
34+
pub const PA_CLIP_OFF: StreamFlags = 0x00000001;
35+
pub const PA_DITHER_OFF: StreamFlags = 0x00000002;
36+
pub const PA_NEVER_DROP_INPUT: StreamFlags = 0x00000004;
37+
pub const PA_PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK: StreamFlags = 0x00000008;
38+
pub const PA_PLATFORM_SPECIFIC_FLAGS: StreamFlags = 0xFFFF0000;
3939

4040
// Stream callback falgs.
4141
pub type StreamCallbackFlags = ::std::os::raw::c_ulong;
42-
pub const INPUT_UNDERFLOW : StreamCallbackFlags = 0x00000001;
43-
pub const INPUT_OVERFLOW : StreamCallbackFlags = 0x00000002;
44-
pub const OUTPUT_UNDERFLOW : StreamCallbackFlags = 0x00000004;
45-
pub const OUTPUT_OVERFLOW : StreamCallbackFlags = 0x00000008;
46-
pub const PRIMING_OUTPUT : StreamCallbackFlags = 0x00000010;
42+
pub const INPUT_UNDERFLOW: StreamCallbackFlags = 0x00000001;
43+
pub const INPUT_OVERFLOW: StreamCallbackFlags = 0x00000002;
44+
pub const OUTPUT_UNDERFLOW: StreamCallbackFlags = 0x00000004;
45+
pub const OUTPUT_OVERFLOW: StreamCallbackFlags = 0x00000008;
46+
pub const PRIMING_OUTPUT: StreamCallbackFlags = 0x00000010;
4747

4848
/// A function to convert C `*const char` arrays into Rust `&'a str`s.
49-
pub fn c_str_to_str<'a>(c_str: *const std::os::raw::c_char) -> Result<&'a str, ::std::str::Utf8Error> {
50-
unsafe {
51-
::std::ffi::CStr::from_ptr(c_str).to_str()
52-
}
49+
pub fn c_str_to_str<'a>(
50+
c_str: *const std::os::raw::c_char,
51+
) -> Result<&'a str, ::std::str::Utf8Error> {
52+
unsafe { ::std::ffi::CStr::from_ptr(c_str).to_str() }
5353
}
5454

5555
/// A function to convert Rust strings to C strings
@@ -61,9 +61,9 @@ pub const PA_CONTINUE: PaStreamCallbackResult = 0;
6161
pub const PA_COMPLETE: PaStreamCallbackResult = 1;
6262
pub const PA_ABORT: PaStreamCallbackResult = 2;
6363
/**
64-
Allowable return values for the PaStreamCallback.
65-
@see PaStreamCallback
66-
*/
64+
Allowable return values for the PaStreamCallback.
65+
@see PaStreamCallback
66+
*/
6767
// XXX Callback returns int, but this is uint,
6868
// making a cast necessary in the examples.
6969
// So it is now a int. Probably not a problem?

src/enum_primitive.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ macro_rules! enum_from_primitive_impl_ty {
3838
}
3939

4040
/// Helper macro for internal use by `enum_from_primitive!`.
41-
#[macro_use(enum_from_primitive_impl_ty)]
4241
macro_rules! enum_from_primitive_impl {
4342
($name:ident, $( $variant:ident )*) => {
4443
impl $crate::FromPrimitive for $name {
@@ -50,7 +49,6 @@ macro_rules! enum_from_primitive_impl {
5049

5150
/// Wrap this macro around an `enum` declaration to get an
5251
/// automatically generated implementation of `num::FromPrimitive`.
53-
#[macro_use(enum_from_primitive_impl)]
5452
macro_rules! enum_from_primitive {
5553
(
5654
$( #[$enum_attr:meta] )*

src/stream.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ use std::os::raw;
1010
use std::{self, ptr};
1111

1212
use super::error::Error;
13-
use super::types::{
14-
sample_format_flags, DeviceIndex, DeviceKind, SampleFormat, SampleFormatFlags, Time,
15-
};
13+
use super::types::{DeviceIndex, DeviceKind, SampleFormat, SampleFormatFlags, Time};
1614
use super::Sample;
1715

1816
pub use self::callback_flags::CallbackFlags;
@@ -85,7 +83,7 @@ pub trait Writer: Flow {
8583
}
8684

8785
/// An alias for the boxed Callback function type.
88-
type CallbackFn = FnMut(
86+
type CallbackFn = dyn FnMut(
8987
*const raw::c_void,
9088
*mut raw::c_void,
9189
raw::c_ulong,
@@ -699,21 +697,22 @@ pub mod flags {
699697
///
700698
/// See the [bitflags repo](https://github.com/rust-lang/bitflags/blob/master/src/lib.rs)
701699
/// for examples of composing flags together.
702-
pub flags Flags: ::std::os::raw::c_ulong {
700+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
701+
pub struct Flags: ::std::os::raw::c_ulong {
703702
/// No flags.
704-
const NO_FLAG = ffi::PA_NO_FLAG,
703+
const NO_FLAG = ffi::PA_NO_FLAG;
705704
/// Disable default clipping of out of range samples.
706-
const CLIP_OFF = ffi::PA_CLIP_OFF,
705+
const CLIP_OFF = ffi::PA_CLIP_OFF;
707706
/// Disable default dithering.
708-
const DITHER_OFF = ffi::PA_DITHER_OFF,
707+
const DITHER_OFF = ffi::PA_DITHER_OFF;
709708
/// Flag requests that where possible a full duplex stream will not discard overflowed
710709
/// input samples without calling the stream callback.
711-
const NEVER_DROP_INPUT = ffi::PA_NEVER_DROP_INPUT,
710+
const NEVER_DROP_INPUT = ffi::PA_NEVER_DROP_INPUT;
712711
/// Call the stream callback to fill initial output buffers, rather than the default
713712
/// behavior of priming the buffers with zeros (silence)
714-
const PA_PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK = ffi::PA_PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK,
713+
const PA_PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK = ffi::PA_PRIME_OUTPUT_BUFFERS_USING_STREAM_CALLBACK;
715714
/// A mask specifying the platform specific bits.
716-
const PA_PLATFORM_SPECIFIC_FLAGS = ffi::PA_PLATFORM_SPECIFIC_FLAGS,
715+
const PA_PLATFORM_SPECIFIC_FLAGS = ffi::PA_PLATFORM_SPECIFIC_FLAGS;
717716
}
718717
}
719718

@@ -755,27 +754,28 @@ pub mod callback_flags {
755754
use ffi;
756755
bitflags! {
757756
/// Flag bit constants for the status flags passed to the stream's callback function.
758-
pub flags CallbackFlags: ::std::os::raw::c_ulong {
757+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
758+
pub struct CallbackFlags: ::std::os::raw::c_ulong {
759759
/// No flags.
760-
const NO_FLAG = ffi::PA_NO_FLAG,
760+
const NO_FLAG = ffi::PA_NO_FLAG;
761761
/// In a stream opened with paFramesPerBufferUnspecified, indicates that input data is
762762
/// all silence (zeros) because no real data is available. In a stream opened without
763763
/// `FramesPerBufferUnspecified`, it indicates that one or more zero samples have been
764764
/// inserted into the input buffer to compensate for an input underflow.
765-
const INPUT_UNDERFLOW = ffi::INPUT_UNDERFLOW,
765+
const INPUT_UNDERFLOW = ffi::INPUT_UNDERFLOW;
766766
/// In a stream opened with paFramesPerBufferUnspecified, indicates that data prior to
767767
/// the first sample of the input buffer was discarded due to an overflow, possibly
768768
/// because the stream callback is using too much CPU time. Otherwise indicates that
769769
/// data prior to one or more samples in the input buffer was discarded.
770-
const INPUT_OVERFLOW = ffi::INPUT_OVERFLOW,
770+
const INPUT_OVERFLOW = ffi::INPUT_OVERFLOW;
771771
/// Indicates that output data (or a gap) was inserted, possibly because the stream
772772
/// callback is using too much CPU time.
773-
const OUTPUT_UNDERFLOW = ffi::OUTPUT_UNDERFLOW,
773+
const OUTPUT_UNDERFLOW = ffi::OUTPUT_UNDERFLOW;
774774
/// Indicates that output data will be discarded because no room is available.
775-
const OUTPUT_OVERFLOW = ffi::OUTPUT_OVERFLOW,
775+
const OUTPUT_OVERFLOW = ffi::OUTPUT_OVERFLOW;
776776
/// Some of all of the output data will be used to prime the stream, input data may be
777777
/// zero.
778-
const PRIMING_OUTPUT = ffi::PRIMING_OUTPUT,
778+
const PRIMING_OUTPUT = ffi::PRIMING_OUTPUT;
779779
}
780780
}
781781

@@ -850,7 +850,7 @@ impl<S: Sample> Parameters<S> {
850850
/// `UseHostApiSpecificDeviceSpecification` flag.
851851
pub fn from_c_params(c_params: ffi::PaStreamParameters) -> Option<Self> {
852852
let sample_format_flags: SampleFormatFlags = c_params.sampleFormat.into();
853-
let is_interleaved = !sample_format_flags.contains(sample_format_flags::NON_INTERLEAVED);
853+
let is_interleaved = !sample_format_flags.contains(SampleFormatFlags::NON_INTERLEAVED);
854854
let c_sample_format = SampleFormat::from_flags(c_params.sampleFormat.into());
855855
if S::sample_format() != c_sample_format {
856856
return None;
@@ -883,7 +883,7 @@ impl<S: Sample> From<Parameters<S>> for ffi::PaStreamParameters {
883883
let sample_format = S::sample_format();
884884
let mut sample_format_flags = sample_format.flags();
885885
if !is_interleaved {
886-
sample_format_flags.insert(sample_format_flags::NON_INTERLEAVED);
886+
sample_format_flags.insert(SampleFormatFlags::NON_INTERLEAVED);
887887
}
888888
ffi::PaStreamParameters {
889889
device: device.into(),

src/types.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -131,19 +131,19 @@ impl SampleFormat {
131131
///
132132
/// Returns `None` if no matching format is found.
133133
pub fn from_flags(flags: SampleFormatFlags) -> Self {
134-
if flags.contains(sample_format_flags::FLOAT_32) {
134+
if flags.contains(SampleFormatFlags::FLOAT_32) {
135135
SampleFormat::F32
136-
} else if flags.contains(sample_format_flags::INT_32) {
136+
} else if flags.contains(SampleFormatFlags::INT_32) {
137137
SampleFormat::I32
138-
} else if flags.contains(sample_format_flags::INT_24) {
138+
} else if flags.contains(SampleFormatFlags::INT_24) {
139139
SampleFormat::I24
140-
} else if flags.contains(sample_format_flags::INT_16) {
140+
} else if flags.contains(SampleFormatFlags::INT_16) {
141141
SampleFormat::I16
142-
} else if flags.contains(sample_format_flags::INT_8) {
142+
} else if flags.contains(SampleFormatFlags::INT_8) {
143143
SampleFormat::I8
144-
} else if flags.contains(sample_format_flags::UINT_8) {
144+
} else if flags.contains(SampleFormatFlags::UINT_8) {
145145
SampleFormat::U8
146-
} else if flags.contains(sample_format_flags::CUSTOM_FORMAT) {
146+
} else if flags.contains(SampleFormatFlags::CUSTOM_FORMAT) {
147147
SampleFormat::Custom
148148
} else {
149149
SampleFormat::Unknown
@@ -153,13 +153,13 @@ impl SampleFormat {
153153
/// Converts `self` into the respective **SampleFormatFlags**.
154154
pub fn flags(self) -> SampleFormatFlags {
155155
match self {
156-
SampleFormat::F32 => sample_format_flags::FLOAT_32,
157-
SampleFormat::I32 => sample_format_flags::INT_32,
158-
SampleFormat::I24 => sample_format_flags::INT_24,
159-
SampleFormat::I16 => sample_format_flags::INT_16,
160-
SampleFormat::I8 => sample_format_flags::INT_8,
161-
SampleFormat::U8 => sample_format_flags::UINT_8,
162-
SampleFormat::Custom => sample_format_flags::CUSTOM_FORMAT,
156+
SampleFormat::F32 => SampleFormatFlags::FLOAT_32,
157+
SampleFormat::I32 => SampleFormatFlags::INT_32,
158+
SampleFormat::I24 => SampleFormatFlags::INT_24,
159+
SampleFormat::I16 => SampleFormatFlags::INT_16,
160+
SampleFormat::I8 => SampleFormatFlags::INT_8,
161+
SampleFormat::U8 => SampleFormatFlags::UINT_8,
162+
SampleFormat::Custom => SampleFormatFlags::CUSTOM_FORMAT,
163163
SampleFormat::Unknown => SampleFormatFlags::empty(),
164164
}
165165
}
@@ -197,23 +197,23 @@ pub mod sample_format_flags {
197197
/// The paNonInterleaved flag indicates that audio data is passed as an array of pointers
198198
/// to separate buffers, one buffer for each channel. Usually, when this flag is not used,
199199
/// audio data is passed as a single buffer with all channels interleaved.
200-
pub flags SampleFormatFlags: ::std::os::raw::c_ulong {
200+
pub struct SampleFormatFlags: ::std::os::raw::c_ulong {
201201
/// 32 bits float sample format
202-
const FLOAT_32 = ffi::PA_FLOAT_32,
202+
const FLOAT_32 = ffi::PA_FLOAT_32;
203203
/// 32 bits int sample format
204-
const INT_32 = ffi::PA_INT_32,
204+
const INT_32 = ffi::PA_INT_32;
205205
/// Packed 24 bits int sample format
206-
const INT_24 = ffi::PA_INT_24,
206+
const INT_24 = ffi::PA_INT_24;
207207
/// 16 bits int sample format
208-
const INT_16 = ffi::PA_INT_16,
208+
const INT_16 = ffi::PA_INT_16;
209209
/// 8 bits int sample format
210-
const INT_8 = ffi::PA_INT_8,
210+
const INT_8 = ffi::PA_INT_8;
211211
/// 8 bits unsigned int sample format
212-
const UINT_8 = ffi::PA_UINT_8,
212+
const UINT_8 = ffi::PA_UINT_8;
213213
/// Custom sample format
214-
const CUSTOM_FORMAT = ffi::PA_CUSTOM_FORMAT,
214+
const CUSTOM_FORMAT = ffi::PA_CUSTOM_FORMAT;
215215
/// Non interleaved sample format
216-
const NON_INTERLEAVED = ffi::PA_NON_INTERLEAVED,
216+
const NON_INTERLEAVED = ffi::PA_NON_INTERLEAVED;
217217
}
218218
}
219219

0 commit comments

Comments
 (0)