@@ -89,8 +89,22 @@ impl Connection {
8989 Some ( UIEvent :: GetInfo ( GetInfo :: QueueList ) )
9090 } else if line == "aq" {
9191 Some ( UIEvent :: TestAddQueue )
92- } else if line == "p" {
93- Some ( UIEvent :: TestPlay )
92+ } else if line. starts_with ( "p " ) {
93+ let p = line. split_ascii_whitespace ( ) . nth ( 1 ) ;
94+ if let Some ( path) = p {
95+ Some ( UIEvent :: TestPlay ( path. to_string ( ) ) )
96+ } else {
97+ None
98+ }
99+ } else if line. starts_with ( "c " ) {
100+ let mut c = line. split_ascii_whitespace ( ) . into_iter ( ) . collect :: < Vec < & str > > ( ) ;
101+ if c. len ( ) < 2 {
102+ None
103+ } else {
104+ c. remove ( 0 ) ;
105+ let t = c. join ( " " ) ;
106+ Some ( UIEvent :: Test ( t. to_string ( ) ) )
107+ }
94108 } else {
95109 println ! ( "?" ) ;
96110 None
@@ -149,7 +163,7 @@ impl Connection {
149163 }
150164 } ) ;
151165 }
152- async fn xmit_test ( & mut self ) {
166+ async fn xmit_test ( & mut self , path : String ) {
153167 let track = protocol:: Track {
154168 path : "blah" . to_string ( ) ,
155169 owner : self . my_id . clone ( ) ,
@@ -168,7 +182,11 @@ impl Connection {
168182
169183 self . play_state = PlayState :: Transmitting ;
170184 tokio:: spawn ( async move {
171- let mut t: Track = Track :: load ( "../temp/demo.mp3" ) . unwrap ( ) ;
185+ let mut t: Track = match Track :: load ( & path) {
186+ Ok ( t) => t,
187+ Err ( _) => return
188+ } ;
189+
172190
173191 dbg ! ( & t. samples. len( ) ) ;
174192 audio_tx_2. send ( AudioData :: Clear ) . unwrap ( ) ;
@@ -269,7 +287,9 @@ impl Connection {
269287 // some ui event
270288 Some ( event) = self . ui_rx. recv( ) => {
271289 match event {
272- UIEvent :: Test ( _) => todo!( ) ,
290+ UIEvent :: Test ( text) => {
291+ self . message_tx. send( Message :: Text ( text) ) . unwrap( ) ;
292+ } ,
273293 UIEvent :: GetInfo ( i) => {
274294 self . message_tx. send( Message :: GetInfo ( i) ) . unwrap( ) ;
275295 } ,
@@ -283,10 +303,10 @@ impl Connection {
283303 self . message_tx. send( Message :: GetInfo ( GetInfo :: QueueList ) ) . unwrap( ) ;
284304 // and uhh put it in idk
285305 } ,
286- UIEvent :: TestPlay => {
306+ UIEvent :: TestPlay ( path ) => {
287307 if self . play_state == PlayState :: Stopped {
288308 println!( "{:?}" , self . play_state) ;
289- self . xmit_test( ) . await ;
309+ self . xmit_test( path ) . await ;
290310 }
291311 } ,
292312 UIEvent :: Quit => break ,
@@ -317,7 +337,7 @@ enum UIEvent {
317337 Test ( String ) ,
318338 GetInfo ( GetInfo ) ,
319339 TestAddQueue ,
320- TestPlay ,
340+ TestPlay ( String ) ,
321341 Quit ,
322342}
323343
0 commit comments