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
6 //! applications. The rust
7 //! jack crate does not provide server creation functionality, so a server has
8 //! to be set up with the
9 //! `jackd` commandline tool, `qjackctl` the gui tool, or another method.
10 //!
11 //! # Client
12 //!
13 //! Typically, applications connect clients to the server. For the rust jack
14 //! crate, a connection can
15 //! be made with `client::Client::new`, which returns a `client::Client`.
16 //!
17 //! The `Client` can query the server for information, register ports, and
18 //! manage connections for
19 //! ports.
20 //!
21 //! To commence processing audio/midi and other information in real-time, rust
22 //! jack provides the
23 //! `client::AsyncClient::new`, which consumes a `Client` an object that
24 //! implements
25 //! `NotificationHandler` and an object that implements `ProcessHandler` and
26 //! returns a
27 //! `AsyncClient`. `AsyncClient` processes the data in real-time with the
28 //! provided handlers.
29 //!
30 //! # Port
31 //!
32 //! A `Client` may obtain port information through the `Client::port_by_id` and
33 //! `Client::port_by_name` methods. These ports can be used to manage
34 //! connections or to obtain port
35 //! metadata, though their port data (audio buffers and midi buffers) cannot be
36 //! accessed safely.
37 //!
38 //! Ports can be registered with the `Client::register_port` method. This
39 //! requires a `PortSpec`. The
40 //! jack crate comes with common specs such as `AudioInSpec`, `AudioOutSpec`,
41 //! `MidiInSpec`, and
42 //! `MidiOutSpec` under the `port` mod.
43 //!
44 //! To access the data of registered ports, use wrappers that are valid when a
45 //! `ProcessScope` is
46 //! present. The ones provided by the rust jack crate are `AudioInPort`,
47 //! `AudioOutPort`,
48 //! `MidiInPort`, and `MidiOutPort`, all of which are under the `port` mod. It
49 //! is also possible to
50 //! access the data without wrapping the newly registered `Port<PortSpec>` by
51 //! using the
52 //! `Port::buffer` method, but this returns a void pointer and is unsafe.
53 #[macro_use]
54 extern crate bitflags;
55 extern crate jack_sys;
56 #[macro_use]
57 extern crate lazy_static;
58 extern crate libc;
59 
60 
61 /// Create and manage client connections to a JACK server.
62 pub mod client;
63 
64 /// Create and manage JACK ring buffers.
65 pub mod ringbuffer;
66 
67 /// Control error and info logging from JACK.
68 pub mod logging;
69 
70 /// Enum types in jack.
71 pub mod jack_enums;
72 
73 mod jack_utils;
74 
75 /// Types for safely interacting with port data from JACK.
76 pub mod port;
77 
78 /// Platform independent types.
79 pub mod primitive_types;
80 
81 /// Return JACK's current system time in microseconds, using the JACK
82 /// clock source.
get_time() -> primitive_types::JackTime83 pub fn get_time() -> primitive_types::JackTime {
84     unsafe { jack_sys::jack_get_time() }
85 }
86 
87 /// Contains every trait defined in the jack crate.
88 pub mod traits {
89     pub use client::{NotificationHandler, ProcessHandler};
90     pub use port::PortSpec;
91 }
92 
93 /// Contains most functionality needed to interact with JACK.
94 pub mod prelude {
95     pub use client::{AsyncClient, Client, ClosureProcessHandler, CycleTimes, NotificationHandler,
96                      ProcessHandler, ProcessScope};
97     pub use client::{ClientOptions, ClientStatus, client_options, client_status};
98     pub use client::CLIENT_NAME_SIZE;
99     pub use jack_enums::{JackControl, JackErr, LatencyType};
100     pub use logging::{get_error_callback, get_info_callback, reset_error_callback,
101                       reset_info_callback, set_error_callback, set_info_callback};
102     pub use port::{AudioInPort, AudioInSpec, AudioOutPort, AudioOutSpec, MidiInPort, MidiInSpec,
103                    MidiIter, MidiOutPort, MidiOutSpec, Port, RawMidi, Unowned, UnownedPort};
104     pub use port::{PORT_NAME_SIZE, PORT_TYPE_SIZE};
105     pub use port::{PortFlags, port_flags};
106     pub use port::PortSpec;
107     pub use primitive_types::{JackFrames, JackPortId, JackTime};
108     pub use ringbuffer::{RingBuffer, RingBufferReader, RingBufferWriter};
109 }
110 
111 #[cfg(test)]
112 mod test;
113