@@ -12,34 +12,18 @@ use std::time::Duration;
1212use super :: stream:: Stream ;
1313use super :: JACK_SAMPLE_FORMAT ;
1414
15- impl From < DeviceType > for DeviceDirection {
16- fn from ( device_type : DeviceType ) -> Self {
17- match device_type {
18- DeviceType :: InputDevice => DeviceDirection :: Input ,
19- DeviceType :: OutputDevice => DeviceDirection :: Output ,
20- }
21- }
22- }
23-
2415pub type SupportedInputConfigs = std:: vec:: IntoIter < SupportedStreamConfigRange > ;
2516pub type SupportedOutputConfigs = std:: vec:: IntoIter < SupportedStreamConfigRange > ;
2617
2718const DEFAULT_NUM_CHANNELS : u16 = 2 ;
2819const DEFAULT_SUPPORTED_CHANNELS : [ u16 ; 10 ] = [ 1 , 2 , 4 , 6 , 8 , 16 , 24 , 32 , 48 , 64 ] ;
2920
30- /// If a device is for input or output.
31- /// Until we have duplex stream support JACK clients and CPAL devices for JACK will be either input or output.
32- #[ derive( Clone , Debug ) ]
33- pub enum DeviceType {
34- InputDevice ,
35- OutputDevice ,
36- }
3721#[ derive( Clone , Debug ) ]
3822pub struct Device {
3923 name : String ,
4024 sample_rate : SampleRate ,
4125 buffer_size : SupportedBufferSize ,
42- device_type : DeviceType ,
26+ direction : DeviceDirection ,
4327 start_server_automatically : bool ,
4428 connect_ports_automatically : bool ,
4529}
@@ -49,7 +33,7 @@ impl Device {
4933 name : String ,
5034 connect_ports_automatically : bool ,
5135 start_server_automatically : bool ,
52- device_type : DeviceType ,
36+ direction : DeviceDirection ,
5337 ) -> Result < Self , String > {
5438 // ClientOptions are bit flags that you can set with the constants provided
5539 let client_options = super :: get_client_options ( start_server_automatically) ;
@@ -66,7 +50,7 @@ impl Device {
6650 min : client. buffer_size ( ) ,
6751 max : client. buffer_size ( ) ,
6852 } ,
69- device_type ,
53+ direction ,
7054 start_server_automatically,
7155 connect_ports_automatically,
7256 } ) ,
@@ -88,7 +72,7 @@ impl Device {
8872 output_client_name,
8973 connect_ports_automatically,
9074 start_server_automatically,
91- DeviceType :: OutputDevice ,
75+ DeviceDirection :: Output ,
9276 )
9377 }
9478
@@ -102,7 +86,7 @@ impl Device {
10286 input_client_name,
10387 connect_ports_automatically,
10488 start_server_automatically,
105- DeviceType :: InputDevice ,
89+ DeviceDirection :: Input ,
10690 )
10791 }
10892
@@ -143,11 +127,11 @@ impl Device {
143127 }
144128
145129 pub fn is_input ( & self ) -> bool {
146- matches ! ( self . device_type , DeviceType :: InputDevice )
130+ self . direction . supports_input ( )
147131 }
148132
149133 pub fn is_output ( & self ) -> bool {
150- matches ! ( self . device_type , DeviceType :: OutputDevice )
134+ self . direction . supports_output ( )
151135 }
152136
153137 /// Validate buffer size if Fixed is specified. This is necessary because JACK buffer size
@@ -172,7 +156,7 @@ impl DeviceTrait for Device {
172156
173157 fn description ( & self ) -> Result < DeviceDescription , DeviceNameError > {
174158 Ok ( DeviceDescriptionBuilder :: new ( self . name . clone ( ) )
175- . direction ( self . device_type . into ( ) )
159+ . direction ( self . direction )
176160 . build ( ) )
177161 }
178162
@@ -218,7 +202,7 @@ impl DeviceTrait for Device {
218202 D : FnMut ( & Data , & InputCallbackInfo ) + Send + ' static ,
219203 E : FnMut ( StreamError ) + Send + ' static ,
220204 {
221- if let DeviceType :: OutputDevice = & self . device_type {
205+ if self . direction . supports_output ( ) {
222206 // Trying to create an input stream from an output device
223207 return Err ( BuildStreamError :: StreamConfigNotSupported ) ;
224208 }
@@ -259,7 +243,7 @@ impl DeviceTrait for Device {
259243 D : FnMut ( & mut Data , & OutputCallbackInfo ) + Send + ' static ,
260244 E : FnMut ( StreamError ) + Send + ' static ,
261245 {
262- if let DeviceType :: InputDevice = & self . device_type {
246+ if self . direction . supports_input ( ) {
263247 // Trying to create an output stream from an input device
264248 return Err ( BuildStreamError :: StreamConfigNotSupported ) ;
265249 }
0 commit comments