jack/lib.rs
1//! Rust bindings for JACK, a real-time audio and midi library.
2//!
3//! # Server
4//!
5//! JACK provides a high priority server to manipulate audio and midi across applications. The rust
6//! jack crate does not provide server creation functionality, so a server has to be set up with the
7//! `jackd` commandline tool, `qjackctl` the gui tool, or another method.
8//!
9//! # Client
10//!
11//! Typically, applications connect clients to the server. For the rust jack crate, a connection can
12//! be made with [`client::Client::new`], which returns a [`client::Client`].
13//!
14//! The `Client` can query the server for information, register ports, and manage connections for
15//! ports.
16//!
17//! To commence processing audio/midi and other information in real-time, rust jack provides the
18//! [`Client::activate_async`], which consumes the [`Client`], an object that implements
19//! `NotificationHandler` and an object that implements `ProcessHandler` and returns a
20//! [`AsyncClient`]. [`AsyncClient`] processes the data in real-time with the provided handlers.
21//!
22//! # Port
23//!
24//! A [`Client`] may obtain port information through the [`Client::port_by_id`] and
25//! [`Client::port_by_name`] methods. These ports can be used to manage connections or to obtain port
26//! metadata, though their port data (audio buffers and midi buffers) cannot be accessed safely.
27//!
28//! Ports can be registered with the [`Client::register_port`] method. This requires a [`PortSpec`]. The
29//! jack crate comes with common specs such as [`AudioIn`], [`AudioOut`], [`MidiIn`], and
30//! [`MidiOut`].
31//!
32//! To access the data of registered ports, use their specialized methods within a `ProcessHandler`
33//! callback. For example, [`Port<AudioIn>::as_mut_slice`] returns a audio buffer that can be written
34//! to.
35
36#[allow(deprecated)]
37pub use crate::client::ClosureProcessHandler;
38pub use crate::client::{
39 AsyncClient, Client, ClientOptions, ClientStatus, CycleTimes, InternalClientID,
40 NotificationHandler, ProcessHandler, ProcessScope, CLIENT_NAME_SIZE,
41};
42pub use crate::jack_enums::{Control, Error, LatencyType};
43pub use crate::logging::{set_logger, LoggerType};
44pub use crate::port::{
45 AudioIn, AudioOut, MidiIn, MidiIter, MidiOut, MidiWriter, Port, PortFlags, PortSpec, RawMidi,
46 Unowned, PORT_NAME_SIZE, PORT_TYPE_SIZE,
47};
48pub use crate::primitive_types::{Frames, PortId, Time};
49pub use crate::properties::*;
50pub use crate::ringbuffer::{RingBuffer, RingBufferReader, RingBufferWriter};
51pub use crate::transport::{
52 Transport, TransportBBT, TransportBBTValidationError, TransportPosition, TransportState,
53 TransportStatePosition,
54};
55
56/// The underlying system bindings for JACK. Can be useful for using possibly experimental stuff
57/// through [`jack_sys::library()`].
58pub use jack_sys;
59
60mod client;
61mod jack_enums;
62mod jack_utils;
63mod logging;
64mod port;
65mod primitive_types;
66mod properties;
67mod ringbuffer;
68mod transport;
69
70/// A collection of useful but optional functionality.
71pub mod contrib {
72 mod closure;
73
74 pub use closure::ClosureProcessHandler;
75}
76
77#[cfg(test)]
78mod tests;
79
80static TIME_CLIENT: std::sync::LazyLock<Client> = std::sync::LazyLock::new(|| {
81 Client::new("deprecated_get_time", ClientOptions::default())
82 .unwrap()
83 .0
84});
85
86/// Return JACK's current system time in microseconds, using the JACK clock
87/// source.
88#[deprecated = "Prefer using Client::time. get_time will be eventually be removed and it requires an extra client initialization."]
89pub fn get_time() -> primitive_types::Time {
90 TIME_CLIENT.time()
91}