From 0e4b5de9d4d0b827d7ad21e1d03a48db549d534c Mon Sep 17 00:00:00 2001 From: Will Medrano Date: Sat, 14 Sep 2024 15:36:18 -0700 Subject: [PATCH] Remove metadata feature. --- src/client/client_impl.rs | 7 +--- src/client/client_options.rs | 6 ++++ src/lib.rs | 5 +-- src/port/port_impl.rs | 1 - src/tests/mod.rs | 1 + src/tests/transport.rs | 30 +++++++++++++++++ src/transport.rs | 64 ++++++++++++++---------------------- 7 files changed, 63 insertions(+), 51 deletions(-) create mode 100644 src/tests/transport.rs diff --git a/src/client/client_impl.rs b/src/client/client_impl.rs index 439bdde1d..abd94f406 100644 --- a/src/client/client_impl.rs +++ b/src/client/client_impl.rs @@ -154,7 +154,6 @@ impl Client { /// # Remarks /// /// * Deallocates, not realtime safe. - #[cfg(feature = "metadata")] pub fn uuid(&self) -> j::jack_uuid_t { unsafe { let mut uuid: j::jack_uuid_t = Default::default(); @@ -169,12 +168,10 @@ impl Client { /// Get the numeric `uuid` of a client by name; returns None if client does not exist /// # Remarks /// * Not realtime safe - #[cfg(feature = "metadata")] pub fn uuid_of_client_by_name(&self, name: &str) -> Option { Self::uuid_of_client_by_name_raw(self.raw(), name) } - #[cfg(feature = "metadata")] pub(crate) fn uuid_of_client_by_name_raw( raw: *mut jack_sys::jack_client_t, name: &str, @@ -225,7 +222,6 @@ impl Client { } /// Get the name of a client by its numeric uuid. - #[cfg(feature = "metadata")] pub fn name_by_uuid(&self, uuid: j::jack_uuid_t) -> Option { let mut uuid_s = ['\0' as _; 37]; //jack_uuid_unparse expects an array of length 37 unsafe { @@ -652,8 +648,7 @@ impl Client { /// /// # Panics /// Calling this method more than once on any given client with cause a panic. - #[cfg(feature = "metadata")] - pub fn register_property_change_handler( + pub fn register_property_change_handler( &mut self, handler: H, ) -> Result<(), Error> { diff --git a/src/client/client_options.rs b/src/client/client_options.rs index d7d66b510..84659e176 100644 --- a/src/client/client_options.rs +++ b/src/client/client_options.rs @@ -32,3 +32,9 @@ bitflags! { const SESSION_ID = j::JackSessionID; } } + +impl Default for ClientOptions { + fn default() -> Self { + ClientOptions::NO_START_SERVER + } +} diff --git a/src/lib.rs b/src/lib.rs index 0792e3ee8..875551f9f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,7 @@ pub use crate::port::{ Unowned, PORT_NAME_SIZE, PORT_TYPE_SIZE, }; pub use crate::primitive_types::{Frames, PortId, Time}; +pub use crate::properties::*; pub use crate::ringbuffer::{RingBuffer, RingBufferReader, RingBufferWriter}; pub use crate::transport::{ Transport, TransportBBT, TransportBBTValidationError, TransportPosition, TransportState, @@ -56,10 +57,6 @@ pub use crate::transport::{ /// through `jack_sys::library()`. pub use jack_sys; -//only expose metadata if enabled -#[cfg(feature = "metadata")] -pub use crate::properties::*; - mod client; mod jack_enums; mod jack_utils; diff --git a/src/port/port_impl.rs b/src/port/port_impl.rs index 8414debfd..e4492c6ee 100644 --- a/src/port/port_impl.rs +++ b/src/port/port_impl.rs @@ -319,7 +319,6 @@ impl Port { } } -#[cfg(feature = "metadata")] impl Port { /// Returns the fully-qualified name of all ports currently connected to this one /// Remarks: Not realtime safe diff --git a/src/tests/mod.rs b/src/tests/mod.rs index f66dc0ab5..194292fe2 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -3,6 +3,7 @@ mod log; mod processing; mod ringbuffer; mod time; +mod transport; #[ctor::ctor] fn log_to_stdio() { diff --git a/src/tests/transport.rs b/src/tests/transport.rs new file mode 100644 index 000000000..0b66e2443 --- /dev/null +++ b/src/tests/transport.rs @@ -0,0 +1,30 @@ +use std::{thread::sleep, time::Duration}; + +use crate::{Client, TransportPosition, TransportState}; + +#[test] +fn new_transport_is_not_valid() { + assert_eq!(TransportPosition::default().valid_bbt(), false); + assert_eq!(TransportPosition::default().valid_bbt_frame_offset(), false); + assert_eq!(TransportPosition::default().frame(), 0); + assert_eq!(TransportPosition::default().bbt(), None); + assert_eq!(TransportPosition::default().bbt_offset(), None); + assert_eq!(TransportPosition::default().frame_rate(), None); + assert_eq!(TransportPosition::default().usecs(), None); +} + +#[test] +fn starting_transport_sets_state_to_started() { + let (client, _) = Client::new("", Default::default()).unwrap(); + let transport = client.transport(); + + transport.stop().unwrap(); + sleep(Duration::from_millis(50)); + assert_eq!(transport.query().unwrap().state, TransportState::Stopped); + + transport.start().unwrap(); + sleep(Duration::from_millis(50)); + assert_eq!(transport.query().unwrap().state, TransportState::Rolling); + + transport.stop().unwrap(); +} diff --git a/src/transport.rs b/src/transport.rs index 915b5d9b0..446e842ca 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -12,6 +12,10 @@ pub struct Transport { pub(crate) client_life: Weak<()>, } +//all exposed methods are realtime safe +unsafe impl Send for Transport {} +unsafe impl Sync for Transport {} + /// A structure representing the transport position. #[repr(transparent)] pub struct TransportPosition(j::jack_position_t); @@ -86,14 +90,6 @@ impl std::fmt::Display for TransportBBTValidationError { impl std::error::Error for TransportBBTValidationError {} impl Transport { - fn with_client R, R>(&self, func: F) -> Result { - if self.client_life.upgrade().is_some() { - Ok(func(self.client_ptr)) - } else { - Err(crate::Error::ClientIsNoLongerAlive) - } - } - /// Start the JACK transport rolling. /// /// # Remarks @@ -171,15 +167,6 @@ impl Transport { } } - // Helper to create generic error from jack response - fn result_from_ffi(v: Result<::libc::c_int>, r: R) -> Result { - match v { - Ok(0) => Ok(r), - Ok(error_code) => Err(crate::Error::UnknownError { error_code }), - Err(e) => Err(e), - } - } - /// Query the current transport state and position. /// /// # Remarks @@ -213,11 +200,24 @@ impl Transport { Self::state_from_ffi(unsafe { j::jack_transport_query(ptr, std::ptr::null_mut()) }) }) } -} -//all exposed methods are realtime safe -unsafe impl Send for Transport {} -unsafe impl Sync for Transport {} + fn with_client R, R>(&self, func: F) -> Result { + if self.client_life.upgrade().is_some() { + Ok(func(self.client_ptr)) + } else { + Err(crate::Error::ClientIsNoLongerAlive) + } + } + + // Helper to create generic error from jack response + fn result_from_ffi(v: Result<::libc::c_int>, r: R) -> Result { + match v { + Ok(0) => Ok(r), + Ok(error_code) => Err(crate::Error::UnknownError { error_code }), + Err(e) => Err(e), + } + } +} impl TransportPosition { /// Query to see if the BarBeatsTick data is valid. @@ -230,23 +230,6 @@ impl TransportPosition { (self.0.valid & j::JackBBTFrameOffset) != 0 } - /* - /// Query to see if the Timecode data is valid. - pub fn valid_timecode(&self) -> bool { - (self.0.valid & j::JackPositionTimecode) != 0 - } - - /// Query to see if the Audio/Video ratio is valid. - pub fn valid_avr(&self) -> bool { - (self.0.valid & j::JackAudioVideoRatio) != 0 - } - - /// Query to see if the Video frame offset is valid. - pub fn valid_video_frame_offset(&self) -> bool { - (self.0.valid & j::JackVideoFrameOffset) != 0 - } - */ - /// Get the frame number on the transport timeline. /// /// # Remarks @@ -316,7 +299,7 @@ impl TransportPosition { /// * `bbt` - The data to set in the position. `None` will invalidate the BarBeatsTick data. /// /// # Remarks - /// * If the bbt does not validate, will leave the pre-existing data intact. + /// * If `bbt` is not valid, will leave the pre-existing data intact. pub fn set_bbt( &mut self, bbt: Option, @@ -449,7 +432,7 @@ impl TransportBBT { self } - /// Validate contents. + /// Returns `self` is valid, otherwise returns an error describing what is invalid. pub fn validated(&'_ self) -> std::result::Result { if self.bar == 0 { Err(TransportBBTValidationError::BarZero) @@ -470,6 +453,7 @@ impl TransportBBT { } } + /// Returns true if valid. Use `validated` to get the exact validation results. pub fn valid(&self) -> bool { self.validated().is_ok() }