Skip to content

Commit

Permalink
Remove metadata feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
wmedrano committed Sep 14, 2024
1 parent 3ff021f commit 0e4b5de
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 51 deletions.
7 changes: 1 addition & 6 deletions src/client/client_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<jack_sys::jack_uuid_t> {
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,
Expand Down Expand Up @@ -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<String> {
let mut uuid_s = ['\0' as _; 37]; //jack_uuid_unparse expects an array of length 37
unsafe {
Expand Down Expand Up @@ -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<H: PropertyChangeHandler + 'static>(
pub fn register_property_change_handler<H: 'static + PropertyChangeHandler>(
&mut self,
handler: H,
) -> Result<(), Error> {
Expand Down
6 changes: 6 additions & 0 deletions src/client/client_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ bitflags! {
const SESSION_ID = j::JackSessionID;
}
}

impl Default for ClientOptions {
fn default() -> Self {
ClientOptions::NO_START_SERVER
}
}
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/port/port_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ impl<PS> Port<PS> {
}
}

#[cfg(feature = "metadata")]
impl<PS> Port<PS> {
/// Returns the fully-qualified name of all ports currently connected to this one
/// Remarks: Not realtime safe
Expand Down
1 change: 1 addition & 0 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod log;
mod processing;
mod ringbuffer;
mod time;
mod transport;

#[ctor::ctor]
fn log_to_stdio() {
Expand Down
30 changes: 30 additions & 0 deletions src/tests/transport.rs
Original file line number Diff line number Diff line change
@@ -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();
}
64 changes: 24 additions & 40 deletions src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -86,14 +90,6 @@ impl std::fmt::Display for TransportBBTValidationError {
impl std::error::Error for TransportBBTValidationError {}

impl Transport {
fn with_client<F: Fn(*mut j::jack_client_t) -> R, R>(&self, func: F) -> Result<R> {
if self.client_life.upgrade().is_some() {
Ok(func(self.client_ptr))
} else {
Err(crate::Error::ClientIsNoLongerAlive)
}
}

/// Start the JACK transport rolling.
///
/// # Remarks
Expand Down Expand Up @@ -171,15 +167,6 @@ impl Transport {
}
}

// Helper to create generic error from jack response
fn result_from_ffi<R>(v: Result<::libc::c_int>, r: R) -> Result<R> {
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
Expand Down Expand Up @@ -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<F: Fn(*mut j::jack_client_t) -> R, R>(&self, func: F) -> Result<R> {
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<R>(v: Result<::libc::c_int>, r: R) -> Result<R> {
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.
Expand All @@ -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
Expand Down Expand Up @@ -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<TransportBBT>,
Expand Down Expand Up @@ -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<Self, TransportBBTValidationError> {
if self.bar == 0 {
Err(TransportBBTValidationError::BarZero)
Expand All @@ -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()
}
Expand Down

0 comments on commit 0e4b5de

Please sign in to comment.