@@ -130,7 +130,6 @@ impl Graph {
130
130
let inputs = vec ! [ AudioRenderQuantum :: from( self . alloc. silence( ) ) ; number_of_inputs] ;
131
131
let outputs = vec ! [ AudioRenderQuantum :: from( self . alloc. silence( ) ) ; number_of_outputs] ;
132
132
133
- let index = index. 0 as usize ;
134
133
self . nodes . insert (
135
134
index,
136
135
RefCell :: new ( Node {
@@ -148,7 +147,7 @@ impl Graph {
148
147
}
149
148
150
149
pub fn add_edge ( & mut self , source : ( AudioNodeId , usize ) , dest : ( AudioNodeId , usize ) ) {
151
- self . nodes [ source. 0 . 0 as usize ]
150
+ self . nodes [ source. 0 ]
152
151
. get_mut ( )
153
152
. outgoing_edges
154
153
. push ( OutgoingEdge {
@@ -161,7 +160,7 @@ impl Graph {
161
160
}
162
161
163
162
pub fn remove_edge ( & mut self , source : AudioNodeId , dest : AudioNodeId ) {
164
- self . nodes [ source. 0 as usize ]
163
+ self . nodes [ source]
165
164
. get_mut ( )
166
165
. outgoing_edges
167
166
. retain ( |edge| edge. other_id != dest) ;
@@ -170,10 +169,7 @@ impl Graph {
170
169
}
171
170
172
171
pub fn remove_edges_from ( & mut self , source : AudioNodeId ) {
173
- self . nodes [ source. 0 as usize ]
174
- . get_mut ( )
175
- . outgoing_edges
176
- . clear ( ) ;
172
+ self . nodes [ source] . get_mut ( ) . outgoing_edges . clear ( ) ;
177
173
178
174
self . nodes . values_mut ( ) . for_each ( |node| {
179
175
node. get_mut ( )
@@ -188,20 +184,17 @@ impl Graph {
188
184
// Issue #92, a race condition can occur for AudioParams. They may have already been
189
185
// removed from the audio graph if the node they feed into was dropped.
190
186
// Therefore, do not assume this node still exists:
191
- if let Some ( node) = self . nodes . get_mut ( index. 0 as usize ) {
187
+ if let Some ( node) = self . nodes . get_mut ( index) {
192
188
node. get_mut ( ) . free_when_finished = true ;
193
189
}
194
190
}
195
191
196
192
pub fn mark_cycle_breaker ( & mut self , index : AudioNodeId ) {
197
- self . nodes [ index. 0 as usize ] . get_mut ( ) . cycle_breaker = true ;
193
+ self . nodes [ index] . get_mut ( ) . cycle_breaker = true ;
198
194
}
199
195
200
196
pub fn route_message ( & mut self , index : AudioNodeId , msg : & mut dyn Any ) {
201
- self . nodes [ index. 0 as usize ]
202
- . get_mut ( )
203
- . processor
204
- . onmessage ( msg) ;
197
+ self . nodes [ index] . get_mut ( ) . processor . onmessage ( msg) ;
205
198
}
206
199
207
200
/// Helper function for `order_nodes` - traverse node and outgoing edges
@@ -224,7 +217,7 @@ impl Graph {
224
217
let cycle_breaker_node = marked_temp
225
218
. iter ( )
226
219
. skip ( pos)
227
- . find ( |node_id| self . nodes [ node_id. 0 as usize ] . borrow ( ) . cycle_breaker ) ;
220
+ . find ( |& & node_id| self . nodes [ node_id] . borrow ( ) . cycle_breaker ) ;
228
221
229
222
match cycle_breaker_node {
230
223
Some ( & node_id) => {
@@ -253,11 +246,7 @@ impl Graph {
253
246
marked_temp. push ( node_id) ;
254
247
255
248
// Visit outgoing nodes, and call `visit` on them recursively
256
- for edge in self . nodes [ node_id. 0 as usize ]
257
- . borrow ( )
258
- . outgoing_edges
259
- . iter ( )
260
- {
249
+ for edge in self . nodes [ node_id] . borrow ( ) . outgoing_edges . iter ( ) {
261
250
let cycle_breaker_applied = self . visit (
262
251
edge. other_id ,
263
252
marked,
@@ -319,7 +308,7 @@ impl Graph {
319
308
// since the audio graph could contain legs detached from the destination and those should
320
309
// still be rendered.
321
310
let mut cycle_breaker_applied = false ;
322
- for node_id in self . nodes . keys ( ) . map ( |i| AudioNodeId ( i as u64 ) ) {
311
+ for node_id in self . nodes . keys ( ) {
323
312
cycle_breaker_applied = self . visit (
324
313
node_id,
325
314
& mut marked,
@@ -338,7 +327,7 @@ impl Graph {
338
327
// clear the outgoing edges of the nodes that have been recognized as cycle breaker
339
328
let nodes = & mut self . nodes ;
340
329
cycle_breakers. iter ( ) . for_each ( |node_id| {
341
- nodes[ node_id. 0 as usize ] . get_mut ( ) . outgoing_edges . clear ( ) ;
330
+ nodes[ * node_id] . get_mut ( ) . outgoing_edges . clear ( ) ;
342
331
} ) ;
343
332
344
333
continue ;
@@ -379,7 +368,7 @@ impl Graph {
379
368
// process every node, in topological sorted order
380
369
self . ordered . iter ( ) . for_each ( |index| {
381
370
// acquire a mutable borrow of the current processing node
382
- let mut node = nodes[ index. 0 as usize ] . borrow_mut ( ) ;
371
+ let mut node = nodes[ * index] . borrow_mut ( ) ;
383
372
384
373
// make sure all input buffers have the correct number of channels, this might not be
385
374
// the case if the node has no inputs connected or the channel count has just changed
@@ -414,7 +403,7 @@ impl Graph {
414
403
// audio params are connected to the 'hidden' usize::MAX output, ignore them here
415
404
. filter ( |edge| edge. other_index != usize:: MAX )
416
405
. for_each ( |edge| {
417
- let mut output_node = nodes[ edge. other_id . 0 as usize ] . borrow_mut ( ) ;
406
+ let mut output_node = nodes[ edge. other_id ] . borrow_mut ( ) ;
418
407
output_node. has_inputs_connected = true ;
419
408
let signal = & node. outputs [ edge. self_index ] ;
420
409
let channel_config = & output_node. channel_config . clone ( ) ;
@@ -440,7 +429,7 @@ impl Graph {
440
429
// Check if we can decommission this node (end of life)
441
430
if can_free {
442
431
// Node is dropped, remove it from the node list
443
- let mut node = nodes. remove ( index. 0 as usize ) . into_inner ( ) ;
432
+ let mut node = nodes. remove ( * index) . into_inner ( ) ;
444
433
self . reclaim_id_channel
445
434
. push ( node. reclaim_id . take ( ) . unwrap ( ) ) ;
446
435
drop ( node) ;
@@ -467,7 +456,7 @@ impl Graph {
467
456
// - special node (destination = id 0, listener = id 1), or
468
457
// - not connected to this dropped node, or
469
458
// - if the control thread still has a handle to it.
470
- let retain = id < 2 || !was_connected || !node. free_when_finished ;
459
+ let retain = id. 0 < 2 || !was_connected || !node. free_when_finished ;
471
460
472
461
if !retain {
473
462
self . reclaim_id_channel
@@ -482,7 +471,7 @@ impl Graph {
482
471
if nodes_dropped {
483
472
let mut i = 0 ;
484
473
while i < self . ordered . len ( ) {
485
- if nodes. get ( self . ordered [ i] . 0 as usize ) . is_none ( ) {
474
+ if nodes. get ( self . ordered [ i] ) . is_none ( ) {
486
475
self . ordered . remove ( i) ;
487
476
} else {
488
477
i += 1 ;
@@ -491,7 +480,7 @@ impl Graph {
491
480
}
492
481
493
482
// Return the output buffer of destination node
494
- & self . nodes [ 0 ] . get_mut ( ) . outputs [ 0 ]
483
+ & self . nodes [ AudioNodeId ( 0 ) ] . get_mut ( ) . outputs [ 0 ]
495
484
}
496
485
}
497
486
@@ -681,7 +670,7 @@ mod tests {
681
670
// dropped and the AudioNodeId(3) should be reclaimed
682
671
add_node ( & mut graph, 2 , node. clone ( ) ) ;
683
672
// Mark the node as 'detached from the control thread', so it is allowed to drop
684
- graph. nodes [ 2 ] . get_mut ( ) . free_when_finished = true ;
673
+ graph. nodes [ AudioNodeId ( 2 ) ] . get_mut ( ) . free_when_finished = true ;
685
674
686
675
// Connect the regular node to the AudioDestinationNode
687
676
add_edge ( & mut graph, 2 , 0 ) ;
@@ -723,7 +712,7 @@ mod tests {
723
712
// dropped and the AudioNodeId(3) should be reclaimed
724
713
add_node ( & mut graph, 2 , node. clone ( ) ) ;
725
714
// Mark the node as 'detached from the control thread', so it is allowed to drop
726
- graph. nodes [ 2 ] . get_mut ( ) . free_when_finished = true ;
715
+ graph. nodes [ AudioNodeId ( 2 ) ] . get_mut ( ) . free_when_finished = true ;
727
716
728
717
// Connect the regular node to the AudioDestinationNode
729
718
add_edge ( & mut graph, 2 , 0 ) ;
@@ -732,7 +721,7 @@ mod tests {
732
721
let param = Box :: new ( TestNode { tail_time : true } ) ; // audio params have tail time true
733
722
add_node ( & mut graph, 3 , param) ;
734
723
// Mark the node as 'detached from the control thread', so it is allowed to drop
735
- graph. nodes [ 3 ] . get_mut ( ) . free_when_finished = true ;
724
+ graph. nodes [ AudioNodeId ( 3 ) ] . get_mut ( ) . free_when_finished = true ;
736
725
737
726
// Connect the audioparam to the regular node
738
727
add_audioparam ( & mut graph, 3 , 2 ) ;
0 commit comments