11use anyhow:: anyhow;
22use caw_viz_udp_app_lib:: VizUdpClient ;
3- use clap:: Parser ;
3+ use clap:: { Parser , Subcommand } ;
44use line_2d:: Coord ;
55use sdl2:: { event:: Event , pixels:: Color , rect:: Rect } ;
66use std:: collections:: VecDeque ;
77
88#[ derive( Parser ) ]
9- struct Args {
10- #[ arg( long) ]
11- server : String ,
9+ struct OscilloscopeCommand {
1210 #[ arg( long, default_value_t = 640 ) ]
1311 width : u32 ,
1412 #[ arg( long, default_value_t = 480 ) ]
@@ -29,13 +27,31 @@ struct Args {
2927 blue : u8 ,
3028}
3129
30+ #[ derive( Subcommand ) ]
31+ enum Command {
32+ Oscilloscope ( OscilloscopeCommand ) ,
33+ }
34+
35+ #[ derive( Parser ) ]
36+ #[ command( name = "caw_viz_udp_app" ) ]
37+ #[ command(
38+ about = "App for launching visualization for a caw synthesizer that receives data to visualize over udp"
39+ ) ]
40+ struct Cli {
41+ #[ command( subcommand) ]
42+ command : Command ,
43+ #[ arg( long) ]
44+ server : String ,
45+ }
46+
3247#[ derive( Default ) ]
3348struct ScopeState {
3449 samples : VecDeque < ( f32 , f32 ) > ,
3550}
3651
3752fn main ( ) -> anyhow:: Result < ( ) > {
38- let mut args = Args :: parse ( ) ;
53+ let Cli { server, command } = Cli :: parse ( ) ;
54+ let Command :: Oscilloscope ( mut args) = command;
3955 let sdl_context = sdl2:: init ( ) . map_err ( |e| anyhow ! ( e) ) ?;
4056 let video_subsystem = sdl_context. video ( ) . map_err ( |e| anyhow ! ( e) ) ?;
4157 let window = video_subsystem
@@ -49,7 +65,7 @@ fn main() -> anyhow::Result<()> {
4965 . build ( ) ?;
5066 canvas. set_blend_mode ( sdl2:: render:: BlendMode :: Blend ) ;
5167 let mut event_pump = sdl_context. event_pump ( ) . map_err ( |e| anyhow ! ( e) ) ?;
52- let mut viz_udp_client = VizUdpClient :: new ( args . server ) ?;
68+ let mut viz_udp_client = VizUdpClient :: new ( server) ?;
5369 let mut scope_state = ScopeState :: default ( ) ;
5470 loop {
5571 for event in event_pump. poll_iter ( ) {
0 commit comments