@@ -89,29 +89,33 @@ function sortStrings(xs) {
8989 return [ ...xs ] . sort ( ) ;
9090}
9191
92+ function clampMoonInt ( value ) {
93+ return Math . min ( value , 0x7fffffff ) ;
94+ }
95+
9296function projectConfig ( config ) {
9397 return {
9498 channels : config . channels ,
95- sample_rate : config . sample_rate ,
99+ sample_rate : clampMoonInt ( config . sample_rate ) ,
96100 sample_format : config . sample_format ,
97101 buffer : {
98102 kind : config . buffer . kind ,
99- min_frames : config . buffer . min_frames ,
100- max_frames : config . buffer . max_frames ,
103+ min_frames : clampMoonInt ( config . buffer . min_frames ) ,
104+ max_frames : clampMoonInt ( config . buffer . max_frames ) ,
101105 } ,
102106 } ;
103107}
104108
105109function projectRange ( range ) {
106110 return {
107111 channels : range . channels ,
108- min_sample_rate : range . min_sample_rate ,
109- max_sample_rate : range . max_sample_rate ,
112+ min_sample_rate : clampMoonInt ( range . min_sample_rate ) ,
113+ max_sample_rate : clampMoonInt ( range . max_sample_rate ) ,
110114 sample_format : range . sample_format ,
111115 buffer : {
112116 kind : range . buffer . kind ,
113- min_frames : range . buffer . min_frames ,
114- max_frames : range . buffer . max_frames ,
117+ min_frames : clampMoonInt ( range . buffer . min_frames ) ,
118+ max_frames : clampMoonInt ( range . buffer . max_frames ) ,
115119 } ,
116120 } ;
117121}
@@ -150,18 +154,51 @@ function sortDevices(devices) {
150154 ) ;
151155}
152156
157+ function projectDevice ( device ) {
158+ return {
159+ id_ok : device . id_ok ,
160+ id : device . id ,
161+ name_ok : device . name_ok ,
162+ name : device . name ,
163+ supports_input : device . supports_input ,
164+ supports_output : device . supports_output ,
165+ has_default_input_config : device . has_default_input_config ,
166+ default_input_config : projectConfig ( device . default_input_config ) ,
167+ has_default_output_config : device . has_default_output_config ,
168+ default_output_config : projectConfig ( device . default_output_config ) ,
169+ supported_input_configs_ok : device . supported_input_configs_ok ,
170+ supported_output_configs_ok : device . supported_output_configs_ok ,
171+ } ;
172+ }
173+
174+ function projectDefaultDevice ( host , kind ) {
175+ const hasKey = `has_default_${ kind } _device` ;
176+ const idOkKey = `default_${ kind } _device_id_ok` ;
177+ const idKey = `default_${ kind } _device_id` ;
178+ if ( ! host [ hasKey ] ) {
179+ return {
180+ present : false ,
181+ } ;
182+ }
183+ const match = host . devices . find (
184+ ( device ) => device . id_ok === host [ idOkKey ] && device . id === host [ idKey ] ,
185+ ) ;
186+ return {
187+ present : true ,
188+ id_ok : host [ idOkKey ] ,
189+ id : host [ idKey ] ,
190+ listed : match !== undefined ,
191+ device : match === undefined ? null : projectDevice ( match ) ,
192+ } ;
193+ }
194+
153195function sortHosts ( hosts ) {
154196 return [ ...hosts ]
155197 . map ( ( host ) => ( {
156198 id : host . id ,
157199 devices_ok : host . devices_ok ,
158- has_default_input_device : host . has_default_input_device ,
159- default_input_device_id_ok : host . default_input_device_id_ok ,
160- default_input_device_id : host . default_input_device_id ,
161- has_default_output_device : host . has_default_output_device ,
162- default_output_device_id_ok : host . default_output_device_id_ok ,
163- default_output_device_id : host . default_output_device_id ,
164- devices : sortDevices ( host . devices ) ,
200+ default_input_device : projectDefaultDevice ( host , 'input' ) ,
201+ default_output_device : projectDefaultDevice ( host , 'output' ) ,
165202 } ) )
166203 . sort ( ( a , b ) => a . id . localeCompare ( b . id , 'en' ) ) ;
167204}
0 commit comments